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

Commit 6127ec9

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Various improvements.
- Implement expansion for diagonal(). - Mark slice subscripts in equations as structural. Belonging to [master]: - #2707
1 parent 0283b33 commit 6127ec9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Compiler/NFFrontEnd/NFExpandExp.mo

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,11 @@ public
271271
algorithm
272272
(outExp, expanded) := match Absyn.pathFirstIdent(fn_path)
273273
case "cat" then expandBuiltinCat(args, call);
274-
case "promote" then expandBuiltinPromote(args);
275274
case "der" then expandBuiltinGeneric(call);
275+
case "diagonal" then expandBuiltinDiagonal(listHead(args));
276276
case "pre" then expandBuiltinGeneric(call);
277277
case "previous" then expandBuiltinGeneric(call);
278+
case "promote" then expandBuiltinPromote(args);
278279
case "transpose" then expandBuiltinTranspose(listHead(args));
279280
end match;
280281
end expandBuiltinCall;
@@ -313,6 +314,18 @@ public
313314
exp := Expression.promote(eexp, Expression.typeOf(eexp), n);
314315
end expandBuiltinPromote;
315316

317+
function expandBuiltinDiagonal
318+
input Expression arg;
319+
output Expression outExp;
320+
output Boolean expanded;
321+
algorithm
322+
(outExp, expanded) := expand(arg);
323+
324+
if expanded then
325+
outExp := Ceval.evalBuiltinDiagonal(outExp);
326+
end if;
327+
end expandBuiltinDiagonal;
328+
316329
function expandBuiltinTranspose
317330
input Expression arg;
318331
output Expression outExp;

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,13 +1378,17 @@ algorithm
13781378
if Type.isArray(ty) then
13791379
outSubscript := Subscript.SLICE(e);
13801380
ty := Type.unliftArray(ty);
1381+
1382+
if ExpOrigin.flagSet(origin, ExpOrigin.EQUATION) then
1383+
Inst.markStructuralParamsExp(e);
1384+
end if;
13811385
else
13821386
outSubscript := Subscript.INDEX(e);
13831387
end if;
13841388
then
13851389
(ty, variability);
13861390

1387-
//// Other subscripts have already been typed, but still need to be type checked.
1391+
// Other subscripts have already been typed, but still need to be type checked.
13881392
case Subscript.INDEX(index = e) then (Expression.typeOf(e), Expression.variability(e));
13891393
case Subscript.SLICE(slice = e) then (Type.unliftArray(Expression.typeOf(e)), Expression.variability(e));
13901394
case Subscript.WHOLE() then (Type.UNKNOWN(), Dimension.variability(dimension));

0 commit comments

Comments
 (0)