Skip to content

Commit

Permalink
Moved around SCodeUtil
Browse files Browse the repository at this point in the history
SCodeUtil was renamed AbsynToSCode and functions from SCode moved
to a new SCodeUtil package.
  • Loading branch information
sjoelund committed Jul 26, 2019
1 parent d9901af commit 21757d3
Show file tree
Hide file tree
Showing 66 changed files with 8,618 additions and 8,522 deletions.
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -108,6 +108,7 @@ import OnRelaxation;
import RemoveSimpleEquations;
import ResolveLoops;
import SCode;
import SCodeUtil;
import Sorting;
import StackOverflow;
import SymbolicImplicitSolver;
Expand Down Expand Up @@ -1145,7 +1146,7 @@ protected
algorithm
try
SOME(SCode.COMMENT(annotation_=SOME(ann))) := comment;
val := SCode.getNamedAnnotation(ann, "tearingSelect");
val := SCodeUtil.getNamedAnnotation(ann, "tearingSelect");
ts_str := AbsynUtil.crefIdent(AbsynUtil.expCref(val));
ts := match(ts_str)
case "always" then SOME(BackendDAE.ALWAYS());
Expand Down Expand Up @@ -1176,7 +1177,7 @@ protected
algorithm
try
SOME(SCode.COMMENT(annotation_=SOME(ann))) := comment;
val := SCode.getNamedAnnotation(ann, "HideResult");
val := SCodeUtil.getNamedAnnotation(ann, "HideResult");
hideResult := Expression.fromAbsynExp(val);

hideResult := match(inCref)
Expand Down
21 changes: 11 additions & 10 deletions OMCompiler/Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -63,6 +63,7 @@ import HashSet;
import List;
import MetaModelica.Dangerous;
import Mutable;
import SCodeUtil;
import StringUtil;
import System;
import Types;
Expand Down Expand Up @@ -1296,7 +1297,7 @@ algorithm
local SCode.Comment comm;

case (BackendDAE.VAR(comment=SOME(comm) ))
then SCode.commentHasBooleanNamedAnnotation(comm, "isMayer");
then SCodeUtil.commentHasBooleanNamedAnnotation(comm, "isMayer");
else false;
end match;
end hasMayerTermAnno;
Expand All @@ -1311,7 +1312,7 @@ algorithm
local SCode.Comment comm;

case (BackendDAE.VAR(comment=SOME(comm) ))
then SCode.commentHasBooleanNamedAnnotation(comm, "isLagrange");
then SCodeUtil.commentHasBooleanNamedAnnotation(comm, "isLagrange");
else false;
end match;
end hasLagrangeTermAnno;
Expand All @@ -1326,7 +1327,7 @@ algorithm
local SCode.Comment comm;

case (BackendDAE.VAR(comment=SOME(comm) ))
then SCode.commentHasBooleanNamedAnnotation(comm, "isConstraint");
then SCodeUtil.commentHasBooleanNamedAnnotation(comm, "isConstraint");
else false;
end match;
end hasConTermAnno;
Expand All @@ -1341,7 +1342,7 @@ algorithm
local SCode.Comment comm;

case (BackendDAE.VAR(comment=SOME(comm) ))
then SCode.commentHasBooleanNamedAnnotation(comm, "isFinalConstraint");
then SCodeUtil.commentHasBooleanNamedAnnotation(comm, "isFinalConstraint");
else false;
end match;
end hasFinalConTermAnno;
Expand All @@ -1356,7 +1357,7 @@ algorithm
local SCode.Comment comm;

case (BackendDAE.VAR(comment=SOME(comm) ))
then SCode.commentHasBooleanNamedAnnotation(comm, "isTimeGrid");
then SCodeUtil.commentHasBooleanNamedAnnotation(comm, "isTimeGrid");
else false;
end match;
end hasTimeGridAnno;
Expand Down Expand Up @@ -1419,7 +1420,7 @@ protected
algorithm
try
BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(anno)))) := v;
val := SCode.getNamedAnnotation(anno, "HideResult");
val := SCodeUtil.getNamedAnnotation(anno, "HideResult");
hidden := match(val)
case Absyn.BOOL(true) then true;
else false;
Expand Down Expand Up @@ -1466,7 +1467,7 @@ algorithm
SCode.Annotation anno;
// Parameter with evaluate annotation
case BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(anno))))
then SCode.hasBooleanNamedAnnotation(anno,"Evaluate");
then SCodeUtil.hasBooleanNamedAnnotation(anno,"Evaluate");
else false;
end match;
end hasVarEvaluateAnnotation;
Expand All @@ -1481,7 +1482,7 @@ protected
algorithm
try
BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(ann)))) := inVar;
(val,_) := SCode.getNamedAnnotation(ann, "Evaluate");
(val,_) := SCodeUtil.getNamedAnnotation(ann, "Evaluate");
isTrue := stringEqual(Dump.printExpStr(val), "true");
else
isTrue := false;
Expand All @@ -1499,7 +1500,7 @@ protected
algorithm
try
BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(ann)))) := inVar;
(val,_) := SCode.getNamedAnnotation(ann, "Evaluate");
(val,_) := SCodeUtil.getNamedAnnotation(ann, "Evaluate");
isFalse := stringEqual(Dump.printExpStr(val), "false");
else
isFalse := false;
Expand All @@ -1526,7 +1527,7 @@ protected
SCode.Annotation ann;
algorithm
BackendDAE.VAR(comment = SOME(SCode.COMMENT(annotation_ = SOME(ann)))) := inVar;
outValue := SCode.getNamedAnnotation(ann, inName);
outValue := SCodeUtil.getNamedAnnotation(ann, inName);
end getNamedAnnotation;

public function getAnnotationComment"gets the annotation comment, if there is one"
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -71,7 +71,7 @@ import Matching;
import MathematicaDump;
import Print;
import SCode;
import SCodeUtil;
import AbsynToSCode;
import Sorting;
import SymbolTable;
import System;
Expand Down Expand Up @@ -2194,7 +2194,7 @@ algorithm
case(_,_,_)
equation
System.realtimeTick(ClockIndexes.RT_CLOCK_UNCERTAINTIES);
p_1 = SCodeUtil.translateAbsyn2SCode(p);
p_1 = AbsynToSCode.translateAbsyn2SCode(p);
(cache,graph,_,dae) = Inst.instantiateClass(icache,InnerOuter.emptyInstHierarchy,p_1,className);
_ = System.realtimeTock(ClockIndexes.RT_CLOCK_UNCERTAINTIES);
System.realtimeTick(ClockIndexes.RT_CLOCK_BACKEND);
Expand Down
23 changes: 12 additions & 11 deletions OMCompiler/Compiler/FFrontEnd/FBuiltin.mo
Expand Up @@ -56,7 +56,8 @@ protected import Global;
protected import List;
protected import MetaUtil;
protected import Parser;
protected import SCodeUtil;
protected import AbsynToSCode;
import SCodeUtil;
protected import Settings;
protected import System;
protected import Util;
Expand Down Expand Up @@ -392,8 +393,8 @@ algorithm
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
(pNF as Absyn.PROGRAM(classes=classesNF)) = MetaUtil.createMetaClassesInProgram(pNF);
(pCF as Absyn.PROGRAM(classes=classesCF)) = MetaUtil.createMetaClassesInProgram(pCF);
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
spNF = List.map(classesNF, AbsynToSCode.translateClass);
spCF = List.map(classesCF, AbsynToSCode.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.METAMODELICA, true), (pNF,spNF))::((Flags.METAMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
Expand All @@ -411,8 +412,8 @@ algorithm
classesCF = listAppend(classes1CF,classes2);
pNF = Absyn.PROGRAM(classesNF,Absyn.TOP());
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
spNF = List.map(classesNF, AbsynToSCode.translateClass);
spCF = List.map(classesCF, AbsynToSCode.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.PARMODELICA, true), (pNF,spNF))::((Flags.PARMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
Expand All @@ -424,8 +425,8 @@ algorithm
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},AbsynUtil.dummyInfo);
(pNF as Absyn.PROGRAM(classes=classes1NF,within_=Absyn.TOP())) = Parser.parsebuiltin(fileModelicaNF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
(pCF as Absyn.PROGRAM(classes=classes1CF,within_=Absyn.TOP())) = Parser.parsebuiltin(fileModelicaCF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
spNF = List.map(classes1NF, SCodeUtil.translateClass);
spCF = List.map(classes1CF, SCodeUtil.translateClass);
spNF = List.map(classes1NF, AbsynToSCode.translateClass);
spCF = List.map(classes1CF, AbsynToSCode.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.MODELICA, true), (pNF,spNF))::((Flags.MODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
Expand All @@ -443,8 +444,8 @@ algorithm
classesCF = listAppend(classes1CF,classes2);
pNF = Absyn.PROGRAM(classesNF,Absyn.TOP());
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
spNF = List.map(classesNF, AbsynToSCode.translateClass);
spCF = List.map(classesCF, AbsynToSCode.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.PDEMODELICA, true), (pNF,spNF))::((Flags.PDEMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
Expand Down Expand Up @@ -686,12 +687,12 @@ algorithm
Absyn.Ident i, n;

case (_, _)
then SCode.getElementWithPath(inProgram, inPath);
then SCodeUtil.getElementWithPath(inProgram, inPath);

else
equation
(_,sp) = FBuiltin.getInitialFunctions();
then SCode.getElementWithPath(sp, inPath);
then SCodeUtil.getElementWithPath(sp, inPath);
end matchcontinue;
end getElementWithPathCheckBuiltin;

Expand Down
29 changes: 15 additions & 14 deletions OMCompiler/Compiler/FFrontEnd/FGraph.mo
Expand Up @@ -66,6 +66,7 @@ import Mod;
import Error;
import ComponentReference;
import Types;
import SCodeUtil;

public
type Name = FCore.Name;
Expand Down Expand Up @@ -1059,16 +1060,16 @@ algorithm
case (_, DAE.TYPES_VAR(name = n),c,_,_,_)
equation
// maks sure the element name and the DAE.TYPES_VAR name is the same!
false = stringEq(n, SCode.elementName(c));
Error.addCompilerError("FGraph.mkComponentNode: The component name: " + SCode.elementName(c) + " is not the same as its DAE.TYPES_VAR: " + n + "\n");
false = stringEq(n, SCodeUtil.elementName(c));
Error.addCompilerError("FGraph.mkComponentNode: The component name: " + SCodeUtil.elementName(c) + " is not the same as its DAE.TYPES_VAR: " + n + "\n");
then
fail();

// Graph of component
case (g, v as DAE.TYPES_VAR(name = n),c,m,i,cg)
equation
// make sure the element name and the DAE.TYPES_VAR name is the same!
true = stringEq(n, SCode.elementName(c));
true = stringEq(n, SCodeUtil.elementName(c));
r = lastScopeRef(g);
g = FGraphBuildEnv.mkCompNode(c, r, FCore.USERDEFINED(), g);
// update the var too!
Expand Down Expand Up @@ -1287,7 +1288,7 @@ algorithm
case (r::_, _)
equation
true = FNode.isRefClass(r);
restr = SCode.getClassRestriction(FNode.getElement(FNode.fromRef(r)));
restr = SCodeUtil.getClassRestriction(FNode.getElement(FNode.fromRef(r)));
true = valueEq(restrictionToScopeType(restr), inScopeType);
then
true;
Expand Down Expand Up @@ -1327,7 +1328,7 @@ algorithm
FCore.ScopeType st;

case r :: _ guard(FNode.isRefClass(r))
then SCode.getClassRestriction(FNode.getElement(FNode.fromRef(r)));
then SCodeUtil.getClassRestriction(FNode.getElement(FNode.fromRef(r)));

case r :: _
algorithm
Expand Down Expand Up @@ -1564,7 +1565,7 @@ algorithm
equation
c = inTargetClass;
gclass = inTargetClassEnv;
targetClassName = SCode.elementName(c);
targetClassName = SCodeUtil.elementName(c);
(newTargetClassName, crefPrefix) = mkVersionName(inSourceEnv, inSourceName, inPrefix, inMod, inTargetClassEnv, targetClassName);
Expand All @@ -1579,7 +1580,7 @@ algorithm
equation
c = inTargetClass;
gclass = inTargetClassEnv;
targetClassName = SCode.elementName(c);
targetClassName = SCodeUtil.elementName(c);

(newTargetClassName, crefPrefix) = mkVersionName(inSourceEnv, inSourceName, inPrefix, inMod, inTargetClassEnv, targetClassName);

Expand All @@ -1599,7 +1600,7 @@ algorithm

// change class name (so unqualified references to the same class reach the original element
FCore.CL(e = c) = FNode.refData(classRef);
c = SCode.setClassName(newTargetClassName, c);
c = SCodeUtil.setClassName(newTargetClassName, c);
classRef = updateClassElement(classRef, c, crefPrefix, inMod, FCore.CLS_INSTANCE(targetClassName) /* FCore.CLS_UNTYPED() */, empty());
// parent the classRef
FNode.addChildRef(targetClassParentRef, newTargetClassName, classRef);
Expand All @@ -1620,7 +1621,7 @@ algorithm
else
equation
c = inTargetClass;
targetClassName = SCode.elementName(c);
targetClassName = SCodeUtil.elementName(c);
(newTargetClassName,_) = mkVersionName(inSourceEnv, inSourceName, inPrefix, inMod, inTargetClassEnv, targetClassName);

Error.addCompilerWarning(
Expand Down Expand Up @@ -1655,7 +1656,7 @@ algorithm
/*
case (_, _, _, _, _, _, _)
equation
print(AbsynUtil.pathString(PrefixUtil.prefixToPath(inPrefix)) + " S:" + getGraphNameStr(inSourceEnv) + "/" + inSourceName + " ||| " + "T:" + getGraphNameStr(inTargetClassEnv) + "/" + SCode.elementName(inTargetClass) + "\n");
print(AbsynUtil.pathString(PrefixUtil.prefixToPath(inPrefix)) + " S:" + getGraphNameStr(inSourceEnv) + "/" + inSourceName + " ||| " + "T:" + getGraphNameStr(inTargetClassEnv) + "/" + SCodeUtil.elementName(inTargetClass) + "\n");
then
fail();*/

Expand All @@ -1672,7 +1673,7 @@ algorithm
true = Config.acceptMetaModelicaGrammar() or
isTargetClassBuiltin(inTargetClassEnv, inTargetClass) or
inFunctionScope(inSourceEnv) or
SCode.isOperatorRecord(inTargetClass);
SCodeUtil.isOperatorRecord(inTargetClass);
then
(inTargetClassEnv, inTargetClass, inIH);

Expand Down Expand Up @@ -1702,7 +1703,7 @@ algorithm
local Ref r;
case (_, _)
equation
r = FNode.child(lastScopeRef(inGraph), SCode.elementName(inClass));
r = FNode.child(lastScopeRef(inGraph), SCodeUtil.elementName(inClass));
yes = FNode.isRefBasicType(r) or FNode.isRefBuiltin(r);
then
yes;
Expand Down Expand Up @@ -1963,7 +1964,7 @@ algorithm
node := match node
case FCore.N(data = data as FCore.CL(e = el))
algorithm
el := SCode.makeClassPartial(el);
el := SCodeUtil.makeClassPartial(el);
data.e := el;
node.data := data;
then
Expand All @@ -1984,7 +1985,7 @@ protected
algorithm
try
FCore.N(data = FCore.CL(e = el)) := FNode.fromRef(lastScopeRef(inEnv));
outIsPartial := SCode.isPartial(el);
outIsPartial := SCodeUtil.isPartial(el);
else
outIsPartial := false;
end try;
Expand Down

0 comments on commit 21757d3

Please sign in to comment.