Otawa  0.10
ContextualProperty.h
Go to the documentation of this file.
1 /*
2  * OTAWA -- WCET computation framework
3  * Copyright (C) 2009 IRIT - UPS <casse@irit.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.package ojawa;
18  */
19 #ifndef OTAWA_PROP_CONTEXTUALPROPERTY_H_
20 #define OTAWA_PROP_CONTEXTUALPROPERTY_H_
21 
22 #include <elm/inhstruct/Tree.h>
23 #include <elm/genstruct/Vector.h>
24 #include <elm/io.h>
25 #include <otawa/base.h>
26 #include <otawa/prop/Property.h>
27 #include <otawa/prop/Identifier.h>
28 
29 namespace otawa {
30 
31 using namespace elm;
32 
33 // pre-declaration
34 class ContextualPath;
35 
36 
37 // ContextualStep class
39 public:
40  typedef enum kind_t {
41  NONE = 0,
45  OTHER_ITER
46  } kind_t;
47 
48  inline ContextualStep(void): _kind(NONE) { }
49  inline ContextualStep(kind_t kind, const Address &address): _kind(kind), addr(address) { };
50  inline ContextualStep(const ContextualStep& step): _kind(step._kind), addr(step.addr) { };
52  { _kind = step._kind; addr = step.addr; return *this; }
53 
54  inline kind_t kind(void) const { return _kind; }
55  inline const Address& address(void) const { return addr; }
56 
57  inline bool equals(const ContextualStep& step) const
58  { return _kind == step.kind() && addr == step.address(); }
59  inline bool operator==(const ContextualStep& step) const { return equals(step); }
60  inline bool operator!=(const ContextualStep& step) const { return !equals(step); }
61 
62  void print(io::Output& out) const;
63 
64 private:
67 };
69  { path.print(out); return out; }
70 
71 
72 // ContextualProperty class
74 
75  // Node class
76  class Node: public PropList, public inhstruct::Tree {
77  public:
78  inline Node(void) { }
79  inline Node(const ContextualStep& _step): step(_step) { }
81  };
82 
83 public:
84  ContextualProperty(void);
85 
86  static bool exists(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
87  static PropList& ref(PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
88 
89  static const PropList& find(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
90  static PropList& make(PropList& props, const ContextualPath& path);
91  static void print(io::Output& out, const PropList& props);
92 
93 private:
94  const PropList& findProps(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id) const;
95  PropList& makeProps(const ContextualPath& path);
96  PropList& refProps(PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
97  void print(io::Output& out, const Node& node, int indent = 0) const;
98 
101 };
102 
103 
104 // ContextualPath class
106 public:
107 
108  // Ref for ContextualPath
109  template <class T>
110  class Ref {
111  public:
112  inline Ref(const ContextualPath& _cp, PropList& _p, const Identifier<T>& _i): cp(_cp), p(_p), i(_i) { }
113  inline Ref(const Ref<T>& r): cp(r.cp), p(r.p), i(r.i) { }
114  inline Ref<T>& operator=(const Ref<T>& r) { cp = r.cp; p = r.p; i = r.i; return *this; }
115 
116  // immutable part
117  inline const ContextualPath& path(void) const { return cp; }
118  inline const PropList &proplist (void) const { return p; }
119  inline const Identifier<T>& identifier (void) const { return i; }
120  inline bool exists(void) const { return ContextualProperty::exists(p, cp, i); };
121  inline const T &get (void) const { return cp.get(i, p); }
122  inline operator const T &(void) const { return get(); }
123  inline T operator->(void) const { return get(); }
124  inline void print(io::Output& out) { i.print(out, find(p, cp, i).getProp(&i)); }
125 
126  // mutable part
127  inline const Ref &add(const T &value) const { i(ContextualProperty::make(p, cp, i)).add(value); }
128  inline void remove(void) const { ContextualProperty::make(p, cp).removeProp(i); }
129  inline T& ref(void) const { return i.ref(ContextualProperty::ref(p, cp, i)); }
130  inline T& operator&(void) const { return ref(); }
131  const Ref<T> &operator=(const T &value) const { ref() = value; return *this; }
132  inline Ref<T> &operator+= (const T &v) const { ref() += value; return *this; }
133  inline Ref<T> &operator-= (const T &v) const { ref() -= value; return *this; }
134  inline Ref<T> &operator *= (const T &v) const { ref() *= value; return *this; }
135  inline Ref<T> &operator/= (const T &v) const { ref() /= value; return *this; }
136  inline Ref<T> &operator%= (const T &v) const { ref() %= value; return *this; }
137  inline Ref<T> &operator &= (const T &v) const { ref() &= value; return *this; }
138  inline Ref<T> &operator|= (const T &v) const { ref() |= value; return *this; }
139  inline Ref<T> &operator^= (const T &v) const { ref() ^= value; return *this; }
140  inline Ref<T> &operator<<= (const T &v) const { ref() <<= value; return *this; }
141  inline Ref<T> &operator>>= (const T &v) const { ref() >>= value; return *this; }
142  inline Ref<T> &operator++ (void) const { ref()++; return *this; }
143  inline Ref<T> &operator-- (void) const { ref()--; return *this; }
144  inline Ref<T> &operator++ (int) const { ref()++; return *this; }
145  inline Ref<T> &operator-- (int) const { ref()--; return *this; }
146 
147  private:
150  const Identifier<T>& i;
151  };
152 
153  // constructors
154  inline ContextualPath(void) { }
155  ContextualPath(const ContextualPath& path);
156  ContextualPath& operator=(const ContextualPath& path);
157 
158  inline void clear(void) { stack.clear(); }
159  inline void push(const ContextualStep& step) { stack.push(step); }
160  inline void push(ContextualStep::kind_t kind, const Address& addr)
161  { stack.push(ContextualStep(kind, addr)); }
162  inline void pop(void) {stack.pop(); }
163 
164  inline bool isEmpty(void) const { return stack.isEmpty(); }
165  inline int count(void) const { return stack.count(); }
166  inline const ContextualStep& step(int i) const { return stack[i]; }
167  inline const ContextualStep& operator[](int i) const { return step(i); }
168  inline operator bool(void) const { return !isEmpty(); }
169  void print(io::Output& out) const;
170 
171  Address getEnclosingFunction(void);
172 
173  template <class T> inline const T& get(const Identifier<T>& id, const PropList& props) const {
174  const PropList& fprops = ContextualProperty::find(props, *this, id);
175  return id.value(fprops);
176  }
177 
178  template <class T> inline Ref<T> ref(const Identifier<T>& id, PropList& props) const
179  { return Ref<T>(*this, props, id); }
180  template <class T> inline const T& get(const Identifier<T>& id, const PropList *props) const
181  { return get(id, *props); }
182  template <class T> inline Ref<T> ref(const Identifier<T>& id, PropList *props) const
183  { return ref(id, *props); }
184 
185  template <class T> inline const T& operator()(const Identifier<T>& id, const PropList *props) const
186  { return get(id, *props); }
187  template <class T> inline const T& operator()(const Identifier<T>& id, const PropList& props) const
188  { return get(id, props); }
189  template <class T> inline Ref<T> operator()(const Identifier<T>& id, PropList *props) const
190  { return ref(id, *props); }
191  template <class T> inline Ref<T> operator()(const Identifier<T>& id, PropList& props) const
192  { return ref(id, props); }
193 
194 private:
196 };
197 
198 // I/O
200  { path.print(out); return out; }
201 template <class T>
202 inline io::Output& operator<<(io::Output& out, const ContextualPath::Ref<T>& r)
203  { r.print(out); return out; }
204 
205 } // otawa
206 
207 #endif /* OTAWA_PROP_CONTEXTUALPROPERTY_H_ */
PropList & p
Definition: ContextualProperty.h:149
Definition: ContextualProperty.h:43
bool operator==(const ContextualStep &step) const
Definition: ContextualProperty.h:59
Definition: ContextualProperty.h:38
void pop(void)
Definition: ContextualProperty.h:162
ContextualStep(kind_t kind, const Address &address)
Definition: ContextualProperty.h:49
static const PropList & find(const PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Get a contextual property from a property list.
Definition: prop_ContextualProperty.cpp:237
static PropList & ref(PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Obtain a reference on a property value in the given contextual path.
Definition: prop_ContextualProperty.cpp:299
Definition: ContextualProperty.h:105
Definition: ClpValue.h:54
Driver * find(kind_t kind)
Find a driver by its output kind.
Definition: display_Graph.cpp:245
void push(ContextualStep::kind_t kind, const Address &addr)
Definition: ContextualProperty.h:160
void print(io::Output &out) const
Print the contextual path.
Definition: prop_ContextualProperty.cpp:107
Definition: ContextualProperty.h:110
static bool exists(const PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Test if a contextual property exists, that is, the property value is defined at any step of the given...
Definition: prop_ContextualProperty.cpp:276
Ref(const ContextualPath &_cp, PropList &_p, const Identifier< T > &_i)
Definition: ContextualProperty.h:112
ContextualStep & operator=(const ContextualStep &step)
Definition: ContextualProperty.h:51
Address addr
Definition: ContextualProperty.h:66
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
Node(const ContextualStep &_step)
Definition: ContextualProperty.h:79
static AbstractIdentifier ID
Private identifier for contextual properties.
Definition: ContextualProperty.h:100
Definition: ContextualProperty.h:76
void push(const ContextualStep &step)
Definition: ContextualProperty.h:159
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
Ref< T > operator()(const Identifier< T > &id, PropList &props) const
Definition: ContextualProperty.h:191
T & operator&(void) const
Definition: ContextualProperty.h:130
Represents a unique identifier used by the annotation system.
Definition: AbstractIdentifier.h:32
Inst::kind_t kind
Definition: odisasm.cpp:106
Ref< T > & operator=(const Ref< T > &r)
Definition: ContextualProperty.h:114
Ref< T > operator()(const Identifier< T > &id, PropList *props) const
Definition: ContextualProperty.h:189
value_t value(CString name, int value)
const Address & address(void) const
Definition: ContextualProperty.h:55
Ref(const Ref< T > &r)
Definition: ContextualProperty.h:113
bool isEmpty(void) const
Definition: ContextualProperty.h:164
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses, and represents a register; VAL represents some values (either a constant or an interval); ALL is the Top element.
Definition: ClpValue.h:53
kind_t _kind
Definition: ContextualProperty.h:65
const Ref< T > & operator=(const T &value) const
Definition: ContextualProperty.h:131
bool exists(void) const
Definition: ContextualProperty.h:120
Definition: ContextualProperty.h:42
ContextualStep(void)
Definition: ContextualProperty.h:48
The representation of an address in OTAWA.
Definition: base.h:54
const Ref & add(const T &value) const
Definition: ContextualProperty.h:127
Definition: ContextualProperty.h:44
Property * make(const Identifier< T > &id, const T &v)
Definition: info.h:31
genstruct::Vector< ContextualStep > stack
Definition: ContextualProperty.h:195
void print(io::Output &out)
Definition: ContextualProperty.h:124
sys::SystemOutStream & out
kind_t kind(void) const
Definition: ContextualProperty.h:54
Ref< T > ref(const Identifier< T > &id, PropList &props) const
Definition: ContextualProperty.h:178
ContextualStep step
Definition: ContextualProperty.h:80
kind_t
Definition: ContextualProperty.h:40
const ContextualStep & operator[](int i) const
Definition: ContextualProperty.h:167
ContextualStep(const ContextualStep &step)
Definition: ContextualProperty.h:50
const T & operator()(const Identifier< T > &id, const PropList *props) const
Definition: ContextualProperty.h:185
void removeProp(const AbstractIdentifier *id)
Remove a property matching the given identifier.
Definition: prop_PropList.cpp:409
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
T & ref(void) const
Definition: ContextualProperty.h:129
const ContextualPath & path(void) const
Definition: ContextualProperty.h:117
ContextualPath(void)
Definition: ContextualProperty.h:154
Node(void)
Definition: ContextualProperty.h:78
This a list of properties.
Definition: PropList.h:63
int count(void) const
Definition: ContextualProperty.h:165
static PropList & make(PropList &props, const ContextualPath &path)
Set a contextual property.
Definition: prop_ContextualProperty.cpp:256
bool operator!=(const ContextualStep &step) const
Definition: ContextualProperty.h:60
void clear(void)
Definition: ContextualProperty.h:158
bool equals(const ContextualStep &step) const
Definition: ContextualProperty.h:57
const Identifier< T > & identifier(void) const
Definition: ContextualProperty.h:119
const ContextualStep & step(int i) const
Definition: ContextualProperty.h:166
Node root
Definition: ContextualProperty.h:99
A property associates a data with an identifier.
Definition: PropList.h:42
const Identifier< T > & i
Definition: ContextualProperty.h:150
void print(io::Output &out) const
Definition: prop_ContextualProperty.cpp:84
Ref< T > ref(const Identifier< T > &id, PropList *props) const
Definition: ContextualProperty.h:182
const T & operator()(const Identifier< T > &id, const PropList &props) const
Definition: ContextualProperty.h:187
T operator->(void) const
Definition: ContextualProperty.h:123
const ContextualPath & cp
Definition: ContextualProperty.h:148
const PropList & proplist(void) const
Definition: ContextualProperty.h:118
A contextual property is a special property that allows to retrieve a property value by its contextua...
Definition: ContextualProperty.h:73