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