Skip to content

Commit 9b6205d

Browse files
committed
- fixes to make slicing like
a[1,:] := a[:]; and/or a[2:3,2] := x[2:3]; work: - fixed code in indexed_assign_real_array(), index_real_array() and index_alloc_real_array() - fixed daeExpCrefRhsIndexSpec() template to generate "zero" dimension size for scalar subscripts for INDEX case: (0), make_index_array(1, <%expPart%>), 'S' - added test ArrayAssignWholeDim.mo; but it should be moved to mosfiles to ensure C-runtime invocation TODO: the same should be done for integer_array.c; then the character slice coding, i.e. 'S','A','W', can be removed entirely; or, perhaps, the slicing operation can be generated inline as appropriate nested for loops (I'll do that for C# generator, then it may be ported back to C++) - fixed daeExpAsub() template for _get_1D() .. _get_4D() constant index cases ... decremented indexes, because the _get_#D() functions works with zero based indexes - commented out #include "utility.h" in simulation_events.cpp to enable debugging in Visual Studio - added NO_INTERACTIVE_DEPENDENCY macro switch used in simulation_runtime.cpp for simpler compilation of simulation runtime in Visual Studio - added SimCode.cref2simvar(ComponentRef,SimCode)->SimVar function and daeLow field into SimCode.SIMCODE record to enable lookup of representation arrays in templates (C#); note that only cref2simvar() is visible from templates, but not the daeLow field which is not added to SimCodeTV.mo; the function needs a SimCode value as a whole, so the implementation is effectively hidden from templates' viewpoint; BUT, this is only a workaround for the lack of the needed information in component references themselves (hope they will have it in the future); see usage of cref2simvar() in SimCodeCSharp.tpl - added extern int const specifiers in functionStoreDelayed C++ template to resolve a link problem in VC++ - renamed local identifiers named cref to cr or ecr (ecr when of type DAE.Exp) in the C++ templates to disambiguate them from cref() template name (will be checked in the future; now value binding names and template names has separate name scopes, but that will be changed in the next versions of Susan); maybe the cref() template should be renamed to compRef() because there exist fields named cref in SimCodeTV.mo - simplified several constructs like '<%val%>' to just val and/or like (libs |> lib => lib) to just (libs) in C++ templates - re-factored some case clauses when they shared the same then part (Susan can have "or" cases,e.g.: case PAT1 case PAT2 case PAT3 then tplExpr ... where the same tplExpr is lexically used for every given case) - renamed subscriptsTpl() and subscriptTpl() templates to more suitable names subscriptsStr() and subscriptStr() - added many improvements in C# code generator - changed some make commands for Susan/C# codegen testing - added testmo make command to Makefile.common git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5881 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 95e688a commit 9b6205d

File tree

14 files changed

+11423
-3992
lines changed

14 files changed

+11423
-3992
lines changed

Compiler/SimCode.mo

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ uniontype SimCode
119119
ExtObjInfo extObjInfo;
120120
MakefileParams makefileParams;
121121
DelayedExpression delayedExps;
122+
DAELow.DAELow daeLow "hidden from typeview - exprerimental; used by cref2simvar() for cref -> SIMVAR mapping available in templates";
122123
end SIMCODE;
123124
end SimCode;
124125

@@ -438,7 +439,7 @@ algorithm
438439
isScalar := matchcontinue(cref, context)
439440
local
440441
Boolean res;
441-
case (_, FUNCTION_CONTEXT)
442+
case (_, FUNCTION_CONTEXT())
442443
equation
443444
res = crefNoSub(cref);
444445
then
@@ -467,7 +468,7 @@ algorithm
467468
case (DAE.CREF_QUAL(subscriptLst=subs1, componentRef=cref1))
468469
equation
469470
subs2 = crefSubs(cref1);
470-
subs = Util.listFlatten({subs1, subs2});
471+
subs = Util.listFlatten({subs1, subs2}); // ??? is this the same as listAppend(subs1, subs2);
471472
then subs;
472473
end matchcontinue;
473474
end crefSubs;
@@ -505,6 +506,43 @@ algorithm
505506
outInt := inInt + increment;
506507
end incrementInt;
507508

509+
public function cref2simvar
510+
"Used by templates to find SIMVAR for given cref (to gain representaion index info mainly)."
511+
input DAE.ComponentRef inCref;
512+
input SimCode simCode;
513+
output SimVar outSimVar;
514+
algorithm
515+
outSimVar := matchcontinue(inCref, simCode)
516+
local
517+
DAELow.Variables vars;
518+
DAELow.Var daelowvar;
519+
DAE.ComponentRef cref, badcref;
520+
SimVar sv;
521+
522+
case (DAE.CREF_QUAL(ident = "$DER", componentRef = cref), SIMCODE(daeLow = DAELow.DAELOW(orderedVars = vars)))
523+
equation
524+
((daelowvar :: _), _) = DAELow.getVar(cref, vars);
525+
sv = dlowvarToSimvar(daelowvar);
526+
then derVarFromStateVar(sv);
527+
528+
case (cref, SIMCODE(daeLow = DAELow.DAELOW(orderedVars = vars)))
529+
equation
530+
((daelowvar :: _), _) = DAELow.getVar(cref, vars);
531+
then dlowvarToSimvar(daelowvar);
532+
533+
case (cref, SIMCODE(daeLow = DAELow.DAELOW(knownVars = vars)))
534+
equation
535+
((daelowvar :: _), _) = DAELow.getVar(cref, vars);
536+
then dlowvarToSimvar(daelowvar);
537+
538+
case (cref, _)
539+
equation
540+
badcref = DAE.CREF_IDENT("ERROR_cref2simvar_failed", DAE.ET_REAL, {});
541+
then
542+
SIMVAR(badcref, DAELow.STATE(), "", -1, false, DAE.ET_REAL, false,NONE);
543+
end matchcontinue;
544+
end cref2simvar;
545+
508546
public function generateModelCode
509547
"Generates code for a model by creating a SimCode structure and calling the
510548
template-based code generator on it."
@@ -1247,7 +1285,8 @@ algorithm
12471285
algorithmAndEquationAsserts, zeroCrossings,
12481286
zeroCrossingsNeedSave, helpVarInfo, whenClauses,
12491287
discreteModelVars, extObjInfo, makefileParams,
1250-
DELAYED_EXPRESSIONS(delayedExps, maxDelayedExpIndex));
1288+
DELAYED_EXPRESSIONS(delayedExps, maxDelayedExpIndex),
1289+
dlow);
12511290
then
12521291
simCode;
12531292
case (_,_,_,_,_,_,_,_,_,_,_)

0 commit comments

Comments
 (0)