Commit 27ad392a authored by cdanger's avatar cdanger

Fixed regression introduced by previous commit (optimization on multary

numeric operators add and multiply)
parent 5311ba01
......@@ -21,6 +21,7 @@ package org.ow2.authzforce.core.pdp.impl.func;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
......@@ -148,8 +149,11 @@ final class NumericArithmeticFunction<AV extends NumericValue<?, AV>> extends Si
*/
final List<Expression<?>> finalArgExpressions = new ArrayList<>(argExpressions.size());
final Datatype<AV> paramType = this.functionSignature.getParameterType();
for (final Expression<?> argExp : argExpressions)
final Iterator<Expression<?>> argExpIterator = argExpressions.iterator();
int argIndex = 0;
while (argExpIterator.hasNext())
{
final Expression<?> argExp = argExpIterator.next();
final Value v = argExp.getValue();
if (v == null)
{
......@@ -159,8 +163,18 @@ final class NumericArithmeticFunction<AV extends NumericValue<?, AV>> extends Si
else
{
// constant
constants.add(paramType.cast(v));
try
{
constants.add(paramType.cast(v));
}
catch (final ClassCastException e)
{
throw new IllegalArgumentException("Function " + this.functionSignature + ": invalid arg #" + argIndex + ": bad type: " + argExp.getReturnType() + ". Expected type: "
+ paramType, e);
}
}
argIndex += 1;
}
if (constants.size() > 1)
......@@ -168,8 +182,20 @@ final class NumericArithmeticFunction<AV extends NumericValue<?, AV>> extends Si
/*
* we can replace all constant args C1, C2... with one constant C = op(C1, C2...)
*/
LOGGER.warn("Function {}: simplifying args to this commutative function (f): replacing all constant args {} with one that is the constant result of f(constant_args)",
this.functionSignature, constants);
final AV constantResult = op.eval(constants);
LOGGER.warn("Function {}: optimizing call to this commutative function: replacing/merging constant args {} with/into one: {}", this.functionSignature, constants, constantResult);
if (finalArgExpressions.isEmpty())
{
/*
* There aren't any other args, i.e. all are constant. The result is constantResult.
*/
return new ConstantResultFirstOrderFunctionCall<>(constantResult, paramType);
}
/*
* finalArgExpressions is not empty. There is at least one variable arg.
*/
finalArgExpressions.add(new ConstantPrimitiveAttributeValueExpression<>(paramType, constantResult));
return new Call<>(functionSignature, op, finalArgExpressions, remainingArgTypes);
}
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIC014:policy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0" >
<Description>
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIC014:policy"
RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
<Description>
Policy for Conformance Test IIC014.
</Description>
<Target/>
<Rule Effect="Permit" RuleId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIC014:rule">
<Description>
<Target />
<Rule Effect="Permit" RuleId="urn:oasis:names:tc:xacml:2.0:conformance-test:IIC014:rule">
<Description>
A subject who is at least 5 years older than Bart
Simpson may read Bart Simpson's medical record.
</Description>
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:age" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false"/>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:age" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false" />
</Apply>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-add">
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:bart-simpson-age" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false"/>
</Apply>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">5</AttributeValue>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:2.0:conformance-test:bart-simpson-age" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false" />
</Apply>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">5</AttributeValue>
</Apply>
</Apply>
</Condition>
</Rule>
</Apply>
</Condition>
</Rule>
</Policy>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment