Skip to content

Commit

Permalink
Fix DAEUtil.getStartAttr for the new frontend (#8749)
Browse files Browse the repository at this point in the history
- Use the type to get the default start attributes when no start
  attribute is given, since the new frontend doesn't create
  VariableAttributes records for variables with no attributes.

Fixes #8743
  • Loading branch information
perost committed Mar 23, 2022
1 parent e6cb23e commit dac4475
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
36 changes: 21 additions & 15 deletions OMCompiler/Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -900,26 +900,32 @@ algorithm
end match;
end setMinMax;

public function getTypeDefaultStart

end getTypeDefaultStart;

public function getStartAttr "
Return the start attribute."
input Option<DAE.VariableAttributes> inVariableAttributesOption;
input Option<DAE.VariableAttributes> inAttributes;
input DAE.Type inType;
output DAE.Exp start;
protected
DAE.Exp e;
algorithm
start := match inVariableAttributesOption
local
DAE.Exp r;
case SOME(DAE.VAR_ATTR_REAL(start = SOME(r))) then r;
case SOME(DAE.VAR_ATTR_REAL(start = NONE())) then DAE.RCONST(0.0);
case SOME(DAE.VAR_ATTR_INT(start = SOME(r))) then r;
case SOME(DAE.VAR_ATTR_INT(start = NONE())) then DAE.ICONST(0);
case SOME(DAE.VAR_ATTR_BOOL(start = SOME(r))) then r;
case SOME(DAE.VAR_ATTR_BOOL(start = NONE())) then DAE.BCONST(false);
case SOME(DAE.VAR_ATTR_STRING(start = SOME(r))) then r;
case SOME(DAE.VAR_ATTR_STRING(start = NONE())) then DAE.SCONST("");
case SOME(DAE.VAR_ATTR_ENUMERATION(start = SOME(r))) then r;
case SOME(DAE.VAR_ATTR_ENUMERATION(start = NONE())) then Types.getNthEnumLiteral(inType, 1);
else DAE.RCONST(0.0);
start := match inAttributes
case SOME(DAE.VAR_ATTR_REAL(start = SOME(e))) then e;
case SOME(DAE.VAR_ATTR_INT(start = SOME(e))) then e;
case SOME(DAE.VAR_ATTR_BOOL(start = SOME(e))) then e;
case SOME(DAE.VAR_ATTR_STRING(start = SOME(e))) then e;
case SOME(DAE.VAR_ATTR_ENUMERATION(start = SOME(e))) then e;
else
match Types.getBasicType(inType)
case DAE.Type.T_INTEGER() then DAE.ICONST(0);
case DAE.Type.T_STRING() then DAE.SCONST("");
case DAE.Type.T_BOOL() then DAE.BCONST(false);
case DAE.Type.T_ENUMERATION() then Types.getNthEnumLiteral(inType, 1);
else DAE.RCONST(0.0);
end match;
end match;
end getStartAttr;

Expand Down
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/FrontEnd/Types.mo
Expand Up @@ -8722,5 +8722,16 @@ algorithm
end match;
end isExpandableConnector;

public function getBasicType
input DAE.Type ty;
output DAE.Type outType;
algorithm
outType := match ty
case DAE.Type.T_ARRAY() then getBasicType(ty.ty);
case DAE.Type.T_SUBTYPE_BASIC() then getBasicType(ty.complexType);
else ty;
end match;
end getBasicType;

annotation(__OpenModelica_Interface="frontend");
end Types;
Expand Up @@ -3,7 +3,6 @@
// status: correct
// cflags:
// teardown_command: rm -rf initializationTests.parameters* _initializationTests.parameters* output.log
// cflags: -d=-newInst

loadString("
within ;
Expand Down

0 comments on commit dac4475

Please sign in to comment.