File: PointCutContext.h

package info (click to toggle)
aspectc%2B%2B 1.0pre4~svn.20090918-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 117,308 kB
  • ctags: 410,601
  • sloc: cpp: 1,883,007; ansic: 17,279; sh: 2,190; makefile: 1,088
file content (143 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2003  The 'ac++' developers (see aspectc.org)
//                                                                
// This program is free software;  you can redistribute it and/or 
// modify it under the terms of the GNU General Public License as 
// published by the Free Software Foundation; either version 2 of 
// the License, or (at your option) any later version.            
//                                                                
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
// GNU General Public License for more details.                   
//                                                                
// You should have received a copy of the GNU General Public      
// License along with this program; if not, write to the Free     
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
// MA  02111-1307  USA                                            

#ifndef __PointCutContext_h__
#define __PointCutContext_h__

#include <set>
using namespace std;

#include "Puma/Array.h"
#include "Puma/Stack.h"

#include "Binding.h"
#ifdef ACMODEL
#include "Elements.h"
#else
#include "JoinPointModel.h"
#endif

using namespace Puma;

namespace Puma {
  class CFunctionInfo;
  class CArgumentInfo;
  class CObjectInfo;
  class ACAspectInfo;
  class CTranslationUnit;
  class ErrorStream;
  class CTree;
}

class PointCutExpr;

typedef Array<const CArgumentInfo*> ArgSet;

class PointCutContext {
#ifdef ACMODEL
  ProjectModel &_jpm;
  ACM_Aspect *_aspect;
#else
  JoinPointModel &_jpm;
  JPL_Aspect *_aspect;
#endif
  CFunctionInfo *_func;
  int _per_aspect_cflows;

  // new pointcut evaluation data members
  Stack<ArgSet*> _arg_bindings;
  int _in_arg;
  bool _in_result;
  bool _in_that;
  bool _in_target;
  bool _pseudo_true;
  set<PointCutExpr*> _cflow_exprs;

  CFunctionInfo *lookup_pointcut(ACAspectInfo *ai, CFunctionInfo *fi);

public:

#ifdef ACMODEL
  PointCutContext (ProjectModel &jpm) :
#else
  PointCutContext (JoinPointModel &jpm) :
#endif
    _jpm (jpm), _aspect (0), _func (0), _per_aspect_cflows (0),
    _in_arg (-1), _in_result (false), _in_that (false), _in_target (false),
    _pseudo_true (false) {
  }

#ifdef ACMODEL
  ProjectModel &jpm () { return _jpm; }
#else
  JoinPointModel &jpm () { return _jpm; }
#endif 

  CFunctionInfo *func (CFunctionInfo *new_func) {
    CFunctionInfo *result = _func;
    _func = new_func;
    return result;
  }
  CFunctionInfo *func () const { return _func; }
#ifdef ACMODEL
  void concrete_aspect (ACM_Aspect &ai) { _aspect = &ai; _per_aspect_cflows = 0; }
#else
  void concrete_aspect (JPL_Aspect &ai) { _aspect = &ai; _per_aspect_cflows = 0; }
#endif
//  ACAspectInfo *aspect_info () const { return _aspect; }
  CFunctionInfo *lookup_pointcut (CFunctionInfo *func, ErrorStream &err,
				  CTree *node);
  bool in_project (CObjectInfo *obj);

  // used for semantic analysis of pointcut expressions
  Stack<ArgSet*> &arg_bindings () { return _arg_bindings; }

  // used for context binding in args()
  bool in_arg () const { return _in_arg >= 0; }
  void set_arg (int a) { _in_arg = a; }
  int get_arg () const { return _in_arg; }

  // used for context binding in result()
  bool in_result () const { return _in_result; }
  void enter_result () { _in_result = true; }
  void leave_result () { _in_result = false; }

  // used for context binding in that()
  bool in_that () const { return _in_that; }
  void enter_that () { _in_that = true; }
  void leave_that () { _in_that = false; }

  // used for context binding in target()
  bool in_target () const { return _in_target; }
  void enter_target () { _in_target = true; }
  void leave_target () { _in_target = false; }

  // that or within was evaluated as true, because we have a pseudo call
  void pseudo_true (bool val) { _pseudo_true = val; }
  bool is_pseudo_true () const { return _pseudo_true; }
  
  // cflow trigger management
  int cflow (PointCutExpr *pce) {
    _cflow_exprs.insert (pce);
    return _per_aspect_cflows++;
  }
  const set<PointCutExpr*> &cflows () { return _cflow_exprs; }
  void cflow_reset () { _cflow_exprs.clear (); }
};

#endif // __PointCutContext_h__