1 | //
|
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
3 | //
|
---|
4 | // The contents of this file are covered under the licence agreement in the
|
---|
5 | // file "LICENCE" distributed with Cforall.
|
---|
6 | //
|
---|
7 | // TypeData.h --
|
---|
8 | //
|
---|
9 | // Author : Peter A. Buhr
|
---|
10 | // Created On : Sat May 16 15:18:36 2015
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Thu Feb 22 16:30:31 2024
|
---|
13 | // Update Count : 210
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include <iosfwd> // for ostream
|
---|
19 | #include <list> // for list
|
---|
20 | #include <string> // for string
|
---|
21 |
|
---|
22 | #include "AST/Type.hpp" // for Type
|
---|
23 | #include "DeclarationNode.h" // for DeclarationNode
|
---|
24 |
|
---|
25 | struct TypeData {
|
---|
26 | // Type flags used in this type, and there names (harmonize with implementation).
|
---|
27 | enum BasicType {
|
---|
28 | Void, Bool, Char, Int, Int128,
|
---|
29 | Float, Double, LongDouble, uuFloat80, uuFloat128,
|
---|
30 | uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x,
|
---|
31 | NoBasicType
|
---|
32 | };
|
---|
33 | static const char * basicTypeNames[];
|
---|
34 | enum ComplexType { Complex, NoComplexType, Imaginary };
|
---|
35 | // Imaginary unsupported => parse, but make invisible and print error message
|
---|
36 | static const char * complexTypeNames[];
|
---|
37 | enum Signedness { Signed, Unsigned, NoSignedness };
|
---|
38 | static const char * signednessNames[];
|
---|
39 | enum Length { Short, Long, LongLong, NoLength };
|
---|
40 | static const char * lengthNames[];
|
---|
41 | enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType };
|
---|
42 | static const char * builtinTypeNames[];
|
---|
43 |
|
---|
44 | enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, EnumConstant, Symbolic,
|
---|
45 | SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Unknown };
|
---|
46 |
|
---|
47 | struct Aggregate_t {
|
---|
48 | ast::AggregateDecl::Aggregate kind;
|
---|
49 | const std::string * name = nullptr;
|
---|
50 | // Polymorphics parameters. (Polymorphic types only.)
|
---|
51 | DeclarationNode * params = nullptr;
|
---|
52 | // Arguments later applied to AggInst. (Polymorphic types only.)
|
---|
53 | ExpressionNode * actuals = nullptr;
|
---|
54 | // Only set if body is true. (Constants for enumerations.)
|
---|
55 | DeclarationNode * fields = nullptr;
|
---|
56 | std::vector<ast::ptr<ast::Attribute>> attributes;
|
---|
57 | // Is this a declaration with a body (may have fields)?
|
---|
58 | bool body;
|
---|
59 | // Is this type anonymous? (Name can still be set to generated name.)
|
---|
60 | bool anon;
|
---|
61 | // Is this a typed enumeration? Type may be stored in base.
|
---|
62 | bool typed;
|
---|
63 | EnumHiding hiding;
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct AggInst_t {
|
---|
67 | TypeData * aggregate = nullptr;
|
---|
68 | ExpressionNode * params = nullptr;
|
---|
69 | bool hoistType;
|
---|
70 | };
|
---|
71 |
|
---|
72 | struct Array_t {
|
---|
73 | ExpressionNode * dimension = nullptr;
|
---|
74 | bool isVarLen;
|
---|
75 | bool isStatic;
|
---|
76 | };
|
---|
77 |
|
---|
78 | struct Function_t {
|
---|
79 | mutable DeclarationNode * params = nullptr; // mutables modified in buildKRFunction
|
---|
80 | mutable DeclarationNode * idList = nullptr; // old-style
|
---|
81 | mutable DeclarationNode * oldDeclList = nullptr;
|
---|
82 | StatementNode * body = nullptr;
|
---|
83 | ExpressionNode * withExprs = nullptr; // expressions from function's with_clause
|
---|
84 | };
|
---|
85 |
|
---|
86 | struct Symbolic_t {
|
---|
87 | const std::string * name = nullptr;
|
---|
88 | bool isTypedef; // false => TYPEGENname, true => TYPEDEFname
|
---|
89 | DeclarationNode * params = nullptr;
|
---|
90 | ExpressionNode * actuals = nullptr;
|
---|
91 | DeclarationNode * assertions = nullptr;
|
---|
92 | };
|
---|
93 |
|
---|
94 | struct Qualified_t { // qualified type S.T
|
---|
95 | TypeData * parent = nullptr;
|
---|
96 | TypeData * child = nullptr;
|
---|
97 | };
|
---|
98 |
|
---|
99 | CodeLocation location;
|
---|
100 |
|
---|
101 | Kind kind;
|
---|
102 | TypeData * base;
|
---|
103 | BasicType basictype = NoBasicType;
|
---|
104 | ComplexType complextype = NoComplexType;
|
---|
105 | Signedness signedness = NoSignedness;
|
---|
106 | Length length = NoLength;
|
---|
107 | BuiltinType builtintype = NoBuiltinType;
|
---|
108 |
|
---|
109 | ast::CV::Qualifiers qualifiers;
|
---|
110 | DeclarationNode * forall = nullptr;
|
---|
111 |
|
---|
112 | Aggregate_t aggregate;
|
---|
113 | AggInst_t aggInst;
|
---|
114 | Array_t array;
|
---|
115 | Function_t function;
|
---|
116 | Symbolic_t symbolic;
|
---|
117 | Qualified_t qualified;
|
---|
118 | DeclarationNode * tuple = nullptr;
|
---|
119 | ExpressionNode * typeexpr = nullptr;
|
---|
120 |
|
---|
121 | TypeData( Kind k = Unknown );
|
---|
122 | ~TypeData();
|
---|
123 | void print( std::ostream &, int indent = 0 ) const;
|
---|
124 | TypeData * clone() const;
|
---|
125 |
|
---|
126 | const std::string * leafName() const;
|
---|
127 |
|
---|
128 | TypeData * getLastBase();
|
---|
129 | void setLastBase( TypeData * );
|
---|
130 | };
|
---|
131 |
|
---|
132 |
|
---|
133 | TypeData * build_type_qualifier( ast::CV::Qualifiers );
|
---|
134 | TypeData * build_basic_type( TypeData::BasicType );
|
---|
135 | TypeData * build_complex_type( TypeData::ComplexType );
|
---|
136 | TypeData * build_signedness( TypeData::Signedness );
|
---|
137 | TypeData * build_builtin_type( TypeData::BuiltinType );
|
---|
138 | TypeData * build_length( TypeData::Length );
|
---|
139 | TypeData * build_forall( DeclarationNode * );
|
---|
140 | TypeData * build_global_scope();
|
---|
141 | TypeData * build_qualified_type( TypeData *, TypeData * );
|
---|
142 | TypeData * build_typedef( const std::string * name );
|
---|
143 | TypeData * build_type_gen( const std::string * name, ExpressionNode * params );
|
---|
144 | TypeData * build_vtable_type( TypeData * );
|
---|
145 |
|
---|
146 | TypeData * addQualifiers( TypeData * ltype, TypeData * rtype );
|
---|
147 | TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & );
|
---|
148 | TypeData * addType( TypeData * ltype, TypeData * rtype );
|
---|
149 | TypeData * cloneBaseType( TypeData * type, TypeData * other );
|
---|
150 | TypeData * makeNewBase( TypeData * type );
|
---|
151 |
|
---|
152 |
|
---|
153 | ast::Type * typebuild( const TypeData * );
|
---|
154 | TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
|
---|
155 | ast::CV::Qualifiers buildQualifiers( const TypeData * td );
|
---|
156 | ast::Type * buildBasicType( const TypeData * );
|
---|
157 | ast::PointerType * buildPointer( const TypeData * );
|
---|
158 | ast::ArrayType * buildArray( const TypeData * );
|
---|
159 | ast::ReferenceType * buildReference( const TypeData * );
|
---|
160 | ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
|
---|
161 | ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
|
---|
162 | ast::BaseInstType * buildAggInst( const TypeData * );
|
---|
163 | ast::TypeDecl * buildVariable( const TypeData * );
|
---|
164 | ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
|
---|
165 | ast::TypeInstType * buildSymbolicInst( const TypeData * );
|
---|
166 | ast::TupleType * buildTuple( const TypeData * );
|
---|
167 | ast::TypeofType * buildTypeof( const TypeData * );
|
---|
168 | ast::VTableType * buildVtable( const TypeData * );
|
---|
169 | ast::Decl * buildDecl(
|
---|
170 | const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *,
|
---|
171 | ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName,
|
---|
172 | ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() );
|
---|
173 | ast::FunctionType * buildFunctionType( const TypeData * );
|
---|
174 | void buildKRFunction( const TypeData::Function_t & function );
|
---|
175 |
|
---|
176 | static inline ast::Type * maybeMoveBuildType( TypeData * type ) {
|
---|
177 | ast::Type * ret = type ? typebuild( type ) : nullptr;
|
---|
178 | delete type;
|
---|
179 | return ret;
|
---|
180 | }
|
---|
181 |
|
---|
182 | // Local Variables: //
|
---|
183 | // tab-width: 4 //
|
---|
184 | // mode: c++ //
|
---|
185 | // compile-command: "make install" //
|
---|
186 | // End: //
|
---|