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