CMS 3D CMS Logo

MethodSetter.cc
Go to the documentation of this file.
2 
9 
10 #include <string>
11 
12 using namespace reco::parser;
13 using namespace std;
14 
15 void
17 operator()(const char* begin, const char* end) const
18 {
19  string name(begin, end);
20  string::size_type parenthesis = name.find_first_of('(');
21  if ((*begin == '[') || (*begin == '(')) {
22  name.insert(0, "operator.."); // operator..[arg];
23  parenthesis = 10; // ^--- idx = 10
24  name[8] = *begin; // operator[.[arg];
25  name[9] = name[name.size() - 1]; // operator[][arg];
26  name[10] = '('; // operator[](arg];
27  name[name.size() - 1] = ')'; // operator[](arg);
28  // we don't actually need the last two, but just for extra care
29  //std::cout << "Transformed {" << string(begin,end) << "} into
30  // {"<< name <<"}" << std::endl;
31  }
32  std::vector<AnyMethodArgument> args;
33  if (parenthesis != string::npos) {
34  name.erase(parenthesis, name.size());
35  if (intStack_.size() == 0) {
36  throw Exception(begin)
37  << "expected method argument, but non given.";
38  }
39  for (vector<AnyMethodArgument>::const_iterator i = intStack_.begin();
40  i != intStack_.end(); ++i) {
41  args.push_back(*i);
42  }
43  intStack_.clear();
44  }
45  string::size_type endOfExpr = name.find_last_of(' ');
46  if (endOfExpr != string::npos) {
47  name.erase(endOfExpr, name.size());
48  }
49  //std::cerr << "Pushing [" << name << "] with " << args.size()
50  // << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
51  if (lazy_) {
52  // for lazy parsing we just push method name and arguments
53  lazyMethStack_.push_back(LazyInvoker(name, args));
54  }
55  else {
56  // otherwise we really have to resolve the method
57  push(name, args, begin);
58  }
59  //std::cerr << "Pushed [" << name << "] with " << args.size() <<
60  // " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
61 }
62 
63 bool
65 push(const string& name, const vector<AnyMethodArgument>& args,
66  const char* begin, bool deep) const
67 {
68  edm::TypeWithDict type = typeStack_.back();
69  vector<AnyMethodArgument> fixups;
70  int error = 0;
71  pair<edm::FunctionWithDict, bool> mem =
72  reco::findMethod(type, name, args, fixups, begin, error);
73  if (bool(mem.first)) {
74  // We found the method.
75  edm::TypeWithDict retType = reco::returnType(mem.first);
76  if (!bool(retType)) {
77  // Invalid return type, fatal error, throw.
78  throw Exception(begin)
79  << "member \"" << mem.first.name()
80  << "\" return type is invalid:\n"
81  << " return type: \""
82  << mem.first.typeName() << "\"\n";
83  }
84  typeStack_.push_back(retType);
85  // check for edm::Ref, edm::RefToBase, edm::Ptr
86  if (mem.second) {
87  // Without fixups.
88  //std::cout << "Mem.second, so book " << mem.first.name() <<
89  // " without fixups." << std::endl;
90  methStack_.push_back(MethodInvoker(mem.first));
91  if (!deep) {
92  return false;
93  }
94  // note: we have not found the method, so we have not
95  // fixupped the arguments
96  push(name, args, begin);
97  }
98  else {
99  // With fixups.
100  //std::cout << "Not mem.second, so book " << mem.first.name()
101  // << " with #args = " << fixups.size() << std::endl;
102  methStack_.push_back(MethodInvoker(mem.first, fixups));
103  }
104  return true;
105  }
106  if (error != reco::parser::kNameDoesNotExist) {
107  // Fatal error, throw.
108  switch (error) {
110  throw Exception(begin)
111  << "method named \"" << name << "\" for type \""
112  << type.name() << "\" is not publically accessible.";
113  break;
115  throw Exception(begin)
116  << "method named \"" << name << "\" for type \""
117  << type.name() << "\" is static.";
118  break;
120  throw Exception(begin)
121  << "method named \"" << name << "\" for type \""
122  << type.name() << "\" is not const.";
123  break;
125  throw Exception(begin)
126  << "method named \"" << name << "\" for type \""
127  << type.name() << "\" was passed the wrong number of arguments.";
128  break;
130  throw Exception(begin)
131  << "method named \"" << name << "\" for type \""
132  << type.name() << "\" was passed the wrong types of arguments.";
133  break;
134  default:
135  throw Exception(begin)
136  << "method named \"" << name << "\" for type \""
137  << type.name() << "\" is not usable in this context.";
138  }
139  }
140  // Not a method, check for a data member.
141  error = 0;
142  edm::MemberWithDict member(reco::findDataMember(type, name, error));
143  if (!bool(member)) {
144  // Not a data member either, fatal error, throw.
145  switch (error) {
147  throw Exception(begin)
148  << "no method or data member named \"" << name
149  << "\" found for type \""
150  << type.name() << "\"";
151  break;
153  throw Exception(begin)
154  << "data member named \"" << name << "\" for type \""
155  << type.name() << "\" is not publically accessible.";
156  break;
157  default:
158  throw Exception(begin)
159  << "data member named \"" << name << "\" for type \""
160  << type.name() << "\" is not usable in this context.";
161  break;
162  }
163  }
164  // Ok, it was a data member.
165  typeStack_.push_back(member.typeOf());
166  methStack_.push_back(MethodInvoker(member));
167  return true;
168 }
169 
type
Definition: HCALResponse.h:21
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
uint16_t size_type
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
std::string name() const
std::pair< edm::FunctionWithDict, bool > findMethod(const edm::TypeWithDict &t, const std::string &name, const std::vector< AnyMethodArgument > &args, std::vector< AnyMethodArgument > &fixuppedArgs, const char *iIterator, int &oError)
Definition: findMethod.cc:145
edm::TypeWithDict returnType(const edm::FunctionWithDict &func)
Definition: returnType.cc:16
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:65
TypeWithDict typeOf() const
uint16_t mem[nChs][nEvts]
#define end
Definition: vmac.h:37
void operator()(const char *, const char *) const
Definition: MethodSetter.cc:17
#define begin
Definition: vmac.h:30