Skip to content

Commit

Permalink
Added stringEmpty and arrayEmpty to MetaModelica.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 9, 2017
1 parent 0e625e9 commit c2054ff
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
16 changes: 5 additions & 11 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -566,7 +566,6 @@ algorithm
outString := matchcontinue (inVariableAttributesOption)
local
String quantity,unit_str,displayUnit_str,stateSel_str,min_str,max_str,nominal_str,initial_str,fixed_str,uncertainty_str,dist_str,res_1,res1,res,startOriginStr;
Boolean is_empty;
Option<DAE.Exp> quant,unit,displayUnit,min,max,initialExp,nominal,fixed,startOrigin;
Option<DAE.StateSelect> stateSel;
Option<DAE.Uncertainty> uncertainty;
Expand All @@ -591,8 +590,7 @@ algorithm
res_1 = Util.stringDelimitListNonEmptyElts(
{quantity,unit_str,displayUnit_str,min_str,max_str,
initial_str,fixed_str,nominal_str,stateSel_str,uncertainty_str,dist_str,startOriginStr}, ", ");
is_empty = Util.isEmptyString(res_1);
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;

Expand All @@ -609,8 +607,7 @@ algorithm
startOriginStr = getStartOrigin(startOrigin);

res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,uncertainty_str,dist_str,startOriginStr}, ", ");
is_empty = Util.isEmptyString(res_1);
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;

Expand All @@ -623,8 +620,7 @@ algorithm
startOriginStr = getStartOrigin(startOrigin);

res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
is_empty = Util.isEmptyString(res_1);
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;

Expand All @@ -636,8 +632,7 @@ algorithm
startOriginStr = getStartOrigin(startOrigin);

res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,startOriginStr}, ", ");
is_empty = Util.isEmptyString(res_1);
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;

Expand All @@ -652,8 +647,7 @@ algorithm
startOriginStr = getStartOrigin(startOrigin);

res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,startOriginStr}, ", ");
is_empty = Util.isEmptyString(res_1);
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;

Expand Down
16 changes: 16 additions & 0 deletions Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -490,6 +490,14 @@ function stringLength "O(1)"
external "builtin";
end stringLength;

function stringEmpty "O(1)"
input String str;
output Boolean isEmpty;
algorithm
isEmpty := stringLength(str) == 0;
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
end stringEmpty;

function stringGet "O(1)"
input String str;
input Integer index;
Expand Down Expand Up @@ -652,6 +660,14 @@ function arrayLength<A> "O(1)"
external "builtin";
end arrayLength;

function arrayEmpty<A> "O(1)"
input array<A> arr;
output Boolean isEmpty;
algorithm
isEmpty := arrayLength(str) == 0;
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
end arrayEmpty;

function arrayGet<A> "O(1)"
input array<A> arr;
input Integer index;
Expand Down
2 changes: 0 additions & 2 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -2264,7 +2264,6 @@ algorithm
case((DAE.NAMEMOD(id,m))::_,_)
equation
s2 = prettyPrintMod(m,depth+1);
s2 = if stringLength(s2) == 0 then "" else s2;
s2 = "(" + id + s2 + "), class or component " + id;
then
s2;
Expand Down Expand Up @@ -2297,7 +2296,6 @@ algorithm
case DAE.NAMEMOD(id,m)
equation
s2 = prettyPrintMod(m,0);
s2 = if stringLength(s2) == 0 then "" else s2;
s2 = id + s2;
then
s2;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -600,7 +600,7 @@ algorithm
cls := Config.classToInstantiate();
// If no class was explicitly specified, instantiate the last class in the
// program. Otherwise, instantiate the given class name.
cname := if stringLength(cls) == 0 then Absyn.lastClassname(program) else Absyn.stringPath(cls);
cname := if stringEmpty(cls) then Absyn.lastClassname(program) else Absyn.stringPath(cls);
st := GlobalScriptUtil.setSymbolTableAST(GlobalScript.emptySymboltable, program);
(cache, env, dae) := CevalScriptBackend.runFrontEnd(FCore.emptyCache(), FGraph.empty(), cname, st, true);
end instantiate;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -247,12 +247,12 @@ algorithm
// to the environment variable! Don't ask me why, ask Microsoft.
omhome := "set OPENMODELICAHOME=\"" + System.stringReplace(omhome_1, "/", "\\") + "\"&& ";
setMakeVars := sum("set "+var+"&& " for var in makeVarsNoBinding);
cdWorkingDir := if stringLength(workingDir) == 0 then "" else ("cd \"" + workingDir + "\"&& ");
cdWorkingDir := if stringEmpty(workingDir) then "" else ("cd \"" + workingDir + "\"&& ");
winCompileMode := if Config.getRunningTestsuite() then "serial" else "parallel";
s_call := stringAppendList({omhome,cdWorkingDir,setMakeVars,"\"",omhome_1,pd,"share",pd,"omc",pd,"scripts",pd,"Compile","\""," ",fileprefix," ",Config.simulationCodeTarget()," ", System.openModelicaPlatform(), " ", winCompileMode});
else
numParallel := if Config.getRunningTestsuite() then 1 else Config.noProc();
cdWorkingDir := if stringLength(workingDir) == 0 then "" else (" -C \"" + workingDir + "\"");
cdWorkingDir := if stringEmpty(workingDir) then "" else (" -C \"" + workingDir + "\"");
setMakeVars := sum(" "+var for var in makeVarsNoBinding);
s_call := stringAppendList({System.getMakeCommand()," -j",intString(numParallel),cdWorkingDir," -f ",fileprefix,".makefile",setMakeVars});
end if;
Expand Down
6 changes: 0 additions & 6 deletions Compiler/Util/Util.mo
Expand Up @@ -943,12 +943,6 @@ public function boolCompare
output Integer outResult = if inN == inM then 0 elseif inN > inM then 1 else -1;
end boolCompare;

public function isEmptyString
"Returns true if string is the empty string."
input String inString;
output Boolean outIsEmpty = stringLength(inString) == 0;
end isEmptyString;

public function isNotEmptyString "Returns true if string is not the empty string."
input String inString;
output Boolean outIsNotEmpty = stringLength(inString) > 0;
Expand Down

0 comments on commit c2054ff

Please sign in to comment.