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 : Tue Jul 12 17:36:16 2016 |
---|
13 | // Update Count : 33 |
---|
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( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
49 | virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
50 | virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
51 | virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
52 | virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
53 | virtual void visit( BranchStmt *branchStmt ); |
---|
54 | virtual void visit( UntypedExpr *untyped ); |
---|
55 | |
---|
56 | Label setLabelsDef( std::list< Label > &, Statement *definition ); |
---|
57 | template< typename UsageNode > |
---|
58 | void setLabelsUsg( Label, UsageNode *usage = 0 ); |
---|
59 | |
---|
60 | private: |
---|
61 | class Entry { |
---|
62 | public: |
---|
63 | Entry( Statement *to ) : definition( to ) {} |
---|
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 | private: |
---|
74 | Label label; |
---|
75 | Statement *definition; |
---|
76 | }; |
---|
77 | |
---|
78 | std::map < Label, Entry *> labelTable; |
---|
79 | LabelGenerator *generator; |
---|
80 | }; |
---|
81 | } // namespace ControlStruct |
---|
82 | |
---|
83 | #endif // LABEL_FIXER_H |
---|
84 | |
---|
85 | // Local Variables: // |
---|
86 | // tab-width: 4 // |
---|
87 | // mode: c++ // |
---|
88 | // compile-command: "make install" // |
---|
89 | // End: // |
---|