source: translator/ControlStruct/LabelFixer.h @ 51587aa

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 3.5 KB
Line 
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// XXX.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count     : 0
14//
15#ifndef LABEL_FIXER_H
16#define LABEL_FIXER_H
17
18#include "utility.h"
19
20#include "SynTree/SynTree.h"
21#include "SynTree/Visitor.h"
22
23#include "LabelGenerator.h"
24
25#include <map>
26
27namespace ControlStruct {
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
57        Label setLabelsDef( std::list< Label > &, Statement *definition );
58        Label setLabelsUsg( Label, Statement *usage = 0 );
59
60      private:
61        class Entry {
62          public:
63            Entry( Statement *to = 0, Statement *from = 0 );
64            bool used() { return ( usage.empty() ); }
65            bool defined() { return ( definition != 0 ); }
66            bool insideLoop();
67
68            Label get_label() const { return label; }
69            Statement *get_definition() const { return definition; }
70            std::list< Statement *> &get_uses() { return usage; }
71
72            void add_use ( Statement *use ) { usage.push_back( use ); }
73            void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); }
74            void set_definition( Statement *def ) { definition = def; }
75
76            void set_label( Label lab ) { label = lab; }
77            Label gset_label() const { return label; }
78          private:
79            Label label; 
80            Statement *definition;
81            std::list<Statement *> usage;
82        };
83             
84        std::map < Label, Entry *> labelTable;
85        LabelGenerator *generator;
86    };
87} // namespace ControlStruct
88
89#endif // LABEL_FIXER_H
90
91/*
92  Local Variables:
93  mode: c++
94  End:
95*/
96// Local Variables: //
97// tab-width: 4 //
98// mode: c++ //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.