Project

General

Profile

7 krennw
/**
*
* 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)
*
*/
2 krennw



#include <string>

#include <ast/IScope.hpp>
#include <ast/identifiers/Identifier.hpp>
#include <base/Exceptions.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/IdentifierBlock.hpp>
#include <ast/identifiers/ConstantIdentifier.hpp>
#include <ast/identifiers/MainModule.hpp>

using namespace Ast;


static void abstractError() {
throw new Base::NotImplementedException();
}


Base::FuncPtr Identifier::s_idVmt [2][IDENTIFIERKIND_NR_ITEMS] =
{
{
/* TypeIdentifier = 0, */ (Base::FuncPtr) &TypeIdentifier::create,
/* EnumIdentifier = 1, */ (Base::FuncPtr) &EnumIdentifier::create,
/* LandmarkIdentifier = 2, */ &abstractError,
/* AttributeIdentifier = 3, */ (Base::FuncPtr) &AttributeIdentifier::create,
/* LocalVariableIdentifier = 4, */ (Base::FuncPtr) &LocalVariableIdentifier::create,
/* ParameterIdentifier = 5, */ (Base::FuncPtr) &ParameterIdentifier::create,
/* ExpressionVariableIdentifier = 6, */ (Base::FuncPtr) &ExpressionVariableIdentifier::create,
/* MethodIdentifier = 7, */ (Base::FuncPtr) &MethodIdentifier::create,
/* NamedActionIdentifier = 8, */ (Base::FuncPtr) &NamedActionIdentifier::create,
/* Module = 9, */ (Base::FuncPtr) &Module::create,
/* List_Normal = 10, */ (Base::FuncPtr) &UnspecIdentifierBlock::create,
/* Constant = 11, */ (Base::FuncPtr) &ConstantIdentifier::create,
/* MainModule = 12, */ (Base::FuncPtr) &MainModule::create,
/* List_Nondeterministic = 13, */ (Base::FuncPtr) &NondetIdentifierBlock::create,
/* List_Seqential = 14, */ (Base::FuncPtr) &SeqIdentifierBlock::create,
/* List_Prioritized = 15, */ (Base::FuncPtr) &PrioIdentifierBlock::create
},
{
/* TypeIdentifier = 0, */ (Base::FuncPtr) &TypeIdentifier::createCopy,
/* EnumIdentifier = 1, */ (Base::FuncPtr) &EnumIdentifier::createCopy,
/* LandmarkIdentifier = 2, */ &abstractError,
/* AttributeIdentifier = 3, */ (Base::FuncPtr) &AttributeIdentifier::createCopy,
/* LocalVariableIdentifier = 4, */ (Base::FuncPtr) &LocalVariableIdentifier::createCopy,
/* ParameterIdentifier = 5, */ (Base::FuncPtr) &ParameterIdentifier::createCopy,
/* ExpressionVariableIdentifier = 6, */ (Base::FuncPtr) &ExpressionVariableIdentifier::createCopy,
/* MethodIdentifier = 7, */ (Base::FuncPtr) &MethodIdentifier::createCopy,
/* NamedActionIdentifier = 8, */ (Base::FuncPtr) &NamedActionIdentifier::createCopy,
/* Module = 9, */ (Base::FuncPtr) &Module::create,
/* List_Normal = 10, */ (Base::FuncPtr) &UnspecIdentifierBlock::createCopy,
/* Constant = 11, */ (Base::FuncPtr) &ConstantIdentifier::createCopy,
/* MainModule = 12, */ (Base::FuncPtr) &MainModule::createCopy,
/* List_Nondeterministic = 13, */ (Base::FuncPtr) &NondetIdentifierBlock::createCopy,
/* List_Seqential = 14, */ (Base::FuncPtr) &SeqIdentifierBlock::createCopy,
/* List_Prioritized = 15, */ (Base::FuncPtr) &PrioIdentifierBlock::createCopy
}
};

Identifier* Identifier::createVirtual(IdentifierKind aType) {
return (std::uint8_t)aType < IDENTIFIERKIND_NR_ITEMS ? ((ConstrPtr)s_idVmt[0][(std::uint8_t)aType])() : nullptr;
}

Identifier* Identifier::createVirtual(const Identifier& toCopy) {
std::uint8_t aType ((std::uint8_t)toCopy.kind());
return ((CopyConstrPtr)s_idVmt[1][aType])(toCopy);
}


Identifier::Identifier(IdentifierKind identifierKind) :
AstElement(AstNodeTypeEnum::identifier),
m_tokenText (""),
m_line (-1),
m_column (-1),
m_definingScope (nullptr),
m_identifierKind(identifierKind),
m_type (nullptr)
{}


Identifier::Identifier(const Identifier& toCopy) :
AstElement(AstNodeTypeEnum::identifier),
m_tokenText (toCopy.m_tokenText),
m_line (toCopy.m_line),
m_column (toCopy.m_column),
m_definingScope (toCopy.m_definingScope),
m_identifierKind(toCopy.m_identifierKind),
m_type (nullptr)
{}

Identifier::~Identifier()
{}

Identifier* Identifier::clone() const
{
throw new Base::NotImplementedException();
}

void Identifier::accept(IAstVisitor& )
{
throw new Base::NotImplementedException();
}

string Identifier::fullyQualifiedName() const {
string result = tokenText();
IScope* parent = definingScope();
while (parent != nullptr) {
std::string scopeName = parent->getScopeName();
if (!scopeName.empty())
result = scopeName + "::" + result;
parent = parent->getParentScope();
}
return result;
}



//int32_t Identifier::compareTo(Identifier* obj)
//{
// throw new Base::NotImplementedException();
//return npc(tokenText())->compareTo(npc(obj)->toString());
//}