Skip to content

Commit

Permalink
- merge cases based on output from rml -Eunify (https://dev.openmodel…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Oct 27, 2014
1 parent 8da37a6 commit 4daf4d1
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 332 deletions.
62 changes: 20 additions & 42 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5863,68 +5863,46 @@ algorithm
ElementArg mod;
Annotation a;
Path p;

case (ANNOTATION(elementArgs = ((mod as MODIFICATION(path = p)) :: oldrest)),ANNOTATION(elementArgs = eltargs))
equation
failure(_ = removeModificationInElementargs(eltargs, p));
ANNOTATION(neweltargs) = mergeAnnotations(ANNOTATION(oldrest), ANNOTATION(eltargs));
then
ANNOTATION((mod :: neweltargs));
case (ANNOTATION(elementArgs = ((MODIFICATION(path = p)) :: oldrest)),ANNOTATION(elementArgs = eltargs))
equation
_ = removeModificationInElementargs(eltargs, p);
ANNOTATION(neweltargs) = mergeAnnotations(ANNOTATION(oldrest), ANNOTATION(eltargs));
then ANNOTATION(neweltargs);
if modificationInElementargs(eltargs, p)
then ANNOTATION(neweltargs)
else ANNOTATION(mod :: neweltargs);

case (ANNOTATION(elementArgs = {}),a) then a;

end matchcontinue;
end mergeAnnotations;

protected function removeModificationInElementargs
" This function removes the class modification named by the second argument.
If no such class modification is found thefunction fails.
Currently, only identifiers are allowed as class modifiers,
i.e. a(...) and not a.b(...)"
protected function modificationInElementargs
"returns true or false if the given path is in the list of modifications"
input list<ElementArg> inAbsynElementArgLst;
input Path inPath;
output list<ElementArg> outAbsynElementArgLst;
output Boolean yes;
algorithm
outAbsynElementArgLst := matchcontinue (inAbsynElementArgLst,inPath)
yes := match (inAbsynElementArgLst,inPath)
local
String id1,id2;
ElementArg m;
list<ElementArg> res,xs;

case ({MODIFICATION(path = IDENT(name = id1))},IDENT(name = id2))
equation
true = stringEq(id1, id2);
then {};

case ({(MODIFICATION(path = IDENT(name = id1)))},IDENT(name = id2))
equation
false = stringEq(id1, id2);
then
fail();
list<ElementArg> xs;
Boolean b;

case ((MODIFICATION(path = IDENT(name = id1)) :: xs),IDENT(name = id2))
equation
true = stringEq(id1, id2);
res = removeModificationInElementargs(xs, inPath);
b = match(stringEq(id1, id2))
case (true) then true;
case (false) then modificationInElementargs(xs, inPath);
end match;
then
res;
b;

case (((m as MODIFICATION(path = IDENT(name = id1))) :: xs),IDENT(name = id2))
equation
false = stringEq(id1, id2);
res = removeModificationInElementargs(xs, inPath);
then
(m :: res);
else false;

case (((m as MODIFICATION(path = IDENT(name = _))) :: xs),IDENT(name = _))
equation
res = removeModificationInElementargs(xs, inPath);
then
(m :: res);
end matchcontinue;
end removeModificationInElementargs;
end match;
end modificationInElementargs;

public function annotationToElementArgs
input Annotation ann;
Expand Down
27 changes: 10 additions & 17 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -714,6 +714,7 @@ algorithm
local
list<tuple<Integer,FGraph.Graph>> assocLst;
FGraph.Graph graph;
Integer f;

// nothing there
case (_)
Expand All @@ -734,27 +735,19 @@ algorithm

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
assocLst = getGlobalRoot(Global.builtinGraphIndex);
setGlobalRoot(Global.builtinGraphIndex, (Flags.METAMODELICA,graph)::assocLst);
then
graph;

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
assocLst = getGlobalRoot(Global.builtinGraphIndex);
setGlobalRoot(Global.builtinGraphIndex, (Flags.PARMODELICA,graph)::assocLst);
f = Flags.getConfigEnum(Flags.GRAMMAR);
assocLst = if f == Flags.METAMODELICA
then (Flags.METAMODELICA,graph)::assocLst
else if f == Flags.PARMODELICA
then (Flags.PARMODELICA,graph)::assocLst
else if f == Flags.MODELICA
then (Flags.MODELICA,graph)::assocLst
else assocLst;
setGlobalRoot(Global.builtinGraphIndex, assocLst);
then
graph;

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
assocLst = getGlobalRoot(Global.builtinGraphIndex);
setGlobalRoot(Global.builtinGraphIndex, (Flags.MODELICA,graph)::assocLst);
then
graph;
end matchcontinue;
end getSetInitialGraph;

Expand Down

0 comments on commit 4daf4d1

Please sign in to comment.