diff --git a/src/main/java/crml/compiler/CRMLC.java b/src/main/java/crml/compiler/CRMLC.java index b9d5fe5..881576d 100644 --- a/src/main/java/crml/compiler/CRMLC.java +++ b/src/main/java/crml/compiler/CRMLC.java @@ -105,7 +105,7 @@ public static void main( String[] args ) throws Exception { if(test.endsWith(".crml")) { logger.trace("Translating test: " + test); parse_file(path, test, cmd.outputDir, cmd.stacktrace, cmd.printAST , - cmd.generateExternal, cmd.within); + cmd.generateExternal, cmd.within, cmd.causal); if(cmd.simulate!=null) { OMCmsg msg; try { @@ -125,7 +125,7 @@ public static void main( String[] args ) throws Exception { String stripped_file_name = Utilities.stripNameEndingAndPath(path); String outputDir = Utilities.addDirToPath(cmd.outputDir, stripped_file_name); parse_file("", path, outputDir, cmd.stacktrace, - cmd.printAST, cmd.generateExternal, cmd.within); + cmd.printAST, cmd.generateExternal, cmd.within, cmd.causal); if(cmd.simulate!=null){ OMCmsg msg; try { @@ -148,7 +148,8 @@ public static void parse_file ( String dir, String file, String gen_dir, Boolean testMode, Boolean printAST, Boolean generateExternal, - String within) throws Exception { + String within, + Boolean causal) throws Exception { try { String fullName = dir + java.io.File.separator + file; @@ -175,9 +176,9 @@ public static void parse_file ( if (generateExternal) - visitor = new crmlVisitorImpl(parser, external_var); + visitor = new crmlVisitorImpl(parser, external_var, causal); else - visitor = new crmlVisitorImpl(parser); + visitor = new crmlVisitorImpl(parser, causal); try { Value result = visitor.visit(tree); @@ -190,6 +191,7 @@ public static void parse_file ( out_file.getParentFile().mkdirs(); BufferedWriter writer = new BufferedWriter(new FileWriter(out_file)); + System.out.println("File : " + out_file.toString() + " within : " + within); if(!within.isEmpty()) writer.write("within " + within + ";\n"); writer.write(result.contents); diff --git a/src/main/java/crml/compiler/CommandLineArgs.java b/src/main/java/crml/compiler/CommandLineArgs.java index 957eec8..06c88ab 100644 --- a/src/main/java/crml/compiler/CommandLineArgs.java +++ b/src/main/java/crml/compiler/CommandLineArgs.java @@ -41,4 +41,7 @@ public class CommandLineArgs { @Parameter(names = "--within", description = "generate the translated modelica model within a given class") public String within = ""; + + @Parameter(names = {"-causal"}, description = "Generates explicit input prefixes in helper blocks") + public Boolean causal = false; } diff --git a/src/main/java/crml/compiler/crmlVisitorImpl.java b/src/main/java/crml/compiler/crmlVisitorImpl.java index c829615..bbebe0b 100644 --- a/src/main/java/crml/compiler/crmlVisitorImpl.java +++ b/src/main/java/crml/compiler/crmlVisitorImpl.java @@ -45,21 +45,32 @@ public class crmlVisitorImpl extends crmlBaseVisitor { private String prefix= ""; //to keep track of variable prefix + private String input_prefix; + private String output_prefix; + Boolean saveExtrnal = false; List external_variables; - public crmlVisitorImpl (crmlParser parser, List external_variables){ - this(parser); + public crmlVisitorImpl (crmlParser parser, List external_variables, Boolean causal){ + this(parser, causal); saveExtrnal= true; this.external_variables = external_variables; } - public crmlVisitorImpl (crmlParser parser) { + public crmlVisitorImpl (crmlParser parser, Boolean causal) { // FIXME check that class name and class file match this.parser = parser; + if (causal) { + input_prefix = "input"; + output_prefix = "output"; + } else { + input_prefix = ""; + output_prefix = ""; + }; + types_mapping = new HashMap(); // table for mapping CRML built in types to Modelica types @@ -292,7 +303,7 @@ else if (ctx.uninstantiated_def()!=null) sig.function_name = modelName.toString(); String mtype = bType; - definition.append("output " + bType + " out; \n"); + definition.append(output_prefix + bType + " out; \n"); // generate variables @@ -301,7 +312,7 @@ else if (ctx.uninstantiated_def()!=null) String type = ctx.operator_def().type().get(i).getText(); mtype = types_mapping.get(type); if(mtype == null) mtype = type; - definition.append("input " + mtype + " " + v.getText() + ";\n"); + definition.append(input_prefix + mtype + " " + v.getText() + ";\n"); // TODO fix set support variableTable.putlocalVariable(v.getText(), type, false); @@ -370,7 +381,7 @@ else if (ctx.uninstantiated_def()!=null) // generate variables for (IdContext v : ctx.id()) { - definition.append("input " + bType + " " + v.getText() + ";\n"); + definition.append(input_prefix + bType + " " + v.getText() + ";\n"); // TODO fix sets variableTable.putlocalVariable(v.getText(), "Boolean", false); @@ -381,7 +392,7 @@ else if (ctx.uninstantiated_def()!=null) user_operators.put(modelName.toString(), sig); - definition.append("output " + bType + " out; \n"); + definition.append(output_prefix + bType + " out; \n"); // append body Value exp = visit(ctx.exp()); diff --git a/src/test/java/ctests/Util.java b/src/test/java/ctests/Util.java index d6f04ca..37746d1 100644 --- a/src/test/java/ctests/Util.java +++ b/src/test/java/ctests/Util.java @@ -36,7 +36,7 @@ static OMCmsg runTest( final String fileName, try { crml.compiler.CRMLC.parse_file(cs.testFolderIn, fileName, out_dir, - true, false, true, stripped_file_name); + true, false, true, stripped_file_name, false); } catch (Exception e) { fail("Unable to translate " + fileName + " to Modelica\n", e); diff --git a/src/test/resources/verificationModels/libraries/ETL_test/BecomesFalse/BecomesFalse_verif.mo b/src/test/resources/verificationModels/libraries/ETL_test/BecomesFalse/BecomesFalse_verif.mo index fc678fe..c9790a6 100644 --- a/src/test/resources/verificationModels/libraries/ETL_test/BecomesFalse/BecomesFalse_verif.mo +++ b/src/test/resources/verificationModels/libraries/ETL_test/BecomesFalse/BecomesFalse_verif.mo @@ -1,4 +1,4 @@ -within ; +within BecomesFalse; model BecomesFalse_verif extends BecomesFalse; BecomesFalse_externals externals diff --git a/src/test/resources/verificationModels/libraries/ETL_test/BecomesTrue/BecomesTrue_verif.mo b/src/test/resources/verificationModels/libraries/ETL_test/BecomesTrue/BecomesTrue_verif.mo index 6ba447f..7c50e74 100644 --- a/src/test/resources/verificationModels/libraries/ETL_test/BecomesTrue/BecomesTrue_verif.mo +++ b/src/test/resources/verificationModels/libraries/ETL_test/BecomesTrue/BecomesTrue_verif.mo @@ -1,4 +1,4 @@ -within ; +within BecomesTrue; model BecomesTrue_verif extends BecomesTrue; BecomesTrue_externals externals