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 : Wed Jul 14 15:47:00 2021
|
---|
13 | // Update Count : 50
|
---|
14 | //
|
---|
15 | #include "Type.h"
|
---|
16 |
|
---|
17 | #include "Attribute.h" // for Attribute
|
---|
18 | #include "Common/ToString.hpp" // for toCString
|
---|
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
|
---|
24 |
|
---|
25 | using namespace std;
|
---|
26 |
|
---|
27 | // GENERATED START, DO NOT EDIT
|
---|
28 | // GENERATED BY BasicTypes-gen.cc
|
---|
29 | const char * BasicType::typeNames[] = {
|
---|
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",
|
---|
66 | };
|
---|
67 | // GENERATED END
|
---|
68 |
|
---|
69 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
|
---|
70 |
|
---|
71 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
|
---|
72 | cloneAll( other.forall, forall );
|
---|
73 | cloneAll( other.attributes, attributes );
|
---|
74 | }
|
---|
75 |
|
---|
76 | Type::~Type() {
|
---|
77 | deleteAll( forall );
|
---|
78 | deleteAll( attributes );
|
---|
79 | }
|
---|
80 |
|
---|
81 | // These must remain in the same order as the corresponding bit fields.
|
---|
82 | const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
|
---|
83 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "__thread", "_Thread_local" };
|
---|
84 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
|
---|
85 |
|
---|
86 | Type * Type::stripDeclarator() {
|
---|
87 | Type * type, * at;
|
---|
88 | for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
|
---|
89 | return type;
|
---|
90 | }
|
---|
91 |
|
---|
92 | Type * Type::stripReferences() {
|
---|
93 | Type * type;
|
---|
94 | ReferenceType * ref;
|
---|
95 | for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
|
---|
96 | return type;
|
---|
97 | }
|
---|
98 |
|
---|
99 | const 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 |
|
---|
106 | int Type::referenceDepth() const { return 0; }
|
---|
107 |
|
---|
108 | AggregateDecl * Type::getAggr() const {
|
---|
109 | assertf( false, "Non-aggregate type: %s", toCString( this ) );
|
---|
110 | }
|
---|
111 |
|
---|
112 | TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
|
---|
113 |
|
---|
114 | void Type::print( std::ostream & os, Indenter indent ) const {
|
---|
115 | if ( ! forall.empty() ) {
|
---|
116 | os << "forall" << std::endl;
|
---|
117 | printAll( forall, os, indent+1 );
|
---|
118 | os << ++indent;
|
---|
119 | } // if
|
---|
120 |
|
---|
121 | if ( ! attributes.empty() ) {
|
---|
122 | os << "with attributes" << endl;
|
---|
123 | printAll( attributes, os, indent+1 );
|
---|
124 | } // if
|
---|
125 |
|
---|
126 | tq.print( os );
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
|
---|
131 | }
|
---|
132 |
|
---|
133 | QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
|
---|
134 | }
|
---|
135 |
|
---|
136 | QualifiedType::~QualifiedType() {
|
---|
137 | delete parent;
|
---|
138 | delete child;
|
---|
139 | }
|
---|
140 |
|
---|
141 | void QualifiedType::print( std::ostream & os, Indenter indent ) const {
|
---|
142 | os << "Qualified Type:" << endl;
|
---|
143 | os << indent+1;
|
---|
144 | parent->print( os, indent+1 );
|
---|
145 | os << endl << indent+1;
|
---|
146 | child->print( os, indent+1 );
|
---|
147 | os << endl;
|
---|
148 | Type::print( os, indent+1 );
|
---|
149 | }
|
---|
150 |
|
---|
151 | GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
|
---|
152 |
|
---|
153 | void GlobalScopeType::print( std::ostream & os, Indenter ) const {
|
---|
154 | os << "Global Scope Type" << endl;
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | // Empty Variable declarations:
|
---|
159 | const Type::FuncSpecifiers noFuncSpecifiers;
|
---|
160 | const Type::StorageClasses noStorageClasses;
|
---|
161 | const Type::Qualifiers noQualifiers;
|
---|
162 |
|
---|
163 | bool 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 |
|
---|
174 | bool 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 |
|
---|
185 | VTableType::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 |
|
---|
190 | VTableType::VTableType( const VTableType &other )
|
---|
191 | : Type( other ), base( other.base->clone() ) {
|
---|
192 | }
|
---|
193 |
|
---|
194 | VTableType::~VTableType() {
|
---|
195 | delete base;
|
---|
196 | }
|
---|
197 |
|
---|
198 | void 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 |
|
---|
206 | // Local Variables: //
|
---|
207 | // tab-width: 4 //
|
---|
208 | // mode: c++ //
|
---|
209 | // compile-command: "make install" //
|
---|
210 | // End: //
|
---|