@@ -78,8 +78,6 @@ public enum CelStandardMacro {
7878 public static final ImmutableSet <CelStandardMacro > STANDARD_MACROS =
7979 ImmutableSet .of (HAS , ALL , EXISTS , EXISTS_ONE , MAP , MAP_FILTER , FILTER );
8080
81- private static final String ACCUMULATOR_VAR = "__result__" ;
82-
8381 private final CelMacro macro ;
8482
8583 CelStandardMacro (CelMacro macro ) {
@@ -123,14 +121,23 @@ private static Optional<CelExpr> expandAllMacro(
123121 CelExpr accuInit = exprFactory .newBoolLiteral (true );
124122 CelExpr condition =
125123 exprFactory .newGlobalCall (
126- Operator .NOT_STRICTLY_FALSE .getFunction (), exprFactory .newIdentifier (ACCUMULATOR_VAR ));
124+ Operator .NOT_STRICTLY_FALSE .getFunction (),
125+ exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ()));
127126 CelExpr step =
128127 exprFactory .newGlobalCall (
129- Operator .LOGICAL_AND .getFunction (), exprFactory .newIdentifier (ACCUMULATOR_VAR ), arg1 );
130- CelExpr result = exprFactory .newIdentifier (ACCUMULATOR_VAR );
128+ Operator .LOGICAL_AND .getFunction (),
129+ exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ()),
130+ arg1 );
131+ CelExpr result = exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ());
131132 return Optional .of (
132133 exprFactory .fold (
133- arg0 .ident ().name (), target , ACCUMULATOR_VAR , accuInit , condition , step , result ));
134+ arg0 .ident ().name (),
135+ target ,
136+ exprFactory .getAccumulatorVarName (),
137+ accuInit ,
138+ condition ,
139+ step ,
140+ result ));
134141 }
135142
136143 // CelMacroExpander implementation for CEL's exists() macro.
@@ -149,14 +156,23 @@ private static Optional<CelExpr> expandExistsMacro(
149156 exprFactory .newGlobalCall (
150157 Operator .NOT_STRICTLY_FALSE .getFunction (),
151158 exprFactory .newGlobalCall (
152- Operator .LOGICAL_NOT .getFunction (), exprFactory .newIdentifier (ACCUMULATOR_VAR )));
159+ Operator .LOGICAL_NOT .getFunction (),
160+ exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ())));
153161 CelExpr step =
154162 exprFactory .newGlobalCall (
155- Operator .LOGICAL_OR .getFunction (), exprFactory .newIdentifier (ACCUMULATOR_VAR ), arg1 );
156- CelExpr result = exprFactory .newIdentifier (ACCUMULATOR_VAR );
163+ Operator .LOGICAL_OR .getFunction (),
164+ exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ()),
165+ arg1 );
166+ CelExpr result = exprFactory .newIdentifier (exprFactory .getAccumulatorVarName ());
157167 return Optional .of (
158168 exprFactory .fold (
159- arg0 .ident ().name (), target , ACCUMULATOR_VAR , accuInit , condition , step , result ));
169+ arg0 .ident ().name (),
170+ target ,
171+ exprFactory .getAccumulatorVarName (),
172+ accuInit ,
173+ condition ,
174+ step ,
175+ result ));
160176 }
161177
162178 // CelMacroExpander implementation for CEL's exists_one() macro.
@@ -178,17 +194,23 @@ private static Optional<CelExpr> expandExistsOneMacro(
178194 arg1 ,
179195 exprFactory .newGlobalCall (
180196 Operator .ADD .getFunction (),
181- exprFactory .newIdentifier (ACCUMULATOR_VAR ),
197+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ),
182198 exprFactory .newIntLiteral (1 )),
183- exprFactory .newIdentifier (ACCUMULATOR_VAR ));
199+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ));
184200 CelExpr result =
185201 exprFactory .newGlobalCall (
186202 Operator .EQUALS .getFunction (),
187- exprFactory .newIdentifier (ACCUMULATOR_VAR ),
203+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ),
188204 exprFactory .newIntLiteral (1 ));
189205 return Optional .of (
190206 exprFactory .fold (
191- arg0 .ident ().name (), target , ACCUMULATOR_VAR , accuInit , condition , step , result ));
207+ arg0 .ident ().name (),
208+ target ,
209+ exprFactory .getAccumulatorVarName (),
210+ accuInit ,
211+ condition ,
212+ step ,
213+ result ));
192214 }
193215
194216 // CelMacroExpander implementation for CEL's map() macro.
@@ -218,25 +240,25 @@ private static Optional<CelExpr> expandMapMacro(
218240 CelExpr step =
219241 exprFactory .newGlobalCall (
220242 Operator .ADD .getFunction (),
221- exprFactory .newIdentifier (ACCUMULATOR_VAR ),
243+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ),
222244 exprFactory .newList (arg1 ));
223245 if (arg2 != null ) {
224246 step =
225247 exprFactory .newGlobalCall (
226248 Operator .CONDITIONAL .getFunction (),
227249 arg2 ,
228250 step ,
229- exprFactory .newIdentifier (ACCUMULATOR_VAR ));
251+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ));
230252 }
231253 return Optional .of (
232254 exprFactory .fold (
233255 arg0 .ident ().name (),
234256 target ,
235- ACCUMULATOR_VAR ,
257+ exprFactory . getAccumulatorVarName () ,
236258 accuInit ,
237259 condition ,
238260 step ,
239- exprFactory .newIdentifier (ACCUMULATOR_VAR )));
261+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () )));
240262 }
241263
242264 // CelMacroExpander implementation for CEL's filter() macro.
@@ -255,23 +277,23 @@ private static Optional<CelExpr> expandFilterMacro(
255277 CelExpr step =
256278 exprFactory .newGlobalCall (
257279 Operator .ADD .getFunction (),
258- exprFactory .newIdentifier (ACCUMULATOR_VAR ),
280+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ),
259281 exprFactory .newList (arg0 ));
260282 step =
261283 exprFactory .newGlobalCall (
262284 Operator .CONDITIONAL .getFunction (),
263285 arg1 ,
264286 step ,
265- exprFactory .newIdentifier (ACCUMULATOR_VAR ));
287+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () ));
266288 return Optional .of (
267289 exprFactory .fold (
268290 arg0 .ident ().name (),
269291 target ,
270- ACCUMULATOR_VAR ,
292+ exprFactory . getAccumulatorVarName () ,
271293 accuInit ,
272294 condition ,
273295 step ,
274- exprFactory .newIdentifier (ACCUMULATOR_VAR )));
296+ exprFactory .newIdentifier (exprFactory . getAccumulatorVarName () )));
275297 }
276298
277299 private static CelExpr reportArgumentError (CelMacroExprFactory exprFactory , CelExpr argument ) {
0 commit comments