Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 8a7d7b1

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Redesign SymbolTable handling
The SymbolTable has been moved out from the frontend completely. It is now handled by a new module called SymbolTable, which uses a thread- local variable to avoid passing around the symbol table. This makes the handling of caching SCode much simpler. Some functionality has been removed: - Cached classes in the symbol table (we use the FCache instead) - Instantiated functions (since they were not used before, and -d=gen is not used anyway) - The LoadedFiles list (since the result was ignored anyway) - OpenModelicaInternal.simplify (since the bootstrapping tests can run simplify instead) Other functionality has been moved between frontend and backend files in order to make the interface cleaner. The handling of loadResource has been updated. The locations of resources is now stored in the runtime in order to make the handling of URIs easier to implement for FMI. There are also fixes for e.g. getErrorString and runScript to not generate error-messages during elaboration. This is done by making getErrorString impure, and by making elabCall able to roll back messages that were not at the top of the stack previously. CevalFunction now stops evaluation on fail() like it does for assert(false). The frontend now fails when the function tree is not valid because there seems to be some model(s) that manage to ignore failing to instantiate a function. We now handle assertions triggered in built-in functions that previously printed to stderr by making them write to the Error.mo buffer instead. Belonging to [master]: - #2116 - OpenModelica/OpenModelica-testsuite#829
1 parent 105aad9 commit 8a7d7b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5375
-6736
lines changed

Compiler/BackEnd/EvaluateParameter.mo

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ algorithm
462462
// apply replacements
463463
(e1, _) = BackendVarTransform.replaceExp(e, repl, NONE());
464464
// evaluate expression
465-
(cache, value, _) = Ceval.ceval(cache, graph, e1, false, NONE(), Absyn.NO_MSG(), 0);
465+
(cache, value) = Ceval.ceval(cache, graph, e1, false, Absyn.NO_MSG(), 0);
466466
e1 = ValuesUtil.valueExp(value);
467467
// set bind value
468468
v = BackendVariable.setBindExp(var, SOME(e1));
@@ -495,7 +495,7 @@ algorithm
495495
// apply replacements
496496
(e1, _) = BackendVarTransform.replaceExp(e, repl, NONE());
497497
// evaluate expression
498-
(cache, value, _) = Ceval.ceval(cache, graph, e1, false, NONE(), Absyn.NO_MSG(), 0);
498+
(cache, value) = Ceval.ceval(cache, graph, e1, false, Absyn.NO_MSG(), 0);
499499
e1 = ValuesUtil.valueExp(value);
500500
// set bind value
501501
v = BackendVariable.setBindExp(var, SOME(e1));
@@ -518,7 +518,7 @@ algorithm
518518
// apply replacements
519519
(e1, _) = BackendVarTransform.replaceExp(e, repl, NONE());
520520
// evaluate expression
521-
(cache, value, _) = Ceval.ceval(cache, graph, e1, false, NONE(), Absyn.NO_MSG(), 0);
521+
(cache, value) = Ceval.ceval(cache, graph, e1, false, Absyn.NO_MSG(), 0);
522522
e1 = ValuesUtil.valueExp(value);
523523
// set bind value
524524
v = BackendVariable.setVarStartValue(var, e1);
@@ -567,7 +567,7 @@ algorithm
567567
// applay replacements
568568
(e,_) = BackendVarTransform.replaceExp(e, repl, NONE());
569569
// evaluate expression
570-
(cache, value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(), 0);
570+
(cache, value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(), 0);
571571
e1 = ValuesUtil.valueExp(value);
572572
// also set this var final because it is used for the calculation of another variable
573573
v = BackendVariable.setVarFinal(var, true);
@@ -587,7 +587,7 @@ algorithm
587587
// apply replacements
588588
(e,_) = BackendVarTransform.replaceExp(e, repl, NONE());
589589
// evaluate expression
590-
(cache, value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
590+
(cache, value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
591591
e1 = ValuesUtil.valueExp(value);
592592
// also set this var final because it is used for the calculation of another variable
593593
v = BackendVariable.setVarFinal(var, true);
@@ -836,12 +836,12 @@ algorithm
836836
local DAE.Exp e1;
837837
case(DAE.CALL(expLst=exps)) guard Expression.isConstWorkList(exps)
838838
equation
839-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
839+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
840840
e1 = ValuesUtil.valueExp(value);
841841
then e1;
842842
case(DAE.ASUB(DAE.CALL(expLst=exps),_)) guard Expression.isConstWorkList(exps)
843843
equation
844-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
844+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
845845
e1 = ValuesUtil.valueExp(value);
846846
then e1;
847847
else e;
@@ -881,12 +881,12 @@ algorithm
881881
local DAE.Exp e1;
882882
case(DAE.CALL(expLst=exps)) guard Expression.isConstWorkList(exps)
883883
equation
884-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
884+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
885885
e1 = ValuesUtil.valueExp(value);
886886
then e1;
887887
case(DAE.ASUB(DAE.CALL(expLst=exps),_)) guard Expression.isConstWorkList(exps)
888888
equation
889-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
889+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
890890
e1 = ValuesUtil.valueExp(value);
891891
then e1;
892892
else e;
@@ -918,12 +918,12 @@ algorithm
918918
local DAE.Exp e1;
919919
case(DAE.CALL(expLst=exps)) guard Expression.isConstWorkList(exps)
920920
equation
921-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
921+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
922922
e1 = ValuesUtil.valueExp(value);
923923
then e1;
924924
case(DAE.ASUB(DAE.CALL(expLst=exps),_)) guard Expression.isConstWorkList(exps)
925925
equation
926-
(_,value,_) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
926+
(_,value) = Ceval.ceval(cache, graph, e, false, Absyn.NO_MSG(),0);
927927
e1 = ValuesUtil.valueExp(value);
928928
then e1;
929929
else e;

Compiler/BackEnd/OpenTURNS.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ import ComponentReference;
5757
import DAEUtil;
5858
import Expression;
5959
import ExpressionDump;
60-
import GlobalScript;
61-
import GlobalScriptUtil;
60+
import SymbolTable;
6261
import List;
6362
import Settings;
6463
import SimCode;
@@ -95,7 +94,7 @@ algorithm
9594

9695
simSettings := CevalScriptBackend.convertSimulationOptionsToSimCode(
9796
CevalScriptBackend.buildSimulationOptionsFromModelExperimentAnnotation(
98-
GlobalScriptUtil.setSymbolTableAST(GlobalScript.emptySymboltable,inProgram),inPath,fileNamePrefix,NONE())
97+
inPath,fileNamePrefix,NONE())
9998
);
10099
// correlation matrix form (vector of records) currently not supported by OpenModelica backend, remove it .
101100
//print("enter dae:");

Compiler/BackEnd/Uncertainties.mo

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import Print;
7070
import SCode;
7171
import SCodeUtil;
7272
import Sorting;
73+
import SymbolTable;
7374
import System;
7475
import Util;
7576

@@ -90,16 +91,14 @@ public function modelEquationsUC
9091
input FCore.Cache inCache;
9192
input FCore.Graph inEnv;
9293
input Absyn.Path className "path for the model";
93-
input GlobalScript.SymbolTable inInteractiveSymbolTable;
9494
input String outputFileIn;
9595
input Boolean dumpSteps;
9696
output FCore.Cache outCache;
9797
output Values.Value outValue;
98-
output GlobalScript.SymbolTable outInteractiveSymbolTable;
9998

10099
algorithm
101-
(outCache,outValue,outInteractiveSymbolTable):=
102-
matchcontinue (inCache,inEnv,className,inInteractiveSymbolTable,outputFileIn,dumpSteps)
100+
(outCache,outValue):=
101+
matchcontinue (inCache,inEnv,className,outputFileIn,dumpSteps)
103102
local
104103
String outputFile,resstr;
105104

@@ -109,7 +108,6 @@ algorithm
109108
Absyn.Program p;
110109

111110
BackendDAE.BackendDAE dlow,dlow_1;
112-
GlobalScript.SymbolTable st;
113111

114112
BackendDAE.IncidenceMatrix m,mt;
115113

@@ -134,10 +132,11 @@ algorithm
134132

135133
Boolean forceOrdering = Flags.getConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING);
136134

137-
case (cache,graph,_,(st as GlobalScript.SYMBOLTABLE(ast = p)),outputFile,_)
135+
case (cache,graph,_,outputFile,_)
138136
equation
139137
//print("Initiating\n");
140138
Print.clearBuf();
139+
p = SymbolTable.getAbsyn();
141140

142141
(dae,cache,graph) = flattenModel(className,p,cache);
143142
description = DAEUtil.daeDescription(dae);
@@ -284,8 +283,8 @@ algorithm
284283
resstr=writeFileIfNonEmpty(outputFile,outString);
285284
//resstr="Done...";
286285
then
287-
(cache,Values.STRING(resstr),st);
288-
case (_,_,_,_,outputFile,_)
286+
(cache,Values.STRING(resstr));
287+
case (_,_,_,outputFile,_)
289288
equation
290289
Print.printBuf("{"+getMathematicaText("Extraction failed")+"}");
291290
outStringA = "Grid[{"+Print.getString()+"}]";

Compiler/FFrontEnd/FCore.mo

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ public uniontype Cache
412412
Mutable<DAE.FunctionTree> functions "set of Option<DAE.Function>; NONE() means instantiation started; SOME() means it's finished";
413413
StructuralParameters evaluatedParams "ht of prefixed crefs and a stack of evaluated but not yet prefix crefs";
414414
Absyn.Path modelName "name of the model being instantiated";
415-
Absyn.Program program "send the program around if we don't have a symbol table";
416415
end CACHE;
417416

418417
record NO_CACHE "no cache" end NO_CACHE;
@@ -443,7 +442,7 @@ protected
443442
algorithm
444443
instFuncs := Mutable.create(DAE.AvlTreePathFunction.Tree.EMPTY());
445444
ht := (AvlSetCR.EMPTY(),{});
446-
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"),Absyn.dummyProgram);
445+
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"));
447446
end emptyCache;
448447

449448

@@ -467,13 +466,12 @@ algorithm
467466
list<list<DAE.ComponentRef>> st;
468467
list<DAE.ComponentRef> crs;
469468
Absyn.Path p;
470-
Absyn.Program program;
471469

472-
case (CACHE(initialGraph,functions,(ht,crs::st),p,program),SCode.PARAM(),_)
473-
then CACHE(initialGraph,functions,(ht,(cr::crs)::st),p,program);
470+
case (CACHE(initialGraph,functions,(ht,crs::st),p),SCode.PARAM(),_)
471+
then CACHE(initialGraph,functions,(ht,(cr::crs)::st),p);
474472

475-
case (CACHE(initialGraph,functions,(ht,{}),p,program),SCode.PARAM(),_)
476-
then CACHE(initialGraph,functions,(ht,{cr}::{}),p,program);
473+
case (CACHE(initialGraph,functions,(ht,{}),p),SCode.PARAM(),_)
474+
then CACHE(initialGraph,functions,(ht,{cr}::{}),p);
477475

478476
else cache;
479477

@@ -506,10 +504,9 @@ algorithm
506504
Mutable<DAE.FunctionTree> ef;
507505
StructuralParameters ht;
508506
Option<Graph> igraph;
509-
Absyn.Program program;
510507

511-
case (CACHE(igraph,ef,ht,_,program),_)
512-
then CACHE(igraph,ef,ht,p,program);
508+
case (CACHE(igraph,ef,ht,_),_)
509+
then CACHE(igraph,ef,ht,p);
513510
else inCache;
514511
end match;
515512
end setCacheClassName;
@@ -586,7 +583,6 @@ algorithm
586583
Option<Graph> igraph;
587584
StructuralParameters ht;
588585
Absyn.Path p;
589-
Absyn.Program program;
590586

591587
// Don't overwrite SOME() with NONE()
592588
case (_, _)
@@ -595,7 +591,7 @@ algorithm
595591
// print("Func quard [there]: " + Absyn.pathString(func) + "\n");
596592
then cache;
597593

598-
case (CACHE(_,ef,_,_,_),Absyn.FULLYQUALIFIED(_))
594+
case (CACHE(functions=ef),Absyn.FULLYQUALIFIED(_))
599595
equation
600596
Mutable.update(ef,DAE.AvlTreePathFunction.add(Mutable.access(ef),func,NONE()));
601597
// print("Func quard [new]: " + Absyn.pathString(func) + "\n");
@@ -622,9 +618,8 @@ algorithm
622618
Option<Graph> igraph;
623619
StructuralParameters ht;
624620
Absyn.Path p;
625-
Absyn.Program program;
626621

627-
case (CACHE(_,ef,_,_,_),_)
622+
case (CACHE(_,ef,_,_),_)
628623
equation
629624
Mutable.update(ef,DAEUtil.addDaeFunction(funcs, Mutable.access(ef)));
630625
then inCache;
@@ -645,9 +640,8 @@ algorithm
645640
Option<Graph> igraph;
646641
StructuralParameters ht;
647642
Absyn.Path p;
648-
Absyn.Program program;
649643

650-
case (CACHE(_,ef,_,_,_),_)
644+
case (CACHE(_,ef,_,_),_)
651645
equation
652646
Mutable.update(ef,DAEUtil.addDaeExtFunction(funcs, Mutable.access(ef)));
653647
then inCache;
@@ -656,33 +650,6 @@ algorithm
656650
end match;
657651
end addDaeExtFunction;
658652

659-
public function getProgramFromCache
660-
input Cache inCache;
661-
output Absyn.Program program;
662-
algorithm
663-
program := match(inCache)
664-
case NO_CACHE() then Absyn.dummyProgram;
665-
case CACHE(program = program) then program;
666-
end match;
667-
end getProgramFromCache;
668-
669-
public function setProgramInCache
670-
input Cache inCache;
671-
input Absyn.Program program;
672-
output Cache outCache;
673-
algorithm
674-
outCache := match(inCache,program)
675-
local
676-
Mutable<DAE.FunctionTree> ef;
677-
StructuralParameters ht;
678-
Absyn.Path p;
679-
Option<Graph> ograph;
680-
681-
case (CACHE(ograph,ef,ht,p,_),_) then CACHE(ograph,ef,ht,p,program);
682-
else inCache;
683-
end match;
684-
end setProgramInCache;
685-
686653
public function setCachedFunctionTree
687654
input Cache inCache;
688655
input DAE.FunctionTree inFunctions;
@@ -735,11 +702,6 @@ public function setCachedInitialGraph "set the initial environment in the cache"
735702
input Graph g;
736703
algorithm
737704
cache := match cache
738-
local
739-
Mutable<DAE.FunctionTree> ef;
740-
StructuralParameters ht;
741-
Absyn.Path p;
742-
Absyn.Program program;
743705

744706
case CACHE()
745707
algorithm

Compiler/FrontEnd/Absyn.mo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,20 @@ function pathStringDefault
27382738
output String s = pathString(path);
27392739
end pathStringDefault;
27402740

2741+
public function classNameCompare
2742+
input Class c1,c2;
2743+
output Integer o;
2744+
algorithm
2745+
o := stringCompare(c1.name, c2.name);
2746+
end classNameCompare;
2747+
2748+
public function classNameGreater
2749+
input Class c1,c2;
2750+
output Boolean b;
2751+
algorithm
2752+
b := stringCompare(c1.name, c2.name) > 0;
2753+
end classNameGreater;
2754+
27412755
public function pathCompare
27422756
input Path ip1;
27432757
input Path ip2;

0 commit comments

Comments
 (0)