1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // LabelFixer.h -- |
---|
8 | // |
---|
9 | // Author : Rodolfo G. Esteves |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Rob Schluntz |
---|
12 | // Last Modified On : Tue May 26 12:55:10 2015 |
---|
13 | // Update Count : 4 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef LABEL_FIXER_H |
---|
17 | #define LABEL_FIXER_H |
---|
18 | |
---|
19 | #include "utility.h" |
---|
20 | #include "SynTree/SynTree.h" |
---|
21 | #include "SynTree/Visitor.h" |
---|
22 | #include "LabelGenerator.h" |
---|
23 | |
---|
24 | #include <map> |
---|
25 | |
---|
26 | namespace ControlStruct { |
---|
27 | class LabelFixer : public Visitor { |
---|
28 | typedef Visitor Parent; |
---|
29 | public: |
---|
30 | LabelFixer( LabelGenerator *gen = 0 ); |
---|
31 | |
---|
32 | std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); |
---|
33 | |
---|
34 | // Declarations |
---|
35 | virtual void visit( FunctionDecl *functionDecl ); |
---|
36 | |
---|
37 | // Statements |
---|
38 | void visit( Statement *stmt ); |
---|
39 | |
---|
40 | virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
41 | virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
42 | virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
43 | virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
44 | virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
45 | virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
46 | virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
47 | virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
48 | virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
49 | virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
50 | virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
51 | virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
52 | virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
53 | virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
54 | virtual void visit( BranchStmt *branchStmt ); |
---|
55 | |
---|
56 | Label setLabelsDef( std::list< Label > &, Statement *definition ); |
---|
57 | Label setLabelsUsg( Label, Statement *usage = 0 ); |
---|
58 | |
---|
59 | private: |
---|
60 | class Entry { |
---|
61 | public: |
---|
62 | Entry( Statement *to = 0, Statement *from = 0 ); |
---|
63 | bool used() { return ( usage.empty() ); } |
---|
64 | bool defined() { return ( definition != 0 ); } |
---|
65 | bool insideLoop(); |
---|
66 | |
---|
67 | Label get_label() const { return label; } |
---|
68 | void set_label( Label lab ) { label = lab; } |
---|
69 | |
---|
70 | Statement *get_definition() const { return definition; } |
---|
71 | void set_definition( Statement *def ) { definition = def; } |
---|
72 | |
---|
73 | std::list< Statement *> &get_uses() { return usage; } |
---|
74 | void add_use ( Statement *use ) { usage.push_back( use ); } |
---|
75 | void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } |
---|
76 | private: |
---|
77 | Label label; |
---|
78 | Statement *definition; |
---|
79 | std::list<Statement *> usage; |
---|
80 | }; |
---|
81 | |
---|
82 | std::map < Label, Entry *> labelTable; |
---|
83 | LabelGenerator *generator; |
---|
84 | }; |
---|
85 | } // namespace ControlStruct |
---|
86 | |
---|
87 | #endif // LABEL_FIXER_H |
---|
88 | |
---|
89 | // Local Variables: // |
---|
90 | // tab-width: 4 // |
---|
91 | // mode: c++ // |
---|
92 | // compile-command: "make install" // |
---|
93 | // End: // |
---|