10 #include "base/integral_types.h" 11 #include "strings/stringpiece.h" 16 class EnumValueDescriptor;
22 namespace gpb = ::google::protobuf;
31 const gpb::EnumValueDescriptor* enum_val;
37 double PromoteToDouble()
const;
59 explicit ExprValue(CppType t) : type(t) {}
64 res.val.int_val = ival;
70 res.val.uint_val = val;
74 explicit ExprValue(StringPiece str) : type(CPPTYPE_STRING) {
78 explicit ExprValue(
const gpb::EnumValueDescriptor* eval) : type(CPPTYPE_ENUM) {
101 typedef std::function<bool(
const ExprValue&)> ExprValueCb;
106 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const = 0;
110 typedef std::vector<Expr*> ArgList;
118 enum class ValType { SINT64, UINT64, DOUBLE };
123 lit.val_.signed_val = v;
124 lit.val_type_ = ValType::SINT64;
131 lit.val_type_ = ValType::UINT64;
138 lit.val_type_ = ValType::DOUBLE;
142 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const override {
144 case ValType::UINT64:
145 cb(ExprValue::fromUInt(val_.uval));
147 case ValType::SINT64:
148 cb(ExprValue::fromInt(val_.signed_val));
150 case ValType::DOUBLE:
151 cb(ExprValue::fromDouble(val_.dval));
158 mutable std::string tmp_;
160 enum Type { CONST, VARIABLE};
162 StringTerm(
const std::string& v, Type t) : val_(v), type_(t) {}
164 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const override;
165 const std::string& val()
const {
return val_; }
171 std::unique_ptr<Expr> left_;
172 std::unique_ptr<Expr> right_;
175 enum Type {EQ, AND, OR, LT, LE, NOT, RLIKE};
176 BinOp(Type t,
Expr* l,
Expr* r) : left_(l), right_(r), type_(t) {}
178 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const override;
179 const Expr& left()
const {
return *left_.get(); }
180 const Expr& right()
const {
return *right_.get(); }
181 Type type()
const {
return type_; }
193 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const override;
199 IsDefFun(
const std::string& name) : name_(name) {};
200 virtual void eval(
const gpb::Message& msg, ExprValueCb cb)
const override;
203 bool EvaluateBoolExpr(
const Expr& e,
const gpb::Message& msg);