Skip to content

Commit

Permalink
-Added error message for circular equations (typically x=x) and loggi…
Browse files Browse the repository at this point in the history
…ng of selected states (both used by MathModelica backend).

-Inserted option to OptManager "logSelectedStates" which is by default turned off.
-Implemented getNumMessages that returns the number of messages in the message queue.

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@4031 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed May 12, 2009
1 parent b900647 commit d3c4037
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
13 changes: 12 additions & 1 deletion Compiler/Error.mo
Expand Up @@ -195,6 +195,7 @@ public constant ErrorID MISSING_INNER_PREFIX = 108;
public constant ErrorID CONNECT_STREAM_TO_NONSTREAM=109;
public constant ErrorID IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY=110;
public constant ErrorID STRUCT_SINGULAR_SYSTEM_INITIALIZATION=111;
public constant ErrorID CIRCULAR_EQUATION=112;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
public constant ErrorID BUILTIN_FUNCTION_SUM_HAS_SCALAR_PARAMETER=501;
public constant ErrorID BUILTIN_FUNCTION_PRODUCT_HAS_SCALAR_PARAMETER=502;
Expand All @@ -211,6 +212,7 @@ public constant ErrorID OUTER_MODIFICATION=512;
public constant ErrorID REDUNDANT_GUESS=513 "Used by MathCore in Backend";
public constant ErrorID DERIVATIVE_NON_REAL=514;
public constant ErrorID UNUSED_MODIFIER=515;
public constant ErrorID SELECTED_STATES=515;


public constant ErrorID INDEX_REDUCTION_NOTIFICATION=1000;
Expand Down Expand Up @@ -472,7 +474,10 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY,TRANSLATION(),ERROR(),
"Identificator %s of implicit for iterator must be present as array subscript in the loop body."),
(STRUCT_SINGULAR_SYSTEM_INITIALIZATION,TRANSLATION(),ERROR(),
"The initialization problem of model is structurally singular, error found sorting equations %s for variables %s")
"The initialization problem of model is structurally singular, error found sorting equations %s for variables %s"),
(CIRCULAR_EQUATION, TRANSLATION(),ERROR(), " Equation : '%s' has circular references for variable %s."),
(SELECTED_STATES,TRANSLATION(),NOTIFICATION(), "The following variables are selected as states: %s")

};

protected import ErrorExt;
Expand Down Expand Up @@ -634,6 +639,12 @@ algorithm
ErrorExt.clearMessages();
end clearMessages;

public function getNumMessages "Returns the number of messages in the message queue"
output Integer num;
algorithm
num := ErrorExt.getNumMessages();
end getNumMessages;

public function getMessagesStr "Relations for interactive comm. These returns the messages as an array
of strings, suitable for sending to clients like model editor, MDT, etc.

Expand Down
6 changes: 6 additions & 0 deletions Compiler/ErrorExt.mo
Expand Up @@ -85,6 +85,12 @@ public function printMessagesStr
external "C" ;
end printMessagesStr;

public function getNumMessages
output Integer num;

external "C";
end getNumMessages;

public function getMessagesStr
output String outString;

Expand Down
9 changes: 9 additions & 0 deletions Compiler/Exp.mo
Expand Up @@ -1072,6 +1072,7 @@ protected import Dump;
protected import Debug;
protected import Static;
protected import Env;
protected import System;

protected constant Exp rconstone=RCONST(1.0);

Expand Down Expand Up @@ -1230,6 +1231,14 @@ algorithm
end matchcontinue;
end pathToCref;

public function crefSortFunc "A sorting function (greatherThan) for crefs"
input ComponentRef cr1;
input ComponentRef cr2;
output Boolean greaterThan;
algorithm
greaterThan := System.strcmp(printComponentRefStr(cr1),printComponentRefStr(cr2)) > 0;
end crefSortFunc;

public function crefStr
"function: crefStr
This function simply converts a ComponentRef to a String."
Expand Down
63 changes: 35 additions & 28 deletions Compiler/runtime/errorext.cpp
Expand Up @@ -51,7 +51,7 @@ extern "C" {
{
std::list<std::string> tokens;
for (int i=nTokens-1; i>=0; i--) {
tokens.push_back(std::string(ctokens[i]));
tokens.push_back(std::string(ctokens[i]));
}
add_message(errorID,type,severity,message,tokens);
}
Expand All @@ -70,15 +70,15 @@ bool error_on=true;
#include "ErrorMessage.hpp"
std::string currVariable("");
absyn_info finfo;
bool haveInfo(false);
bool haveInfo(false);
queue<ErrorMessage*> errorMessageQueue; // Global variable of all error messages.
vector<int> checkPoints;
/* Adds a message without file info. */
void add_message(int errorID,
char* type,
char* severity,
char* message,
std::list<std::string> tokens)
std::list<std::string> tokens)
{
std::string tmp("");
if(currVariable.length()>0){
Expand All @@ -89,7 +89,7 @@ bool error_on=true;
}
if(!haveInfo){
ErrorMessage *msg = new ErrorMessage((long)errorID, std::string(type ), std::string(severity), /*std::string(message),*/ tmp, tokens);
if (errorMessageQueue.empty() ||
if (errorMessageQueue.empty() ||
(!errorMessageQueue.empty() && errorMessageQueue.back()->getFullMessage() != msg->getFullMessage())) {
/*std::cerr << "inserting error message "<< msg.getFullMessage() << " on variable "<< currVariable << std::endl;*/
errorMessageQueue.push(msg);
Expand All @@ -98,15 +98,15 @@ bool error_on=true;
else{
ErrorMessage *msg = new ErrorMessage((long)errorID, std::string(type ), std::string(severity), /*std::string(message),*/ tmp, tokens,
finfo.rs,finfo.cs,finfo.re,finfo.ce,finfo.wr/*not important?*/,finfo.fn);
if (errorMessageQueue.empty() ||

if (errorMessageQueue.empty() ||
(!errorMessageQueue.empty() && errorMessageQueue.back()->getFullMessage() != msg->getFullMessage())) {
/*std::cerr << "inserting error message "<< msg.getFullMessage() << " on variable "<< currVariable << std::endl;
std::cerr << "values: " << finfo.rs << " " << finfo.ce << std::endl;*/
std::cerr << "values: " << finfo.rs << " " << finfo.ce << std::endl;*/
errorMessageQueue.push(msg);
}
}
}
}
/* sets the current_variable(which is beeing instantiated) */
void update_current_component(char* newVar,bool wr, char* fn, int rs, int re, int cs, int ce)
{
Expand All @@ -119,7 +119,7 @@ bool error_on=true;
finfo.re = re;
finfo.cs = cs;
finfo.ce = ce;
haveInfo = true;
haveInfo = true;
}
else
{haveInfo = false;}
Expand Down Expand Up @@ -148,7 +148,7 @@ bool error_on=true;
(long)endCol,
isReadOnly,
std::string(filename));
if (errorMessageQueue.empty() ||
if (errorMessageQueue.empty() ||
(!errorMessageQueue.empty() && errorMessageQueue.back()->getFullMessage() != msg->getFullMessage())) {
/*std::cerr << "inserting error message "<< msg.getFullMessage() << std::endl;*/
errorMessageQueue.push(msg);
Expand All @@ -161,25 +161,25 @@ extern "C"

#include <assert.h>
#include "rml.h"


void ErrorExt_5finit(void)
{
// empty the queue.
while(!errorMessageQueue.empty()) {
while(!errorMessageQueue.empty()) {
delete errorMessageQueue.front();
errorMessageQueue.pop();
}
}
RML_BEGIN_LABEL(ErrorExt__setCheckpoint)
{
{
checkPoints.push_back(errorMessageQueue.size());
//printf(" ERROREXT: setting checkpoint: %d\n",errorMessageQueue.size());
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
RML_BEGIN_LABEL(ErrorExt__delCheckpoint)
{
{
if(checkPoints.size() > 0){
//printf(" ERROREXT: deleting checkpoint: %d\n", checkPoints[checkPoints.size()-1]);
checkPoints.pop_back();
Expand All @@ -191,19 +191,19 @@ extern "C"
}
RML_END_LABEL
RML_BEGIN_LABEL(ErrorExt__rollBack)
{
{
if(checkPoints.size() > 0){
//printf(" ERROREXT: rollback to: %d from %d\n",checkPoints.back(),errorMessageQueue.size());
/*std::string res("");
if(!errorMessageQueue.empty())
res = res+errorMessageQueue.front()->getMessage()+string("\n");
printf(res.c_str());*/
//printf(" rollback from: %d to: %d\n",errorMessageQueue.size(),checkPoints.back());
while(errorMessageQueue.size() > checkPoints.back() && errorMessageQueue.size() > 0){
while(errorMessageQueue.size() > checkPoints.back() && errorMessageQueue.size() > 0){
//printf("*** %d deleted %d ***\n",errorMessageQueue.size(),checkPoints.back());
errorMessageQueue.pop();
}

checkPoints.pop_back();
}
RML_TAILCALLK(rmlSC);
Expand Down Expand Up @@ -231,7 +231,7 @@ extern "C"
int re = RML_UNTAGFIXNUM(rmlA4);
int cs = RML_UNTAGFIXNUM(rmlA5);
int ce = RML_UNTAGFIXNUM(rmlA6);
update_current_component(newVar,write,fileName,rs,re,cs,ce);
update_current_component(newVar,write,fileName,rs,re,cs,ce);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand All @@ -252,7 +252,7 @@ extern "C"
add_message(errorID,tp,severity,message,tokens);
}
RML_TAILCALLK(rmlSC);
}
}
RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__addSourceMessage)
Expand All @@ -264,22 +264,29 @@ extern "C"
int scol = RML_UNTAGFIXNUM(rmlA4);
int eline = RML_UNTAGFIXNUM(rmlA5);
int ecol = RML_UNTAGFIXNUM(rmlA6);
bool isReadOnly = RML_UNTAGFIXNUM(rmlA7)?true:false;
bool isReadOnly = RML_UNTAGFIXNUM(rmlA7)?true:false;
char* filename = RML_STRINGDATA(rmlA8);
char* message = RML_STRINGDATA(rmlA9);
void* tokenlst = rmlA10;
std::list<std::string> tokens;

if (error_on) {
while(RML_GETHDR(tokenlst) != RML_NILHDR) {
tokens.push_back(string(RML_STRINGDATA(RML_CAR(tokenlst))));
tokenlst=RML_CDR(tokenlst);
}

add_source_message(errorID,tp,severity,message,tokens,sline,scol,eline,ecol,isReadOnly,filename);
}
RML_TAILCALLK(rmlSC);
}
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__getNumMessages)
{
rmlA0 = mk_icon((errorMessageQueue.size()));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__printMessagesStr)
Expand All @@ -292,7 +299,7 @@ extern "C"
}
rmlA0 = mk_scon((char*)res.c_str());
RML_TAILCALLK(rmlSC);
}
}
RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__getMessagesStr)
Expand All @@ -306,16 +313,16 @@ extern "C"
res+=string("}");
rmlA0 = mk_scon((char*)res.c_str());
RML_TAILCALLK(rmlSC);
}
}
RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__clearMessages)
{
while(!errorMessageQueue.empty()) {
delete errorMessageQueue.front();
errorMessageQueue.pop();
}
RML_TAILCALLK(rmlSC);
}
}
RML_END_LABEL
} //extern "C"
2 changes: 2 additions & 0 deletions Compiler/runtime/optmanager.cpp
Expand Up @@ -68,6 +68,8 @@ extern "C"
options.insert(std::pair<std::string,bool>("MOOSEScaleEquations",true));
options.insert(std::pair<std::string,bool>("analyticJacobian",false));
options.insert(std::pair<std::string,bool>("dummyOption",false));
options.insert(std::pair<std::string,bool>("logSelectedStates",false));

//options.insert(std::pair<std::string,bool>("dummy",false));

/* for(stringMap::const_iterator it = options.begin(); it != options.end(); ++it)
Expand Down

0 comments on commit d3c4037

Please sign in to comment.