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