Changeset 65197c2 for src/Parser


Ignore:
Timestamp:
Dec 5, 2017, 2:17:17 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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, stuck-waitfor-destruct, with_gc
Children:
971d9f2, a85e44c, c13e8dc8
Parents:
12d2dc8 (diff), 866f560 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r12d2dc8 r65197c2  
    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

    r12d2dc8 r65197c2  
    6969
    7070        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
    71         virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
     71        virtual void printList( std::ostream &os, int indent = 0 ) const {
     72                print( os, indent );
     73                if ( next ) next->print( os, indent );
     74        }
    7275
    7376        static int indent_by;
     
    120123        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
    121124
    122         virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
     125        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
     126                os << expr.get() << std::endl;
     127        }
    123128        void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
    124129
     
    257262        DeclarationNode * addBitfield( ExpressionNode * size );
    258263        DeclarationNode * addVarArgs();
    259         DeclarationNode * addFunctionBody( StatementNode * body );
     264        DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr );
    260265        DeclarationNode * addOldDeclList( DeclarationNode * list );
    261266        DeclarationNode * setBase( TypeData * newType );
     
    359364        virtual StatementNode * append_last_case( StatementNode * );
    360365
    361         virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
    362         virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
     366        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
     367                os << stmt.get() << std::endl;
     368        }
    363369  private:
    364370        std::unique_ptr<Statement> stmt;
     
    408414WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when );
    409415WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when );
     416WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );
    410417
    411418//##############################################################################
  • src/Parser/StatementNode.cc

    r12d2dc8 r65197c2  
    282282        node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    283283
    284         node->orelse.statement = maybeMoveBuild<Statement >( else_stmt );
     284        node->orelse.statement  = maybeMoveBuild<Statement >( else_stmt );
    285285        node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( else_when ) );
    286286
    287287        return node;
     288}
     289
     290WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     291        std::list< Expression * > e;
     292        buildMoveList( exprs, e );
     293        Statement * s = maybeMoveBuild<Statement>( stmt );
     294        return new WithStmt( e, s );
    288295}
    289296
  • src/Parser/parser.yy

    r12d2dc8 r65197c2  
    10581058with_statement:
    10591059        WITH '(' tuple_expression_list ')' statement
    1060                 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME
     1060                {
     1061                        $$ = new StatementNode( build_with( $3, $5 ) );
     1062                }
    10611063        ;
    10621064
     
    24102412                { $$ = nullptr; }
    24112413        | WITH '(' tuple_expression_list ')'
    2412                 { throw SemanticError("With clause is currently unimplemented."); $$ = nullptr; } // FIX ME
     2414                { $$ = new StatementNode( build_with( $3, nullptr ) ); }
    24132415        ;
    24142416
     
    24202422                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
    24212423                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
    2422                         $1->get_last()->addFunctionBody( $3 );
     2424                        $1->get_last()->addFunctionBody( $3, $2 );
    24232425                        $$ = $1;
    24242426                }
     
    24282430                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24292431                        typedefTable.leaveScope();
    2430                         $$ = $2->addFunctionBody( $4 )->addType( $1 );
     2432                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24312433                }
    24322434                // handles default int return type, OBSOLESCENT (see 1)
     
    24352437                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24362438                        typedefTable.leaveScope();
    2437                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2439                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    24382440                }
    24392441                // handles default int return type, OBSOLESCENT (see 1)
     
    24422444                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24432445                        typedefTable.leaveScope();
    2444                         $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2446                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
    24452447                }
    24462448                // handles default int return type, OBSOLESCENT (see 1)
     
    24492451                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24502452                        typedefTable.leaveScope();
    2451                         $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     2453                        $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
    24522454                }
    24532455
     
    24582460                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24592461                        typedefTable.leaveScope();
    2460                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
     2462                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
    24612463                }
    24622464                // handles default int return type, OBSOLESCENT (see 1)
     
    24652467                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24662468                        typedefTable.leaveScope();
    2467                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2469                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    24682470                }
    24692471                // handles default int return type, OBSOLESCENT (see 1)
     
    24722474                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24732475                        typedefTable.leaveScope();
    2474                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2476                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
    24752477                }
    24762478                // handles default int return type, OBSOLESCENT (see 1)
     
    24792481                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24802482                        typedefTable.leaveScope();
    2481                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
     2483                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    24822484                }
    24832485        ;
Note: See TracChangeset for help on using the changeset viewer.