Skip to content

Commit

Permalink
- emit an error when trying to simulate a model that doesn't exist
Browse files Browse the repository at this point in the history
- fixed bug with min/max code generation:
  http://openmodelica.ida.liu.se:8080/cb/issue/1032


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3822 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Jan 27, 2009
1 parent 22d6852 commit 31e7fd4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Compiler/Ceval.mo
Expand Up @@ -1945,6 +1945,25 @@ algorithm
compiledFunctions = cf)),msg) /* failing build_model */
then (cache,Values.ARRAY({Values.STRING(""),Values.STRING("")}),st_1);

/* adrpo: see if the model exists before simulation! */
case (cache,env,(exp as
Exp.CALL(path = Absyn.IDENT(name = "simulate"),
expLst = {Exp.CODE(Absyn.C_TYPENAME(className),_),starttime,stoptime,interval,tolerance,method,filenameprefix,storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(
ast = p, explodedAst = sp, instClsLst = ic, lstVarVal = iv, compiledFunctions = cf)),msg)
local
Absyn.ComponentRef crefCName;
String errMsg;
equation
crefCName = Absyn.pathToCref(className);
false = Interactive.existClass(crefCName, p);
errMsg = "Simulation Failed. Model: " +& Absyn.pathString(className) +& " does not exists! Please load it first before simulation.";
simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),
{Values.STRING(errMsg)},
{"resultFile"});
then
(cache,simValue,st_1);

case (cache,env,(exp as
Exp.CALL(
path = Absyn.IDENT(name = "simulate"),
Expand Down Expand Up @@ -2005,7 +2024,7 @@ algorithm
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg)
local String errorStr, error;
local String errorStr, error;
equation
omhome = Settings.getInstallationDirectoryPath() "simulation fail for some other reason than OPENMODELICAHOME not being set." ;
errorStr = Error.printMessagesStr();
Expand Down
28 changes: 27 additions & 1 deletion Compiler/Codegen.mo
Expand Up @@ -4410,7 +4410,33 @@ algorithm
(cfn1,var2,tnr2) = generateExpression(s2, tnr1, context);
(tdecl,tvar,tnr3) = generateTempDecl(tp_str, tnr2);
cfn2 = cAddVariables(cfn1, {tdecl});
stmt = Util.stringAppendList({tvar," = max(",var1,",",var2,");"});
stmt = Util.stringAppendList({tvar," = max(((modelica_real)(",var1,")),((modelica_real)(",var2,")));"});
cfn = cAddStatements(cfn2, {stmt});
then
(cfn,tvar,tnr3);
/* min */
case (Exp.CALL(path = Absyn.IDENT(name = "min"),expLst = {arg},tuple_ = false,builtin = true),tnr,context) /* min(v), v is vector */
equation
tp = Exp.typeof(arg);
tp_str = expTypeStr(tp, true);
tp_str2 = expTypeStr(tp, false);
(cfn1,var1,tnr1) = generateExpression(arg, tnr, context);
fn_name = stringAppend("min_", tp_str);
(tdecl,tvar,tnr2) = generateTempDecl(tp_str2, tnr1);
cfn2 = cAddVariables(cfn1, {tdecl});
stmt = Util.stringAppendList({tvar," = ",fn_name,"(&",var1,");"});
cfn = cAddStatements(cfn2, {stmt});
then
(cfn,tvar,tnr2);
case (Exp.CALL(path = Absyn.IDENT(name = "min"),expLst = {s1,s2},tuple_ = false,builtin = true),tnr,context) /* min (a,b) a, b scalars */
equation
tp = Exp.typeof(s1);
tp_str = expTypeStr(tp, false);
(cfn1,var1,tnr1) = generateExpression(s1, tnr, context);
(cfn1,var2,tnr2) = generateExpression(s2, tnr1, context);
(tdecl,tvar,tnr3) = generateTempDecl(tp_str, tnr2);
cfn2 = cAddVariables(cfn1, {tdecl});
stmt = Util.stringAppendList({tvar," = min(((modelica_real)(",var1,")),((modelica_real)(",var2,")));"});
cfn = cAddStatements(cfn2, {stmt});
then
(cfn,tvar,tnr3);
Expand Down
11 changes: 11 additions & 0 deletions Compiler/Interactive.mo
Expand Up @@ -8566,6 +8566,17 @@ algorithm
_ = getPathedClassInProgram(path, p);
then
true;
case (cr,p)
equation
failure(path = Absyn.crefToPath(cr));
then
false;
case (cr,p)
equation
path = Absyn.crefToPath(cr);
failure(_ = getPathedClassInProgram(path, p));
then
false;
case (cr,p) then false;
end matchcontinue;
end existClass;
Expand Down

0 comments on commit 31e7fd4

Please sign in to comment.