Search in sources :

Example 1 with FnCallExpr

use of com.rockwellcollins.atc.resolute.resolute.FnCallExpr in project osate2 by osate.

the class ExecuteResoluteUtil method executeResoluteFunctionOnce.

/**
 * invokes Resolute claim function on targetComponent or targetElement if not null.
 * instanceroot is used to initialize the Resolute evaluation context.
 * targetComponent is the evaluation context
 * targetElement is the model element within the component instance or null.
 * parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
 * parameterObjects can be null or an empty list.
 * The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
 * If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
 */
public Diagnostic executeResoluteFunctionOnce(EObject fundef, final SystemInstance instanceroot, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
    FunctionDefinition fd = (FunctionDefinition) fundef;
    initializeResoluteContext(instanceroot);
    EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
    // check for claim function
    FnCallExpr fcncall = createWrapperFunctionCall(fd, targetComponent, targetElement, parameterObjects);
    if (fcncall != null) {
        // using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
        ResoluteProver prover = new ResoluteProver(context) {

            @Override
            protected ResoluteEvaluator createResoluteEvaluator() {
                return new ResoluteEvaluator(context, varStack.peek()) {

                    @Override
                    public ResoluteValue caseThisExpr(ThisExpr object) {
                        NamedElement curr = context.getThisInstance();
                        if (object.getSub() != null) {
                            curr = object.getSub().getBase();
                        }
                        return new NamedElementValue(curr);
                    }
                };
            }
        };
        ResoluteResult res = prover.doSwitch(fcncall);
        return doResoluteResults(res);
    } else {
        return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
    }
}
Also used : ResoluteEvaluator(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator) ResoluteResult(com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult) NamedElementValue(com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue) FunctionDefinition(com.rockwellcollins.atc.resolute.resolute.FunctionDefinition) EvaluationContext(com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) NamedElement(org.osate.aadl2.NamedElement) ResoluteProver(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr)

Example 2 with FnCallExpr

use of com.rockwellcollins.atc.resolute.resolute.FnCallExpr in project osate2 by osate.

the class ResoluteInterface method createWrapperFunctionCall.

private FnCallExpr createWrapperFunctionCall(FunctionDefinition fd, InstanceObject io, List<PropertyExpression> params) {
    ResoluteFactory factory = ResoluteFactory.eINSTANCE;
    FnCallExpr call = factory.createFnCallExpr();
    call.setFn(fd);
    int fdparams = fd.getArgs().size();
    int aparams = 0;
    if (params != null) {
        aparams = params.size();
    }
    if (fdparams == aparams + 1) {
        call.getArgs().add(createInstanceObjectReference(io));
    }
    if (params != null) {
        addParams(call, params);
    }
    return call;
}
Also used : ResoluteFactory(com.rockwellcollins.atc.resolute.resolute.ResoluteFactory) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr)

Example 3 with FnCallExpr

use of com.rockwellcollins.atc.resolute.resolute.FnCallExpr in project osate2 by osate.

the class ResoluteInterface method addParams.

private void addParams(FnCallExpr call, List<PropertyExpression> params) {
    for (PropertyExpression p : params) {
        if (p instanceof RealLiteral) {
            RealExpr realval = ResoluteFactory.eINSTANCE.createRealExpr();
            realval.setVal((RealLiteral) p);
            call.getArgs().add(realval);
        } else if (p instanceof IntegerLiteral) {
            IntExpr intval = ResoluteFactory.eINSTANCE.createIntExpr();
            intval.setVal((IntegerLiteral) p);
            call.getArgs().add(intval);
        } else if (p instanceof StringLiteral) {
            StringExpr stringval = ResoluteFactory.eINSTANCE.createStringExpr();
            stringval.setVal((StringLiteral) p);
            call.getArgs().add(stringval);
        } else if (p instanceof BooleanLiteral) {
            BoolExpr boolval = ResoluteFactory.eINSTANCE.createBoolExpr();
            boolval.setVal((BooleanLiteral) p);
            call.getArgs().add(boolval);
        } else if (p instanceof InstanceReferenceValue) {
            Expr ref = createInstanceObjectReference(((InstanceReferenceValue) p).getReferencedInstanceObject());
            call.getArgs().add(ref);
        }
    }
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) StringExpr(com.rockwellcollins.atc.resolute.resolute.StringExpr) BoolExpr(com.rockwellcollins.atc.resolute.resolute.BoolExpr) StringLiteral(org.osate.aadl2.StringLiteral) BoolExpr(com.rockwellcollins.atc.resolute.resolute.BoolExpr) Expr(com.rockwellcollins.atc.resolute.resolute.Expr) IntExpr(com.rockwellcollins.atc.resolute.resolute.IntExpr) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) RealExpr(com.rockwellcollins.atc.resolute.resolute.RealExpr) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr) StringExpr(com.rockwellcollins.atc.resolute.resolute.StringExpr) BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) IntExpr(com.rockwellcollins.atc.resolute.resolute.IntExpr) RealExpr(com.rockwellcollins.atc.resolute.resolute.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 4 with FnCallExpr

use of com.rockwellcollins.atc.resolute.resolute.FnCallExpr in project osate2 by osate.

the class ResoluteInterface method executeResoluteFunctionOnce.

/**
 * invokes Resolute claim function on targetComponent or targetElement if not null.
 * instanceroot is used to initialize the Resolute evaluation context.
 * targetComponent is the evaluation context
 * targetElement is the model element within the component instance or null.
 * parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
 * parameterObjects can be null or an empty list.
 * The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
 * If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
 */
public EObject executeResoluteFunctionOnce(EObject fundef, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
    FunctionDefinition fd = (FunctionDefinition) fundef;
    initializeResoluteContext(targetComponent.getSystemInstance());
    EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
    // check for claim function
    FnCallExpr fcncall = createWrapperFunctionCall(fd, targetElement, parameterObjects);
    if (fcncall != null) {
        // if (fcncall.getFn().getBody() instanceof ClaimBody) {
        // using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
        ResoluteProver prover = new ResoluteProver(context) {

            @Override
            protected ResoluteEvaluator createResoluteEvaluator() {
                return new ResoluteEvaluator(context, varStack.peek()) {

                    @Override
                    public ResoluteValue caseThisExpr(ThisExpr object) {
                        // We prepare a thisexpr with either the component instance as context object or a single reference to a model element
                        // See createWrapperFunctionCall
                        NamedElement curr = context.getThisInstance();
                        if (object.getSub() != null) {
                            curr = object.getSub().getBase();
                        }
                        return new NamedElementValue(curr);
                    }
                };
            }
        };
        try {
            ResoluteResult res = prover.doSwitch(fcncall);
            return doResoluteResults(res);
        } catch (ResoluteFailException e) {
            return ResultUtil.createFailureResult(e.getMessage(), targetElement);
        }
    // } else {
    // // computational function
    // ResoluteEvaluator engine = new ResoluteEvaluator(context, null) {
    // @Override
    // public ResoluteValue caseThisExpr(ThisExpr object) {
    // // We prepare a thisexpr with either the component instance as context object or a single reference to a model element
    // // See createWrapperFunctionCall
    // NamedElement curr = context.getThisInstance();
    // if (object.getSub() != null) {
    // curr = object.getSub().getBase();
    // }
    // return new NamedElementValue(curr);
    // }
    // };
    // Object res = engine.doSwitch(fcncall);
    // return null;
    // }
    } else {
        return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
    }
}
Also used : ResoluteEvaluator(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator) ResoluteResult(com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult) NamedElementValue(com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue) FunctionDefinition(com.rockwellcollins.atc.resolute.resolute.FunctionDefinition) ResoluteFailException(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteFailException) EvaluationContext(com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr) NamedElement(org.osate.aadl2.NamedElement) ResoluteProver(com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver) ThisExpr(com.rockwellcollins.atc.resolute.resolute.ThisExpr)

Example 5 with FnCallExpr

use of com.rockwellcollins.atc.resolute.resolute.FnCallExpr in project osate2 by osate.

the class ExecuteResoluteUtil method createWrapperFunctionCall.

private FnCallExpr createWrapperFunctionCall(FunctionDefinition fd, ComponentInstance evalContext, InstanceObject io, List<PropertyExpression> params) {
    ResoluteFactory factory = ResoluteFactory.eINSTANCE;
    FnCallExpr call = factory.createFnCallExpr();
    call.setFn(fd);
    call.getArgs().add(createInstanceObjectReference(evalContext, io));
    if (params != null) {
        addParams(call, params);
    }
    return call;
}
Also used : ResoluteFactory(com.rockwellcollins.atc.resolute.resolute.ResoluteFactory) FnCallExpr(com.rockwellcollins.atc.resolute.resolute.FnCallExpr)

Aggregations

FnCallExpr (com.rockwellcollins.atc.resolute.resolute.FnCallExpr)5 ThisExpr (com.rockwellcollins.atc.resolute.resolute.ThisExpr)3 EvaluationContext (com.rockwellcollins.atc.resolute.analysis.execution.EvaluationContext)2 ResoluteEvaluator (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteEvaluator)2 ResoluteProver (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteProver)2 ResoluteResult (com.rockwellcollins.atc.resolute.analysis.results.ResoluteResult)2 NamedElementValue (com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue)2 FunctionDefinition (com.rockwellcollins.atc.resolute.resolute.FunctionDefinition)2 ResoluteFactory (com.rockwellcollins.atc.resolute.resolute.ResoluteFactory)2 NamedElement (org.osate.aadl2.NamedElement)2 ResoluteFailException (com.rockwellcollins.atc.resolute.analysis.execution.ResoluteFailException)1 BoolExpr (com.rockwellcollins.atc.resolute.resolute.BoolExpr)1 Expr (com.rockwellcollins.atc.resolute.resolute.Expr)1 IntExpr (com.rockwellcollins.atc.resolute.resolute.IntExpr)1 RealExpr (com.rockwellcollins.atc.resolute.resolute.RealExpr)1 StringExpr (com.rockwellcollins.atc.resolute.resolute.StringExpr)1 BooleanLiteral (org.osate.aadl2.BooleanLiteral)1 IntegerLiteral (org.osate.aadl2.IntegerLiteral)1 PropertyExpression (org.osate.aadl2.PropertyExpression)1 RealLiteral (org.osate.aadl2.RealLiteral)1