Changeset 5fcba14 for src/Parser


Ignore:
Timestamp:
Dec 4, 2017, 11:08:27 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
6d2f993
Parents:
497282e
Message:

Implement function declaration's with clause

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r497282e r5fcba14  
    717717}
    718718
    719 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) {
     719DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body, StatementNode * with ) {
    720720        assert( type );
    721721        assert( type->kind == TypeData::Function );
    722722        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        }
    723734        type->function.body = body;
    724735        return this;
  • src/Parser/ParseNode.h

    r497282e r5fcba14  
    262262        DeclarationNode * addBitfield( ExpressionNode * size );
    263263        DeclarationNode * addVarArgs();
    264         DeclarationNode * addFunctionBody( StatementNode * body );
     264        DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr );
    265265        DeclarationNode * addOldDeclList( DeclarationNode * list );
    266266        DeclarationNode * setBase( TypeData * newType );
  • src/Parser/parser.yy

    r497282e r5fcba14  
    24122412                { $$ = nullptr; }
    24132413        | WITH '(' tuple_expression_list ')'
    2414                 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME
     2414                { $$ = new StatementNode( build_with( $3, nullptr ) ); }
    24152415        ;
    24162416
     
    24222422                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    24232423                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
    2424                         $1->get_last()->addFunctionBody( $3 );
     2424                        $1->get_last()->addFunctionBody( $3, $2 );
    24252425                        $$ = $1;
    24262426                }
     
    24302430                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24312431                        typedefTable.leaveScope();
    2432                         $$ = $2->addFunctionBody( $4 )->addType( $1 );
     2432                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24332433                }
    24342434                // handles default int return type, OBSOLESCENT (see 1)
     
    24372437                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24382438                        typedefTable.leaveScope();
    2439                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2439                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    24402440                }
    24412441                // handles default int return type, OBSOLESCENT (see 1)
     
    24442444                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24452445                        typedefTable.leaveScope();
    2446                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2446                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    24472447                }
    24482448                // handles default int return type, OBSOLESCENT (see 1)
     
    24512451                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24522452                        typedefTable.leaveScope();
    2453                         $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     2453                        $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    24542454                }
    24552455
     
    24602460                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24612461                        typedefTable.leaveScope();
    2462                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
     2462                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    24632463                }
    24642464                // handles default int return type, OBSOLESCENT (see 1)
     
    24672467                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24682468                        typedefTable.leaveScope();
    2469                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2469                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    24702470                }
    24712471                // handles default int return type, OBSOLESCENT (see 1)
     
    24742474                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24752475                        typedefTable.leaveScope();
    2476                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2476                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    24772477                }
    24782478                // handles default int return type, OBSOLESCENT (see 1)
     
    24812481                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24822482                        typedefTable.leaveScope();
    2483                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
     2483                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    24842484                }
    24852485        ;
Note: See TracChangeset for help on using the changeset viewer.