Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit c2054ff

Browse files
perostOpenModelica-Hudson
authored andcommitted
Added stringEmpty and arrayEmpty to MetaModelica.
1 parent 0e625e9 commit c2054ff

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

Compiler/FrontEnd/DAEDump.mo

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ algorithm
566566
outString := matchcontinue (inVariableAttributesOption)
567567
local
568568
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;
569-
Boolean is_empty;
570569
Option<DAE.Exp> quant,unit,displayUnit,min,max,initialExp,nominal,fixed,startOrigin;
571570
Option<DAE.StateSelect> stateSel;
572571
Option<DAE.Uncertainty> uncertainty;
@@ -591,8 +590,7 @@ algorithm
591590
res_1 = Util.stringDelimitListNonEmptyElts(
592591
{quantity,unit_str,displayUnit_str,min_str,max_str,
593592
initial_str,fixed_str,nominal_str,stateSel_str,uncertainty_str,dist_str,startOriginStr}, ", ");
594-
is_empty = Util.isEmptyString(res_1);
595-
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
593+
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
596594
then
597595
res;
598596

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

611609
res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,uncertainty_str,dist_str,startOriginStr}, ", ");
612-
is_empty = Util.isEmptyString(res_1);
613-
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
610+
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
614611
then
615612
res;
616613

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

625622
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
626-
is_empty = Util.isEmptyString(res_1);
627-
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
623+
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
628624
then
629625
res;
630626

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

638634
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,startOriginStr}, ", ");
639-
is_empty = Util.isEmptyString(res_1);
640-
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
635+
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
641636
then
642637
res;
643638

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

654649
res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,startOriginStr}, ", ");
655-
is_empty = Util.isEmptyString(res_1);
656-
res = if is_empty then "" else stringAppendList({"(",res_1,")"});
650+
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
657651
then
658652
res;
659653

Compiler/FrontEnd/MetaModelicaBuiltin.mo

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ function stringLength "O(1)"
490490
external "builtin";
491491
end stringLength;
492492

493+
function stringEmpty "O(1)"
494+
input String str;
495+
output Boolean isEmpty;
496+
algorithm
497+
isEmpty := stringLength(str) == 0;
498+
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
499+
end stringEmpty;
500+
493501
function stringGet "O(1)"
494502
input String str;
495503
input Integer index;
@@ -652,6 +660,14 @@ function arrayLength<A> "O(1)"
652660
external "builtin";
653661
end arrayLength;
654662

663+
function arrayEmpty<A> "O(1)"
664+
input array<A> arr;
665+
output Boolean isEmpty;
666+
algorithm
667+
isEmpty := arrayLength(str) == 0;
668+
annotation(__OpenModelica_EarlyInline = true, __OpenModelica_BuiltinPtr = true);
669+
end arrayEmpty;
670+
655671
function arrayGet<A> "O(1)"
656672
input array<A> arr;
657673
input Integer index;

Compiler/FrontEnd/Mod.mo

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,6 @@ algorithm
22642264
case((DAE.NAMEMOD(id,m))::_,_)
22652265
equation
22662266
s2 = prettyPrintMod(m,depth+1);
2267-
s2 = if stringLength(s2) == 0 then "" else s2;
22682267
s2 = "(" + id + s2 + "), class or component " + id;
22692268
then
22702269
s2;
@@ -2297,7 +2296,6 @@ algorithm
22972296
case DAE.NAMEMOD(id,m)
22982297
equation
22992298
s2 = prettyPrintMod(m,0);
2300-
s2 = if stringLength(s2) == 0 then "" else s2;
23012299
s2 = id + s2;
23022300
then
23032301
s2;

Compiler/Main/Main.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ algorithm
600600
cls := Config.classToInstantiate();
601601
// If no class was explicitly specified, instantiate the last class in the
602602
// program. Otherwise, instantiate the given class name.
603-
cname := if stringLength(cls) == 0 then Absyn.lastClassname(program) else Absyn.stringPath(cls);
603+
cname := if stringEmpty(cls) then Absyn.lastClassname(program) else Absyn.stringPath(cls);
604604
st := GlobalScriptUtil.setSymbolTableAST(GlobalScript.emptySymboltable, program);
605605
(cache, env, dae) := CevalScriptBackend.runFrontEnd(FCore.emptyCache(), FGraph.empty(), cname, st, true);
606606
end instantiate;

Compiler/Script/CevalScript.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ algorithm
247247
// to the environment variable! Don't ask me why, ask Microsoft.
248248
omhome := "set OPENMODELICAHOME=\"" + System.stringReplace(omhome_1, "/", "\\") + "\"&& ";
249249
setMakeVars := sum("set "+var+"&& " for var in makeVarsNoBinding);
250-
cdWorkingDir := if stringLength(workingDir) == 0 then "" else ("cd \"" + workingDir + "\"&& ");
250+
cdWorkingDir := if stringEmpty(workingDir) then "" else ("cd \"" + workingDir + "\"&& ");
251251
winCompileMode := if Config.getRunningTestsuite() then "serial" else "parallel";
252252
s_call := stringAppendList({omhome,cdWorkingDir,setMakeVars,"\"",omhome_1,pd,"share",pd,"omc",pd,"scripts",pd,"Compile","\""," ",fileprefix," ",Config.simulationCodeTarget()," ", System.openModelicaPlatform(), " ", winCompileMode});
253253
else
254254
numParallel := if Config.getRunningTestsuite() then 1 else Config.noProc();
255-
cdWorkingDir := if stringLength(workingDir) == 0 then "" else (" -C \"" + workingDir + "\"");
255+
cdWorkingDir := if stringEmpty(workingDir) then "" else (" -C \"" + workingDir + "\"");
256256
setMakeVars := sum(" "+var for var in makeVarsNoBinding);
257257
s_call := stringAppendList({System.getMakeCommand()," -j",intString(numParallel),cdWorkingDir," -f ",fileprefix,".makefile",setMakeVars});
258258
end if;

Compiler/Util/Util.mo

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,6 @@ public function boolCompare
943943
output Integer outResult = if inN == inM then 0 elseif inN > inM then 1 else -1;
944944
end boolCompare;
945945

946-
public function isEmptyString
947-
"Returns true if string is the empty string."
948-
input String inString;
949-
output Boolean outIsEmpty = stringLength(inString) == 0;
950-
end isEmptyString;
951-
952946
public function isNotEmptyString "Returns true if string is not the empty string."
953947
input String inString;
954948
output Boolean outIsNotEmpty = stringLength(inString) > 0;

0 commit comments

Comments
 (0)