Skip to content

Commit

Permalink
- Added System.stringFindString (same as System.findString, but retur…
Browse files Browse the repository at this point in the history
…ns the found String instead of an index).

- Modified Error.mo to look for the +d=rtest flag.
  - If the flag is present, you look for "/testsuite/" in the filename string, and print the path relative to /testsuite/.
  - Updated the msl221 and biochem rtest files to use this flag.
  - Updated the PID_Controller.mos testcase so you don't have to run the testsuite from c:/petar/dev/... in order to get the same error messages.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5225 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 26, 2010
1 parent 24b928b commit 7f3cf54
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
31 changes: 28 additions & 3 deletions Compiler/Error.mo
Expand Up @@ -548,6 +548,8 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
protected import ErrorExt;
protected import Util;
protected import Print;
protected import RTOpts;
protected import System;

public function updateCurrentComponent "Function: updateCurrentComponent
This function takes a String and set the global var to which the current variable the
Expand All @@ -557,10 +559,11 @@ compiler is working with.
input Option<Absyn.Info> info;
algorithm _ :=
matchcontinue (component, info)
local String s1; Integer i1,i2,i3,i4; Boolean b1;
case(component,SOME(Absyn.INFO(s1,b1,i1,i2,i3,i4,_)))
local String filename; Integer i1,i2,i3,i4; Boolean b1;
case(component,SOME(Absyn.INFO(filename,b1,i1,i2,i3,i4,_)))
equation
ErrorExt.updateCurrentComponent(component,b1,s1,i1,i3,i2,i4);
filename = fixFilenameForTestsuite(filename);
ErrorExt.updateCurrentComponent(component,b1,filename,i1,i3,i2,i4);
then ();
case(component,NONE)
equation
Expand Down Expand Up @@ -613,6 +616,9 @@ public function addSourceMessage "function: addSourceMessage

Adds a message given ID, tokens and source file info.
The rest of the info is looked up in the message table.
Not used 2010-03-26. I'll keep it here in case MathCore uses it,
but changes made here do not fix things in OpenModelica!
"
input ErrorID inErrorID;
input MessageTokens inMessageTokens;
Expand Down Expand Up @@ -887,6 +893,7 @@ algorithm
ErrorID sline,scol,eline,ecol;
case (Absyn.INFO(fileName = filename,isReadOnly = isReadOnly,lineNumberStart = sline,columnNumberStart = scol,lineNumberEnd = eline,columnNumberEnd = ecol))
equation
filename = fixFilenameForTestsuite(filename);
s1 = selectString(isReadOnly, "readonly", "writable");
sline_str = intString(sline);
scol_str = intString(scol);
Expand All @@ -899,5 +906,23 @@ algorithm
res;
end matchcontinue;
end infoStr;

protected function fixFilenameForTestsuite
"Updates the filename if it is used within the testsuite.
This ensures that error messages use the same filename for
everyone running the testsuite."
input String filename;
output String outFilename;
algorithm
outFilename := matchcontinue filename
case filename
equation
true = RTOpts.debugFlag("rtest");
filename = System.stringFindString(filename, "/testsuite/");
then filename;
case filename then filename;
end matchcontinue;
end fixFilenameForTestsuite;

end Error;

8 changes: 8 additions & 0 deletions Compiler/System.mo
Expand Up @@ -78,6 +78,14 @@ public function stringFind "locates substring searchStr in str. If succeeds retu
external "C" ;
end stringFind;

public function stringFindString "locates substring searchStr in str. If succeeds return the string, otherwise fail"
input String str;
input String searchStr;
output String outString;

external "C";
end stringFindString;

public function strncmp
input String inString1;
input String inString2;
Expand Down
48 changes: 45 additions & 3 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -507,6 +507,27 @@ RML_BEGIN_LABEL(System__stringFind)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__stringFindString)
{
char *str = RML_STRINGDATA(rmlA0);
char *searchStr = RML_STRINGDATA(rmlA1);
int strLen = strlen(str);
int strSearchLen = strlen(searchStr);
int i,retVal=-1;

for (i=0; i< strLen - strSearchLen+1; i++) {
if (strncmp(&str[i],searchStr,strSearchLen) == 0) {
retVal = i;
break;
}
}
if (retVal == -1)
RML_TAILCALLK(rmlFC);
rmlA0 = (void*) mk_scon(str+retVal);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__strncmp)
{
char *str = RML_STRINGDATA(rmlA0);
Expand Down Expand Up @@ -2254,6 +2275,27 @@ RML_BEGIN_LABEL(System__stringFind)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__stringFindString)
{
char *str = RML_STRINGDATA(rmlA0);
char *searchStr = RML_STRINGDATA(rmlA1);
int strLen = strlen(str);
int strSearchLen = strlen(searchStr);
int i,retVal=-1;

for (i=0; i< strLen - strSearchLen+1; i++) {
if (strncmp(&str[i],searchStr,strSearchLen) == 0) {
retVal = i;
break;
}
}
if (retVal == -1)
RML_TAILCALLK(rmlFC);
rmlA0 = (void*) mk_scon(str+retVal);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__strncmp)
{
char *str = RML_STRINGDATA(rmlA0);
Expand Down Expand Up @@ -2927,7 +2969,7 @@ RML_END_LABEL
inline RML_BEGIN_LABEL(System__hash)
{
char *str = RML_STRINGDATA(rmlA0);
int hash=0, c=0;
long hash=0, c=0;
while( c = *str++ ) hash +=c;
rmlA0 = RML_IMMEDIATE(RML_TAGFIXNUM(hash));
RML_TAILCALLK(rmlSC);
Expand Down Expand Up @@ -3333,9 +3375,9 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setDataPort)
{
int port = RML_UNTAGFIXNUM(rmlA0);
long port = RML_UNTAGFIXNUM(rmlA0);
char* p = malloc(10);
sprintf(p, "%s", port);
sprintf(p, "%s", (char*) port);
setenv("sendDataPort", p, 1 /* overwrite */);
free(p);
setDataPort(port);
Expand Down

0 comments on commit 7f3cf54

Please sign in to comment.