Skip to content

Commit

Permalink
Fixed bug #13, #34.
Browse files Browse the repository at this point in the history
Fixed so loadModel and loadFile returns parse error messages, if any, to error buffer.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1918 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Oct 13, 2005
1 parent bae0128 commit ac2140f
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 94 deletions.
31 changes: 11 additions & 20 deletions Compiler/Ceval.rml
Expand Up @@ -1315,7 +1315,13 @@ end
int_eq (res,0) => true &
System.pwd => str'
-------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("cd"),[Exp.SCONST(str)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg) => (Values.STRING(str'),st)
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("cd"),[Exp.SCONST(str)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg) => (Values.STRING(str'),st)

(* no such directory *)
rule not System.directory_exist(str) => 0 &
Util.string_append_list(["Error, directory ", str, " does not exist,"]) => res
----------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("cd"),[Exp.SCONST(str)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg) => (Values.STRING(res),st)

rule System.pwd() => str'
-------------------------
Expand Down Expand Up @@ -1376,6 +1382,8 @@ end
------------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("loadModel"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg) => (Values.BOOL(false),st)

(* loadModel failed *)
axiom ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("loadModel"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg) => (Values.BOOL(false),st)

rule System.regular_file_exist(name) => 0 &
Parser.parse(name) => p1 &
Expand All @@ -1392,8 +1400,8 @@ end
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("loadFile"),[Exp.SCONST(name)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.BOOL(false),st)

rule not Parser.parse(name) => _
rule (*not Parser.parse(name) => _*)
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("loadFile"),[Exp.SCONST(name)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.BOOL(false),st)
Expand Down Expand Up @@ -1512,23 +1520,6 @@ end
st,msg)
=> (v, st')

(* FIXME: test code: remove *)
rule Exp.exp_contains (exp1, exp2) => res
----------------------------------------------
ceval_interactive_functions(env, Exp.CALL(Absyn.IDENT("exp_contains"),
[exp1, exp2], _, _),
st,msg)
=> (Values.BOOL(res), st)

rule Exp.solve (exp1, exp2, exp3) => res1 &
Exp.print_exp_str res1 => res
----------------------------------------------
ceval_interactive_functions(env, Exp.CALL(Absyn.IDENT("solve"),
[exp1, exp2, exp3], _, _),
st,msg)
=> (Values.STRING(res), st)
(* /FIXME: test code: remove *)

end

relation generate_makefilename:(Exp.ComponentRef) => string =
Expand Down
5 changes: 3 additions & 2 deletions Compiler/ClassLoader.rml
Expand Up @@ -68,6 +68,7 @@ with "Parser.rml"
with "Print.rml"
with "Env.rml"
with "Dump.rml"
with "Debug.rml"

(** relation: load_class
** This relation takes a 'Path' and the $MODELICAPATH as a string
Expand Down Expand Up @@ -100,7 +101,7 @@ relation load_class: (Absyn.Path, string) => (Absyn.Program) =
-------------------------------------
load_class(path as Absyn.QUALIFIED(pack,rest),mp) => p

rule print "load_class failed\n"
rule Debug.fprint("failtrace", "load_class failed\n")
-------------------
load_class(_,_) => fail
end
Expand Down Expand Up @@ -174,7 +175,7 @@ relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =
--------------------------------------
load_class_from_mp(class,mp') => p

rule print "load_class_from_mp failed\n"
rule Debug.fprint("failtrace", "load_class_from_mp failed\n" )
--------------------
load_class_from_mp(_,_) => fail
end
Expand Down
14 changes: 14 additions & 0 deletions Compiler/Interactive.rml
Expand Up @@ -4452,13 +4452,21 @@ relation get_classnames_in_parts:(Absyn.ClassPart list ) => string list =

relation get_icon_annotation_in_class : (Absyn.Class) => string =

(* class definitions *)
rule get_icon_annotation_from_parts(parts) => annlst &
get_icon_annotation_str(annlst) => s1 &
string_append("{",s1) => s2 &
string_append(s2,"}") => str
------------------------
get_icon_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_),_))
=> str

(* short class definitions *)
rule get_icon_annotation_str(annlst) => s1 &
string_append("{",s1) => s2 &
string_append(s2,"}") => str
------------------------
get_icon_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.DERIVED(_,_,_,_,SOME(Absyn.COMMENT(SOME(Absyn.ANNOTATION(annlst)),_))),_)) => str
end

(** relation: get_icon_annotation_from_parts
Expand Down Expand Up @@ -4595,12 +4603,18 @@ relation get_classnames_in_parts:(Absyn.ClassPart list ) => string list =

relation get_diagram_annotation_in_class : (Absyn.Class) => string =

(* class def. *)
rule get_public_list(parts) => publst &
get_protected_list(parts) => protlst &
list_append(publst,protlst) => lst &
get_diagram_annotation_in_elementitemlist(lst) => str
----------------------------
get_diagram_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_),_)) => str

rule get_diagram_annotation_str(annlst) => str
----------------------------
get_diagram_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.DERIVED(_,_,_,_,SOME(Absyn.COMMENT(SOME(Absyn.ANNOTATION(annlst)),_))),_)) => str

end

relation get_diagram_annotation_in_elementitemlist: (Absyn.ElementItem list) => string =
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Main.rml
Expand Up @@ -91,7 +91,7 @@ relation server_loop: (int,Interactive.InteractiveSymbolTable) => Interactive.I
Debug.fprint ("interactivedump" , str ) &
Debug.fprint ("interactivedump", "------- End recieved Data-----\n") &
Print.clear_buf &
Print.clear_error_buf &
(*Print.clear_error_buf &*)
handle_command (str,isymb) => (true,replystr,newsymb) &
Socket.sendreply(shandle,replystr) &
server_loop (shandle,newsymb) => ressymb
Expand All @@ -103,7 +103,7 @@ relation server_loop: (int,Interactive.InteractiveSymbolTable) => Interactive.I
Debug.fprint ("interactivedump" ,"------- Recieved Data from client -----\n") &
Debug.fprint ("interactivedump" , str ) &
Debug.fprint ("interactivedump", "------- End recieved Data-----\n") &
Print.clear_error_buf &
(*Print.clear_error_buf &*)
Print.clear_buf &
handle_command (str,isymb) => (false,replystr,newsymb) &
(* 2004-11-27 - adrpo added part ends here *)
Expand Down
75 changes: 54 additions & 21 deletions Compiler/absyn_builder/parse.cpp
Expand Up @@ -42,6 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <iostream>
#include <sstream>


#include <fstream>

#include "modelica_lexer.hpp"
Expand All @@ -66,6 +68,9 @@ string modelicafilename; // The filename for the parsed file.
extern "C"
{

extern int print_error_buf_impl(char *);


int check_debug_flag(char const* strdata);

#include <errno.h>
Expand Down Expand Up @@ -101,8 +106,10 @@ extern "C"
std::ifstream stream(filename);
if (!stream)
{
std::cerr << "Error opening file" << std::endl;
RML_TAILCALLK(rmlFC);
const char* msg = "Error opening file";
std::cerr << msg << std::endl;
print_error_buf_impl((char*)msg);
RML_TAILCALLK(rmlFC);
}
//bool debug = true;
modelica_lexer *lex=0;
Expand Down Expand Up @@ -142,6 +149,7 @@ extern "C"
parse->setASTFactory( &my_factory );

parse->stored_definition();

t = RefMyAST(parse->getAST());
}
}
Expand All @@ -152,36 +160,58 @@ extern "C"
}
catch (ANTLR_USE_NAMESPACE(antlr)TokenStreamRecognitionException &e)
{
std::cerr << "Parsing error. TokenStreamRecognitionException on line "
<< flat_lex->getLine() << "near :"<< flat_lex->getText() << std::endl;
ast = mk_nil();
modelica_lexer *currentLex=0;

if (parseFlatModelica) {
currentLex = (modelica_lexer*)flat_lex;
}
else {
currentLex = lex;
}
stringstream str;
str << "Syntax error on line " << currentLex->getLine()
<< " near :" << currentLex->getText() << std::endl;
string msg = str.str();
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}
catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException &e)
{
std::cerr << "[" << filestring << ":" << e.getLine() << ":" << e.getColumn()
<< "]: error: " << e.getMessage() << std::endl;
ast = mk_nil();
stringstream str;
str << "[" << filestring << ":" << e.getLine() << ":"
<< e.getColumn() << "]: error: " << e.getMessage()
<< std::endl;
string msg = str.str();
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}
catch (ANTLR_USE_NAMESPACE(antlr)TokenStreamException &e)
{
std::cerr << "[" << filestring << ":" << flat_lex->getLine() << ":" << flat_lex->getColumn()
<< "]: error: illegal token" << std::endl;
stringstream str;
str << "[" << filestring << ":" << flat_lex->getLine()
<< ":" << flat_lex->getColumn()
<< "]: error: illegal token" << std::endl;
string msg = str.str();
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}
catch (ANTLR_USE_NAMESPACE(antlr)ANTLRException &e)
{
std::cerr << "ANTLRException: " << e.getMessage() << std::endl;
ast = mk_nil();
string msg = string("ANTLRException: ") + e.getMessage();
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}
catch (std::exception &e)
{
std::cerr << "Error while parsing:\n" << e.what() << "\n";
ast = mk_nil();
string msg = string("Error while parsing:\n") + e.what();
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}
catch (...)
{
std::cerr << "Error while parsing\n";
ast = mk_nil();
string msg = string("Error while parsing");
print_error_buf_impl((char*)msg.c_str());
ast = mk_nil();
}

//Parsing complete
Expand Down Expand Up @@ -235,24 +265,27 @@ extern "C"
if (parse) delete parse;
if (flat_parse) delete parse;
if (lex) delete lex;
ast = mk_nil();
modelicafilename=string("");
RML_TAILCALLK(rmlSC); // rmlFC
RML_TAILCALLK(rmlFC); // rmlFC
}
modelicafilename=string("");
if (debug)
{
std::cout << "Build done\n";
}

rmlA0 = ast ? ast : mk_nil();

rmlA0 = ast;

// adrpo added 2004-10-27
if (flat_parse) delete parse;
if (parse) delete parse;
if (lex) delete lex;
if (flat_lex) delete flat_lex;

if (!ast) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
}
else
Expand All @@ -263,10 +296,10 @@ extern "C"
if (lex) delete lex;
if (flat_lex) delete flat_lex;
ast = mk_nil();
std::cerr << "Error building AST" << std::endl;
//std::cerr << "Error building AST" << std::endl;
}

RML_TAILCALLK(rmlSC); // rmlFC
RML_TAILCALLK(rmlFC); // rmlFC
}
RML_END_LABEL

Expand Down

0 comments on commit ac2140f

Please sign in to comment.