Changeset 936e9f4 for src/Parser
- Timestamp:
- Aug 16, 2017, 6:31:41 PM (7 years ago)
- 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:
- 21f0aa8, 6d49ea3
- Parents:
- fcc88a4
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rfcc88a4 r936e9f4 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thu Aug 10 16:54:00201713 // Update Count : 7 8911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 16 16:46:48 2017 13 // Update Count : 794 14 14 // 15 15 … … 376 376 Statement * build_expr( ExpressionNode * ctl ); 377 377 378 struct IfCtl { 379 IfCtl( DeclarationNode * decl, ExpressionNode * condition ) : 380 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} 381 382 StatementNode * init; 383 ExpressionNode * condition; 384 }; 385 378 386 struct ForCtl { 379 387 ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) : … … 387 395 }; 388 396 389 Statement * build_if( ExpressionNode* ctl, StatementNode * then_stmt, StatementNode * else_stmt );397 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 390 398 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt ); 391 399 Statement * build_case( ExpressionNode * ctl ); -
src/Parser/StatementNode.cc
rfcc88a4 r936e9f4 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 11 21:23:15201713 // Update Count : 3 3112 // Last Modified On : Wed Aug 16 16:39:43 2017 13 // Update Count : 340 14 14 // 15 15 … … 79 79 } 80 80 81 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {81 Statement *build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) { 82 82 Statement *thenb, *elseb = 0; 83 83 std::list< Statement * > branches; … … 92 92 elseb = branches.front(); 93 93 } // if 94 return new IfStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), thenb, elseb ); 94 95 std::list< Statement * > init; 96 if ( ctl->init != 0 ) { 97 buildMoveList( ctl->init, init ); 98 } // if 99 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; 95 109 } 96 110 -
src/Parser/parser.yy
rfcc88a4 r936e9f4 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 4 13:33:00201713 // Update Count : 24 7511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 16 18:09:14 2017 13 // Update Count : 2485 14 14 // 15 15 … … 98 98 StatementNode * sn; 99 99 ConstantExpr * constant; 100 IfCtl * ifctl; 100 101 ForCtl * fctl; 101 102 LabelNode * label; … … 175 176 %type<en> comma_expression comma_expression_opt 176 177 %type<en> argument_expression_list argument_expression default_initialize_opt 178 %type<ifctl> if_control_expression 177 179 %type<fctl> for_control_expression 178 180 %type<en> subrange … … 794 796 795 797 selection_statement: 796 IF '(' comma_expression ')' statement %prec THEN798 IF '(' if_control_expression ')' statement %prec THEN 797 799 // explicitly deal with the shift/reduce conflict on if/else 798 800 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 799 | IF '(' comma_expression ')' statement ELSE statement801 | IF '(' if_control_expression ')' statement ELSE statement 800 802 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 801 803 | SWITCH '(' comma_expression ')' case_clause // CFA … … 819 821 } 820 822 ; 823 824 if_control_expression: 825 comma_expression 826 { $$ = new IfCtl( nullptr, $1 ); } 827 | c_declaration // no semi-coln 828 { $$ = new IfCtl( $1, nullptr ); } 829 | cfa_declaration // no semi-colon 830 { $$ = new IfCtl( $1, nullptr ); } 831 | declaration comma_expression 832 { $$ = new IfCtl( $1, $2 ); } 833 ; 821 834 822 835 // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case … … 1097 1110 1098 1111 KR_declaration_list: 1099 c_declaration 1100 | KR_declaration_list push c_declaration 1112 c_declaration ';' 1113 | KR_declaration_list push c_declaration ';' 1101 1114 { $$ = $1->appendList( $3 ); } 1102 1115 ; … … 1117 1130 ; 1118 1131 1119 declaration: // CFA, new & oldstyle declarations1120 c fa_declaration1121 | c _declaration1132 declaration: // old & new style declarations 1133 c_declaration ';' 1134 | cfa_declaration ';' // CFA 1122 1135 ; 1123 1136 … … 1134 1147 1135 1148 cfa_declaration: // CFA 1136 cfa_variable_declaration pop ';'1137 | cfa_typedef_declaration pop ';'1138 | cfa_function_declaration pop ';'1139 | type_declaring_list pop ';'1140 | trait_specifier pop ';'1149 cfa_variable_declaration pop 1150 | cfa_typedef_declaration pop 1151 | cfa_function_declaration pop 1152 | type_declaring_list pop 1153 | trait_specifier pop 1141 1154 ; 1142 1155 … … 1338 1351 1339 1352 c_declaration: 1340 declaration_specifier declaring_list pop ';'1353 declaration_specifier declaring_list pop 1341 1354 { 1342 1355 $$ = distAttr( $1, $2 ); 1343 1356 } 1344 | typedef_declaration pop ';'1345 | typedef_expression pop ';'// GCC, naming expression type1346 | sue_declaration_specifier pop ';'1357 | typedef_declaration pop 1358 | typedef_expression pop // GCC, naming expression type 1359 | sue_declaration_specifier pop 1347 1360 ; 1348 1361
Note: See TracChangeset
for help on using the changeset viewer.