Skip to content

Commit ea2e9d2

Browse files
committed
- use consistent naming in uniontype Context
- change comments to description strings git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16769 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent e9165df commit ea2e9d2

File tree

7 files changed

+95
-101
lines changed

7 files changed

+95
-101
lines changed

Compiler/BackEnd/SimCode.mo

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ type JacobianMatrix = tuple<list<JacobianColumn>, // col
7171

7272
public constant list<DAE.Exp> listExpLength1 = {DAE.ICONST(0)} "For CodegenC.tpl";
7373

74-
// Root data structure containing information required for templates to
75-
// generate simulation code for a Modelica model.
7674
uniontype SimCode
75+
"Root data structure containing information required for templates to
76+
generate simulation code for a Modelica model."
7777
record SIMCODE
7878
ModelInfo modelInfo;
7979
list<DAE.Exp> literals "shared literals";
@@ -83,8 +83,8 @@ uniontype SimCode
8383
list<list<SimEqSystem>> odeEquations;
8484
list<list<SimEqSystem>> algebraicEquations;
8585
list<SimEqSystem> residualEquations;
86-
Boolean useSymbolicInitialization; // true if a system to solve the initial problem symbolically is generated, otherwise false
87-
Boolean useHomotopy; // true if homotopy(...) is used during initialization
86+
Boolean useSymbolicInitialization "true if a system to solve the initial problem symbolically is generated, otherwise false";
87+
Boolean useHomotopy "true if homotopy(...) is used during initialization";
8888
list<SimEqSystem> initialEquations;
8989
list<SimEqSystem> startValueEquations;
9090
list<SimEqSystem> parameterEquations;
@@ -112,17 +112,17 @@ uniontype SimCode
112112
end SIMCODE;
113113
end SimCode;
114114

115-
// Delayed expressions type
116115
uniontype DelayedExpression
116+
"Delayed expressions type"
117117
record DELAYED_EXPRESSIONS
118118
list<tuple<Integer, tuple<DAE.Exp, DAE.Exp, DAE.Exp>>> delayedExps;
119119
Integer maxDelayedIndex;
120120
end DELAYED_EXPRESSIONS;
121121
end DelayedExpression;
122122

123-
// Root data structure containing information required for templates to
124-
// generate C functions for Modelica/MetaModelica functions.
125123
uniontype FunctionCode
124+
"Root data structure containing information required for templates to
125+
generate C functions for Modelica/MetaModelica functions."
126126
record FUNCTIONCODE
127127
String name;
128128
Option<Function> mainFunction "This function is special; the 'in'-function should be generated for it";
@@ -134,8 +134,7 @@ uniontype FunctionCode
134134
end FUNCTIONCODE;
135135
end FunctionCode;
136136

137-
// Container for metadata about a Modelica model.
138-
uniontype ModelInfo
137+
uniontype ModelInfo "Container for metadata about a Modelica model."
139138
record MODELINFO
140139
Absyn.Path name;
141140
String directory;
@@ -161,8 +160,7 @@ uniontype FileInfo
161160
end FILEINFO;
162161
end FileInfo;
163162

164-
// Number of variables of various types in a Modelica model.
165-
uniontype VarInfo
163+
uniontype VarInfo "Number of variables of various types in a Modelica model."
166164
record VARINFO
167165
Integer numZeroCrossings;
168166
Integer numTimeEvents;
@@ -184,7 +182,7 @@ uniontype VarInfo
184182
Integer numInVars;
185183
Integer numInitialEquations;
186184
Integer numInitialAlgorithms;
187-
Integer numInitialResiduals; // numInitialEquations+numInitialAlgorithms
185+
Integer numInitialResiduals "numInitialEquations + numInitialAlgorithms";
188186
Integer numExternalObjects;
189187
Integer numStringAlgVars;
190188
Integer numStringParamVars;
@@ -199,8 +197,7 @@ uniontype VarInfo
199197
end VARINFO;
200198
end VarInfo;
201199

202-
// Container for metadata about variables in a Modelica model.
203-
uniontype SimVars
200+
uniontype SimVars "Container for metadata about variables in a Modelica model."
204201
record SIMVARS
205202
list<SimVar> stateVars;
206203
list<SimVar> derivativeVars;
@@ -230,8 +227,7 @@ end SimVars;
230227
public constant SimVars emptySimVars = SIMVARS({}, {}, {}, {}, {}, {}, {}, {},
231228
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {});
232229

233-
// Information about a variable in a Modelica model.
234-
uniontype SimVar
230+
uniontype SimVar "Information about a variable in a Modelica model."
235231
record SIMVAR
236232
DAE.ComponentRef name;
237233
BackendDAE.VarKind varKind;
@@ -274,10 +270,10 @@ uniontype Causality
274270
record INPUT end INPUT;
275271
end Causality;
276272

277-
// Represents a Modelica or MetaModelica function.
278273
// TODO: I believe some of these fields can be removed. Check to see what is
279274
// used in templates.
280-
uniontype Function
275+
uniontype Function
276+
"Represents a Modelica or MetaModelica function."
281277
record FUNCTION
282278
Absyn.Path name;
283279
list<Variable> outVars;
@@ -314,7 +310,7 @@ uniontype Function
314310
list<Variable> inVars;
315311
list<Variable> outVars;
316312
list<Variable> biVars;
317-
list<String> libs; //need this one for C#
313+
list<String> libs "need this one for C#";
318314
String language "C or Fortran";
319315
Absyn.Info info;
320316
Boolean dynamicLoad;
@@ -330,22 +326,22 @@ end Function;
330326

331327
uniontype RecordDeclaration
332328
record RECORD_DECL_FULL
333-
String name; // struct (record) name ? encoded
334-
Absyn.Path defPath; //definition path
335-
list<Variable> variables; //only name and type
329+
String name "struct (record) name ? encoded";
330+
Absyn.Path defPath "definition path";
331+
list<Variable> variables "only name and type";
336332
end RECORD_DECL_FULL;
337333
record RECORD_DECL_DEF
338-
Absyn.Path path; //definition path .. encoded ?
334+
Absyn.Path path "definition path .. encoded?";
339335
list<String> fieldNames;
340336
end RECORD_DECL_DEF;
341337
end RecordDeclaration;
342338

343-
// Information about an argument to an external function.
344339
uniontype SimExtArg
340+
"Information about an argument to an external function."
345341
record SIMEXTARG
346342
DAE.ComponentRef cref;
347343
Boolean isInput;
348-
Integer outputIndex; // > 0 if output
344+
Integer outputIndex "> 0 if output";
349345
Boolean isArray;
350346
Boolean hasBinding "avoid double allocation";
351347
DAE.Type type_;
@@ -357,19 +353,19 @@ uniontype SimExtArg
357353
record SIMEXTARGSIZE
358354
DAE.ComponentRef cref;
359355
Boolean isInput;
360-
Integer outputIndex; // > 0 if output
356+
Integer outputIndex "> 0 if output";
361357
DAE.Type type_;
362358
DAE.Exp exp;
363359
end SIMEXTARGSIZE;
364360
record SIMNOEXTARG end SIMNOEXTARG;
365361
end SimExtArg;
366362

367-
/* a variable represents a name, a type and a possible default value */
368363
uniontype Variable
364+
"a variable represents a name, a type and a possible default value"
369365
record VARIABLE
370366
DAE.ComponentRef name;
371367
DAE.Type ty;
372-
Option<DAE.Exp> value; // Default value
368+
Option<DAE.Exp> value "default value";
373369
list<DAE.Exp> instDims;
374370
DAE.VarParallelism parallelism;
375371
end VARIABLE;
@@ -388,9 +384,8 @@ uniontype Statement
388384
end ALGORITHM;
389385
end Statement;
390386

391-
// Represents a single equation or a system of equations that must be solved
392-
// together.
393387
uniontype SimEqSystem
388+
"Represents a single equation or a system of equations that must be solved together."
394389
record SES_RESIDUAL
395390
Integer index;
396391
DAE.Exp exp;
@@ -451,8 +446,8 @@ uniontype SimEqSystem
451446

452447
record SES_WHEN
453448
Integer index;
454-
list<DAE.ComponentRef> conditions; // list of boolean variables as conditions
455-
Boolean initialCall; // true, if top-level branch with initial()
449+
list<DAE.ComponentRef> conditions "list of boolean variables as conditions";
450+
Boolean initialCall "true, if top-level branch with initial()";
456451
DAE.ComponentRef left;
457452
DAE.Exp right;
458453
Option<SimEqSystem> elseWhen;
@@ -474,9 +469,9 @@ end StateSet;
474469

475470
uniontype SimWhenClause
476471
record SIM_WHEN_CLAUSE
477-
list<DAE.ComponentRef> conditionVars; // is no longer needed
478-
list<DAE.ComponentRef> conditions; // list of boolean variables as conditions
479-
Boolean initialCall; // true, if top-level branch with initial()
472+
list<DAE.ComponentRef> conditionVars "is no longer needed";
473+
list<DAE.ComponentRef> conditions "list of boolean variables as conditions";
474+
Boolean initialCall "true, if top-level branch with initial()";
480475
list<BackendDAE.WhenOperator> reinits;
481476
Option<BackendDAE.WhenEquation> whenEq;
482477
end SIM_WHEN_CLAUSE;
@@ -489,8 +484,8 @@ uniontype ExtObjInfo
489484
end EXTOBJINFO;
490485
end ExtObjInfo;
491486

492-
// Platform specific parameters used when generating makefiles.
493487
uniontype MakefileParams
488+
"Platform specific parameters used when generating makefiles."
494489
record MAKEFILE_PARAMS
495490
String ccompiler;
496491
String cxxcompiler;
@@ -525,55 +520,54 @@ uniontype SimulationSettings
525520
end SIMULATION_SETTINGS;
526521
end SimulationSettings;
527522

528-
// Constants of this type defined below are used by templates to be able to
529-
// generate different code depending on the context it is generated in.
530523
uniontype Context
531-
record SIMULATION
524+
"Constants of this type defined below are used by templates to be able to
525+
generate different code depending on the context it is generated in."
526+
record SIMULATION_CONTEXT
532527
Boolean genDiscrete;
533-
end SIMULATION;
528+
end SIMULATION_CONTEXT;
529+
534530
record FUNCTION_CONTEXT
535531
end FUNCTION_CONTEXT;
536532

537533
record ALGLOOP_CONTEXT
538534
Boolean genInitialisation;
539535
end ALGLOOP_CONTEXT;
540-
record OTHER
541-
end OTHER;
536+
537+
record OTHER_CONTEXT
538+
end OTHER_CONTEXT;
539+
542540
record INLINE_CONTEXT
543541
end INLINE_CONTEXT;
542+
544543
record PARALLEL_FUNCTION_CONTEXT
545544
end PARALLEL_FUNCTION_CONTEXT;
545+
546546
record ZEROCROSSINGS_CONTEXT
547547
end ZEROCROSSINGS_CONTEXT;
548-
record OPTIMIZATION
549-
end OPTIMIZATION;
548+
549+
record OPTIMIZATION_CONTEXT
550+
end OPTIMIZATION_CONTEXT;
550551
end Context;
551552

552-
553-
public constant Context contextSimulationNonDiscrete = SIMULATION(false);
554-
public constant Context contextSimulationDiscrete = SIMULATION(true);
553+
public constant Context contextSimulationNonDiscrete = SIMULATION_CONTEXT(false);
554+
public constant Context contextSimulationDiscrete = SIMULATION_CONTEXT(true);
555555
public constant Context contextInlineSolver = INLINE_CONTEXT();
556556
public constant Context contextFunction = FUNCTION_CONTEXT();
557557
public constant Context contextAlgloopInitialisation = ALGLOOP_CONTEXT(true);
558558
public constant Context contextAlgloop = ALGLOOP_CONTEXT(false);
559-
public constant Context contextOther = OTHER();
559+
public constant Context contextOther = OTHER_CONTEXT();
560560
public constant Context contextParallelFunction = PARALLEL_FUNCTION_CONTEXT();
561561
public constant Context contextZeroCross = ZEROCROSSINGS_CONTEXT();
562-
public constant Context contextOptimization = OPTIMIZATION();
563-
562+
public constant Context contextOptimization = OPTIMIZATION_CONTEXT();
564563

565564
/****** HashTable ComponentRef -> SimCode.SimVar ******/
566565
/* a workaround to enable "cross public import" */
567566

568-
569567
/* HashTable instance specific code */
570-
571568
public
572569
type Key = DAE.ComponentRef;
573570
type Value = SimVar;
574-
575-
576-
577571
/* end of HashTable instance specific code */
578572

579573
/* Generic hashtable code below!! */
@@ -599,7 +593,7 @@ end ValueArray;
599593

600594
public uniontype HpcOmParInformation "informations for the taskgraph parallelization"
601595
record HPCOMPARINFORMATION
602-
list<list<Integer>> eqsOfLevels; //The equations of the level <%listindex%>
596+
list<list<Integer>> eqsOfLevels "The equations of the level <%listindex%>";
603597
end HPCOMPARINFORMATION;
604598
end HpcOmParInformation;
605599
end SimCode;

Compiler/Template/CodegenAdevs.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,7 +3369,7 @@ case ecr as CREF(componentRef=WILD(__)) then
33693369
case CREF(ty= t as DAE.T_ARRAY(__)) then
33703370
let lhsStr = scalarLhsCref(exp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
33713371
match context
3372-
case SIMULATION(__) then
3372+
case SIMULATION_CONTEXT(__) then
33733373
<<
33743374
copy_<%expTypeShort(t)%>_array_data_mem(&<%rhsStr%>, &<%lhsStr%>);
33753375
>>
@@ -3378,7 +3378,7 @@ case CREF(ty= t as DAE.T_ARRAY(__)) then
33783378
case UNARY(exp = e as CREF(ty= t as DAE.T_ARRAY(__))) then
33793379
let lhsStr = scalarLhsCref(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
33803380
match context
3381-
case SIMULATION(__) then
3381+
case SIMULATION_CONTEXT(__) then
33823382
<<
33833383
usub_<%expTypeShort(t)%>_array(&<%rhsStr%>);<%\n%>
33843384
copy_<%expTypeShort(t)%>_array_data_mem(&<%rhsStr%>, &<%lhsStr%>);
@@ -3637,7 +3637,7 @@ template algStmtWhen(DAE.Statement when, Context context, Text &varDecls /*BUFP*
36373637
"Generates a when algorithm statement."
36383638
::=
36393639
match context
3640-
case SIMULATION(genDiscrete=true) then
3640+
case SIMULATION_CONTEXT(genDiscrete=true) then
36413641
match when
36423642
case STMT_WHEN(__) then
36433643
let helpIf = (conditions |> e => '(<%cref(e)%> && !_PRE<%cref(e)%> /* edge */)';separator=" || ")
@@ -4153,7 +4153,7 @@ template daeExpRelationSim(Exp exp, Context context, Text &preExp /*BUFP*/,
41534153
match exp
41544154
case rel as RELATION(__) then
41554155
match context
4156-
case SIMULATION(genDiscrete=false) then
4156+
case SIMULATION_CONTEXT(genDiscrete=false) then
41574157
match rel.optionExpisASUB
41584158
case NONE() then
41594159
let e1 = daeExp(rel.exp1, context, &preExp /*BUFC*/, &varDecls /*BUFC*/)
@@ -4194,7 +4194,7 @@ case rel as RELATION(__) then
41944194
res
41954195
end match
41964196
end match
4197-
case SIMULATION(genDiscrete=true) then
4197+
case SIMULATION_CONTEXT(genDiscrete=true) then
41984198
match rel.optionExpisASUB
41994199
case NONE() then
42004200
let e1 = daeExp(rel.exp1, context, &preExp /*BUFC*/, &varDecls /*BUFC*/)
@@ -4528,14 +4528,14 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
45284528
let retVar = match attr.ty
45294529
case T_NORETCALL(__) then ""
45304530
else tempDecl(retType, &varDecls)
4531-
let &preExp += if not attr.builtin then match context case SIMULATION(__) then
4531+
let &preExp += if not attr.builtin then match context case SIMULATION_CONTEXT(__) then
45324532
<<
45334533
#ifdef _OMC_MEASURE_TIME
45344534
SIM_PROF_TICK_FN(<%funName%>_index);
45354535
#endif<%\n%>
45364536
>>
45374537
let &preExp += '<%if retVar then '<%retVar%> = '%><%daeExpCallBuiltinPrefix(attr.builtin)%><%funName%>(<%argStr%>);<%\n%>'
4538-
let &preExp += if not attr.builtin then match context case SIMULATION(__) then
4538+
let &preExp += if not attr.builtin then match context case SIMULATION_CONTEXT(__) then
45394539
<<
45404540
#ifdef _OMC_MEASURE_TIME
45414541
SIM_PROF_ACC_FN(<%funName%>_index);

0 commit comments

Comments
 (0)