Changeset 6a276a0
- Timestamp:
- Mar 14, 2018, 1:19:39 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, with_gc
- Children:
- 720a007
- Parents:
- e2c70ab
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
re2c70ab r6a276a0 392 392 393 393 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 394 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );394 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 395 395 Statement * build_case( ExpressionNode * ctl ); 396 396 Statement * build_default(); -
src/Parser/StatementNode.cc
re2c70ab r6a276a0 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 23:25:23 201713 // Update Count : 34 612 // Last Modified On : Thu Mar 8 14:31:32 2018 13 // Update Count : 348 14 14 // 15 15 … … 116 116 } 117 117 118 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {118 Statement *build_switch( bool isSwitch, ExpressionNode *ctl, StatementNode *stmt ) { 119 119 std::list< Statement * > branches; 120 120 buildMoveList< Statement, StatementNode >( stmt, branches ); 121 if ( ! isSwitch ) { // choose statement 122 for ( Statement * stmt : branches ) { 123 CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt ); 124 if ( ! caseStmt->stmts.empty() ) { // code after "case" => end of case list 125 CompoundStmt * block = strict_dynamic_cast< CompoundStmt * >( caseStmt->stmts.front() ); 126 block->kids.push_back( new BranchStmt( "", BranchStmt::Break ) ); 127 } // if 128 } // for 129 } // if 121 130 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements 122 131 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); -
src/Parser/parser.yy
re2c70ab r6a276a0 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 17:48:54201813 // Update Count : 30 2812 // Last Modified On : Fri Mar 9 11:37:35 2018 13 // Update Count : 3075 14 14 // 15 15 … … 254 254 %type<sn> statement_decl statement_decl_list statement_list_nodecl 255 255 %type<sn> selection_statement 256 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list256 %type<sn> switch_clause_list_opt switch_clause_list 257 257 %type<en> case_value 258 258 %type<sn> case_clause case_value_list case_label case_label_list 259 %type<sn> fall_through fall_through_opt260 259 %type<sn> iteration_statement jump_statement 261 260 %type<sn> expression_statement asm_statement … … 917 916 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 918 917 | SWITCH '(' comma_expression ')' case_clause 919 { $$ = new StatementNode( build_switch( $3, $5 ) ); }918 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 920 919 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 921 920 { 922 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );921 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); 923 922 // The semantics of the declaration list is changed to include associated initialization, which is performed 924 923 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 929 928 } 930 929 | CHOOSE '(' comma_expression ')' case_clause // CFA 931 { $$ = new StatementNode( build_switch( $3, $5 ) ); }932 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA933 { 934 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );930 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 931 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 932 { 933 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); 935 934 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 936 935 } … … 970 969 ; 971 970 971 //label_list_opt: 972 // // empty 973 // | identifier_or_type_name ':' 974 // | label_list_opt identifier_or_type_name ':' 975 // ; 976 972 977 case_label_list: // CFA 973 978 case_label … … 990 995 | switch_clause_list case_label_list statement_list_nodecl 991 996 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); } 992 ;993 994 choose_clause_list_opt: // CFA995 // empty996 { $$ = nullptr; }997 | choose_clause_list998 ;999 1000 choose_clause_list: // CFA1001 case_label_list fall_through1002 { $$ = $1->append_last_case( $2 ); }1003 | case_label_list statement_list_nodecl fall_through_opt1004 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }1005 | choose_clause_list case_label_list fall_through1006 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }1007 | choose_clause_list case_label_list statement_list_nodecl fall_through_opt1008 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }1009 ;1010 1011 fall_through_opt: // CFA1012 // empty1013 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break1014 | fall_through1015 ;1016 1017 fall_through_name: // CFA1018 FALLTHRU1019 | FALLTHROUGH1020 ;1021 1022 fall_through: // CFA1023 fall_through_name1024 { $$ = nullptr; }1025 | fall_through_name ';'1026 { $$ = nullptr; }1027 997 ; 1028 998 … … 1050 1020 // whereas normal operator precedence yields goto (*i)+3; 1051 1021 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 1022 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1023 | fall_through_name ';' // CFA 1024 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); } 1025 | fall_through_name identifier_or_type_name ';' // CFA 1026 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); } 1027 | fall_through_name DEFAULT ';' // CFA 1028 { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); } 1052 1029 | CONTINUE ';' 1053 1030 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. … … 1076 1053 ; 1077 1054 1055 fall_through_name: // CFA 1056 FALLTHRU 1057 | FALLTHROUGH 1058 ; 1059 1078 1060 with_statement: 1079 1061 WITH '(' tuple_expression_list ')' statement … … 1090 1072 1091 1073 when_clause: 1092 WHEN '(' comma_expression ')' 1093 { $$ = $3; } 1074 WHEN '(' comma_expression ')' { $$ = $3; } 1094 1075 ; 1095 1076 … … 1115 1096 1116 1097 timeout: 1117 TIMEOUT '(' comma_expression ')' 1118 { $$ = $3; } 1098 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1119 1099 ; 1120 1100 … … 1159 1139 //empty 1160 1140 { $$ = nullptr; } 1161 | ';' conditional_expression 1162 { $$ = $2; } 1141 | ';' conditional_expression { $$ = $2; } 1163 1142 ; 1164 1143 1165 1144 handler_key: 1166 CATCH 1167 { $$ = CatchStmt::Terminate; } 1168 | CATCHRESUME 1169 { $$ = CatchStmt::Resume; } 1145 CATCH { $$ = CatchStmt::Terminate; } 1146 | CATCHRESUME { $$ = CatchStmt::Resume; } 1170 1147 ; 1171 1148 1172 1149 finally_clause: 1173 FINALLY compound_statement 1174 { 1175 $$ = new StatementNode( build_finally( $2 ) ); 1176 } 1150 FINALLY compound_statement { $$ = new StatementNode( build_finally( $2 ) ); } 1177 1151 ; 1178 1152 … … 2413 2387 $$ = $2; 2414 2388 } 2415 | forall'{' external_definition_list '}' // CFA, namespace2389 | type_qualifier_list '{' external_definition_list '}' // CFA, namespace 2416 2390 ; 2417 2391 -
src/SynTree/Statement.cc
re2c70ab r6a276a0 34 34 Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {} 35 35 36 void Statement::print( std::ostream & os, Indenter ) const {36 void Statement::print( std::ostream & os, Indenter indent ) const { 37 37 if ( ! labels.empty() ) { 38 os << "Labels: {";38 os << indent << "... Labels: {"; 39 39 for ( const Label & l : labels ) { 40 40 os << l << ","; … … 223 223 224 224 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 225 if ( isDefault() ) os << "Default ";225 if ( isDefault() ) os << indent << "Default "; 226 226 else { 227 os << "Case ";227 os << indent << "Case "; 228 228 condition->print( os, indent ); 229 229 } // if … … 231 231 232 232 for ( Statement * stmt : stmts ) { 233 os << indent+1; 233 234 stmt->print( os, indent+1 ); 234 235 } … … 478 479 } 479 480 480 void NullStmt::print( std::ostream &os, Indenter ) const {481 void NullStmt::print( std::ostream &os, Indenter indent ) const { 481 482 os << "Null Statement" << endl; 483 Statement::print( os, indent ); 482 484 } 483 485 -
src/SynTree/Statement.h
re2c70ab r6a276a0 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 20:46:46 201713 // Update Count : 7 712 // Last Modified On : Thu Mar 8 14:53:02 2018 13 // Update Count : 78 14 14 // 15 15 … … 255 255 class BranchStmt : public Statement { 256 256 public: 257 enum Type { Goto = 0, Break, Continue };257 enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault }; 258 258 259 259 // originalTarget kept for error messages.
Note: See TracChangeset
for help on using the changeset viewer.