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 | enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic, |
---|
27 | SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Unknown }; |
---|
28 | |
---|
29 | struct Aggregate_t { |
---|
30 | ast::AggregateDecl::Aggregate kind; |
---|
31 | const std::string * name = nullptr; |
---|
32 | const std::string * parent = nullptr; |
---|
33 | DeclarationNode * params = nullptr; |
---|
34 | ExpressionNode * actuals = nullptr; // holds actual parameters later applied to AggInst |
---|
35 | DeclarationNode * fields = nullptr; |
---|
36 | std::vector<ast::ptr<ast::Attribute>> attributes; |
---|
37 | bool body; |
---|
38 | bool anon; |
---|
39 | bool tagged; |
---|
40 | }; |
---|
41 | |
---|
42 | struct AggInst_t { |
---|
43 | TypeData * aggregate = nullptr; |
---|
44 | ExpressionNode * params = nullptr; |
---|
45 | bool hoistType; |
---|
46 | }; |
---|
47 | |
---|
48 | struct Array_t { |
---|
49 | ExpressionNode * dimension = nullptr; |
---|
50 | bool isVarLen; |
---|
51 | bool isStatic; |
---|
52 | }; |
---|
53 | |
---|
54 | struct Enumeration_t { |
---|
55 | const std::string * name = nullptr; |
---|
56 | DeclarationNode * constants = nullptr; |
---|
57 | bool body; |
---|
58 | bool anon; |
---|
59 | bool typed; |
---|
60 | EnumHiding hiding; |
---|
61 | }; |
---|
62 | |
---|
63 | struct Function_t { |
---|
64 | mutable DeclarationNode * params = nullptr; // mutables modified in buildKRFunction |
---|
65 | mutable DeclarationNode * idList = nullptr; // old-style |
---|
66 | mutable DeclarationNode * oldDeclList = nullptr; |
---|
67 | StatementNode * body = nullptr; |
---|
68 | ExpressionNode * withExprs = nullptr; // expressions from function's with_clause |
---|
69 | }; |
---|
70 | |
---|
71 | struct Symbolic_t { |
---|
72 | const std::string * name = nullptr; |
---|
73 | bool isTypedef; // false => TYPEGENname, true => TYPEDEFname |
---|
74 | DeclarationNode * params = nullptr; |
---|
75 | ExpressionNode * actuals = nullptr; |
---|
76 | DeclarationNode * assertions = nullptr; |
---|
77 | }; |
---|
78 | |
---|
79 | struct Qualified_t { // qualified type S.T |
---|
80 | TypeData * parent = nullptr; |
---|
81 | TypeData * child = nullptr; |
---|
82 | }; |
---|
83 | |
---|
84 | CodeLocation location; |
---|
85 | |
---|
86 | Kind kind; |
---|
87 | TypeData * base; |
---|
88 | DeclarationNode::BasicType basictype = DeclarationNode::NoBasicType; |
---|
89 | DeclarationNode::ComplexType complextype = DeclarationNode::NoComplexType; |
---|
90 | DeclarationNode::Signedness signedness = DeclarationNode::NoSignedness; |
---|
91 | DeclarationNode::Length length = DeclarationNode::NoLength; |
---|
92 | DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType; |
---|
93 | |
---|
94 | ast::CV::Qualifiers qualifiers; |
---|
95 | DeclarationNode * forall = nullptr; |
---|
96 | |
---|
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 | Qualified_t qualified; |
---|
104 | DeclarationNode * tuple = nullptr; |
---|
105 | ExpressionNode * typeexpr = nullptr; |
---|
106 | |
---|
107 | TypeData( Kind k = Unknown ); |
---|
108 | ~TypeData(); |
---|
109 | void print( std::ostream &, int indent = 0 ) const; |
---|
110 | TypeData * clone() const; |
---|
111 | |
---|
112 | const std::string * leafName() const; |
---|
113 | |
---|
114 | TypeData * getLastBase(); |
---|
115 | void setLastBase( TypeData * ); |
---|
116 | }; |
---|
117 | |
---|
118 | |
---|
119 | TypeData * build_type_qualifier( ast::CV::Qualifiers ); |
---|
120 | TypeData * build_basic_type( DeclarationNode::BasicType ); |
---|
121 | TypeData * build_complex_type( DeclarationNode::ComplexType ); |
---|
122 | TypeData * build_signedness( DeclarationNode::Signedness ); |
---|
123 | TypeData * build_builtin_type( DeclarationNode::BuiltinType ); |
---|
124 | TypeData * build_length( DeclarationNode::Length ); |
---|
125 | TypeData * build_forall( DeclarationNode * ); |
---|
126 | TypeData * build_global_scope(); |
---|
127 | TypeData * build_qualified_type( TypeData *, TypeData * ); |
---|
128 | TypeData * build_typedef( const std::string * name ); |
---|
129 | TypeData * build_type_gen( const std::string * name, ExpressionNode * params ); |
---|
130 | TypeData * build_vtable_type( TypeData * ); |
---|
131 | |
---|
132 | TypeData * addQualifiers( TypeData * ltype, TypeData * rtype ); |
---|
133 | TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & ); |
---|
134 | TypeData * addType( TypeData * ltype, TypeData * rtype ); |
---|
135 | TypeData * cloneBaseType( TypeData * type, TypeData * other ); |
---|
136 | TypeData * makeNewBase( TypeData * type ); |
---|
137 | |
---|
138 | |
---|
139 | ast::Type * typebuild( const TypeData * ); |
---|
140 | TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true ); |
---|
141 | ast::CV::Qualifiers buildQualifiers( const TypeData * td ); |
---|
142 | ast::Type * buildBasicType( const TypeData * ); |
---|
143 | ast::PointerType * buildPointer( const TypeData * ); |
---|
144 | ast::ArrayType * buildArray( const TypeData * ); |
---|
145 | ast::ReferenceType * buildReference( const TypeData * ); |
---|
146 | ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> ); |
---|
147 | ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage ); |
---|
148 | ast::BaseInstType * buildAggInst( const TypeData * ); |
---|
149 | ast::TypeDecl * buildVariable( const TypeData * ); |
---|
150 | ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec ); |
---|
151 | ast::TypeInstType * buildSymbolicInst( const TypeData * ); |
---|
152 | ast::TupleType * buildTuple( const TypeData * ); |
---|
153 | ast::TypeofType * buildTypeof( const TypeData * ); |
---|
154 | ast::VTableType * buildVtable( const TypeData * ); |
---|
155 | ast::Decl * buildDecl( |
---|
156 | const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *, |
---|
157 | ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName, |
---|
158 | ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() ); |
---|
159 | ast::FunctionType * buildFunctionType( const TypeData * ); |
---|
160 | void buildKRFunction( const TypeData::Function_t & function ); |
---|
161 | |
---|
162 | static inline ast::Type * maybeMoveBuildType( TypeData * type ) { |
---|
163 | ast::Type * ret = type ? typebuild( type ) : nullptr; |
---|
164 | delete type; |
---|
165 | return ret; |
---|
166 | } |
---|
167 | |
---|
168 | // Local Variables: // |
---|
169 | // tab-width: 4 // |
---|
170 | // mode: c++ // |
---|
171 | // compile-command: "make install" // |
---|
172 | // End: // |
---|