source: src/SynTree/Type.cc @ 357390f

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 357390f was 357390f, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

formatting

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[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]24using namespace std;
25
[357390f]26const 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]67static_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]72Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
[51b7345]73
[64ac636]74Type::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]79Type::~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]85const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
[615a096]86const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
87const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
[0dd3a2f]88
[0698aa1]89Type * 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]95Type * 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]102const 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]109int Type::referenceDepth() const { return 0; }
110
[9bfc9da]111TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
112
[357390f]113void 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]129QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
[c5d7701]130}
131
[c194661]132QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
[c5d7701]133}
134
135QualifiedType::~QualifiedType() {
[c194661]136        delete parent;
137        delete child;
[c5d7701]138}
139
140void 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]150GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
151
[0b3b2ae]152void GlobalScopeType::print( std::ostream & os, Indenter ) const {
[47498bd]153        os << "Global Scope Type" << endl;
154}
155
[c5d7701]156
[65cdc1e]157// Empty Variable declarations:
158const Type::FuncSpecifiers noFuncSpecifiers;
159const Type::StorageClasses noStorageClasses;
160const Type::Qualifiers noQualifiers;
161
[0dd3a2f]162// Local Variables: //
163// tab-width: 4 //
164// mode: c++ //
165// compile-command: "make install" //
166// End: //
Note: See TracBrowser for help on using the repository browser.