source: src/Parser/DeclarationNode.cpp@ 0dffe91

Last change on this file since 0dffe91 was 16ba4897, checked in by Andrew Beach <ajbeach@…>, 12 months ago

Replaced SemanticErrorException::isEmpty with ...::throwIfNonEmpty. This is how it was used in every context and it saves a bit of text (if not two lines) at every use. I considered putting this function in the header for better inlining, but this should have at least the same preformance as the last version.

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