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

Commit ff81880

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] ones/zeros and dimensions type check fixes.
- Change ones/zeros to the appropriate fill calls, since the code generation expects that. - Fixed equality check for dimensions to handle expressions better. Belonging to [master]: - #2378 - OpenModelica/OpenModelica-testsuite#925
1 parent 129d50f commit ff81880

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

Compiler/NFFrontEnd/NFBuiltinFuncs.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,9 @@ constant Function ARRAY_FUNC = Function.FUNCTION(Path.IDENT("array"),
234234
InstNode.EMPTY_NODE(), {}, {}, {}, {},
235235
Type.UNKNOWN(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));
236236

237+
constant Function FILL_FUNC = Function.FUNCTION(Path.IDENT("fill"),
238+
InstNode.EMPTY_NODE(), {}, {}, {}, {},
239+
Type.UNKNOWN(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));
240+
237241
annotation(__OpenModelica_Interface="frontend");
238242
end NFBuiltinFuncs;

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,13 +1889,13 @@ protected
18891889

18901890
// Type the first argument, which is the fill value.
18911891
(fill_arg, ty, _) := Typing.typeExp(fill_arg, origin, info);
1892-
(callExp, ty, variability) := typeFillCall2(fn_ref, ty, {fill_arg}, args, origin, info);
1892+
(callExp, ty, variability) := typeFillCall2(fn_ref, ty, fill_arg, args, origin, info);
18931893
end typeFillCall;
18941894

18951895
function typeFillCall2
18961896
input ComponentRef fnRef;
18971897
input Type fillType;
1898-
input list<Expression> fillArgs;
1898+
input Expression fillArg;
18991899
input list<Expression> dimensionArgs;
19001900
input ExpOrigin.Type origin;
19011901
input SourceInfo info;
@@ -1910,7 +1910,7 @@ protected
19101910
Function fn;
19111911
list<Dimension> dims;
19121912
algorithm
1913-
ty_args := fillArgs;
1913+
ty_args := {fillArg};
19141914
dims := {};
19151915

19161916
// Type the dimension arguments.
@@ -1941,9 +1941,9 @@ protected
19411941
ty := Type.ARRAY(fillType, dims);
19421942

19431943
if variability <= Variability.STRUCTURAL_PARAMETER and intBitAnd(origin, ExpOrigin.FUNCTION) == 0 then
1944-
callExp := Ceval.evalBuiltinCall(fn, ty_args, Ceval.EvalTarget.IGNORE_ERRORS());
1944+
callExp := Ceval.evalBuiltinFill(ty_args);
19451945
else
1946-
callExp := Expression.CALL(makeBuiltinCall2(fn, ty_args, ty, variability));
1946+
callExp := Expression.CALL(makeBuiltinCall2(NFBuiltinFuncs.FILL_FUNC, ty_args, ty, variability));
19471947
end if;
19481948
end typeFillCall2;
19491949

@@ -1974,7 +1974,13 @@ protected
19741974
{toString(call), ComponentRef.toString(fn_ref) + "(Integer, ...) => Integer[:, ...]"}, info);
19751975
end if;
19761976

1977-
(callExp, ty, variability) := typeFillCall2(fn_ref, Type.INTEGER(), {}, args, origin, info);
1977+
if ComponentRef.firstName(fn_ref) == "ones" then
1978+
fill_arg := Expression.INTEGER(1);
1979+
else
1980+
fill_arg := Expression.INTEGER(0);
1981+
end if;
1982+
1983+
(callExp, ty, variability) := typeFillCall2(fn_ref, Type.INTEGER(), fill_arg, args, origin, info);
19781984
end typeZerosOnesCall;
19791985

19801986
function typeScalarCall

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ algorithm
716716
end match;
717717
end evalBuiltinExp;
718718

719+
public
719720
function evalBuiltinFill
720721
input list<Expression> args;
721722
output Expression result;
@@ -744,6 +745,7 @@ algorithm
744745
end for;
745746
end evalBuiltinFill2;
746747

748+
protected
747749
function evalBuiltinFloor
748750
input Expression arg;
749751
output Expression result;

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public
169169
isEqual := match (dim1, dim2)
170170
case (UNKNOWN(), _) then true;
171171
case (_, UNKNOWN()) then true;
172+
case (EXP(), EXP()) then Expression.isEqual(dim1.exp, dim2.exp);
172173
case (EXP(), _) then true;
173174
case (_, EXP()) then true;
174175
else Dimension.size(dim1) == Dimension.size(dim2);

Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,21 +1827,21 @@ function matchDimensions
18271827
input Boolean allowUnknown;
18281828
output Dimension compatibleDim;
18291829
output Boolean compatible;
1830-
protected
1831-
Boolean known1, known2;
18321830
algorithm
1833-
known1 := Dimension.isKnown(dim1);
1834-
known2 := Dimension.isKnown(dim2);
1835-
1836-
if known1 and known2 then
1831+
if Dimension.isEqual(dim1, dim2) then
18371832
compatibleDim := dim1;
1838-
compatible := Dimension.isEqual(dim1, dim2);
1839-
elseif allowUnknown then
1840-
compatibleDim := if known1 then dim1 else dim2;
18411833
compatible := true;
18421834
else
1843-
compatibleDim := dim1;
1844-
compatible := false;
1835+
if not Dimension.isKnown(dim1) then
1836+
compatibleDim := dim2;
1837+
compatible := true;
1838+
elseif not Dimension.isKnown(dim2) then
1839+
compatibleDim := dim1;
1840+
compatible := true;
1841+
else
1842+
compatibleDim := dim1;
1843+
compatible := false;
1844+
end if;
18451845
end if;
18461846
end matchDimensions;
18471847

0 commit comments

Comments
 (0)