root/trunk/compiler/cppAst/ast/identifiers/Identifier.hpp
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 | ||
#pragma once
|
|||
#include <cstdint>
|
|||
#include <string>
|
|||
#include <ast/AstElement.hpp>
|
|||
#include <ast/IScope.hpp>
|
|||
#include <base/TiresiasObject.hpp>
|
|||
namespace Ast {
|
|||
using namespace std;
|
|||
/**
|
|||
* You must not change the assigned values as this
|
|||
* needs to be kept in sync with the definitions in Argos!
|
|||
*/
|
|||
enum class IdentifierKind : std::uint8_t
|
|||
{
|
|||
TypeIdentifier = 0, // some named type
|
|||
EnumIdentifier = 1, // identifier of enumerated type
|
|||
LandmarkIdentifier = 2, // landmark
|
|||
AttributeIdentifier = 3, // global attribute
|
|||
LocalVariableIdentifier = 4, // local variable
|
|||
ParameterIdentifier = 5, // method/named action argument
|
|||
ExpressionVariableIdentifier = 6, // var in an expression
|
|||
MethodIdentifier = 7, // a method
|
|||
NamedActionIdentifier = 8, // a named action
|
|||
Module = 9, // the main module - actually this has no name...
|
|||
List_Normal = 10,
|
|||
Constant = 11,
|
|||
MainModule = 12,
|
|||
List_Nondeterministic = 13,
|
|||
List_Seqential = 14,
|
|||
List_Prioritized = 15,
|
|||
IDENTIFIERKIND_LAST_ITEM = List_Prioritized
|
|||
};
|
|||
#define IDENTIFIERKIND_NR_ITEMS ((std::uint8_t)IdentifierKind::IDENTIFIERKIND_LAST_ITEM + 1)
|
|||
class Type; // forward
|
|||
class Identifier
|
|||
: public AstElement
|
|||
{
|
|||
protected:
|
|||
typedef Identifier* (*ConstrPtr)();
|
|||
typedef Identifier* (*CopyConstrPtr)(const Identifier& toCopy);
|
|||
IdentifierKind m_identifierKind;
|
|||
int32_t m_line;
|
|||
int32_t m_column;
|
|||
IScope* m_definingScope;
|
|||
Type* m_type;
|
|||
string m_tokenText;
|
|||
static Base::FuncPtr s_idVmt [2][IDENTIFIERKIND_NR_ITEMS];
|
|||
static Identifier* createVirtual(IdentifierKind aType); // virtual constructor used by Ast
|
|||
static Identifier* createVirtual(const Identifier& toCopy); // virtual copy constructor used by Ast
|
|||
public:
|
|||
friend class Ast;
|
|||
Identifier(IdentifierKind identifierKind);
|
|||
Identifier(const Identifier& toCopy);
|
|||
~Identifier() override;
|
|||
IdentifierKind kind() const { return m_identifierKind; };
|
|||
Type* type() const { return m_type; };
|
|||
int32_t line() const { return m_line; };
|
|||
int32_t column() const { return m_column; };
|
|||
IScope* definingScope() const { return m_definingScope; };
|
|||
string tokenText() const { return m_tokenText; };
|
|||
string toString() const { return tokenText(); };
|
|||
string fullyQualifiedName() const;
|
|||
void setType(Type* aType) { m_type = aType; };
|
|||
void setTokenText(string aText) { m_tokenText = aText; };
|
|||
void init(std::int32_t line, std::int32_t col, const char* text,
|
|||
IScope* scopeRef, Type* typeRef)
|
|||
{
|
|||
m_line = line;
|
|||
m_column = col;
|
|||
m_tokenText = text;
|
|||
m_definingScope = scopeRef;
|
|||
m_type = typeRef;
|
|||
}
|
|||
void accept(IAstVisitor& visitor);
|
|||
virtual Identifier* clone() const;
|
|||
};
|
|||
}
|
|||
#include <ast/types/Type.hpp>
|