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 : Peter A. Buhr |
---|
12 | // Last Modified On : Thu Jan 31 21:54:16 2019 |
---|
13 | // Update Count : 43 |
---|
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 | const 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 | }; |
---|
108 | static_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 | |
---|
113 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
114 | |
---|
115 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
116 | cloneAll( other.forall, forall ); |
---|
117 | cloneAll( other.attributes, attributes ); |
---|
118 | } |
---|
119 | |
---|
120 | Type::~Type() { |
---|
121 | deleteAll( forall ); |
---|
122 | deleteAll( attributes ); |
---|
123 | } |
---|
124 | |
---|
125 | // These must remain in the same order as the corresponding bit fields. |
---|
126 | const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; |
---|
127 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
128 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" }; |
---|
129 | |
---|
130 | Type * Type::stripDeclarator() { |
---|
131 | Type * type, * at; |
---|
132 | for ( type = this; (at = InitTweak::getPointerBase( type )); type = at ); |
---|
133 | return type; |
---|
134 | } |
---|
135 | |
---|
136 | Type * 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 | |
---|
143 | int Type::referenceDepth() const { return 0; } |
---|
144 | |
---|
145 | TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } |
---|
146 | |
---|
147 | void Type::print( std::ostream &os, Indenter indent ) const { |
---|
148 | if ( ! forall.empty() ) { |
---|
149 | os << "forall" << std::endl; |
---|
150 | printAll( forall, os, indent+1 ); |
---|
151 | os << ++indent; |
---|
152 | } // if |
---|
153 | |
---|
154 | if ( ! attributes.empty() ) { |
---|
155 | os << "with attributes" << endl; |
---|
156 | printAll( attributes, os, indent+1 ); |
---|
157 | } // if |
---|
158 | |
---|
159 | tq.print( os ); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) { |
---|
164 | } |
---|
165 | |
---|
166 | QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) { |
---|
167 | } |
---|
168 | |
---|
169 | QualifiedType::~QualifiedType() { |
---|
170 | delete parent; |
---|
171 | delete child; |
---|
172 | } |
---|
173 | |
---|
174 | void QualifiedType::print( std::ostream & os, Indenter indent ) const { |
---|
175 | os << "Qualified Type:" << endl; |
---|
176 | os << indent+1; |
---|
177 | parent->print( os, indent+1 ); |
---|
178 | os << endl << indent+1; |
---|
179 | child->print( os, indent+1 ); |
---|
180 | os << endl; |
---|
181 | Type::print( os, indent+1 ); |
---|
182 | } |
---|
183 | |
---|
184 | GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {} |
---|
185 | |
---|
186 | void GlobalScopeType::print( std::ostream & os, Indenter ) const { |
---|
187 | os << "Global Scope Type" << endl; |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | // Empty Variable declarations: |
---|
192 | const Type::FuncSpecifiers noFuncSpecifiers; |
---|
193 | const Type::StorageClasses noStorageClasses; |
---|
194 | const Type::Qualifiers noQualifiers; |
---|
195 | |
---|
196 | // Local Variables: // |
---|
197 | // tab-width: 4 // |
---|
198 | // mode: c++ // |
---|
199 | // compile-command: "make install" // |
---|
200 | // End: // |
---|