root / trunk / compiler / cppAst / ast / identifiers / Identifier.cpp
1 |
/**
|
---|---|
2 |
*
|
3 |
* OOAS Compiler - C++ AST
|
4 |
*
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
6 |
* All rights reserved.
|
7 |
*
|
8 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
9 |
*
|
10 |
* If you modify the file please update the list of contributors below to in-
|
11 |
* clude your name. Please also stick to the coding convention of using TABs
|
12 |
* to do the basic (block-level) indentation and spaces for anything after
|
13 |
* that. (Enable the display of special chars and it should be pretty obvious
|
14 |
* what this means.) Also, remove all trailing whitespace.
|
15 |
*
|
16 |
* Contributors:
|
17 |
* Willibald Krenn (AIT)
|
18 |
* Stephan Zimmerer (AIT)
|
19 |
* Christoph Czurda (AIT)
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
#include <string> |
27 |
|
28 |
#include <ast/IScope.hpp> |
29 |
#include <ast/identifiers/Identifier.hpp> |
30 |
#include <base/Exceptions.hpp> |
31 |
#include <ast/identifiers/TypeIdentifier.hpp> |
32 |
#include <ast/identifiers/EnumIdentifier.hpp> |
33 |
#include <ast/identifiers/AttributeIdentifier.hpp> |
34 |
#include <ast/identifiers/LocalVariableIdentifier.hpp> |
35 |
#include <ast/identifiers/ParameterIdentifier.hpp> |
36 |
#include <ast/identifiers/ExpressionVariableIdentifier.hpp> |
37 |
#include <ast/identifiers/MethodIdentifier.hpp> |
38 |
#include <ast/identifiers/NamedActionIdentifier.hpp> |
39 |
#include <ast/identifiers/Module.hpp> |
40 |
#include <ast/identifiers/IdentifierBlock.hpp> |
41 |
#include <ast/identifiers/ConstantIdentifier.hpp> |
42 |
#include <ast/identifiers/MainModule.hpp> |
43 |
|
44 |
using namespace Ast; |
45 |
|
46 |
|
47 |
static void abstractError() { |
48 |
throw new Base::NotImplementedException(); |
49 |
} |
50 |
|
51 |
|
52 |
Base::FuncPtr Identifier::s_idVmt [2][IDENTIFIERKIND_NR_ITEMS] =
|
53 |
{ |
54 |
{ |
55 |
/* TypeIdentifier = 0, */ (Base::FuncPtr) &TypeIdentifier::create,
|
56 |
/* EnumIdentifier = 1, */ (Base::FuncPtr) &EnumIdentifier::create,
|
57 |
/* LandmarkIdentifier = 2, */ &abstractError,
|
58 |
/* AttributeIdentifier = 3, */ (Base::FuncPtr) &AttributeIdentifier::create,
|
59 |
/* LocalVariableIdentifier = 4, */ (Base::FuncPtr) &LocalVariableIdentifier::create,
|
60 |
/* ParameterIdentifier = 5, */ (Base::FuncPtr) &ParameterIdentifier::create,
|
61 |
/* ExpressionVariableIdentifier = 6, */ (Base::FuncPtr) &ExpressionVariableIdentifier::create,
|
62 |
/* MethodIdentifier = 7, */ (Base::FuncPtr) &MethodIdentifier::create,
|
63 |
/* NamedActionIdentifier = 8, */ (Base::FuncPtr) &NamedActionIdentifier::create,
|
64 |
/* Module = 9, */ (Base::FuncPtr) &Module::create,
|
65 |
/* List_Normal = 10, */ (Base::FuncPtr) &UnspecIdentifierBlock::create,
|
66 |
/* Constant = 11, */ (Base::FuncPtr) &ConstantIdentifier::create,
|
67 |
/* MainModule = 12, */ (Base::FuncPtr) &MainModule::create,
|
68 |
/* List_Nondeterministic = 13, */ (Base::FuncPtr) &NondetIdentifierBlock::create,
|
69 |
/* List_Seqential = 14, */ (Base::FuncPtr) &SeqIdentifierBlock::create,
|
70 |
/* List_Prioritized = 15, */ (Base::FuncPtr) &PrioIdentifierBlock::create
|
71 |
}, |
72 |
{ |
73 |
/* TypeIdentifier = 0, */ (Base::FuncPtr) &TypeIdentifier::createCopy,
|
74 |
/* EnumIdentifier = 1, */ (Base::FuncPtr) &EnumIdentifier::createCopy,
|
75 |
/* LandmarkIdentifier = 2, */ &abstractError,
|
76 |
/* AttributeIdentifier = 3, */ (Base::FuncPtr) &AttributeIdentifier::createCopy,
|
77 |
/* LocalVariableIdentifier = 4, */ (Base::FuncPtr) &LocalVariableIdentifier::createCopy,
|
78 |
/* ParameterIdentifier = 5, */ (Base::FuncPtr) &ParameterIdentifier::createCopy,
|
79 |
/* ExpressionVariableIdentifier = 6, */ (Base::FuncPtr) &ExpressionVariableIdentifier::createCopy,
|
80 |
/* MethodIdentifier = 7, */ (Base::FuncPtr) &MethodIdentifier::createCopy,
|
81 |
/* NamedActionIdentifier = 8, */ (Base::FuncPtr) &NamedActionIdentifier::createCopy,
|
82 |
/* Module = 9, */ (Base::FuncPtr) &Module::create,
|
83 |
/* List_Normal = 10, */ (Base::FuncPtr) &UnspecIdentifierBlock::createCopy,
|
84 |
/* Constant = 11, */ (Base::FuncPtr) &ConstantIdentifier::createCopy,
|
85 |
/* MainModule = 12, */ (Base::FuncPtr) &MainModule::createCopy,
|
86 |
/* List_Nondeterministic = 13, */ (Base::FuncPtr) &NondetIdentifierBlock::createCopy,
|
87 |
/* List_Seqential = 14, */ (Base::FuncPtr) &SeqIdentifierBlock::createCopy,
|
88 |
/* List_Prioritized = 15, */ (Base::FuncPtr) &PrioIdentifierBlock::createCopy
|
89 |
} |
90 |
}; |
91 |
|
92 |
Identifier* Identifier::createVirtual(IdentifierKind aType) { |
93 |
return (std::uint8_t)aType < IDENTIFIERKIND_NR_ITEMS ? ((ConstrPtr)s_idVmt[0][(std::uint8_t)aType])() : nullptr; |
94 |
} |
95 |
|
96 |
Identifier* Identifier::createVirtual(const Identifier& toCopy) {
|
97 |
std::uint8_t aType ((std::uint8_t)toCopy.kind()); |
98 |
return ((CopyConstrPtr)s_idVmt[1][aType])(toCopy); |
99 |
} |
100 |
|
101 |
|
102 |
Identifier::Identifier(IdentifierKind identifierKind) : |
103 |
AstElement(AstNodeTypeEnum::identifier), |
104 |
m_tokenText (""),
|
105 |
m_line (-1),
|
106 |
m_column (-1),
|
107 |
m_definingScope (nullptr),
|
108 |
m_identifierKind(identifierKind), |
109 |
m_type (nullptr)
|
110 |
{} |
111 |
|
112 |
|
113 |
Identifier::Identifier(const Identifier& toCopy) :
|
114 |
AstElement(AstNodeTypeEnum::identifier), |
115 |
m_tokenText (toCopy.m_tokenText), |
116 |
m_line (toCopy.m_line), |
117 |
m_column (toCopy.m_column), |
118 |
m_definingScope (toCopy.m_definingScope), |
119 |
m_identifierKind(toCopy.m_identifierKind), |
120 |
m_type (nullptr)
|
121 |
{} |
122 |
|
123 |
Identifier::~Identifier() |
124 |
{} |
125 |
|
126 |
Identifier* Identifier::clone() const
|
127 |
{ |
128 |
throw new Base::NotImplementedException(); |
129 |
} |
130 |
|
131 |
void Identifier::accept(IAstVisitor& )
|
132 |
{ |
133 |
throw new Base::NotImplementedException(); |
134 |
} |
135 |
|
136 |
string Identifier::fullyQualifiedName() const { |
137 |
string result = tokenText();
|
138 |
IScope* parent = definingScope(); |
139 |
while (parent != nullptr) { |
140 |
std::string scopeName = parent->getScopeName();
|
141 |
if (!scopeName.empty())
|
142 |
result = scopeName + "::" + result;
|
143 |
parent = parent->getParentScope(); |
144 |
} |
145 |
return result;
|
146 |
} |
147 |
|
148 |
|
149 |
|
150 |
//int32_t Identifier::compareTo(Identifier* obj)
|
151 |
//{
|
152 |
// throw new Base::NotImplementedException();
|
153 |
//return npc(tokenText())->compareTo(npc(obj)->toString());
|
154 |
//}
|
155 |
|
156 |
|