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