1 | #ifndef TYPEDATA_H |
---|
2 | #define TYPEDATA_H |
---|
3 | |
---|
4 | #include <list> |
---|
5 | #include "ParseNode.h" |
---|
6 | #include "SynTree/SynTree.h" |
---|
7 | #include "SynTree/Type.h" |
---|
8 | #include "SynTree/Declaration.h" |
---|
9 | #include "SemanticError.h" |
---|
10 | #include "LinkageSpec.h" |
---|
11 | |
---|
12 | struct TypeData { |
---|
13 | enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, |
---|
14 | Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Attr } kind; |
---|
15 | |
---|
16 | TypeData( Kind k = Unknown ); |
---|
17 | ~TypeData(); |
---|
18 | void print( std::ostream &, int indent = 0 ) const; |
---|
19 | TypeData *clone() const; |
---|
20 | |
---|
21 | Type *build() const; |
---|
22 | FunctionType *buildFunction() const; |
---|
23 | |
---|
24 | TypeData *base; |
---|
25 | std::list< DeclarationNode::Qualifier > qualifiers; |
---|
26 | DeclarationNode *forall; |
---|
27 | |
---|
28 | struct Basic_t { |
---|
29 | std::list< DeclarationNode::BasicType > typeSpec; |
---|
30 | std::list< DeclarationNode::Modifier > modifiers; |
---|
31 | }; |
---|
32 | |
---|
33 | struct Aggregate_t { |
---|
34 | DeclarationNode::TyCon kind; |
---|
35 | std::string name; |
---|
36 | DeclarationNode *params; |
---|
37 | ExpressionNode *actuals; // holds actual parameters later applied to AggInst |
---|
38 | DeclarationNode *members; |
---|
39 | }; |
---|
40 | |
---|
41 | struct AggInst_t { |
---|
42 | TypeData *aggregate; |
---|
43 | ExpressionNode *params; |
---|
44 | }; |
---|
45 | |
---|
46 | struct Array_t { |
---|
47 | ExpressionNode *dimension; |
---|
48 | bool isVarLen; |
---|
49 | bool isStatic; |
---|
50 | }; |
---|
51 | |
---|
52 | struct Enumeration_t { |
---|
53 | std::string name; |
---|
54 | DeclarationNode *constants; |
---|
55 | }; |
---|
56 | |
---|
57 | struct Function_t { |
---|
58 | DeclarationNode *params; |
---|
59 | DeclarationNode *idList; // old-style |
---|
60 | DeclarationNode *oldDeclList; |
---|
61 | StatementNode *body; |
---|
62 | bool hasBody; |
---|
63 | bool newStyle; |
---|
64 | }; |
---|
65 | |
---|
66 | struct Symbolic_t { |
---|
67 | std::string name; |
---|
68 | bool isTypedef; |
---|
69 | DeclarationNode *params; |
---|
70 | ExpressionNode *actuals; |
---|
71 | DeclarationNode *assertions; |
---|
72 | }; |
---|
73 | |
---|
74 | struct Variable_t { |
---|
75 | DeclarationNode::TypeClass tyClass; |
---|
76 | std::string name; |
---|
77 | DeclarationNode *assertions; |
---|
78 | }; |
---|
79 | |
---|
80 | struct Tuple_t { |
---|
81 | DeclarationNode *members; |
---|
82 | }; |
---|
83 | |
---|
84 | struct Typeof_t { |
---|
85 | ExpressionNode *expr; |
---|
86 | }; |
---|
87 | |
---|
88 | struct Attr_t { |
---|
89 | std::string name; |
---|
90 | ExpressionNode *expr; |
---|
91 | DeclarationNode *type; |
---|
92 | }; |
---|
93 | |
---|
94 | union { |
---|
95 | Basic_t *basic; |
---|
96 | Aggregate_t *aggregate; |
---|
97 | AggInst_t *aggInst; |
---|
98 | Array_t *array; |
---|
99 | Enumeration_t *enumeration; |
---|
100 | Function_t *function; |
---|
101 | Symbolic_t *symbolic; |
---|
102 | Variable_t *variable; |
---|
103 | Tuple_t *tuple; |
---|
104 | Typeof_t *typeexpr; |
---|
105 | Attr_t *attr; |
---|
106 | }; |
---|
107 | |
---|
108 | TypeData *extractAggregate( bool toplevel = true ) const; |
---|
109 | // helper function for DeclNodeImpl::build |
---|
110 | Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const; |
---|
111 | // helper functions for build() |
---|
112 | Type::Qualifiers buildQualifiers() const; |
---|
113 | Type *buildBasicType() const; |
---|
114 | PointerType * buildPointer() const; |
---|
115 | ArrayType * buildArray() const; |
---|
116 | AggregateDecl * buildAggregate() const; |
---|
117 | ReferenceToType * buildAggInst() const; |
---|
118 | NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const; |
---|
119 | TypeDecl* buildVariable() const; |
---|
120 | EnumDecl* buildEnum() const; |
---|
121 | TypeInstType * buildSymbolicInst() const; |
---|
122 | TupleType * buildTuple() const; |
---|
123 | TypeofType * buildTypeof() const; |
---|
124 | AttrType * buildAttr() const; |
---|
125 | }; |
---|
126 | |
---|
127 | #endif // TYPEDATA_H |
---|