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 : Peter A. Buhr |
---|
12 | // Last Modified On : Mon Jan 25 21:22:22 2016 |
---|
13 | // Update Count : 32 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef LABEL_FIXER_H |
---|
17 | #define LABEL_FIXER_H |
---|
18 | |
---|
19 | #include "Common/utility.h" |
---|
20 | #include "SynTree/SynTree.h" |
---|
21 | #include "SynTree/Visitor.h" |
---|
22 | #include "SynTree/Label.h" |
---|
23 | #include "LabelGenerator.h" |
---|
24 | #include <map> |
---|
25 | |
---|
26 | namespace ControlStruct { |
---|
27 | /// normalizes label definitions and generates multi-level exit labels |
---|
28 | class LabelFixer : public Visitor { |
---|
29 | typedef Visitor Parent; |
---|
30 | public: |
---|
31 | LabelFixer( LabelGenerator *gen = 0 ); |
---|
32 | |
---|
33 | std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); |
---|
34 | |
---|
35 | // Declarations |
---|
36 | virtual void visit( FunctionDecl *functionDecl ); |
---|
37 | |
---|
38 | // Statements |
---|
39 | void visit( Statement *stmt ); |
---|
40 | |
---|
41 | virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
42 | virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
43 | virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
44 | virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
45 | virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
46 | virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
47 | virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
48 | virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
49 | virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
50 | virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
51 | virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
52 | virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
53 | virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
54 | virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
55 | virtual void visit( BranchStmt *branchStmt ); |
---|
56 | virtual void visit( UntypedExpr *untyped ); |
---|
57 | |
---|
58 | Label setLabelsDef( std::list< Label > &, Statement *definition ); |
---|
59 | template< typename UsageNode > |
---|
60 | void setLabelsUsg( Label, UsageNode *usage = 0 ); |
---|
61 | |
---|
62 | private: |
---|
63 | class Entry { |
---|
64 | public: |
---|
65 | Entry( Statement *to ) : definition( to ) {} |
---|
66 | bool defined() { return ( definition != 0 ); } |
---|
67 | bool insideLoop(); |
---|
68 | |
---|
69 | Label get_label() const { return label; } |
---|
70 | void set_label( Label lab ) { label = lab; } |
---|
71 | |
---|
72 | Statement *get_definition() const { return definition; } |
---|
73 | void set_definition( Statement *def ) { definition = def; } |
---|
74 | |
---|
75 | private: |
---|
76 | Label label; |
---|
77 | Statement *definition; |
---|
78 | }; |
---|
79 | |
---|
80 | std::map < Label, Entry *> labelTable; |
---|
81 | LabelGenerator *generator; |
---|
82 | }; |
---|
83 | } // namespace ControlStruct |
---|
84 | |
---|
85 | #endif // LABEL_FIXER_H |
---|
86 | |
---|
87 | // Local Variables: // |
---|
88 | // tab-width: 4 // |
---|
89 | // mode: c++ // |
---|
90 | // compile-command: "make install" // |
---|
91 | // End: // |
---|