forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute_utility.h
More file actions
77 lines (66 loc) · 3.07 KB
/
Copy pathattribute_utility.h
File metadata and controls
77 lines (66 loc) · 3.07 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
#ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_UNKNOWNS_UTILITY_H_
#define THIRD_PARTY_CEL_CPP_EVAL_EVAL_UNKNOWNS_UTILITY_H_
#include <vector>
#include "google/protobuf/arena.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "eval/eval/attribute_trail.h"
#include "eval/public/activation.h"
#include "eval/public/cel_attribute.h"
#include "eval/public/cel_expression.h"
#include "eval/public/cel_value.h"
#include "eval/public/unknown_attribute_set.h"
#include "eval/public/unknown_set.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
// Helper class for handling unknowns and missing attribute logic. Provides
// helpers for merging unknown sets from arguments on the stack and for
// identifying unknown/missing attributes based on the patterns for a given
// Evaluation.
class AttributeUtility {
public:
AttributeUtility(
const std::vector<CelAttributePattern>* unknown_patterns,
const std::vector<CelAttributePattern>* missing_attribute_patterns,
google::protobuf::Arena* arena)
: unknown_patterns_(unknown_patterns),
missing_attribute_patterns_(missing_attribute_patterns),
arena_(arena) {}
// Checks whether particular corresponds to any patterns that define missing
// attribute.
bool CheckForMissingAttribute(const AttributeTrail& trail) const;
// Checks whether particular corresponds to any patterns that define unknowns.
bool CheckForUnknown(const AttributeTrail& trail, bool use_partial) const;
// Creates merged UnknownAttributeSet.
// Scans over the args collection, determines if there matches to unknown
// patterns and returns the (possibly empty) collection.
UnknownAttributeSet CheckForUnknowns(absl::Span<const AttributeTrail> args,
bool use_partial) const;
// Creates merged UnknownSet.
// Scans over the args collection, merges any UnknownAttributeSets found in
// it together with initial_set (if initial_set is not null).
// Returns pointer to merged set or nullptr, if there were no sets to merge.
const UnknownSet* MergeUnknowns(absl::Span<const CelValue> args,
const UnknownSet* initial_set) const;
// Creates merged UnknownSet.
// Merges together attributes from UnknownSets found in the args
// collection, attributes from attr that match unknown pattern
// patterns, and attributes from initial_set
// (if initial_set is not null).
// Returns pointer to merged set or nullptr, if there were no sets to merge.
const UnknownSet* MergeUnknowns(absl::Span<const CelValue> args,
absl::Span<const AttributeTrail> attrs,
const UnknownSet* initial_set,
bool use_partial) const;
private:
const std::vector<CelAttributePattern>* unknown_patterns_;
const std::vector<CelAttributePattern>* missing_attribute_patterns_;
google::protobuf::Arena* arena_;
};
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google
#endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_UNKNOWNS_UTILITY_H_