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 | // DeclarationNode.cc --
|
---|
8 | //
|
---|
9 | // Author : Rodolfo G. Esteves
|
---|
10 | // Created On : Sat May 16 12:34:05 2015
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Mon Aug 29 15:55:12 2016
|
---|
13 | // Update Count : 311
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include <string>
|
---|
17 | #include <list>
|
---|
18 | #include <iterator>
|
---|
19 | #include <algorithm>
|
---|
20 | #include <cassert>
|
---|
21 |
|
---|
22 | #include "TypeData.h"
|
---|
23 |
|
---|
24 | #include "SynTree/Declaration.h"
|
---|
25 | #include "SynTree/Expression.h"
|
---|
26 |
|
---|
27 | #include "TypedefTable.h"
|
---|
28 | extern TypedefTable typedefTable;
|
---|
29 |
|
---|
30 | using namespace std;
|
---|
31 |
|
---|
32 | // These must remain in the same order as the corresponding DeclarationNode enumerations.
|
---|
33 | const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" };
|
---|
34 | const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
|
---|
35 | const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", };
|
---|
36 | const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" };
|
---|
37 | const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
|
---|
38 | const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
|
---|
39 | const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
|
---|
40 |
|
---|
41 | UniqueName DeclarationNode::anonymous( "__anonymous" );
|
---|
42 |
|
---|
43 | extern LinkageSpec::Spec linkage; // defined in parser.yy
|
---|
44 |
|
---|
45 | DeclarationNode *DeclarationNode::clone() const {
|
---|
46 | DeclarationNode *newnode = new DeclarationNode;
|
---|
47 | newnode->type = maybeClone( type );
|
---|
48 | newnode->name = name;
|
---|
49 | newnode->storageClass = storageClass;
|
---|
50 | newnode->isInline = isInline;
|
---|
51 | newnode->isNoreturn = isNoreturn;
|
---|
52 | newnode->bitfieldWidth = maybeClone( bitfieldWidth );
|
---|
53 | newnode->hasEllipsis = hasEllipsis;
|
---|
54 | newnode->initializer = maybeClone( initializer );
|
---|
55 | newnode->set_next( maybeClone( get_next() ) );
|
---|
56 | newnode->linkage = linkage;
|
---|
57 | return newnode;
|
---|
58 | } // DeclarationNode::clone
|
---|
59 |
|
---|
60 | DeclarationNode::DeclarationNode()
|
---|
61 | : type( 0 )
|
---|
62 | , storageClass( NoStorageClass )
|
---|
63 | , isInline( false )
|
---|
64 | , isNoreturn( false )
|
---|
65 | , bitfieldWidth( 0 )
|
---|
66 | , initializer( 0 )
|
---|
67 | , hasEllipsis( false )
|
---|
68 | , linkage( ::linkage )
|
---|
69 | , extension( false )
|
---|
70 | , error() {
|
---|
71 | }
|
---|
72 |
|
---|
73 | DeclarationNode::~DeclarationNode() {
|
---|
74 | delete type;
|
---|
75 | delete bitfieldWidth;
|
---|
76 | delete initializer;
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool DeclarationNode::get_hasEllipsis() const {
|
---|
80 | return hasEllipsis;
|
---|
81 | }
|
---|
82 |
|
---|
83 | void DeclarationNode::print( std::ostream &os, int indent ) const {
|
---|
84 | os << string( indent, ' ' );
|
---|
85 | if ( name == "" ) {
|
---|
86 | os << "unnamed: ";
|
---|
87 | } else {
|
---|
88 | os << name << ": ";
|
---|
89 | } // if
|
---|
90 |
|
---|
91 | if ( linkage != LinkageSpec::Cforall ) {
|
---|
92 | os << LinkageSpec::toString( linkage ) << " ";
|
---|
93 | } // if
|
---|
94 |
|
---|
95 | if ( storageClass != NoStorageClass ) os << DeclarationNode::storageName[storageClass] << ' ';
|
---|
96 | if ( isInline ) os << DeclarationNode::storageName[Inline] << ' ';
|
---|
97 | if ( isNoreturn ) os << DeclarationNode::storageName[Noreturn] << ' ';
|
---|
98 | if ( type ) {
|
---|
99 | type->print( os, indent );
|
---|
100 | } else {
|
---|
101 | os << "untyped entity ";
|
---|
102 | } // if
|
---|
103 |
|
---|
104 | if ( bitfieldWidth ) {
|
---|
105 | os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
|
---|
106 | bitfieldWidth->printOneLine( os );
|
---|
107 | } // if
|
---|
108 |
|
---|
109 | if ( initializer != 0 ) {
|
---|
110 | os << endl << string( indent + 2, ' ' ) << "with initializer ";
|
---|
111 | initializer->printOneLine( os );
|
---|
112 | os << " maybe constructed? " << initializer->get_maybeConstructed();
|
---|
113 |
|
---|
114 | } // if
|
---|
115 |
|
---|
116 | os << endl;
|
---|
117 | }
|
---|
118 |
|
---|
119 | void DeclarationNode::printList( std::ostream &os, int indent ) const {
|
---|
120 | ParseNode::printList( os, indent );
|
---|
121 | if ( hasEllipsis ) {
|
---|
122 | os << string( indent, ' ' ) << "and a variable number of other arguments" << endl;
|
---|
123 | } // if
|
---|
124 | }
|
---|
125 |
|
---|
126 | DeclarationNode *DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) {
|
---|
127 | DeclarationNode *newnode = new DeclarationNode;
|
---|
128 | newnode->name = assign_strptr( name );
|
---|
129 |
|
---|
130 | newnode->type = new TypeData( TypeData::Function );
|
---|
131 | newnode->type->function.params = param;
|
---|
132 | newnode->type->function.newStyle = newStyle;
|
---|
133 | newnode->type->function.body = body;
|
---|
134 | typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
|
---|
135 |
|
---|
136 | if ( body ) {
|
---|
137 | newnode->type->function.hasBody = true;
|
---|
138 | } // if
|
---|
139 |
|
---|
140 | if ( ret ) {
|
---|
141 | newnode->type->base = ret->type;
|
---|
142 | ret->type = 0;
|
---|
143 | delete ret;
|
---|
144 | } // if
|
---|
145 |
|
---|
146 | return newnode;
|
---|
147 | } // DeclarationNode::newFunction
|
---|
148 |
|
---|
149 | DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {
|
---|
150 | DeclarationNode *newnode = new DeclarationNode;
|
---|
151 | newnode->type = new TypeData();
|
---|
152 | newnode->type->qualifiers[ q ] = 1;
|
---|
153 | return newnode;
|
---|
154 | } // DeclarationNode::newQualifier
|
---|
155 |
|
---|
156 | DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) {
|
---|
157 | DeclarationNode *newnode = new DeclarationNode;
|
---|
158 | newnode->type = new TypeData( TypeData::Unknown );
|
---|
159 | newnode->type->forall = forall;
|
---|
160 | return newnode;
|
---|
161 | } // DeclarationNode::newForall
|
---|
162 |
|
---|
163 | DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
|
---|
164 | DeclarationNode *newnode = new DeclarationNode;
|
---|
165 | //switch (sc) {
|
---|
166 | // case Inline: newnode->isInline = true; break;
|
---|
167 | // case Noreturn: newnode->isNoreturn = true; break;
|
---|
168 | // default: newnode->storageClass = sc; break;
|
---|
169 | //}
|
---|
170 | newnode->storageClass = sc;
|
---|
171 | return newnode;
|
---|
172 | } // DeclarationNode::newStorageClass
|
---|
173 |
|
---|
174 | DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
|
---|
175 | DeclarationNode *newnode = new DeclarationNode;
|
---|
176 | newnode->type = new TypeData( TypeData::Basic );
|
---|
177 | newnode->type->basic.typeSpec.push_back( bt );
|
---|
178 | return newnode;
|
---|
179 | } // DeclarationNode::newBasicType
|
---|
180 |
|
---|
181 | DeclarationNode * DeclarationNode::newModifier( Modifier mod ) {
|
---|
182 | DeclarationNode *newnode = new DeclarationNode;
|
---|
183 | newnode->type = new TypeData( TypeData::Basic );
|
---|
184 | newnode->type->basic.modifiers.push_back( mod );
|
---|
185 | return newnode;
|
---|
186 | } // DeclarationNode::newModifier
|
---|
187 |
|
---|
188 | DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
|
---|
189 | DeclarationNode *newnode = new DeclarationNode;
|
---|
190 | newnode->type = new TypeData( TypeData::SymbolicInst );
|
---|
191 | newnode->type->symbolic.name = assign_strptr( name );
|
---|
192 | newnode->type->symbolic.isTypedef = true;
|
---|
193 | newnode->type->symbolic.params = 0;
|
---|
194 | return newnode;
|
---|
195 | } // DeclarationNode::newFromTypedef
|
---|
196 |
|
---|
197 | DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
|
---|
198 | DeclarationNode *newnode = new DeclarationNode;
|
---|
199 | newnode->type = new TypeData( TypeData::Aggregate );
|
---|
200 | newnode->type->aggregate.kind = kind;
|
---|
201 | newnode->type->aggregate.name = assign_strptr( name );
|
---|
202 | if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ?
|
---|
203 | newnode->type->aggregate.name = anonymous.newName();
|
---|
204 | } // if
|
---|
205 | newnode->type->aggregate.actuals = actuals;
|
---|
206 | newnode->type->aggregate.fields = fields;
|
---|
207 | newnode->type->aggregate.body = body;
|
---|
208 | return newnode;
|
---|
209 | } // DeclarationNode::newAggregate
|
---|
210 |
|
---|
211 | DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
|
---|
212 | DeclarationNode *newnode = new DeclarationNode;
|
---|
213 | newnode->name = assign_strptr( name );
|
---|
214 | newnode->type = new TypeData( TypeData::Enum );
|
---|
215 | newnode->type->enumeration.name = newnode->name;
|
---|
216 | if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ?
|
---|
217 | newnode->type->enumeration.name = DeclarationNode::anonymous.newName();
|
---|
218 | } // if
|
---|
219 | newnode->type->enumeration.constants = constants;
|
---|
220 | return newnode;
|
---|
221 | } // DeclarationNode::newEnum
|
---|
222 |
|
---|
223 | DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
|
---|
224 | DeclarationNode *newnode = new DeclarationNode;
|
---|
225 | newnode->name = assign_strptr( name );
|
---|
226 | newnode->enumeratorValue.reset( constant );
|
---|
227 | typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
|
---|
228 | return newnode;
|
---|
229 | } // DeclarationNode::newEnumConstant
|
---|
230 |
|
---|
231 | DeclarationNode *DeclarationNode::newName( std::string *name ) {
|
---|
232 | DeclarationNode *newnode = new DeclarationNode;
|
---|
233 | newnode->name = assign_strptr( name );
|
---|
234 | return newnode;
|
---|
235 | } // DeclarationNode::newName
|
---|
236 |
|
---|
237 | DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
|
---|
238 | DeclarationNode *newnode = new DeclarationNode;
|
---|
239 | newnode->type = new TypeData( TypeData::SymbolicInst );
|
---|
240 | newnode->type->symbolic.name = assign_strptr( name );
|
---|
241 | newnode->type->symbolic.isTypedef = false;
|
---|
242 | newnode->type->symbolic.actuals = params;
|
---|
243 | return newnode;
|
---|
244 | } // DeclarationNode::newFromTypeGen
|
---|
245 |
|
---|
246 | DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
|
---|
247 | DeclarationNode *newnode = new DeclarationNode;
|
---|
248 | newnode->name = assign_strptr( name );
|
---|
249 | newnode->type = new TypeData( TypeData::Variable );
|
---|
250 | newnode->type->variable.tyClass = tc;
|
---|
251 | newnode->type->variable.name = newnode->name;
|
---|
252 | return newnode;
|
---|
253 | } // DeclarationNode::newTypeParam
|
---|
254 |
|
---|
255 | DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
|
---|
256 | DeclarationNode *newnode = new DeclarationNode;
|
---|
257 | newnode->type = new TypeData( TypeData::Aggregate );
|
---|
258 | newnode->type->aggregate.kind = Trait;
|
---|
259 | newnode->type->aggregate.params = params;
|
---|
260 | newnode->type->aggregate.fields = asserts;
|
---|
261 | newnode->type->aggregate.name = assign_strptr( name );
|
---|
262 | return newnode;
|
---|
263 | } // DeclarationNode::newTrait
|
---|
264 |
|
---|
265 | DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
|
---|
266 | DeclarationNode *newnode = new DeclarationNode;
|
---|
267 | newnode->type = new TypeData( TypeData::AggregateInst );
|
---|
268 | newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
|
---|
269 | newnode->type->aggInst.aggregate->aggregate.kind = Trait;
|
---|
270 | newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );
|
---|
271 | newnode->type->aggInst.params = params;
|
---|
272 | return newnode;
|
---|
273 | } // DeclarationNode::newTraitUse
|
---|
274 |
|
---|
275 | DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
|
---|
276 | DeclarationNode *newnode = new DeclarationNode;
|
---|
277 | newnode->name = assign_strptr( name );
|
---|
278 | newnode->type = new TypeData( TypeData::Symbolic );
|
---|
279 | newnode->type->symbolic.isTypedef = false;
|
---|
280 | newnode->type->symbolic.params = typeParams;
|
---|
281 | newnode->type->symbolic.name = newnode->name;
|
---|
282 | return newnode;
|
---|
283 | } // DeclarationNode::newTypeDecl
|
---|
284 |
|
---|
285 | DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
|
---|
286 | DeclarationNode *newnode = new DeclarationNode;
|
---|
287 | newnode->type = new TypeData( TypeData::Pointer );
|
---|
288 | return newnode->addQualifiers( qualifiers );
|
---|
289 | } // DeclarationNode::newPointer
|
---|
290 |
|
---|
291 | DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
|
---|
292 | DeclarationNode *newnode = new DeclarationNode;
|
---|
293 | newnode->type = new TypeData( TypeData::Array );
|
---|
294 | newnode->type->array.dimension = size;
|
---|
295 | newnode->type->array.isStatic = isStatic;
|
---|
296 | if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {
|
---|
297 | newnode->type->array.isVarLen = false;
|
---|
298 | } else {
|
---|
299 | newnode->type->array.isVarLen = true;
|
---|
300 | } // if
|
---|
301 | return newnode->addQualifiers( qualifiers );
|
---|
302 | } // DeclarationNode::newArray
|
---|
303 |
|
---|
304 | DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
|
---|
305 | DeclarationNode *newnode = new DeclarationNode;
|
---|
306 | newnode->type = new TypeData( TypeData::Array );
|
---|
307 | newnode->type->array.dimension = 0;
|
---|
308 | newnode->type->array.isStatic = false;
|
---|
309 | newnode->type->array.isVarLen = true;
|
---|
310 | return newnode->addQualifiers( qualifiers );
|
---|
311 | }
|
---|
312 |
|
---|
313 | DeclarationNode *DeclarationNode::newBitfield( ExpressionNode *size ) {
|
---|
314 | DeclarationNode *newnode = new DeclarationNode;
|
---|
315 | newnode->bitfieldWidth = size;
|
---|
316 | return newnode;
|
---|
317 | }
|
---|
318 |
|
---|
319 | DeclarationNode *DeclarationNode::newTuple( DeclarationNode *members ) {
|
---|
320 | DeclarationNode *newnode = new DeclarationNode;
|
---|
321 | newnode->type = new TypeData( TypeData::Tuple );
|
---|
322 | newnode->type->tuple = members;
|
---|
323 | return newnode;
|
---|
324 | }
|
---|
325 |
|
---|
326 | DeclarationNode *DeclarationNode::newTypeof( ExpressionNode *expr ) {
|
---|
327 | DeclarationNode *newnode = new DeclarationNode;
|
---|
328 | newnode->type = new TypeData( TypeData::Typeof );
|
---|
329 | newnode->type->typeexpr = expr;
|
---|
330 | return newnode;
|
---|
331 | }
|
---|
332 |
|
---|
333 | DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
|
---|
334 | DeclarationNode *newnode = new DeclarationNode;
|
---|
335 | newnode->type = new TypeData( TypeData::Builtin );
|
---|
336 | newnode->builtin = bt;
|
---|
337 | return newnode;
|
---|
338 | } // DeclarationNode::newBuiltinType
|
---|
339 |
|
---|
340 | DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
|
---|
341 | DeclarationNode *newnode = new DeclarationNode;
|
---|
342 | newnode->type = new TypeData( TypeData::Attr );
|
---|
343 | newnode->type->attr.name = assign_strptr( name );
|
---|
344 | newnode->type->attr.expr = expr;
|
---|
345 | return newnode;
|
---|
346 | }
|
---|
347 |
|
---|
348 | DeclarationNode *DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) {
|
---|
349 | DeclarationNode *newnode = new DeclarationNode;
|
---|
350 | newnode->type = new TypeData( TypeData::Attr );
|
---|
351 | newnode->type->attr.name = assign_strptr( name );
|
---|
352 | newnode->type->attr.type = type;
|
---|
353 | return newnode;
|
---|
354 | }
|
---|
355 |
|
---|
356 | static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
|
---|
357 | if ( src && dst ) {
|
---|
358 | if ( src->forall && dst->kind == TypeData::Function ) {
|
---|
359 | if ( dst->forall ) {
|
---|
360 | dst->forall->appendList( src->forall );
|
---|
361 | } else {
|
---|
362 | dst->forall = src->forall;
|
---|
363 | } // if
|
---|
364 | src->forall = 0;
|
---|
365 | } // if
|
---|
366 | if ( dst->base ) {
|
---|
367 | addQualifiersToType( src, dst->base );
|
---|
368 | } else if ( dst->kind == TypeData::Function ) {
|
---|
369 | dst->base = src;
|
---|
370 | src = 0;
|
---|
371 | } else {
|
---|
372 | dst->qualifiers |= src->qualifiers;
|
---|
373 | } // if
|
---|
374 | } // if
|
---|
375 | }
|
---|
376 |
|
---|
377 | void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
|
---|
378 | TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers;
|
---|
379 |
|
---|
380 | if ( (qsrc & qdst).any() ) { // common bits between qualifier masks ?
|
---|
381 | error = "duplicate qualifier ";
|
---|
382 | int j = 0; // separator detector
|
---|
383 | for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) {
|
---|
384 | if ( qsrc[i] & qdst[i] ) { // find specific qualifiers in common
|
---|
385 | if ( j > 0 ) error += ", ";
|
---|
386 | error += DeclarationNode::qualifierName[i];
|
---|
387 | j += 1;
|
---|
388 | } // if
|
---|
389 | } // for
|
---|
390 | error += " in declaration of ";
|
---|
391 | } // if
|
---|
392 | } // DeclarationNode::checkQualifiers
|
---|
393 |
|
---|
394 | DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
|
---|
395 | if ( q ) {
|
---|
396 | copyStorageClasses(q);
|
---|
397 | if ( q->type ) {
|
---|
398 | if ( ! type ) {
|
---|
399 | type = new TypeData;
|
---|
400 | } else {
|
---|
401 | checkQualifiers( q->type, type );
|
---|
402 | } // if
|
---|
403 | addQualifiersToType( q->type, type );
|
---|
404 | if ( q->type && q->type->forall ) {
|
---|
405 | if ( type->forall ) {
|
---|
406 | type->forall->appendList( q->type->forall );
|
---|
407 | } else {
|
---|
408 | if ( type->kind == TypeData::Aggregate ) {
|
---|
409 | type->aggregate.params = q->type->forall;
|
---|
410 | // change implicit typedef from TYPEDEFname to TYPEGENname
|
---|
411 | typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
|
---|
412 | } else {
|
---|
413 | type->forall = q->type->forall;
|
---|
414 | } // if
|
---|
415 | } // if
|
---|
416 | q->type->forall = 0;
|
---|
417 | } // if
|
---|
418 | } // if
|
---|
419 | } // if
|
---|
420 | delete q;
|
---|
421 | return this;
|
---|
422 | }
|
---|
423 |
|
---|
424 | DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
|
---|
425 | isInline = isInline || q->isInline;
|
---|
426 | isNoreturn = isNoreturn || q->isNoreturn;
|
---|
427 | if ( storageClass == NoStorageClass ) {
|
---|
428 | storageClass = q->storageClass;
|
---|
429 | } else if ( q->storageClass != NoStorageClass ) {
|
---|
430 | q->error = "invalid combination of storage classes in declaration of ";
|
---|
431 | } // if
|
---|
432 | if ( error.empty() ) error = q->error;
|
---|
433 | return this;
|
---|
434 | }
|
---|
435 |
|
---|
436 | static void addTypeToType( TypeData *&src, TypeData *&dst ) {
|
---|
437 | if ( src && dst ) {
|
---|
438 | if ( src->forall && dst->kind == TypeData::Function ) {
|
---|
439 | if ( dst->forall ) {
|
---|
440 | dst->forall->appendList( src->forall );
|
---|
441 | } else {
|
---|
442 | dst->forall = src->forall;
|
---|
443 | } // if
|
---|
444 | src->forall = 0;
|
---|
445 | } // if
|
---|
446 | if ( dst->base ) {
|
---|
447 | addTypeToType( src, dst->base );
|
---|
448 | } else {
|
---|
449 | switch ( dst->kind ) {
|
---|
450 | case TypeData::Unknown:
|
---|
451 | src->qualifiers |= dst->qualifiers;
|
---|
452 | dst = src;
|
---|
453 | src = 0;
|
---|
454 | break;
|
---|
455 | case TypeData::Basic:
|
---|
456 | dst->qualifiers |= src->qualifiers;
|
---|
457 | if ( src->kind != TypeData::Unknown ) {
|
---|
458 | assert( src->kind == TypeData::Basic );
|
---|
459 | dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
|
---|
460 | dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
|
---|
461 | } // if
|
---|
462 | break;
|
---|
463 | default:
|
---|
464 | switch ( src->kind ) {
|
---|
465 | case TypeData::Aggregate:
|
---|
466 | case TypeData::Enum:
|
---|
467 | dst->base = new TypeData( TypeData::AggregateInst );
|
---|
468 | dst->base->aggInst.aggregate = src;
|
---|
469 | if ( src->kind == TypeData::Aggregate ) {
|
---|
470 | dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
|
---|
471 | } // if
|
---|
472 | dst->base->qualifiers |= src->qualifiers;
|
---|
473 | src = 0;
|
---|
474 | break;
|
---|
475 | default:
|
---|
476 | if ( dst->forall ) {
|
---|
477 | dst->forall->appendList( src->forall );
|
---|
478 | } else {
|
---|
479 | dst->forall = src->forall;
|
---|
480 | } // if
|
---|
481 | src->forall = 0;
|
---|
482 | dst->base = src;
|
---|
483 | src = 0;
|
---|
484 | } // switch
|
---|
485 | } // switch
|
---|
486 | } // if
|
---|
487 | } // if
|
---|
488 | }
|
---|
489 |
|
---|
490 | DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
|
---|
491 | if ( o ) {
|
---|
492 | copyStorageClasses( o );
|
---|
493 | if ( o->type ) {
|
---|
494 | if ( ! type ) {
|
---|
495 | if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
|
---|
496 | type = new TypeData( TypeData::AggregateInst );
|
---|
497 | type->aggInst.aggregate = o->type;
|
---|
498 | if ( o->type->kind == TypeData::Aggregate ) {
|
---|
499 | type->aggInst.params = maybeClone( o->type->aggregate.actuals );
|
---|
500 | } // if
|
---|
501 | type->qualifiers |= o->type->qualifiers;
|
---|
502 | } else {
|
---|
503 | type = o->type;
|
---|
504 | } // if
|
---|
505 | o->type = 0;
|
---|
506 | } else {
|
---|
507 | addTypeToType( o->type, type );
|
---|
508 | } // if
|
---|
509 | } // if
|
---|
510 | if ( o->bitfieldWidth ) {
|
---|
511 | bitfieldWidth = o->bitfieldWidth;
|
---|
512 | } // if
|
---|
513 |
|
---|
514 | // there may be typedefs chained onto the type
|
---|
515 | if ( o->get_next() ) {
|
---|
516 | set_last( o->get_next()->clone() );
|
---|
517 | } // if
|
---|
518 | } // if
|
---|
519 | delete o;
|
---|
520 | return this;
|
---|
521 | }
|
---|
522 |
|
---|
523 | DeclarationNode *DeclarationNode::addTypedef() {
|
---|
524 | TypeData *newtype = new TypeData( TypeData::Symbolic );
|
---|
525 | newtype->symbolic.params = 0;
|
---|
526 | newtype->symbolic.isTypedef = true;
|
---|
527 | newtype->symbolic.name = name;
|
---|
528 | newtype->base = type;
|
---|
529 | type = newtype;
|
---|
530 | return this;
|
---|
531 | }
|
---|
532 |
|
---|
533 | DeclarationNode *DeclarationNode::addAssertions( DeclarationNode *assertions ) {
|
---|
534 | assert( type );
|
---|
535 | switch ( type->kind ) {
|
---|
536 | case TypeData::Symbolic:
|
---|
537 | if ( type->symbolic.assertions ) {
|
---|
538 | type->symbolic.assertions->appendList( assertions );
|
---|
539 | } else {
|
---|
540 | type->symbolic.assertions = assertions;
|
---|
541 | } // if
|
---|
542 | break;
|
---|
543 | case TypeData::Variable:
|
---|
544 | if ( type->variable.assertions ) {
|
---|
545 | type->variable.assertions->appendList( assertions );
|
---|
546 | } else {
|
---|
547 | type->variable.assertions = assertions;
|
---|
548 | } // if
|
---|
549 | break;
|
---|
550 | default:
|
---|
551 | assert( false );
|
---|
552 | } // switch
|
---|
553 |
|
---|
554 | return this;
|
---|
555 | }
|
---|
556 |
|
---|
557 | DeclarationNode *DeclarationNode::addName( std::string *newname ) {
|
---|
558 | name = assign_strptr( newname );
|
---|
559 | return this;
|
---|
560 | }
|
---|
561 |
|
---|
562 | DeclarationNode *DeclarationNode::addBitfield( ExpressionNode *size ) {
|
---|
563 | bitfieldWidth = size;
|
---|
564 | return this;
|
---|
565 | }
|
---|
566 |
|
---|
567 | DeclarationNode *DeclarationNode::addVarArgs() {
|
---|
568 | assert( type );
|
---|
569 | hasEllipsis = true;
|
---|
570 | return this;
|
---|
571 | }
|
---|
572 |
|
---|
573 | DeclarationNode *DeclarationNode::addFunctionBody( StatementNode *body ) {
|
---|
574 | assert( type );
|
---|
575 | assert( type->kind == TypeData::Function );
|
---|
576 | assert( type->function.body == 0 );
|
---|
577 | type->function.body = body;
|
---|
578 | type->function.hasBody = true;
|
---|
579 | return this;
|
---|
580 | }
|
---|
581 |
|
---|
582 | DeclarationNode *DeclarationNode::addOldDeclList( DeclarationNode *list ) {
|
---|
583 | assert( type );
|
---|
584 | assert( type->kind == TypeData::Function );
|
---|
585 | assert( type->function.oldDeclList == 0 );
|
---|
586 | type->function.oldDeclList = list;
|
---|
587 | return this;
|
---|
588 | }
|
---|
589 |
|
---|
590 | static void setBase( TypeData *&type, TypeData *newType ) {
|
---|
591 | if ( type ) {
|
---|
592 | TypeData *prevBase = type;
|
---|
593 | TypeData *curBase = type->base;
|
---|
594 | while ( curBase != 0 ) {
|
---|
595 | prevBase = curBase;
|
---|
596 | curBase = curBase->base;
|
---|
597 | } // while
|
---|
598 | prevBase->base = newType;
|
---|
599 | } else {
|
---|
600 | type = newType;
|
---|
601 | } // if
|
---|
602 | }
|
---|
603 |
|
---|
604 | DeclarationNode *DeclarationNode::addPointer( DeclarationNode *p ) {
|
---|
605 | if ( p ) {
|
---|
606 | assert( p->type->kind == TypeData::Pointer );
|
---|
607 | setBase( type, p->type );
|
---|
608 | p->type = 0;
|
---|
609 | delete p;
|
---|
610 | } // if
|
---|
611 | return this;
|
---|
612 | }
|
---|
613 |
|
---|
614 | DeclarationNode *DeclarationNode::addArray( DeclarationNode *a ) {
|
---|
615 | if ( a ) {
|
---|
616 | assert( a->type->kind == TypeData::Array );
|
---|
617 | setBase( type, a->type );
|
---|
618 | a->type = 0;
|
---|
619 | delete a;
|
---|
620 | } // if
|
---|
621 | return this;
|
---|
622 | }
|
---|
623 |
|
---|
624 | DeclarationNode *DeclarationNode::addNewPointer( DeclarationNode *p ) {
|
---|
625 | if ( p ) {
|
---|
626 | assert( p->type->kind == TypeData::Pointer );
|
---|
627 | if ( type ) {
|
---|
628 | switch ( type->kind ) {
|
---|
629 | case TypeData::Aggregate:
|
---|
630 | case TypeData::Enum:
|
---|
631 | p->type->base = new TypeData( TypeData::AggregateInst );
|
---|
632 | p->type->base->aggInst.aggregate = type;
|
---|
633 | if ( type->kind == TypeData::Aggregate ) {
|
---|
634 | p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
|
---|
635 | } // if
|
---|
636 | p->type->base->qualifiers |= type->qualifiers;
|
---|
637 | break;
|
---|
638 |
|
---|
639 | default:
|
---|
640 | p->type->base = type;
|
---|
641 | } // switch
|
---|
642 | type = 0;
|
---|
643 | } // if
|
---|
644 | delete this;
|
---|
645 | return p;
|
---|
646 | } else {
|
---|
647 | return this;
|
---|
648 | } // if
|
---|
649 | }
|
---|
650 |
|
---|
651 | static TypeData *findLast( TypeData *a ) {
|
---|
652 | assert( a );
|
---|
653 | TypeData *cur = a;
|
---|
654 | while ( cur->base ) {
|
---|
655 | cur = cur->base;
|
---|
656 | } // while
|
---|
657 | return cur;
|
---|
658 | }
|
---|
659 |
|
---|
660 | DeclarationNode *DeclarationNode::addNewArray( DeclarationNode *a ) {
|
---|
661 | if ( a ) {
|
---|
662 | assert( a->type->kind == TypeData::Array );
|
---|
663 | TypeData *lastArray = findLast( a->type );
|
---|
664 | if ( type ) {
|
---|
665 | switch ( type->kind ) {
|
---|
666 | case TypeData::Aggregate:
|
---|
667 | case TypeData::Enum:
|
---|
668 | lastArray->base = new TypeData( TypeData::AggregateInst );
|
---|
669 | lastArray->base->aggInst.aggregate = type;
|
---|
670 | if ( type->kind == TypeData::Aggregate ) {
|
---|
671 | lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
|
---|
672 | } // if
|
---|
673 | lastArray->base->qualifiers |= type->qualifiers;
|
---|
674 | break;
|
---|
675 | default:
|
---|
676 | lastArray->base = type;
|
---|
677 | } // switch
|
---|
678 | type = 0;
|
---|
679 | } // if
|
---|
680 | delete this;
|
---|
681 | return a;
|
---|
682 | } else {
|
---|
683 | return this;
|
---|
684 | } // if
|
---|
685 | }
|
---|
686 |
|
---|
687 | DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
|
---|
688 | TypeData *ftype = new TypeData( TypeData::Function );
|
---|
689 | ftype->function.params = params;
|
---|
690 | setBase( type, ftype );
|
---|
691 | return this;
|
---|
692 | }
|
---|
693 |
|
---|
694 | static TypeData *addIdListToType( TypeData *type, DeclarationNode *ids ) {
|
---|
695 | if ( type ) {
|
---|
696 | if ( type->kind != TypeData::Function ) {
|
---|
697 | type->base = addIdListToType( type->base, ids );
|
---|
698 | } else {
|
---|
699 | type->function.idList = ids;
|
---|
700 | } // if
|
---|
701 | return type;
|
---|
702 | } else {
|
---|
703 | TypeData *newtype = new TypeData( TypeData::Function );
|
---|
704 | newtype->function.idList = ids;
|
---|
705 | return newtype;
|
---|
706 | } // if
|
---|
707 | }
|
---|
708 |
|
---|
709 | DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
|
---|
710 | type = addIdListToType( type, ids );
|
---|
711 | return this;
|
---|
712 | }
|
---|
713 |
|
---|
714 | DeclarationNode *DeclarationNode::addInitializer( InitializerNode *init ) {
|
---|
715 | //assert
|
---|
716 | initializer = init;
|
---|
717 | return this;
|
---|
718 | }
|
---|
719 |
|
---|
720 | DeclarationNode *DeclarationNode::cloneBaseType( string *newName ) {
|
---|
721 | DeclarationNode *newnode = new DeclarationNode;
|
---|
722 | TypeData *srcType = type;
|
---|
723 | while ( srcType->base ) {
|
---|
724 | srcType = srcType->base;
|
---|
725 | } // while
|
---|
726 | newnode->type = maybeClone( srcType );
|
---|
727 | if ( newnode->type->kind == TypeData::AggregateInst ) {
|
---|
728 | // don't duplicate members
|
---|
729 | if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {
|
---|
730 | delete newnode->type->aggInst.aggregate->enumeration.constants;
|
---|
731 | newnode->type->aggInst.aggregate->enumeration.constants = 0;
|
---|
732 | } else {
|
---|
733 | assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );
|
---|
734 | delete newnode->type->aggInst.aggregate->aggregate.fields;
|
---|
735 | newnode->type->aggInst.aggregate->aggregate.fields = 0;
|
---|
736 | } // if
|
---|
737 | } // if
|
---|
738 | newnode->type->forall = maybeClone( type->forall );
|
---|
739 | newnode->copyStorageClasses( this );
|
---|
740 | newnode->name = assign_strptr( newName );
|
---|
741 | return newnode;
|
---|
742 | }
|
---|
743 |
|
---|
744 | DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
|
---|
745 | if ( o ) {
|
---|
746 | o->copyStorageClasses( this );
|
---|
747 | if ( type ) {
|
---|
748 | TypeData *srcType = type;
|
---|
749 | while ( srcType->base ) {
|
---|
750 | srcType = srcType->base;
|
---|
751 | } // while
|
---|
752 | TypeData *newType = srcType->clone();
|
---|
753 | if ( newType->kind == TypeData::AggregateInst ) {
|
---|
754 | // don't duplicate members
|
---|
755 | if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
|
---|
756 | delete newType->aggInst.aggregate->enumeration.constants;
|
---|
757 | newType->aggInst.aggregate->enumeration.constants = 0;
|
---|
758 | } else {
|
---|
759 | assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
|
---|
760 | delete newType->aggInst.aggregate->aggregate.fields;
|
---|
761 | newType->aggInst.aggregate->aggregate.fields = 0;
|
---|
762 | } // if
|
---|
763 | } // if
|
---|
764 | newType->forall = maybeClone( type->forall );
|
---|
765 | if ( ! o->type ) {
|
---|
766 | o->type = newType;
|
---|
767 | } else {
|
---|
768 | addTypeToType( newType, o->type );
|
---|
769 | delete newType;
|
---|
770 | } // if
|
---|
771 | } // if
|
---|
772 | } // if
|
---|
773 | return o;
|
---|
774 | }
|
---|
775 |
|
---|
776 | DeclarationNode *DeclarationNode::cloneType( string *newName ) {
|
---|
777 | DeclarationNode *newnode = new DeclarationNode;
|
---|
778 | newnode->type = maybeClone( type );
|
---|
779 | newnode->copyStorageClasses( this );
|
---|
780 | newnode->name = assign_strptr( newName );
|
---|
781 | return newnode;
|
---|
782 | }
|
---|
783 |
|
---|
784 | DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
|
---|
785 | if ( o ) {
|
---|
786 | o->copyStorageClasses( this );
|
---|
787 | if ( type ) {
|
---|
788 | TypeData *newType = type->clone();
|
---|
789 | if ( ! o->type ) {
|
---|
790 | o->type = newType;
|
---|
791 | } else {
|
---|
792 | addTypeToType( newType, o->type );
|
---|
793 | delete newType;
|
---|
794 | } // if
|
---|
795 | } // if
|
---|
796 | } // if
|
---|
797 | delete o;
|
---|
798 | return o;
|
---|
799 | }
|
---|
800 |
|
---|
801 | DeclarationNode *DeclarationNode::extractAggregate() const {
|
---|
802 | if ( type ) {
|
---|
803 | TypeData *ret = typeextractAggregate( type );
|
---|
804 | if ( ret ) {
|
---|
805 | DeclarationNode *newnode = new DeclarationNode;
|
---|
806 | newnode->type = ret;
|
---|
807 | return newnode;
|
---|
808 | } // if
|
---|
809 | } // if
|
---|
810 | return 0;
|
---|
811 | }
|
---|
812 |
|
---|
813 | void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
|
---|
814 | SemanticError errors;
|
---|
815 | std::back_insert_iterator< std::list< Declaration * > > out( outputList );
|
---|
816 | const DeclarationNode *cur = firstNode;
|
---|
817 | while ( cur ) {
|
---|
818 | try {
|
---|
819 | if ( DeclarationNode *extr = cur->extractAggregate() ) {
|
---|
820 | // handle the case where a structure declaration is contained within an object or type declaration
|
---|
821 | Declaration *decl = extr->build();
|
---|
822 | if ( decl ) {
|
---|
823 | *out++ = decl;
|
---|
824 | } // if
|
---|
825 | delete extr;
|
---|
826 | } // if
|
---|
827 | Declaration *decl = cur->build();
|
---|
828 | if ( decl ) {
|
---|
829 | *out++ = decl;
|
---|
830 | } // if
|
---|
831 | } catch( SemanticError &e ) {
|
---|
832 | errors.append( e );
|
---|
833 | } // try
|
---|
834 | cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
|
---|
835 | } // while
|
---|
836 | if ( ! errors.isEmpty() ) {
|
---|
837 | throw errors;
|
---|
838 | } // if
|
---|
839 | }
|
---|
840 |
|
---|
841 | void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {
|
---|
842 | SemanticError errors;
|
---|
843 | std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
|
---|
844 | const DeclarationNode *cur = firstNode;
|
---|
845 | while ( cur ) {
|
---|
846 | try {
|
---|
847 | /// if ( DeclarationNode *extr = cur->extractAggregate() ) {
|
---|
848 | /// // handle the case where a structure declaration is contained within an object or type
|
---|
849 | /// // declaration
|
---|
850 | /// Declaration *decl = extr->build();
|
---|
851 | /// if ( decl ) {
|
---|
852 | /// *out++ = decl;
|
---|
853 | /// }
|
---|
854 | /// }
|
---|
855 | Declaration *decl = cur->build();
|
---|
856 | if ( decl ) {
|
---|
857 | if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
|
---|
858 | *out++ = dwt;
|
---|
859 | } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {
|
---|
860 | StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
|
---|
861 | *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
|
---|
862 | delete agg;
|
---|
863 | } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {
|
---|
864 | UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
|
---|
865 | *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
|
---|
866 | } // if
|
---|
867 | } // if
|
---|
868 | } catch( SemanticError &e ) {
|
---|
869 | errors.append( e );
|
---|
870 | } // try
|
---|
871 | cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
|
---|
872 | } // while
|
---|
873 | if ( ! errors.isEmpty() ) {
|
---|
874 | throw errors;
|
---|
875 | } // if
|
---|
876 | }
|
---|
877 |
|
---|
878 | void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {
|
---|
879 | SemanticError errors;
|
---|
880 | std::back_insert_iterator< std::list< Type * > > out( outputList );
|
---|
881 | const DeclarationNode *cur = firstNode;
|
---|
882 | while ( cur ) {
|
---|
883 | try {
|
---|
884 | *out++ = cur->buildType();
|
---|
885 | } catch( SemanticError &e ) {
|
---|
886 | errors.append( e );
|
---|
887 | } // try
|
---|
888 | cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
|
---|
889 | } // while
|
---|
890 | if ( ! errors.isEmpty() ) {
|
---|
891 | throw errors;
|
---|
892 | } // if
|
---|
893 | }
|
---|
894 |
|
---|
895 | Declaration *DeclarationNode::build() const {
|
---|
896 | if ( ! error.empty() ) throw SemanticError( error, this );
|
---|
897 | if ( type ) {
|
---|
898 | return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
|
---|
899 | } // if
|
---|
900 | if ( ! isInline && ! isNoreturn ) {
|
---|
901 | return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
|
---|
902 | } // if
|
---|
903 | throw SemanticError( "invalid function specifier in declaration of ", this );
|
---|
904 | }
|
---|
905 |
|
---|
906 | Type *DeclarationNode::buildType() const {
|
---|
907 | assert( type );
|
---|
908 |
|
---|
909 | switch ( type->kind ) {
|
---|
910 | case TypeData::Enum:
|
---|
911 | return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
|
---|
912 | case TypeData::Aggregate: {
|
---|
913 | ReferenceToType *ret;
|
---|
914 | switch ( type->aggregate.kind ) {
|
---|
915 | case DeclarationNode::Struct:
|
---|
916 | ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
|
---|
917 | break;
|
---|
918 | case DeclarationNode::Union:
|
---|
919 | ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
|
---|
920 | break;
|
---|
921 | case DeclarationNode::Trait:
|
---|
922 | ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
|
---|
923 | break;
|
---|
924 | default:
|
---|
925 | assert( false );
|
---|
926 | } // switch
|
---|
927 | buildList( type->aggregate.actuals, ret->get_parameters() );
|
---|
928 | return ret;
|
---|
929 | }
|
---|
930 | case TypeData::Symbolic: {
|
---|
931 | TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
|
---|
932 | buildList( type->symbolic.actuals, ret->get_parameters() );
|
---|
933 | return ret;
|
---|
934 | }
|
---|
935 | default:
|
---|
936 | return typebuild( type );
|
---|
937 | } // switch
|
---|
938 | }
|
---|
939 |
|
---|
940 | // DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
|
---|
941 | // DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
|
---|
942 | // for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
|
---|
943 | // if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
|
---|
944 | // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?
|
---|
945 | // throw SemanticError( "invalid combination of storage classes in declaration of ", this );
|
---|
946 | // } // if
|
---|
947 | // ret = *i;
|
---|
948 | // } // for
|
---|
949 | // return ret;
|
---|
950 | // }
|
---|
951 |
|
---|
952 | // bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
|
---|
953 | // std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
|
---|
954 | // if ( first == storageClasses.end() ) return false; // not found
|
---|
955 | // first = std::find( ++first, storageClasses.end(), key ); // found
|
---|
956 | // if ( first == storageClasses.end() ) return true; // not found again
|
---|
957 | // throw SemanticError( "duplicate function specifier in declaration of ", this );
|
---|
958 | // }
|
---|
959 |
|
---|
960 | // Local Variables: //
|
---|
961 | // tab-width: 4 //
|
---|
962 | // mode: c++ //
|
---|
963 | // compile-command: "make install" //
|
---|
964 | // End: //
|
---|