Skip to content

Commit

Permalink
- Made Types.matchTypes tail recursive.
Browse files Browse the repository at this point in the history
- Made Static.elabBuiltinTransition3 not fail.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22321 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 16, 2014
1 parent 2bd62ee commit 0f312a9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
4 changes: 1 addition & 3 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -5446,9 +5446,7 @@ algorithm
Absyn.Exp argValue;

case (_, Absyn.NAMEDARG(argName=argName))
equation
true = name ==& argName;
then true;
then stringEq(name, argName);

else false;
end match;
Expand Down
74 changes: 60 additions & 14 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -5814,35 +5814,81 @@ algorithm
end matchType;

public function matchTypes
"matchType, list of actual types, one expected type."
"matchType, list of actual types, one expected type."
input list<DAE.Exp> iexps;
input list<DAE.Type> itys;
input DAE.Type expected;
input Boolean printFailtrace;
output list<DAE.Exp> outExps;
output list<DAE.Type> outTys;
algorithm
(outExps,outTys) := matchcontinue (iexps,itys,expected,printFailtrace)
(outExps, outTys) := matchTypes_tail(iexps, itys, expected, printFailtrace, {}, {});
end matchTypes;

protected function matchTypes_tail
input list<DAE.Exp> iexps;
input list<DAE.Type> itys;
input DAE.Type expected;
input Boolean printFailtrace;
input list<DAE.Exp> inAccumExps;
input list<DAE.Type> inAccumTypes;
output list<DAE.Exp> outExps;
output list<DAE.Type> outTys;
algorithm
(outExps, outTys) :=
match(iexps, itys, expected, printFailtrace, inAccumExps, inAccumTypes)
local
DAE.Type ty;
list<DAE.Type> otys,tys;
DAE.Exp e;
list<DAE.Exp> exps;
DAE.Type ty;
list<DAE.Type> tys;

case (e :: exps, ty :: tys, _, _, _, _)
equation
(e, ty) = matchTypes2(e, ty, expected, printFailtrace);
(exps, tys) = matchTypes_tail(exps, tys, expected, printFailtrace,
e :: inAccumExps, ty :: inAccumTypes);
then
(exps, tys);

case ({}, {}, _, _, _, _)
then (listReverse(inAccumExps), listReverse(inAccumTypes));

end match;
end matchTypes_tail;

protected function matchTypes2
input DAE.Exp inExp;
input DAE.Type inType;
input DAE.Type inExpected;
input Boolean inPrintFailtrace;
output DAE.Exp outExp;
output DAE.Type outType;
algorithm
(outExp, outType) := matchcontinue(inExp, inType, inExpected, inPrintFailtrace)
local
DAE.Exp e;
DAE.Type ty, expected_ty;
String str;
case ({},{},_,_) then ({},{});
case (e::exps,ty::tys,_,_)

case (_, _, _, _)
equation
(e,ty) = matchType(e,getUniontypeIfMetarecordReplaceAllSubtypes(ty),getUniontypeIfMetarecordReplaceAllSubtypes(expected),printFailtrace);
(exps,otys) = matchTypes(exps,tys,expected,printFailtrace);
ty = getUniontypeIfMetarecordReplaceAllSubtypes(inType);
expected_ty = getUniontypeIfMetarecordReplaceAllSubtypes(inExpected);
(e, ty) = matchType(inExp, ty, expected_ty, inPrintFailtrace);
then
(e::exps,ty::otys);
case (e::_,ty::_,_,true)
(e, ty);

else
equation
str = "- Types.matchTypes failed for " +& ExpressionDump.printExpStr(e) +& " from " +& unparseType(ty) +& " to " +& unparseType(expected) +& "\n";
Error.addMessage(Error.INTERNAL_ERROR,{str});
then fail();
str = "- Types.matchTypes failed for " +& ExpressionDump.printExpStr(inExp)
+& " from " +& unparseType(inType) +& " to " +& unparseType(inExpected) +& "\n";
Error.addMessage(Error.INTERNAL_ERROR, {str});
then
fail();

end matchcontinue;
end matchTypes;
end matchTypes2;

protected function printFailure
"@author adrpo
Expand Down

0 comments on commit 0f312a9

Please sign in to comment.