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

Commit 24b68a2

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Handle initial complex equations better.
- Create the appropriate DAE element for initial complex equations. - Always generate default constructors for operator records, but hide them from the function matching if an overloaded constructor exists. Belonging to [master]: - #2526 - OpenModelica/OpenModelica-testsuite#981
1 parent 27740e1 commit 24b68a2

File tree

5 files changed

+46
-67
lines changed

5 files changed

+46
-67
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,17 @@ protected
900900
list<Integer> errors;
901901
algorithm
902902
ErrorExt.setCheckpoint("NFCall:checkMatchingFunctions");
903-
matchedFunctions := {};
904-
905-
_ := match call
906-
case ARG_TYPED_CALL(ref = ComponentRef.CREF(node = fn_node)) algorithm
907-
allfuncs := Function.getCachedFuncs(fn_node);
908-
matchedFunctions := Function.matchFunctions(allfuncs, call.arguments, call.named_args, info);
909-
then
910-
();
903+
904+
matchedFunctions := match call
905+
case ARG_TYPED_CALL(ref = ComponentRef.CREF(node = fn_node))
906+
algorithm
907+
allfuncs := Function.getCachedFuncs(fn_node);
908+
909+
if listLength(allfuncs) > 1 then
910+
allfuncs := list(fn for fn guard not Function.isDefaultRecordConstructor(fn) in allfuncs);
911+
end if;
912+
then
913+
Function.matchFunctions(allfuncs, call.arguments, call.named_args, info);
911914
end match;
912915

913916
if listEmpty(matchedFunctions) then
@@ -937,58 +940,28 @@ protected
937940
// about matching. We have one matching func if we reach here.
938941
ErrorExt.rollBack("NFCall:checkMatchingFunctions");
939942

940-
if listLength(matchedFunctions) == 1 then
941-
matchedFunc ::_ := matchedFunctions;
942-
943-
// Overwrite the actuall function name with the overload name
944-
// for builtin functions.
945-
if Function.isBuiltin(matchedFunc.func) then
946-
func := matchedFunc.func;
947-
func.path := Function.nameConsiderBuiltin(func);
948-
matchedFunc.func := func;
949-
end if;
950-
return;
951-
end if;
952-
953943
if listLength(matchedFunctions) > 1 then
954944
exactMatches := MatchedFunction.getExactMatches(matchedFunctions);
955-
if listLength(exactMatches) == 1 then
956-
matchedFunc ::_ := exactMatches;
957-
958-
// Overwrite the actual function name with the overload name
959-
// for builtin functions.
960-
if Function.isBuiltin(matchedFunc.func) then
961-
func := matchedFunc.func;
962-
func.path := Function.nameConsiderBuiltin(func);
963-
matchedFunc.func := func;
964-
end if;
965-
return;
966-
else
967-
matchedFunctions := resolveOverloadedVsDefaultConstructorAmbigutiy(matchedFunctions);
968-
if listLength(matchedFunctions) == 1 then
969-
matchedFunc ::_ := matchedFunctions;
970-
return;
971-
else
972-
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
973-
{typedString(call), Function.candidateFuncListString(list(mfn.func for mfn in matchedFunctions))}, info);
945+
946+
if listLength(exactMatches) > 1 then
947+
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
948+
{typedString(call), Function.candidateFuncListString(list(mfn.func for mfn in matchedFunctions))}, info);
974949
fail();
975-
end if;
976950
end if;
951+
952+
matchedFunc := listHead(exactMatches);
953+
else
954+
matchedFunc := listHead(matchedFunctions);
977955
end if;
978956

957+
// Overwrite the actual function name with the overload name for builtin functions.
958+
if Function.isBuiltin(matchedFunc.func) then
959+
func := matchedFunc.func;
960+
func.path := Function.nameConsiderBuiltin(func);
961+
matchedFunc.func := func;
962+
end if;
979963
end checkMatchingFunctions;
980964

981-
function resolveOverloadedVsDefaultConstructorAmbigutiy
982-
input list<MatchedFunction> matchedFunctions;
983-
output list<MatchedFunction> outMatches;
984-
algorithm
985-
// We have at least two exact matches. find the default constructor (if there is one) and remove it from the list
986-
// so that it
987-
// - doesn't cause ambiguities if there is only one other match left OR
988-
// - it doesn't appear in the error messages in the case of more than one overloaded constructor matches.
989-
outMatches := list(m for m guard not Function.isDefaultRecordConstructor(m.func) in matchedFunctions);
990-
end resolveOverloadedVsDefaultConstructorAmbigutiy;
991-
992965
function iteratorToDAE
993966
input tuple<InstNode, Expression> iter;
994967
output DAE.ReductionIterator diter;

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,14 @@ algorithm
453453
list<DAE.Dimension> dims;
454454
list<DAE.Element> body;
455455

456-
case Equation.EQUALITY() guard Type.isComplex(eq.ty)
457-
algorithm
458-
e1 := Expression.toDAE(eq.lhs);
459-
e2 := Expression.toDAE(eq.rhs);
460-
then
461-
DAE.Element.COMPLEX_EQUATION(e1, e2, eq.source) :: elements;
462-
463456
case Equation.EQUALITY()
464457
algorithm
465458
e1 := Expression.toDAE(eq.lhs);
466459
e2 := Expression.toDAE(eq.rhs);
467460
then
468-
DAE.Element.EQUATION(e1, e2, eq.source) :: elements;
461+
(if Type.isComplex(eq.ty) then
462+
DAE.Element.COMPLEX_EQUATION(e1, e2, eq.source) else
463+
DAE.Element.EQUATION(e1, e2, eq.source)) :: elements;
469464

470465
case Equation.CREF_EQUALITY()
471466
algorithm
@@ -605,7 +600,9 @@ algorithm
605600
e1 := Expression.toDAE(eq.lhs);
606601
e2 := Expression.toDAE(eq.rhs);
607602
then
608-
DAE.Element.INITIALEQUATION(e1, e2, eq.source) :: elements;
603+
(if Type.isComplex(eq.ty) then
604+
DAE.Element.INITIAL_COMPLEX_EQUATION(e1, e2, eq.source) else
605+
DAE.Element.INITIALEQUATION(e1, e2, eq.source)) :: elements;
609606

610607
case Equation.ARRAY_EQUALITY()
611608
algorithm

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import ElementSource;
8383
import Ceval = NFCeval;
8484
import NFTyping.ExpOrigin;
8585
import SimplifyExp = NFSimplifyExp;
86+
import Restriction = NFRestriction;
8687

8788
public
8889
type FunctionTree = FunctionTreeImpl.Tree;

Compiler/NFFrontEnd/NFOperatorOverloading.mo

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ public
7272
checkOperatorConstructorOutput(f, Class.lastBaseClass(recordNode), ctor_path, info);
7373
recordNode := InstNode.cacheAddFunc(recordNode, f, false);
7474
end for;
75-
else
76-
// If it doesn't have an an overloaded constructor, construct a default
77-
// record constructor and use that instead.
78-
recordNode := Record.instDefaultConstructor(path, recordNode, info);
7975
end if;
76+
77+
recordNode := Record.instDefaultConstructor(path, recordNode, info);
8078
end instConstructor;
8179

8280
function instOperatorFunctions

Compiler/NFFrontEnd/NFRestriction.mo

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,24 @@ public
125125

126126
function isRecord
127127
input Restriction res;
128-
output Boolean isFunction;
128+
output Boolean isRecord;
129129
algorithm
130-
isFunction := match res
130+
isRecord := match res
131131
case RECORD() then true;
132132
else false;
133133
end match;
134134
end isRecord;
135135

136+
function isOperatorRecord
137+
input Restriction res;
138+
output Boolean isOpRecord;
139+
algorithm
140+
isOpRecord := match res
141+
case RECORD() then res.isOperator;
142+
else false;
143+
end match;
144+
end isOperatorRecord;
145+
136146
function isType
137147
input Restriction res;
138148
output Boolean isType;

0 commit comments

Comments
 (0)