[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 |
---|
| 12 | // Last Modified On : Mon Sep 11 13:21:25 2017 |
---|
| 13 | // Update Count : 37 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | #include "Type.h" |
---|
[0dd3a2f] | 16 | |
---|
[ea6332d] | 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 |
---|
[be9288a] | 21 | #include "SynTree/Declaration.h" // for TypeDecl |
---|
[51b7345] | 22 | |
---|
[c0aa336] | 23 | using namespace std; |
---|
| 24 | |
---|
[17cd4eb] | 25 | const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = { |
---|
[a08ba92] | 26 | "_Bool", |
---|
| 27 | "char", |
---|
[de9285f] | 28 | "signed char", |
---|
[a08ba92] | 29 | "unsigned char", |
---|
[de9285f] | 30 | "signed short int", |
---|
| 31 | "unsigned short int", |
---|
| 32 | "signed int", |
---|
[a08ba92] | 33 | "unsigned int", |
---|
[de9285f] | 34 | "signed long int", |
---|
| 35 | "unsigned long int", |
---|
| 36 | "signed long long int", |
---|
| 37 | "unsigned long long int", |
---|
[a08ba92] | 38 | "float", |
---|
| 39 | "double", |
---|
| 40 | "long double", |
---|
| 41 | "float _Complex", |
---|
| 42 | "double _Complex", |
---|
| 43 | "long double _Complex", |
---|
| 44 | "float _Imaginary", |
---|
| 45 | "double _Imaginary", |
---|
| 46 | "long double _Imaginary", |
---|
[17cd4eb] | 47 | }; |
---|
[51b7345] | 48 | |
---|
[c0aa336] | 49 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
[51b7345] | 50 | |
---|
[64ac636] | 51 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
[a08ba92] | 52 | cloneAll( other.forall, forall ); |
---|
[c0aa336] | 53 | cloneAll( other.attributes, attributes ); |
---|
[51b7345] | 54 | } |
---|
| 55 | |
---|
[17cd4eb] | 56 | Type::~Type() { |
---|
[a08ba92] | 57 | deleteAll( forall ); |
---|
[c0aa336] | 58 | deleteAll( attributes ); |
---|
[51b7345] | 59 | } |
---|
| 60 | |
---|
[68fe077a] | 61 | // These must remain in the same order as the corresponding bit fields. |
---|
[615a096] | 62 | const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" }; |
---|
| 63 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
| 64 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" }; |
---|
[0dd3a2f] | 65 | |
---|
[0698aa1] | 66 | Type * Type::stripDeclarator() { |
---|
[de9285f] | 67 | Type * type, * at; |
---|
| 68 | for ( type = this; (at = InitTweak::getPointerBase( type )); type = at ); |
---|
[6f95000] | 69 | return type; |
---|
| 70 | } |
---|
[0dd3a2f] | 71 | |
---|
[0698aa1] | 72 | Type * Type::stripReferences() { |
---|
[de9285f] | 73 | Type * type; |
---|
| 74 | ReferenceType * ref; |
---|
| 75 | for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->get_base() ); |
---|
[0698aa1] | 76 | return type; |
---|
| 77 | } |
---|
| 78 | |
---|
[e6cee92] | 79 | int Type::referenceDepth() const { return 0; } |
---|
| 80 | |
---|
[f1b1e4c] | 81 | void Type::print( std::ostream &os, int indent ) const { |
---|
| 82 | if ( ! forall.empty() ) { |
---|
| 83 | os << "forall" << std::endl; |
---|
| 84 | printAll( forall, os, indent + 4 ); |
---|
| 85 | os << std::string( indent+2, ' ' ); |
---|
| 86 | } // if |
---|
[c0aa336] | 87 | |
---|
| 88 | if ( ! attributes.empty() ) { |
---|
| 89 | os << endl << string( indent+2, ' ' ) << "with attributes" << endl; |
---|
| 90 | printAll( attributes, os, indent+4 ); |
---|
| 91 | } // if |
---|
[64ac636] | 92 | |
---|
[d6d747d] | 93 | tq.print( os ); |
---|
[f1b1e4c] | 94 | } |
---|
| 95 | |
---|
[65cdc1e] | 96 | // Empty Variable declarations: |
---|
| 97 | const Type::FuncSpecifiers noFuncSpecifiers; |
---|
| 98 | const Type::StorageClasses noStorageClasses; |
---|
| 99 | const Type::Qualifiers noQualifiers; |
---|
| 100 | |
---|
[3906301] | 101 | std::ostream & operator<<( std::ostream & out, const Type * type ) { |
---|
[8bf784a] | 102 | if ( type ) { |
---|
| 103 | type->print( out ); |
---|
| 104 | } else { |
---|
| 105 | out << "nullptr"; |
---|
[c0aa336] | 106 | } // if |
---|
[baf7fee] | 107 | return out; |
---|
| 108 | } |
---|
| 109 | |
---|
[0dd3a2f] | 110 | // Local Variables: // |
---|
| 111 | // tab-width: 4 // |
---|
| 112 | // mode: c++ // |
---|
| 113 | // compile-command: "make install" // |
---|
| 114 | // End: // |
---|