Package: IsaPogCLI

IsaPogCLI

nameinstructionbranchcomplexitylinemethod
IsaPogCLI()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
main(String[])
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
parseAndCheck(String[], CommandLineParser, CommandLine, Options)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
printUsage(Options)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
process(CommandLine, Options)
M: 120 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 32 C: 0
0%
M: 1 C: 0
0%
validateInput(TypeCheckerUtil.TypeCheckResult)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.isapog;
2:
3: import org.apache.commons.cli.*;
4: import org.overture.ast.analysis.AnalysisException;
5: import org.overture.ast.expressions.PExp;
6: import org.overture.ast.lex.Dialect;
7: import org.overture.ast.modules.AModuleModules;
8: import org.overture.ast.node.INode;
9: import org.overture.codegen.ir.CodeGenBase;
10: import org.overture.codegen.utils.GeneralCodeGenUtils;
11: import org.overture.config.Release;
12: import org.overture.config.Settings;
13: import org.overture.typechecker.util.TypeCheckerUtil;
14: import org.overturetool.cgisa.IsaGen;
15:
16: import java.io.File;
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: /**
21: * Created by ldc on 09/02/16.
22: */
23: public class IsaPogCLI {
24:
25: private static final String GENERATE_BOTH_OPT = "b";
26: private static final String GENERATE_BOTH_LONG_OPT = "model-pos";
27: private static final String GENERATE_BOTH_DESC = "Generate Isabelle theories for model and pos search to same country only.";
28:
29: private static final String PRINT_OPT = "p";
30: private static final String PRINT_LONG_OPT = "print";
31: private static final String PRINT_DESC = "Print output to console instead of generating files.";
32:
33: private static final String EXP_OPT = "e";
34: private static final String EXP_DESC = "blah";
35:
36: private static final String USAGE = "java -jar isapog.jar source1 source2...";
37: public static final String GEN_FOLDER_NAME = "generated";
38:
39:
40: public static void main(final String[] args) {
41: CommandLineParser clp = new DefaultParser();
42: CommandLine cmd = null;
43: Options opts = new Options();
44: opts.addOption(GENERATE_BOTH_OPT, GENERATE_BOTH_LONG_OPT, false, GENERATE_BOTH_DESC);
45: opts.addOption(PRINT_OPT, PRINT_LONG_OPT, false, PRINT_DESC);
46: opts.addOption(EXP_OPT, EXP_DESC);
47:
48: cmd = parseAndCheck(args, clp, cmd, opts);
49:
50: process(cmd, opts);
51:
52: }
53:
54: private static void process(CommandLine cmd, Options opts) {
55: try {
56: // Settings.release= Release.DEFAULT;
57: Settings.dialect = Dialect.VDM_SL;
58:
59:• if (cmd.hasOption(EXP_OPT)) {
60: TypeCheckerUtil.TypeCheckResult<PExp> expResult = TypeCheckerUtil.typeCheckExpression(cmd.getArgList().get(0));
61: validateInput(expResult);
62: System.out.println(IsaGen.vdmExp2IsaString(expResult.result));
63: System.exit(0);
64: }
65: List<String> sources = cmd.getArgList();
66:
67: List<File> files = new ArrayList<>(sources.size());
68:
69:• for (String s : sources) {
70: File f = new File(s);
71:• if (f.exists()) {
72: files.add(new File(s));
73: } else {
74: printUsage(opts);
75: }
76: }
77:
78: TypeCheckerUtil.TypeCheckResult<List<AModuleModules>> result = TypeCheckerUtil.typeCheckSl(files);
79:
80: validateInput(result);
81:
82: List<INode> ast = CodeGenBase.getNodes(result.result);
83:
84: IsaPog ip = new IsaPog(ast);
85:
86: File folder = new File(GEN_FOLDER_NAME);
87: CodeGenBase.emitCode(folder, ip.getModelThyName(), ip.getModelThyString());
88:
89:• if (cmd.hasOption(GENERATE_BOTH_OPT)) {
90: CodeGenBase.emitCode(folder, ip.getPosThyName(), ip.getPosThyString());
91: }
92:
93: } catch (AnalysisException e) {
94: System.err.println("Error processing the model:");
95: System.err.println(e.getMessage());
96: System.exit(1);
97: } catch (org.overture.codegen.ir.analysis.AnalysisException e) {
98: System.err.println("Error generating Isabelle sources:");
99: System.err.println(e.getMessage());
100: System.exit(1);
101: }
102:
103:
104: }
105:
106: private static void validateInput(TypeCheckerUtil.TypeCheckResult<?> result) {
107:• if (GeneralCodeGenUtils.hasErrors(result)) {
108: System.err.println("Found errors in VDM model:");
109: System.err.println(GeneralCodeGenUtils.errorStr(result));
110: System.exit(1);
111: }
112: }
113:
114: private static CommandLine parseAndCheck(String[] args, CommandLineParser clp, CommandLine cmd, Options opts) {
115: try {
116: cmd = clp.parse(opts, args);
117: } catch (ParseException e) {
118: printUsage(opts);
119: }
120:
121:• if (cmd.getArgList().size() < 1) {
122: printUsage(opts);
123: }
124: return cmd;
125: }
126:
127: private static void printUsage(Options opts) {
128: HelpFormatter help = new HelpFormatter();
129: help.printHelp(USAGE, opts);
130: System.exit(1);
131: }
132:
133:
134: }