Skip to content

Commit

Permalink
Added support for ModelicaStrings_compare, and fixed the ModelicaStri…
Browse files Browse the repository at this point in the history
…ngs_skipWhiteSpace implementation

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17755 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 18, 2013
1 parent c1beab1 commit 6b94399
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Compiler/FrontEnd/Ceval.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ algorithm
case ("ModelicaInternal_readLine") then ();
case ("ModelicaInternal_stat") then ();
case ("ModelicaInternal_fullPathName") then ();
case ("ModelicaStrings_compare") then ();
case ("ModelicaStrings_scanReal") then ();
case ("ModelicaStrings_skipWhiteSpace") then ();
case ("ModelicaError") then ();
Expand All @@ -1232,7 +1233,7 @@ algorithm
outValue := match (id,inValuesValueLst,inMsg)
local
Real rv_1,rv,rv1,rv2,sv,cv,r;
String str,fileName,re;
String str,fileName,re,str1,str2;
Integer start, stop, i, lineNumber, n;
Boolean b, extended, insensitive;
list<String> strs;
Expand Down Expand Up @@ -1354,12 +1355,18 @@ algorithm
v = Values.ENUM_LITERAL(p,i);
then v;

case ("ModelicaStrings_compare",{Values.STRING(str1),Values.STRING(str2),Values.BOOL(b)},_)
equation
i = ModelicaExternalC.Strings_compare(str1,str2,b);
p = listGet({EnumCompareLess,EnumCompareEqual,EnumCompareGreater},i);
then Values.ENUM_LITERAL(p,i);

case ("ModelicaStrings_scanReal",{Values.STRING(str),Values.INTEGER(i),Values.BOOL(b)},_)
equation
(i,r) = ModelicaExternalC.Strings_advanced_scanReal(str,i,b);
then Values.TUPLE({Values.INTEGER(i),Values.REAL(r)});

case ("ModelicaInternal_skipWhiteSpace",{Values.STRING(str),Values.INTEGER(i)},_)
case ("ModelicaStrings_skipWhiteSpace",{Values.STRING(str),Values.INTEGER(i)},_)
equation
i = ModelicaExternalC.Strings_advanced_skipWhiteSpace(str,i);
then Values.INTEGER(i);
Expand All @@ -1374,6 +1381,10 @@ algorithm
end match;
end cevalKnownExternalFuncs2;

protected constant Absyn.Path EnumCompareLess = Absyn.QUALIFIED("Modelica",Absyn.QUALIFIED("Utilities",Absyn.QUALIFIED("Types",Absyn.QUALIFIED("Compare",Absyn.IDENT("Less")))));
protected constant Absyn.Path EnumCompareEqual = Absyn.QUALIFIED("Modelica",Absyn.QUALIFIED("Utilities",Absyn.QUALIFIED("Types",Absyn.QUALIFIED("Compare",Absyn.IDENT("Equal")))));
protected constant Absyn.Path EnumCompareGreater = Absyn.QUALIFIED("Modelica",Absyn.QUALIFIED("Utilities",Absyn.QUALIFIED("Types",Absyn.QUALIFIED("Compare",Absyn.IDENT("Greater")))));

protected function cevalMatrixElt "Evaluates the expression of a matrix constructor, e.g. {1,2;3,4}"
input Env.Cache inCache;
input Env.Env inEnv;
Expand Down
9 changes: 9 additions & 0 deletions Compiler/Util/ModelicaExternalC.mo
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ function Streams_close
external "C" ModelicaStreams_closeFile(fileName) annotation(Library="ModelicaExternalC");
end Streams_close;

function Strings_compare
input String string1;
input String string2;
input Boolean caseSensitive;
output Integer result;

external "C" result=ModelicaStrings_compare(string1,string2,caseSensitive) annotation(Library = "ModelicaExternalC");
end Strings_compare;

function Strings_advanced_scanReal
input String string;
input Integer startIndex;
Expand Down
16 changes: 16 additions & 0 deletions Compiler/runtime/ModelicaExternalC_rml.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int ModelicaInternal_countLines(const char*);
const char* ModelicaInternal_fullPathName(const char*);
int ModelicaInternal_stat(const char*);
void ModelicaStreams_closeFile(const char*);
int ModelicaStrings_compare(const char*,const char*,int);
void ModelicaStrings_scanReal(const char*,int,int,int*,double*);
int ModelicaStrings_skipWhiteSpace(const char*,int);

Expand Down Expand Up @@ -141,6 +142,21 @@ RML_BEGIN_LABEL(ModelicaExternalC__Streams_5fclose)
}
RML_END_LABEL

RML_BEGIN_LABEL(ModelicaExternalC__Strings_5fcompare)
{
char* str1 = RML_STRINGDATA(rmlA0);
char* str2 = RML_STRINGDATA(rmlA1);
int i = RML_UNTAGFIXNUM(rmlA2), fail = 1;
MMC_TRY_TOP();
i = ModelicaStrings_compare(str1,str2,i);
fail = 0;
MMC_CATCH_TOP();
if (fail) RML_TAILCALLK(rmlFC);
rmlA0 = mk_icon(i);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(ModelicaExternalC__Strings_5fadvanced_5fscanReal)
{
char* str = RML_STRINGDATA(rmlA0);
Expand Down

0 comments on commit 6b94399

Please sign in to comment.