more on error handling

fiz inefficient grammar
output cmake recognised packages
This commit is contained in:
Vitor Santos Costa 2018-04-10 13:14:16 +01:00
parent 2c64eea060
commit d172c9a0f7
6 changed files with 44 additions and 49 deletions

View File

@ -1771,9 +1771,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
sc[2] = MkAtomTerm(LOCAL_SourceFileName);
sc[3] = t;
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
sc[1] = MkAtomTerm(AtomWarning);
Yap_PrintWarning(Yap_MkApplTerm(Yap_MkFunctor(AtomError, 2), 2, sc));
Yap_PrintWarning(t);
} else if (Yap_multiple(p, tmode PASS_REGS)) {
Term disc[4], sc[4];
if (p->ArityOfPE) {
@ -1789,9 +1787,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
sc[2] = MkAtomTerm(LOCAL_SourceFileName);
sc[3] = t;
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
sc[1] = MkAtomTerm(AtomWarning);
Yap_PrintWarning(Yap_MkApplTerm(Yap_MkFunctor(AtomError, 2), 2, sc));
Yap_PrintWarning(t);
}
if (mode == consult)
not_was_reconsulted(p, t, true);

View File

@ -1,3 +1,4 @@
/*************************************************************************
* *
* Yap Prolog *
@ -323,12 +324,12 @@ bool Yap_PrintWarning(Term twarning) {
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
bool rc;
Term ts[2];
Term ts[2], err;
if (LOCAL_PrologMode & InErrorMode) {
fprintf(stderr, "%% ERROR WITHIN ERROR while processing warning: %s\n",
Yap_TermToBuffer(twarning, ENC_ISO_UTF8,Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f));
Yap_RestartYap(1);
if (LOCAL_PrologMode & InErrorMode && LOCAL_CommittedError && (err = LOCAL_CommittedError->errorNo)) {
fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
Yap_TermToBuffer(twarning, ENC_ISO_UTF8,Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f), Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
return false;
}
LOCAL_PrologMode |= InErrorMode;
LOCAL_DoingUndefp = true;
@ -378,7 +379,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
serr);
return false;
}
LOCAL_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
return true;
case RESOURCE_ERROR_AUXILIARY_STACK:
if (LOCAL_MAX_SIZE < (char *)AuxSp - AuxBase) {
@ -390,7 +391,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
ARG1, serr);
return false;
}
LOCAL_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
return true;
case RESOURCE_ERROR_HEAP:
if (!Yap_growheap(FALSE, 0, NULL)) {
@ -574,10 +575,6 @@ yap_error_descriptor_t *Yap_popErrorContext(bool pass) {
sizeof(yap_error_descriptor_t));
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
if (LOCAL_ActiveError == YAP_NO_ERROR)
LOCAL_PrologMode = UserMode;
else
LOCAL_PrologMode = InErrorMode;
return new_error;
}
@ -648,10 +645,11 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
/* disallow recursive error handling */
if (LOCAL_PrologMode & InErrorMode &&
((err = LOCAL_ActiveError->errorNo) ||
( LOCAL_CommittedError->errorNo &&
(err = LOCAL_CommittedError->errorNo)))) {
fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n",
((err = LOCAL_ActiveError->errorNo) ||
( LOCAL_CommittedError &&
LOCAL_CommittedError->errorNo &&
(err = LOCAL_CommittedError->errorNo)))) {
fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n",
Yap_errorClassName(Yap_errorClass(type)), Yap_errorName(type),
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
return P;
@ -667,7 +665,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
LOCAL_ActiveError->culprit = Yap_TermToBuffer(
where, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
}
LOCAL_ActiveError->errorNo = type;
LOCAL_ActiveError->errorNo = type;
LOCAL_ActiveError->errorAsText = Yap_errorName(type);
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
LOCAL_ActiveError->classAsText =
@ -1007,13 +1005,15 @@ static Int get_exception(USES_REGS1) {
i = LOCAL_CommittedError;
LOCAL_CommittedError = NULL;
if (i && i->errorNo != YAP_NO_ERROR) {
if (i->errorNo == THROW_EVENT)
printErr(i);
if (i->errorNo == THROW_EVENT)
t = i->errorRawTerm;
else if (i->culprit != NULL) {
t = mkerrort(i->errorNo, Yap_BufferToTerm(i->culprit,TermNil),
MkSysError(i));
} else {
t = mkerrort(i->errorNo, TermNil, MkSysError(i));
Yap_DebugPlWriteln(t);
}
Yap_ResetException(LOCAL_ActiveError);
return Yap_unify(t, ARG1);
@ -1026,6 +1026,7 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
t1 = ArgOfTerm(1, t);
t2 = ArgOfTerm(2, t);
char ename[65];
Term n = t;
// LOCAL_Error_TYPE = ERROR_EVENT;
LOCAL_ActiveError->errorNo = USER_EVENT;
@ -1084,20 +1085,21 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
LOCAL_ActiveError->errorNo = UNINSTANTIATION_ERROR;
}
}
n = t2;
while (IsPairTerm(t2)) {
Term hd = HeadOfTerm(t2);
if (IsPairTerm(hd)) {
Term hdhd = HeadOfTerm(hd);
Term hdtl = TailOfTerm(hd);
if (hdhd == Termg) {
Term n = ArgOfTerm(1,hdtl);
n = ArgOfTerm(1,hdtl);
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
}
t2 = TailOfTerm(t2);
}
t2 = TailOfTerm(t2);
}
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS);
{
char *errs = malloc(strlen(LOCAL_ActiveError->errorAsText)+1);

View File

@ -974,18 +974,12 @@ static Int cleanup_on_exit(USES_REGS1) {
complete_pt[0] = TermExit;
}
Yap_ignore(cleanup, false);
bp = B;
while (bp && bp != B0) {
if (bp->cp_ap == NOCODE &&
bp->cp_b) {
bp->cp_ap = TRUSTFAILCODE;
}
bp = bp->cp_b;
}
if (B0->cp_ap == NOCODE)
B0->cp_ap = TRUSTFAILCODE;
if (Yap_RaiseException()) {
return false;
}
return true;
return true;
}
static bool complete_ge(bool out, Term omod, yhandle_t sl, bool creeping) {
@ -2081,7 +2075,6 @@ static Int jump_env(USES_REGS1) {
LCL0 - (CELL *)B > LOCAL_CBorder) {
// we're failing up to the top layer
}
LOCAL_CommittedError = Yap_GetException();
return out;
}

View File

@ -79,4 +79,6 @@ install(FILES ${LIBRARY_PL} DESTINATION ${libpl})
if (ANDROID)
file( INSTALL ${LIBRARY_PL} DESTINATION ${libpl} )
endif()
endif()
include_directories("dialect/swi")

View File

@ -661,10 +661,7 @@ static void warn_singletons(FEnv *fe, TokEntry *tokstart) {
else
singls[1] = TermTrue;
Term t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, singls);
singls[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
singls[1] = v;
Yap_PrintWarning(Yap_MkApplTerm(FunctorError, 2, singls));
Yap_PrintWarning(t);
}
}

View File

@ -230,6 +230,12 @@ compose_message(myddas_version(Version), _Leve) -->
[ 'MYDDAS version ~a' - [Version] ].
compose_message(yes, _Level) --> !,
[ 'yes'- [] ].
compose_message(style_check(What,FILE,Line,Clause), Level)-->
!,
{ '$show_consult_level'(LC) },
location(style_check(What,FILE,Line,Clause), Level, LC),
main_message(style_check(What,FILE,Line,Clause) , Level, LC )
].
compose_message(error(E, exception(Exc)), Level) -->
{ '$show_consult_level'(LC) },
location(error(E, exception(Exc)), Level, LC),
@ -239,7 +245,7 @@ compose_message(error(E, exception(Exc)), Level) -->
extra_info( Exc, Level ),
!,
[nl,nl].
compose_message(error(E,[I|Is]), Level) -->
compose_message(error(E,[I|Is]), Level) -->
{ translate_info([I|Is], In) },
compose_message( e(E, In), Level),
[nl,nl].
@ -312,9 +318,10 @@ location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)),
!,
[ '~a:~d:~d ' - [FileName,LN,0] ] .
location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) -->
location(style_check(_,LN,FileName,_ ), Level , LC) -->
!,
[ '~a:~d:0 ' - [FileName,LN] ] .
display_consulting( FileName, Level, LC ),
[ '~a:~d:0 ~s ' - [FileName,LN,Level] ] .
location( error(_,exception(Desc)), Level, LC ) -->
{ '$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos),
@ -339,7 +346,7 @@ main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term
[' ~a: failed_processing syntax error term ~q' - [Level,Term]],
[nl]
).
main_message(error(style_check(style_check(singleton(SVs),_Pos,_File,P)),_), Level, _LC) -->
main_message(style_check(singleton(SVs),_Pos,_File,P), Level, _LC) -->
!,
% {writeln(ci)},
{ clause_to_indicator(P, I) },
@ -347,10 +354,10 @@ main_message(error(style_check(style_check(singleton(SVs),_Pos,_File,P)),_), Lev
{ svs(SVs,SVs,SVsL),
( SVs = [_] -> NVs = 0 ; NVs = 1 )
}.
main_message(error(style_check(style_check(multiple(N,A,Mod,I0),_Pos,File,_P)),_), Level, _LC) -->
main_message(style_check(multiple(N,A,Mod,I0),_Pos,File,_P),_), Level, _LC) -->
!,
[ ' ~a: ~a redefines ~q from ~a.' - [Level,File, Mod:N/A, I0] ].
main_message(error(style_check(style_check(discontiguous(N,A,Mod),_S,_W,_P)),_) , Level, _LC)-->
main_message(style_check(discontiguous(N,A,Mod),_S,_W,_P) , Level, _LC)-->
!,
[ ' ~a: discontiguous definition for ~p.' - [Level,Mod:N/A] ].
main_message(error(consistency_error(Who)), Level, _LC) -->
@ -809,8 +816,6 @@ print_lines_(flush, S, Prefixes, Key) -->
!,
{ flush_output(S) },
print_lines( S, Prefixes, Key ).
!,
print_lines( S, Prefixes, Key ).
print_lines_(format(Fmt,Args), S, Prefixes, Key) -->
!,
{ format(S, Fmt, Args) },