Changeset d9a0e76 for translator/ControlStruct/LabelFixer.h
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ControlStruct/LabelFixer.h
r3848e0e rd9a0e76 12 12 13 13 namespace ControlStruct { 14 class LabelFixer : public Visitor { 15 typedef Visitor Parent; 16 public: 17 LabelFixer( LabelGenerator *gen = 0 ); 14 18 15 class LabelFixer : public Visitor 16 { 17 typedef Visitor Parent; 19 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); 18 20 19 public: 20 LabelFixer( LabelGenerator *gen = 0);21 // Declarations 22 virtual void visit( FunctionDecl *functionDecl ); 21 23 22 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); 24 // Statements 25 void visit( Statement *stmt ); 23 26 24 // Declarations 25 virtual void visit(FunctionDecl *functionDecl); 27 virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 28 virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 29 virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 30 virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 31 virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 32 virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 33 virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 34 virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 35 virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 36 virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 37 virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 38 virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 39 virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 40 virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 41 virtual void visit( BranchStmt *branchStmt ); 26 42 27 // Statements 28 void visit(Statement *stmt);43 Label setLabelsDef( std::list< Label > &, Statement *definition ); 44 Label setLabelsUsg( Label, Statement *usage = 0 ); 29 45 30 virtual void visit(CompoundStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 31 virtual void visit(NullStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 32 virtual void visit(ExprStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 33 virtual void visit(IfStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 34 virtual void visit(WhileStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 35 virtual void visit(ForStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 36 virtual void visit(SwitchStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 37 virtual void visit(ChooseStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 38 virtual void visit(FallthruStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 39 virtual void visit(CaseStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 40 virtual void visit(ReturnStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 41 virtual void visit(TryStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 42 virtual void visit(CatchStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 43 virtual void visit(DeclStmt *stmt) { visit( (Statement *)stmt ); return Parent::visit(stmt); } 44 virtual void visit(BranchStmt *branchStmt); 46 private: 47 class Entry { 48 public: 49 Entry( Statement *to = 0, Statement *from = 0 ); 50 bool used() { return ( usage.empty() ); } 51 bool defined() { return ( definition != 0 ); } 52 bool insideLoop(); 45 53 46 Label setLabelsDef( std::list< Label > &, Statement *definition ); 47 Label setLabelsUsg( Label, Statement *usage = 0 ); 54 Label get_label() const { return label; } 55 Statement *get_definition() const { return definition; } 56 std::list< Statement *> &get_uses() { return usage; } 48 57 49 private: 50 class Entry 51 { 52 public: 53 Entry( Statement *to = 0, Statement *from = 0 ); 54 bool used() { return ( usage.empty() ); } 55 bool defined() { return ( definition != 0 ); } 56 bool insideLoop(); 58 void add_use ( Statement *use ) { usage.push_back( use ); } 59 void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 60 void set_definition( Statement *def ) { definition = def; } 57 61 58 Label get_label() const { return label; } 59 Statement *get_definition() const { return definition; } 60 std::list< Statement *> &get_uses() { return usage; } 61 62 void add_use ( Statement *use ) { usage.push_back(use); } 63 void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 64 void set_definition( Statement *def ) { definition = def; } 65 66 void set_label( Label lab ) { label = lab; } 67 Label gset_label() const { return label; } 68 private: 69 Label label; 70 Statement *definition; 71 std::list<Statement *> usage; 72 }; 62 void set_label( Label lab ) { label = lab; } 63 Label gset_label() const { return label; } 64 private: 65 Label label; 66 Statement *definition; 67 std::list<Statement *> usage; 68 }; 73 69 74 75 70 std::map < Label, Entry *> labelTable; 71 LabelGenerator *generator; 76 72 }; 77 73 } // namespace ControlStruct 78 74 79 #endif // #ifndefLABEL_FIXER_H75 #endif // LABEL_FIXER_H 80 76 81 77 /*
Note: See TracChangeset
for help on using the changeset viewer.