MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / Macro

Class Macro

parser/macro.h:69–167  ·  view source on GitHub ↗

Macro interface for describing the function signature to match and the MacroExpander to apply. Note: when a Macro should apply to multiple overloads (based on arg count) of a given function, a Macro should be created per arg-count.

Source from the content-addressed store, hash-verified

67// Note: when a Macro should apply to multiple overloads (based on arg count) of
68// a given function, a Macro should be created per arg-count.
69class Macro final {
70 public:
71 static absl::StatusOr<Macro> Global(absl::string_view name,
72 size_t argument_count,
73 GlobalMacroExpander expander);
74
75 static absl::StatusOr<Macro> GlobalVarArg(absl::string_view name,
76 GlobalMacroExpander expander);
77
78 static absl::StatusOr<Macro> Receiver(absl::string_view name,
79 size_t argument_count,
80 ReceiverMacroExpander expander);
81
82 static absl::StatusOr<Macro> ReceiverVarArg(absl::string_view name,
83 ReceiverMacroExpander expander);
84
85 Macro(const Macro&) = default;
86 Macro(Macro&&) = default;
87 Macro& operator=(const Macro&) = default;
88 Macro& operator=(Macro&&) = default;
89
90 // Function name to match.
91 absl::string_view function() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
92 return rep_->function;
93 }
94
95 // argument_count() for the function call.
96 //
97 // When the macro is a var-arg style macro, the return value will be zero, but
98 // the MacroKey will contain a `*` where the arg count would have been.
99 size_t argument_count() const { return rep_->arg_count; }
100
101 // is_receiver_style returns true if the macro matches a receiver style call.
102 bool is_receiver_style() const { return rep_->receiver_style; }
103
104 bool is_variadic() const { return rep_->var_arg_style; }
105
106 // key() returns the macro signatures accepted by this macro.
107 //
108 // Format: `<function>:<arg-count>:<is-receiver>`.
109 //
110 // When the macros is a var-arg style macro, the `arg-count` value is
111 // represented as a `*`.
112 absl::string_view key() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
113 return rep_->key;
114 }
115
116 // Expander returns the MacroExpander to apply when the macro key matches the
117 // parsed call signature.
118 const MacroExpander& expander() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
119 return rep_->expander;
120 }
121
122 ABSL_MUST_USE_RESULT absl::optional<Expr> Expand(
123 MacroExprFactory& factory,
124 absl::optional<std::reference_wrapper<Expr>> target,
125 absl::Span<Expr> arguments) const {
126 return (expander())(factory, target, arguments);

Callers 1

MakeMethod · 0.85

Calls 1

ExpandFunction · 0.85

Tested by

no test coverage detected