source: src/Parser/DeclarationNode.cc@ f31cb3e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since f31cb3e was 138e29e, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Implemented filename and linenumber errors in most cases, only missing constructor errors apparently

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