Changeset fb114fa1 for src/Parser


Ignore:
Timestamp:
Sep 27, 2016, 11:22:48 AM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4b1fd2c
Parents:
3b5e3aa
Message:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r3b5e3aa rfb114fa1  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep 24 11:12:52 2016
    13 // Update Count     : 627
     12// Last Modified On : Mon Sep 26 22:18:40 2016
     13// Update Count     : 640
    1414//
    1515
     
    9292
    9393        newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
     94        newnode->variable.tyClass = variable.tyClass;
    9495        newnode->variable.assertions = maybeClone( variable.assertions );
    95         newnode->variable.tyClass = variable.tyClass;
    9696
    9797        newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
     
    148148}
    149149
    150 DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
     150DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
    151151        DeclarationNode * newnode = new DeclarationNode;
    152152        newnode->name = name;
    153 
    154153        newnode->type = new TypeData( TypeData::Function );
    155154        newnode->type->function.params = param;
     
    222221} // DeclarationNode::newLength
    223222
    224 DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) {
     223DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
    225224        DeclarationNode * newnode = new DeclarationNode;
    226225        newnode->type = new TypeData( TypeData::SymbolicInst );
    227         newnode->type->symbolic.name = name ? new string( *name ) : nullptr;
     226        newnode->type->symbolic.name = name;
    228227        newnode->type->symbolic.isTypedef = true;
    229228        newnode->type->symbolic.params = nullptr;
     
    231230} // DeclarationNode::newFromTypedef
    232231
    233 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     232DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    234233        DeclarationNode * newnode = new DeclarationNode;
    235234        newnode->type = new TypeData( TypeData::Aggregate );
    236235        newnode->type->aggregate.kind = kind;
    237236        if ( name ) {
    238                 newnode->type->aggregate.name = new string( *name );
     237                newnode->type->aggregate.name = name;
    239238        } else {                                                                                        // anonymous aggregate ?
    240239                newnode->type->aggregate.name = new string( anonymous.newName() );
     
    246245} // DeclarationNode::newAggregate
    247246
    248 DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) {
    249         DeclarationNode * newnode = new DeclarationNode;
    250         newnode->name = name;
     247DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants ) {
     248        DeclarationNode * newnode = new DeclarationNode;
    251249        newnode->type = new TypeData( TypeData::Enum );
    252250        if ( name ) {
    253                 newnode->type->enumeration.name = new string( *name );
     251                newnode->type->enumeration.name = name;
    254252        } else {                                                                                        // anonymous aggregate ?
    255253                newnode->type->enumeration.name = new string( anonymous.newName() );
     
    259257} // DeclarationNode::newEnum
    260258
    261 DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) {
     259DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
    262260        DeclarationNode * newnode = new DeclarationNode;
    263261        newnode->name = name;
     
    267265} // DeclarationNode::newEnumConstant
    268266
    269 DeclarationNode * DeclarationNode::newName( std::string * name ) {
     267DeclarationNode * DeclarationNode::newName( string * name ) {
    270268        DeclarationNode * newnode = new DeclarationNode;
    271269        newnode->name = name;
     
    273271} // DeclarationNode::newName
    274272
    275 DeclarationNode * DeclarationNode::newFromTypeGen( std::string * name, ExpressionNode * params ) {
     273DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
    276274        DeclarationNode * newnode = new DeclarationNode;
    277275        newnode->type = new TypeData( TypeData::SymbolicInst );
    278         newnode->type->symbolic.name = name ? new string( *name ) : nullptr;
     276        newnode->type->symbolic.name = name;
    279277        newnode->type->symbolic.isTypedef = false;
    280278        newnode->type->symbolic.actuals = params;
     
    282280} // DeclarationNode::newFromTypeGen
    283281
    284 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) {
    285         DeclarationNode * newnode = new DeclarationNode;
    286         newnode->name = name;
    287 //      newnode->type = new TypeData( TypeData::Variable );
     282DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
     283        DeclarationNode * newnode = new DeclarationNode;
    288284        newnode->type = nullptr;
    289285        newnode->variable.tyClass = tc;
    290         newnode->variable.name = newnode->name ? new string( *newnode->name ) : nullptr;
     286        newnode->variable.name = name;
    291287        return newnode;
    292288} // DeclarationNode::newTypeParam
    293289
    294 DeclarationNode * DeclarationNode::newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ) {
     290DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
    295291        DeclarationNode * newnode = new DeclarationNode;
    296292        newnode->type = new TypeData( TypeData::Aggregate );
     
    302298} // DeclarationNode::newTrait
    303299
    304 DeclarationNode * DeclarationNode::newTraitUse( const std::string * name, ExpressionNode * params ) {
     300DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
    305301        DeclarationNode * newnode = new DeclarationNode;
    306302        newnode->type = new TypeData( TypeData::AggregateInst );
     
    312308} // DeclarationNode::newTraitUse
    313309
    314 DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) {
    315         DeclarationNode * newnode = new DeclarationNode;
    316         newnode->name = name;
     310DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
     311        DeclarationNode * newnode = new DeclarationNode;
    317312        newnode->type = new TypeData( TypeData::Symbolic );
    318313        newnode->type->symbolic.isTypedef = false;
    319314        newnode->type->symbolic.params = typeParams;
    320         newnode->type->symbolic.name = newnode->name;
     315        newnode->type->symbolic.name = name;
    321316        return newnode;
    322317} // DeclarationNode::newTypeDecl
     
    377372} // DeclarationNode::newBuiltinType
    378373
    379 DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) {
    380         DeclarationNode * newnode = new DeclarationNode;
    381 //      newnode->type = new TypeData( TypeData::Attr );
     374DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
     375        DeclarationNode * newnode = new DeclarationNode;
    382376        newnode->type = nullptr;
    383377        newnode->attr.name = name;
     
    386380}
    387381
    388 DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) {
    389         DeclarationNode * newnode = new DeclarationNode;
    390 //      newnode->type = new TypeData( TypeData::Attr );
     382DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
     383        DeclarationNode * newnode = new DeclarationNode;
    391384        newnode->type = nullptr;
    392385        newnode->attr.name = name;
     
    520513                                        dst->basictype = src->basictype;
    521514                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    522                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     515                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
    523516
    524517                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    525518                                        dst->complextype = src->complextype;
    526519                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    527                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     520                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
    528521
    529522                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    530523                                        dst->signedness = src->signedness;
    531524                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    532                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     525                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
    533526
    534527                                if ( dst->length == DeclarationNode::NoLength ) {
     
    537530                                        dst->length = DeclarationNode::LongLong;
    538531                                } else if ( src->length != DeclarationNode::NoLength )
    539                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     532                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
    540533                        } // if
    541534                        break;
     
    643636}
    644637
    645 DeclarationNode * DeclarationNode::addName( std::string * newname ) {
     638DeclarationNode * DeclarationNode::addName( string * newname ) {
    646639        assert( ! name );
    647640        name = newname;
Note: See TracChangeset for help on using the changeset viewer.