source: src/SynTree/Type.cc @ 85dac33

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 85dac33 was 85dac33, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Added 'const' in some leaf positions where it doesn't seem to effect much.

  • Property mode set to 100644
File size: 5.2 KB
Line 
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 : Andrew Beach
12// Last Modified On : Fri Jul 12 15:48:00 2019
13// Update Count     : 44
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#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
23
24using namespace std;
25
26const char *BasicType::typeNames[] = {
27#if 0
28        "_Bool",
29        "char",
30        "signed char",
31        "unsigned char",
32        "signed short int",
33        "unsigned short int",
34        "signed int",
35        "unsigned int",
36        "signed long int",
37        "unsigned long int",
38        "signed long long int",
39        "unsigned long long int",
40        "float",
41        "double",
42        "long double",
43        "float _Complex",
44        "double _Complex",
45        "long double _Complex",
46        "float _Imaginary",
47        "double _Imaginary",
48        "long double _Imaginary",
49        "__int128",
50        "unsigned __int128",
51        "__float80",
52        "__float128",
53        "_Float16",
54        "_Float32",
55        "_Float32x",
56        "_Float64",
57        "_Float64x",
58        "_Float128",
59        "_Float128x",
60        "_Float16 _Complex",
61        "_Float32 _Complex",
62        "_Float32x _Complex",
63        "_Float64 _Complex",
64        "_Float64x _Complex",
65        "_Float128 _Complex",
66        "_Float128x _Complex",
67#endif
68        "_Bool",
69        "char",
70        "signed char",
71        "unsigned char",
72        "signed short int",
73        "unsigned short int",
74        "signed int",
75        "unsigned int",
76        "signed long int",
77        "unsigned long int",
78        "signed long long int",
79        "unsigned long long int",
80        "__int128",
81        "unsigned __int128",
82        "_Float16",
83        "_Float16 _Complex",
84        "_Float32",
85        "_Float32 _Complex",
86        "float",
87        "float _Complex",
88        //"float _Imaginary",
89        "_Float32x",
90        "_Float32x _Complex",
91        "_Float64",
92        "_Float64 _Complex",
93        "double",
94        "double _Complex",
95        //"double _Imaginary",
96        "_Float64x",
97        "_Float64x _Complex",
98        "__float80",
99        "_Float128",
100        "_Float128 _Complex",
101        "__float128",
102        "long double",
103        "long double _Complex",
104        //"long double _Imaginary",
105        "_Float128x",
106        "_Float128x _Complex",
107};
108static_assert(
109        sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
110        "Each basic type name should have a corresponding kind enum value"
111);
112
113Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
114
115Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
116        cloneAll( other.forall, forall );
117        cloneAll( other.attributes, attributes );
118}
119
120Type::~Type() {
121        deleteAll( forall );
122        deleteAll( attributes );
123}
124
125// These must remain in the same order as the corresponding bit fields.
126const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
127const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
128const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
129
130Type * Type::stripDeclarator() {
131        Type * type, * at;
132        for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
133        return type;
134}
135
136Type * Type::stripReferences() {
137        Type * type;
138        ReferenceType * ref;
139        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
140        return type;
141}
142
143const Type * Type::stripReferences() const {
144        const Type * type;
145        const ReferenceType * ref;
146        for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
147        return type;
148}
149
150int Type::referenceDepth() const { return 0; }
151
152TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
153
154void Type::print( std::ostream &os, Indenter indent ) const {
155        if ( ! forall.empty() ) {
156                os << "forall" << std::endl;
157                printAll( forall, os, indent+1 );
158                os << ++indent;
159        } // if
160
161        if ( ! attributes.empty() ) {
162                os << "with attributes" << endl;
163                printAll( attributes, os, indent+1 );
164        } // if
165
166        tq.print( os );
167}
168
169
170QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
171}
172
173QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
174}
175
176QualifiedType::~QualifiedType() {
177        delete parent;
178        delete child;
179}
180
181void QualifiedType::print( std::ostream & os, Indenter indent ) const {
182        os << "Qualified Type:" << endl;
183        os << indent+1;
184        parent->print( os, indent+1 );
185        os << endl << indent+1;
186        child->print( os, indent+1 );
187        os << endl;
188        Type::print( os, indent+1 );
189}
190
191GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
192
193void GlobalScopeType::print( std::ostream & os, Indenter ) const {
194        os << "Global Scope Type" << endl;
195}
196
197
198// Empty Variable declarations:
199const Type::FuncSpecifiers noFuncSpecifiers;
200const Type::StorageClasses noStorageClasses;
201const Type::Qualifiers noQualifiers;
202
203// Local Variables: //
204// tab-width: 4 //
205// mode: c++ //
206// compile-command: "make install" //
207// End: //
Note: See TracBrowser for help on using the repository browser.