root / trunk / compiler / cppAst / ast / types / EnumType.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 <ast/types/Type.hpp> |
29 |
#include <ast/SymbolTable.hpp> |
30 |
#include <deque> |
31 |
#include <ast/identifiers/EnumIdentifier.hpp> |
32 |
#include <ast/IAstVisitor.hpp> |
33 |
|
34 |
namespace Ast {
|
35 |
|
36 |
class EnumType |
37 |
: public Type
|
38 |
{ |
39 |
protected:
|
40 |
SymbolTable* m_enumSymbols; |
41 |
std::deque<EnumIdentifier*> m_listOfEnumSymbols; |
42 |
|
43 |
EnumType(TypeKind tk): |
44 |
Type(tk), |
45 |
m_enumSymbols(nullptr),
|
46 |
m_listOfEnumSymbols() |
47 |
{} |
48 |
EnumType(): |
49 |
Type(TypeKind::EnumeratedType), |
50 |
m_enumSymbols(nullptr),
|
51 |
m_listOfEnumSymbols() |
52 |
{} |
53 |
EnumType(const EnumType& toCopy):
|
54 |
Type(toCopy), |
55 |
m_enumSymbols(toCopy.m_enumSymbols), |
56 |
m_listOfEnumSymbols(toCopy.m_listOfEnumSymbols) |
57 |
{} |
58 |
static EnumType* create() {return new EnumType(); } |
59 |
static EnumType* createCopy(const EnumType& toCopy) {return new EnumType(toCopy); } |
60 |
public:
|
61 |
friend class Ast; |
62 |
friend class Type; |
63 |
|
64 |
void init( TypeIdentifier* identifierRef, bool anonymousType, SymbolTable* symTabRef) { |
65 |
Type::init(identifierRef, anonymousType); |
66 |
m_enumSymbols = symTabRef; |
67 |
m_listOfEnumSymbols.clear(); |
68 |
for (auto& iter : *symTabRef){ |
69 |
m_listOfEnumSymbols.push_back((EnumIdentifier*)iter.second); |
70 |
} |
71 |
} |
72 |
|
73 |
SymbolTable* symbolTable() {return m_enumSymbols;};
|
74 |
std::deque<EnumIdentifier*>& listOfEnumSymbols() {return m_listOfEnumSymbols;};
|
75 |
|
76 |
void accept(IAstVisitor& visitor) override {visitor.visit(this);}; |
77 |
void addEnumSymbol(EnumIdentifier*) {throw new Base::NotImplementedException();} |
78 |
|
79 |
bool isSigned() override {return false;} |
80 |
|
81 |
uint32_t bitwidth() override {
|
82 |
return (std::uint32_t) std::floor(std::log2(m_listOfEnumSymbols.size())) + 1; |
83 |
} |
84 |
|
85 |
}; |
86 |
} |