source: src/Parser/TypeData.h@ 9f4af04

Last change on this file since 9f4af04 was 6cef439, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Return 'TypeData *' from some parse rules. Moved TypeData construction over to that file.

  • Property mode set to 100644
File size: 6.0 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 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
119TypeData * build_type_qualifier( ast::CV::Qualifiers );
120TypeData * build_basic_type( DeclarationNode::BasicType );
121TypeData * build_complex_type( DeclarationNode::ComplexType );
122TypeData * build_signedness( DeclarationNode::Signedness );
123TypeData * build_builtin_type( DeclarationNode::BuiltinType );
124TypeData * build_length( DeclarationNode::Length );
125TypeData * build_forall( DeclarationNode * );
126TypeData * build_global_scope();
127TypeData * build_qualified_type( TypeData *, TypeData * );
128TypeData * build_typedef( const std::string * name );
129TypeData * build_type_gen( const std::string * name, ExpressionNode * params );
130TypeData * build_vtable_type( TypeData * );
131
132TypeData * addQualifiers( TypeData * ltype, TypeData * rtype );
133TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & );
134TypeData * addType( TypeData * ltype, TypeData * rtype );
135TypeData * cloneBaseType( TypeData * type, TypeData * other );
136TypeData * makeNewBase( TypeData * type );
137
138
139ast::Type * typebuild( const TypeData * );
140TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
141ast::CV::Qualifiers buildQualifiers( const TypeData * td );
142ast::Type * buildBasicType( const TypeData * );
143ast::PointerType * buildPointer( const TypeData * );
144ast::ArrayType * buildArray( const TypeData * );
145ast::ReferenceType * buildReference( const TypeData * );
146ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
147ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
148ast::BaseInstType * buildAggInst( const TypeData * );
149ast::TypeDecl * buildVariable( const TypeData * );
150ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
151ast::TypeInstType * buildSymbolicInst( const TypeData * );
152ast::TupleType * buildTuple( const TypeData * );
153ast::TypeofType * buildTypeof( const TypeData * );
154ast::VTableType * buildVtable( const TypeData * );
155ast::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>>() );
159ast::FunctionType * buildFunctionType( const TypeData * );
160void buildKRFunction( const TypeData::Function_t & function );
161
162static 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: //
Note: See TracBrowser for help on using the repository browser.