Skip to content

Commit

Permalink
[NF] Operator overloading fixes.
Browse files Browse the repository at this point in the history
- Handle +/- with arrays when no exact matching operator is defined.
- Fix the matching so that the operator overloading can use operator
  functions that take operator record arrays as argument.
- Move some code from TypeCheck to OperatorOverloading.

Belonging to [master]:
  - OpenModelica/OMCompiler#2515
  - OpenModelica/OpenModelica-testsuite#978
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jun 19, 2018
1 parent 8dca89a commit af928ab
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 101 deletions.
9 changes: 6 additions & 3 deletions Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -884,6 +884,7 @@ uniontype Function
input list<TypedArg> args;
input list<TypedNamedArg> named_args;
input SourceInfo info;
input Boolean vectorize = true;
output list<TypedArg> out_args;
output FunctionMatchKind matchKind = NO_MATCH;
protected
Expand All @@ -895,7 +896,7 @@ uniontype Function

// If we failed to match a function normally then we try to see if
// we can have a vectorized match.
if not matched then
if not matched and vectorize then
(out_args, matched, matchKind) := matchArgsVectorize(func, out_args, info);
end if;
end if;
Expand All @@ -906,6 +907,7 @@ uniontype Function
input list<TypedArg> args;
input list<TypedNamedArg> named_args;
input SourceInfo info;
input Boolean vectorize = true;
output list<MatchedFunction> matchedFunctions;
protected
list<TypedArg> m_args;
Expand All @@ -914,7 +916,7 @@ uniontype Function
algorithm
matchedFunctions := {};
for func in funcs loop
(m_args, matchKind) := matchFunction(func, args, named_args, info);
(m_args, matchKind) := matchFunction(func, args, named_args, info, vectorize);

if FunctionMatchKind.isValid(matchKind) then
matchedFunctions := MatchedFunction.MATCHED_FUNC(func,m_args,matchKind)::matchedFunctions;
Expand All @@ -927,11 +929,12 @@ uniontype Function
input list<TypedArg> args;
input list<TypedNamedArg> named_args;
input SourceInfo info;
input Boolean vectorize = true;
output list<MatchedFunction> matchedFunctions;
protected
algorithm
ErrorExt.setCheckpoint("NFFunction:matchFunctions");
matchedFunctions := matchFunctions(funcs, args, named_args, info);
matchedFunctions := matchFunctions(funcs, args, named_args, info, vectorize);
ErrorExt.rollBack("NFFunction:matchFunctions");
end matchFunctionsSilent;

Expand Down
35 changes: 34 additions & 1 deletion Compiler/NFFrontEnd/NFOperatorOverloading.mo
Expand Up @@ -32,9 +32,10 @@
encapsulated package NFOperatorOverloading
import Absyn;
import NFInstNode.InstNode;
import NFFunction.Function;
import Type = NFType;

protected
import NFFunction.Function;
import Record = NFRecord;
import ComponentRef = NFComponentRef;
import NFClassTree.ClassTree;
Expand Down Expand Up @@ -127,6 +128,38 @@ public
end if;
end checkOperatorRestrictions;

function lookupOperatorFunctionsInType
input String operatorName;
input Type ty;
output list<Function> functions;
protected
InstNode node;
ComponentRef fn_ref;
Boolean is_defined;
algorithm
functions := match Type.arrayElementType(ty)
case Type.COMPLEX(cls = node)
algorithm
try
fn_ref := Function.lookupFunctionSimple(operatorName, node);
is_defined := true;
else
is_defined := false;
end try;

if is_defined then
fn_ref := Function.instFunctionRef(fn_ref, InstNode.info(node));
functions := Function.typeRefCache(fn_ref);
else
functions := {};
end if;
then
functions;

else {};
end match;
end lookupOperatorFunctionsInType;

protected
function checkOperatorConstructorOutput
input Function fn;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -724,7 +724,7 @@ public
then List.isEqualOnTrue(ty1.types, ty2.types, isEqual);

case (TUPLE(), TUPLE()) then false;

case (COMPLEX(), COMPLEX()) then InstNode.isSame(ty1.cls, ty2.cls);
else true;
end match;
end isEqual;
Expand Down

0 comments on commit af928ab

Please sign in to comment.