root / trunk / compiler / cppAst / ast / identifiers / Identifier.hpp @ 7
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 |
#pragma once
|
27 |
|
28 |
#include <cstdint> |
29 |
#include <string> |
30 |
|
31 |
#include <ast/AstElement.hpp> |
32 |
#include <ast/IScope.hpp> |
33 |
#include <base/TiresiasObject.hpp> |
34 |
|
35 |
|
36 |
namespace Ast {
|
37 |
|
38 |
using namespace std; |
39 |
|
40 |
/**
|
41 |
* You must not change the assigned values as this
|
42 |
* needs to be kept in sync with the definitions in Argos!
|
43 |
*/
|
44 |
enum class IdentifierKind : std::uint8_t |
45 |
{ |
46 |
TypeIdentifier = 0, // some named type |
47 |
EnumIdentifier = 1, // identifier of enumerated type |
48 |
LandmarkIdentifier = 2, // landmark |
49 |
AttributeIdentifier = 3, // global attribute |
50 |
LocalVariableIdentifier = 4, // local variable |
51 |
ParameterIdentifier = 5, // method/named action argument |
52 |
ExpressionVariableIdentifier = 6, // var in an expression |
53 |
MethodIdentifier = 7, // a method |
54 |
NamedActionIdentifier = 8, // a named action |
55 |
Module = 9, // the main module - actually this has no name... |
56 |
List_Normal = 10,
|
57 |
Constant = 11,
|
58 |
MainModule = 12,
|
59 |
List_Nondeterministic = 13,
|
60 |
List_Seqential = 14,
|
61 |
List_Prioritized = 15,
|
62 |
IDENTIFIERKIND_LAST_ITEM = List_Prioritized |
63 |
}; |
64 |
|
65 |
#define IDENTIFIERKIND_NR_ITEMS ((std::uint8_t)IdentifierKind::IDENTIFIERKIND_LAST_ITEM + 1) |
66 |
|
67 |
class Type; // forward |
68 |
|
69 |
class Identifier |
70 |
: public AstElement
|
71 |
{ |
72 |
protected:
|
73 |
typedef Identifier* (*ConstrPtr)();
|
74 |
typedef Identifier* (*CopyConstrPtr)(const Identifier& toCopy); |
75 |
|
76 |
IdentifierKind m_identifierKind; |
77 |
int32_t m_line; |
78 |
int32_t m_column; |
79 |
IScope* m_definingScope; |
80 |
Type* m_type; |
81 |
string m_tokenText;
|
82 |
|
83 |
static Base::FuncPtr s_idVmt [2][IDENTIFIERKIND_NR_ITEMS]; |
84 |
static Identifier* createVirtual(IdentifierKind aType); // virtual constructor used by Ast |
85 |
static Identifier* createVirtual(const Identifier& toCopy); // virtual copy constructor used by Ast |
86 |
public:
|
87 |
friend class Ast; |
88 |
Identifier(IdentifierKind identifierKind); |
89 |
Identifier(const Identifier& toCopy);
|
90 |
~Identifier() override;
|
91 |
|
92 |
IdentifierKind kind() const { return m_identifierKind; }; |
93 |
Type* type() const { return m_type; }; |
94 |
int32_t line() const { return m_line; }; |
95 |
int32_t column() const { return m_column; }; |
96 |
IScope* definingScope() const { return m_definingScope; }; |
97 |
string tokenText() const { return m_tokenText; }; |
98 |
string toString() const { return tokenText(); }; |
99 |
string fullyQualifiedName() const; |
100 |
|
101 |
void setType(Type* aType) { m_type = aType; };
|
102 |
void setTokenText(string aText) { m_tokenText = aText; }; |
103 |
|
104 |
void init(std::int32_t line, std::int32_t col, const char* text, |
105 |
IScope* scopeRef, Type* typeRef) |
106 |
{ |
107 |
m_line = line; |
108 |
m_column = col; |
109 |
m_tokenText = text; |
110 |
m_definingScope = scopeRef; |
111 |
m_type = typeRef; |
112 |
} |
113 |
|
114 |
|
115 |
void accept(IAstVisitor& visitor);
|
116 |
virtual Identifier* clone() const; |
117 |
}; |
118 |
} |
119 |
#include <ast/types/Type.hpp> |