OpenASIP 2.2
Loading...
Searching...
No Matches
Scope.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file Scope.hh
26 *
27 * Declaration of Scope class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#ifndef TTA_SCOPE_HH
34#define TTA_SCOPE_HH
35
36#include <string>
37#include <vector>
38
39#include "Address.hh"
40#include "Exception.hh"
41
42namespace TTAProgram {
43
44class CodeLabel;
45class DataLabel;
46
47/**
48 * Scopes provide containers for different visibility level labels.
49 *
50 * @todo Implement rest of the Scopes (only GlobalScope is supported
51 * currently).
52 */
53class Scope {
54public:
55 Scope();
56 virtual ~Scope();
57
58 virtual bool isGlobal() const;
59 virtual bool isUnit() const;
60 virtual bool isProcedure() const;
61 virtual bool isLocal() const;
62
63 bool containsCodeLabel(const std::string& name) const;
64 bool containsDataLabel(const std::string& name) const;
65
66 const CodeLabel& codeLabel(const std::string& name) const;
67 const DataLabel& dataLabel(const std::string& name) const;
68
69 int codeLabelCount(Address address) const;
70 const CodeLabel& codeLabel(Address address, int index) const;
71
72 int dataLabelCount(Address address) const;
73 const DataLabel& dataLabel(Address address, int index) const;
74
75 virtual void addCodeLabel(const CodeLabel* codeLabel);
76 virtual void addDataLabel(const DataLabel* dataLabel);
77 virtual void removeCodeLabels(InstructionAddress address);
78
79 virtual Scope* copy() const = 0;
80
81protected:
82 /// List for child scopes.
83 typedef std::vector<const Scope*> ScopeList;
84 /// Child scopes.
86
87 /// List of data labels.
88 typedef std::vector<const DataLabel*> DataLabelList;
89 /// List of code labels.
90 typedef std::vector<const CodeLabel*> CodeLabelList;
91
92 /// Data labels contained by this scope.
94 /// Code labels contained by this scope.
96
97 /// Adds a code label and its owner to the global label bookkeeping.
98 ///
99 /// @param dataLabel The code label to be added.
100 /// @param owner The owner scope of the label.
101 virtual void addGlobalCodeLabel(
102 const CodeLabel& codeLabel, const Scope& owner) = 0;
103
104 /// Adds a data label and its owner to the global label bookkeeping.
105 ///
106 /// @param dataLabel The data label to be added.
107 /// @param owner The owner scope of the label.
108 virtual void addGlobalDataLabel(
109 const DataLabel& dataLabel, const Scope& owner) = 0;
110
111 Scope& parent() const;
112 void setParent(Scope& scope);
113
114 int childCount() const;
115 void addChild(const Scope& scope);
116 const Scope& child(int index) const;
117
118private:
119 /// Copying not allowed.
120 Scope(const Scope&);
121 /// Assignment not allowed.
123
124 /// The smallest outer scope that contains this scope.
126};
127
128}
129
130#endif
UInt32 InstructionAddress
Definition BaseType.hh:175
ScopeList children_
Child scopes.
Definition Scope.hh:85
int codeLabelCount(Address address) const
Definition Scope.cc:269
virtual void addGlobalDataLabel(const DataLabel &dataLabel, const Scope &owner)=0
Adds a data label and its owner to the global label bookkeeping.
virtual bool isProcedure() const
Definition Scope.cc:92
int dataLabelCount(Address address) const
Definition Scope.cc:323
bool containsDataLabel(const std::string &name) const
Definition Scope.cc:215
virtual bool isUnit() const
Definition Scope.cc:82
void setParent(Scope &scope)
Definition Scope.cc:152
std::vector< const CodeLabel * > CodeLabelList
List of code labels.
Definition Scope.hh:90
Scope & parent() const
Definition Scope.cc:132
virtual void removeCodeLabels(InstructionAddress address)
Definition Scope.cc:451
int childCount() const
Definition Scope.cc:171
virtual void addDataLabel(const DataLabel *dataLabel)
Definition Scope.cc:415
Scope * parent_
The smallest outer scope that contains this scope.
Definition Scope.hh:125
Scope(const Scope &)
Copying not allowed.
bool containsCodeLabel(const std::string &name) const
Definition Scope.cc:199
DataLabelList dataLabels_
Data labels contained by this scope.
Definition Scope.hh:93
const CodeLabel & codeLabel(const std::string &name) const
Definition Scope.cc:233
virtual Scope * copy() const =0
CodeLabelList codeLabels_
Code labels contained by this scope.
Definition Scope.hh:95
const DataLabel & dataLabel(const std::string &name) const
Definition Scope.cc:251
virtual void addGlobalCodeLabel(const CodeLabel &codeLabel, const Scope &owner)=0
Adds a code label and its owner to the global label bookkeeping.
virtual bool isGlobal() const
Definition Scope.cc:72
void addChild(const Scope &scope)
Definition Scope.cc:114
virtual ~Scope()
Definition Scope.cc:54
virtual bool isLocal() const
Definition Scope.cc:102
const Scope & child(int index) const
Definition Scope.cc:184
std::vector< const DataLabel * > DataLabelList
List of data labels.
Definition Scope.hh:88
std::vector< const Scope * > ScopeList
List for child scopes.
Definition Scope.hh:83
Scope & operator=(const Scope &)
Assignment not allowed.
virtual void addCodeLabel(const CodeLabel *codeLabel)
Definition Scope.cc:376