Changeset e50e9ff for src/Parser


Ignore:
Timestamp:
Aug 22, 2017, 11:42:06 AM (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:
90c4df0
Parents:
6ac5223 (diff), b3d413b (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:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 16:39:43 2017
    13 // Update Count     : 340
     12// Last Modified On : Thu Aug 17 16:01:31 2017
     13// Update Count     : 345
    1414//
    1515
     
    2424#include "SynTree/Expression.h"    // for Expression, ConstantExpr
    2525#include "SynTree/Label.h"         // for Label, noLabels
     26#include "SynTree/Declaration.h"
    2627#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
    2728#include "parserutility.h"         // for notZeroExpr
     
    9899        } // if
    99100
    100         return new IfStmt( noLabels, notZeroExpr(
    101                                                            /*ctl->condition
    102                                                                  ?*/ maybeMoveBuild< Expression >(ctl->condition)
    103                                                                  /*: new VariableExpr( init.end() )*/ )
    104                                                    , thenb, elseb );
    105         // ret->initialization = init;
    106         // delete ctl;
    107         // assert( ret );
    108         // return ret;
     101        Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     102        delete ctl;
     103        return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
    109104}
    110105
  • src/Parser/parser.yy

    r6ac5223 re50e9ff  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 18:09:14 2017
    13 // Update Count     : 2485
     12// Last Modified On : Sun Aug 20 09:21:54 2017
     13// Update Count     : 2573
    1414//
    1515
     
    131131%token ATTRIBUTE EXTENSION                                                              // GCC
    132132%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    133 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH   // CFA
     133%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH // CFA
    134134%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    135135%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    796796
    797797selection_statement:
    798         IF '(' if_control_expression ')' statement                              %prec THEN
     798        IF '(' push if_control_expression ')' statement                         %prec THEN
    799799                // explicitly deal with the shift/reduce conflict on if/else
    800                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    801         | IF '(' if_control_expression ')' statement ELSE statement
    802                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    803         | SWITCH '(' comma_expression ')' case_clause           // CFA
     800                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     801        | IF '(' push if_control_expression ')' statement ELSE statement
     802                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
     803        | SWITCH '(' comma_expression ')' case_clause
    804804                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    805805        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     
    823823
    824824if_control_expression:
    825         comma_expression
     825        comma_expression pop
    826826                { $$ = new IfCtl( nullptr, $1 ); }
    827         | c_declaration                                                                         // no semi-coln
     827        | c_declaration pop                                                                     // no semi-colon
    828828                { $$ = new IfCtl( $1, nullptr ); }
    829         | cfa_declaration                                                                       // no semi-colon
     829        | cfa_declaration pop                                                           // no semi-colon
    830830                { $$ = new IfCtl( $1, nullptr ); }
    831         | declaration comma_expression
     831        | declaration comma_expression                                          // semi-colon separated
    832832                { $$ = new IfCtl( $1, $2 ); }
    833833        ;
     
    11041104
    11051105KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    1106         pop
     1106        // empty
    11071107                { $$ = nullptr; }
    11081108        | KR_declaration_list
     
    11101110
    11111111KR_declaration_list:
    1112         c_declaration ';'
    1113         | KR_declaration_list push c_declaration ';'
     1112        push c_declaration pop ';'
     1113                { $$ = $2; }
     1114        | KR_declaration_list push c_declaration pop ';'
    11141115                { $$ = $1->appendList( $3 ); }
    11151116        ;
     
    11311132
    11321133declaration:                                                                                    // old & new style declarations
    1133         c_declaration ';'
    1134         | cfa_declaration ';'                                                           // CFA
     1134        c_declaration pop ';'
     1135        | cfa_declaration pop ';'                                                       // CFA
    11351136        ;
    11361137
     
    11471148
    11481149cfa_declaration:                                                                                // CFA
    1149         cfa_variable_declaration pop
    1150         | cfa_typedef_declaration pop
    1151         | cfa_function_declaration pop
    1152         | type_declaring_list pop
    1153         | trait_specifier pop
     1150        cfa_variable_declaration
     1151        | cfa_typedef_declaration
     1152        | cfa_function_declaration
     1153        | type_declaring_list
     1154        | trait_specifier
    11541155        ;
    11551156
     
    13511352
    13521353c_declaration:
    1353         declaration_specifier declaring_list pop
     1354        declaration_specifier declaring_list
    13541355                {
    13551356                        $$ = distAttr( $1, $2 );
    13561357                }
    1357         | typedef_declaration pop
    1358         | typedef_expression pop                                                        // GCC, naming expression type
    1359         | sue_declaration_specifier pop
     1358        | typedef_declaration
     1359        | typedef_expression                                                            // GCC, naming expression type
     1360        | sue_declaration_specifier
    13601361        ;
    13611362
     
    22302231                        $$ = $1->addFunctionBody( $2 );
    22312232                }
    2232         | KR_function_declarator push KR_declaration_list_opt compound_statement
     2233        | KR_function_declarator KR_declaration_list_opt compound_statement
    22332234                {
    22342235                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22352236                        typedefTable.leaveScope();
    2236                         $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 );
     2237                        $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
    22372238                }
    22382239        ;
     
    22782279
    22792280                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2280         | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2281        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22812282                {
    22822283                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22832284                        typedefTable.leaveScope();
    2284                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addType( $1 );
    2285                 }
    2286         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2285                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
     2286                }
     2287        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22872288                {
    22882289                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22892290                        typedefTable.leaveScope();
    2290                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
     2291                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
    22912292                }
    22922293
    22932294                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2294         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2295        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22952296                {
    22962297                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22972298                        typedefTable.leaveScope();
    2298                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    2299                 }
    2300         | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2299                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2300                }
     2301        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    23012302                {
    23022303                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23032304                        typedefTable.leaveScope();
    2304                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
     2305                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
    23052306                }
    23062307        ;
Note: See TracChangeset for help on using the changeset viewer.