[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 |
---|
[c0aa336] | 11 | // Last Modified By : Peter A. Buhr |
---|
[615a096] | 12 | // Last Modified On : Fri Mar 17 08:42:47 2017 |
---|
| 13 | // Update Count : 28 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "SynTree.h" |
---|
| 17 | #include "Visitor.h" |
---|
| 18 | #include "Type.h" |
---|
| 19 | #include "Declaration.h" |
---|
[c0aa336] | 20 | #include "Attribute.h" |
---|
[6f95000] | 21 | #include "InitTweak/InitTweak.h" |
---|
[d3b7937] | 22 | #include "Common/utility.h" |
---|
[51b7345] | 23 | |
---|
[c0aa336] | 24 | using namespace std; |
---|
| 25 | |
---|
[17cd4eb] | 26 | const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = { |
---|
[a08ba92] | 27 | "_Bool", |
---|
| 28 | "char", |
---|
| 29 | "char", |
---|
| 30 | "unsigned char", |
---|
| 31 | "short", |
---|
| 32 | "short unsigned", |
---|
| 33 | "int", |
---|
| 34 | "unsigned int", |
---|
| 35 | "long int", |
---|
| 36 | "long unsigned int", |
---|
| 37 | "long long int", |
---|
| 38 | "long long unsigned int", |
---|
| 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", |
---|
[17cd4eb] | 48 | }; |
---|
[51b7345] | 49 | |
---|
[c0aa336] | 50 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
[51b7345] | 51 | |
---|
[64ac636] | 52 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
[a08ba92] | 53 | cloneAll( other.forall, forall ); |
---|
[c0aa336] | 54 | cloneAll( other.attributes, attributes ); |
---|
[51b7345] | 55 | } |
---|
| 56 | |
---|
[17cd4eb] | 57 | Type::~Type() { |
---|
[a08ba92] | 58 | deleteAll( forall ); |
---|
[c0aa336] | 59 | deleteAll( attributes ); |
---|
[51b7345] | 60 | } |
---|
| 61 | |
---|
[68fe077a] | 62 | // These must remain in the same order as the corresponding bit fields. |
---|
[615a096] | 63 | const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" }; |
---|
| 64 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
| 65 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" }; |
---|
[0dd3a2f] | 66 | |
---|
[6f95000] | 67 | Type *Type::stripDeclarator() { |
---|
| 68 | Type * type = this; |
---|
| 69 | while ( Type * at = InitTweak::getPointerBase( type ) ) { |
---|
| 70 | type = at; |
---|
| 71 | } |
---|
| 72 | return type; |
---|
| 73 | } |
---|
[0dd3a2f] | 74 | |
---|
[f1b1e4c] | 75 | void Type::print( std::ostream &os, int indent ) const { |
---|
| 76 | if ( ! forall.empty() ) { |
---|
| 77 | os << "forall" << std::endl; |
---|
| 78 | printAll( forall, os, indent + 4 ); |
---|
| 79 | os << std::string( indent+2, ' ' ); |
---|
| 80 | } // if |
---|
[c0aa336] | 81 | |
---|
| 82 | if ( ! attributes.empty() ) { |
---|
| 83 | os << endl << string( indent+2, ' ' ) << "with attributes" << endl; |
---|
| 84 | printAll( attributes, os, indent+4 ); |
---|
| 85 | } // if |
---|
[64ac636] | 86 | |
---|
[d6d747d] | 87 | tq.print( os ); |
---|
[f1b1e4c] | 88 | } |
---|
| 89 | |
---|
[3906301] | 90 | std::ostream & operator<<( std::ostream & out, const Type * type ) { |
---|
[8bf784a] | 91 | if ( type ) { |
---|
| 92 | type->print( out ); |
---|
| 93 | } else { |
---|
| 94 | out << "nullptr"; |
---|
[c0aa336] | 95 | } // if |
---|
[baf7fee] | 96 | return out; |
---|
| 97 | } |
---|
| 98 | |
---|
[0dd3a2f] | 99 | // Local Variables: // |
---|
| 100 | // tab-width: 4 // |
---|
| 101 | // mode: c++ // |
---|
| 102 | // compile-command: "make install" // |
---|
| 103 | // End: // |
---|