source: src/Parser/DeclarationNode.cc @ 692c1cc

ADTast-experimental
Last change on this file since 692c1cc was 692c1cc, checked in by Peter A. Buhr <pabuhr@…>, 15 months ago

update printing attributes, clean up anon flag setting, move attribute transparent_union from typedef to its union alias

  • Property mode set to 100644
File size: 42.7 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// 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 : Thu Feb 16 14:12:03 2023
13// Update Count     : 1388
14//
15
16#include <cassert>                 // for assert, assertf, strict_dynamic_cast
17#include <iterator>                // for back_insert_iterator
18#include <list>                    // for list
19#include <memory>                  // for unique_ptr
20#include <ostream>                 // for operator<<, ostream, basic_ostream
21#include <string>                  // for string, operator+, allocator, char...
22
23#include "Common/SemanticError.h"  // for SemanticError
24#include "Common/UniqueName.h"     // for UniqueName
25#include "Common/utility.h"        // for maybeClone, maybeBuild, CodeLocation
26#include "Parser/ParseNode.h"      // for DeclarationNode, ExpressionNode
27#include "SynTree/LinkageSpec.h"   // for Spec, linkageName, Cforall
28#include "SynTree/Attribute.h"     // for Attribute
29#include "SynTree/Declaration.h"   // for TypeDecl, ObjectDecl, InlineMemberDecl, Declaration
30#include "SynTree/Expression.h"    // for Expression, ConstantExpr
31#include "SynTree/Statement.h"     // for AsmStmt
32#include "SynTree/Type.h"          // for Type, Type::StorageClasses, Type::...
33#include "TypeData.h"              // for TypeData, TypeData::Aggregate_t
34#include "TypedefTable.h"          // for TypedefTable
35
36class Initializer;
37
38extern TypedefTable typedefTable;
39
40using namespace std;
41
42// These must harmonize with the corresponding DeclarationNode enumerations.
43const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "int128",
44                                                                                                   "float", "double", "long double", "float80", "float128",
45                                                                                                   "_float16", "_float32", "_float32x", "_float64", "_float64x", "_float128", "_float128x", "NoBasicTypeNames" };
46const char * DeclarationNode::complexTypeNames[] = { "_Complex", "NoComplexTypeNames", "_Imaginary" }; // Imaginary unsupported => parse, but make invisible and print error message
47const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
48const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
49const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" };
50
51UniqueName DeclarationNode::anonymous( "__anonymous" );
52
53extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
54
55DeclarationNode::DeclarationNode() :
56        linkage( ::linkage ) {
57
58//      variable.name = nullptr;
59        variable.tyClass = TypeDecl::NUMBER_OF_KINDS;
60        variable.assertions = nullptr;
61        variable.initializer = nullptr;
62
63//      attr.name = nullptr;
64        attr.expr = nullptr;
65        attr.type = nullptr;
66
67        assert.condition = nullptr;
68        assert.message = nullptr;
69}
70
71DeclarationNode::~DeclarationNode() {
72//      delete attr.name;
73        delete attr.expr;
74        delete attr.type;
75
76//      delete variable.name;
77        delete variable.assertions;
78        delete variable.initializer;
79
80//      delete type;
81        delete bitfieldWidth;
82
83        delete asmStmt;
84        // asmName, no delete, passed to next stage
85        delete initializer;
86
87        delete assert.condition;
88        delete assert.message;
89}
90
91DeclarationNode * DeclarationNode::clone() const {
92        DeclarationNode * newnode = new DeclarationNode;
93        newnode->set_next( maybeClone( get_next() ) );
94        newnode->name = name ? new string( *name ) : nullptr;
95
96        newnode->builtin = NoBuiltinType;
97        newnode->type = maybeClone( type );
98        newnode->inLine = inLine;
99        newnode->storageClasses = storageClasses;
100        newnode->funcSpecs = funcSpecs;
101        newnode->bitfieldWidth = maybeClone( bitfieldWidth );
102        newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) );
103        newnode->hasEllipsis = hasEllipsis;
104        newnode->linkage = linkage;
105        newnode->asmName = maybeClone( asmName );
106        cloneAll( attributes, newnode->attributes );
107        newnode->initializer = maybeClone( initializer );
108        newnode->extension = extension;
109        newnode->asmStmt = maybeClone( asmStmt );
110        newnode->error = error;
111
112//      newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
113        newnode->variable.tyClass = variable.tyClass;
114        newnode->variable.assertions = maybeClone( variable.assertions );
115        newnode->variable.initializer = maybeClone( variable.initializer );
116
117//      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
118        newnode->attr.expr = maybeClone( attr.expr );
119        newnode->attr.type = maybeClone( attr.type );
120
121        newnode->assert.condition = maybeClone( assert.condition );
122        newnode->assert.message = maybeClone( assert.message );
123        return newnode;
124} // DeclarationNode::clone
125
126void DeclarationNode::print( std::ostream & os, int indent ) const {
127        os << string( indent, ' ' );
128        if ( name ) {
129                os << *name << ": ";
130        } // if
131
132        if ( linkage != LinkageSpec::Cforall ) {
133                os << LinkageSpec::name( linkage ) << " ";
134        } // if
135
136        storageClasses.print( os );
137        funcSpecs.print( os );
138
139        if ( type ) {
140                type->print( os, indent );
141        } else {
142                os << "untyped entity ";
143        } // if
144
145        if ( bitfieldWidth ) {
146                os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
147                bitfieldWidth->printOneLine( os );
148        } // if
149
150        if ( initializer ) {
151                os << endl << string( indent + 2, ' ' ) << "with initializer ";
152                initializer->printOneLine( os );
153                os << " maybe constructed? " << initializer->get_maybeConstructed();
154        } // if
155
156        if ( ! attributes.empty() ) {
157                os << string( indent + 2, ' ' ) << "with attributes " << endl;
158                for ( Attribute * attr: reverseIterate( attributes ) ) {
159                        os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
160                } // for
161        } // if
162
163        os << endl;
164}
165
166void DeclarationNode::printList( std::ostream & os, int indent ) const {
167        ParseNode::printList( os, indent );
168        if ( hasEllipsis ) {
169                os << string( indent, ' ' )  << "and a variable number of other arguments" << endl;
170        } // if
171}
172
173DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) {
174        DeclarationNode * newnode = new DeclarationNode;
175        newnode->storageClasses = sc;
176        return newnode;
177} // DeclarationNode::newStorageClass
178
179DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) {
180        DeclarationNode * newnode = new DeclarationNode;
181        newnode->funcSpecs = fs;
182        return newnode;
183} // DeclarationNode::newFuncSpecifier
184
185DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) {
186        DeclarationNode * newnode = new DeclarationNode;
187        newnode->type = new TypeData();
188        newnode->type->qualifiers = tq;
189        return newnode;
190} // DeclarationNode::newQualifier
191
192DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
193        DeclarationNode * newnode = new DeclarationNode;
194        newnode->type = new TypeData( TypeData::Basic );
195        newnode->type->basictype = bt;
196        return newnode;
197} // DeclarationNode::newBasicType
198
199DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
200        DeclarationNode * newnode = new DeclarationNode;
201        newnode->type = new TypeData( TypeData::Basic );
202        newnode->type->complextype = ct;
203        return newnode;
204} // DeclarationNode::newComplexType
205
206DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
207        DeclarationNode * newnode = new DeclarationNode;
208        newnode->type = new TypeData( TypeData::Basic );
209        newnode->type->signedness = sn;
210        return newnode;
211} // DeclarationNode::newSignedNess
212
213DeclarationNode * DeclarationNode::newLength( Length lnth ) {
214        DeclarationNode * newnode = new DeclarationNode;
215        newnode->type = new TypeData( TypeData::Basic );
216        newnode->type->length = lnth;
217        return newnode;
218} // DeclarationNode::newLength
219
220DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {
221        DeclarationNode * newnode = new DeclarationNode;
222        newnode->type = new TypeData( TypeData::Unknown );
223        newnode->type->forall = forall;
224        return newnode;
225} // DeclarationNode::newForall
226
227DeclarationNode * DeclarationNode::newFromGlobalScope() {
228        DeclarationNode * newnode = new DeclarationNode;
229        newnode->type = new TypeData( TypeData::GlobalScope );
230        return newnode;
231}
232
233DeclarationNode * DeclarationNode::newQualifiedType( DeclarationNode * parent, DeclarationNode * child) {
234        DeclarationNode * newnode = new DeclarationNode;
235        newnode->type = new TypeData( TypeData::Qualified );
236        newnode->type->qualified.parent = parent->type;
237        newnode->type->qualified.child = child->type;
238        parent->type = nullptr;
239        child->type = nullptr;
240        delete parent;
241        delete child;
242        return newnode;
243}
244
245DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
246        DeclarationNode * newnode = new DeclarationNode;
247        newnode->type = new TypeData( TypeData::Aggregate );
248        newnode->type->aggregate.kind = kind;
249        newnode->type->aggregate.anon = name == nullptr;
250        newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
251        newnode->type->aggregate.actuals = actuals;
252        newnode->type->aggregate.fields = fields;
253        newnode->type->aggregate.body = body;
254        newnode->type->aggregate.tagged = false;
255        newnode->type->aggregate.parent = nullptr;
256        return newnode;
257} // DeclarationNode::newAggregate
258
259DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base, EnumHiding hiding ) {
260        DeclarationNode * newnode = new DeclarationNode;
261        newnode->type = new TypeData( TypeData::Enum );
262        newnode->type->enumeration.anon = name == nullptr;
263        newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
264        newnode->type->enumeration.constants = constants;
265        newnode->type->enumeration.body = body;
266        newnode->type->enumeration.typed = typed;
267        newnode->type->enumeration.hiding = hiding;
268        if ( base && base->type)  {
269                newnode->type->base = base->type;
270        } // if
271
272        return newnode;
273} // DeclarationNode::newEnum
274
275
276
277DeclarationNode * DeclarationNode::newName( const string * name ) {
278        DeclarationNode * newnode = new DeclarationNode;
279        assert( ! newnode->name );
280        newnode->name = name;
281        return newnode;
282} // DeclarationNode::newName
283
284DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
285        DeclarationNode * newnode = newName( name );
286        newnode->enumeratorValue.reset( constant );
287        return newnode;
288} // DeclarationNode::newEnumConstant
289
290DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) {
291        if ( init ) {
292                if ( init->get_expression() ) {
293                        return newEnumConstant( name, init->get_expression() );
294                } else {
295                        DeclarationNode * newnode = newName( name );
296                        newnode->initializer = init;
297                        return newnode;
298                } // if
299        } else {
300                return newName( name );
301        } // if
302} // DeclarationNode::newEnumValueGeneric
303
304DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
305        DeclarationNode * newnode = newName( new std::string(name) );
306        newnode->enumInLine = true;
307        return newnode;
308}
309
310DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
311        DeclarationNode * newnode = new DeclarationNode;
312        newnode->type = new TypeData( TypeData::SymbolicInst );
313        newnode->type->symbolic.name = name;
314        newnode->type->symbolic.isTypedef = true;
315        newnode->type->symbolic.params = nullptr;
316        return newnode;
317} // DeclarationNode::newFromTypedef
318
319DeclarationNode * DeclarationNode::newFromTypeGen( const string * name, ExpressionNode * params ) {
320        DeclarationNode * newnode = new DeclarationNode;
321        newnode->type = new TypeData( TypeData::SymbolicInst );
322        newnode->type->symbolic.name = name;
323        newnode->type->symbolic.isTypedef = false;
324        newnode->type->symbolic.actuals = params;
325        return newnode;
326} // DeclarationNode::newFromTypeGen
327
328DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) {
329        DeclarationNode * newnode = newName( name );
330        newnode->type = nullptr;
331        newnode->variable.tyClass = tc;
332        newnode->variable.assertions = nullptr;
333        return newnode;
334} // DeclarationNode::newTypeParam
335
336DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
337        DeclarationNode * newnode = new DeclarationNode;
338        newnode->type = new TypeData( TypeData::Aggregate );
339        newnode->type->aggregate.name = name;
340        newnode->type->aggregate.kind = AggregateDecl::Trait;
341        newnode->type->aggregate.params = params;
342        newnode->type->aggregate.fields = asserts;
343        return newnode;
344} // DeclarationNode::newTrait
345
346DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
347        DeclarationNode * newnode = new DeclarationNode;
348        newnode->type = new TypeData( TypeData::AggregateInst );
349        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
350        newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;
351        newnode->type->aggInst.aggregate->aggregate.name = name;
352        newnode->type->aggInst.params = params;
353        return newnode;
354} // DeclarationNode::newTraitUse
355
356DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
357        DeclarationNode * newnode = newName( name );
358        newnode->type = new TypeData( TypeData::Symbolic );
359        newnode->type->symbolic.isTypedef = false;
360        newnode->type->symbolic.params = typeParams;
361        return newnode;
362} // DeclarationNode::newTypeDecl
363
364DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers, OperKinds kind ) {
365        DeclarationNode * newnode = new DeclarationNode;
366        newnode->type = new TypeData( kind == OperKinds::PointTo ? TypeData::Pointer : TypeData::Reference );
367        if ( kind == OperKinds::And ) {
368                // T && is parsed as 'And' operator rather than two references => add a second reference type
369                TypeData * td = new TypeData( TypeData::Reference );
370                td->base = newnode->type;
371                newnode->type = td;
372        }
373        if ( qualifiers ) {
374                return newnode->addQualifiers( qualifiers );
375        } else {
376                return newnode;
377        } // if
378} // DeclarationNode::newPointer
379
380DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
381        DeclarationNode * newnode = new DeclarationNode;
382        newnode->type = new TypeData( TypeData::Array );
383        newnode->type->array.dimension = size;
384        newnode->type->array.isStatic = isStatic;
385        if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
386                newnode->type->array.isVarLen = false;
387        } else {
388                newnode->type->array.isVarLen = true;
389        } // if
390        return newnode->addQualifiers( qualifiers );
391} // DeclarationNode::newArray
392
393DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
394        DeclarationNode * newnode = new DeclarationNode;
395        newnode->type = new TypeData( TypeData::Array );
396        newnode->type->array.dimension = nullptr;
397        newnode->type->array.isStatic = false;
398        newnode->type->array.isVarLen = true;
399        return newnode->addQualifiers( qualifiers );
400}
401
402DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
403        DeclarationNode * newnode = new DeclarationNode;
404        newnode->bitfieldWidth = size;
405        return newnode;
406}
407
408DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
409        DeclarationNode * newnode = new DeclarationNode;
410        newnode->type = new TypeData( TypeData::Tuple );
411        newnode->type->tuple = members;
412        return newnode;
413}
414
415DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr, bool basetypeof ) {
416        DeclarationNode * newnode = new DeclarationNode;
417        newnode->type = new TypeData( basetypeof ? TypeData::Basetypeof : TypeData::Typeof );
418        newnode->type->typeexpr = expr;
419        return newnode;
420}
421
422DeclarationNode * DeclarationNode::newVtableType( DeclarationNode * decl ) {
423        DeclarationNode * newnode = new DeclarationNode;
424        newnode->type = new TypeData( TypeData::Vtable );
425        newnode->setBase( decl->type );
426        return newnode;
427}
428
429DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
430        DeclarationNode * newnode = new DeclarationNode;
431        newnode->type = new TypeData( TypeData::Builtin );
432        newnode->builtin = bt;
433        newnode->type->builtintype = newnode->builtin;
434        return newnode;
435} // DeclarationNode::newBuiltinType
436
437DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
438        DeclarationNode * newnode = newName( name );
439        newnode->type = new TypeData( TypeData::Function );
440        newnode->type->function.params = param;
441        newnode->type->function.body = body;
442
443        if ( ret ) {
444                newnode->type->base = ret->type;
445                ret->type = nullptr;
446                delete ret;
447        } // if
448
449        return newnode;
450} // DeclarationNode::newFunction
451
452DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
453        DeclarationNode * newnode = new DeclarationNode;
454        newnode->type = nullptr;
455        std::list< Expression * > exprs;
456        buildList( expr, exprs );
457        newnode->attributes.push_back( new Attribute( *name, exprs ) );
458        delete name;
459        return newnode;
460}
461
462DeclarationNode * DeclarationNode::newDirectiveStmt( StatementNode * stmt ) {
463        DeclarationNode * newnode = new DeclarationNode;
464        newnode->directiveStmt = stmt;
465        return newnode;
466}
467
468DeclarationNode * DeclarationNode::newAsmStmt( StatementNode * stmt ) {
469        DeclarationNode * newnode = new DeclarationNode;
470        newnode->asmStmt = stmt;
471        return newnode;
472}
473
474DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) {
475        DeclarationNode * newnode = new DeclarationNode;
476        newnode->assert.condition = condition;
477        newnode->assert.message = message;
478        return newnode;
479}
480
481
482void appendError( string & dst, const string & src ) {
483        if ( src.empty() ) return;
484        if ( dst.empty() ) { dst = src; return; }
485        dst += ", " + src;
486} // appendError
487
488void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
489        const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
490
491        if ( (qsrc & qdst).any() ) {                                            // duplicates ?
492                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
493                        if ( qsrc[i] && qdst[i] ) {
494                                appendError( error, string( "duplicate " ) + Type::QualifiersNames[i] );
495                        } // if
496                } // for
497        } // for
498} // DeclarationNode::checkQualifiers
499
500void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
501        if ( (funcSpecs & src->funcSpecs).any() ) {                     // duplicates ?
502                for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates
503                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
504                                appendError( error, string( "duplicate " ) + Type::FuncSpecifiersNames[i] );
505                        } // if
506                } // for
507        } // if
508
509        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
510                if ( (storageClasses & src->storageClasses ).any() ) { // duplicates ?
511                        for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates
512                                if ( storageClasses[i] && src->storageClasses[i] ) {
513                                        appendError( error, string( "duplicate " ) + Type::StorageClassesNames[i] );
514                                } // if
515                        } // for
516                        // src is the new item being added and has a single bit
517                } else if ( ! src->storageClasses.is_threadlocal_any() ) { // conflict ?
518                        appendError( error, string( "conflicting " ) + Type::StorageClassesNames[storageClasses.ffs()] +
519                                                 " & " + Type::StorageClassesNames[src->storageClasses.ffs()] );
520                        src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
521                } // if
522        } // if
523
524        appendError( error, src->error );
525} // DeclarationNode::checkSpecifiers
526
527DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
528        funcSpecs |= q->funcSpecs;
529        storageClasses |= q->storageClasses;
530
531        for ( Attribute * attr: reverseIterate( q->attributes ) ) {
532                attributes.push_front( attr->clone() );
533        } // for
534        return this;
535} // DeclarationNode::copySpecifiers
536
537static void addQualifiersToType( TypeData *& src, TypeData * dst ) {
538        if ( dst->base ) {
539                addQualifiersToType( src, dst->base );
540        } else if ( dst->kind == TypeData::Function ) {
541                dst->base = src;
542                src = nullptr;
543        } else {
544                dst->qualifiers |= src->qualifiers;
545        } // if
546} // addQualifiersToType
547
548DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
549        if ( ! q ) { return this; }                                                     // empty qualifier
550
551        checkSpecifiers( q );
552        copySpecifiers( q );
553
554        if ( ! q->type ) { delete q; return this; }
555
556        if ( ! type ) {
557                type = q->type;                                                                 // reuse structure
558                q->type = nullptr;
559                delete q;
560                return this;
561        } // if
562
563        if ( q->type->forall ) {                                                        // forall qualifier ?
564                if ( type->forall ) {                                                   // polymorphic routine ?
565                        type->forall->appendList( q->type->forall ); // augment forall qualifier
566                } else {
567                        if ( type->kind == TypeData::Aggregate ) {      // struct/union ?
568                                if ( type->aggregate.params ) {                 // polymorphic ?
569                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
570                                } else {                                                                // not polymorphic
571                                        type->aggregate.params = q->type->forall; // set forall qualifier
572                                } // if
573                        } else {                                                                        // not polymorphic
574                                type->forall = q->type->forall;                 // make polymorphic routine
575                        } // if
576                } // if
577                q->type->forall = nullptr;                                              // forall qualifier moved
578        } // if
579
580        checkQualifiers( type, q->type );
581        if ( (builtin == Zero || builtin == One) && q->type->qualifiers.val != 0 && error.length() == 0 ) {
582                SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )], builtinTypeNames[builtin] );
583        } // if
584        addQualifiersToType( q->type, type );
585
586        delete q;
587        return this;
588} // addQualifiers
589
590static void addTypeToType( TypeData *& src, TypeData *& dst ) {
591        if ( src->forall && dst->kind == TypeData::Function ) {
592                if ( dst->forall ) {
593                        dst->forall->appendList( src->forall );
594                } else {
595                        dst->forall = src->forall;
596                } // if
597                src->forall = nullptr;
598        } // if
599        if ( dst->base ) {
600                addTypeToType( src, dst->base );
601        } else {
602                switch ( dst->kind ) {
603                  case TypeData::Unknown:
604                        src->qualifiers |= dst->qualifiers;
605                        dst = src;
606                        src = nullptr;
607                        break;
608                  case TypeData::Basic:
609                        dst->qualifiers |= src->qualifiers;
610                        if ( src->kind != TypeData::Unknown ) {
611                                assert( src->kind == TypeData::Basic );
612
613                                if ( dst->basictype == DeclarationNode::NoBasicType ) {
614                                        dst->basictype = src->basictype;
615                                } else if ( src->basictype != DeclarationNode::NoBasicType )
616                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
617
618                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
619                                        dst->complextype = src->complextype;
620                                } else if ( src->complextype != DeclarationNode::NoComplexType )
621                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
622
623                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
624                                        dst->signedness = src->signedness;
625                                } else if ( src->signedness != DeclarationNode::NoSignedness )
626                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
627
628                                if ( dst->length == DeclarationNode::NoLength ) {
629                                        dst->length = src->length;
630                                } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
631                                        dst->length = DeclarationNode::LongLong;
632                                } else if ( src->length != DeclarationNode::NoLength )
633                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
634                        } // if
635                        break;
636                  default:
637                        switch ( src->kind ) {
638                          case TypeData::Aggregate:
639                          case TypeData::Enum:
640                                dst->base = new TypeData( TypeData::AggregateInst );
641                                dst->base->aggInst.aggregate = src;
642                                if ( src->kind == TypeData::Aggregate ) {
643                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
644                                } // if
645                                dst->base->qualifiers |= src->qualifiers;
646                                src = nullptr;
647                                break;
648                          default:
649                                if ( dst->forall ) {
650                                        dst->forall->appendList( src->forall );
651                                } else {
652                                        dst->forall = src->forall;
653                                } // if
654                                src->forall = nullptr;
655                                dst->base = src;
656                                src = nullptr;
657                        } // switch
658                } // switch
659        } // if
660}
661
662DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
663        if ( o ) {
664                checkSpecifiers( o );
665                copySpecifiers( o );
666                if ( o->type ) {
667                        if ( ! type ) {
668                                if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
669                                        type = new TypeData( TypeData::AggregateInst );
670                                        type->aggInst.aggregate = o->type;
671                                        if ( o->type->kind == TypeData::Aggregate ) {
672                                                type->aggInst.hoistType = o->type->aggregate.body;
673                                                type->aggInst.params = maybeClone( o->type->aggregate.actuals );
674                                        } else {
675                                                type->aggInst.hoistType = o->type->enumeration.body;
676                                        } // if
677                                        type->qualifiers |= o->type->qualifiers;
678                                } else {
679                                        type = o->type;
680                                } // if
681                                o->type = nullptr;
682                        } else {
683                                addTypeToType( o->type, type );
684                        } // if
685                } // if
686                if ( o->bitfieldWidth ) {
687                        bitfieldWidth = o->bitfieldWidth;
688                } // if
689
690                // there may be typedefs chained onto the type
691                if ( o->get_next() ) {
692                        set_last( o->get_next()->clone() );
693                } // if
694        } // if
695        delete o;
696
697        return this;
698}
699
700DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
701        if ( o && o -> type)  {
702                type->base= o->type;
703        }
704        delete o;
705        return this;
706}
707
708DeclarationNode * DeclarationNode::addTypedef() {
709        TypeData * newtype = new TypeData( TypeData::Symbolic );
710        newtype->symbolic.params = nullptr;
711        newtype->symbolic.isTypedef = true;
712        newtype->symbolic.name = name ? new string( *name ) : nullptr;
713        newtype->base = type;
714        type = newtype;
715        return this;
716}
717
718DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
719        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
720                if ( variable.assertions ) {
721                        variable.assertions->appendList( assertions );
722                } else {
723                        variable.assertions = assertions;
724                } // if
725                return this;
726        } // if
727
728        assert( type );
729        switch ( type->kind ) {
730          case TypeData::Symbolic:
731                if ( type->symbolic.assertions ) {
732                        type->symbolic.assertions->appendList( assertions );
733                } else {
734                        type->symbolic.assertions = assertions;
735                } // if
736                break;
737          default:
738                assert( false );
739        } // switch
740
741        return this;
742}
743
744DeclarationNode * DeclarationNode::addName( string * newname ) {
745        assert( ! name );
746        name = newname;
747        return this;
748}
749
750DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
751        assert( ! asmName );
752        asmName = newname ? newname->asmName : nullptr;
753        return this->addQualifiers( newname );
754}
755
756DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
757        bitfieldWidth = size;
758        return this;
759}
760
761DeclarationNode * DeclarationNode::addVarArgs() {
762        assert( type );
763        hasEllipsis = true;
764        return this;
765}
766
767DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, ExpressionNode * withExprs ) {
768        assert( type );
769        assert( type->kind == TypeData::Function );
770        assert( ! type->function.body );
771        type->function.body = body;
772        type->function.withExprs = withExprs;
773        return this;
774}
775
776DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
777        assert( type );
778        assert( type->kind == TypeData::Function );
779        assert( ! type->function.oldDeclList );
780        type->function.oldDeclList = list;
781        return this;
782}
783
784DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
785        if ( type ) {
786                TypeData * prevBase = type;
787                TypeData * curBase = type->base;
788                while ( curBase != nullptr ) {
789                        prevBase = curBase;
790                        curBase = curBase->base;
791                } // while
792                prevBase->base = newType;
793        } else {
794                type = newType;
795        } // if
796        return this;
797}
798
799DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
800        if ( a ) {
801                for ( Attribute *attr: reverseIterate( a->attributes ) ) {
802                        attributes.push_front( attr );
803                } // for
804                a->attributes.clear();
805        } // if
806        return this;
807} // copyAttribute
808
809DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
810        if ( p ) {
811                assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
812                setBase( p->type );
813                p->type = nullptr;
814                copyAttribute( p );
815                delete p;
816        } // if
817        return this;
818}
819
820DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
821        if ( a ) {
822                assert( a->type->kind == TypeData::Array );
823                setBase( a->type );
824                a->type = nullptr;
825                copyAttribute( a );
826                delete a;
827        } // if
828        return this;
829}
830
831DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
832        if ( p ) {
833                assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
834                if ( type ) {
835                        switch ( type->kind ) {
836                          case TypeData::Aggregate:
837                          case TypeData::Enum:
838                                p->type->base = new TypeData( TypeData::AggregateInst );
839                                p->type->base->aggInst.aggregate = type;
840                                if ( type->kind == TypeData::Aggregate ) {
841                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
842                                } // if
843                                p->type->base->qualifiers |= type->qualifiers;
844                                break;
845
846                          default:
847                                p->type->base = type;
848                        } // switch
849                        type = nullptr;
850                } // if
851                delete this;
852                return p;
853        } else {
854                return this;
855        } // if
856}
857
858static TypeData * findLast( TypeData * a ) {
859        assert( a );
860        TypeData * cur = a;
861        while ( cur->base ) {
862                cur = cur->base;
863        } // while
864        return cur;
865}
866
867DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
868  if ( ! a ) return this;
869        assert( a->type->kind == TypeData::Array );
870        TypeData * lastArray = findLast( a->type );
871        if ( type ) {
872                switch ( type->kind ) {
873                  case TypeData::Aggregate:
874                  case TypeData::Enum:
875                        lastArray->base = new TypeData( TypeData::AggregateInst );
876                        lastArray->base->aggInst.aggregate = type;
877                        if ( type->kind == TypeData::Aggregate ) {
878                                lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
879                        } // if
880                        lastArray->base->qualifiers |= type->qualifiers;
881                        break;
882                  default:
883                        lastArray->base = type;
884                } // switch
885                type = nullptr;
886        } // if
887        delete this;
888        return a;
889}
890
891DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
892        TypeData * ftype = new TypeData( TypeData::Function );
893        ftype->function.params = params;
894        setBase( ftype );
895        return this;
896}
897
898static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
899        if ( type ) {
900                if ( type->kind != TypeData::Function ) {
901                        type->base = addIdListToType( type->base, ids );
902                } else {
903                        type->function.idList = ids;
904                } // if
905                return type;
906        } else {
907                TypeData * newtype = new TypeData( TypeData::Function );
908                newtype->function.idList = ids;
909                return newtype;
910        } // if
911} // addIdListToType
912
913DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
914        type = addIdListToType( type, ids );
915        return this;
916}
917
918DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
919        initializer = init;
920        return this;
921}
922
923DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
924        assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
925        variable.initializer = init;
926        return this;
927}
928
929DeclarationNode * DeclarationNode::cloneType( string * name ) {
930        DeclarationNode * newnode = newName( name );
931        newnode->type = maybeClone( type );
932        newnode->copySpecifiers( this );
933        return newnode;
934}
935
936DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
937        if ( ! o ) return nullptr;
938
939        o->copySpecifiers( this );
940        if ( type ) {
941                TypeData * srcType = type;
942
943                // search for the base type by scanning off pointers and array designators
944                while ( srcType->base ) {
945                        srcType = srcType->base;
946                } // while
947
948                TypeData * newType = srcType->clone();
949                if ( newType->kind == TypeData::AggregateInst ) {
950                        // don't duplicate members
951                        if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
952                                delete newType->aggInst.aggregate->enumeration.constants;
953                                newType->aggInst.aggregate->enumeration.constants = nullptr;
954                                newType->aggInst.aggregate->enumeration.body = false;
955                        } else {
956                                assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
957                                delete newType->aggInst.aggregate->aggregate.fields;
958                                newType->aggInst.aggregate->aggregate.fields = nullptr;
959                                newType->aggInst.aggregate->aggregate.body = false;
960                        } // if
961                        // don't hoist twice
962                        newType->aggInst.hoistType = false;
963                } // if
964
965                newType->forall = maybeClone( type->forall );
966                if ( ! o->type ) {
967                        o->type = newType;
968                } else {
969                        addTypeToType( newType, o->type );
970                        delete newType;
971                } // if
972        } // if
973        return o;
974}
975
976DeclarationNode * DeclarationNode::extractAggregate() const {
977        if ( type ) {
978                TypeData * ret = typeextractAggregate( type );
979                if ( ret ) {
980                        DeclarationNode * newnode = new DeclarationNode;
981                        newnode->type = ret;
982                        return newnode;
983                } // if
984        } // if
985        return nullptr;
986}
987
988void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) {
989        SemanticErrorException errors;
990        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
991
992        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
993                try {
994                        bool extracted = false, anon = false;
995                        AggregateDecl * unionDecl = nullptr;
996
997                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
998                                // handle the case where a structure declaration is contained within an object or type declaration
999
1000                                Declaration * decl = extr->build();
1001                                if ( decl ) {
1002                                        // Remember the declaration if it is a union aggregate ?
1003                                        unionDecl = dynamic_cast<UnionDecl *>( decl );
1004
1005                                        decl->location = cur->location;
1006                                        *out++ = decl;
1007
1008                                        // need to remember the cases where a declaration contains an anonymous aggregate definition
1009                                        extracted = true;
1010                                        assert( extr->type );
1011                                        if ( extr->type->kind == TypeData::Aggregate ) {
1012                                                // typedef struct { int A } B is the only case?
1013                                                anon = extr->type->aggregate.anon;
1014                                        } else if ( extr->type->kind == TypeData::Enum ) {
1015                                                // typedef enum { A } B is the only case?
1016                                                anon = extr->type->enumeration.anon;
1017                                        }
1018                                } // if
1019                                delete extr;
1020                        } // if
1021
1022                        Declaration * decl = cur->build();
1023                        if ( decl ) {
1024                                if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {
1025                                        if ( unionDecl ) {                                      // is the typedef alias a union aggregate ?
1026                                                // This code handles a special issue with the attribute transparent_union.
1027                                                //
1028                                                //    typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union ))
1029                                                //
1030                                                // Here the attribute aligned goes with the typedef_name, so variables declared of this type are
1031                                                // aligned.  However, the attribute transparent_union must be moved from the typedef_name to
1032                                                // alias union U.  Currently, this is the only know attribute that must be moved from typedef to
1033                                                // alias.
1034
1035                                                // If typedef is an alias for a union, then its alias type was hoisted above and remembered.
1036                                                if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) {
1037                                                        // Remove all transparent_union attributes from typedef and move to alias union.
1038                                                        list<Attribute *>::iterator attr;
1039                                                        for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order
1040                                                                if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
1041                                                                        list<Attribute *>::iterator cur = attr; // remember current node
1042                                                                        attr++;                         // advance iterator
1043                                                                        unionDecl->attributes.emplace_back( *cur ); // move current
1044                                                                        unionInstType->attributes.erase( cur ); // remove current
1045                                                                } else {
1046                                                                        attr++;                         // advance iterator
1047                                                                } // if
1048                                                        } // for
1049                                                } // if
1050                                        } // if
1051                                } // if
1052
1053                                // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.:
1054                                // struct S {
1055                                //   struct T { int x; }; // no anonymous member
1056                                //   struct { int y; };   // anonymous member
1057                                //   struct T;            // anonymous member
1058                                // };
1059                                if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) {
1060                                        if ( decl->name == "" ) {
1061                                                if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) {
1062                                                        if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType *>( dwt->get_type() ) ) {
1063                                                                if ( aggr->name.find("anonymous") == std::string::npos ) {
1064                                                                        if ( ! cur->get_inLine() ) {
1065                                                                                // temporary: warn about anonymous member declarations of named types, since
1066                                                                                // this conflicts with the syntax for the forward declaration of an anonymous type
1067                                                                                SemanticWarning( cur->location, Warning::AggrForwardDecl, aggr->name.c_str() );
1068                                                                        } // if
1069                                                                } // if
1070                                                        } // if
1071                                                } // if
1072                                        } // if
1073                                        decl->location = cur->location;
1074                                        *out++ = decl;
1075                                } // if
1076                        } // if
1077                } catch( SemanticErrorException & e ) {
1078                        errors.append( e );
1079                } // try
1080        } // for
1081
1082        if ( ! errors.isEmpty() ) {
1083                throw errors;
1084        } // if
1085} // buildList
1086
1087// currently only builds assertions, function parameters, and return values
1088void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) {
1089        SemanticErrorException errors;
1090        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
1091
1092        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
1093                try {
1094                        Declaration * decl = cur->build();
1095                        assert( decl );
1096                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
1097                                dwt->location = cur->location;
1098                                *out++ = dwt;
1099                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
1100                                // e.g., int foo(struct S) {}
1101                                StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
1102                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
1103                                obj->location = cur->location;
1104                                *out++ = obj;
1105                                delete agg;
1106                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
1107                                // e.g., int foo(union U) {}
1108                                UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
1109                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
1110                                obj->location = cur->location;
1111                                *out++ = obj;
1112                        } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
1113                                // e.g., int foo(enum E) {}
1114                                EnumInstType * inst = new EnumInstType( Type::Qualifiers(), agg->name );
1115                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
1116                                obj->location = cur->location;
1117                                *out++ = obj;
1118                        } // if
1119                } catch( SemanticErrorException & e ) {
1120                        errors.append( e );
1121                } // try
1122        } // for
1123
1124        if ( ! errors.isEmpty() ) {
1125                throw errors;
1126        } // if
1127} // buildList
1128
1129void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) {
1130        SemanticErrorException errors;
1131        std::back_insert_iterator< std::list< Type * > > out( outputList );
1132        const DeclarationNode * cur = firstNode;
1133
1134        while ( cur ) {
1135                try {
1136                        * out++ = cur->buildType();
1137                } catch( SemanticErrorException & e ) {
1138                        errors.append( e );
1139                } // try
1140                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
1141        } // while
1142
1143        if ( ! errors.isEmpty() ) {
1144                throw errors;
1145        } // if
1146} // buildTypeList
1147
1148Declaration * DeclarationNode::build() const {
1149        if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
1150
1151        if ( asmStmt ) {
1152                return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) );
1153        } // if
1154        if ( directiveStmt ) {
1155                return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) );
1156        } // if
1157
1158        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
1159                // otype is internally converted to dtype + otype parameters
1160                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dimension };
1161                static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
1162                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
1163                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::DStype, variable.initializer ? variable.initializer->buildType() : nullptr );
1164                buildList( variable.assertions, ret->get_assertions() );
1165                return ret;
1166        } // if
1167
1168        if ( type ) {
1169                // Function specifiers can only appear on a function definition/declaration.
1170                //
1171                //    inline _Noreturn int f();                 // allowed
1172                //    inline _Noreturn int g( int i );  // allowed
1173                //    inline _Noreturn int i;                   // disallowed
1174                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
1175                        SemanticError( this, "invalid function specifier for " );
1176                } // if
1177                // Forall qualifier can only appear on a function/aggregate definition/declaration.
1178                //
1179                //    forall int f();                                   // allowed
1180                //    forall int g( int i );                    // allowed
1181                //    forall int i;                                             // disallowed
1182                if ( type->kind != TypeData::Function && type->forall ) {
1183                        SemanticError( this, "invalid type qualifier for " );
1184                } // if
1185                bool isDelete = initializer && initializer->get_isDelete();
1186                Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
1187                if ( isDelete ) {
1188                        DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
1189                        dwt->isDeleted = true;
1190                }
1191                return decl;
1192        } // if
1193
1194        if ( assert.condition ) {
1195                return new StaticAssertDecl( maybeBuild< Expression >( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
1196        }
1197
1198        // SUE's cannot have function specifiers, either
1199        //
1200        //    inline _Noreturn struct S { ... };                // disallowed
1201        //    inline _Noreturn enum   E { ... };                // disallowed
1202        if ( funcSpecs.any() ) {
1203                SemanticError( this, "invalid function specifier for " );
1204        } // if
1205        if ( enumInLine ) {
1206                return new InlineMemberDecl( *name, storageClasses, linkage, nullptr );
1207        } // if
1208        assertf( name, "ObjectDecl must a have name\n" );
1209        return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension );
1210}
1211
1212Type * DeclarationNode::buildType() const {
1213        assert( type );
1214
1215        if ( attr.expr ) {
1216                return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
1217        } else if ( attr.type ) {
1218                return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
1219        } // if
1220
1221        switch ( type->kind ) {
1222          case TypeData::Enum:
1223          case TypeData::Aggregate: {
1224                  ReferenceToType * ret = buildComAggInst( type, attributes, linkage );
1225                  buildList( type->aggregate.actuals, ret->get_parameters() );
1226                  return ret;
1227          }
1228          case TypeData::Symbolic: {
1229                  TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
1230                  buildList( type->symbolic.actuals, ret->get_parameters() );
1231                  return ret;
1232          }
1233          default:
1234                Type * simpletypes = typebuild( type );
1235                simpletypes->get_attributes() = attributes;             // copy because member is const
1236                return simpletypes;
1237        } // switch
1238}
1239
1240// Local Variables: //
1241// tab-width: 4 //
1242// mode: c++ //
1243// compile-command: "make install" //
1244// End: //
Note: See TracBrowser for help on using the repository browser.