CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
reco::parser::MethodSetter Class Reference

#include <MethodSetter.h>

Public Member Functions

 MethodSetter (MethodStack &methStack, LazyMethodStack &lazyMethStack, TypeStack &typeStack, MethodArgumentStack &intStack, bool lazy=false)
 
void operator() (const char *, const char *) const
 
bool push (const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
 

Private Attributes

MethodArgumentStackintStack_
 
bool lazy_
 
LazyMethodStacklazyMethStack_
 
MethodStackmethStack_
 
TypeStacktypeStack_
 

Detailed Description

Definition at line 17 of file MethodSetter.h.

Constructor & Destructor Documentation

◆ MethodSetter()

reco::parser::MethodSetter::MethodSetter ( MethodStack methStack,
LazyMethodStack lazyMethStack,
TypeStack typeStack,
MethodArgumentStack intStack,
bool  lazy = false 
)
inlineexplicit

Definition at line 26 of file MethodSetter.h.

31  : methStack_(methStack),
32  lazyMethStack_(lazyMethStack),
33  typeStack_(typeStack),
34  intStack_(intStack),
35  lazy_(lazy) {}
MethodArgumentStack & intStack_
Definition: MethodSetter.h:22
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:20

Member Function Documentation

◆ operator()()

void MethodSetter::operator() ( const char *  begin,
const char *  end 
) const

Definition at line 15 of file MethodSetter.cc.

References writedatasetfile::args, Exception, mps_fire::i, Skims_PA_cff::name, and edm_modernize_messagelogger::parenthesis.

15  {
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 }
MethodArgumentStack & intStack_
Definition: MethodSetter.h:22
uint16_t size_type
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
LazyMethodStack & lazyMethStack_
Definition: MethodSetter.h:20
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57

◆ push()

bool MethodSetter::push ( const std::string &  ,
const std::vector< AnyMethodArgument > &  ,
const char *  ,
bool  deep = true 
) const

Resolve the name to either a function member or a data member, push a MethodInvoker on the MethodStack, and its return type to the TypeStack (after stripping "*" and "&").

This method is used also by the LazyInvoker to perform the fetch once the final type is known.

If the object is an edm::Ref/Ptr/RefToBase and the method is not found in the class:

1) it pushes a no-argument 'get()' method

2) if deep = true, it attempts to resolve and push the method on the object to which the edm ref points to. In that case, the MethodStack will contain two more items after this call instead of just one. This behaviour is what you want for non-lazy parsing.

2b) if instead deep = false, it just pushes the 'get' on the stack. this will allow the LazyInvoker to then re-discover the runtime type of the pointee

The method will:

  • throw exception, if the member can't be resolved
  • return 'false' if deep = false and it only pushed - return true otherwise

Definition at line 57 of file MethodSetter.cc.

References writedatasetfile::args, relativeConstraints::error, Exception, f, reco::findDataMember(), reco::findMethod(), stringResolutionProvider_cfi::functions, reco::parser::kIsNotConst, reco::parser::kIsNotPublic, reco::parser::kIsStatic, reco::parser::kNameDoesNotExist, reco::parser::kWrongArgumentType, reco::parser::kWrongNumberOfArguments, visualization-live-secondInstance_cfg::m, mem, Skims_PA_cff::name, reco::returnType(), and edm::MemberWithDict::typeOf().

Referenced by reco::parser::SingleInvoker::SingleInvoker(), esMonitoring.LineHistoryEnd::write(), and esMonitoring.LineHistoryStart::write().

57  {
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 }
edm::MemberWithDict findDataMember(const edm::TypeWithDict &iType, const std::string &iName, int &oError)
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]
bool push(const std::string &, const std::vector< AnyMethodArgument > &, const char *, bool deep=true) const
Definition: MethodSetter.cc:57

Member Data Documentation

◆ intStack_

MethodArgumentStack& reco::parser::MethodSetter::intStack_
private

Definition at line 22 of file MethodSetter.h.

◆ lazy_

bool reco::parser::MethodSetter::lazy_
private

Definition at line 23 of file MethodSetter.h.

◆ lazyMethStack_

LazyMethodStack& reco::parser::MethodSetter::lazyMethStack_
private

Definition at line 20 of file MethodSetter.h.

◆ methStack_

MethodStack& reco::parser::MethodSetter::methStack_
private

Definition at line 19 of file MethodSetter.h.

◆ typeStack_

TypeStack& reco::parser::MethodSetter::typeStack_
private

Definition at line 21 of file MethodSetter.h.