29
29
#include "MatchTemplateArg.h"
30
30
#include "MatchName.h"
32
// this is an abstraction for AspectC++ match expressions. These expressions
33
// describe signature patters, which can be matched agains the signatures
32
// This class is an abstraction for a C++ object signature (function, type,
35
class MatchSignature {
40
40
NEW = 0, // this object is not initialized, yet
92
90
_allow_name (true), _type (PRIM_NONE) {}
95
// the name pattern of the match expression
94
//! match expression type
95
enum Type { ATTRIBUTE, FUNCTION, TYPE } _expr_type;
98
//! the name pattern of the match expression
97
101
MatchTypeRef _type;
100
104
// constructors/destructor
102
inline MatchExpr (ErrorStream &err, Location loc, const char *str);
105
inline MatchSignature ();
106
inline MatchSignature (ErrorStream &err, Location loc, const char *str);
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);
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);
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;
120
// manipulate the state
121
inline void declare_virtual_function ();
123
// get more detailed infos about the match expression
124
inline MatchName &name ();
125
inline MatchTypeRef &type ();
120
128
// internal parser functions that analyse a match expr string
147
155
// implementations of inline constructors/destructor
148
inline MatchExpr::MatchExpr () : _state (NEW) {}
149
inline MatchExpr::MatchExpr (ErrorStream &err, Location loc, const char *str) :
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);
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);
169
inline bool MatchSignature::is_attribute () const { return _expr_type == ATTRIBUTE; }
170
inline bool MatchSignature::is_type () const { return _expr_type == TYPE; }
172
// manipulate the state
173
inline void MatchSignature::declare_virtual_function () {
174
assert (is_function ());
175
_fct_spec = (FctSpec)(FCT_VIRTUAL | _fct_spec);
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; }
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 ("%", "...").
188
class MatchExpr : public MatchSignature {
191
// constructors/destructor
193
inline MatchExpr (ErrorStream &err, Location loc, const char *str);
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);
200
// check if the match expression matches a passed match signature
201
inline bool matches (MatchSignature &sig);
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) {}
160
209
// check if a certain signature is matched by this expression
161
210
// true is returned if the signature is matched
168
217
if (!_name.matches (obj))
170
if (is_function () && (_fct_spec & FCT_VIRTUAL) != 0) {
219
if (is_virtual_function ()) {
171
220
if (!(obj->isVirtual () || obj->FunctionInfo ()->overridesVirtual ()))
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 ()))
233
if (!_name.matches (sig.name ()))
235
if (is_virtual_function ()) {
236
if (!sig.is_virtual_function ())
177
242
#endif // __MatchExpr_h__