Changeset 37eb41b
- Timestamp:
- Jan 31, 2022, 10:20:44 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- d7e9c12
- Parents:
- 0fba0d4
- Location:
- src/ControlStruct
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/FixLabels.cpp
r0fba0d4 r37eb41b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 1 09:39:00 2021 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Nov 8 10:53:00 202113 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 22:19:17 2022 13 // Update Count : 9 14 14 // 15 15 … … 20 20 #include "AST/Stmt.hpp" 21 21 #include "ControlStruct/MultiLevelExit.hpp" 22 using namespace ast; 22 23 23 24 namespace ControlStruct { 24 25 namespace { 26 27 class FixLabelsCore final : public ast::WithGuards { 25 class FixLabelsCore final : public WithGuards { 28 26 LabelToStmt labelTable; 29 public:27 public: 30 28 FixLabelsCore() : labelTable() {} 31 29 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 * );30 void previsit( const FunctionDecl * ); 31 const FunctionDecl * postvisit( const FunctionDecl * ); 32 void previsit( const Stmt * ); 33 void previsit( const BranchStmt * ); 34 void previsit( const LabelAddressExpr * ); 37 35 38 void setLabelsDef( const std::vector< ast::Label> &, const ast::Stmt * );39 void setLabelsUsage( const ast::Label & );36 void setLabelsDef( const std::vector<Label> &, const Stmt * ); 37 void setLabelsUsage( const Label & ); 40 38 }; 41 39 42 void FixLabelsCore::previsit( const ast::FunctionDecl * ) {40 void FixLabelsCore::previsit( const FunctionDecl * ) { 43 41 GuardValue( labelTable ).clear(); 44 42 } 45 43 46 const ast::FunctionDecl * FixLabelsCore::postvisit(47 const ast::FunctionDecl * decl ) {44 const FunctionDecl * FixLabelsCore::postvisit( 45 const FunctionDecl * decl ) { 48 46 if ( nullptr == decl->stmts ) return decl; 49 47 for ( auto kvp : labelTable ) { 50 48 if ( nullptr == kvp.second ) { 51 49 SemanticError( kvp.first.location, 52 "Use of undefined label: " + kvp.first.name );50 "Use of undefined label: " + kvp.first.name ); 53 51 } 54 52 } 55 return ast::mutate_field( decl, &ast::FunctionDecl::stmts,56 multiLevelExitUpdate( decl->stmts.get(), labelTable ) );53 return mutate_field( decl, &FunctionDecl::stmts, 54 multiLevelExitUpdate( decl->stmts.get(), labelTable ) ); 57 55 } 58 56 59 void FixLabelsCore::previsit( const ast::Stmt * stmt ) {57 void FixLabelsCore::previsit( const Stmt * stmt ) { 60 58 if ( !stmt->labels.empty() ) { 61 59 setLabelsDef( stmt->labels, stmt ); … … 63 61 } 64 62 65 void FixLabelsCore::previsit( const ast::BranchStmt * stmt ) {63 void FixLabelsCore::previsit( const BranchStmt * stmt ) { 66 64 if ( !stmt->labels.empty() ) { 67 65 setLabelsDef( stmt->labels, stmt ); … … 72 70 } 73 71 74 void FixLabelsCore::previsit( const ast::LabelAddressExpr * expr ) {72 void FixLabelsCore::previsit( const LabelAddressExpr * expr ) { 75 73 assert( !expr->arg.empty() ); 76 74 setLabelsUsage( expr->arg ); … … 78 76 79 77 void FixLabelsCore::setLabelsDef( 80 const std::vector<ast::Label> & labels, const ast::Stmt * stmt ) {78 const std::vector<Label> & labels, const Stmt * stmt ) { 81 79 assert( !labels.empty() ); 82 80 assert( stmt ); … … 89 87 // Duplicate definition, this is an error. 90 88 SemanticError( label.location, 91 "Duplicate definition of label: " + label.name );89 "Duplicate definition of label: " + label.name ); 92 90 } else { 93 91 // Perviously used, but not defined until now. … … 98 96 99 97 // Label was used, if it is new add it to the table. 100 void FixLabelsCore::setLabelsUsage( const ast::Label & label ) {98 void FixLabelsCore::setLabelsUsage( const Label & label ) { 101 99 if ( labelTable.find( label ) == labelTable.end() ) { 102 100 labelTable[ label ] = nullptr; … … 104 102 } 105 103 106 } // namespace 107 108 void fixLabels( ast::TranslationUnit & translationUnit ) { 109 ast::Pass<FixLabelsCore>::run( translationUnit ); 104 void fixLabels( TranslationUnit & translationUnit ) { 105 Pass<FixLabelsCore>::run( translationUnit ); 110 106 } 111 112 107 } // namespace ControlStruct 113 108 -
src/ControlStruct/FixLabels.hpp
r0fba0d4 r37eb41b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 1 09:36:00 2021 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Nov 1 09:40:00 202113 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 22:18:43 2022 13 // Update Count : 2 14 14 // 15 15 … … 17 17 18 18 namespace ast { 19 19 class TranslationUnit; 20 20 } 21 21 22 22 namespace ControlStruct { 23 24 /// normalizes label definitions and generates multi-level exit labels 23 // normalizes label definitions and generates multi-level exit labels 25 24 void fixLabels( ast::TranslationUnit & translationUnit ); 26 27 25 } 28 26
Note: See TracChangeset
for help on using the changeset viewer.