[0dd3a2f] | 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 | // |
---|
[f1b1e4c] | 7 | // Type.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[de9285f] | 11 | // Last Modified By : Peter A. Buhr |
---|
[cdcddfe1] | 12 | // Last Modified On : Thu Jan 31 21:54:16 2019 |
---|
| 13 | // Update Count : 43 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | #include "Type.h" |
---|
[0dd3a2f] | 16 | |
---|
[9bfc9da] | 17 | #include "Attribute.h" // for Attribute |
---|
| 18 | #include "Common/utility.h" // for cloneAll, deleteAll, printAll |
---|
| 19 | #include "InitTweak/InitTweak.h" // for getPointerBase |
---|
| 20 | #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode |
---|
| 21 | #include "SynTree/Declaration.h" // for TypeDecl |
---|
| 22 | #include "SynTree/TypeSubstitution.h" // for TypeSubstitution |
---|
[51b7345] | 23 | |
---|
[c0aa336] | 24 | using namespace std; |
---|
| 25 | |
---|
[4ee3b0c1] | 26 | const char *BasicType::typeNames[] = { |
---|
[cdcddfe1] | 27 | #if 0 |
---|
[a08ba92] | 28 | "_Bool", |
---|
| 29 | "char", |
---|
[de9285f] | 30 | "signed char", |
---|
[a08ba92] | 31 | "unsigned char", |
---|
[de9285f] | 32 | "signed short int", |
---|
| 33 | "unsigned short int", |
---|
| 34 | "signed int", |
---|
[a08ba92] | 35 | "unsigned int", |
---|
[de9285f] | 36 | "signed long int", |
---|
| 37 | "unsigned long int", |
---|
| 38 | "signed long long int", |
---|
| 39 | "unsigned long long int", |
---|
[a08ba92] | 40 | "float", |
---|
| 41 | "double", |
---|
| 42 | "long double", |
---|
| 43 | "float _Complex", |
---|
| 44 | "double _Complex", |
---|
| 45 | "long double _Complex", |
---|
| 46 | "float _Imaginary", |
---|
| 47 | "double _Imaginary", |
---|
| 48 | "long double _Imaginary", |
---|
[201aeb9] | 49 | "__int128", |
---|
| 50 | "unsigned __int128", |
---|
[4ee3b0c1] | 51 | "__float80", |
---|
[cdcddfe1] | 52 | "__float128", |
---|
| 53 | "_Float16", |
---|
| 54 | "_Float32", |
---|
| 55 | "_Float32x", |
---|
| 56 | "_Float64", |
---|
| 57 | "_Float64x", |
---|
| 58 | "_Float128", |
---|
| 59 | "_Float128x", |
---|
| 60 | "_Float16 _Complex", |
---|
| 61 | "_Float32 _Complex", |
---|
| 62 | "_Float32x _Complex", |
---|
| 63 | "_Float64 _Complex", |
---|
| 64 | "_Float64x _Complex", |
---|
| 65 | "_Float128 _Complex", |
---|
| 66 | "_Float128x _Complex", |
---|
| 67 | #endif |
---|
| 68 | "_Bool", |
---|
| 69 | "char", |
---|
| 70 | "signed char", |
---|
| 71 | "unsigned char", |
---|
| 72 | "signed short int", |
---|
| 73 | "unsigned short int", |
---|
| 74 | "signed int", |
---|
| 75 | "unsigned int", |
---|
| 76 | "signed long int", |
---|
| 77 | "unsigned long int", |
---|
| 78 | "signed long long int", |
---|
| 79 | "unsigned long long int", |
---|
| 80 | "__int128", |
---|
| 81 | "unsigned __int128", |
---|
| 82 | "_Float16", |
---|
| 83 | "_Float16 _Complex", |
---|
| 84 | "_Float32", |
---|
| 85 | "_Float32 _Complex", |
---|
| 86 | "float", |
---|
| 87 | "float _Complex", |
---|
| 88 | //"float _Imaginary", |
---|
| 89 | "_Float32x", |
---|
| 90 | "_Float32x _Complex", |
---|
| 91 | "_Float64", |
---|
| 92 | "_Float64 _Complex", |
---|
| 93 | "double", |
---|
| 94 | "double _Complex", |
---|
| 95 | //"double _Imaginary", |
---|
| 96 | "_Float64x", |
---|
| 97 | "_Float64x _Complex", |
---|
| 98 | "__float80", |
---|
| 99 | "_Float128", |
---|
| 100 | "_Float128 _Complex", |
---|
| 101 | "__float128", |
---|
| 102 | "long double", |
---|
| 103 | "long double _Complex", |
---|
| 104 | //"long double _Imaginary", |
---|
| 105 | "_Float128x", |
---|
| 106 | "_Float128x _Complex", |
---|
[17cd4eb] | 107 | }; |
---|
[4ee3b0c1] | 108 | static_assert( |
---|
| 109 | sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES, |
---|
| 110 | "Each basic type name should have a corresponding kind enum value" |
---|
| 111 | ); |
---|
[51b7345] | 112 | |
---|
[c0aa336] | 113 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
[51b7345] | 114 | |
---|
[64ac636] | 115 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
[a08ba92] | 116 | cloneAll( other.forall, forall ); |
---|
[c0aa336] | 117 | cloneAll( other.attributes, attributes ); |
---|
[51b7345] | 118 | } |
---|
| 119 | |
---|
[17cd4eb] | 120 | Type::~Type() { |
---|
[a08ba92] | 121 | deleteAll( forall ); |
---|
[c0aa336] | 122 | deleteAll( attributes ); |
---|
[51b7345] | 123 | } |
---|
| 124 | |
---|
[68fe077a] | 125 | // These must remain in the same order as the corresponding bit fields. |
---|
[999c700] | 126 | const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; |
---|
[615a096] | 127 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
| 128 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" }; |
---|
[0dd3a2f] | 129 | |
---|
[0698aa1] | 130 | Type * Type::stripDeclarator() { |
---|
[de9285f] | 131 | Type * type, * at; |
---|
| 132 | for ( type = this; (at = InitTweak::getPointerBase( type )); type = at ); |
---|
[6f95000] | 133 | return type; |
---|
| 134 | } |
---|
[0dd3a2f] | 135 | |
---|
[0698aa1] | 136 | Type * Type::stripReferences() { |
---|
[de9285f] | 137 | Type * type; |
---|
| 138 | ReferenceType * ref; |
---|
[50377a4] | 139 | for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base ); |
---|
[0698aa1] | 140 | return type; |
---|
| 141 | } |
---|
| 142 | |
---|
[e6cee92] | 143 | int Type::referenceDepth() const { return 0; } |
---|
| 144 | |
---|
[9bfc9da] | 145 | TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } |
---|
| 146 | |
---|
[50377a4] | 147 | void Type::print( std::ostream &os, Indenter indent ) const { |
---|
[f1b1e4c] | 148 | if ( ! forall.empty() ) { |
---|
| 149 | os << "forall" << std::endl; |
---|
[50377a4] | 150 | printAll( forall, os, indent+1 ); |
---|
| 151 | os << ++indent; |
---|
[f1b1e4c] | 152 | } // if |
---|
[c0aa336] | 153 | |
---|
| 154 | if ( ! attributes.empty() ) { |
---|
[50377a4] | 155 | os << "with attributes" << endl; |
---|
| 156 | printAll( attributes, os, indent+1 ); |
---|
[c0aa336] | 157 | } // if |
---|
[64ac636] | 158 | |
---|
[d6d747d] | 159 | tq.print( os ); |
---|
[f1b1e4c] | 160 | } |
---|
| 161 | |
---|
[c5d7701] | 162 | |
---|
[c194661] | 163 | QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) { |
---|
[c5d7701] | 164 | } |
---|
| 165 | |
---|
[c194661] | 166 | QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) { |
---|
[c5d7701] | 167 | } |
---|
| 168 | |
---|
| 169 | QualifiedType::~QualifiedType() { |
---|
[c194661] | 170 | delete parent; |
---|
| 171 | delete child; |
---|
[c5d7701] | 172 | } |
---|
| 173 | |
---|
| 174 | void QualifiedType::print( std::ostream & os, Indenter indent ) const { |
---|
[07ec1a2] | 175 | os << "Qualified Type:" << endl; |
---|
[c194661] | 176 | os << indent+1; |
---|
| 177 | parent->print( os, indent+1 ); |
---|
| 178 | os << endl << indent+1; |
---|
| 179 | child->print( os, indent+1 ); |
---|
| 180 | os << endl; |
---|
[c5d7701] | 181 | Type::print( os, indent+1 ); |
---|
| 182 | } |
---|
| 183 | |
---|
[47498bd] | 184 | GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {} |
---|
| 185 | |
---|
[0b3b2ae] | 186 | void GlobalScopeType::print( std::ostream & os, Indenter ) const { |
---|
[47498bd] | 187 | os << "Global Scope Type" << endl; |
---|
| 188 | } |
---|
| 189 | |
---|
[c5d7701] | 190 | |
---|
[65cdc1e] | 191 | // Empty Variable declarations: |
---|
| 192 | const Type::FuncSpecifiers noFuncSpecifiers; |
---|
| 193 | const Type::StorageClasses noStorageClasses; |
---|
| 194 | const Type::Qualifiers noQualifiers; |
---|
| 195 | |
---|
[0dd3a2f] | 196 | // Local Variables: // |
---|
| 197 | // tab-width: 4 // |
---|
| 198 | // mode: c++ // |
---|
| 199 | // compile-command: "make install" // |
---|
| 200 | // End: // |
---|