Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-17 23:10:26

0001 #include "CommonTools/Utils/interface/ExpressionVarSetter.h"
0002 #include "CommonTools/Utils/src/ExpressionVar.h"
0003 #include "CommonTools/Utils/interface/returnType.h"
0004 #include "CommonTools/Utils/interface/Exception.h"
0005 #include <string>
0006 using namespace reco::parser;
0007 using namespace std;
0008 
0009 void ExpressionVarSetter::operator()(const char *begin, const char *end) const {
0010   //std::cerr << "ExpressionVarSetter: Pushed [" << std::string(begin,end) << "]" << std::endl;
0011   if (!methStack_.empty())
0012     push(begin, end);
0013   else if (!lazyMethStack_.empty())
0014     lazyPush(begin, end);
0015   else
0016     throw Exception(begin) << " Expression didn't parse neither hastily nor lazyly. This must not happen.\n";
0017 }
0018 
0019 void ExpressionVarSetter::push(const char *begin, const char *end) const {
0020   edm::TypeWithDict type = typeStack_.back();
0021   method::TypeCode retType = reco::typeCode(type);
0022   if (retType == method::invalid) {
0023     throw Exception(begin) << "member \"" << methStack_.back().methodName() << "\" has an invalid return type: \""
0024                            << methStack_.back().returnTypeName() << "\"";
0025   }
0026   if (!ExpressionVar::isValidReturnType(retType)) {
0027     throw Exception(begin) << "member \"" << methStack_.back().methodName() << "\" return type is \""
0028                            << methStack_.back().returnTypeName() << "\" which is not convertible to double.";
0029   }
0030 
0031   exprStack_.push_back(std::shared_ptr<ExpressionBase>(new ExpressionVar(methStack_, retType)));
0032   methStack_.clear();
0033   typeStack_.resize(1);
0034 }
0035 
0036 void ExpressionVarSetter::lazyPush(const char *begin, const char *end) const {
0037   exprStack_.push_back(std::shared_ptr<ExpressionBase>(new ExpressionLazyVar(lazyMethStack_)));
0038   lazyMethStack_.clear();
0039   typeStack_.resize(1);
0040 }