forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat_expr_builder.h
More file actions
93 lines (76 loc) · 3.04 KB
/
Copy pathflat_expr_builder.h
File metadata and controls
93 lines (76 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef THIRD_PARTY_CEL_CPP_EVAL_COMPILER_FLAT_EXPR_BUILDER_H_
#define THIRD_PARTY_CEL_CPP_EVAL_COMPILER_FLAT_EXPR_BUILDER_H_
#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "eval/public/cel_expression.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
// CelExpressionBuilder implementation.
// Builds instances of CelExpressionFlatImpl.
class FlatExprBuilder : public CelExpressionBuilder {
public:
FlatExprBuilder()
: enable_unknowns_(false),
enable_unknown_function_results_(false),
enable_missing_attribute_errors_(false),
shortcircuiting_(true),
constant_folding_(false),
constant_arena_(nullptr),
enable_comprehension_(true),
comprehension_max_iterations_(0),
fail_on_warnings_(true) {}
// set_enable_unknowns controls support for unknowns in expressions created.
void set_enable_unknowns(bool enabled) { enable_unknowns_ = enabled; }
// set_enable_missing_attribute_errors support for error injection in
// expressions created.
void set_enable_missing_attribute_errors(bool enabled) {
enable_missing_attribute_errors_ = enabled;
}
// set_enable_unknown_function_results controls support for unknown function
// results.
void set_enable_unknown_function_results(bool enabled) {
enable_unknown_function_results_ = enabled;
}
// set_shortcircuiting regulates shortcircuiting of some expressions.
// Be default shortcircuiting is enabled.
void set_shortcircuiting(bool enabled) { shortcircuiting_ = enabled; }
// Toggle constant folding optimization. By default it is not enabled.
// The provided arena is used to hold the generated constants.
void set_constant_folding(bool enabled, google::protobuf::Arena* arena) {
constant_folding_ = enabled;
constant_arena_ = arena;
}
void set_enable_comprehension(bool enabled) {
enable_comprehension_ = enabled;
}
void set_comprehension_max_iterations(int max_iterations) {
comprehension_max_iterations_ = max_iterations;
}
// Warnings (e.g. no function bound) fail immediately.
void set_fail_on_warnings(bool should_fail) {
fail_on_warnings_ = should_fail;
}
absl::StatusOr<std::unique_ptr<CelExpression>> CreateExpression(
const google::api::expr::v1alpha1::Expr* expr,
const google::api::expr::v1alpha1::SourceInfo* source_info) const override;
absl::StatusOr<std::unique_ptr<CelExpression>> CreateExpression(
const google::api::expr::v1alpha1::Expr* expr,
const google::api::expr::v1alpha1::SourceInfo* source_info,
std::vector<absl::Status>* warnings) const override;
private:
bool enable_unknowns_;
bool enable_unknown_function_results_;
bool enable_missing_attribute_errors_;
bool shortcircuiting_;
bool constant_folding_;
google::protobuf::Arena* constant_arena_;
bool enable_comprehension_;
int comprehension_max_iterations_;
bool fail_on_warnings_;
};
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google
#endif // THIRD_PARTY_CEL_CPP_EVAL_COMPILER_FLAT_EXPR_BUILDER_H_