Skip to content

Commit

Permalink
Clean up Interactive/InteractiveUtil.
Browse files Browse the repository at this point in the history
- Move utility functions from Interactive to InteractiveUtil and remove
  ~8 KLOC of duplicated code.
  • Loading branch information
perost committed Nov 17, 2020
1 parent aab0aff commit 467f446
Show file tree
Hide file tree
Showing 19 changed files with 4,398 additions and 19,133 deletions.
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/Main/Main.mo
Expand Up @@ -71,6 +71,7 @@ import GC;
import Global;
import GlobalScript;
import Interactive;
import InteractiveUtil;
import List;
import Parser;
import Print;
Expand Down Expand Up @@ -191,8 +192,8 @@ algorithm
table = SymbolTable.get();
ast = table.ast;
vars = table.vars;
prog2 = Interactive.addScope(prog, vars);
prog2 = Interactive.updateProgram(prog2, ast);
prog2 = InteractiveUtil.addScope(prog, vars);
prog2 = InteractiveUtil.updateProgram(prog2, ast);
if Flags.isSet(Flags.DUMP) then
Debug.trace("\n--------------- Parsed program ---------------\n");
Dump.dump(prog2);
Expand Down Expand Up @@ -355,7 +356,7 @@ algorithm
equation
pnew = Parser.parse(inLib, "UTF-8");
p = SymbolTable.getAbsyn();
pnew = Interactive.mergeProgram(pnew, p);
pnew = InteractiveUtil.mergeProgram(pnew, p);
SymbolTable.setAbsyn(pnew);
then ();

Expand Down
24 changes: 12 additions & 12 deletions OMCompiler/Compiler/Script/Binding.mo
Expand Up @@ -8,7 +8,7 @@ public import SCodeDump;
public import Dump;

protected import AbsynToSCode;
protected import Interactive;
protected import InteractiveUtil;
protected import Parser;
protected import GlobalScript;
protected import System;
Expand Down Expand Up @@ -77,14 +77,14 @@ protected
list<SCode.Element> scode_def;
list<Client_e> client_list;
algorithm
model_def := Interactive.getPathedClassInProgram(model_path, env);
model_def := InteractiveUtil.getPathedClassInProgram(model_path, env);
scode_def := AbsynToSCode.translateAbsyn2SCode(env);
// print(SCodeDump.programStr(scode_def));
ms := getMediatorDefsElements(scode_def, {});
client_list := buildInstList(model_def, env, NO_PRED(), ms, {}, {});
out_vmodel := inferBindingClientList(client_list, model_def, env);
print(Dump.unparseClassStr(out_vmodel) + "\n");
out_model_def := Interactive.updateProgram(Absyn.PROGRAM({out_vmodel}, Interactive.buildWithin(model_path)), env);
out_model_def := InteractiveUtil.updateProgram(Absyn.PROGRAM({out_vmodel}, InteractiveUtil.buildWithin(model_path)), env);
end inferBindings;

public function generateVerificationScenarios "@autor lenab : root function called from API "
Expand All @@ -111,7 +111,7 @@ algorithm
scenarios := getAllElementsOfType(scode_def, "VVDRlib.Verification.Scenario", "", {});
// get mediators
ms := getMediatorDefsElements(scode_def, {});
package_def := Interactive.getPathedClassInProgram(package_path, in_env);
package_def := InteractiveUtil.getPathedClassInProgram(package_path, in_env);
autogen_model_list := {};
i:=0;
for s in scenarios loop
Expand All @@ -138,7 +138,7 @@ algorithm
end for;
out_vmodel := updatePackage(package_def, autogen_model_list);
print("******** Autogenerated classes: \n"+ Dump.unparseClassStr(out_vmodel) + "\n");
out_env := Interactive.updateProgram(Absyn.PROGRAM({out_vmodel}, Interactive.buildWithin(package_path)), in_env);
out_env := InteractiveUtil.updateProgram(Absyn.PROGRAM({out_vmodel}, InteractiveUtil.buildWithin(package_path)), in_env);
end generateVerificationScenarios;

public function updatePackage
Expand Down Expand Up @@ -538,7 +538,7 @@ algorithm
algorithm
_ := AbsynUtil.typeSpecPath(typeSpec);
//print ("**** Finding clients ... " + Dump.unparseTypeSpec(typeSpec) + " + " +Dump.unparseTypeSpec(tSpec)+ " + "+Dump.unparseTypeSpec(rootType) + "... \n");
//if Interactive.isPrimitive(AbsynUtil.pathToCref(path), defs) then fail(); end if;
//if InteractiveUtil.isPrimitive(AbsynUtil.pathToCref(path), defs) then fail(); end if;
// TODO: add generation error for is mandatory
if ((AbsynUtil.typeSpecPathString(rootType) == AbsynUtil.typeSpecPathString(tSpec)) and not(listEmpty(exp2))) then
print("... found instance provider " + Dump.unparseTypeSpec(tSpec) + "\n");
Expand Down Expand Up @@ -1058,8 +1058,8 @@ algorithm
//print(Dump.unparseTypeSpec(typeSpec));
//print(" VS " +className);
//print ("... \n");
// if Interactive.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := Interactive.getPathedClassInProgram(path,env); // load the element
// if InteractiveUtil.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := InteractiveUtil.getPathedClassInProgram(path,env); // load the element
if (AbsynUtil.typeSpecPathString(typeSpec) == className) then
print("... found provider " + className + "\n");
cnew := (components, pathInClass)::in_components;
Expand Down Expand Up @@ -1200,8 +1200,8 @@ algorithm
//print(Dump.unparseTypeSpec(typeSpec));
//print ("... \n");

//if Interactive.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := Interactive.getPathedClassInProgram(path, env); // load the element
//if InteractiveUtil.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := InteractiveUtil.getPathedClassInProgram(path, env); // load the element

(isCl, iname, m) := isClient(AbsynUtil.typeSpecPathString(typeSpec), mediators, {});
// TODO: check if it was not already added to the list
Expand Down Expand Up @@ -1268,8 +1268,8 @@ algorithm
//print ("TESTING in parseElementList ... ");
//print(Dump.unparseTypeSpec(typeSpec));
//print ("... \n");
//if Interactive.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := Interactive.getPathedClassInProgram(path, env); // load the element
//if InteractiveUtil.isPrimitive(AbsynUtil.pathToCref(path), env) then fail(); end if;
def := InteractiveUtil.getPathedClassInProgram(path, env); // load the element
(isCl, iname, m) := isClient(AbsynUtil.typeSpecPathString(typeSpec), mediators, {});
// TODO: check if it was not already added to the list
if(isCl) then
Expand Down

0 comments on commit 467f446

Please sign in to comment.