Changes in / [d7e9c12:8e5e945]
- Location:
- src
- Files:
-
- 6 edited
-
ControlStruct/ExceptTranslateNew.cpp (modified) (3 diffs)
-
ControlStruct/FixLabels.cpp (modified) (8 diffs)
-
ControlStruct/FixLabels.hpp (modified) (2 diffs)
-
Parser/ParseNode.h (modified) (3 diffs)
-
Parser/StatementNode.cc (modified) (4 diffs)
-
Parser/parser.yy (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslateNew.cpp
rd7e9c12 r8e5e945 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 8 11:53:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jan 31 18:49:58 202213 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 8 16:50:00 2021 13 // Update Count : 0 14 14 // 15 15 … … 22 22 23 23 namespace ControlStruct { 24 25 namespace { 24 26 25 27 class TranslateThrowsCore : public ast::WithGuards { … … 126 128 } 127 129 130 } // namespace 131 128 132 void translateThrows( ast::TranslationUnit & transUnit ) { 129 133 ast::Pass<TranslateThrowsCore>::run( transUnit ); -
src/ControlStruct/FixLabels.cpp
rd7e9c12 r8e5e945 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 1 09:39:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jan 31 22:19:17 202213 // Update Count : 911 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 8 10:53:00 2021 13 // Update Count : 3 14 14 // 15 15 … … 20 20 #include "AST/Stmt.hpp" 21 21 #include "ControlStruct/MultiLevelExit.hpp" 22 using namespace ast;23 22 24 23 namespace ControlStruct { 25 class FixLabelsCore final : public WithGuards { 24 25 namespace { 26 27 class FixLabelsCore final : public ast::WithGuards { 26 28 LabelToStmt labelTable; 27 public:29 public: 28 30 FixLabelsCore() : labelTable() {} 29 31 30 void previsit( const FunctionDecl * );31 const FunctionDecl * postvisit( constFunctionDecl * );32 void previsit( const Stmt * );33 void previsit( const BranchStmt * );34 void previsit( const LabelAddressExpr * );32 void previsit( const ast::FunctionDecl * ); 33 const ast::FunctionDecl * postvisit( const ast::FunctionDecl * ); 34 void previsit( const ast::Stmt * ); 35 void previsit( const ast::BranchStmt * ); 36 void previsit( const ast::LabelAddressExpr * ); 35 37 36 void setLabelsDef( const std::vector< Label> &, constStmt * );37 void setLabelsUsage( const Label & );38 void setLabelsDef( const std::vector<ast::Label> &, const ast::Stmt * ); 39 void setLabelsUsage( const ast::Label & ); 38 40 }; 39 41 40 void FixLabelsCore::previsit( const FunctionDecl * ) {42 void FixLabelsCore::previsit( const ast::FunctionDecl * ) { 41 43 GuardValue( labelTable ).clear(); 42 44 } 43 45 44 const FunctionDecl * FixLabelsCore::postvisit(45 constFunctionDecl * decl ) {46 const ast::FunctionDecl * FixLabelsCore::postvisit( 47 const ast::FunctionDecl * decl ) { 46 48 if ( nullptr == decl->stmts ) return decl; 47 49 for ( auto kvp : labelTable ) { 48 50 if ( nullptr == kvp.second ) { 49 51 SemanticError( kvp.first.location, 50 "Use of undefined label: " + kvp.first.name );52 "Use of undefined label: " + kvp.first.name ); 51 53 } 52 54 } 53 return mutate_field( decl, &FunctionDecl::stmts,54 multiLevelExitUpdate( decl->stmts.get(), labelTable ) );55 return ast::mutate_field( decl, &ast::FunctionDecl::stmts, 56 multiLevelExitUpdate( decl->stmts.get(), labelTable ) ); 55 57 } 56 58 57 void FixLabelsCore::previsit( const Stmt * stmt ) {59 void FixLabelsCore::previsit( const ast::Stmt * stmt ) { 58 60 if ( !stmt->labels.empty() ) { 59 61 setLabelsDef( stmt->labels, stmt ); … … 61 63 } 62 64 63 void FixLabelsCore::previsit( const BranchStmt * stmt ) {65 void FixLabelsCore::previsit( const ast::BranchStmt * stmt ) { 64 66 if ( !stmt->labels.empty() ) { 65 67 setLabelsDef( stmt->labels, stmt ); … … 70 72 } 71 73 72 void FixLabelsCore::previsit( const LabelAddressExpr * expr ) {74 void FixLabelsCore::previsit( const ast::LabelAddressExpr * expr ) { 73 75 assert( !expr->arg.empty() ); 74 76 setLabelsUsage( expr->arg ); … … 76 78 77 79 void FixLabelsCore::setLabelsDef( 78 const std::vector<Label> & labels, constStmt * stmt ) {80 const std::vector<ast::Label> & labels, const ast::Stmt * stmt ) { 79 81 assert( !labels.empty() ); 80 82 assert( stmt ); … … 87 89 // Duplicate definition, this is an error. 88 90 SemanticError( label.location, 89 "Duplicate definition of label: " + label.name );91 "Duplicate definition of label: " + label.name ); 90 92 } else { 91 93 // Perviously used, but not defined until now. … … 96 98 97 99 // Label was used, if it is new add it to the table. 98 void FixLabelsCore::setLabelsUsage( const Label & label ) {100 void FixLabelsCore::setLabelsUsage( const ast::Label & label ) { 99 101 if ( labelTable.find( label ) == labelTable.end() ) { 100 102 labelTable[ label ] = nullptr; … … 102 104 } 103 105 104 void fixLabels( TranslationUnit & translationUnit ) { 105 Pass<FixLabelsCore>::run( translationUnit ); 106 } // namespace 107 108 void fixLabels( ast::TranslationUnit & translationUnit ) { 109 ast::Pass<FixLabelsCore>::run( translationUnit ); 106 110 } 111 107 112 } // namespace ControlStruct 108 113 -
src/ControlStruct/FixLabels.hpp
rd7e9c12 r8e5e945 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 1 09:36:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jan 31 22:18:43 202213 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Nov 1 09:40:00 2021 13 // Update Count : 0 14 14 // 15 15 … … 17 17 18 18 namespace ast { 19 class TranslationUnit;19 class TranslationUnit; 20 20 } 21 21 22 22 namespace ControlStruct { 23 // normalizes label definitions and generates multi-level exit labels 23 24 /// normalizes label definitions and generates multi-level exit labels 24 25 void fixLabels( ast::TranslationUnit & translationUnit ); 26 25 27 } 26 28 -
src/Parser/ParseNode.h
rd7e9c12 r8e5e945 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:56 202213 // Update Count : 90 112 // Last Modified On : Wed Jul 14 17:28:53 2021 13 // Update Count : 900 14 14 // 15 15 … … 390 390 Statement * build_expr( ExpressionNode * ctl ); 391 391 392 struct CondCtl {393 CondCtl( DeclarationNode * decl, ExpressionNode * condition ) :392 struct IfCtrl { 393 IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) : 394 394 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} 395 395 … … 409 409 }; 410 410 411 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init );412 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );411 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ); 412 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 413 413 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 414 414 Statement * build_case( ExpressionNode * ctl ); 415 415 Statement * build_default(); 416 Statement * build_while( CondCtl * ctl, StatementNode * stmt );416 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ); 417 417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ); 418 418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ); -
src/Parser/StatementNode.cc
rd7e9c12 r8e5e945 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:51 202213 // Update Count : 38 412 // Last Modified On : Sat Oct 24 04:20:55 2020 13 // Update Count : 383 14 14 // 15 15 … … 78 78 } // build_expr 79 79 80 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ) {80 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ) { 81 81 if ( ctl->init != 0 ) { 82 82 buildMoveList( ctl->init, init ); … … 100 100 } // build_if_control 101 101 102 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {102 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 103 103 Statement * thenb, * elseb = nullptr; 104 104 std::list< Statement * > branches; … … 145 145 } // build_default 146 146 147 Statement * build_while( CondCtl * ctl, StatementNode * stmt ) {147 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ) { 148 148 std::list< Statement * > branches; 149 149 buildMoveList< Statement, StatementNode >( stmt, branches ); -
src/Parser/parser.yy
rd7e9c12 r8e5e945 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 30 09:41:13 202213 // Update Count : 516 512 // Last Modified On : Fri Oct 15 09:20:17 2021 13 // Update Count : 5163 14 14 // 15 15 … … 238 238 WaitForStmt * wfs; 239 239 Expression * constant; 240 CondCtl * ifctl;240 IfCtrl * ifctl; 241 241 ForCtrl * fctl; 242 242 enum OperKinds compop; … … 327 327 %type<en> comma_expression comma_expression_opt 328 328 %type<en> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt 329 %type<ifctl> conditional_declaration329 %type<ifctl> if_control_expression 330 330 %type<fctl> for_control_expression for_control_expression_list 331 331 %type<compop> inclexcl … … 1123 1123 1124 1124 if_statement: 1125 IF '(' conditional_declaration ')' statement%prec THEN1125 IF '(' if_control_expression ')' statement %prec THEN 1126 1126 // explicitly deal with the shift/reduce conflict on if/else 1127 1127 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); } 1128 | IF '(' conditional_declaration ')' statement ELSE statement1128 | IF '(' if_control_expression ')' statement ELSE statement 1129 1129 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 ) ) ); } 1130 1130 ; 1131 1131 1132 conditional_declaration:1132 if_control_expression: 1133 1133 comma_expression 1134 { $$ = new CondCtl( nullptr, $1 ); }1134 { $$ = new IfCtrl( nullptr, $1 ); } 1135 1135 | c_declaration // no semi-colon 1136 { $$ = new CondCtl( $1, nullptr ); }1136 { $$ = new IfCtrl( $1, nullptr ); } 1137 1137 | cfa_declaration // no semi-colon 1138 { $$ = new CondCtl( $1, nullptr ); }1138 { $$ = new IfCtrl( $1, nullptr ); } 1139 1139 | declaration comma_expression // semi-colon separated 1140 { $$ = new CondCtl( $1, $2 ); }1140 { $$ = new IfCtrl( $1, $2 ); } 1141 1141 ; 1142 1142 … … 1193 1193 iteration_statement: 1194 1194 WHILE '(' ')' statement // CFA => while ( 1 ) 1195 { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }1196 | WHILE '(' conditional_declaration ')' statement%prec THEN1195 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); } 1196 | WHILE '(' if_control_expression ')' statement %prec THEN 1197 1197 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); } 1198 | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA1198 | WHILE '(' if_control_expression ')' statement ELSE statement // CFA 1199 1199 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1200 1200 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 )
Note:
See TracChangeset
for help on using the changeset viewer.