Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rf2f512ba r5fcba14  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 20 14:56:54 2018
    13 // Update Count     : 1107
     12// Last Modified On : Mon Nov 20 09:21:52 2017
     13// Update Count     : 1031
    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
     34#include "TypedefTable.h"          // for TypedefTable, TypedefTable::kind_t...
    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", "zero_t", "one_t", "NoBuiltinTypeNames" };
     49const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "NoBuiltinTypeNames" };
    5050
    5151UniqueName DeclarationNode::anonymous( "__anonymous" );
     
    5454
    5555DeclarationNode::DeclarationNode() :
    56         linkage( ::linkage ) {
     56                type( nullptr ),
     57                bitfieldWidth( nullptr ),
     58                hasEllipsis( false ),
     59                linkage( ::linkage ),
     60                asmName( nullptr ),
     61                initializer( nullptr ),
     62                extension( false ),
     63                asmStmt( nullptr ) {
    5764
    5865//      variable.name = nullptr;
     
    6471        attr.expr = nullptr;
    6572        attr.type = nullptr;
    66 
    67         assert.condition = nullptr;
    68         assert.message = nullptr;
    6973}
    7074
     
    8488        // asmName, no delete, passed to next stage
    8589        delete initializer;
    86 
    87         delete assert.condition;
    88         delete assert.message;
    8990}
    9091
     
    9495        newnode->name = name ? new string( *name ) : nullptr;
    9596
    96         newnode->builtin = NoBuiltinType;
    9797        newnode->type = maybeClone( type );
    98         newnode->inLine = inLine;
    9998        newnode->storageClasses = storageClasses;
    10099        newnode->funcSpecs = funcSpecs;
     
    118117        newnode->attr.expr = maybeClone( attr.expr );
    119118        newnode->attr.type = maybeClone( attr.type );
    120 
    121         newnode->assert.condition = maybeClone( assert.condition );
    122         newnode->assert.message = maybeClone( assert.message );
    123119        return newnode;
    124120} // DeclarationNode::clone
    125121
    126 void DeclarationNode::print( std::ostream & os, int indent ) const {
     122bool DeclarationNode::get_hasEllipsis() const {
     123        return hasEllipsis;
     124}
     125
     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( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
     169DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
    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;
    174175        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
    175181
    176182        if ( ret ) {
     
    238244} // DeclarationNode::newForall
    239245
    240 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
     246DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
    241247        DeclarationNode * newnode = new DeclarationNode;
    242248        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    247253} // DeclarationNode::newFromTypedef
    248254
    249 DeclarationNode * DeclarationNode::newFromGlobalScope() {
    250         DeclarationNode * newnode = new DeclarationNode;
    251         newnode->type = new TypeData( TypeData::GlobalScope );
    252         return newnode;
    253 }
    254 
    255 DeclarationNode * 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 
    267255DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     256        assert( name );
    268257        DeclarationNode * newnode = new DeclarationNode;
    269258        newnode->type = new TypeData( TypeData::Aggregate );
    270259        newnode->type->aggregate.kind = kind;
    271         newnode->type->aggregate.name =  name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     260        newnode->type->aggregate.name = name;
    272261        newnode->type->aggregate.actuals = actuals;
    273262        newnode->type->aggregate.fields = fields;
     
    275264        newnode->type->aggregate.tagged = false;
    276265        newnode->type->aggregate.parent = nullptr;
    277         newnode->type->aggregate.anon = name == nullptr;
    278266        return newnode;
    279267} // DeclarationNode::newAggregate
    280268
    281 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
     269DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
     270        assert( name );
    282271        DeclarationNode * newnode = new DeclarationNode;
    283272        newnode->type = new TypeData( TypeData::Enum );
    284         newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     273        newnode->type->enumeration.name = name;
    285274        newnode->type->enumeration.constants = constants;
    286275        newnode->type->enumeration.body = body;
    287         newnode->type->enumeration.anon = name == nullptr;
    288276        return newnode;
    289277} // DeclarationNode::newEnum
    290278
    291 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
     279DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
    292280        DeclarationNode * newnode = new DeclarationNode;
    293281        newnode->name = name;
    294282        newnode->enumeratorValue.reset( constant );
     283        typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    295284        return newnode;
    296285} // DeclarationNode::newEnumConstant
    297286
    298 DeclarationNode * DeclarationNode::newName( const string * name ) {
     287DeclarationNode * DeclarationNode::newName( string * name ) {
    299288        DeclarationNode * newnode = new DeclarationNode;
    300289        newnode->name = name;
     
    302291} // DeclarationNode::newName
    303292
    304 DeclarationNode * DeclarationNode::newFromTypeGen( const string * name, ExpressionNode * params ) {
     293DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
    305294        DeclarationNode * newnode = new DeclarationNode;
    306295        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    311300} // DeclarationNode::newFromTypeGen
    312301
    313 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, const string * name ) {
     302DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
    314303        DeclarationNode * newnode = new DeclarationNode;
    315304        newnode->type = nullptr;
     
    342331} // DeclarationNode::newTraitUse
    343332
    344 DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
     333DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
    345334        DeclarationNode * newnode = new DeclarationNode;
    346335        newnode->name = name;
     
    354343        DeclarationNode * newnode = new DeclarationNode;
    355344        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         }
    362345        if ( qualifiers ) {
    363346                return newnode->addQualifiers( qualifiers );
     
    417400} // DeclarationNode::newBuiltinType
    418401
    419 DeclarationNode * DeclarationNode::newAttr( const string * name, ExpressionNode * expr ) {
     402DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
    420403        DeclarationNode * newnode = new DeclarationNode;
    421404        newnode->type = nullptr;
     
    426409}
    427410
    428 DeclarationNode * DeclarationNode::newAttr( const string * name, DeclarationNode * type ) {
     411DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
    429412        DeclarationNode * newnode = new DeclarationNode;
    430413        newnode->type = nullptr;
     
    435418}
    436419
    437 DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
     420DeclarationNode * DeclarationNode::newAttribute( string * name, ExpressionNode * expr ) {
    438421        DeclarationNode * newnode = new DeclarationNode;
    439422        newnode->type = nullptr;
     
    450433        return newnode;
    451434}
    452 
    453 DeclarationNode * 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 
    460435
    461436void appendError( string & dst, const string & src ) {
     
    514489} // DeclarationNode::copySpecifiers
    515490
    516 static void addQualifiersToType( TypeData *& src, TypeData * dst ) {
     491static 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
    517500        if ( dst->base ) {
    518501                addQualifiersToType( src, dst->base );
     
    526509
    527510DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
    528         if ( ! q ) { return this; }                                                     // empty qualifier
     511        if ( ! q ) { delete q; return this; }                           // empty qualifier
    529512
    530513        checkSpecifiers( q );
     
    548531                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
    549532                                } else {                                                                // not polymorphic
    550                                         type->aggregate.params = q->type->forall; // set forall qualifier
     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 );
    551536                                } // if
    552537                        } else {                                                                        // not polymorphic
     
    558543
    559544        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
    563545        addQualifiersToType( q->type, type );
    564546
     
    567549} // addQualifiers
    568550
    569 static void addTypeToType( TypeData *& src, TypeData *& dst ) {
     551static void addTypeToType( TypeData *&src, TypeData *&dst ) {
    570552        if ( src->forall && dst->kind == TypeData::Function ) {
    571553                if ( dst->forall ) {
     
    593575                                        dst->basictype = src->basictype;
    594576                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    595                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: " );
     577                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: ", src );
    596578
    597579                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    598580                                        dst->complextype = src->complextype;
    599581                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    600                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: " );
     582                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: ", src );
    601583
    602584                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    603585                                        dst->signedness = src->signedness;
    604586                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    605                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: " );
     587                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: ", src );
    606588
    607589                                if ( dst->length == DeclarationNode::NoLength ) {
     
    610592                                        dst->length = DeclarationNode::LongLong;
    611593                                } else if ( src->length != DeclarationNode::NoLength )
    612                                         SemanticError( yylloc, src, string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: " );
     594                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: ", src );
    613595                        } // if
    614596                        break;
     
    735717}
    736718
    737 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, ExpressionNode * withExprs ) {
     719DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, StatementNode * with ) {
    738720        assert( type );
    739721        assert( type->kind == TypeData::Function );
    740722        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        }
    741734        type->function.body = body;
    742         type->function.withExprs = withExprs;
    743735        return this;
    744736}
     
    779771DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    780772        if ( p ) {
    781                 assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
     773                assert( p->type->kind == TypeData::Pointer || TypeData::Reference );
    782774                setBase( p->type );
    783775                p->type = nullptr;
     
    924916                                delete newType->aggInst.aggregate->enumeration.constants;
    925917                                newType->aggInst.aggregate->enumeration.constants = nullptr;
    926                                 newType->aggInst.aggregate->enumeration.body = false;
    927918                        } else {
    928919                                assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
    929920                                delete newType->aggInst.aggregate->aggregate.fields;
    930921                                newType->aggInst.aggregate->aggregate.fields = nullptr;
    931                                 newType->aggInst.aggregate->aggregate.body = false;
    932922                        } // if
    933923                        // don't hoist twice
     
    958948}
    959949
    960 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) {
    961         SemanticErrorException errors;
     950void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
     951        SemanticError errors;
    962952        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    963953
    964954        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    965955                try {
    966                         bool extracted = false;
    967                         bool anon = false;
    968956                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    969957                                // handle the case where a structure declaration is contained within an object or type declaration
    970958                                Declaration * decl = extr->build();
    971959                                if ( decl ) {
    972                                         // hoist the structure declaration
    973960                                        decl->location = cur->location;
    974961                                        * 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                                         }
    985962                                } // if
    986963                                delete extr;
     
    989966                        Declaration * decl = cur->build();
    990967                        if ( 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;
     968                                decl->location = cur->location;
     969                                * out++ = decl;
     970                        } // if
     971                } catch( SemanticError &e ) {
     972                        e.set_location( cur->location );
     973                        errors.append( e );
     974                } // try
     975        } // while
     976
     977        if ( ! errors.isEmpty() ) {
     978                throw errors;
     979        } // if
     980} // buildList
     981
     982void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
     983        SemanticError errors;
     984        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
     985
     986        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
     987                try {
     988                        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;
    10131004                                } // if
    10141005                        } // if
    1015                 } catch( SemanticErrorException & e ) {
     1006                } catch( SemanticError &e ) {
     1007                        e.set_location( cur->location );
    10161008                        errors.append( e );
    10171009                } // try
     
    10231015} // buildList
    10241016
    1025 // currently only builds assertions, function parameters, and return values
    1026 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) {
    1027         SemanticErrorException errors;
    1028         std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    1029 
    1030         for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    1031                 try {
    1032                         Declaration * decl = cur->build();
    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;
    1056                         } // if
    1057                 } catch( SemanticErrorException & e ) {
    1058                         errors.append( e );
    1059                 } // try
    1060         } // for
    1061 
    1062         if ( ! errors.isEmpty() ) {
    1063                 throw errors;
    1064         } // if
    1065 } // buildList
    1066 
    1067 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) {
    1068         SemanticErrorException errors;
     1017void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
     1018        SemanticError errors;
    10691019        std::back_insert_iterator< std::list< Type * > > out( outputList );
    10701020        const DeclarationNode * cur = firstNode;
     
    10731023                try {
    10741024                        * out++ = cur->buildType();
    1075                 } catch( SemanticErrorException & e ) {
     1025                } catch( SemanticError &e ) {
     1026                        e.set_location( cur->location );
    10761027                        errors.append( e );
    10771028                } // try
     
    10851036
    10861037Declaration * DeclarationNode::build() const {
    1087         if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
     1038        if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
    10881039
    10891040        if ( asmStmt ) {
     
    11081059                //    inline _Noreturn int i;                   // disallowed
    11091060                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
    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         }
     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
    11321065
    11331066        // SUE's cannot have function specifiers, either
     
    11361069        //    inlne _Noreturn enum   E { ... };         // disallowed
    11371070        if ( funcSpecs.any() ) {
    1138                 SemanticError( this, "invalid function specifier for " );
     1071                throw SemanticError( "invalid function specifier for ", this );
    11391072        } // if
    11401073        assertf( name, "ObjectDecl must a have name\n" );
Note: See TracChangeset for help on using the changeset viewer.