~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to AspectC++/MatchExpr.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "MatchTemplateArg.h"
30
30
#include "MatchName.h"
31
31
 
32
 
// this is an abstraction for AspectC++ match expressions. These expressions
33
 
// describe signature patters, which can be matched agains the signatures
34
 
// of C++ objects.
35
 
 
36
 
class MatchExpr {
37
 
 
 
32
// This class is an abstraction for a C++ object signature (function, type,
 
33
// attribute).
 
34
 
 
35
class MatchSignature {
 
36
 
 
37
protected:
38
38
  // object state 
39
39
  enum State {
40
40
    NEW    = 0, // this object is not initialized, yet
61
61
    ERR_INVALID_FCT_SPEC   = -19  // only functions can have function specifiers
62
62
  } _state;
63
63
  
64
 
  // match expression type
65
 
  enum Type { ATTRIBUTE, FUNCTION, TYPE } _expr_type;
66
 
  
 
64
private:
67
65
  // primitive types
68
66
  enum PrimType {
69
67
    PRIM_NONE, PRIM_CHAR, PRIM_INT, PRIM_VOID, PRIM_BOOL, PRIM_FLOAT,
92
90
      _allow_name (true), _type (PRIM_NONE) {}
93
91
  };
94
92
  
95
 
  // the name pattern of the match expression
 
93
public:
 
94
  //! match expression type
 
95
  enum Type { ATTRIBUTE, FUNCTION, TYPE } _expr_type;
 
96
  
 
97
protected:
 
98
  //! the name pattern of the match expression
96
99
  MatchName _name;
 
100
  //! the type pattern
97
101
  MatchTypeRef _type;
98
102
  
99
103
public:
100
104
  // constructors/destructor
101
 
  inline MatchExpr ();
102
 
  inline MatchExpr (ErrorStream &err, Location loc, const char *str);
 
105
  inline MatchSignature ();
 
106
  inline MatchSignature (ErrorStream &err, Location loc, const char *str);
103
107
  
104
108
  // parse a match expression string
105
109
  // complain about errors => result false
106
110
  bool parse (ErrorStream &err, Location loc, const char *str);
107
111
  
108
 
  // check if a certain signature is matched by this expression,
109
 
  // obj is passed to check the name part of the signature
110
 
  // true is returned if the signature is matched
111
 
  inline bool matches (CTypeInfo *type, CObjectInfo *obj);
112
 
  
113
112
  // check the state of this match expression
114
113
  inline bool error () const;
 
114
  inline bool is_new () const;
115
115
  inline bool is_function () const;
 
116
  inline bool is_virtual_function () const;
116
117
  inline bool is_attribute () const;
117
118
  inline bool is_type () const;
 
119
 
 
120
  // manipulate the state
 
121
  inline void declare_virtual_function ();
 
122
  
 
123
  // get more detailed infos about the match expression
 
124
  inline MatchName &name ();
 
125
  inline MatchTypeRef &type ();
118
126
  
119
127
private:
120
128
  // internal parser functions that analyse a match expr string
145
153
};
146
154
 
147
155
// implementations of inline constructors/destructor
148
 
inline MatchExpr::MatchExpr () : _state (NEW) {}
149
 
inline MatchExpr::MatchExpr (ErrorStream &err, Location loc, const char *str) :
150
 
  _state (NEW) {
 
156
inline MatchSignature::MatchSignature () : _state (NEW) {}
 
157
inline MatchSignature::MatchSignature (ErrorStream &err, Location loc,
 
158
  const char *str) : _state (NEW) {
151
159
  parse (err, loc, str);
152
160
}
153
161
 
154
162
// check the state of this match expression
155
 
inline bool MatchExpr::error () const { return _state < 0; }
156
 
inline bool MatchExpr::is_function () const { return _expr_type == FUNCTION; }
157
 
inline bool MatchExpr::is_attribute () const { return _expr_type == ATTRIBUTE; }
158
 
inline bool MatchExpr::is_type () const { return _expr_type == TYPE; }
 
163
inline bool MatchSignature::error () const { return _state < 0; }
 
164
inline bool MatchSignature::is_new () const { return _state == NEW; }
 
165
inline bool MatchSignature::is_function () const { return _expr_type == FUNCTION; }
 
166
inline bool MatchSignature::is_virtual_function () const {
 
167
  return is_function () && ((_fct_spec & FCT_VIRTUAL) != 0);
 
168
}
 
169
inline bool MatchSignature::is_attribute () const { return _expr_type == ATTRIBUTE; }
 
170
inline bool MatchSignature::is_type () const { return _expr_type == TYPE; }
 
171
 
 
172
// manipulate the state
 
173
inline void MatchSignature::declare_virtual_function () {
 
174
  assert (is_function ());
 
175
  _fct_spec = (FctSpec)(FCT_VIRTUAL | _fct_spec);
 
176
}
 
177
 
 
178
// get more detailed infos about the match expression
 
179
// TODO: const correctness
 
180
inline MatchName &MatchSignature::name () { return _name; }
 
181
inline MatchTypeRef &MatchSignature::type () { return _type; }
 
182
 
 
183
// this is an abstraction for AspectC++ match expressions. These expressions
 
184
// describe signature patters, which can be matched agains the signatures
 
185
// of C++ objects. Match expressions are 'Signatures' that may contain
 
186
// special wildcard symbols ("%", "...").
 
187
 
 
188
class MatchExpr : public MatchSignature {
 
189
public:
 
190
  
 
191
  // constructors/destructor
 
192
  inline MatchExpr ();
 
193
  inline MatchExpr (ErrorStream &err, Location loc, const char *str);
 
194
 
 
195
  // check if a certain signature is matched by this expression,
 
196
  // obj is passed to check the name part of the signature
 
197
  // true is returned if the signature is matched
 
198
  inline bool matches (CTypeInfo *type, CObjectInfo *obj);
 
199
 
 
200
  // check if the match expression matches a passed match signature
 
201
  inline bool matches (MatchSignature &sig);
 
202
};
 
203
 
 
204
// implementations of inline constructors/destructor
 
205
inline MatchExpr::MatchExpr () {}
 
206
inline MatchExpr::MatchExpr (ErrorStream &err, Location loc, const char *str)
 
207
  : MatchSignature (err, loc, str) {}
159
208
 
160
209
// check if a certain signature is matched by this expression
161
210
// true is returned if the signature is matched
167
216
    return true;
168
217
  if (!_name.matches (obj))
169
218
    return false;
170
 
  if (is_function () && (_fct_spec & FCT_VIRTUAL) != 0) {
 
219
  if (is_virtual_function ()) {
171
220
    if (!(obj->isVirtual () || obj->FunctionInfo ()->overridesVirtual ()))
172
221
      return false;
173
222
  }
174
223
  return true;
175
224
}
176
225
 
 
226
// check if the match expression matches a passed match signature
 
227
inline bool MatchExpr::matches (MatchSignature &sig) {
 
228
  assert (_state == NORMAL && _expr_type == sig._expr_type && !_type.is_undefined ());
 
229
  if (!_type.matches (sig.type ()))
 
230
    return false;
 
231
  if (is_type ())
 
232
    return true;
 
233
  if (!_name.matches (sig.name ()))
 
234
    return false;
 
235
  if (is_virtual_function ()) {
 
236
    if (!sig.is_virtual_function ())
 
237
      return false;
 
238
  }
 
239
  return true;
 
240
}
 
241
 
177
242
#endif // __MatchExpr_h__