~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to AspectC++/AdviceInfo.cc

  • 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:
19
19
#include "AdviceInfo.h"
20
20
#include "AspectInfo.h"
21
21
#include "Binding.h"
 
22
#include "BackEndProblems.h"
22
23
 
23
24
#include <string.h>
 
25
#include <sstream>
 
26
using std::ostringstream;
24
27
 
25
28
#include "Puma/CClassDatabase.h"
26
29
#include "Puma/CArgumentInfo.h"
27
30
 
28
 
void AdviceInfo::gen_invocation_func (ostream &out, bool def) {
29
 
 
30
 
  CFunctionInfo *ad_func = _code->function ();
 
31
AdviceInfo::AdviceInfo (AspectInfo &ai, JPL_AdviceCode &c) :
 
32
  _aspect_info (ai), _aspect (ai.loc ()), _code (c) {}
 
33
 
 
34
void AdviceInfo::gen_invocation_func (ostream &out, bool def,
 
35
                                      const BackEndProblems &bep) {
 
36
 
 
37
  CFunctionInfo *ad_func = TI_AdviceCode::of (_code)->function ();
31
38
  CStructure *ad_cls = ad_func->ClassScope ();
32
39
  
33
 
  ThisJoinPoint &tjp = _code->this_join_point ();
34
 
  ThisJoinPoint &aspectof_tjp = aspect ()->aspectof_this_join_point ();
 
40
  const ThisJoinPoint &tjp = TI_AdviceCode::of (_code)->this_join_point ();
 
41
  const ThisJoinPoint &aspectof_tjp = _aspect_info.aspectof_this_join_point ();
35
42
    
36
43
  // determine whether the invocation functions needs JoinPoint, tjp, or Bind.
37
44
  bool has_context = (ad_func->Arguments () > 0);
42
49
    
43
50
  if (type_needed) {
44
51
    out << "  template <class JoinPoint";
45
 
    if (has_context)
46
 
      out << ", class Binding";
 
52
//    if (has_context)
 
53
//      out << ", class Binding";
47
54
    out << ">" << endl;
48
55
  }
49
 
  out << "  inline void invoke_" << _aspect->name () << "_"
50
 
      << Scope ()->Name () << "_" << (name () + 1) << " (";
 
56
  ostringstream suffix;
 
57
  suffix << _aspect.signature () << "_"
 
58
         << Scope ()->Name () << "_" << (name () + 1);
 
59
       
 
60
  out << "  ";
 
61
  if (bep._use_always_inline)
 
62
    out << "__attribute((always_inline)) ";
 
63
  out << "inline void invoke_" << suffix.str () << " (";
51
64
  if (pointer_needed)
52
65
    out << "JoinPoint *tjp";
53
66
  out << ")" << (def ? " {" : ";") << endl;
58
71
      
59
72
  // generate typedefs
60
73
  for (int a = 0; a < (int)ad_func->Arguments (); a++)
61
 
    out << "    typedef typename Binding::template Arg<" << a << "> Arg" << a 
62
 
        << ";" << endl;
 
74
//    out << "    typedef typename Binding::template Arg<" << a << "> Arg" << a 
 
75
//        << ";" << endl;
 
76
    out << "    typedef typename JoinPoint::Binding_" << suffix.str ()
 
77
        << "::template Arg<" << a << "> Arg" << a << ";" << endl;
63
78
 
64
79
  // generate advice call
65
80
  out << "    ";
66
 
  if (ad_cls != aspect ()->ClassInfo ())
 
81
  CClassInfo *aspect_cls = TI_Aspect::of (aspect ())->ClassInfo ();
 
82
  if (ad_cls != aspect_cls)
67
83
    out << "((::" << ad_cls->QualName () << "*)";
68
84
  // aspectof function
69
 
  out << "::" << aspect ()->name () << "::aspectof";
 
85
  out << "::" << aspect ().signature () << "::aspectof";
70
86
  // generate <JoinPoint> if necessary
71
87
  if (aspectof_tjp.type_needed () && !aspectof_tjp.pointer_needed ())
72
88
    out << "<JoinPoint>";
75
91
    out << "tjp";
76
92
  out << ")";
77
93
    
78
 
  if (ad_cls != aspect ()->ClassInfo ())
 
94
  if (ad_cls != aspect_cls)
79
95
    out << ")";
80
96
  out << "->";
81
97
  if (tjp.type_needed () && !tjp.pointer_needed())
110
126
 
111
127
void AdviceInfo::gen_invocation_func_call (ostream &stmt, const char* tjp_tp,
112
128
                                           const char *tjp_obj) {
113
 
  ThisJoinPoint &tjp = _code->this_join_point ();
114
 
  ThisJoinPoint &aspectof_tjp = aspect ()->aspectof_this_join_point ();
 
129
  const ThisJoinPoint &tjp = TI_AdviceCode::of (_code)->this_join_point ();
 
130
  const ThisJoinPoint &aspectof_tjp = _aspect_info.aspectof_this_join_point ();
115
131
    
116
132
  // determine whether the invocation functions needs JoinPoint or tjp
117
 
  bool has_context = (_code->function ()->Arguments () > 0);
 
133
  bool has_context = (TI_AdviceCode::of (_code)->function ()->Arguments () > 0);
118
134
  bool type_needed = tjp.type_needed () || aspectof_tjp.type_needed () ||
119
135
                     has_context;
120
136
  bool pointer_needed = tjp.pointer_needed () || has_context ||
121
137
                        aspectof_tjp.pointer_needed ();
122
138
    
123
 
  stmt << "AC::invoke_" << _aspect->name () << "_"
 
139
  stmt << "AC::invoke_" << _aspect.signature () << "_"
124
140
       << Scope ()->Name () << "_" << (name () + 1);
125
141
       
126
142
  if (type_needed) {
127
143
    stmt << "<" << tjp_tp;
128
 
    if (has_context) {
129
 
      string tp (tjp_tp);
130
 
      tp.erase (tp.length () - 2, tp.length ());
131
 
      stmt << ", Binding_" << tp << "_0_" << _aspect->name () << "_"
132
 
           << Scope ()->Name () << "_" << (name () + 1);
133
 
    }
 
144
//    if (has_context) {
 
145
//      string tp (tjp_tp);
 
146
//      tp.erase (tp.length () - 2, tp.length ());
 
147
//      stmt << ", Binding_" << tp << "_0_" << _aspect->name () << "_"
 
148
//           << Scope ()->Name () << "_" << (name () + 1);
 
149
//    }
134
150
    stmt << ">";
135
151
  }
136
152
 
144
160
void AdviceInfo::gen_binding_template (ostream &out, const char *jpname,
145
161
                                       const BackEndProblems &bep) {
146
162
  // later this will be passed as an argument
147
 
  Binding &bind = _code->binding ();
 
163
  Binding &bind = binding ();
148
164
 
149
165
  // no code generation if no context variables are expected
150
166
  if (!bind._used)
151
167
    return;
152
168
      
153
169
  // generate the mapping of context variables to advice function arguments
154
 
  out << "struct Binding_" << jpname << "_" << _aspect->name () << "_"
 
170
  out << "struct Binding_" /* << jpname << "_" */ << _aspect.signature () << "_"
155
171
      << Scope ()->Name () << "_" << (name () + 1) << " {" << endl;
156
 
  out << "  typedef " << jpname << " TJP;" << endl;
 
172
  out << "  typedef " /* << jpname*/ << "__TJP" << " TJP;" << endl;
157
173
  out << "  template <int I";
158
174
  if (bep._spec_scope)
159
175
    out << ", int DUMMY = 0";
161
177
  out << "    void val (TJP *tjp) {} // for VC7" << endl;
162
178
  out << "  };" << endl;
163
179
 
164
 
  CFunctionInfo *ad_func = _code->function ();
 
180
  CFunctionInfo *ad_func = TI_AdviceCode::of (_code)->function ();
165
181
  for (int a = 0; a < (int)ad_func->Arguments (); a++) {
166
182
    CTypeInfo *argtype = ad_func->Argument (a)->TypeInfo ();
167
183
    int bind_index = bind.bound_to (ad_func->Argument (a));
173
189
    if (bep._spec_scope)
174
190
      out << ", DUMMY";
175
191
    out << "> {" << endl
176
 
        << "    static TJP::";
 
192
        << "    static typename TJP::";
177
193
    switch (bind_index) {
178
194
      case Binding::BIND_THAT:
179
195
        out << "That " << (argtype->isPointer () ? "*" : "&")
191
207
      case Binding::BIND_NOT_FOUND: // already handled by assertion
192
208
        break;
193
209
      default: // argument
194
 
        out << "Arg<" << bind_index << ">::ReferredType &val (TJP *tjp) {"
 
210
        out << "template Arg<" << bind_index << ">::ReferredType &val (TJP *tjp) {"
195
211
            << " return *tjp->template arg<" << bind_index << "> (); }" << endl;
196
212
    }
197
213
    out << "  };" << endl;