[b87a5ed] | 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 | // |
---|
[148f7290] | 7 | // TypeData.h -- |
---|
[b87a5ed] | 8 | // |
---|
[fec3e9a] | 9 | // Author : Peter A. Buhr |
---|
[b87a5ed] | 10 | // Created On : Sat May 16 15:18:36 2015 |
---|
[4eb3a7c5] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Thu Feb 22 16:30:31 2024 |
---|
| 13 | // Update Count : 210 |
---|
[b87a5ed] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[c468150] | 18 | #include <iosfwd> // for ostream |
---|
| 19 | #include <list> // for list |
---|
| 20 | #include <string> // for string |
---|
[d180746] | 21 | |
---|
[c468150] | 22 | #include "AST/Type.hpp" // for Type |
---|
| 23 | #include "DeclarationNode.h" // for DeclarationNode |
---|
[51b7345] | 24 | |
---|
[c8ffe20b] | 25 | struct TypeData { |
---|
[f7e4db27] | 26 | enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic, |
---|
[66406f3] | 27 | SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Unknown }; |
---|
[b87a5ed] | 28 | |
---|
| 29 | struct Aggregate_t { |
---|
[bb7422a] | 30 | ast::AggregateDecl::Aggregate kind; |
---|
[5509ff4] | 31 | const std::string * name = nullptr; |
---|
[4eb3a7c5] | 32 | const std::string * parent = nullptr; |
---|
[5509ff4] | 33 | DeclarationNode * params = nullptr; |
---|
[fec3e9a] | 34 | ExpressionNode * actuals = nullptr; // holds actual parameters later applied to AggInst |
---|
[5509ff4] | 35 | DeclarationNode * fields = nullptr; |
---|
[4eb3a7c5] | 36 | std::vector<ast::ptr<ast::Attribute>> attributes; |
---|
[5d125e4] | 37 | bool body; |
---|
[3d7e53b] | 38 | bool anon; |
---|
[6ea87486] | 39 | bool tagged; |
---|
[b87a5ed] | 40 | }; |
---|
| 41 | |
---|
[bb7422a] | 42 | struct AggInst_t { |
---|
[5509ff4] | 43 | TypeData * aggregate = nullptr; |
---|
| 44 | ExpressionNode * params = nullptr; |
---|
[43c89a7] | 45 | bool hoistType; |
---|
[b87a5ed] | 46 | }; |
---|
| 47 | |
---|
| 48 | struct Array_t { |
---|
[5509ff4] | 49 | ExpressionNode * dimension = nullptr; |
---|
[b87a5ed] | 50 | bool isVarLen; |
---|
| 51 | bool isStatic; |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | struct Enumeration_t { |
---|
[5509ff4] | 55 | const std::string * name = nullptr; |
---|
| 56 | DeclarationNode * constants = nullptr; |
---|
[ca1a547] | 57 | bool body; |
---|
[3d7e53b] | 58 | bool anon; |
---|
[b0d9ff7] | 59 | bool typed; |
---|
[e4d7c1c] | 60 | EnumHiding hiding; |
---|
[b87a5ed] | 61 | }; |
---|
| 62 | |
---|
| 63 | struct Function_t { |
---|
[fec3e9a] | 64 | mutable DeclarationNode * params = nullptr; // mutables modified in buildKRFunction |
---|
| 65 | mutable DeclarationNode * idList = nullptr; // old-style |
---|
[5509ff4] | 66 | mutable DeclarationNode * oldDeclList = nullptr; |
---|
| 67 | StatementNode * body = nullptr; |
---|
[fec3e9a] | 68 | ExpressionNode * withExprs = nullptr; // expressions from function's with_clause |
---|
[b87a5ed] | 69 | }; |
---|
| 70 | |
---|
| 71 | struct Symbolic_t { |
---|
[5509ff4] | 72 | const std::string * name = nullptr; |
---|
[721f17a] | 73 | bool isTypedef; // false => TYPEGENname, true => TYPEDEFname |
---|
[5509ff4] | 74 | DeclarationNode * params = nullptr; |
---|
| 75 | ExpressionNode * actuals = nullptr; |
---|
| 76 | DeclarationNode * assertions = nullptr; |
---|
[b87a5ed] | 77 | }; |
---|
| 78 | |
---|
[f7e4db27] | 79 | struct Qualified_t { // qualified type S.T |
---|
[5509ff4] | 80 | TypeData * parent = nullptr; |
---|
| 81 | TypeData * child = nullptr; |
---|
[c194661] | 82 | }; |
---|
| 83 | |
---|
[0b0f1dd] | 84 | CodeLocation location; |
---|
| 85 | |
---|
[28307be] | 86 | Kind kind; |
---|
[413ad05] | 87 | TypeData * base; |
---|
[5b639ee] | 88 | DeclarationNode::BasicType basictype = DeclarationNode::NoBasicType; |
---|
| 89 | DeclarationNode::ComplexType complextype = DeclarationNode::NoComplexType; |
---|
| 90 | DeclarationNode::Signedness signedness = DeclarationNode::NoSignedness; |
---|
| 91 | DeclarationNode::Length length = DeclarationNode::NoLength; |
---|
[148f7290] | 92 | DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType; |
---|
[c3396e0] | 93 | |
---|
[bb7422a] | 94 | ast::CV::Qualifiers qualifiers; |
---|
[5509ff4] | 95 | DeclarationNode * forall = nullptr; |
---|
[413ad05] | 96 | |
---|
[c3396e0] | 97 | Aggregate_t aggregate; |
---|
| 98 | AggInst_t aggInst; |
---|
| 99 | Array_t array; |
---|
| 100 | Enumeration_t enumeration; |
---|
| 101 | Function_t function; |
---|
| 102 | Symbolic_t symbolic; |
---|
[c194661] | 103 | Qualified_t qualified; |
---|
[5509ff4] | 104 | DeclarationNode * tuple = nullptr; |
---|
| 105 | ExpressionNode * typeexpr = nullptr; |
---|
[b87a5ed] | 106 | |
---|
[413ad05] | 107 | TypeData( Kind k = Unknown ); |
---|
| 108 | ~TypeData(); |
---|
| 109 | void print( std::ostream &, int indent = 0 ) const; |
---|
| 110 | TypeData * clone() const; |
---|
[7de22b28] | 111 | |
---|
| 112 | const std::string * leafName() const; |
---|
[af60383] | 113 | |
---|
| 114 | TypeData * getLastBase(); |
---|
| 115 | void setLastBase( TypeData * ); |
---|
[51b7345] | 116 | }; |
---|
| 117 | |
---|
[6cef439] | 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 | |
---|
[af60383] | 132 | TypeData * addQualifiers( TypeData * ltype, TypeData * rtype ); |
---|
| 133 | TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & ); |
---|
[6cef439] | 134 | TypeData * addType( TypeData * ltype, TypeData * rtype ); |
---|
[af60383] | 135 | TypeData * cloneBaseType( TypeData * type, TypeData * other ); |
---|
| 136 | TypeData * makeNewBase( TypeData * type ); |
---|
| 137 | |
---|
[6cef439] | 138 | |
---|
[bb7422a] | 139 | ast::Type * typebuild( const TypeData * ); |
---|
[413ad05] | 140 | TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true ); |
---|
[bb7422a] | 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 * ); |
---|
[3a5131ed] | 160 | void buildKRFunction( const TypeData::Function_t & function ); |
---|
[413ad05] | 161 | |
---|
[6cef439] | 162 | static inline ast::Type * maybeMoveBuildType( TypeData * type ) { |
---|
| 163 | ast::Type * ret = type ? typebuild( type ) : nullptr; |
---|
| 164 | delete type; |
---|
| 165 | return ret; |
---|
| 166 | } |
---|
| 167 | |
---|
[b87a5ed] | 168 | // Local Variables: // |
---|
| 169 | // tab-width: 4 // |
---|
| 170 | // mode: c++ // |
---|
| 171 | // compile-command: "make install" // |
---|
| 172 | // End: // |
---|