CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MethodSetter.cc
Go to the documentation of this file.
7 #include <string>
8 using namespace reco::parser;
9 using namespace std;
10 using namespace Reflex;
11 
12 void MethodSetter::operator()(const char * begin, const char * end) const {
13  string name(begin, end);
14  string::size_type parenthesis = name.find_first_of('(');
15  if (*begin == '[' || *begin == '(') {
16  name.insert(0, "operator.."); // operator..[arg];
17  parenthesis = 10; // ^--- idx = 10
18  name[8] = *begin; // operator[.[arg];
19  name[9] = name[name.size()-1]; // operator[][arg];
20  name[10] = '('; // operator[](arg];
21  name[name.size()-1] = ')'; // operator[](arg);
22  // we don't actually need the last two, but just for extra care
23  //std::cout << "Transformed {" << string(begin,end) << "} into {"<< name <<"}" << std::endl;
24  }
25  std::vector<AnyMethodArgument> args;
26  if(parenthesis != string::npos) {
27  name.erase(parenthesis, name.size());
28  if(intStack_.size()==0)
29  throw Exception(begin)
30  << "expected method argument, but non given.";
31  for(vector<AnyMethodArgument>::const_iterator i = intStack_.begin(); i != intStack_.end(); ++i)
32  args.push_back(*i);
33  intStack_.clear();
34  }
35  string::size_type endOfExpr = name.find_last_of(' ');
36  if(endOfExpr != string::npos)
37  name.erase(endOfExpr, name.size());
38  //std::cerr << "Pushing [" << name << "] with " << args.size() << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
39  if (lazy_) lazyMethStack_.push_back(LazyInvoker(name, args)); // for lazy parsing we just push method name and arguments
40  else push(name, args,begin); // otherwise we really have to resolve the method
41  //std::cerr << "Pushed [" << name << "] with " << args.size() << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
42 }
43 
44 bool MethodSetter::push(const string & name, const vector<AnyMethodArgument> & args, const char* begin,bool deep) const {
45  Type type = typeStack_.back();
46  vector<AnyMethodArgument> fixups;
47  int error;
48  pair<Member, bool> mem = reco::findMethod(type, name, args, fixups,begin,error);
49  if(mem.first) {
50  Type retType = reco::returnType(mem.first);
51  if(!retType) {
52  throw Exception(begin)
53  << "member \"" << mem.first.Name() << "\" return type is invalid:\n"
54  << " member type: \"" << mem.first.TypeOf().Name() << "\"\n"
55  << " return type: \"" << mem.first.TypeOf().ReturnType().Name() << "\"\n";
56 
57  }
58  typeStack_.push_back(retType);
59  // check for edm::Ref, edm::RefToBase, edm::Ptr
60  if(mem.second) {
61  //std::cout << "Mem.second, so book " << mem.first.Name() << " without fixups." << std::endl;
62  methStack_.push_back(MethodInvoker(mem.first));
63  if (deep) push(name, args,begin); // note: we have not found the method, so we have not fixupped the arguments
64  else return false;
65  } else {
66  //std::cout << "Not mem.second, so book " << mem.first.Name() << " with #args = " << fixups.size() << std::endl;
67  methStack_.push_back(MethodInvoker(mem.first, fixups));
68  }
69  } else {
70  if(error != reco::parser::kNameDoesNotExist) {
71  switch(error) {
73  throw Exception(begin)
74  << "method named \"" << name << "\" for type \""
75  <<type.Name() << "\" is not publically accessible.";
76  break;
78  throw Exception(begin)
79  << "method named \"" << name << "\" for type \""
80  <<type.Name() << "\" is static.";
81  break;
83  throw Exception(begin)
84  << "method named \"" << name << "\" for type \""
85  <<type.Name() << "\" is not const.";
86  break;
88  throw Exception(begin)
89  << "method named \"" << name << "\" for type \""
90  <<type.Name() << "\" was passed the wrong number of arguments.";
91  break;
93  throw Exception(begin)
94  << "method named \"" << name << "\" for type \""
95  <<type.Name() << "\" was passed the wrong types of arguments.";
96  break;
97  default:
98  throw Exception(begin)
99  << "method named \"" << name << "\" for type \""
100  <<type.Name() << "\" is not usable in this context.";
101  }
102  }
103  //see if it is a member data
104  int error;
105  Member member = reco::findDataMember(type,name,error);
106  if(!member) {
107  switch(error) {
109  throw Exception(begin)
110  << "no method or data member named \"" << name << "\" found for type \""
111  <<type.Name() << "\"";
112  break;
114  throw Exception(begin)
115  << "data member named \"" << name << "\" for type \""
116  <<type.Name() << "\" is not publically accessible.";
117  break;
118  default:
119  throw Exception(begin)
120  << "data member named \"" << name << "\" for type \""
121  <<type.Name() << "\" is not usable in this context.";
122  break;
123  }
124  }
125  typeStack_.push_back(member.TypeOf());
126  methStack_.push_back(MethodInvoker(member));
127  }
128  return true;
129 }
130 
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:44
uint16_t size_type
Type returnType(const Member &mem)
Definition: returnType.cc:9
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:65
uint16_t mem[nChs][nEvts]
#define end
Definition: vmac.h:38
pair< Member, bool > findMethod(const Type &t, const string &name, const std::vector< AnyMethodArgument > &args, std::vector< AnyMethodArgument > &fixuppedArgs, const char *iIterator, int &oError)
Definition: findMethod.cc:66
void operator()(const char *, const char *) const
Definition: MethodSetter.cc:12
dictionary args
#define begin
Definition: vmac.h:31
Reflex::Member findDataMember(const Reflex::Type &iType, const std::string &iName, int &oError)