source: src/Parser/TypeData.h@ c041d29

Last change on this file since c041d29 was e048ece, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Moved the DeclarationNode enums over to TypeData where they are actually used.

  • Property mode set to 100644
File size: 6.6 KB
Line 
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
25struct 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, Enum, 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 const std::string * parent = nullptr;
51 DeclarationNode * params = nullptr;
52 ExpressionNode * actuals = nullptr; // holds actual parameters later applied to AggInst
53 DeclarationNode * fields = nullptr;
54 std::vector<ast::ptr<ast::Attribute>> attributes;
55 bool body;
56 bool anon;
57 bool tagged;
58 };
59
60 struct AggInst_t {
61 TypeData * aggregate = nullptr;
62 ExpressionNode * params = nullptr;
63 bool hoistType;
64 };
65
66 struct Array_t {
67 ExpressionNode * dimension = nullptr;
68 bool isVarLen;
69 bool isStatic;
70 };
71
72 struct Enumeration_t {
73 const std::string * name = nullptr;
74 DeclarationNode * constants = nullptr;
75 bool body;
76 bool anon;
77 bool typed;
78 EnumHiding hiding;
79 };
80
81 struct Function_t {
82 mutable DeclarationNode * params = nullptr; // mutables modified in buildKRFunction
83 mutable DeclarationNode * idList = nullptr; // old-style
84 mutable DeclarationNode * oldDeclList = nullptr;
85 StatementNode * body = nullptr;
86 ExpressionNode * withExprs = nullptr; // expressions from function's with_clause
87 };
88
89 struct Symbolic_t {
90 const std::string * name = nullptr;
91 bool isTypedef; // false => TYPEGENname, true => TYPEDEFname
92 DeclarationNode * params = nullptr;
93 ExpressionNode * actuals = nullptr;
94 DeclarationNode * assertions = nullptr;
95 };
96
97 struct Qualified_t { // qualified type S.T
98 TypeData * parent = nullptr;
99 TypeData * child = nullptr;
100 };
101
102 CodeLocation location;
103
104 Kind kind;
105 TypeData * base;
106 BasicType basictype = NoBasicType;
107 ComplexType complextype = NoComplexType;
108 Signedness signedness = NoSignedness;
109 Length length = NoLength;
110 BuiltinType builtintype = NoBuiltinType;
111
112 ast::CV::Qualifiers qualifiers;
113 DeclarationNode * forall = nullptr;
114
115 Aggregate_t aggregate;
116 AggInst_t aggInst;
117 Array_t array;
118 Enumeration_t enumeration;
119 Function_t function;
120 Symbolic_t symbolic;
121 Qualified_t qualified;
122 DeclarationNode * tuple = nullptr;
123 ExpressionNode * typeexpr = nullptr;
124
125 TypeData( Kind k = Unknown );
126 ~TypeData();
127 void print( std::ostream &, int indent = 0 ) const;
128 TypeData * clone() const;
129
130 const std::string * leafName() const;
131
132 TypeData * getLastBase();
133 void setLastBase( TypeData * );
134};
135
136
137TypeData * build_type_qualifier( ast::CV::Qualifiers );
138TypeData * build_basic_type( TypeData::BasicType );
139TypeData * build_complex_type( TypeData::ComplexType );
140TypeData * build_signedness( TypeData::Signedness );
141TypeData * build_builtin_type( TypeData::BuiltinType );
142TypeData * build_length( TypeData::Length );
143TypeData * build_forall( DeclarationNode * );
144TypeData * build_global_scope();
145TypeData * build_qualified_type( TypeData *, TypeData * );
146TypeData * build_typedef( const std::string * name );
147TypeData * build_type_gen( const std::string * name, ExpressionNode * params );
148TypeData * build_vtable_type( TypeData * );
149
150TypeData * addQualifiers( TypeData * ltype, TypeData * rtype );
151TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & );
152TypeData * addType( TypeData * ltype, TypeData * rtype );
153TypeData * cloneBaseType( TypeData * type, TypeData * other );
154TypeData * makeNewBase( TypeData * type );
155
156
157ast::Type * typebuild( const TypeData * );
158TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
159ast::CV::Qualifiers buildQualifiers( const TypeData * td );
160ast::Type * buildBasicType( const TypeData * );
161ast::PointerType * buildPointer( const TypeData * );
162ast::ArrayType * buildArray( const TypeData * );
163ast::ReferenceType * buildReference( const TypeData * );
164ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
165ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
166ast::BaseInstType * buildAggInst( const TypeData * );
167ast::TypeDecl * buildVariable( const TypeData * );
168ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
169ast::TypeInstType * buildSymbolicInst( const TypeData * );
170ast::TupleType * buildTuple( const TypeData * );
171ast::TypeofType * buildTypeof( const TypeData * );
172ast::VTableType * buildVtable( const TypeData * );
173ast::Decl * buildDecl(
174 const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *,
175 ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName,
176 ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() );
177ast::FunctionType * buildFunctionType( const TypeData * );
178void buildKRFunction( const TypeData::Function_t & function );
179
180static inline ast::Type * maybeMoveBuildType( TypeData * type ) {
181 ast::Type * ret = type ? typebuild( type ) : nullptr;
182 delete type;
183 return ret;
184}
185
186// Local Variables: //
187// tab-width: 4 //
188// mode: c++ //
189// compile-command: "make install" //
190// End: //
Note: See TracBrowser for help on using the repository browser.