Skip to content

Commit

Permalink
- New getMessagesStringInternal() API. Example session :)
Browse files Browse the repository at this point in the history
  skew({1,2,"",3});
  errors:=getMessagesStringInternal();
  size(errors,1); // 2
  currentError:=errors[1];
  currentError.info.filename;
  currentError.info.columnStart;
  currentError.message;
  currentError.kind;
  currentError:=errors[2];



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10163 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 19, 2011
1 parent 038857d commit 8fd3f97
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 52 deletions.
23 changes: 6 additions & 17 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -987,46 +987,35 @@ function getMessagesString
external "builtin" messagesString=getErrorString();
end getMessagesString;

function getMessagesStringInternal
"{{[file.mo:n:n-n:n:b] Error: message, TRANSLATION, Error, code}}"
output String messagesString;
external "builtin";
end getMessagesStringInternal;

/*
TODO: Implement getMessagesStringInternal better:
record SourceInfo
String filename;
Integer rowStart,columnStart,rowEnd,columnEnd;
Boolean writable;
Boolean readonly;
Integer lineStart,columnStart,lineEnd,columnEnd;
end SourceInfo;

type ErrorKind = enumeration(
unknown "unknown error code; possibly from C runtime",
syntax "syntax errors",
grammar "grammatical errors",
translation "instantiation errors: up to flat modelica",
symbolic "symbolic manipulation error, simcodegen, up to executable file",
runtime "simulation/function runtime error",
scripting "runtime scripting /interpretation error"
};
);
type ErrorLevel = enumeration(notification,warning,error);

record ErrorString
record ErrorMessage
SourceInfo info;
String message "After applying the individual arguments";
ErrorKind kind;
ErrorLevel level;
Integer id "Internal ID of the error (just ignore this)";
end ErrorString;
end ErrorMessage;

function getMessagesStringInternal
"{{[file.mo:n:n-n:n:b] Error: message, TRANSLATION, Error, code}}"
output ErrorString[:] messagesString;
output ErrorMessage[:] messagesString;
external "builtin";
end getMessagesStringInternal;
*/

function clearMessages "Clears the error buffer"
output Boolean success;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Makefile.in
Expand Up @@ -147,7 +147,7 @@ else
simcode: OpenModelicaBootstrappingHeader.h
$(MAKE) -C susan_codegen/
$(MAKE) -C susan_codegen/SimCode/
OpenModelicaBootstrappingHeader.h: FrontEnd/Absyn.mo Script/Interactive.mo FrontEnd/Values.mo GenerateOMCHeader.mos Template/Unparsing.mo
OpenModelicaBootstrappingHeader.h: FrontEnd/Absyn.mo Script/Interactive.mo FrontEnd/Values.mo Util/Error.mo GenerateOMCHeader.mos Template/Unparsing.mo
../build/bin/omc +g=MetaModelica GenerateOMCHeader.mos > $@.log || (cat $@.log && false)
@mv $@.new $@
endif
Expand Down
15 changes: 15 additions & 0 deletions Compiler/OpenModelicaBootstrappingHeader.h
Expand Up @@ -162,6 +162,21 @@ extern struct record_description Error_Message_MESSAGE__desc;
#define Error__MESSAGE_3dBOX4 3
#define Error__MESSAGE(id,ty,severity,message) (mmc_mk_box5(3,&Error_Message_MESSAGE__desc,id,ty,severity,message))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Error_TotalMessage_TOTALMESSAGE__desc_added
#define Error_TotalMessage_TOTALMESSAGE__desc_added
const char* Error_TotalMessage_TOTALMESSAGE__desc__fields[2] = {"msg","info"};
struct record_description Error_TotalMessage_TOTALMESSAGE__desc = {
"Error_TotalMessage_TOTALMESSAGE",
"Error.TotalMessage.TOTALMESSAGE",
Error_TotalMessage_TOTALMESSAGE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description Error_TotalMessage_TOTALMESSAGE__desc;
#endif
#define Error__TOTALMESSAGE_3dBOX2 3
#define Error__TOTALMESSAGE(msg,info) (mmc_mk_box3(3,&Error_TotalMessage_TOTALMESSAGE__desc,msg,info))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Values_Value_INTEGER__desc_added
#define Values_Value_INTEGER__desc_added
const char* Values_Value_INTEGER__desc__fields[1] = {"integer"};
Expand Down
111 changes: 99 additions & 12 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -55,6 +55,7 @@ public import BackendDAE;
public import Ceval;
public import DAE;
public import Env;
public import Error;
public import Interactive;
public import Dependency;
public import Values;
Expand All @@ -74,7 +75,6 @@ protected import DAEUtil;
protected import DAEDump;
protected import Debug;
protected import Dump;
protected import Error;
protected import Expression;
protected import Inst;
protected import InnerOuter;
Expand Down Expand Up @@ -1362,9 +1362,9 @@ algorithm

case (cache,env,"getMessagesStringInternal",{},st,msg)
equation
str = Error.getMessagesStr();
v = ValuesUtil.makeArray(List.map(Error.getMessages(),errorToValue));
then
(cache,Values.STRING(str),st);
(cache,v,st);

case (cache,env,"runScript",{Values.STRING(str)},st,msg)
equation
Expand Down Expand Up @@ -2408,7 +2408,7 @@ algorithm
// If we already have an up-to-date version of the binary file, we don't need to recompile.
equation
//cdef = Interactive.getPathedClassInProgram(classname,p);
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
// Only compile if change occured after last build.
( Absyn.CLASS(info = Absyn.INFO(buildTimes= Absyn.TIMESTAMP(build,_)))) = Interactive.getPathedClassInProgram(classname,p);
true = (build >. edit);
Expand All @@ -2428,7 +2428,7 @@ algorithm
(cdef as Absyn.CLASS(info = Absyn.INFO(buildTimes=ts as Absyn.TIMESTAMP(_,globalEdit)))) = Interactive.getPathedClassInProgram(classname,p);
Absyn.PROGRAM(_,_,Absyn.TIMESTAMP(globalBuild,_)) = p;

_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
oldDir = System.pwd();
compileDir = changeToTempDirectory(cdToTemp);
(cache,simSettings) = calculateSimulationSettings(cache,env,vals,st_1,msg);
Expand Down Expand Up @@ -3171,7 +3171,7 @@ algorithm
Interactive.getPathedClassInProgram(className, p);
// this case should not handle functions so here we check anything but functions!
false = listMember(restriction, {Absyn.R_FUNCTION()});
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
Print.clearErrorBuf() "Clear error buffer";
classNameStr = Absyn.pathString(className);
/* this part is not needed anymore as when checkModel is active you can normally instantiate partial classes
Expand Down Expand Up @@ -3238,7 +3238,7 @@ algorithm
Absyn.CLASS(partialPrefix = false, restriction = restriction) = Interactive.getPathedClassInProgram(className, p);
// this case should not handle functions so here we check anything but functions!
false = listMember(restriction, {Absyn.R_FUNCTION()});
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
Print.clearErrorBuf() "Clear error buffer";
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);

Expand Down Expand Up @@ -3278,7 +3278,7 @@ algorithm
ptot = Dependency.getTotalProgram(className,p);

(c as Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(),_,_)) = Interactive.getPathedClassInProgram(className, p);
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
Print.clearErrorBuf() "Clear error buffer";
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);

Expand Down Expand Up @@ -3461,7 +3461,7 @@ algorithm
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),Values.STRING(string="flat"),Values.BOOL(addOriginalIncidenceMatrix),Values.BOOL(addSolvingInfo),Values.BOOL(addMathMLCode),Values.BOOL(dumpResiduals),Values.STRING(filenameprefix),Values.BOOL(cdToTemp)},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
equation
//translationLevel=DAE.SCONST(string="flat")
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
oldDir = System.pwd();
compileDir = changeToTempDirectory(cdToTemp);
filenameprefix = Util.if_(filenameprefix ==& "<default>", Absyn.pathString(classname), filenameprefix);
Expand All @@ -3488,7 +3488,7 @@ algorithm
equation
//translationLevel=DAE.SCONST(string="optimiser")
//asInSimulationCode==false => it's NOT necessary to do all the translation's steps before dumping with xml
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
oldDir = System.pwd();
compileDir = changeToTempDirectory(cdToTemp);
cname_str = Absyn.pathString(classname);
Expand All @@ -3515,7 +3515,7 @@ algorithm
equation
//translationLevel=DAE.SCONST(string="backEnd")
//asInSimulationCode==true => it's necessary to do all the translation's steps before dumping with xml
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
oldDir = System.pwd();
compileDir = changeToTempDirectory(cdToTemp);
cname_str = Absyn.pathString(classname);
Expand Down Expand Up @@ -3820,7 +3820,7 @@ algorithm
case (cache,env,vals as {Values.CODE(Absyn.C_TYPENAME(classname)),starttime,stoptime,interval,tolerance, method,Values.STRING(filenameprefix),Values.BOOL(cdToTemp),noClean,options},(st as Interactive.SYMBOLTABLE(ast = p as Absyn.PROGRAM(globalBuildTimes=ts))),msg)
equation
cdef = Interactive.getPathedClassInProgram(classname,p);
_ = Error.getMessagesStr() "Clear messages";
Error.clearMessages() "Clear messages";
oldDir = System.pwd();
compileDir = changeToTempDirectory(cdToTemp);
(cache,simSettings) = calculateSimulationSettings(cache,env,vals,st,msg);
Expand Down Expand Up @@ -4129,4 +4129,91 @@ algorithm
path := getBasePathFromUri(str1,str2,Settings.getModelicaPath(),printError) +& str3;
end getFullPathFromUri;

protected function errorToValue
input Error.TotalMessage err;
output Values.Value val;
algorithm
val := match err
local
Absyn.Path msgpath;
Values.Value tyVal,severityVal,infoVal;
list<Values.Value> values;
String message;
Integer id;
Error.Severity severity;
Error.MessageType ty;
Absyn.Info info;
case Error.TOTALMESSAGE(Error.MESSAGE(id,ty,severity,message),info)
equation
msgpath = Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("Scripting",Absyn.IDENT("ErrorMessage"))));
tyVal = errorTypeToValue(ty);
severityVal = errorLevelToValue(severity);
infoVal = infoToValue(info);
values = {infoVal,Values.STRING(message),tyVal,severityVal,Values.INTEGER(id)};
then Values.RECORD(msgpath,values,{"info","message","kind","level","id"},-1);
end match;
end errorToValue;

protected function infoToValue
input Absyn.Info info;
output Values.Value val;
algorithm
val := match info
local
list<Values.Value> values;
Absyn.Path infopath;
Integer ls,cs,le,ce;
String filename;
Boolean readonly;
case Absyn.INFO(filename,readonly,ls,cs,le,ce,_)
equation
infopath = Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("Scripting",Absyn.IDENT("SourceInfo"))));
values = {Values.STRING(filename),Values.BOOL(readonly),Values.INTEGER(ls),Values.INTEGER(cs),Values.INTEGER(le),Values.INTEGER(ce)};
then Values.RECORD(infopath,values,{"filename","readonly","lineStart","columnStart","lineEnd","columnEnd"},-1);
end match;
end infoToValue;

protected function makeErrorEnumLiteral
input String enumName;
input String enumField;
input Integer index;
output Values.Value val;
annotation(__OpenModelica_EarlyInline=true);
algorithm
val := Values.ENUM_LITERAL(Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("Scripting",Absyn.QUALIFIED(enumName,Absyn.IDENT(enumField))))),index);
end makeErrorEnumLiteral;

protected function errorTypeToValue
input Error.MessageType ty;
output Values.Value val;
algorithm
val := match ty
case Error.SYNTAX() then makeErrorEnumLiteral("ErrorKind","syntax",1);
case Error.GRAMMAR() then makeErrorEnumLiteral("ErrorKind","grammar",2);
case Error.TRANSLATION() then makeErrorEnumLiteral("ErrorKind","translation",3);
case Error.SYMBOLIC() then makeErrorEnumLiteral("ErrorKind","symbolic",4);
case Error.SIMULATION() then makeErrorEnumLiteral("ErrorKind","runtime",5);
case Error.SCRIPTING() then makeErrorEnumLiteral("ErrorKind","scripting",6);
else
equation
print("errorTypeToValue failed\n");
then fail();
end match;
end errorTypeToValue;

protected function errorLevelToValue
input Error.Severity severity;
output Values.Value val;
algorithm
val := match severity
case Error.ERROR() then makeErrorEnumLiteral("ErrorLevel","syntax",1);
case Error.WARNING() then makeErrorEnumLiteral("ErrorLevel","grammar",2);
case Error.NOTIFICATION() then makeErrorEnumLiteral("ErrorLevel","translation",3);
else
equation
print("errorLevelToValue failed\n");
then fail();
end match;
end errorLevelToValue;

end CevalScript;
16 changes: 12 additions & 4 deletions Compiler/Util/Error.mo
Expand Up @@ -110,6 +110,14 @@ uniontype Message
end MESSAGE;
end Message;

public
uniontype TotalMessage
record TOTALMESSAGE
Message msg;
Absyn.Info info;
end TOTALMESSAGE;
end TotalMessage;

public
type MessageTokens = list<String> "\"Tokens\" to insert into message at
positions identified by
Expand Down Expand Up @@ -846,18 +854,18 @@ algorithm
num := ErrorExt.getNumErrorMessages();
end getNumErrorMessages;

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

function getMessagesStr

Return all messages in a matrix format, vector of strings for each
message, written out as a string.
"
output String res;
output list<TotalMessage> res;
algorithm
res := ErrorExt.getMessagesStr();
end getMessagesStr;
res := ErrorExt.getMessages();
end getMessages;

public function getMessagesStrType "function getMessagesStrType

Expand Down
8 changes: 4 additions & 4 deletions Compiler/Util/ErrorExt.mo
Expand Up @@ -98,11 +98,11 @@ public function getNumErrorMessages
external "C" num=ErrorImpl__getNumErrorMessages() annotation(Library = "omcruntime");
end getNumErrorMessages;

public function getMessagesStr
output String outString;
public function getMessages
output list<Error.TotalMessage> res;

external "C" outString=Error_getMessagesStr() annotation(Library = "omcruntime");
end getMessagesStr;
external "C" res=Error_getMessagesStr() annotation(Library = "omcruntime");
end getMessages;

public function clearMessages
external "C" ErrorImpl__clearMessages() annotation(Library = "omcruntime");
Expand Down
13 changes: 9 additions & 4 deletions Compiler/runtime/Error_omc.cpp
Expand Up @@ -28,13 +28,18 @@
*
*/

#include "errorext.cpp"

extern "C" {

#include "modelica.h"
#include "rml_compatibility.h"
#include "OpenModelicaBootstrappingHeader.h"

}

#include "errorext.cpp"

extern "C" {

void Error_addMessage(int errorID, void *msg_type, void *severity, const char* message, modelica_metatype tokenlst)
{
ErrorMessage::TokenList tokens;
Expand All @@ -51,9 +56,9 @@ void Error_addMessage(int errorID, void *msg_type, void *severity, const char* m
}
}

extern const char* Error_getMessagesStr()
extern void* Error_getMessages()
{
return strdup(ErrorImpl__getMessagesStr().c_str());
return listReverse(ErrorImpl__getMessages());
}

extern const char* Error_printMessagesStr()
Expand Down

0 comments on commit 8fd3f97

Please sign in to comment.