Skip to content

Commit ac2140f

Browse files
author
Peter Aronsson
committed
Fixed bug #13, #34.
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
1 parent bae0128 commit ac2140f

File tree

10 files changed

+155
-94
lines changed

10 files changed

+155
-94
lines changed

Compiler/Ceval.rml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,13 @@ end
13151315
int_eq (res,0) => true &
13161316
System.pwd => str'
13171317
-------------------------
1318-
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)
1318+
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)
1319+
1320+
(* no such directory *)
1321+
rule not System.directory_exist(str) => 0 &
1322+
Util.string_append_list(["Error, directory ", str, " does not exist,"]) => res
1323+
----------------------
1324+
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)
13191325

13201326
rule System.pwd() => str'
13211327
-------------------------
@@ -1376,6 +1382,8 @@ end
13761382
------------------------------
13771383
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)
13781384

1385+
(* loadModel failed *)
1386+
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)
13791387

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

1395-
1396-
rule not Parser.parse(name) => _
1403+
1404+
rule (*not Parser.parse(name) => _*)
13971405
--------------------------
13981406
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("loadFile"),[Exp.SCONST(name)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
13991407
=> (Values.BOOL(false),st)
@@ -1512,23 +1520,6 @@ end
15121520
st,msg)
15131521
=> (v, st')
15141522

1515-
(* FIXME: test code: remove *)
1516-
rule Exp.exp_contains (exp1, exp2) => res
1517-
----------------------------------------------
1518-
ceval_interactive_functions(env, Exp.CALL(Absyn.IDENT("exp_contains"),
1519-
[exp1, exp2], _, _),
1520-
st,msg)
1521-
=> (Values.BOOL(res), st)
1522-
1523-
rule Exp.solve (exp1, exp2, exp3) => res1 &
1524-
Exp.print_exp_str res1 => res
1525-
----------------------------------------------
1526-
ceval_interactive_functions(env, Exp.CALL(Absyn.IDENT("solve"),
1527-
[exp1, exp2, exp3], _, _),
1528-
st,msg)
1529-
=> (Values.STRING(res), st)
1530-
(* /FIXME: test code: remove *)
1531-
15321523
end
15331524

15341525
relation generate_makefilename:(Exp.ComponentRef) => string =

Compiler/ClassLoader.rml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ with "Parser.rml"
6868
with "Print.rml"
6969
with "Env.rml"
7070
with "Dump.rml"
71+
with "Debug.rml"
7172

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

103-
rule print "load_class failed\n"
104+
rule Debug.fprint("failtrace", "load_class failed\n")
104105
-------------------
105106
load_class(_,_) => fail
106107
end
@@ -174,7 +175,7 @@ relation load_class_from_mp: (Absyn.Ident, string) => Absyn.Program =
174175
--------------------------------------
175176
load_class_from_mp(class,mp') => p
176177

177-
rule print "load_class_from_mp failed\n"
178+
rule Debug.fprint("failtrace", "load_class_from_mp failed\n" )
178179
--------------------
179180
load_class_from_mp(_,_) => fail
180181
end

Compiler/Interactive.rml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,13 +4452,21 @@ relation get_classnames_in_parts:(Absyn.ClassPart list ) => string list =
44524452

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

4455+
(* class definitions *)
44554456
rule get_icon_annotation_from_parts(parts) => annlst &
44564457
get_icon_annotation_str(annlst) => s1 &
44574458
string_append("{",s1) => s2 &
44584459
string_append(s2,"}") => str
44594460
------------------------
44604461
get_icon_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_),_))
44614462
=> str
4463+
4464+
(* short class definitions *)
4465+
rule get_icon_annotation_str(annlst) => s1 &
4466+
string_append("{",s1) => s2 &
4467+
string_append(s2,"}") => str
4468+
------------------------
4469+
get_icon_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.DERIVED(_,_,_,_,SOME(Absyn.COMMENT(SOME(Absyn.ANNOTATION(annlst)),_))),_)) => str
44624470
end
44634471

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

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

4606+
(* class def. *)
45984607
rule get_public_list(parts) => publst &
45994608
get_protected_list(parts) => protlst &
46004609
list_append(publst,protlst) => lst &
46014610
get_diagram_annotation_in_elementitemlist(lst) => str
46024611
----------------------------
46034612
get_diagram_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_),_)) => str
4613+
4614+
rule get_diagram_annotation_str(annlst) => str
4615+
----------------------------
4616+
get_diagram_annotation_in_class (Absyn.CLASS(_,_,_,_,_,Absyn.DERIVED(_,_,_,_,SOME(Absyn.COMMENT(SOME(Absyn.ANNOTATION(annlst)),_))),_)) => str
4617+
46044618
end
46054619

46064620
relation get_diagram_annotation_in_elementitemlist: (Absyn.ElementItem list) => string =

Compiler/Main.rml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ relation server_loop: (int,Interactive.InteractiveSymbolTable) => Interactive.I
9191
Debug.fprint ("interactivedump" , str ) &
9292
Debug.fprint ("interactivedump", "------- End recieved Data-----\n") &
9393
Print.clear_buf &
94-
Print.clear_error_buf &
94+
(*Print.clear_error_buf &*)
9595
handle_command (str,isymb) => (true,replystr,newsymb) &
9696
Socket.sendreply(shandle,replystr) &
9797
server_loop (shandle,newsymb) => ressymb
@@ -103,7 +103,7 @@ relation server_loop: (int,Interactive.InteractiveSymbolTable) => Interactive.I
103103
Debug.fprint ("interactivedump" ,"------- Recieved Data from client -----\n") &
104104
Debug.fprint ("interactivedump" , str ) &
105105
Debug.fprint ("interactivedump", "------- End recieved Data-----\n") &
106-
Print.clear_error_buf &
106+
(*Print.clear_error_buf &*)
107107
Print.clear_buf &
108108
handle_command (str,isymb) => (false,replystr,newsymb) &
109109
(* 2004-11-27 - adrpo added part ends here *)

Compiler/absyn_builder/parse.cpp

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242

4343
#include <iostream>
4444
#include <sstream>
45+
46+
4547
#include <fstream>
4648

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

71+
extern int print_error_buf_impl(char *);
72+
73+
6974
int check_debug_flag(char const* strdata);
7075

7176
#include <errno.h>
@@ -101,8 +106,10 @@ extern "C"
101106
std::ifstream stream(filename);
102107
if (!stream)
103108
{
104-
std::cerr << "Error opening file" << std::endl;
105-
RML_TAILCALLK(rmlFC);
109+
const char* msg = "Error opening file";
110+
std::cerr << msg << std::endl;
111+
print_error_buf_impl((char*)msg);
112+
RML_TAILCALLK(rmlFC);
106113
}
107114
//bool debug = true;
108115
modelica_lexer *lex=0;
@@ -142,6 +149,7 @@ extern "C"
142149
parse->setASTFactory( &my_factory );
143150

144151
parse->stored_definition();
152+
145153
t = RefMyAST(parse->getAST());
146154
}
147155
}
@@ -152,36 +160,58 @@ extern "C"
152160
}
153161
catch (ANTLR_USE_NAMESPACE(antlr)TokenStreamRecognitionException &e)
154162
{
155-
std::cerr << "Parsing error. TokenStreamRecognitionException on line "
156-
<< flat_lex->getLine() << "near :"<< flat_lex->getText() << std::endl;
157-
ast = mk_nil();
163+
modelica_lexer *currentLex=0;
164+
165+
if (parseFlatModelica) {
166+
currentLex = (modelica_lexer*)flat_lex;
167+
}
168+
else {
169+
currentLex = lex;
170+
}
171+
stringstream str;
172+
str << "Syntax error on line " << currentLex->getLine()
173+
<< " near :" << currentLex->getText() << std::endl;
174+
string msg = str.str();
175+
print_error_buf_impl((char*)msg.c_str());
176+
ast = mk_nil();
158177
}
159178
catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException &e)
160179
{
161-
std::cerr << "[" << filestring << ":" << e.getLine() << ":" << e.getColumn()
162-
<< "]: error: " << e.getMessage() << std::endl;
163-
ast = mk_nil();
180+
stringstream str;
181+
str << "[" << filestring << ":" << e.getLine() << ":"
182+
<< e.getColumn() << "]: error: " << e.getMessage()
183+
<< std::endl;
184+
string msg = str.str();
185+
print_error_buf_impl((char*)msg.c_str());
186+
ast = mk_nil();
164187
}
165188
catch (ANTLR_USE_NAMESPACE(antlr)TokenStreamException &e)
166189
{
167-
std::cerr << "[" << filestring << ":" << flat_lex->getLine() << ":" << flat_lex->getColumn()
168-
<< "]: error: illegal token" << std::endl;
190+
stringstream str;
191+
str << "[" << filestring << ":" << flat_lex->getLine()
192+
<< ":" << flat_lex->getColumn()
193+
<< "]: error: illegal token" << std::endl;
194+
string msg = str.str();
195+
print_error_buf_impl((char*)msg.c_str());
169196
ast = mk_nil();
170197
}
171198
catch (ANTLR_USE_NAMESPACE(antlr)ANTLRException &e)
172199
{
173-
std::cerr << "ANTLRException: " << e.getMessage() << std::endl;
174-
ast = mk_nil();
200+
string msg = string("ANTLRException: ") + e.getMessage();
201+
print_error_buf_impl((char*)msg.c_str());
202+
ast = mk_nil();
175203
}
176204
catch (std::exception &e)
177205
{
178-
std::cerr << "Error while parsing:\n" << e.what() << "\n";
179-
ast = mk_nil();
206+
string msg = string("Error while parsing:\n") + e.what();
207+
print_error_buf_impl((char*)msg.c_str());
208+
ast = mk_nil();
180209
}
181210
catch (...)
182211
{
183-
std::cerr << "Error while parsing\n";
184-
ast = mk_nil();
212+
string msg = string("Error while parsing");
213+
print_error_buf_impl((char*)msg.c_str());
214+
ast = mk_nil();
185215
}
186216

187217
//Parsing complete
@@ -235,24 +265,27 @@ extern "C"
235265
if (parse) delete parse;
236266
if (flat_parse) delete parse;
237267
if (lex) delete lex;
238-
ast = mk_nil();
239268
modelicafilename=string("");
240-
RML_TAILCALLK(rmlSC); // rmlFC
269+
RML_TAILCALLK(rmlFC); // rmlFC
241270
}
242271
modelicafilename=string("");
243272
if (debug)
244273
{
245274
std::cout << "Build done\n";
246275
}
247276

248-
rmlA0 = ast ? ast : mk_nil();
277+
278+
rmlA0 = ast;
249279

250280
// adrpo added 2004-10-27
251281
if (flat_parse) delete parse;
252282
if (parse) delete parse;
253283
if (lex) delete lex;
254284
if (flat_lex) delete flat_lex;
255285

286+
if (!ast) {
287+
RML_TAILCALLK(rmlFC);
288+
}
256289
RML_TAILCALLK(rmlSC);
257290
}
258291
else
@@ -263,10 +296,10 @@ extern "C"
263296
if (lex) delete lex;
264297
if (flat_lex) delete flat_lex;
265298
ast = mk_nil();
266-
std::cerr << "Error building AST" << std::endl;
299+
//std::cerr << "Error building AST" << std::endl;
267300
}
268301

269-
RML_TAILCALLK(rmlSC); // rmlFC
302+
RML_TAILCALLK(rmlFC); // rmlFC
270303
}
271304
RML_END_LABEL
272305

0 commit comments

Comments
 (0)