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 MethodSetter::operator()(const char* begin, const char* end) const {
16  string name(begin, end);
17  string::size_type parenthesis = name.find_first_of('(');
18  if ((*begin == '[') || (*begin == '(')) {
19  name.insert(0, "operator.."); // operator..[arg];
20  parenthesis = 10; // ^--- idx = 10
21  name[8] = *begin; // operator[.[arg];
22  name[9] = name[name.size() - 1]; // operator[][arg];
23  name[10] = '('; // operator[](arg];
24  name[name.size() - 1] = ')'; // operator[](arg);
25  // we don't actually need the last two, but just for extra care
26  //std::cout << "Transformed {" << string(begin,end) << "} into
27  // {"<< name <<"}" << std::endl;
28  }
29  std::vector<AnyMethodArgument> args;
30  if (parenthesis != string::npos) {
31  name.erase(parenthesis, name.size());
32  if (intStack_.empty()) {
33  throw Exception(begin) << "expected method argument, but non given.";
34  }
35  for (vector<AnyMethodArgument>::const_iterator i = intStack_.begin(); i != intStack_.end(); ++i) {
36  args.push_back(*i);
37  }
38  intStack_.clear();
39  }
40  string::size_type endOfExpr = name.find_last_of(' ');
41  if (endOfExpr != string::npos) {
42  name.erase(endOfExpr, name.size());
43  }
44  //std::cerr << "Pushing [" << name << "] with " << args.size()
45  // << " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
46  if (lazy_) {
47  // for lazy parsing we just push method name and arguments
48  lazyMethStack_.push_back(LazyInvoker(name, args));
49  } else {
50  // otherwise we really have to resolve the method
51  push(name, args, begin);
52  }
53  //std::cerr << "Pushed [" << name << "] with " << args.size() <<
54  // " args " << (lazy_ ? "(lazy)" : "(immediate)") << std::endl;
55 }
56 
57 bool MethodSetter::push(const string& name, const vector<AnyMethodArgument>& args, const char* begin, bool deep) const {
58  edm::TypeWithDict type = typeStack_.back();
59  vector<AnyMethodArgument> fixups;
60  int error = 0;
61  pair<edm::FunctionWithDict, bool> mem = reco::findMethod(type, name, args, fixups, begin, error);
62  if (bool(mem.first)) {
63  // We found the method.
64  edm::TypeWithDict retType = reco::returnType(mem.first);
65  if (!bool(retType)) {
66  // Invalid return type, fatal error, throw.
67  throw Exception(begin) << "member \"" << mem.first.name() << "\" return type is invalid:\n"
68  << " return type: \"" << mem.first.typeName() << "\"\n";
69  }
70  typeStack_.push_back(retType);
71  // check for edm::Ref, edm::RefToBase, edm::Ptr
72  if (mem.second) {
73  // Without fixups.
74  //std::cout << "Mem.second, so book " << mem.first.name() <<
75  // " without fixups." << std::endl;
76  methStack_.push_back(MethodInvoker(mem.first));
77  if (!deep) {
78  return false;
79  }
80  // note: we have not found the method, so we have not
81  // fixupped the arguments
82  push(name, args, begin);
83  } else {
84  // With fixups.
85  //std::cout << "Not mem.second, so book " << mem.first.name()
86  // << " with #args = " << fixups.size() << std::endl;
87  methStack_.push_back(MethodInvoker(mem.first, fixups));
88  }
89  return true;
90  }
92  // Fatal error, throw.
93  switch (error) {
95  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
96  << "\" is not publically accessible.";
97  break;
99  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name() << "\" is static.";
100  break;
102  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name() << "\" is not const.";
103  break;
105  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
106  << "\" was passed the wrong number of arguments.";
107  break;
109  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
110  << "\" was passed the wrong types of arguments.";
111  break;
112  default:
113  throw Exception(begin) << "method named \"" << name << "\" for type \"" << type.name()
114  << "\" is not usable in this context.";
115  }
116  }
117  // Not a method, check for a data member.
118  error = 0;
120  if (!bool(member)) {
121  // Not a data member either, fatal error, throw.
122  switch (error) {
124  Exception ex(begin);
125  ex << "no method or data member named \"" << name << "\" found for type \"" << type.name() << "\"\n";
126  // The following information is for temporary debugging only, intended to be removed later
127  ex << "It has the following methods\n";
129  for (auto const& f : functions) {
130  ex << " " << f->GetName() << "\n";
131  }
132  ex << "and the following data members\n";
133  edm::TypeDataMembers members(type);
134  for (auto const& m : members) {
135  ex << " " << m->GetName() << "\n";
136  }
137  throw ex;
138  } break;
140  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
141  << "\" is not publically accessible.";
142  break;
143  default:
144  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
145  << "\" is not usable in this context.";
146  break;
147  }
148  }
149  // Ok, it was a data member.
150  typeStack_.push_back(member.typeOf());
151  methStack_.push_back(MethodInvoker(member));
152  return true;
153 }
TypeWithDict typeOf() const
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::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:130
edm::TypeWithDict returnType(const edm::FunctionWithDict &)
Definition: returnType.cc:16
double f[11][100]
uint16_t mem[nChs][nEvts]
void operator()(const char *, const char *) const
Definition: MethodSetter.cc:15
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57