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  throw Exception(begin) << "no method or data member named \"" << name << "\" found for type \"" << type.name()
125  << "\"";
126  break;
128  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
129  << "\" is not publically accessible.";
130  break;
131  default:
132  throw Exception(begin) << "data member named \"" << name << "\" for type \"" << type.name()
133  << "\" is not usable in this context.";
134  break;
135  }
136  }
137  // Ok, it was a data member.
138  typeStack_.push_back(member.typeOf());
139  methStack_.push_back(MethodInvoker(member));
140  return true;
141 }
writedatasetfile.args
args
Definition: writedatasetfile.py:18
mps_fire.i
i
Definition: mps_fire.py:428
reco::findDataMember
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
Definition: findDataMember.cc:30
reco::parser::kIsNotPublic
Definition: ErrorCodes.h:33
ErrorCodes.h
reco::parser::kNameDoesNotExist
Definition: ErrorCodes.h:32
edm_modernize_messagelogger.parenthesis
parenthesis
Definition: edm_modernize_messagelogger.py:52
reco::parser::MethodSetter::operator()
void operator()(const char *, const char *) const
Definition: MethodSetter.cc:15
reco::parser::MethodInvoker
Definition: MethodInvoker.h:25
mem
uint16_t mem[nChs][nEvts]
Definition: recycleTccEmu.cc:13
relativeConstraints.error
error
Definition: relativeConstraints.py:53
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
reco::parser::kIsNotConst
Definition: ErrorCodes.h:35
Exception.h
mps_fire.end
end
Definition: mps_fire.py:242
edm::MemberWithDict::typeOf
TypeWithDict typeOf() const
Definition: MemberWithDict.cc:18
reco::findMethod
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
reco::returnType
edm::TypeWithDict returnType(const edm::FunctionWithDict &func)
Definition: returnType.cc:16
edm::TypeWithDict
Definition: TypeWithDict.h:38
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
reco::parser::LazyInvoker
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke()
Definition: MethodInvoker.h:96
edm::MemberWithDict
Definition: MemberWithDict.h:19
MethodInvoker.h
returnType.h
reco::parser::kIsStatic
Definition: ErrorCodes.h:34
reco::parser
Definition: cutParser.h:9
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:245
findDataMember.h
reco::parser::MethodSetter::push
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::parser::kWrongNumberOfArguments
Definition: ErrorCodes.h:40
findMethod.h
reco::parser::kWrongArgumentType
Definition: ErrorCodes.h:41
MethodSetter.h