source: src/Parser/DeclarationNode.cc@ b8cb388

Last change on this file since b8cb388 was 67467a3, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Fused TypeData::Enum and TypeData::Aggregate, an enumeration is a kind of aggregate after all. There will always be some unused fields in Aggregate_t (but less in TypeData overall) but the code is almost always simpler.

  • Property mode set to 100644
File size: 33.5 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
[b38f6da]11// Last Modified By : Peter A. Buhr
[4eb3a7c5]12// Last Modified On : Fri Feb 23 18:25:57 2024
13// Update Count : 1533
[b87a5ed]14//
15
[c468150]16#include "DeclarationNode.h"
17
[e3e16bc]18#include <cassert> // for assert, assertf, strict_dynamic_cast
[d180746]19#include <iterator> // for back_insert_iterator
20#include <list> // for list
21#include <memory> // for unique_ptr
22#include <ostream> // for operator<<, ostream, basic_ostream
23#include <string> // for string, operator+, allocator, char...
[51b73452]24
[bb7422a]25#include "AST/Attribute.hpp" // for Attribute
26#include "AST/Copy.hpp" // for shallowCopy
27#include "AST/Decl.hpp" // for Decl
28#include "AST/Expr.hpp" // for Expr
29#include "AST/Print.hpp" // for print
30#include "AST/Stmt.hpp" // for AsmStmt, DirectiveStmt
31#include "AST/StorageClasses.hpp" // for Storage::Class
32#include "AST/Type.hpp" // for Type
33#include "Common/CodeLocation.h" // for CodeLocation
34#include "Common/Iterate.hpp" // for reverseIterate
[d180746]35#include "Common/SemanticError.h" // for SemanticError
36#include "Common/UniqueName.h" // for UniqueName
[5bf685f]37#include "Common/utility.h" // for copy, spliceBegin
[c468150]38#include "Parser/ExpressionNode.h" // for ExpressionNode
39#include "Parser/InitializerNode.h"// for InitializerNode
40#include "Parser/StatementNode.h" // for StatementNode
[d180746]41#include "TypeData.h" // for TypeData, TypeData::Aggregate_t
[2f0a0678]42#include "TypedefTable.h" // for TypedefTable
[bdd516a]43
[de62360d]44extern TypedefTable typedefTable;
45
[51b73452]46using namespace std;
47
48UniqueName DeclarationNode::anonymous( "__anonymous" );
49
[bb7422a]50extern ast::Linkage::Spec linkage; // defined in parser.yy
[51b73452]51
[7d05e7e]52DeclarationNode::DeclarationNode() :
[e07caa2]53 linkage( ::linkage ) {
[2298f728]54
[faddbd8]55// variable.name = nullptr;
[bb7422a]56 variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;
[28307be]57 variable.assertions = nullptr;
[67cf18c]58 variable.initializer = nullptr;
[7d05e7e]59
[f6e3e34]60 assert.condition = nullptr;
61 assert.message = nullptr;
[28307be]62}
63
64DeclarationNode::~DeclarationNode() {
[4c0b674]65 delete name;
66
[faddbd8]67// delete variable.name;
[2298f728]68 delete variable.assertions;
[67cf18c]69 delete variable.initializer;
[2298f728]70
[702e826]71// delete type;
[28307be]72 delete bitfieldWidth;
[e994912]73
74 delete asmStmt;
[58dd019]75 // asmName, no delete, passed to next stage
[28307be]76 delete initializer;
[f6e3e34]77
78 delete assert.condition;
79 delete assert.message;
[28307be]80}
81
[ba7aa2d]82DeclarationNode * DeclarationNode::clone() const {
83 DeclarationNode * newnode = new DeclarationNode;
[44adf1b]84 newnode->next = maybeCopy( next );
[2298f728]85 newnode->name = name ? new string( *name ) : nullptr;
[c0aa336]86
[5bf685f]87 newnode->type = maybeCopy( type );
[679e644]88 newnode->inLine = inLine;
[a7c90d4]89 newnode->storageClasses = storageClasses;
90 newnode->funcSpecs = funcSpecs;
[5bf685f]91 newnode->bitfieldWidth = maybeCopy( bitfieldWidth );
92 newnode->enumeratorValue.reset( maybeCopy( enumeratorValue.get() ) );
[b87a5ed]93 newnode->hasEllipsis = hasEllipsis;
94 newnode->linkage = linkage;
[bb7422a]95 newnode->asmName = maybeCopy( asmName );
96 newnode->attributes = attributes;
[5bf685f]97 newnode->initializer = maybeCopy( initializer );
[c0aa336]98 newnode->extension = extension;
[5bf685f]99 newnode->asmStmt = maybeCopy( asmStmt );
[c0aa336]100 newnode->error = error;
[3848e0e]101
[faddbd8]102// newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
[28307be]103 newnode->variable.tyClass = variable.tyClass;
[5bf685f]104 newnode->variable.assertions = maybeCopy( variable.assertions );
105 newnode->variable.initializer = maybeCopy( variable.initializer );
[3848e0e]106
[5bf685f]107 newnode->assert.condition = maybeCopy( assert.condition );
[bb7422a]108 newnode->assert.message = maybeCopy( assert.message );
[28307be]109 return newnode;
110} // DeclarationNode::clone
[3848e0e]111
[f2f512ba]112void DeclarationNode::print( std::ostream & os, int indent ) const {
[59db689]113 os << string( indent, ' ' );
[2298f728]114 if ( name ) {
115 os << *name << ": ";
[68cd1ce]116 } // if
[51b73452]117
[bb7422a]118 if ( linkage != ast::Linkage::Cforall ) {
119 os << ast::Linkage::name( linkage ) << " ";
[68cd1ce]120 } // if
[3848e0e]121
[bb7422a]122 ast::print( os, storageClasses );
123 ast::print( os, funcSpecs );
[dd020c0]124
[b87a5ed]125 if ( type ) {
126 type->print( os, indent );
127 } else {
128 os << "untyped entity ";
[68cd1ce]129 } // if
[3848e0e]130
[b87a5ed]131 if ( bitfieldWidth ) {
[59db689]132 os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
[b87a5ed]133 bitfieldWidth->printOneLine( os );
[68cd1ce]134 } // if
[3848e0e]135
[2298f728]136 if ( initializer ) {
[59db689]137 os << endl << string( indent + 2, ' ' ) << "with initializer ";
[b87a5ed]138 initializer->printOneLine( os );
[974906e2]139 os << " maybe constructed? " << initializer->get_maybeConstructed();
[68cd1ce]140 } // if
[3848e0e]141
[692c1cc]142 if ( ! attributes.empty() ) {
[4eb3a7c5]143 os << string( indent + 2, ' ' ) << "with attributes" << endl;
[bb7422a]144 for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
[4eb3a7c5]145 os << string( indent + 4, ' ' );
146 ast::print( os, attr, indent + 2 );
[692c1cc]147 } // for
148 } // if
[66406f3]149
[b87a5ed]150 os << endl;
[51b73452]151}
152
[f2f512ba]153void DeclarationNode::printList( std::ostream & os, int indent ) const {
[dc3fbe5]154 ParseList::printList( os, indent );
[b87a5ed]155 if ( hasEllipsis ) {
156 os << string( indent, ' ' ) << "and a variable number of other arguments" << endl;
[68cd1ce]157 } // if
[51b73452]158}
159
[6cef439]160DeclarationNode * DeclarationNode::newFromTypeData( TypeData * type ) {
161 DeclarationNode * newnode = new DeclarationNode;
162 newnode->type = type;
163 return newnode;
164} // DeclarationNode::newFromTypeData
165
[bb7422a]166DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) {
[ba7aa2d]167 DeclarationNode * newnode = new DeclarationNode;
[08d5507b]168 newnode->storageClasses = sc;
[b87a5ed]169 return newnode;
[dd020c0]170} // DeclarationNode::newStorageClass
[3848e0e]171
[bb7422a]172DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) {
[ba7aa2d]173 DeclarationNode * newnode = new DeclarationNode;
[08d5507b]174 newnode->funcSpecs = fs;
[c1c1112]175 return newnode;
[dd020c0]176} // DeclarationNode::newFuncSpecifier
[c1c1112]177
[bb7422a]178DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
[ba7aa2d]179 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]180 newnode->type = new TypeData( TypeData::Aggregate );
[8f6f47d7]181 newnode->type->aggregate.kind = kind;
[692c1cc]182 newnode->type->aggregate.anon = name == nullptr;
183 newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
[8f6f47d7]184 newnode->type->aggregate.actuals = actuals;
185 newnode->type->aggregate.fields = fields;
186 newnode->type->aggregate.body = body;
[b87a5ed]187 return newnode;
[984dce6]188} // DeclarationNode::newAggregate
[3848e0e]189
[e4d7c1c]190DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base, EnumHiding hiding ) {
[67467a3]191 DeclarationNode * newnode = newAggregate( ast::AggregateDecl::Enum, name, nullptr, constants, body );
192 newnode->type->aggregate.typed = typed;
193 newnode->type->aggregate.hiding = hiding;
[057608a]194 if ( base ) {
195 assert( typed );
196 assert( base->type );
[ed9a1ae]197 newnode->type->base = base->type;
[057608a]198 base->type = nullptr;
199 delete base;
[9e7236f4]200 } // if
201
[b87a5ed]202 return newnode;
[984dce6]203} // DeclarationNode::newEnum
[3848e0e]204
[a46b69c]205DeclarationNode * DeclarationNode::newName( const string * name ) {
[ba7aa2d]206 DeclarationNode * newnode = new DeclarationNode;
[a46b69c]207 assert( ! newnode->name );
[2298f728]208 newnode->name = name;
[a46b69c]209 return newnode;
210} // DeclarationNode::newName
211
[374cb117]212DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
[a46b69c]213 DeclarationNode * newnode = newName( name );
[4f147cc]214 newnode->enumeratorValue.reset( constant );
[b87a5ed]215 return newnode;
[984dce6]216} // DeclarationNode::newEnumConstant
[3848e0e]217
[374cb117]218DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) {
[057608a]219 if ( nullptr == init ) {
[b0d9ff7]220 return newName( name );
[057608a]221 } else if ( init->get_expression() ) {
222 return newEnumConstant( name, init->get_expression() );
223 } else {
224 DeclarationNode * newnode = newName( name );
225 newnode->initializer = init;
226 return newnode;
[374cb117]227 } // if
[9e7236f4]228} // DeclarationNode::newEnumValueGeneric
[374cb117]229
[1e30df7]230DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
231 DeclarationNode * newnode = newName( new std::string(name) );
232 newnode->enumInLine = true;
233 return newnode;
234}
235
[bb7422a]236DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) {
[a46b69c]237 DeclarationNode * newnode = newName( name );
[2298f728]238 newnode->type = nullptr;
[28307be]239 newnode->variable.tyClass = tc;
[faddbd8]240 newnode->variable.assertions = nullptr;
[b87a5ed]241 return newnode;
[984dce6]242} // DeclarationNode::newTypeParam
[3848e0e]243
[fb114fa1]244DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
[ba7aa2d]245 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]246 newnode->type = new TypeData( TypeData::Aggregate );
[2298f728]247 newnode->type->aggregate.name = name;
[bb7422a]248 newnode->type->aggregate.kind = ast::AggregateDecl::Trait;
[8f6f47d7]249 newnode->type->aggregate.params = params;
250 newnode->type->aggregate.fields = asserts;
[b87a5ed]251 return newnode;
[984dce6]252} // DeclarationNode::newTrait
[3848e0e]253
[fb114fa1]254DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
[ba7aa2d]255 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]256 newnode->type = new TypeData( TypeData::AggregateInst );
[8f6f47d7]257 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
[bb7422a]258 newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait;
[2298f728]259 newnode->type->aggInst.aggregate->aggregate.name = name;
[8f6f47d7]260 newnode->type->aggInst.params = params;
[b87a5ed]261 return newnode;
[984dce6]262} // DeclarationNode::newTraitUse
[3848e0e]263
[25bca42]264DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
[a46b69c]265 DeclarationNode * newnode = newName( name );
[b87a5ed]266 newnode->type = new TypeData( TypeData::Symbolic );
[8f6f47d7]267 newnode->type->symbolic.isTypedef = false;
268 newnode->type->symbolic.params = typeParams;
[b87a5ed]269 return newnode;
[984dce6]270} // DeclarationNode::newTypeDecl
[3848e0e]271
[ce8c12f]272DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers, OperKinds kind ) {
[ba7aa2d]273 DeclarationNode * newnode = new DeclarationNode;
[ce8c12f]274 newnode->type = new TypeData( kind == OperKinds::PointTo ? TypeData::Pointer : TypeData::Reference );
[71d0eab]275 if ( kind == OperKinds::And ) {
276 // T && is parsed as 'And' operator rather than two references => add a second reference type
277 TypeData * td = new TypeData( TypeData::Reference );
278 td->base = newnode->type;
279 newnode->type = td;
280 }
[c3396e0]281 if ( qualifiers ) {
282 return newnode->addQualifiers( qualifiers );
283 } else {
284 return newnode;
285 } // if
[984dce6]286} // DeclarationNode::newPointer
[3848e0e]287
[ba7aa2d]288DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
289 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]290 newnode->type = new TypeData( TypeData::Array );
[8f6f47d7]291 newnode->type->array.dimension = size;
292 newnode->type->array.isStatic = isStatic;
[a3525c4]293 newnode->type->array.isVarLen = size && !size->isExpressionType<ast::ConstantExpr *>();
[b87a5ed]294 return newnode->addQualifiers( qualifiers );
[984dce6]295} // DeclarationNode::newArray
[3848e0e]296
[ba7aa2d]297DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
298 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]299 newnode->type = new TypeData( TypeData::Array );
[2298f728]300 newnode->type->array.dimension = nullptr;
[8f6f47d7]301 newnode->type->array.isStatic = false;
302 newnode->type->array.isVarLen = true;
[b87a5ed]303 return newnode->addQualifiers( qualifiers );
[3848e0e]304}
305
[ba7aa2d]306DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
307 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]308 newnode->bitfieldWidth = size;
309 return newnode;
[3848e0e]310}
311
[ba7aa2d]312DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
313 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]314 newnode->type = new TypeData( TypeData::Tuple );
[8f6f47d7]315 newnode->type->tuple = members;
[b87a5ed]316 return newnode;
[3848e0e]317}
318
[f855545]319DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr, bool basetypeof ) {
[ba7aa2d]320 DeclarationNode * newnode = new DeclarationNode;
[f855545]321 newnode->type = new TypeData( basetypeof ? TypeData::Basetypeof : TypeData::Typeof );
[8f6f47d7]322 newnode->type->typeexpr = expr;
[b87a5ed]323 return newnode;
[3848e0e]324}
325
[a46b69c]326DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
327 DeclarationNode * newnode = newName( name );
328 newnode->type = new TypeData( TypeData::Function );
329 newnode->type->function.params = param;
330 newnode->type->function.body = body;
331
332 if ( ret ) {
333 newnode->type->base = ret->type;
334 ret->type = nullptr;
335 delete ret;
336 } // if
337
338 return newnode;
339} // DeclarationNode::newFunction
340
[25bca42]341DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
[44a81853]342 DeclarationNode * newnode = new DeclarationNode;
343 newnode->type = nullptr;
[bb7422a]344 std::vector<ast::ptr<ast::Expr>> exprs;
[44a81853]345 buildList( expr, exprs );
[b38f6da]346 newnode->attributes.push_back( new ast::Attribute( *name, std::move( exprs ) ) );
[44a81853]347 delete name;
348 return newnode;
349}
350
[2d019af]351DeclarationNode * DeclarationNode::newDirectiveStmt( StatementNode * stmt ) {
352 DeclarationNode * newnode = new DeclarationNode;
353 newnode->directiveStmt = stmt;
354 return newnode;
355}
356
[e994912]357DeclarationNode * DeclarationNode::newAsmStmt( StatementNode * stmt ) {
358 DeclarationNode * newnode = new DeclarationNode;
359 newnode->asmStmt = stmt;
360 return newnode;
361}
362
[bb7422a]363DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr * message ) {
[f6e3e34]364 DeclarationNode * newnode = new DeclarationNode;
365 newnode->assert.condition = condition;
366 newnode->assert.message = message;
367 return newnode;
368}
369
[bb7422a]370static void appendError( string & dst, const string & src ) {
[5b639ee]371 if ( src.empty() ) return;
372 if ( dst.empty() ) { dst = src; return; }
373 dst += ", " + src;
374} // appendError
375
[ba7aa2d]376void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
[bb7422a]377 const ast::CV::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
378 const ast::CV::Qualifiers duplicates = qsrc & qdst;
379
380 if ( duplicates.any() ) {
381 std::stringstream str;
382 str << "duplicate ";
383 ast::print( str, duplicates );
384 str << "qualifier(s)";
385 appendError( error, str.str() );
[a7c90d4]386 } // for
[c1c1112]387} // DeclarationNode::checkQualifiers
388
[a7c90d4]389void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
[bb7422a]390 ast::Function::Specs fsDups = funcSpecs & src->funcSpecs;
391 if ( fsDups.any() ) {
392 std::stringstream str;
393 str << "duplicate ";
394 ast::print( str, fsDups );
395 str << "function specifier(s)";
396 appendError( error, str.str() );
[dd020c0]397 } // if
398
[bb7422a]399 // Skip if everything is unset.
400 if ( storageClasses.any() && src->storageClasses.any() ) {
401 ast::Storage::Classes dups = storageClasses & src->storageClasses;
402 // Check for duplicates.
403 if ( dups.any() ) {
404 std::stringstream str;
405 str << "duplicate ";
406 ast::print( str, dups );
407 str << "storage class(es)";
408 appendError( error, str.str() );
409 // Check for conflicts.
410 } else if ( !src->storageClasses.is_threadlocal_any() ) {
411 std::stringstream str;
412 str << "conflicting ";
413 ast::print( str, ast::Storage::Classes( 1 << storageClasses.ffs() ) );
414 str << "& ";
415 ast::print( str, ast::Storage::Classes( 1 << src->storageClasses.ffs() ) );
416 str << "storage classes";
417 appendError( error, str.str() );
418 // FIX to preserve invariant of one basic storage specifier
419 src->storageClasses.reset();
420 }
[b6424d9]421 } // if
[dd020c0]422
[a7c90d4]423 appendError( error, src->error );
424} // DeclarationNode::checkSpecifiers
[b6424d9]425
[4eb3a7c5]426DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q, bool copyattr ) {
[6f95000]427 funcSpecs |= q->funcSpecs;
428 storageClasses |= q->storageClasses;
[c0aa336]429
[4eb3a7c5]430 if ( copyattr ) {
431 std::vector<ast::ptr<ast::Attribute>> tmp;
432 tmp.reserve( q->attributes.size() );
433 for ( auto const & attr : q->attributes ) {
434 tmp.emplace_back( ast::shallowCopy( attr.get() ) );
435 } // for
436 spliceBegin( attributes, tmp );
437 } // if
[bb7422a]438
[b6424d9]439 return this;
[a7c90d4]440} // DeclarationNode::copySpecifiers
[b6424d9]441
[ba7aa2d]442DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
[af9da5f]443 if ( ! q ) { return this; } // empty qualifier
[101e0bd]444
[a7c90d4]445 checkSpecifiers( q );
446 copySpecifiers( q );
[101e0bd]447
[c38ae92]448 if ( ! q->type ) { delete q; return this; }
[101e0bd]449
450 if ( ! type ) {
[c38ae92]451 type = q->type; // reuse structure
[1b772749]452 q->type = nullptr;
453 delete q;
[101e0bd]454 return this;
455 } // if
456
[a7c90d4]457 checkQualifiers( type, q->type );
[e048ece]458 TypeData::BuiltinType const builtin = type->builtintype;
459 if ( (builtin == TypeData::Zero || builtin == TypeData::One) && q->type->qualifiers.any() && error.length() == 0 ) {
460 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, TypeData::builtinTypeNames[builtin] );
[9dc31c10]461 } // if
[af60383]462 type = ::addQualifiers( q->type, type );
463 q->type = nullptr;
[6ef2d81]464
[b87a5ed]465 delete q;
466 return this;
[101e0bd]467} // addQualifiers
[3848e0e]468
[af60383]469DeclarationNode * DeclarationNode::addType( DeclarationNode * o, bool copyattr ) {
470 if ( !o ) return this;
471
472 checkSpecifiers( o );
473 copySpecifiers( o, copyattr );
474 if ( o->type ) {
475 type = ::addType( o->type, type, o->attributes );
476 o->type = nullptr;
[101e0bd]477 } // if
[af60383]478 if ( o->bitfieldWidth ) {
479 bitfieldWidth = o->bitfieldWidth;
[68cd1ce]480 } // if
[3848e0e]481
[af60383]482 // there may be typedefs chained onto the type
483 if ( o->next ) {
484 set_last( o->next->clone() );
[68cd1ce]485 } // if
[66406f3]486
[af60383]487 delete o;
[b87a5ed]488 return this;
[3848e0e]489}
490
[f135b50]491DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
[af60383]492 if ( o && o->type ) {
493 type->base = o->type;
[b38f6da]494 } // if
[f135b50]495 delete o;
496 return this;
497}
498
[2583407]499// This code handles a special issue with the attribute transparent_union.
500//
501// typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union ))
502//
503// Here the attribute aligned goes with the typedef_name, so variables declared of this type are
504// aligned. However, the attribute transparent_union must be moved from the typedef_name to
505// alias union U. Currently, this is the only know attribute that must be moved from typedef to
506// alias.
507static void moveUnionAttribute( DeclarationNode * decl, DeclarationNode * unionDecl ) {
508 assert( decl->type->kind == TypeData::Symbolic );
509 assert( decl->type->symbolic.isTypedef );
510 assert( unionDecl->type->kind == TypeData::Aggregate );
511
512 if ( unionDecl->type->aggregate.kind != ast::AggregateDecl::Union ) return;
513
514 // Ignore the Aggregate_t::attributes. Why did we add that before the rework?
515 for ( auto attr = decl->attributes.begin() ; attr != decl->attributes.end() ; ) {
516 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
517 unionDecl->attributes.emplace_back( attr->release() );
518 attr = decl->attributes.erase( attr );
519 } else {
520 ++attr;
521 }
522 }
523}
524
525// Helper for addTypedef, handles the case where the typedef wraps an
526// aggregate declaration (not a type), returns a chain of nodes.
527static DeclarationNode * addTypedefAggr(
528 DeclarationNode * olddecl, TypeData * newtype ) {
529 TypeData *& oldaggr = olddecl->type->aggInst.aggregate;
530
531 // Handle anonymous aggregates: typedef struct { int i; } foo
532 // Give the typedefed type a consistent name across translation units.
533 if ( oldaggr->aggregate.anon ) {
534 delete oldaggr->aggregate.name;
535 oldaggr->aggregate.name = new string( "__anonymous_" + *olddecl->name );
536 oldaggr->aggregate.anon = false;
537 oldaggr->qualifiers.reset();
538 }
539
540 // Replace the wrapped TypeData with a forward declaration.
541 TypeData * newaggr = new TypeData( TypeData::Aggregate );
542 newaggr->aggregate.kind = oldaggr->aggregate.kind;
543 newaggr->aggregate.name = oldaggr->aggregate.name ? new string( *oldaggr->aggregate.name ) : nullptr;
544 newaggr->aggregate.body = false;
545 newaggr->aggregate.anon = oldaggr->aggregate.anon;
[67467a3]546 newaggr->aggregate.typed = oldaggr->aggregate.typed;
547 newaggr->aggregate.hiding = oldaggr->aggregate.hiding;
[2583407]548 swap( newaggr, oldaggr );
549
550 newtype->base = olddecl->type;
551 olddecl->type = newtype;
552 DeclarationNode * newdecl = new DeclarationNode;
553 newdecl->type = newaggr;
554 newdecl->next = olddecl;
555
556 moveUnionAttribute( olddecl, newdecl );
557
558 return newdecl;
559}
560
[057608a]561// Wrap the declaration in a typedef. It actually does that by modifying the
562// existing declaration, and may split it into two declarations.
563// This only happens if the wrapped type is actually a declaration of a SUE
564// type. If it does, the DeclarationNode for the SUE declaration is the node
565// returned, make sure later transformations are applied to the right node.
[ba7aa2d]566DeclarationNode * DeclarationNode::addTypedef() {
567 TypeData * newtype = new TypeData( TypeData::Symbolic );
[2298f728]568 newtype->symbolic.params = nullptr;
[8f6f47d7]569 newtype->symbolic.isTypedef = true;
[2298f728]570 newtype->symbolic.name = name ? new string( *name ) : nullptr;
[2583407]571 // If this typedef is wrapping an aggregate, separate them out.
572 if ( TypeData::AggregateInst == type->kind
573 && TypeData::Aggregate == type->aggInst.aggregate->kind
574 && type->aggInst.aggregate->aggregate.body ) {
575 return addTypedefAggr( this, newtype );
576 // There is no internal declaration, just a type.
577 } else {
578 newtype->base = type;
579 type = newtype;
580 return this;
581 }
[3848e0e]582}
583
[ba7aa2d]584DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
[bb7422a]585 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
[702e826]586 if ( variable.assertions ) {
[dc3fbe5]587 variable.assertions->set_last( assertions );
[702e826]588 } else {
589 variable.assertions = assertions;
590 } // if
591 return this;
[2298f728]592 } // if
593
[b87a5ed]594 assert( type );
595 switch ( type->kind ) {
[0d0931d]596 case TypeData::Symbolic:
[8f6f47d7]597 if ( type->symbolic.assertions ) {
[dc3fbe5]598 type->symbolic.assertions->set_last( assertions );
[b87a5ed]599 } else {
[8f6f47d7]600 type->symbolic.assertions = assertions;
[68cd1ce]601 } // if
[b87a5ed]602 break;
[0d0931d]603 default:
[b87a5ed]604 assert( false );
[68cd1ce]605 } // switch
[974906e2]606
[b87a5ed]607 return this;
[51b73452]608}
609
[fb114fa1]610DeclarationNode * DeclarationNode::addName( string * newname ) {
[2298f728]611 assert( ! name );
612 name = newname;
[b87a5ed]613 return this;
[51b73452]614}
615
[c0aa336]616DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
[58dd019]617 assert( ! asmName );
[c0aa336]618 asmName = newname ? newname->asmName : nullptr;
619 return this->addQualifiers( newname );
[58dd019]620}
621
[ba7aa2d]622DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
[b87a5ed]623 bitfieldWidth = size;
624 return this;
[51b73452]625}
626
[ba7aa2d]627DeclarationNode * DeclarationNode::addVarArgs() {
[b87a5ed]628 assert( type );
629 hasEllipsis = true;
630 return this;
[51b73452]631}
632
[c453ac4]633DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, ExpressionNode * withExprs ) {
[b87a5ed]634 assert( type );
635 assert( type->kind == TypeData::Function );
[2298f728]636 assert( ! type->function.body );
[8f6f47d7]637 type->function.body = body;
[c453ac4]638 type->function.withExprs = withExprs;
[b87a5ed]639 return this;
[51b73452]640}
641
[ba7aa2d]642DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
[b87a5ed]643 assert( type );
644 assert( type->kind == TypeData::Function );
[2298f728]645 assert( ! type->function.oldDeclList );
[8f6f47d7]646 type->function.oldDeclList = list;
[b87a5ed]647 return this;
[51b73452]648}
649
[c0aa336]650DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
[b87a5ed]651 if ( type ) {
[af60383]652 type->setLastBase( newType );
[b87a5ed]653 } else {
654 type = newType;
[68cd1ce]655 } // if
[c0aa336]656 return this;
[3848e0e]657}
658
[c0aa336]659DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
660 if ( a ) {
[bb7422a]661 spliceBegin( attributes, a->attributes );
[c0aa336]662 a->attributes.clear();
663 } // if
664 return this;
665} // copyAttribute
666
[ba7aa2d]667DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
[b87a5ed]668 if ( p ) {
[6926a6d]669 assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
[c0aa336]670 setBase( p->type );
[2298f728]671 p->type = nullptr;
[c0aa336]672 copyAttribute( p );
[b87a5ed]673 delete p;
[68cd1ce]674 } // if
[b87a5ed]675 return this;
[3848e0e]676}
677
[ba7aa2d]678DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
[b87a5ed]679 if ( a ) {
680 assert( a->type->kind == TypeData::Array );
[c0aa336]681 setBase( a->type );
[2298f728]682 a->type = nullptr;
[c0aa336]683 copyAttribute( a );
[b87a5ed]684 delete a;
[68cd1ce]685 } // if
[b87a5ed]686 return this;
[51b73452]687}
688
[ba7aa2d]689DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
[b87a5ed]690 if ( p ) {
[e6cee92]691 assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
[b87a5ed]692 if ( type ) {
[af60383]693 p->type->base = makeNewBase( type );
[2298f728]694 type = nullptr;
[68cd1ce]695 } // if
[b87a5ed]696 delete this;
697 return p;
698 } else {
699 return this;
[68cd1ce]700 } // if
[51b73452]701}
702
[ba7aa2d]703DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
[0d0931d]704 if ( ! a ) return this;
[738e304]705 assert( a->type->kind == TypeData::Array );
706 if ( type ) {
[af60383]707 a->type->setLastBase( makeNewBase( type ) );
[738e304]708 type = nullptr;
[68cd1ce]709 } // if
[738e304]710 delete this;
711 return a;
[51b73452]712}
[3848e0e]713
[ba7aa2d]714DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
715 TypeData * ftype = new TypeData( TypeData::Function );
[8f6f47d7]716 ftype->function.params = params;
[c0aa336]717 setBase( ftype );
[b87a5ed]718 return this;
[3848e0e]719}
720
[ba7aa2d]721static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
[b87a5ed]722 if ( type ) {
723 if ( type->kind != TypeData::Function ) {
724 type->base = addIdListToType( type->base, ids );
725 } else {
[8f6f47d7]726 type->function.idList = ids;
[68cd1ce]727 } // if
[b87a5ed]728 return type;
[3848e0e]729 } else {
[ba7aa2d]730 TypeData * newtype = new TypeData( TypeData::Function );
[8f6f47d7]731 newtype->function.idList = ids;
[b87a5ed]732 return newtype;
[68cd1ce]733 } // if
[2298f728]734} // addIdListToType
[974906e2]735
[ba7aa2d]736DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
[b87a5ed]737 type = addIdListToType( type, ids );
738 return this;
[3848e0e]739}
740
[ba7aa2d]741DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
[b87a5ed]742 initializer = init;
743 return this;
[3848e0e]744}
745
[67cf18c]746DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
[bb7422a]747 assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
[67cf18c]748 variable.initializer = init;
749 return this;
750}
751
[a46b69c]752DeclarationNode * DeclarationNode::cloneType( string * name ) {
753 DeclarationNode * newnode = newName( name );
[5bf685f]754 newnode->type = maybeCopy( type );
[a7c90d4]755 newnode->copySpecifiers( this );
[b87a5ed]756 return newnode;
[3848e0e]757}
758
[4eb3a7c5]759DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o, bool copyattr ) {
[2298f728]760 if ( ! o ) return nullptr;
[4eb3a7c5]761 o->copySpecifiers( this, copyattr );
[2298f728]762 if ( type ) {
[af60383]763 o->type = ::cloneBaseType( type, o->type );
[68cd1ce]764 } // if
[b87a5ed]765 return o;
[51b73452]766}
767
[ba7aa2d]768DeclarationNode * DeclarationNode::extractAggregate() const {
[b87a5ed]769 if ( type ) {
[ba7aa2d]770 TypeData * ret = typeextractAggregate( type );
[b87a5ed]771 if ( ret ) {
[ba7aa2d]772 DeclarationNode * newnode = new DeclarationNode;
[b87a5ed]773 newnode->type = ret;
[4eb3a7c5]774 if ( ret->kind == TypeData::Aggregate ) {
775 newnode->attributes.swap( ret->aggregate.attributes );
776 } // if
[b87a5ed]777 return newnode;
[843054c2]778 } // if
779 } // if
[2298f728]780 return nullptr;
[3848e0e]781}
782
[45e753c]783// Get the non-anonymous name of the instance type of the declaration,
784// if one exists.
785static const std::string * getInstTypeOfName( ast::Decl * decl ) {
786 if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
787 if ( auto aggr = dynamic_cast<ast::BaseInstType const *>( dwt->get_type() ) ) {
788 if ( aggr->name.find("anonymous") == std::string::npos ) {
789 return &aggr->name;
790 }
791 }
792 }
793 return nullptr;
794}
795
[b38f6da]796void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::Decl>> & outputList ) {
[a16764a6]797 SemanticErrorException errors;
[bb7422a]798 std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList );
[2298f728]799
[dc3fbe5]800 for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) {
[b87a5ed]801 try {
[45e753c]802 bool extracted_named = false;
[692c1cc]803
[ba7aa2d]804 if ( DeclarationNode * extr = cur->extractAggregate() ) {
[78e2fca]805 assert( cur->type );
[692c1cc]806
[45e753c]807 if ( ast::Decl * decl = extr->build() ) {
[692c1cc]808 *out++ = decl;
[3d7e53b]809
810 // need to remember the cases where a declaration contains an anonymous aggregate definition
811 assert( extr->type );
812 if ( extr->type->kind == TypeData::Aggregate ) {
[692c1cc]813 // typedef struct { int A } B is the only case?
[4eb3a7c5]814 extracted_named = ! extr->type->aggregate.anon;
[45e753c]815 } else {
816 extracted_named = true;
[3d7e53b]817 }
[843054c2]818 } // if
[f39096c]819 delete extr;
[843054c2]820 } // if
[2298f728]821
[45e753c]822 if ( ast::Decl * decl = cur->build() ) {
823 if ( "" == decl->name && !cur->get_inLine() ) {
824 // Don't include anonymous declaration for named aggregates,
825 // but do include them for anonymous aggregates, e.g.:
826 // struct S {
827 // struct T { int x; }; // no anonymous member
828 // struct { int y; }; // anonymous member
829 // struct T; // anonymous member
830 // };
831 if ( extracted_named ) {
832 continue;
833 }
[692c1cc]834
[45e753c]835 if ( auto name = getInstTypeOfName( decl ) ) {
836 // Temporary: warn about anonymous member declarations of named types, since
837 // this conflicts with the syntax for the forward declaration of an anonymous type.
838 SemanticWarning( cur->location, Warning::AggrForwardDecl, name->c_str() );
839 }
[e07caa2]840 } // if
[45e753c]841 *out++ = decl;
[843054c2]842 } // if
[45e753c]843 } catch ( SemanticErrorException & e ) {
[b87a5ed]844 errors.append( e );
[843054c2]845 } // try
[e07caa2]846 } // for
[2298f728]847
[b87a5ed]848 if ( ! errors.isEmpty() ) {
849 throw errors;
[843054c2]850 } // if
[2298f728]851} // buildList
[3848e0e]852
[3d7e53b]853// currently only builds assertions, function parameters, and return values
[6611177]854void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ) {
[a16764a6]855 SemanticErrorException errors;
[bb7422a]856 std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList );
[43c89a7]857
[dc3fbe5]858 for ( const DeclarationNode * cur = firstNode; cur; cur = cur->next ) {
[b87a5ed]859 try {
[bb7422a]860 ast::Decl * decl = cur->build();
[45e753c]861 assertf( decl, "buildList: build for ast::DeclWithType." );
[bb7422a]862 if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
[47498bd]863 dwt->location = cur->location;
[3ca7ef3]864 *out++ = dwt;
[bb7422a]865 } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) {
[3d7e53b]866 // e.g., int foo(struct S) {}
[bb7422a]867 auto inst = new ast::StructInstType( agg->name );
868 auto obj = new ast::ObjectDecl( cur->location, "", inst );
869 obj->linkage = linkage;
[3ca7ef3]870 *out++ = obj;
[47498bd]871 delete agg;
[bb7422a]872 } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) {
[3d7e53b]873 // e.g., int foo(union U) {}
[bb7422a]874 auto inst = new ast::UnionInstType( agg->name );
875 auto obj = new ast::ObjectDecl( cur->location,
876 "", inst, nullptr, ast::Storage::Classes(),
877 linkage );
[3ca7ef3]878 *out++ = obj;
[bb7422a]879 } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) {
[3d7e53b]880 // e.g., int foo(enum E) {}
[bb7422a]881 auto inst = new ast::EnumInstType( agg->name );
882 auto obj = new ast::ObjectDecl( cur->location,
883 "",
884 inst,
885 nullptr,
886 ast::Storage::Classes(),
887 linkage
888 );
[3ca7ef3]889 *out++ = obj;
[45e753c]890 } else {
891 assertf( false, "buildList: Could not convert to ast::DeclWithType." );
[843054c2]892 } // if
[45e753c]893 } catch ( SemanticErrorException & e ) {
[b87a5ed]894 errors.append( e );
[843054c2]895 } // try
[3a5131ed]896 } // for
897
[b87a5ed]898 if ( ! errors.isEmpty() ) {
899 throw errors;
[843054c2]900 } // if
[2298f728]901} // buildList
[3848e0e]902
[bb7422a]903void buildTypeList( const DeclarationNode * firstNode,
904 std::vector<ast::ptr<ast::Type>> & outputList ) {
[a16764a6]905 SemanticErrorException errors;
[bb7422a]906 std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList );
[2298f728]907
[dc3fbe5]908 for ( const DeclarationNode * cur = firstNode ; cur ; cur = cur->next ) {
[b87a5ed]909 try {
[ba7aa2d]910 * out++ = cur->buildType();
[45e753c]911 } catch ( SemanticErrorException & e ) {
[b87a5ed]912 errors.append( e );
[843054c2]913 } // try
[45e753c]914 } // for
[2298f728]915
[b87a5ed]916 if ( ! errors.isEmpty() ) {
917 throw errors;
[843054c2]918 } // if
[2298f728]919} // buildTypeList
[51b73452]920
[bb7422a]921ast::Decl * DeclarationNode::build() const {
[a16764a6]922 if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
[2298f728]923
[e994912]924 if ( asmStmt ) {
[bb7422a]925 auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() );
926 return new ast::AsmDecl( stmt->location, stmt );
[e994912]927 } // if
[2d019af]928 if ( directiveStmt ) {
[bb7422a]929 auto stmt = strict_dynamic_cast<ast::DirectiveStmt *>( directiveStmt->build() );
930 return new ast::DirectiveDecl( stmt->location, stmt );
[2d019af]931 } // if
[e994912]932
[bb7422a]933 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
[f0ecf9b]934 // otype is internally converted to dtype + otype parameters
[bb7422a]935 static const ast::TypeDecl::Kind kindMap[] = { ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Ftype, ast::TypeDecl::Ttype, ast::TypeDecl::Dimension };
936 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == ast::TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
[8f60f0b]937 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
[bb7422a]938 ast::TypeDecl * ret = new ast::TypeDecl( location,
939 *name,
940 ast::Storage::Classes(),
941 (ast::Type *)nullptr,
942 kindMap[ variable.tyClass ],
943 variable.tyClass == ast::TypeDecl::Otype || variable.tyClass == ast::TypeDecl::DStype,
944 variable.initializer ? variable.initializer->buildType() : nullptr
945 );
946 buildList( variable.assertions, ret->assertions );
[2298f728]947 return ret;
948 } // if
949
[843054c2]950 if ( type ) {
[dd020c0]951 // Function specifiers can only appear on a function definition/declaration.
952 //
953 // inline _Noreturn int f(); // allowed
954 // inline _Noreturn int g( int i ); // allowed
955 // inline _Noreturn int i; // disallowed
[fb04321]956 if ( type->kind != TypeData::Function && funcSpecs.any() ) {
[a16764a6]957 SemanticError( this, "invalid function specifier for " );
[dd020c0]958 } // if
[284da8c]959 // Forall qualifier can only appear on a function/aggregate definition/declaration.
960 //
961 // forall int f(); // allowed
962 // forall int g( int i ); // allowed
963 // forall int i; // disallowed
964 if ( type->kind != TypeData::Function && type->forall ) {
965 SemanticError( this, "invalid type qualifier for " );
966 } // if
[3ed994e]967 bool isDelete = initializer && initializer->get_isDelete();
[bb7422a]968 ast::Decl * decl = buildDecl(
969 type,
970 name ? *name : string( "" ),
971 storageClasses,
972 maybeBuild( bitfieldWidth ),
973 funcSpecs,
974 linkage,
975 asmName,
976 isDelete ? nullptr : maybeBuild( initializer ),
977 copy( attributes )
978 )->set_extension( extension );
[3ed994e]979 if ( isDelete ) {
[bb7422a]980 auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl );
[3ed994e]981 dwt->isDeleted = true;
982 }
983 return decl;
[843054c2]984 } // if
[2298f728]985
[f6e3e34]986 if ( assert.condition ) {
[bb7422a]987 auto cond = maybeBuild( assert.condition );
988 auto msg = strict_dynamic_cast<ast::ConstantExpr *>( maybeCopy( assert.message ) );
989 return new ast::StaticAssertDecl( location, cond, msg );
[f6e3e34]990 }
991
[dd020c0]992 // SUE's cannot have function specifiers, either
993 //
[79aae15]994 // inline _Noreturn struct S { ... }; // disallowed
995 // inline _Noreturn enum E { ... }; // disallowed
[fb04321]996 if ( funcSpecs.any() ) {
[a16764a6]997 SemanticError( this, "invalid function specifier for " );
[843054c2]998 } // if
[e874605]999 if ( enumInLine ) {
[bb7422a]1000 return new ast::InlineMemberDecl( location,
1001 *name, (ast::Type*)nullptr, storageClasses, linkage );
[e874605]1002 } // if
[dd020c0]1003 assertf( name, "ObjectDecl must a have name\n" );
[bb7422a]1004 auto ret = new ast::ObjectDecl( location,
1005 *name,
1006 (ast::Type*)nullptr,
1007 maybeBuild( initializer ),
1008 storageClasses,
1009 linkage,
1010 maybeBuild( bitfieldWidth )
1011 );
1012 ret->asmName = asmName;
1013 ret->extension = extension;
1014 return ret;
[51b73452]1015}
1016
[bb7422a]1017ast::Type * DeclarationNode::buildType() const {
[b87a5ed]1018 assert( type );
[974906e2]1019
[b87a5ed]1020 switch ( type->kind ) {
[0d0931d]1021 case TypeData::Aggregate: {
[bb7422a]1022 ast::BaseInstType * ret =
1023 buildComAggInst( type, copy( attributes ), linkage );
1024 buildList( type->aggregate.actuals, ret->params );
[0d0931d]1025 return ret;
1026 }
1027 case TypeData::Symbolic: {
[bb7422a]1028 ast::TypeInstType * ret = new ast::TypeInstType(
1029 *type->symbolic.name,
1030 // This is just a default, the true value is not known yet.
1031 ast::TypeDecl::Dtype,
1032 buildQualifiers( type ),
1033 copy( attributes ) );
1034 buildList( type->symbolic.actuals, ret->params );
[0d0931d]1035 return ret;
1036 }
1037 default:
[bb7422a]1038 ast::Type * simpletypes = typebuild( type );
1039 // copy because member is const
1040 simpletypes->attributes = attributes;
[c0aa336]1041 return simpletypes;
[b87a5ed]1042 } // switch
[3848e0e]1043}
1044
[b87a5ed]1045// Local Variables: //
1046// tab-width: 4 //
1047// mode: c++ //
1048// compile-command: "make install" //
1049// End: //
Note: See TracBrowser for help on using the repository browser.