Search in sources :

Example 31 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class AgreeUtils method getLustreTypes.

public static List<TypeDef> getLustreTypes(AgreeProgram agreeProgram) {
    List<TypeDef> types = new ArrayList<>();
    for (Type type : agreeProgram.globalTypes) {
        String typeName;
        if (type instanceof RecordType) {
            typeName = ((RecordType) type).id;
        } else if (type instanceof EnumType) {
            typeName = ((EnumType) type).id;
        } else {
            throw new AgreeException("Unable to handle type of type '" + type.getClass() + "'");
        }
        types.add(new TypeDef(typeName, type));
    }
    // add synonym types
    types.addAll(getTypeSynonmyms());
    return types;
}
Also used : RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ComponentType(org.osate.aadl2.ComponentType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) TypeDef(jkind.lustre.TypeDef) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ArrayList(java.util.ArrayList)

Example 32 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class SaveHandler method doAnalysis.

protected IStatus doAnalysis(final IProgressMonitor monitor) {
    Thread analysisThread = new Thread() {

        String filePath;

        TestSuiteView view;

        @Override
        public void run() {
            activateTerminateHandler(monitor);
            Shell activeShell = getWindow().getShell();
            System.out.println("Saving test suite...");
            syncExec(() -> {
                view = (TestSuiteView) getWindow().getActivePage().findView(TestSuiteView.ID);
            });
            if (view != null) {
                TestSuite suite = view.getInput();
                if (suite != null) {
                    System.out.println("Bringing up file dialog...");
                    syncExec(() -> {
                        FileDialog dialog = new FileDialog(activeShell, SWT.SAVE);
                        if (startingFilePath != null) {
                            dialog.setFileName(startingFilePath);
                        }
                        String[] filterNames = new String[] { "XML Files", "All Files (*)" };
                        String[] filterExtensions = new String[] { "*.xml", "*" };
                        dialog.setFilterNames(filterNames);
                        dialog.setFilterExtensions(filterExtensions);
                        dialog.setOverwrite(true);
                        filePath = dialog.open();
                    });
                    if (filePath != null) {
                        startingFilePath = filePath;
                        System.out.println("filePath: " + filePath);
                        TestSuiteLinker linker = (TestSuiteLinker) view.getMenuListener().getLinker();
                        AnalysisResult result = view.getMenuListener().getAnalysisResult();
                        List<Type> types = linker.getAgreeProgram(result).globalTypes;
                        try {
                            TcgXmlWriter tcgXmlWriter = new TcgXmlWriter(filePath, types, false);
                            tcgXmlWriter.writeSuite(suite);
                            System.out.println("This would be where test suite written to " + filePath);
                        } catch (FileNotFoundException fnfe) {
                            fnfe.printStackTrace();
                        }
                    // TcgXmlWriter consoleWriter = new TcgXmlWriter(null, null, true);
                    // consoleWriter.writeSuite(suite);
                    }
                } else {
                    syncExec(() -> {
                        MessageBox mb = new MessageBox(activeShell);
                        mb.setMessage("Error: no test suite loaded.  Please open a test suite\n");
                        mb.open();
                    });
                }
            } else {
                syncExec(() -> {
                    MessageBox mb = new MessageBox(activeShell);
                    mb.setMessage("Error: test suite view needs to be active in order to save.\n");
                    mb.open();
                });
            }
            deactivateTerminateHandler();
        }
    };
    analysisThread.start();
    return Status.OK_STATUS;
}
Also used : TestSuiteView(com.rockwellcollins.atc.tcg.views.TestSuiteView) TestSuiteLinker(com.rockwellcollins.atc.tcg.views.TestSuiteLinker) FileNotFoundException(java.io.FileNotFoundException) AnalysisResult(jkind.api.results.AnalysisResult) TcgXmlWriter(com.rockwellcollins.atc.tcg.writers.TcgXmlWriter) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) Type(jkind.lustre.Type) TestSuite(com.rockwellcollins.atc.tcg.suite.TestSuite) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 33 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class GenerateUfcObligationsVisitor method addBoundaryValueTests.

// /////////////////////////////////////////////////////////////////////////
// 
// Note: this is not really correct; we want a value that is *less than or equal to*
// the boundary distance, not *exactly* at the boundary distance.  For integers with
// delta 1, it is the same, but it should be fixed for floating point numbers.  Note
// also that to write these tests, we need to introduce additional inputs to
// represent the deltas.
// 
// /////////////////////////////////////////////////////////////////////////
protected void addBoundaryValueTests(Expr e, ObligationSet s) {
    if (e instanceof BinaryExpr && this.generateBoundaryValueTests) {
        Expr rightDelta = null;
        BinaryExpr be = (BinaryExpr) e;
        if (be.op == BinaryOp.EQUAL || be.op == BinaryOp.GREATER || be.op == BinaryOp.GREATEREQUAL || be.op == BinaryOp.LESS || be.op == BinaryOp.LESSEQUAL) {
            Type t = getType(be.left);
            if (t == NamedType.INT) {
                rightDelta = new IntExpr(BigInteger.valueOf(this.intDelta));
            } else if (t == NamedType.REAL) {
                rightDelta = new RealExpr(BigDecimal.valueOf(this.realDelta));
            }
            // Add tests at the boundary.
            if (rightDelta != null) {
                s.add(new BinaryExpr(be.left, BinaryOp.EQUAL, new BinaryExpr(be.right, BinaryOp.PLUS, rightDelta)));
                s.add(new BinaryExpr(be.left, BinaryOp.EQUAL, rightDelta));
                s.add(new BinaryExpr(be.left, BinaryOp.EQUAL, new BinaryExpr(be.right, BinaryOp.MINUS, rightDelta)));
            }
        }
    }
}
Also used : Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) RecordExpr(jkind.lustre.RecordExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayExpr(jkind.lustre.ArrayExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) IntExpr(jkind.lustre.IntExpr) RealExpr(jkind.lustre.RealExpr)

Aggregations

Type (jkind.lustre.Type)33 NamedType (jkind.lustre.NamedType)29 RecordType (jkind.lustre.RecordType)16 ArrayList (java.util.ArrayList)12 Expr (jkind.lustre.Expr)12 IdExpr (jkind.lustre.IdExpr)11 RecordAccessExpr (jkind.lustre.RecordAccessExpr)11 ConnectionType (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType)10 ComponentType (org.osate.aadl2.ComponentType)10 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)8 NodeCallExpr (jkind.lustre.NodeCallExpr)8 VarDecl (jkind.lustre.VarDecl)8 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)8 FeatureGroupType (org.osate.aadl2.FeatureGroupType)8 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 IntExpr (jkind.lustre.IntExpr)7 UnaryExpr (jkind.lustre.UnaryExpr)7 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)6