Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rf9feab8 r90152a4  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 20 09:21:52 2017
    13 // Update Count     : 1031
     12// Last Modified On : Fri Jul 20 14:56:54 2018
     13// Update Count     : 1107
    1414//
    1515
     
    3232#include "SynTree/Type.h"          // for Type, Type::StorageClasses, Type::...
    3333#include "TypeData.h"              // for TypeData, TypeData::Aggregate_t
    34 #include "TypedefTable.h"          // for TypedefTable, TypedefTable::kind_t...
     34#include "TypedefTable.h"          // for TypedefTable
    3535
    3636class Initializer;
     
    4747const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };
    4848const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
    49 const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "NoBuiltinTypeNames" };
     49const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "zero_t", "one_t", "NoBuiltinTypeNames" };
    5050
    5151UniqueName DeclarationNode::anonymous( "__anonymous" );
     
    5454
    5555DeclarationNode::DeclarationNode() :
    56                 type( nullptr ),
    57                 bitfieldWidth( nullptr ),
    58                 hasEllipsis( false ),
    59                 linkage( ::linkage ),
    60                 asmName( nullptr ),
    61                 initializer( nullptr ),
    62                 extension( false ),
    63                 asmStmt( nullptr ) {
     56        linkage( ::linkage ) {
    6457
    6558//      variable.name = nullptr;
     
    7164        attr.expr = nullptr;
    7265        attr.type = nullptr;
     66
     67        assert.condition = nullptr;
     68        assert.message = nullptr;
    7369}
    7470
     
    8884        // asmName, no delete, passed to next stage
    8985        delete initializer;
     86
     87        delete assert.condition;
     88        delete assert.message;
    9089}
    9190
     
    9594        newnode->name = name ? new string( *name ) : nullptr;
    9695
     96        newnode->builtin = NoBuiltinType;
    9797        newnode->type = maybeClone( type );
     98        newnode->inLine = inLine;
    9899        newnode->storageClasses = storageClasses;
    99100        newnode->funcSpecs = funcSpecs;
     
    117118        newnode->attr.expr = maybeClone( attr.expr );
    118119        newnode->attr.type = maybeClone( attr.type );
     120
     121        newnode->assert.condition = maybeClone( assert.condition );
     122        newnode->assert.message = maybeClone( assert.message );
    119123        return newnode;
    120124} // DeclarationNode::clone
    121125
    122 bool DeclarationNode::get_hasEllipsis() const {
    123         return hasEllipsis;
    124 }
    125 
    126 void DeclarationNode::print( std::ostream &os, int indent ) const {
     126void DeclarationNode::print( std::ostream & os, int indent ) const {
    127127        os << string( indent, ' ' );
    128128        if ( name ) {
     
    160160}
    161161
    162 void DeclarationNode::printList( std::ostream &os, int indent ) const {
     162void DeclarationNode::printList( std::ostream & os, int indent ) const {
    163163        ParseNode::printList( os, indent );
    164164        if ( hasEllipsis ) {
     
    167167}
    168168
    169 DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
     169DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
    170170        DeclarationNode * newnode = new DeclarationNode;
    171171        newnode->name = name;
    172172        newnode->type = new TypeData( TypeData::Function );
    173173        newnode->type->function.params = param;
    174         newnode->type->function.newStyle = newStyle;
    175174        newnode->type->function.body = body;
    176 
    177         // ignore unnamed routine declarations: void p( int (*)(int) );
    178         if ( newnode->name ) {
    179                 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    180         } // if
    181175
    182176        if ( ret ) {
     
    244238} // DeclarationNode::newForall
    245239
    246 DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
     240DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
    247241        DeclarationNode * newnode = new DeclarationNode;
    248242        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    253247} // DeclarationNode::newFromTypedef
    254248
     249DeclarationNode * DeclarationNode::newFromGlobalScope() {
     250        DeclarationNode * newnode = new DeclarationNode;
     251        newnode->type = new TypeData( TypeData::GlobalScope );
     252        return newnode;
     253}
     254
     255DeclarationNode * DeclarationNode::newQualifiedType( DeclarationNode * parent, DeclarationNode * child) {
     256        DeclarationNode * newnode = new DeclarationNode;
     257        newnode->type = new TypeData( TypeData::Qualified );
     258        newnode->type->qualified.parent = parent->type;
     259        newnode->type->qualified.child = child->type;
     260        parent->type = nullptr;
     261        child->type = nullptr;
     262        delete parent;
     263        delete child;
     264        return newnode;
     265}
     266
    255267DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    256         assert( name );
    257268        DeclarationNode * newnode = new DeclarationNode;
    258269        newnode->type = new TypeData( TypeData::Aggregate );
    259270        newnode->type->aggregate.kind = kind;
    260         newnode->type->aggregate.name = name;
     271        newnode->type->aggregate.name =  name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
    261272        newnode->type->aggregate.actuals = actuals;
    262273        newnode->type->aggregate.fields = fields;
     
    264275        newnode->type->aggregate.tagged = false;
    265276        newnode->type->aggregate.parent = nullptr;
     277        newnode->type->aggregate.anon = name == nullptr;
    266278        return newnode;
    267279} // DeclarationNode::newAggregate
    268280
    269 DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
    270         assert( name );
     281DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
    271282        DeclarationNode * newnode = new DeclarationNode;
    272283        newnode->type = new TypeData( TypeData::Enum );
    273         newnode->type->enumeration.name = name;
     284        newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
    274285        newnode->type->enumeration.constants = constants;
    275286        newnode->type->enumeration.body = body;
     287        newnode->type->enumeration.anon = name == nullptr;
    276288        return newnode;
    277289} // DeclarationNode::newEnum
    278290
    279 DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
     291DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
    280292        DeclarationNode * newnode = new DeclarationNode;
    281293        newnode->name = name;
    282294        newnode->enumeratorValue.reset( constant );
    283         typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    284295        return newnode;
    285296} // DeclarationNode::newEnumConstant
    286297
    287 DeclarationNode * DeclarationNode::newName( string * name ) {
     298DeclarationNode * DeclarationNode::newName( const string * name ) {
    288299        DeclarationNode * newnode = new DeclarationNode;
    289300        newnode->name = name;
     
    291302} // DeclarationNode::newName
    292303
    293 DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
     304DeclarationNode * DeclarationNode::newFromTypeGen( const string * name, ExpressionNode * params ) {
    294305        DeclarationNode * newnode = new DeclarationNode;
    295306        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    300311} // DeclarationNode::newFromTypeGen
    301312
    302 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
     313DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, const string * name ) {
    303314        DeclarationNode * newnode = new DeclarationNode;
    304315        newnode->type = nullptr;
     
    331342} // DeclarationNode::newTraitUse
    332343
    333 DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
     344DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
    334345        DeclarationNode * newnode = new DeclarationNode;
    335346        newnode->name = name;
     
    343354        DeclarationNode * newnode = new DeclarationNode;
    344355        newnode->type = new TypeData( kind == OperKinds::PointTo ? TypeData::Pointer : TypeData::Reference );
     356        if ( kind == OperKinds::And ) {
     357                // T && is parsed as 'And' operator rather than two references => add a second reference type
     358                TypeData * td = new TypeData( TypeData::Reference );
     359                td->base = newnode->type;
     360                newnode->type = td;
     361        }
    345362        if ( qualifiers ) {
    346363                return newnode->addQualifiers( qualifiers );
     
    400417} // DeclarationNode::newBuiltinType
    401418
    402 DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
     419DeclarationNode * DeclarationNode::newAttr( const string * name, ExpressionNode * expr ) {
    403420        DeclarationNode * newnode = new DeclarationNode;
    404421        newnode->type = nullptr;
     
    409426}
    410427
    411 DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
     428DeclarationNode * DeclarationNode::newAttr( const string * name, DeclarationNode * type ) {
    412429        DeclarationNode * newnode = new DeclarationNode;
    413430        newnode->type = nullptr;
     
    418435}
    419436
    420 DeclarationNode * DeclarationNode::newAttribute( string * name, ExpressionNode * expr ) {
     437DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
    421438        DeclarationNode * newnode = new DeclarationNode;
    422439        newnode->type = nullptr;
     
    433450        return newnode;
    434451}
     452
     453DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) {
     454        DeclarationNode * newnode = new DeclarationNode;
     455        newnode->assert.condition = condition;
     456        newnode->assert.message = message;
     457        return newnode;
     458}
     459
    435460
    436461void appendError( string & dst, const string & src ) {
     
    489514} // DeclarationNode::copySpecifiers
    490515
    491 static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
    492         if ( src->forall && dst->kind == TypeData::Function ) {
    493                 if ( dst->forall ) {
    494                         dst->forall->appendList( src->forall );
    495                 } else {
    496                         dst->forall = src->forall;
    497                 } // if
    498                 src->forall = nullptr;
    499         } // if
     516static void addQualifiersToType( TypeData *& src, TypeData * dst ) {
    500517        if ( dst->base ) {
    501518                addQualifiersToType( src, dst->base );
     
    509526
    510527DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
    511         if ( ! q ) { delete q; return this; }                           // empty qualifier
     528        if ( ! q ) { return this; }                                                     // empty qualifier
    512529
    513530        checkSpecifiers( q );
     
    531548                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
    532549                                } else {                                                                // not polymorphic
    533                                         type->aggregate.params = q->type->forall; // make polymorphic type
    534                                         // change implicit typedef from TYPEDEFname to TYPEGENname
    535                                         typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
     550                                        type->aggregate.params = q->type->forall; // set forall qualifier
    536551                                } // if
    537552                        } else {                                                                        // not polymorphic
     
    543558
    544559        checkQualifiers( type, q->type );
     560        if ( (builtin == Zero || builtin == One) && q->type->qualifiers.val != 0 && error.length() == 0 ) {
     561                SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )], builtinTypeNames[builtin] );
     562        } // if
    545563        addQualifiersToType( q->type, type );
    546564
     
    549567} // addQualifiers
    550568
    551 static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     569static void addTypeToType( TypeData *& src, TypeData *& dst ) {
    552570        if ( src->forall && dst->kind == TypeData::Function ) {
    553571                if ( dst->forall ) {
     
    575593                                        dst->basictype = src->basictype;
    576594                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    577                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: ", src );
     595                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
    578596
    579597                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    580598                                        dst->complextype = src->complextype;
    581599                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    582                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: ", src );
     600                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
    583601
    584602                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    585603                                        dst->signedness = src->signedness;
    586604                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    587                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: ", src );
     605                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
    588606
    589607                                if ( dst->length == DeclarationNode::NoLength ) {
     
    592610                                        dst->length = DeclarationNode::LongLong;
    593611                                } else if ( src->length != DeclarationNode::NoLength )
    594                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: ", src );
     612                                        SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
    595613                        } // if
    596614                        break;
     
    717735}
    718736
    719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, StatementNode * with ) {
     737DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, ExpressionNode * withExprs ) {
    720738        assert( type );
    721739        assert( type->kind == TypeData::Function );
    722740        assert( ! type->function.body );
    723         if ( with ) {
    724                 // convert
    725                 //  void f(S s) with (s) { x = 0; }
    726                 // to
    727                 //  void f(S s) { with(s) { x = 0; } }
    728                 WithStmt * withStmt = strict_dynamic_cast< WithStmt * >( with->build() );
    729                 withStmt->stmt = body->build();
    730                 delete body;
    731                 delete with;
    732                 body = new StatementNode( new CompoundStmt( { withStmt } ) );
    733         }
    734741        type->function.body = body;
     742        type->function.withExprs = withExprs;
    735743        return this;
    736744}
     
    771779DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    772780        if ( p ) {
    773                 assert( p->type->kind == TypeData::Pointer || TypeData::Reference );
     781                assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
    774782                setBase( p->type );
    775783                p->type = nullptr;
     
    916924                                delete newType->aggInst.aggregate->enumeration.constants;
    917925                                newType->aggInst.aggregate->enumeration.constants = nullptr;
     926                                newType->aggInst.aggregate->enumeration.body = false;
    918927                        } else {
    919928                                assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
    920929                                delete newType->aggInst.aggregate->aggregate.fields;
    921930                                newType->aggInst.aggregate->aggregate.fields = nullptr;
     931                                newType->aggInst.aggregate->aggregate.body = false;
    922932                        } // if
    923933                        // don't hoist twice
     
    948958}
    949959
    950 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
    951         SemanticError errors;
     960void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) {
     961        SemanticErrorException errors;
    952962        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    953963
    954964        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    955965                try {
     966                        bool extracted = false;
     967                        bool anon = false;
    956968                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    957969                                // handle the case where a structure declaration is contained within an object or type declaration
    958970                                Declaration * decl = extr->build();
    959971                                if ( decl ) {
     972                                        // hoist the structure declaration
    960973                                        decl->location = cur->location;
    961974                                        * out++ = decl;
     975
     976                                        // need to remember the cases where a declaration contains an anonymous aggregate definition
     977                                        extracted = true;
     978                                        assert( extr->type );
     979                                        if ( extr->type->kind == TypeData::Aggregate ) {
     980                                                anon = extr->type->aggregate.anon;
     981                                        } else if ( extr->type->kind == TypeData::Enum ) {
     982                                                // xxx - is it useful to have an implicit anonymous enum member?
     983                                                anon = extr->type->enumeration.anon;
     984                                        }
    962985                                } // if
    963986                                delete extr;
     
    966989                        Declaration * decl = cur->build();
    967990                        if ( decl ) {
    968                                 decl->location = cur->location;
    969                                 * out++ = decl;
     991                                // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.:
     992                                // struct S {
     993                                //   struct T { int x; }; // no anonymous member
     994                                //   struct { int y; };   // anonymous member
     995                                //   struct T;            // anonymous member
     996                                // };
     997                                if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) {
     998                                        if ( decl->name == "" ) {
     999                                                if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) {
     1000                                                        if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType *>( dwt->get_type() ) ) {
     1001                                                                if ( aggr->name.find("anonymous") == std::string::npos ) {
     1002                                                                        if ( ! cur->get_inLine() ) {
     1003                                                                                // temporary: warn about anonymous member declarations of named types, since
     1004                                                                                // this conflicts with the syntax for the forward declaration of an anonymous type
     1005                                                                                SemanticWarning( cur->location, Warning::AggrForwardDecl, aggr->name.c_str() );
     1006                                                                        } // if
     1007                                                                } // if
     1008                                                        } // if
     1009                                                } // if
     1010                                        } // if
     1011                                        decl->location = cur->location;
     1012                                        *out++ = decl;
     1013                                } // if
    9701014                        } // if
    971                 } catch( SemanticError &e ) {
    972                         e.set_location( cur->location );
     1015                } catch( SemanticErrorException & e ) {
    9731016                        errors.append( e );
    9741017                } // try
    975         } // while
     1018        } // for
    9761019
    9771020        if ( ! errors.isEmpty() ) {
     
    9801023} // buildList
    9811024
    982 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
    983         SemanticError errors;
     1025// currently only builds assertions, function parameters, and return values
     1026void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) {
     1027        SemanticErrorException errors;
    9841028        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    9851029
     
    9871031                try {
    9881032                        Declaration * decl = cur->build();
    989                         if ( decl ) {
    990                                 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    991                                         dwt->location = cur->location;
    992                                         * out++ = dwt;
    993                                 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    994                                         StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    995                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    996                                         obj->location = cur->location;
    997                                         * out++ = obj;
    998                                         delete agg;
    999                                 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    1000                                         UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    1001                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1002                                         obj->location = cur->location;
    1003                                         * out++ = obj;
    1004                                 } // if
     1033                        assert( decl );
     1034                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     1035                                dwt->location = cur->location;
     1036                                * out++ = dwt;
     1037                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     1038                                // e.g., int foo(struct S) {}
     1039                                StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
     1040                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1041                                obj->location = cur->location;
     1042                                * out++ = obj;
     1043                                delete agg;
     1044                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     1045                                // e.g., int foo(union U) {}
     1046                                UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
     1047                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1048                                obj->location = cur->location;
     1049                                * out++ = obj;
     1050                        } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
     1051                                // e.g., int foo(enum E) {}
     1052                                EnumInstType * inst = new EnumInstType( Type::Qualifiers(), agg->name );
     1053                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1054                                obj->location = cur->location;
     1055                                * out++ = obj;
    10051056                        } // if
    1006                 } catch( SemanticError &e ) {
    1007                         e.set_location( cur->location );
     1057                } catch( SemanticErrorException & e ) {
    10081058                        errors.append( e );
    10091059                } // try
     
    10151065} // buildList
    10161066
    1017 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
    1018         SemanticError errors;
     1067void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) {
     1068        SemanticErrorException errors;
    10191069        std::back_insert_iterator< std::list< Type * > > out( outputList );
    10201070        const DeclarationNode * cur = firstNode;
     
    10231073                try {
    10241074                        * out++ = cur->buildType();
    1025                 } catch( SemanticError &e ) {
    1026                         e.set_location( cur->location );
     1075                } catch( SemanticErrorException & e ) {
    10271076                        errors.append( e );
    10281077                } // try
     
    10361085
    10371086Declaration * DeclarationNode::build() const {
    1038         if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
     1087        if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
    10391088
    10401089        if ( asmStmt ) {
     
    10591108                //    inline _Noreturn int i;                   // disallowed
    10601109                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
    1061                         throw SemanticError( "invalid function specifier for ", this );
    1062                 } // if
    1063                 return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
    1064         } // if
     1110                        SemanticError( this, "invalid function specifier for " );
     1111                } // if
     1112                // Forall qualifier can only appear on a function/aggregate definition/declaration.
     1113                //
     1114                //    forall int f();                                   // allowed
     1115                //    forall int g( int i );                    // allowed
     1116                //    forall int i;                                             // disallowed
     1117                if ( type->kind != TypeData::Function && type->forall ) {
     1118                        SemanticError( this, "invalid type qualifier for " );
     1119                } // if
     1120                bool isDelete = initializer && initializer->get_isDelete();
     1121                Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     1122                if ( isDelete ) {
     1123                        DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
     1124                        dwt->isDeleted = true;
     1125                }
     1126                return decl;
     1127        } // if
     1128
     1129        if ( assert.condition ) {
     1130                return new StaticAssertDecl( maybeBuild< Expression >( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
     1131        }
    10651132
    10661133        // SUE's cannot have function specifiers, either
     
    10691136        //    inlne _Noreturn enum   E { ... };         // disallowed
    10701137        if ( funcSpecs.any() ) {
    1071                 throw SemanticError( "invalid function specifier for ", this );
     1138                SemanticError( this, "invalid function specifier for " );
    10721139        } // if
    10731140        assertf( name, "ObjectDecl must a have name\n" );
Note: See TracChangeset for help on using the changeset viewer.