YAP 7.1.0
YapError.h
1/*************************************************************************
2 * *
3 * YAP Prolog %W% %G% *
4 * Yap Prolog was developed at NCCUP - Universidade do Porto *
5 * *
6 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
7 * *
8 **************************************************************************
9 * *
10 * File: YapError.h * mods:
11 ** comments: error header file for YAP *
12 * version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
13 *************************************************************************/
14
15#ifndef YAP_ERROR_H
16#define YAP_ERROR_H 1
17
18#define ECLASS(CL, A, B) CL,
19
20#define E0(A, B, C) A,
21#define E(A, B, C) A,
22#define E1(A, B, C) A,
23#define E2(A, B, C, D) A,
24
25#define BEGIN_ERRORS() typedef enum {
26
27#define END_ERRORS() \
28 } \
29 yap_error_number
30
31#define BEGIN_ERROR_CLASSES() typedef enum {
32
33#define END_ERROR_CLASSES() \
34 } \
35 yap_error_class_number
36
37#include "YapErrors.h"
38
39#define MAX_ERROR_MSG_SIZE 1024
40
41extern void Yap_InitError__(const char *file, const char *function, int lineno,
42 yap_error_number e, YAP_Term g, ...);
43extern struct yami *Yap_Error__(bool thrw, const char *file,
44 const char *function, int lineno,
45 yap_error_number err, YAP_Term wheret, ...);
46
47extern void Yap_do_warning__( const char *file,
48 const char *function, int lineno,
49 yap_error_number err, YAP_Term wheret, ...);
50
51extern void Yap_ThrowError__(const char *file, const char *function, int lineno,
52 yap_error_number err, YAP_Term wheret, const char *msg, ...)
53 ;
54
55#define Yap_NilError(id, ...) \
56Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
57#define Yap_InitError(id, ...) \
58 Yap_InitError__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
59
60#define Yap_Error(id, inp, ...) \
61 Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
62
63#define Yap_ThrowError(id, inp, ...) \
64 Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
65
66
67
68#define Yap_do_warning(id, inp, ...) \
69 Yap_do_warning__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
70
71#ifdef YAP_TERM_H
76#define Yap_ensure_atom(T0, TF) \
77 { if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; \
78 }
79
80//INLINE_ONLY
81 static Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
82 Term in) {
83 Term t = Deref(in);
84 // Term Context = Deref(ARG2);
85 if (!IsVarTerm(t) && IsAtomTerm(t))
86 return t;
87 if (IsVarTerm(t)) {
88 Yap_Error__(false, fu, fi, line, INSTANTIATION_ERROR, t, NULL);
89 } else {
90 if (IsAtomTerm(t))
91 return t;
92 Yap_Error__(false, fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
93 return 0L;
94 }
95
96#endif
97
98#define JMP_LOCAL_ERROR(v, LAB) \
99 if (H + 2 * (v) > ASP - 1024) { \
100 LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
101 LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
102 goto LAB; \
103 }
104
105#define LOCAL_ERROR(t, v) \
106 if (HR + (v) > ASP - 1024) { \
107 LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
108 LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
109 return NULL; \
110 }
111
112#define LOCAL_TERM_ERROR(t, v) \
113 if (HR + (v) > ASP - 1024) { \
114 LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
115 LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
116 return 0L; \
117 }
118
119#define AUX_ERROR(t, n, s, TYPE) \
120 if (s + (n + 1) > (TYPE *)AuxSp) { \
121 LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
122 LOCAL_Error_Size = n * sizeof(TYPE); \
123 return NULL; \
124 }
125
126#define AUX_TERM_ERROR(t, n, s, TYPE) \
127 if (s + (n + 1) > (TYPE *)AuxSp) { \
128 LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
129 LOCAL_Error_Size = n * sizeof(TYPE); \
130 return 0L; \
131 }
132
133#define JMP_AUX_ERROR(n, s, t, TYPE, LAB) \
134 if (s + (n + 1) > (TYPE *)AuxSp) { \
135 LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
136 LOCAL_Error_Size = n * sizeof(TYPE); \
137 goto LAB; \
138 }
139
140#define HEAP_ERROR(a, TYPE) \
141 if (a == NIL) { \
142 LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
143 LOCAL_Error_Size = n * sizeof(TYPE); \
144 return NULL; \
145 }
146
147#define HEAP_TERM_ERROR(a, TYPE, n) \
148 if (a == NIL) { \
149 LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
150 LOCAL_Error_Size = n * sizeof(TYPE); \
151 return 0L; \
152 }
153
154#define JMP_HEAP_ERROR(a, n, t, TYPE, LAB) \
155 if (a == NIL) { \
156 LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
157 LOCAL_Error_Size = n * sizeof(TYPE); \
158 goto LAB; \
159 }
160
166 typedef enum yap_error_status {
168 YAP_NO_ERROR_STATUS = 0x0,
170 YAP_ERROR_INITIATED_IN_PROLOG = 0x1,
172 YAP_ERROR_INITIATED_IN_BOOT = 0x2,
174 YAP_ERROR_INITIATED_IN_HELPER = 0x4,
176 YAP_ERROR_INITIATED_IN_SYSTEM_C = 0x8,
178 YAP_ERROR_INITIATED_IN_USER_C = 0x10,
180 YAP_THROW_THROWN = 0x20,
182 YAP_THROW_CAUGHT = 0x40,
184 YAP_ERROR_EXPORTED_TO_CXX = 0x80,
186 YAP_ERROR_BEING_PROCESSED_IN_PROLOG = 0x100
188 } yap_error_stage_t;
189
191
192 typedef struct yap_error_prolog_source {
193 intptr_t prologPredCl;
194 uintptr_t prologPredLine;
195 uintptr_t prologPredFirstLine;
196 uintptr_t prologPredLastLine;
197 const char *prologPredName;
198 uintptr_t prologPredArity;
199 const char *prologPredModule;
200 const char *prologPredFile;
201 struct error_prolog_source *errorParent;
203
205 typedef struct s_yap_error_descriptor {
207 yap_error_number errorNo;
209 yap_error_class_number errorClass;
216 intptr_t errorLine;
218 const char *errorFunction;
220 const char *errorFile;
221 // struct error_prolog_source *errorSource;
223 const char *prologPredName;
227 const char *prologPredModule;
229 const char *prologPredFile;
231 uintptr_t prologPredLine;
233 uintptr_t parserPos;
234 uintptr_t parserFirstPos;
235 uintptr_t parserLastPos;
236 uintptr_t parserLine;
237 uintptr_t parserFirstLine;
238 uintptr_t parserLastLine;
239 const char *parserTextA;
240 size_t parserTextB;
241 const char *parserFile;
246 const char * culprit;
247 YAP_Term errorUserTerm, culprit_t;
249 const char *prologStack;
250 char *errorMsg;
251 size_t errorMsgLen;
252 struct s_yap_error_descriptor *top_error;
254
256#define LOCAL_Error_TYPE LOCAL_ActiveError->errorNo
257#define LOCAL_Error_File LOCAL_ActiveError->errorFile
258#define LOCAL_Error_Function LOCAL_ActiveError->errorFunction
259#define LOCAL_Error_Lineno LOCAL_ActiveError->errorLine
260#define LOCAL_Error_Size LOCAL_ActiveError->errorMsgLen
261#define LOCAL_UserTerm LOCAL_ActiveError->errorUserTerm
262#define LOCAL_ErrorFullTerm LOCAL_ActiveError->FullErrorTerm
263#define LOCAL_ErrorMessage LOCAL_ActiveError->errorMsg
264
265 extern void Yap_CatchError(void);
266 extern void Yap_ThrowExistingError(void);
267 extern YAP_Term Yap_MkPrologError(YAP_Term t, yap_error_descriptor_t * i);
268 extern YAP_Term MkSysError(yap_error_descriptor_t * r);
269 extern YAP_Term Yap_MkFullError(yap_error_descriptor_t * r);
270 extern bool Yap_MkErrorRecord(
271 yap_error_descriptor_t * r, const char *file, const char *function,
272 int lineno, yap_error_number type, YAP_Term where, const char *msg);
273
274 extern yap_error_descriptor_t *Yap_pc_add_location(
275 yap_error_descriptor_t * t, void *pc0, void *b_ptr0, void *env0);
276 extern yap_error_descriptor_t *Yap_env_add_location(
277 yap_error_descriptor_t * t, void *cp0, void *b_ptr0, void *env0,
278 YAP_Int ignore_first);
279
280 extern const char *Yap_dump_stack(void);
281
282 extern yap_error_descriptor_t *Yap_prolog_add_culprit(yap_error_descriptor_t *
283 t);
284
285 extern yap_error_class_number Yap_errorClassNumber(const char *c);
286 extern char *Yap_errorName(yap_error_number e);
287 extern yap_error_class_number Yap_errorClass(yap_error_number e);
288 extern char *Yap_errorClassName(yap_error_class_number e);
289 extern yap_error_number Yap_errorNumber(yap_error_class_number, const char * e) ;
290
291 extern bool Yap_get_exception(void);
292
293 extern YAP_Term Yap_UserError(YAP_Term t, yap_error_descriptor_t *i);
294
297 extern yap_error_descriptor_t *Yap_popErrorContext(bool oerr, bool pass, yap_error_descriptor_t *);
298
299 void Yap_must_be_list0(YAP_Term t);
300
301 #endif
302
303
yap_error_number Yap_errorNumber(yap_error_class_number, const char *e)
given a string(s, lookup for a corresponding error class r numbe
Definition: errors.c:1570
YAP_Term Yap_MkFullError(yap_error_descriptor_t *r)
convert a C-error to a Prolog term:
Definition: errors.c:853
yamop * Yap_Error__(bool throw, const char *file, const char *function, int lineno, yap_error_number type, Term where,...)
Yap_Error This function handles errors in the C code.
Definition: errors.c:981
void Yap_ThrowError__(const char *file, const char *function, int lineno, yap_error_number type, Term where, const char *msg,...)
Throw an error directly to the error handler.
Definition: errors.c:789
YAP_Term MkSysError(yap_error_descriptor_t *r)
Wrap the error descriptor as exception/2.
Definition: errors.c:841
yap_error_descriptor_t * Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error, yap_error_descriptor_t *old)
add a new error descriptor, either to the top of the stack, or as the top;
Definition: errors.c:746
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file, const char *function, int lineno, yap_error_number type, Term where, const char *s)
complete an error descriptor:
Definition: errors.c:882
all we need to know about an error/throw
Definition: YapError.h:205
bool parserReadingCode
reading a clause, or called from read?
Definition: YapError.h:243
const char * prologStack
Prolog stack at the time.
Definition: YapError.h:249
uintptr_t prologPredLine
line where error clause defined
Definition: YapError.h:231
uintptr_t parserPos
syntax and other parsing errors
Definition: YapError.h:233
const char * errorFunction
C-function.
Definition: YapError.h:218
const char * errorFile
C-file.
Definition: YapError.h:220
yap_error_number errorNo
error identifier
Definition: YapError.h:207
yap_error_class_number errorClass
kind of error: derived from errorNo;
Definition: YapError.h:209
const char * prologPredName
Prolog predicate that caused the error: name.
Definition: YapError.h:223
char * classAsText
errorClass as text
Definition: YapError.h:213
char * errorAsText
errorNo as text
Definition: YapError.h:211
const char * prologPredFile
Prolog predicate that caused the error:line
Definition: YapError.h:229
bool prologConsulting
whether we are consulting
Definition: YapError.h:245
intptr_t errorLine
c-code that generated the error C-line
Definition: YapError.h:216
const char * prologPredModule
Prolog predicate that caused the error:module
Definition: YapError.h:227
uintptr_t prologPredArity
Prolog predicate that caused the error:arity.
Definition: YapError.h:225
Definition: amidefs.h:264
a Prolog goal that caused a bug
Definition: YapError.h:192