Skip to content

Commit

Permalink
- Added a generic error message for elabExp (only 1 testcase needed t…
Browse files Browse the repository at this point in the history
…o be updated; no scary floods of failed expressions followed...)

- Changed errorext.cpp slightly: Now we remove duplicate errors when pop'ing the stack.
  - The reason for this change is that if we called Error.addSourceMessage and the top already had a copy of that message, the error count would not increase. This could cause additional generic error messages to appear.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7539 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 21, 2010
1 parent fa38339 commit 50435f2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 106 deletions.
11 changes: 10 additions & 1 deletion Compiler/FrontEnd/Dump.mo
Expand Up @@ -4164,6 +4164,7 @@ algorithm
case (Absyn.CALL(function_ = _)) then 0;
case (Absyn.PARTEVALFUNCTION(function_= _)) then 0;
case (Absyn.ARRAY(arrayExp = _)) then 0;
case (Absyn.LIST(exps = _)) then 0;
case (Absyn.MATRIX(matrix = _)) then 0;
/* arithmetic operators */
case (Absyn.BINARY(op = Absyn.POW())) then 1;
Expand Down Expand Up @@ -4408,7 +4409,15 @@ algorithm
s_2 = stringAppend(s_1, "}");
then
s_2;


case Absyn.LIST(exps = es)
equation
s = printListStr(es, printExpStr, ",") "Does not need parentheses" ;
s_1 = stringAppend("{", s);
s_2 = stringAppend(s_1, "}");
then
s_2;

case Absyn.TUPLE(expressions = es)
equation
s = printListStr(es, printExpStr, ",") "Does not need parentheses" ;
Expand Down
104 changes: 65 additions & 39 deletions Compiler/FrontEnd/Static.mo

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -243,6 +243,7 @@ public constant ErrorID FUNCTION_ELEMENT_WRONG_KIND=155;
public constant ErrorID WITHOUT_SENDDATA=156 "Used in external C sources; do not use another index";
public constant ErrorID DUPLICATE_CLASSES_TOP_LEVEL=157;
public constant ErrorID WHEN_EQ_LHS=158;
public constant ErrorID GENERIC_ELAB_EXPRESSION=159;

public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
Expand Down Expand Up @@ -675,6 +676,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(FUNCTION_ELEMENT_WRONG_KIND,TRANSLATION(),ERROR(),"Element is not allowed in function context: %s"),
(WITHOUT_SENDDATA,SCRIPTING(),ERROR(),"%s failed because OpenModelica was configured without sendData support."),
(WHEN_EQ_LHS,TRANSLATION(),ERROR(),"Invalid left-hand side of when-equation: %s."),
(GENERIC_ELAB_EXPRESSION,TRANSLATION(),ERROR(),"Failed to elaborate expression: %s"),

(COMPILER_WARNING,TRANSLATION(),WARNING(),"%s")
};
Expand Down
23 changes: 12 additions & 11 deletions Compiler/runtime/ErrorMessage.cpp
Expand Up @@ -56,6 +56,8 @@
endColumnNo_ = 0;
isReadOnly_ = false;
filename_ = std::string("");
shortMessage = getMessage_();
fullMessage = getFullMessage_();
}

ErrorMessage::ErrorMessage(long errorID,
Expand All @@ -82,21 +84,22 @@ ErrorMessage::ErrorMessage(long errorID,
message_(message),
tokens_(tokens)
{
shortMessage = getMessage_();
fullMessage = getFullMessage_();
}

/*
* adrpo, 2006-02-05 changed position handling
*/
std::string ErrorMessage::getMessage()
std::string ErrorMessage::getMessage_()
{
std::string fullMessage = message_;
std::list<std::string>::iterator tok;
std::string::size_type str_pos;
for (tok=tokens_.begin(); tok != tokens_.end(); tok++) {
str_pos=fullMessage.find("%s");
if (str_pos < fullMessage.size())
str_pos=message_.find("%s");
if (str_pos < message_.size())
{
fullMessage.replace(str_pos,2,*tok);
message_.replace(str_pos,2,*tok);
}
else
{
Expand All @@ -110,21 +113,19 @@ std::string ErrorMessage::getMessage()
if (filename_ == "" && startLineNo_ == 0 && startColumnNo_ == 0 &&
endLineNo_ == 0 && endColumnNo_ == 0 /*&& isReadOnly_ == false*/)
{
return severity_+": "+fullMessage;
return severity_+": "+message_;
}
else
{
return positionInfo + fullMessage;
return positionInfo + message_;
}
}

std::string ErrorMessage::getFullMessage()
std::string ErrorMessage::getFullMessage_()
{
std::string message_text= getMessage();

std::stringstream strbuf;

strbuf << "{\"" << message_text << "\", \"" <<
strbuf << "{\"" << shortMessage << "\", \"" <<
messageType_ << "\", \"" <<
severity_ << "\", \"" <<
errorID_ << "\"}";
Expand Down
32 changes: 19 additions & 13 deletions Compiler/runtime/ErrorMessage.hpp
Expand Up @@ -55,33 +55,36 @@ class ErrorMessage {
bool isReadOnly,
std::string filename);

long getID() { return errorID_; };
long getID() const { return errorID_; };

std::string getType() { return messageType_; };
std::string getType() const { return messageType_; };

std::string getSeverity() { return severity_; };
std::string getSeverity() const { return severity_; };

// Returns the expanded message with inserted tokens.
std::string getMessage();
std::string getMessage() const {return shortMessage;};

// Returns the complete message in string format corresponding to a Modeica vector.
std::string getFullMessage();
std::string getFullMessage() const {return fullMessage;};

long getLineNo() { return startLineNo_; };
long getColumnNo() { return startColumnNo_; };
long getLineNo() const { return startLineNo_; };
long getColumnNo() const { return startColumnNo_; };
/* adrpo added these new ones */
long getStartLineNo() { return startLineNo_; };
long getStartColumnNo() { return startColumnNo_; };
long getEndLineNo() { return endLineNo_; };
long getEndColumnNo() { return endColumnNo_; };
bool getIsFileReadOnly() { return isReadOnly_; };
std::string getFileName() { return filename_; };
long getStartLineNo() const { return startLineNo_; };
long getStartColumnNo() const { return startColumnNo_; };
long getEndLineNo() const { return endLineNo_; };
long getEndColumnNo() const { return endColumnNo_; };
bool getIsFileReadOnly() const { return isReadOnly_; };
std::string getFileName() const { return filename_; };
std::list<std::string> getTokens() const { return tokens_; };
private:
long errorID_;
std::string messageType_;
std::string severity_;
std::string message_;
std::list<std::string> tokens_;
std::string shortMessage;
std::string fullMessage;

/* adrpo 2006-02-05 changed the ones below */
long startLineNo_;
Expand All @@ -91,6 +94,9 @@ class ErrorMessage {
bool isReadOnly_;
std::string filename_;

std::string getMessage_();
std::string getFullMessage_();

};


Expand Down
5 changes: 3 additions & 2 deletions Compiler/runtime/Makefile.common
Expand Up @@ -54,8 +54,8 @@ Dynload_rml.o: systemimpl.h errorext.h rtopts.h ../Absyn.h ../Values.h ../../c_r
Dynload_omc.o: systemimpl.h errorext.h rtopts.h ../OpenModelicaBootstrappingHeader.h ../../c_runtime/read_write.h ../../c_runtime/memory_pool.h Dynload.cpp
Print_rml.o : printimpl.c
Print_omc.o : printimpl.c
Error_rml.o : errorext.cpp
Error_omc.o : errorext.cpp
Error_rml.o : errorext.cpp ErrorMessage.hpp
Error_omc.o : errorext.cpp ErrorMessage.hpp
System_rml.o : systemimpl.c config.h $(configUnix)
System_omc.o : systemimpl.c config.h $(configUnix)
RTOpts_rml.o : rtoptsimpl.c
Expand All @@ -74,6 +74,7 @@ Socket_rml.o : socketimpl.c
Socket_omc.o : socketimpl.c
ptolemyio_rml.o : ptolemyio.cpp
ptolemyio_omc.o : ptolemyio.cpp
ErrorMessage.o : ErrorMessage.cpp ErrorMessage.hpp

clean:
$(RM) -rf *.a *.o omc_communication.cc omc_communication.h omc_communication-* sqlite/*.o
66 changes: 26 additions & 40 deletions Compiler/runtime/errorext.cpp
Expand Up @@ -51,6 +51,7 @@ struct absyn_info{
};
// if error_on is true, message is added, otherwise not.
static bool error_on=true;
static int numErrorMessages=0;

#include "ErrorMessage.hpp"
static std::string currVariable("");
Expand All @@ -66,6 +67,19 @@ static void push_message(ErrorMessage *msg)
std::cerr << msg->getFullMessage() << std::endl;
else
errorMessageQueue.push(msg);
if (msg->getSeverity().compare(std::string("Error")) == 0) numErrorMessages++;
}

/* pop the top of the message stack (and any duplicate messages that have also been added) */
static void pop_message()
{
ErrorMessage *msg = errorMessageQueue.top();
if (msg->getSeverity().compare(std::string("Error")) == 0) numErrorMessages--;
errorMessageQueue.pop();
int pop_more = errorMessageQueue.size() > 0 && msg->getFullMessage() == errorMessageQueue.top()->getFullMessage();
delete msg;
if (pop_more)
pop_message();
}

/* Adds a message without file info. */
Expand All @@ -82,22 +96,10 @@ extern void add_message(int errorID,
else {
tmp=message;
}
if(!haveInfo) {
ErrorMessage *msg = new ErrorMessage((long)errorID, std::string(type ), std::string(severity), /*std::string(message),*/ tmp, tokens);
if (errorMessageQueue.empty() || (!errorMessageQueue.empty() && errorMessageQueue.top()->getFullMessage() != msg->getFullMessage())) {
// std::cerr << "inserting error message "<< msg->getFullMessage() << " on variable "<< currVariable << std::endl; fflush(stderr);
push_message(msg);
}
} 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() || (!errorMessageQueue.empty() && errorMessageQueue.top()->getFullMessage() != msg->getFullMessage())) {
// std::cerr << "inserting error message "<< msg->getFullMessage() << " on variable "<< currVariable << std::endl;
// std::cerr << "values: " << finfo.rs << " " << finfo.ce << std::endl; fflush(stderr);
push_message(msg);
}
}
ErrorMessage *msg = haveInfo ?
new ErrorMessage((long)errorID, std::string(type ), std::string(severity), tmp, tokens, finfo.rs,finfo.cs,finfo.re,finfo.ce,finfo.wr,finfo.fn) :
new ErrorMessage((long)errorID, std::string(type ), std::string(severity), tmp, tokens);
push_message(msg);
}

/* Adds a message with file information */
Expand All @@ -124,10 +126,7 @@ void add_source_message(int errorID,
(long)endCol,
isReadOnly,
std::string(filename));
if (errorMessageQueue.empty() || (!errorMessageQueue.empty() && errorMessageQueue.top()->getFullMessage() != msg->getFullMessage())) {
// std::cerr << "inserting error message "<< msg->getFullMessage() << std::endl; fflush(stderr);
push_message(msg);
}
push_message(msg);
}

extern "C"
Expand Down Expand Up @@ -163,8 +162,7 @@ static void printCheckpointStack(void)
printf("%5d %s message:", i, cp.second.c_str());
while(errorMessageQueue.size() > cp.first && errorMessageQueue.size() > 0){
res = errorMessageQueue.top()->getMessage()+string(" ")+res;
delete errorMessageQueue.top();
errorMessageQueue.pop();
pop_message();
}
printf("%s\n", res.c_str());
}
Expand Down Expand Up @@ -217,7 +215,7 @@ extern void ErrorImpl__rollBack(const char* id)
res = res+errorMessageQueue.top()->getMessage()+string("\n");
printf( (string("Deleted: ") + res).c_str());
}*/
errorMessageQueue.pop();
pop_message();
}
/*if(!errorMessageQueue.empty()){
res = res+errorMessageQueue.top()->getMessage()+string("\n");
Expand Down Expand Up @@ -246,8 +244,7 @@ extern char* ErrorImpl__rollBackAndPrint(const char* id)
if(checkPoints.size() > 0){
while(errorMessageQueue.size() > checkPoints.back().first && errorMessageQueue.size() > 0){
res = errorMessageQueue.top()->getMessage()+string("\n")+res;
delete errorMessageQueue.top();
errorMessageQueue.pop();
pop_message();
}
pair<int,string> cp;
cp = checkPoints[checkPoints.size()-1];
Expand Down Expand Up @@ -318,22 +315,13 @@ extern void c_add_source_message(int errorID, const char* type, const char* seve
}

extern int ErrorImpl__getNumErrorMessages() {
int res=0;
stack<ErrorMessage*> queueCopy(errorMessageQueue);
while (!queueCopy.empty()) {
if (queueCopy.top()->getSeverity().compare(std::string("Error")) == 0) {
res++;
}
queueCopy.pop();
}
return res;
return numErrorMessages;
}

extern void ErrorImpl__clearMessages()
{
while(!errorMessageQueue.empty()) {
delete errorMessageQueue.top();
errorMessageQueue.pop();
pop_message();
}
}

Expand All @@ -343,8 +331,7 @@ extern std::string ErrorImpl__getMessagesStr()
std::string res("}");
while(!errorMessageQueue.empty()) {
res = errorMessageQueue.top()->getFullMessage() + res;
delete errorMessageQueue.top();
errorMessageQueue.pop();
pop_message();
if (!errorMessageQueue.empty()) { res = string(",") + res; }
}
res = string("{") + res;
Expand All @@ -357,8 +344,7 @@ extern std::string ErrorImpl__printMessagesStr()
std::string res("");
while(!errorMessageQueue.empty()) {
res = errorMessageQueue.top()->getMessage()+string("\n")+res;
delete errorMessageQueue.top();
errorMessageQueue.pop();
pop_message();
}
return res;
}
Expand Down

0 comments on commit 50435f2

Please sign in to comment.