| 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 | //
 | 
|---|
| 7 | // Type.cc --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Mon Sep 25 15:16:32 2017
 | 
|---|
| 13 | // Update Count     : 38
 | 
|---|
| 14 | //
 | 
|---|
| 15 | #include "Type.h"
 | 
|---|
| 16 | 
 | 
|---|
| 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 | 
 | 
|---|
| 23 | using namespace std;
 | 
|---|
| 24 | 
 | 
|---|
| 25 | const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = {
 | 
|---|
| 26 |         "_Bool",
 | 
|---|
| 27 |         "char",
 | 
|---|
| 28 |         "signed char",
 | 
|---|
| 29 |         "unsigned char",
 | 
|---|
| 30 |         "signed short int",
 | 
|---|
| 31 |         "unsigned short int",
 | 
|---|
| 32 |         "signed int",
 | 
|---|
| 33 |         "unsigned int",
 | 
|---|
| 34 |         "signed long int",
 | 
|---|
| 35 |         "unsigned long int",
 | 
|---|
| 36 |         "signed long long int",
 | 
|---|
| 37 |         "unsigned long long int",
 | 
|---|
| 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",
 | 
|---|
| 47 |         "__int128",
 | 
|---|
| 48 |         "unsigned __int128",
 | 
|---|
| 49 | };
 | 
|---|
| 50 | 
 | 
|---|
| 51 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
 | 
|---|
| 52 | 
 | 
|---|
| 53 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
 | 
|---|
| 54 |         cloneAll( other.forall, forall );
 | 
|---|
| 55 |         cloneAll( other.attributes, attributes );
 | 
|---|
| 56 | }
 | 
|---|
| 57 | 
 | 
|---|
| 58 | Type::~Type() {
 | 
|---|
| 59 |         deleteAll( forall );
 | 
|---|
| 60 |         deleteAll( attributes );
 | 
|---|
| 61 | }
 | 
|---|
| 62 | 
 | 
|---|
| 63 | // These must remain in the same order as the corresponding bit fields.
 | 
|---|
| 64 | const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" };
 | 
|---|
| 65 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
 | 
|---|
| 66 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
 | 
|---|
| 67 | 
 | 
|---|
| 68 | Type * Type::stripDeclarator() {
 | 
|---|
| 69 |         Type * type, * at;
 | 
|---|
| 70 |         for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
 | 
|---|
| 71 |         return type;
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | Type * Type::stripReferences() {
 | 
|---|
| 75 |         Type * type;
 | 
|---|
| 76 |         ReferenceType * ref;
 | 
|---|
| 77 |         for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
 | 
|---|
| 78 |         return type;
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | int Type::referenceDepth() const { return 0; }
 | 
|---|
| 82 | 
 | 
|---|
| 83 | void Type::print( std::ostream &os, Indenter indent ) const {
 | 
|---|
| 84 |         if ( ! forall.empty() ) {
 | 
|---|
| 85 |                 os << "forall" << std::endl;
 | 
|---|
| 86 |                 printAll( forall, os, indent+1 );
 | 
|---|
| 87 |                 os << ++indent;
 | 
|---|
| 88 |         } // if
 | 
|---|
| 89 | 
 | 
|---|
| 90 |         if ( ! attributes.empty() ) {
 | 
|---|
| 91 |                 os << "with attributes" << endl;
 | 
|---|
| 92 |                 printAll( attributes, os, indent+1 );
 | 
|---|
| 93 |         } // if
 | 
|---|
| 94 | 
 | 
|---|
| 95 |         tq.print( os );
 | 
|---|
| 96 | }
 | 
|---|
| 97 | 
 | 
|---|
| 98 | // Empty Variable declarations:
 | 
|---|
| 99 | const Type::FuncSpecifiers noFuncSpecifiers;
 | 
|---|
| 100 | const Type::StorageClasses noStorageClasses;
 | 
|---|
| 101 | const Type::Qualifiers noQualifiers;
 | 
|---|
| 102 | 
 | 
|---|
| 103 | // Local Variables: //
 | 
|---|
| 104 | // tab-width: 4 //
 | 
|---|
| 105 | // mode: c++ //
 | 
|---|
| 106 | // compile-command: "make install" //
 | 
|---|
| 107 | // End: //
 | 
|---|