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