[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 |
---|
[357390f] | 11 | // Last Modified By : Peter A. Buhr |
---|
[cfaa2873] | 12 | // Last Modified On : Sun Dec 15 16:52:37 2019 |
---|
| 13 | // Update Count : 49 |
---|
[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 | |
---|
[cfaa2873] | 26 | // GENERATED START, DO NOT EDIT |
---|
| 27 | // GENERATED BY BasicTypes-gen.cc |
---|
[357390f] | 28 | const char * BasicType::typeNames[] = { |
---|
[cdcddfe1] | 29 | "_Bool", |
---|
| 30 | "char", |
---|
| 31 | "signed char", |
---|
| 32 | "unsigned char", |
---|
| 33 | "signed short int", |
---|
| 34 | "unsigned short int", |
---|
| 35 | "signed int", |
---|
| 36 | "unsigned int", |
---|
| 37 | "signed long int", |
---|
| 38 | "unsigned long int", |
---|
| 39 | "signed long long int", |
---|
| 40 | "unsigned long long int", |
---|
| 41 | "__int128", |
---|
| 42 | "unsigned __int128", |
---|
| 43 | "_Float16", |
---|
| 44 | "_Float16 _Complex", |
---|
| 45 | "_Float32", |
---|
| 46 | "_Float32 _Complex", |
---|
| 47 | "float", |
---|
| 48 | "float _Complex", |
---|
| 49 | "_Float32x", |
---|
| 50 | "_Float32x _Complex", |
---|
| 51 | "_Float64", |
---|
| 52 | "_Float64 _Complex", |
---|
| 53 | "double", |
---|
| 54 | "double _Complex", |
---|
| 55 | "_Float64x", |
---|
| 56 | "_Float64x _Complex", |
---|
| 57 | "__float80", |
---|
| 58 | "_Float128", |
---|
| 59 | "_Float128 _Complex", |
---|
| 60 | "__float128", |
---|
| 61 | "long double", |
---|
| 62 | "long double _Complex", |
---|
| 63 | "_Float128x", |
---|
| 64 | "_Float128x _Complex", |
---|
[17cd4eb] | 65 | }; |
---|
[cfaa2873] | 66 | // GENERATED END |
---|
[51b7345] | 67 | |
---|
[c0aa336] | 68 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
[51b7345] | 69 | |
---|
[64ac636] | 70 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
[a08ba92] | 71 | cloneAll( other.forall, forall ); |
---|
[c0aa336] | 72 | cloneAll( other.attributes, attributes ); |
---|
[51b7345] | 73 | } |
---|
| 74 | |
---|
[17cd4eb] | 75 | Type::~Type() { |
---|
[a08ba92] | 76 | deleteAll( forall ); |
---|
[c0aa336] | 77 | deleteAll( attributes ); |
---|
[51b7345] | 78 | } |
---|
| 79 | |
---|
[68fe077a] | 80 | // These must remain in the same order as the corresponding bit fields. |
---|
[999c700] | 81 | const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; |
---|
[615a096] | 82 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
[b4f8808] | 83 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" }; |
---|
[0dd3a2f] | 84 | |
---|
[0698aa1] | 85 | Type * Type::stripDeclarator() { |
---|
[de9285f] | 86 | Type * type, * at; |
---|
| 87 | for ( type = this; (at = InitTweak::getPointerBase( type )); type = at ); |
---|
[6f95000] | 88 | return type; |
---|
| 89 | } |
---|
[0dd3a2f] | 90 | |
---|
[0698aa1] | 91 | Type * Type::stripReferences() { |
---|
[de9285f] | 92 | Type * type; |
---|
| 93 | ReferenceType * ref; |
---|
[50377a4] | 94 | for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base ); |
---|
[0698aa1] | 95 | return type; |
---|
| 96 | } |
---|
| 97 | |
---|
[85dac33] | 98 | const Type * Type::stripReferences() const { |
---|
| 99 | const Type * type; |
---|
| 100 | const ReferenceType * ref; |
---|
| 101 | for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base ); |
---|
| 102 | return type; |
---|
| 103 | } |
---|
| 104 | |
---|
[e6cee92] | 105 | int Type::referenceDepth() const { return 0; } |
---|
| 106 | |
---|
[9bfc9da] | 107 | TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } |
---|
| 108 | |
---|
[357390f] | 109 | void Type::print( std::ostream & os, Indenter indent ) const { |
---|
[f1b1e4c] | 110 | if ( ! forall.empty() ) { |
---|
| 111 | os << "forall" << std::endl; |
---|
[50377a4] | 112 | printAll( forall, os, indent+1 ); |
---|
| 113 | os << ++indent; |
---|
[f1b1e4c] | 114 | } // if |
---|
[c0aa336] | 115 | |
---|
| 116 | if ( ! attributes.empty() ) { |
---|
[50377a4] | 117 | os << "with attributes" << endl; |
---|
| 118 | printAll( attributes, os, indent+1 ); |
---|
[c0aa336] | 119 | } // if |
---|
[64ac636] | 120 | |
---|
[d6d747d] | 121 | tq.print( os ); |
---|
[f1b1e4c] | 122 | } |
---|
| 123 | |
---|
[c5d7701] | 124 | |
---|
[c194661] | 125 | QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) { |
---|
[c5d7701] | 126 | } |
---|
| 127 | |
---|
[c194661] | 128 | QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) { |
---|
[c5d7701] | 129 | } |
---|
| 130 | |
---|
| 131 | QualifiedType::~QualifiedType() { |
---|
[c194661] | 132 | delete parent; |
---|
| 133 | delete child; |
---|
[c5d7701] | 134 | } |
---|
| 135 | |
---|
| 136 | void QualifiedType::print( std::ostream & os, Indenter indent ) const { |
---|
[07ec1a2] | 137 | os << "Qualified Type:" << endl; |
---|
[c194661] | 138 | os << indent+1; |
---|
| 139 | parent->print( os, indent+1 ); |
---|
| 140 | os << endl << indent+1; |
---|
| 141 | child->print( os, indent+1 ); |
---|
| 142 | os << endl; |
---|
[c5d7701] | 143 | Type::print( os, indent+1 ); |
---|
| 144 | } |
---|
| 145 | |
---|
[47498bd] | 146 | GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {} |
---|
| 147 | |
---|
[0b3b2ae] | 148 | void GlobalScopeType::print( std::ostream & os, Indenter ) const { |
---|
[47498bd] | 149 | os << "Global Scope Type" << endl; |
---|
| 150 | } |
---|
| 151 | |
---|
[c5d7701] | 152 | |
---|
[65cdc1e] | 153 | // Empty Variable declarations: |
---|
| 154 | const Type::FuncSpecifiers noFuncSpecifiers; |
---|
| 155 | const Type::StorageClasses noStorageClasses; |
---|
| 156 | const Type::Qualifiers noQualifiers; |
---|
| 157 | |
---|
[cd6a6ff] | 158 | bool isUnboundType(const Type * type) { |
---|
| 159 | if (auto typeInst = dynamic_cast<const TypeInstType *>(type)) { |
---|
| 160 | // xxx - look for a type name produced by renameTyVars. |
---|
| 161 | |
---|
| 162 | // TODO: once TypeInstType representation is updated, it should properly check |
---|
| 163 | // if the context id is filled. this is a temporary hack for now |
---|
| 164 | return isUnboundType(typeInst->name); |
---|
| 165 | } |
---|
| 166 | return false; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | bool isUnboundType(const std::string & tname) { |
---|
| 170 | // xxx - look for a type name produced by renameTyVars. |
---|
| 171 | |
---|
| 172 | // TODO: once TypeInstType representation is updated, it should properly check |
---|
| 173 | // if the context id is filled. this is a temporary hack for now |
---|
| 174 | if (std::count(tname.begin(), tname.end(), '_') >= 3) { |
---|
| 175 | return true; |
---|
| 176 | } |
---|
| 177 | return false; |
---|
| 178 | } |
---|
| 179 | |
---|
[0dd3a2f] | 180 | // Local Variables: // |
---|
| 181 | // tab-width: 4 // |
---|
| 182 | // mode: c++ // |
---|
| 183 | // compile-command: "make install" // |
---|
| 184 | // End: // |
---|