error handling

This commit is contained in:
Vitor Santos Costa 2018-07-02 15:20:17 +01:00
parent 53de04c38f
commit 71aed8b870
4 changed files with 461 additions and 476 deletions

View File

@ -90,21 +90,23 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
return i->k ? TermTrue : TermFalse; \ return i->k ? TermTrue : TermFalse; \
} }
#define query_key_i(k, ks, q, i) \ #define query_key_i(k, ks, q, i) if (strcmp(ks, q) == 0) { \
if (strcmp(ks, q) == 0) { \
return MkIntegerTerm(i->k); \ return MkIntegerTerm(i->k); \
} }
#define query_key_s(k, ks, q, i) \ #define query_key_s(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \ if (strcmp(ks, q) == 0) { \
return (i->k && i->k[0] ? MkStringTerm(i->k) : TermNil); \ return MkAtomTerm(Yap_LookupAtom(i->k)); }
}
#define query_key_t(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \
Term t; if((t = Yap_BufferToTerm(i->k, TermNil) ) == 0 ) return TermNil; return t; }
static Term queryErr(const char *q, yap_error_descriptor_t *i) { static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_i(errorNo, "errorNo", q, i); query_key_i(errorNo, "errorNo", q, i);
query_key_i(errorClass, "errorClass", q, i); query_key_i(errorClass, "errorClass", q, i);
query_key_s(errorAsText, "errorAsText", q, i); query_key_s(errorAsText, "errorAsText", q, i);
query_key_s(errorGoal, "errorGoal", q, i); query_key_t(errorGoal, "errorGoal", q, i);
query_key_s(classAsText, "classAsText", q, i); query_key_s(classAsText, "classAsText", q, i);
query_key_i(errorLine, "errorLine", q, i); query_key_i(errorLine, "errorLine", q, i);
query_key_s(errorFunction, "errorFunction", q, i); query_key_s(errorFunction, "errorFunction", q, i);
@ -123,7 +125,7 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_s(prologParserText, "prologParserText", q, i); query_key_s(prologParserText, "prologParserText", q, i);
query_key_s(prologParserFile, "prologParserFile", q, i); query_key_s(prologParserFile, "prologParserFile", q, i);
query_key_b(prologConsulting, "prologConsulting", q, i); query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_s(culprit, "culprit", q, i); query_key_t(culprit, "culprit", q, i);
query_key_s(errorMsg, "errorMsg", q, i); query_key_s(errorMsg, "errorMsg", q, i);
query_key_i(errorMsgLen, "errorMsgLen", q, i); query_key_i(errorMsgLen, "errorMsgLen", q, i);
return TermNil; return TermNil;
@ -581,23 +583,17 @@ bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
/* if (Yap_HasException()) */ /* if (Yap_HasException()) */
/* memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError)); */ /* memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError)); */
/* LOCAL_ActiveError->top_error = bf; */ /* LOCAL_ActiveError->top_error = bf; */
/* } */ /* } */
yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) { yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
yap_error_descriptor_t *e = LOCAL_ActiveError; yap_error_descriptor_t *e = LOCAL_ActiveError, *ep = LOCAL_ActiveError->top_error;
// last block // last block
LOCAL_ActiveError = e->top_error; LOCAL_ActiveError = ep;
if (e->errorNo) { if (e->errorNo && !ep->errorNo && pass) {
if (!LOCAL_ActiveError->errorNo && pass) { yap_error_descriptor_t *epp = ep->top_error;
memmove(LOCAL_ActiveError, e, sizeof(*LOCAL_ActiveError)); memmove(ep, e, sizeof(*e));
} else { ep->top_error = epp;
return e;
}
} else {
if (e->errorNo)
return e;
} }
return NULL; return LOCAL_ActiveError;
} }
/** /**
* Throw an error directly to the error handler * Throw an error directly to the error handler

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ add_definitions(-DSQLITE_ENABLE_JSON1=1 )
add_definitions(-DSQLITE_ENABLE_RBU=1 ) add_definitions(-DSQLITE_ENABLE_RBU=1 )
add_definitions(-DSQLITE_ENABLE_RTREE=1 ) add_definitions(-DSQLITE_ENABLE_RTREE=1 )
add_definitions(-DSQLITE_ENABLE_FTS5=1 ) add_definitions(-DSQLITE_ENABLE_FTS5=1 )
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
@ -47,6 +46,8 @@ else()
add_library( YAPsqlite3 SHARED add_library( YAPsqlite3 SHARED
${YAPSQLITE3_SOURCES}) ${YAPSQLITE3_SOURCES})
target_link_libraries(YAPsqlite3 libYap )
set_target_properties(YAPsqlite3 set_target_properties(YAPsqlite3
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}

View File

@ -198,10 +198,9 @@ compose_message( halt, _Level) --> !,
% syntax error. % syntax error.
compose_message(error(E, Exc), Level) --> compose_message(error(E, Exc), Level) -->
{ '$show_consult_level'(LC), '$print_exception'(Exc) { '$show_consult_level'(LC) },
},
location(error(E, Exc), Level, LC), location(error(E, Exc), Level, LC),
main_message(error(E,Exc) , Level, LC ), main_message(error(E,Exc) , Level, LC ),
c_goal( error(E, Exc), Level ), c_goal( error(E, Exc), Level ),
caller( error(E, Exc), Level ), caller( error(E, Exc), Level ),
extra_info( error(E, Exc), Level ), extra_info( error(E, Exc), Level ),
@ -257,7 +256,8 @@ location(style_check(A,LN,FileName,B ), Level , LC) -->
display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ), display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ),
[ '~a:~d:0 ~a ' - [FileName,LN,Level] ] . [ '~a:~d:0 ~a ' - [FileName,LN,Level] ] .
location( error(_,Info), Level, LC ) --> location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) },
{ '$error_descriptor'(Info, Desc) },
{ {
'$query_exception'(prologPredFile, Desc, File), '$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos), '$query_exception'(prologPredLine, Desc, FilePos),
@ -267,19 +267,7 @@ location( error(_,Info), Level, LC ) -->
}, },
!, !,
display_consulting( File, Level, Info, LC ), display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ]. [ '~a:~d:0 ~a in ~a:~a/~d:'-[File, FilePos,Level,M,Na,Ar] ].
location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) },
{
'$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos),
'$query_exception'(prologPredModule, Desc, M),
'$query_exception'(prologPredName, Desc, Na),
'$query_exception'(prologPredArity, Desc, Ar)
},
!,
display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ].
location( error(_,Info), Level, LC ) --> location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) }, { '$error_descriptor'(Info, Desc) },
{ {
@ -289,7 +277,7 @@ location( error(_,Info), Level, LC ) -->
}, },
!, !,
display_consulting( File, Level, Info, LC ), display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s():'-[File, FilePos,Level,F] ]. [ '~a:~d:0 ~a in ~a():'-[File, FilePos,Level,F] ].
location( _Ball, _Level, _LC ) --> []. location( _Ball, _Level, _LC ) --> [].
@ -393,7 +381,7 @@ caller( Info, _) -->
}, },
!, !,
[nl], [nl],
['~*| raised from ~a:~q:~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]], ['~*| ~q:~d:0 ~a:~q'-[10,File, FilePos,M,Na,Ar]],
[nl]. [nl].
caller( _, _) --> caller( _, _) -->
[]. [].
@ -982,8 +970,9 @@ confusing to YAP (who will process the error?). So we write this small
stub to ensure everything os ok stub to ensure everything os ok
*/ */
:- dynamic in/0.
/* /*
/*:- dynamic in/0.
prolog:print_message(Severity, Msg) :- prolog:print_message(Severity, Msg) :-
\+ in, \+ in,
assert(in), assert(in),
@ -991,7 +980,7 @@ prolog:print_message(Severity, Msg) :-
( prolog:print_message(Severity, Msg), fail; ( prolog:print_message(Severity, Msg), fail;
stop_low_level_trace, stop_low_level_trace,
retract(in) retract(in)
).*/ ).
*/ */
prolog:print_message(Severity, Msg) :- prolog:print_message(Severity, Msg) :-
( (
@ -1043,7 +1032,8 @@ prolog:print_message(Severity, Term) :-
), ),
!. !.
prolog:print_message(Severity, Term) :- prolog:print_message(Severity, Term) :-
translate_message( Term, Severity, Lines0, [ end(Id)]), translate_message( Term, Severity, Lines0, [ end(Id)]),
writeln(Lines0),
Lines = [begin(Severity, Id)| Lines0], Lines = [begin(Severity, Id)| Lines0],
( (
user:message_hook(Term, Severity, Lines) user:message_hook(Term, Severity, Lines)
@ -1057,7 +1047,7 @@ prolog:print_message(Severity, Term) :-
prolog:print_message(_Severity, _Term) :- prolog:print_message(_Severity, _Term) :-
format(user_error,'failed to print ~w: ~w~n' ,[ _Severity, _Term]). format(user_error,'failed to print ~w: ~w~n' ,[ _Severity, _Term]).
'$error_descriptor'( error(_,Info), Info ). '$error_descriptor'( exception(Info), Info ).
/** /**