Project

General

Profile

/**
*
* OOAS Compiler - C++ AST
*
* Copyright 2015, AIT Austrian Institute of Technology.
* All rights reserved.
*
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
*
* If you modify the file please update the list of contributors below to in-
* clude your name. Please also stick to the coding convention of using TABs
* to do the basic (block-level) indentation and spaces for anything after
* that. (Enable the display of special chars and it should be pretty obvious
* what this means.) Also, remove all trailing whitespace.
*
* Contributors:
* Willibald Krenn (AIT)
* Stephan Zimmerer (AIT)
* Christoph Czurda (AIT)
*
*/



/*
* Ast.cpp
*
* Created on: Jan 27, 2014
* Author: willibald
*/

#include "Ast.hpp"

#include <ast/identifiers/TypeIdentifier.hpp>
#include <ast/identifiers/EnumIdentifier.hpp>
#include <ast/identifiers/AttributeIdentifier.hpp>
#include <ast/identifiers/LocalVariableIdentifier.hpp>
#include <ast/identifiers/ParameterIdentifier.hpp>
#include <ast/identifiers/ExpressionVariableIdentifier.hpp>
#include <ast/identifiers/MethodIdentifier.hpp>
#include <ast/identifiers/NamedActionIdentifier.hpp>
#include <ast/identifiers/Module.hpp>
#include <ast/identifiers/ConstantIdentifier.hpp>
#include <ast/types/IntType.hpp>
#include <ast/types/BoolType.hpp>
#include <ast/types/EnumType.hpp>
#include <ast/types/ValuedEnumType.hpp>
#include <ast/types/ListType.hpp>
#include <ast/types/TupleType.hpp>
#include <ast/types/NullType.hpp>
#include <ast/types/FunctionType.hpp>
#include <ast/types/ActionSystemType.hpp>
#include <ast/statements/GuardedCommand.hpp>
#include <ast/statements/Call.hpp>
#include <ast/statements/Assignment.hpp>
#include <ast/statements/SeqBlock.hpp>
#include <ast/statements/NondetBlock.hpp>
#include <ast/statements/PrioBlock.hpp>
#include <ast/statements/Skip.hpp>
#include <ast/statements/Abort.hpp>
#include <ast/expressions/TernaryOperator.hpp>
#include <ast/expressions/BinaryOperator.hpp>
#include <ast/expressions/UnaryOperator.hpp>
#include <ast/expressions/ExistsQuantifier.hpp>
#include <ast/expressions/ForallQuantifier.hpp>
#include <ast/expressions/ListConstructor.hpp>
#include <ast/expressions/SetConstructor.hpp>
#include <ast/expressions/TupleConstructor.hpp>
#include <ast/expressions/ObjectConstructor.hpp>
#include <ast/expressions/IdentifierExpression.hpp>
#include <ast/expressions/ValueExpression.hpp>
#include <ast/expressions/TypeExpression.hpp>
#include <ast/expressions/TupleMapAccessExpression.hpp>
#include <ast/expressions/CallExpression.hpp>
#include <ast/expressions/AccessExpression.hpp>
#include <ast/identifiers/IdentifierBlock.hpp>
#include <ast/identifiers/MainModule.hpp>
#include <ast/types/PointerType.hpp>
#include "DeepCloneVisitor.hpp"
#include <CallContext.hpp>
#include <base/CdtFixes.hpp>
#include <cassert>


namespace Ast {

Base::TiresiasObject* Ast::takeOwnership(Base::TiresiasObject* obj) {
m_allocatedAstObjects.push_back(obj);
return obj;
}



SymbolTable* Ast::createSymbolTable() {
return (SymbolTable*) takeOwnership(new SymbolTable());
}
SymbolTable* Ast::createSymbolTable(const SymbolTable& toCopy) {
return (SymbolTable*) takeOwnership(new SymbolTable(toCopy));
}


// Identifiers
Identifier* Ast::createIdentifier(IdentifierKind t) {
Identifier* result = (Identifier*) takeOwnership(Identifier::createVirtual(t));
assert(result == nullptr || result->kind() == t);
return result;
}
Identifier* Ast::createIdentifier(const Identifier& toCopy) {
Identifier* result = (Identifier*) takeOwnership(Identifier::createVirtual(toCopy));
assert(result == nullptr || result->kind() == toCopy.kind());
return result;
}


ActionSystemInstance* Ast::createActionSystemInstance(){
return (ActionSystemInstance*) takeOwnership(new ActionSystemInstance());
}
ActionSystemInstance* Ast::createActionSystemInstance(const ActionSystemInstance& toCopy) {
return (ActionSystemInstance*) takeOwnership(new ActionSystemInstance(toCopy));
}


IdentifierList* Ast::createIdentifierList() {
return (IdentifierList*) takeOwnership(new IdentifierList());
};
IdentifierList* Ast::createIdentifierList(const IdentifierList& toCopy) {
return (IdentifierList*) takeOwnership(new IdentifierList(toCopy));
}


ParameterList* Ast::createParameterList() {
return (ParameterList*) takeOwnership(new ParameterList());
}
ParameterList* Ast::createParameterList(const ParameterList& toCopy) {
return (ParameterList*) takeOwnership(new ParameterList(toCopy));
}


ActionSystemInstanceList* Ast::createActionSystemInstanceList() {
return (ActionSystemInstanceList*) takeOwnership(new ActionSystemInstanceList());
}
ActionSystemInstanceList* Ast::createActionSystemInstanceList(const ActionSystemInstanceList& toCopy) {
return (ActionSystemInstanceList*) takeOwnership(new ActionSystemInstanceList(toCopy));
}


// Types
Type* Ast::createType(TypeKind t) {
Type* result = (Type*)takeOwnership(Type::createVirtual(t));
assert(result == nullptr || result->kind() == t);
return result;
}
Type* Ast::createType(const Type& toCopy) {
Type* result = (Type*)takeOwnership(Type::createVirtual(toCopy));
assert(result == nullptr || result->kind() == toCopy.kind());
return result;
}


TypeList* Ast::createTypeList() {
return (TypeList*) takeOwnership(new TypeList());
}
TypeList* Ast::createTypeList(const TypeList& toCopy) {
return (TypeList*) takeOwnership(new TypeList(toCopy));
}


// Statements
Statement* Ast::createStatement(StatementKind t) {
Statement* result = (Statement*) takeOwnership(Statement::createVirtual(t));
assert(result == nullptr || result->kind() == t);
return result;
}
Statement* Ast::createStatement(const Statement& toCopy) {
Statement* result = (Statement*) takeOwnership(Statement::createVirtual(toCopy));
assert(result == nullptr || result->kind() == toCopy.kind());
return result;
}

Statement* Ast::deepCopyStatement(Statement* toCopy) {
Statement* result = createStatement(*toCopy);
DeepCloneVisitor cloner (m_context, this);
result->accept(cloner);
return result;
}


StatementList* Ast::createStatementList() {
return (StatementList*) takeOwnership( new StatementList());
};
StatementList* Ast::createStatementList(const StatementList& toCopy) {
return (StatementList*) takeOwnership( new StatementList(toCopy));
}



// Expressions
Expression* Ast::createExpression(ExpressionKind t) {
Expression* result = (Expression*) takeOwnership(Expression::createVirtual(t));
assert(result == nullptr || result->kind() == t);
return result;
}
Expression* Ast::createExpression(const Expression& toCopy) {
Expression* result = (Expression*) takeOwnership(Expression::createVirtual(toCopy));
assert(result == nullptr || result->kind() == toCopy.kind());
return result;
}

Expression* Ast::deepCopyExpression(Expression* toCopy) {
Expression* result = createExpression(*toCopy);
DeepCloneVisitor cloner (m_context, this);
result->accept(cloner);
return result;
}


ExpressionList* Ast::createExpressionList(){
return (ExpressionList*) takeOwnership(new ExpressionList());
};
ExpressionList* Ast::createExpressionList(const ExpressionList& toCopy) {
return (ExpressionList*) takeOwnership(new ExpressionList(toCopy));
}

Ast::Ast(CallContext* context):
m_context (context),
m_allocatedAstObjects()
{}

Ast::~Ast() {
for (auto& o: m_allocatedAstObjects)
delete o;
}

} /* namespace Ast */
(1-1/23)