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