source: src/SynTree/Type.cc @ 3df4cd9

Last change on this file since 3df4cd9 was 9feb34b, checked in by Andrew Beach <ajbeach@…>, 15 months ago

Moved toString and toCString to a new header. Updated includes. cassert was somehow getting instances of toString before but that stopped working so I embedded the new smaller include.

  • Property mode set to 100644
File size: 5.7 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
[ca69a8a]11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Jul 14 15:47:00 2021
13// Update Count     : 50
[0dd3a2f]14//
[51b7345]15#include "Type.h"
[0dd3a2f]16
[9bfc9da]17#include "Attribute.h"                // for Attribute
[9feb34b]18#include "Common/ToString.hpp"        // for toCString
[9bfc9da]19#include "Common/utility.h"           // for cloneAll, deleteAll, printAll
20#include "InitTweak/InitTweak.h"      // for getPointerBase
21#include "SynTree/BaseSyntaxNode.h"   // for BaseSyntaxNode
22#include "SynTree/Declaration.h"      // for TypeDecl
23#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
[51b7345]24
[c0aa336]25using namespace std;
26
[cfaa2873]27// GENERATED START, DO NOT EDIT
28// GENERATED BY BasicTypes-gen.cc
[357390f]29const char * BasicType::typeNames[] = {
[cdcddfe1]30        "_Bool",
31        "char",
32        "signed char",
33        "unsigned char",
34        "signed short int",
35        "unsigned short int",
36        "signed int",
37        "unsigned int",
38        "signed long int",
39        "unsigned long int",
40        "signed long long int",
41        "unsigned long long int",
42        "__int128",
43        "unsigned __int128",
44        "_Float16",
45        "_Float16 _Complex",
46        "_Float32",
47        "_Float32 _Complex",
48        "float",
49        "float _Complex",
50        "_Float32x",
51        "_Float32x _Complex",
52        "_Float64",
53        "_Float64 _Complex",
54        "double",
55        "double _Complex",
56        "_Float64x",
57        "_Float64x _Complex",
58        "__float80",
59        "_Float128",
60        "_Float128 _Complex",
61        "__float128",
62        "long double",
63        "long double _Complex",
64        "_Float128x",
65        "_Float128x _Complex",
[17cd4eb]66};
[cfaa2873]67// GENERATED END
[51b7345]68
[c0aa336]69Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
[51b7345]70
[64ac636]71Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
[a08ba92]72        cloneAll( other.forall, forall );
[c0aa336]73        cloneAll( other.attributes, attributes );
[51b7345]74}
75
[17cd4eb]76Type::~Type() {
[a08ba92]77        deleteAll( forall );
[c0aa336]78        deleteAll( attributes );
[51b7345]79}
80
[68fe077a]81// These must remain in the same order as the corresponding bit fields.
[999c700]82const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
[ed9a1ae]83const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "__thread", "_Thread_local" };
[b4f8808]84const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
[0dd3a2f]85
[0698aa1]86Type * Type::stripDeclarator() {
[de9285f]87        Type * type, * at;
88        for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
[6f95000]89        return type;
90}
[0dd3a2f]91
[0698aa1]92Type * Type::stripReferences() {
[de9285f]93        Type * type;
94        ReferenceType * ref;
[50377a4]95        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
[0698aa1]96        return type;
97}
98
[85dac33]99const Type * Type::stripReferences() const {
100        const Type * type;
101        const ReferenceType * ref;
102        for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
103        return type;
104}
105
[e6cee92]106int Type::referenceDepth() const { return 0; }
107
[9feb34b]108AggregateDecl * Type::getAggr() const {
109        assertf( false, "Non-aggregate type: %s", toCString( this ) );
110}
111
[9bfc9da]112TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
113
[357390f]114void Type::print( std::ostream & os, Indenter indent ) const {
[f1b1e4c]115        if ( ! forall.empty() ) {
116                os << "forall" << std::endl;
[50377a4]117                printAll( forall, os, indent+1 );
118                os << ++indent;
[f1b1e4c]119        } // if
[c0aa336]120
121        if ( ! attributes.empty() ) {
[50377a4]122                os << "with attributes" << endl;
123                printAll( attributes, os, indent+1 );
[c0aa336]124        } // if
[64ac636]125
[d6d747d]126        tq.print( os );
[f1b1e4c]127}
128
[c5d7701]129
[c194661]130QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
[c5d7701]131}
132
[c194661]133QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
[c5d7701]134}
135
136QualifiedType::~QualifiedType() {
[c194661]137        delete parent;
138        delete child;
[c5d7701]139}
140
141void QualifiedType::print( std::ostream & os, Indenter indent ) const {
[07ec1a2]142        os << "Qualified Type:" << endl;
[c194661]143        os << indent+1;
144        parent->print( os, indent+1 );
145        os << endl << indent+1;
146        child->print( os, indent+1 );
147        os << endl;
[c5d7701]148        Type::print( os, indent+1 );
149}
150
[47498bd]151GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
152
[0b3b2ae]153void GlobalScopeType::print( std::ostream & os, Indenter ) const {
[47498bd]154        os << "Global Scope Type" << endl;
155}
156
[c5d7701]157
[65cdc1e]158// Empty Variable declarations:
159const Type::FuncSpecifiers noFuncSpecifiers;
160const Type::StorageClasses noStorageClasses;
161const Type::Qualifiers noQualifiers;
162
[cd6a6ff]163bool isUnboundType(const Type * type) {
164        if (auto typeInst = dynamic_cast<const TypeInstType *>(type)) {
165                // xxx - look for a type name produced by renameTyVars.
166
167                // TODO: once TypeInstType representation is updated, it should properly check
168                // if the context id is filled. this is a temporary hack for now
169                return isUnboundType(typeInst->name);
170        }
171        return false;
172}
173
174bool isUnboundType(const std::string & tname) {
175        // xxx - look for a type name produced by renameTyVars.
176
177        // TODO: once TypeInstType representation is updated, it should properly check
178        // if the context id is filled. this is a temporary hack for now
179        if (std::count(tname.begin(), tname.end(), '_') >= 3) {
180                return true;
181        }
182        return false;
183}
184
[ca69a8a]185VTableType::VTableType( const Type::Qualifiers &tq, Type *base, const std::list< Attribute * > & attributes )
186                : Type( tq, attributes ), base( base ) {
187        assertf( base, "VTableType with a null base created." );
188}
189
190VTableType::VTableType( const VTableType &other )
191                : Type( other ), base( other.base->clone() ) {
192}
193
194VTableType::~VTableType() {
195        delete base;
196}
197
198void VTableType::print( std::ostream &os, Indenter indent ) const {
199        Type::print( os, indent );
200        os << "get virtual-table type of ";
201        if ( base ) {
202                base->print( os, indent );
203        } // if
204}
205
[0dd3a2f]206// Local Variables: //
207// tab-width: 4 //
208// mode: c++ //
209// compile-command: "make install" //
210// End: //
Note: See TracBrowser for help on using the repository browser.