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