- File:
-
- 1 edited
-
src/ControlStruct/FixLabels.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/FixLabels.cpp
r37eb41b ra5a08a05 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
Note:
See TracChangeset
for help on using the changeset viewer.