Skip to content

Commit

Permalink
Add debug flag +d=acceptTooManyFields
Browse files Browse the repository at this point in the history
- The flag is disabled by default, and will accept calling a function with a record that has more fields than expected
- This behaviour is considered breaking the Modelica spec in m:#1245
- The flag makes Fluid.Dissipation work again, and it is the default for library testing until Fluid.Dissipation is updated


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21097 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 13, 2014
1 parent 51fbb1e commit 31a18ed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Types.mo
Expand Up @@ -4560,7 +4560,7 @@ algorithm
case (e, DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(p1),varLst = els1), t2 as DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(p2),varLst = els2),_)
equation
false = Absyn.pathEqual(p1,p2) "We need to add a cast from one record to another";
true = listLength(els1) == listLength(els2);
true = Flags.isSet(Flags.ALLOW_RECORD_TOO_MANY_FIELDS) or (listLength(els1) == listLength(els2));
true = subtypeVarlist(els1, els2);
e = DAE.CAST(t2, e);
then (e, t2);
Expand Down
18 changes: 10 additions & 8 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -9015,14 +9015,16 @@ case CAST(__) then
let from = expTypeFromExpShort(exp)
let &preExp += 'cast_<%from%>_array_to_<%to%>(&<%expVar%>, &<%tvar%>);<%\n%>'
'<%tvar%>'
case T_COMPLEX(complexClassType=rec as RECORD(__)) then
/*
// TODO: Unify all records with the same fields into a single typedef so we don't need this
let tmp = tempDecl(expTypeFromExpModelica(exp),&varDecls)
let &preExp += '<%tmp%> = <%expVar%>;<%\n%>'
'(*((<%underscorePath(rec.path)%>*)&<%tmp%>))'
*/
expVar
case ty1 as T_COMPLEX(complexClassType=rec as RECORD(__)) then
match typeof(exp)
case ty2 as T_COMPLEX(__) then
if intEq(listLength(ty1.varLst),listLength(ty2.varLst)) then expVar
else
let tmp = tempDecl(expTypeModelica(ty2),&varDecls)
let res = tempDecl(expTypeModelica(ty1),&varDecls)
let &preExp += '<%tmp%> = <%expVar%>;<%\n%>'
let &preExp += ty1.varLst |> var as DAE.TYPES_VAR() => '<%res%>._<%var.name%> = <%tmp%>._<%var.name%>;<%\n%>'
res
else
'(<%expVar%>) /* could not cast, using the variable as it is */'
end daeExpCast;
Expand Down
5 changes: 4 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -389,6 +389,8 @@ constant DebugFlag PRINT_STRUCTURAL = DEBUG_FLAG(111, "printStructuralParameters
Util.gettext("Prints the structural parameters identified by the front-end"));
constant DebugFlag ITERATION_VARS = DEBUG_FLAG(112, "iterationVars", false,
Util.gettext("Shows a list of all iteration variables."));
constant DebugFlag ALLOW_RECORD_TOO_MANY_FIELDS = DEBUG_FLAG(113, "acceptTooManyFields", false,
Util.gettext("Accepts passing records with more fields than expected to a function. This is not allowed, but is used in Fluid.Dissipation. See https://trac.modelica.org/Modelica/ticket/1245 for details."));

// This is a list of all debug flags, to keep track of which flags are used. A
// flag can not be used unless it's in this list, and the list is checked at
Expand Down Expand Up @@ -506,7 +508,8 @@ constant list<DebugFlag> allDebugFlags = {
IMPL_ODE,
EVAL_FUNC_DUMP,
PRINT_STRUCTURAL,
ITERATION_VARS
ITERATION_VARS,
ALLOW_RECORD_TOO_MANY_FIELDS
};

// CONFIGURATION FLAGS
Expand Down
4 changes: 2 additions & 2 deletions Examples/BuildModelRecursive.mos
Expand Up @@ -2,7 +2,7 @@

setCommandLineOptions("+d=nogen");
if not regularFileExists("CustomCommands.mos") then
customCommands := "setCommandLineOptions(\"+d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection\");
customCommands := "setCommandLineOptions(\"+d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection,acceptTooManyFields\");
setMatchingAlgorithm(\"PFPlusExt\");
setIndexReductionMethod(\"dynamicStateSelection\");";
writeFile("CustomCommands.mos",customCommands);
Expand All @@ -22,7 +22,7 @@ simFlags := "-abortSlowSimulation -alarm=" + ulimitExe;
runScript("CustomCommands.mos");

customCommandsStr := if regularFileExists("CustomCommands.mos") then ("Flags: <pre>" + escapeXML(readFile("CustomCommands.mos")) + "</pre>") else "";
library:=$TypeName(Modelica);
library:=$TypeName(ModelicaTest.Fluid.Dissipation.Verifications.HeatTransfer.StraightPipe.kc_overall);
libraryVersion:="default";

setCommandLineOptions({"+g=Modelica","+d=nogen"});
Expand Down

0 comments on commit 31a18ed

Please sign in to comment.