Skip to content

Commit

Permalink
Added better error messages when building. etc.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2244 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Mar 23, 2006
1 parent 9da670c commit 13ea309
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 18 deletions.
11 changes: 1 addition & 10 deletions Compiler/Ceval.rml
Expand Up @@ -1939,7 +1939,7 @@ end
DAE.transform_if_eq_to_expr(dae') => (dae as DAE.DAE(dael)) &
Interactive.add_instantiated_class(ic,Interactive.INSTCLASS(classname,dael,env))
=> ic' &
DAELow.lower(dae,true) => dlow &
DAELow.lower(dae,true) => dlow &
Debug.fprint("bltdump","Lowered DAE:\n") &
Debug.fcall("bltdump", DAELow.dump,dlow) &
DAELow.incidence_matrix(dlow) => m &
Expand Down Expand Up @@ -1973,15 +1973,6 @@ end
fileprefix)
=> (Values.STRING("The model have been translated"),st,
indexed_dlow', libs)

rule (*Print.printErrorBuf("# translate_model failed\n")*)
---------------------------------------------
translate_model (env, cr,
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),
_,
_)
=> fail

end


Expand Down
4 changes: 3 additions & 1 deletion Compiler/Codegen.rml
Expand Up @@ -2488,7 +2488,9 @@ relation generate_expression : (Exp.Exp, int) => (CFunction,string,int) =
rule Debug.fprintln("failtrace","# generate_expression failed") &
Exp.print_exp_str e => s &
Debug.fprintln("failtrace",s) &
Debug.fprintln("failtrace","")
Debug.fprintln("failtrace","") &
Util.string_append_list(["code generation of expression ",s," failed"]) => msg &
Error.add_message(Error.INTERNAL_ERROR,[msg])
----------------
generate_expression(e,_) => fail
end
Expand Down
9 changes: 7 additions & 2 deletions Compiler/DAELow.rml
Expand Up @@ -4456,7 +4456,9 @@ relation check_matching : (DAELow,MatchingOptions) => () =

rule equation_size(eqns) => esize &
int_lt(esize,vars_size) => true &
int_string(esize) => esize_str &
int_sub(esize,1) => esize & (* remove dummy var*)
int_sub(vars_size,1) => vars_size & (* remove dummy var*)
int_string(esize) => esize_str &
int_string(vars_size) => vsize_str &
Error.add_message(Error.UNDERDET_EQN_SYSTEM,[vsize_str,esize_str])
------------------
Expand All @@ -4465,6 +4467,8 @@ relation check_matching : (DAELow,MatchingOptions) => () =

rule equation_size(eqns) => esize &
int_gt(esize,vars_size) => true &
int_sub(esize,1) => esize & (* remove dummy var*)
int_sub(vars_size,1) => vars_size & (* remove dummy var*)
int_string(esize) => esize_str &
int_string(vars_size) => vsize_str &
Error.add_message(Error.OVERDET_EQN_SYSTEM,[vsize_str,esize_str])
Expand Down Expand Up @@ -6148,7 +6152,8 @@ relation strong_components: (IncidenceMatrix, IncidenceMatrixT,
-----------------------------------
strong_components(m,mt,ass1,ass2) => (comps)

rule Debug.fprint("failtrace", "strong_components failed\n")
rule Debug.fprint("failtrace", "strong_components failed\n") &
Error.add_message(Error.INTERNAL_ERROR, ["sorting equations(strong components failed)"])
----------------------------------
strong_components(_,_,_,_) => fail
end
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Error.rml
Expand Up @@ -293,6 +293,8 @@ val ERROR_OPENING_FILE : ErrorID (* Error opening file *)

val INHERIT_BASIC_WITH_COMPS : ErrorID (*Inherits basic type and has comps *)

val ERROR_FLATTENING: ErrorID (*Error occured while flattening*)

(** Warning messages *)

val UNBOUND_PARAMETER_WARNING : ErrorID (* parameter without a value *)
Expand Down Expand Up @@ -477,6 +479,8 @@ val INHERIT_BASIC_WITH_COMPS = 86

val MODIFIER_TYPE_MISMATCH_ERROR = 87

val ERROR_FLATTENING = 88

val UNBOUND_PARAMETER_WARNING = 500

val INDEX_REDUCTION_NOTIFICATION = 1000
Expand Down Expand Up @@ -639,6 +643,7 @@ val ErrorTable =
(INHERIT_BASIC_WITH_COMPS,TRANSLATION, ERROR, "Class %s inherits primary type but has components"),

(MODIFIER_TYPE_MISMATCH_ERROR, TRANSLATION, ERROR, "Type mismatch in modifier, expected type %s, got modifier %s of type %s"),
(ERROR_FLATTENING, TRANSLATION, ERROR, "Error occured while flattening model %s"),

(* WARNING *)
(UNBOUND_PARAMETER_WARNING, TRANSLATION, WARNING, "Warning, parameter %s has no value."),
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Inst.rml
Expand Up @@ -368,6 +368,13 @@ relation instantiate_class : (SCode.Program, SCode.Path)
--------------------------------------------
instantiate_class(cdecls as _::_, path as Absyn.QUALIFIED(name,_))
=> (DAE.DAE([DAE.COMP(pathstr,DAE.DAE(dae))]),env'')

(* error instantiating *)
rule Absyn.path_string(path) => cname_str &
Error.add_message(Error.ERROR_FLATTENING,[cname_str])
----------------------------
instantiate_class(cdecls, path )
=> fail

end

Expand Down
6 changes: 3 additions & 3 deletions Compiler/SimCodegen.rml
Expand Up @@ -216,7 +216,7 @@ relation generate_simulation_code: (DAE.DAElist,
generate_simulation_code(dae,dlow,ass1,ass2,m,mt,comps,class,filename,funcfilename) => ()


rule Error.add_message(Error.INTERNAL_ERROR, ["generate_simulation_code failed"])
rule Error.add_message(Error.INTERNAL_ERROR, ["Generation of simulation code failed"])
-----------------------
generate_simulation_code(_,_,_,_,_,_,_,_,_,_) => fail
end
Expand Down Expand Up @@ -3369,7 +3369,7 @@ relation generate_functions: (SCode.Program, (* Needed to instantiate functions*
=> libs


rule Error.add_message(Error.INTERNAL_ERROR, ["generate_functions failed"])
rule Error.add_message(Error.INTERNAL_ERROR, ["Code generation of Modelica functions failed. "])
-------------------------------------
generate_functions (_, _, _, _, _) => fail

Expand Down Expand Up @@ -4730,7 +4730,7 @@ relation relop_symbol : Exp.Operator => string =
axiom relop_symbol(Exp.GREATER(_)) => " > "
axiom relop_symbol(Exp.GREATEREQ(_)) => " >= "
axiom relop_symbol(Exp.EQUAL(_)) => " == "
axiom relop_symbol(Exp.NEQUAL(_)) => " <> "
axiom relop_symbol(Exp.NEQUAL(_)) => " != "
end


Expand Down
24 changes: 23 additions & 1 deletion Compiler/runtime/errorext.cpp
Expand Up @@ -41,10 +41,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <fstream>
#include <queue>

#include <list>

using namespace std;

void add_message(int errorID,
char* type,
char* severity,
char* message,
std::list<std::string> tokens);

extern "C" {
void c_add_message(int errorID,
char* type,
char* severity,
char* message,
char** ctokens,
int nTokens)
{
std::list<std::string> tokens;
for (int i=nTokens-1; i>=0; i--) {
tokens.push_back(std::string(ctokens[i]));
}
add_message(errorID,type,severity,message,tokens);
}
}

// if error_on is true, message is added, otherwise not.
bool error_on=true;

Expand Down
9 changes: 9 additions & 0 deletions Compiler/runtime/errorext.h
Expand Up @@ -45,6 +45,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <list>

extern "C" {
void c_add_message(int errorID,
char* type,
char* severity,
char* message,
char** ctokens,
int nTokens);
}


void add_message(int errorID,
char* type,
Expand Down
14 changes: 14 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -499,6 +499,13 @@ RML_BEGIN_LABEL(System__writeFile)
FILE * file=NULL;
file = fopen(filename,"w");
if (file == NULL) {
char *c_tokens[1]={filename};
c_add_message(21, /* WRITING_FILE_ERROR */
"SCRIPTING",
"ERROR",
"Error writing to file %s.",
c_tokens,
1);
RML_TAILCALLK(rmlFC);
}
fprintf(file,"%s",data);
Expand All @@ -518,6 +525,13 @@ RML_BEGIN_LABEL(System__readFile)

if(res!=0)
{
char *c_tokens[1]={filename};
c_add_message(85, /* ERROR_OPENING_FILE */
"SCRIPTING",
"ERROR",
"Error opening file %s.",
c_tokens,
1);
rmlA0 = (void*) mk_scon("No such file");
RML_TAILCALLK(rmlSC);
}
Expand Down
15 changes: 14 additions & 1 deletion Compiler/winruntime/systemimpl.c
Expand Up @@ -511,7 +511,13 @@ RML_BEGIN_LABEL(System__writeFile)
FILE * file=NULL;
file = fopen(filename,"w");
if (file == NULL) {
printf("error opening file: %s\n",filename);
char *c_tokens[1]={filename};
c_add_message(21, /* WRITING_FILE_ERROR */
"SCRIPTING",
"ERROR",
"Error writing to file %s.",
c_tokens,
1);
RML_TAILCALLK(rmlFC);
}
fprintf(file,"%s",data);
Expand All @@ -531,6 +537,13 @@ RML_BEGIN_LABEL(System__readFile)

if(res!=0)
{
char *c_tokens[1]={filename};
c_add_message(85, /* ERROR_OPENING_FILE */
"SCRIPTING",
"ERROR",
"Error opening file %s.",
c_tokens,
1);
rmlA0 = (void*) mk_scon("No such file");
RML_TAILCALLK(rmlSC);
}
Expand Down

0 comments on commit 13ea309

Please sign in to comment.