BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
err.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: err.h
4 // Purpose: Handling of error and warning messages
5 // Last Change: 04.08.2017
6 // Language: C++
7 // EMail: brass@informatik.uni-halle.de
8 // WWW: http://www.informatik.uni-halle.de/~brass/
9 // Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10 // Copyright: (c) 2010-2017 by Stefan Brass
11 // License: See file "LICENSE" for copying conditions.
12 // Note: There is no warranty at all - this code may contain bugs.
13 // ============================================================================
14 
15 
22 //=============================================================================
23 // Include File Frame:
24 //=============================================================================
25 
26 #ifndef ERR_INCLUDED
27 #define ERR_INCLUDED
28 
29 //=============================================================================
30 // Used Types and Macros:
31 //=============================================================================
32 
33 #ifndef VER_INCLUDED
34 #include "ver.h"
35 #endif
36 
37 #ifndef STR_INCLUDED
38 #include "str.h"
39 #endif
40 
41 #ifndef CHECK_INCLUDED
42 #include "check.h"
43 #endif
44 
45 // Forward declaration, in this way we do not need to include <iostream>:
46 class ofstream;
47 
48 //=============================================================================
49 // Private Constants:
50 //=============================================================================
51 
52 //-----------------------------------------------------------------------------
53 // ERR_BUFSIZE: Size of buffer for a single error message.
54 //-----------------------------------------------------------------------------
55 
56 static const int ERR_BUFSIZE = 512;
57  // Note: For syntax errors this contains the error message,
58  // plus the input line plus the spaces for marking the error position.
59  // I.e. this must be large enough to hold three full lines.
60 
61 //-----------------------------------------------------------------------------
62 // ERR_MAXERRS: Maximal number of error messages kept in memory.
63 //-----------------------------------------------------------------------------
64 
65 static const int ERR_MAXERRS = 10;
66 
67 //=============================================================================
68 // Module for Error Message Handling (Class with only static members):
69 //=============================================================================
70 
75 class err_c {
76  public:
77 
78 
79  //=====================================================================
80  // Possibility to query last error messages:
81  //=====================================================================
82 
83 
84  //---------------------------------------------------------------------
85  // reset:
86  //---------------------------------------------------------------------
87 
92  static void reset();
93 
94  //---------------------------------------------------------------------
95  // ok:
96  //---------------------------------------------------------------------
97 
102  static bool ok();
103 
104  //---------------------------------------------------------------------
105  // num_errs:
106  //---------------------------------------------------------------------
107 
112  static int num_errs();
113 
114  //---------------------------------------------------------------------
115  // msg:
116  //---------------------------------------------------------------------
117 
122  static str_t msg(int n = 0);
123 
124 
125  //=====================================================================
126  // Automatic printing of error messages (Alert-File and/or stderr):
127  //=====================================================================
128 
129 
130  //---------------------------------------------------------------------
131  // open_alert:
132  //---------------------------------------------------------------------
133 
138  static bool open_alert(str_t filename);
139 
140  //---------------------------------------------------------------------
141  // close:
142  //---------------------------------------------------------------------
143 
148  static bool close_alert();
149 
150  //---------------------------------------------------------------------
151  // use_stderr:
152  //---------------------------------------------------------------------
153 
158  static void use_stderr(bool b);
159 
160 
161  //=====================================================================
162  // Errors detected in mem.cpp:
163  //=====================================================================
164 
165 
166  //---------------------------------------------------------------------
167  // malloc_failed:
168  //---------------------------------------------------------------------
169 
174  static void malloc_failed(unsigned int chunk_size, int num_chunks);
175 
176 
177  //=====================================================================
178  // Errors detected in stack.h:
179  //=====================================================================
180 
181 
182  //---------------------------------------------------------------------
183  // stack_overflow:
184  //---------------------------------------------------------------------
185 
190  static void stack_overflow(str_t name, int curr_limit);
191 
192 
193  //=====================================================================
194  // Errors detected in flexarr.h:
195  //=====================================================================
196 
197 
198  //---------------------------------------------------------------------
199  // flexarr_capacity_limit:
200  //---------------------------------------------------------------------
201 
206  static void flexarr_capacity_limit(str_t name, int curr_length);
207 
208 
209  //=====================================================================
210  // Errors detected in list.h:
211  //=====================================================================
212 
213 
214  //---------------------------------------------------------------------
215  // list_capacity_limit:
216  //---------------------------------------------------------------------
217 
222  static void list_capacity_limit(str_t name, int curr_length);
223 
224 
225  //=====================================================================
226  // Errors detected in dup_2i.cpp:
227  //=====================================================================
228 
229 
230  //---------------------------------------------------------------------
231  // hashtab_limit:
232  //---------------------------------------------------------------------
233 
238  static void hashtab_limit(str_t tab_name, int hash_size,
239  int hash_pages, int max_pages);
240 
241 
242  //=====================================================================
243  // Errors detected in pred.cpp:
244  //=====================================================================
245 
246 
247  //---------------------------------------------------------------------
248  // pred_arity_too_large:
249  //---------------------------------------------------------------------
250 
255  static void pred_arity_too_large(str_t name, int arity, int limit);
256 
257  //---------------------------------------------------------------------
258  // pred_too_many_rels:
259  //---------------------------------------------------------------------
260 
265  static void pred_too_many_rels(str_t name, int limit);
266 
267 
268  //=====================================================================
269  // Errors detected in in_file.cpp:
270  //=====================================================================
271 
272 
273  //---------------------------------------------------------------------
274  // cgi_security:
275  //---------------------------------------------------------------------
276 
281  static void cgi_security(str_t filename);
282 
283  //---------------------------------------------------------------------
284  // open_failed:
285  //---------------------------------------------------------------------
286 
291  static void open_failed(str_t filename, str_t msg);
292 
293  //---------------------------------------------------------------------
294  // close_failed:
295  //---------------------------------------------------------------------
296 
301  static void close_failed(str_t filename, str_t msg);
302 
303  //---------------------------------------------------------------------
304  // read_failed:
305  //---------------------------------------------------------------------
306 
311  static void read_failed(str_t filename, str_t msg);
312 
313 
314  //=====================================================================
315  // Errors detected in in_cgi.cpp:
316  //=====================================================================
317 
318 
319  //---------------------------------------------------------------------
320  // bad_request_method:
321  //---------------------------------------------------------------------
322 
327  static void bad_request_method();
328 
329  //---------------------------------------------------------------------
330  // bad_content_type:
331  //---------------------------------------------------------------------
332 
337  static void bad_content_type();
338 
339  //---------------------------------------------------------------------
340  // bad_content_length:
341  //---------------------------------------------------------------------
342 
347  static void bad_content_length();
348 
349  //---------------------------------------------------------------------
350  // bad_cgi_hex:
351  //---------------------------------------------------------------------
352 
357  static void bad_cgi_hex();
358 
359  //---------------------------------------------------------------------
360  // cgi_premature_eof:
361  //---------------------------------------------------------------------
362 
367  static void cgi_premature_eof();
368 
369  //---------------------------------------------------------------------
370  // cgi_null_char:
371  //---------------------------------------------------------------------
372 
377  static void cgi_null_char();
378 
379  //---------------------------------------------------------------------
380  // cgi_field_not_terminated:
381  //---------------------------------------------------------------------
382 
387  static void cgi_field_not_terminated();
388 
389  //---------------------------------------------------------------------
390  // cgi_duplicate_program:
391  //---------------------------------------------------------------------
392 
397  static void cgi_duplicate_program();
398 
399  //---------------------------------------------------------------------
400  // cgi_no_program:
401  //---------------------------------------------------------------------
402 
407  static void cgi_no_program();
408 
409 
410  //=====================================================================
411  // Errors detected in lex.cpp:
412  //=====================================================================
413 
414 
415  //---------------------------------------------------------------------
416  // null_char:
417  //---------------------------------------------------------------------
418 
423  static void null_char(str_t filename, int lineno);
424 
425  //---------------------------------------------------------------------
426  // line_too_long:
427  //---------------------------------------------------------------------
428 
433  static void line_too_long(str_t filename, int lineno);
434 
435 
436  //=====================================================================
437  // Functions for Syntax Error Messages (includes input line):
438  //=====================================================================
439 
440 
441  //---------------------------------------------------------------------
442  // syntax_begin:
443  //---------------------------------------------------------------------
444 
449  static void syntax_begin(str_t filename, int line, str_t msg);
450 
451  //---------------------------------------------------------------------
452  // syntax_input:
453  //---------------------------------------------------------------------
454 
459  static void syntax_input(char c);
460 
461  //---------------------------------------------------------------------
462  // syntax_newline:
463  //---------------------------------------------------------------------
464 
469  static void syntax_newline();
470 
471  //---------------------------------------------------------------------
472  // syntax_eof:
473  //---------------------------------------------------------------------
474 
479  static void syntax_eof();
480 
481  //---------------------------------------------------------------------
482  // syntax_end:
483  //---------------------------------------------------------------------
484 
489  static void syntax_end();
490 
491 
492  //=====================================================================
493  // Errors detected in load.cpp:
494  //=====================================================================
495 
496 
497  //---------------------------------------------------------------------
498  // store_fact_failed:
499  //---------------------------------------------------------------------
500 
505  static void store_fact_failed(str_t filename, int line_no,
506  str_t pred_name);
507 
508 
509  //=====================================================================
510  // Errors detected in test.cpp:
511  //=====================================================================
512 
513 
514  //---------------------------------------------------------------------
515  // test_has_no_arg:
516  //---------------------------------------------------------------------
517 
522  static void test_has_no_arg(str_t test_id);
523 
524  //---------------------------------------------------------------------
525  // invalid_test_arg:
526  //---------------------------------------------------------------------
527 
532  static void invalid_test_arg(str_t test_id, int arg);
533 
534 
535  //=====================================================================
536  // Errors detected in main.cpp:
537  //=====================================================================
538 
539 
540  //---------------------------------------------------------------------
541  // option_missing:
542  //---------------------------------------------------------------------
543 
548  static void option_missing();
549 
550  //---------------------------------------------------------------------
551  // unknown_option:
552  //---------------------------------------------------------------------
553 
558  static void unknown_option(str_t arg);
559 
560  //---------------------------------------------------------------------
561  // benchmark_with_debug_code:
562  //---------------------------------------------------------------------
563 
568  static void benchmark_with_debug_code();
569 
570  //---------------------------------------------------------------------
571  // debug_output_disabled:
572  //---------------------------------------------------------------------
573 
578  static void debug_output_disabled();
579 
580 
581  //=====================================================================
582  // Functions for Dumping Data:
583  //=====================================================================
584 
585 
586  //---------------------------------------------------------------------
587  // dump_begin:
588  //---------------------------------------------------------------------
589 
594  static void dump_begin(str_t headline);
595 
596  //---------------------------------------------------------------------
597  // dump_str:
598  //---------------------------------------------------------------------
599 
604  static void dump_str(str_t str);
605 
606  //---------------------------------------------------------------------
607  // dump_nl:
608  //---------------------------------------------------------------------
609 
614  static void dump_nl();
615 
616  //---------------------------------------------------------------------
617  // dump_char:
618  //---------------------------------------------------------------------
619 
624  static void dump_char(char c);
625 
626  //---------------------------------------------------------------------
627  // dump_int:
628  //---------------------------------------------------------------------
629 
634  static void dump_int(int n);
635 
636  //---------------------------------------------------------------------
637  // dump_uint:
638  //---------------------------------------------------------------------
639 
644  static void dump_uint(unsigned int n);
645 
646  //---------------------------------------------------------------------
647  // dump_bool:
648  //---------------------------------------------------------------------
649 
654  static void dump_bool(bool b);
655 
656  //---------------------------------------------------------------------
657  // dump_ptr:
658  //---------------------------------------------------------------------
659 
664  static void dump_ptr(const void *p);
665 
666  //---------------------------------------------------------------------
667  // dump_end:
668  //---------------------------------------------------------------------
669 
674  static void dump_end();
675 
676 
677 //=============================================================================
678 // Auxillary Static Methods:
679 //=============================================================================
680 
681  private:
682 
683  // msg_begin: Begin construction of message in buffer.
684  static void msg_begin();
685 
686  // msg_str: Add/Append string to message buffer.
687  static void msg_str(str_t str);
688 
689  // msg_char: Add/Append character to message buffer.
690  static void msg_char(char c);
691 
692  // msg_int: Add/Append int to message buffer.
693  static void msg_int(int i);
694 
695  // msg_uint: Add/Append unsigned int to message buffer.
696  static void msg_uint(unsigned int i);
697 
698  // msg_output: Output contents of message buffer.
699  static void msg_output();
700 
701  // dump_output: Output a string as part of a data structure dump.
702  static void dump_output(str_t str);
703 
704  // dump_flush: Make sure that dump data is really written.
705  static void dump_flush();
706 
707 //-----------------------------------------------------------------------------
708 // Class Variables:
709 //-----------------------------------------------------------------------------
710 
711  private:
712 
713  // UseStderr: Defines whether error messages are printed to stderr.
714  static bool UseStderr;
715 
716  // Buf: Buffer for current message.
717  static char Buf[ERR_BUFSIZE];
718 
719  // BufPtr: Next free position in buffer.
720  static char *BufPtr;
721 
722  // BufFree: Number of free characters in buffer.
723  static int BufFree;
724 
725  // NumErrs: Number of error messages after last reset().
726  static int NumErrs;
727 
728  // ErrMsg: Array of last error messages.
729  static char ErrMsg[ERR_MAXERRS][ERR_BUFSIZE];
730 
731 //-----------------------------------------------------------------------------
732 // There are no objects of this class, therefore no constructor is available:
733 //-----------------------------------------------------------------------------
734 
735  private:
736 
737  // Constructor:
738  err_c(); // Not implemented
739 
740  // Destructor:
741  ~err_c(); // Not implemented
742 
743  // Copy-Constructor:
744  err_c(const err_c& obj); // Not implemented
745 
746  // Assignment operator:
747  err_c& operator=(const err_c& obj); // Not implemented
748 
749 
750 //-----------------------------------------------------------------------------
751 // End of Class:
752 //-----------------------------------------------------------------------------
753 
754 };
755 
756 
757 //=============================================================================
758 // End of Include File:
759 //=============================================================================
760 
761 #endif
762 
static void use_stderr(bool b)
Definition: err.cpp:130
static void null_char(str_t filename, int lineno)
Definition: err.cpp:461
Runtime assertion check.
static void syntax_eof()
Definition: err.cpp:546
static void malloc_failed(unsigned int chunk_size, int num_chunks)
Definition: err.cpp:143
static void cgi_premature_eof()
Definition: err.cpp:395
static void line_too_long(str_t filename, int lineno)
Definition: err.cpp:480
static void syntax_newline()
Definition: err.cpp:537
static void dump_ptr(const void *p)
Definition: err.cpp:791
static void bad_content_length()
Definition: err.cpp:370
static void dump_str(str_t str)
Definition: err.cpp:705
static void test_has_no_arg(str_t test_id)
Definition: err.cpp:600
static str_t msg(int n=0)
Definition: err.cpp:80
static void cgi_null_char()
Definition: err.cpp:407
static void stack_overflow(str_t name, int curr_limit)
Definition: err.cpp:164
Defines type str_t and some useful string functions.
static void benchmark_with_debug_code()
Definition: err.cpp:658
Definition: err.h:75
static void pred_arity_too_large(str_t name, int arity, int limit)
Definition: err.cpp:248
static void cgi_field_not_terminated()
Definition: err.cpp:419
static void cgi_duplicate_program()
Definition: err.cpp:431
static void dump_bool(bool b)
Definition: err.cpp:779
static void bad_content_type()
Definition: err.cpp:357
static int num_errs()
Definition: err.cpp:71
static void unknown_option(str_t arg)
Definition: err.cpp:645
static void syntax_input(char c)
Definition: err.cpp:528
static void invalid_test_arg(str_t test_id, int arg)
Definition: err.cpp:614
static void cgi_no_program()
Definition: err.cpp:443
static void dump_begin(str_t headline)
Definition: err.cpp:685
const char * str_t
Definition: str.h:41
static void pred_too_many_rels(str_t name, int limit)
Definition: err.cpp:264
Some basic version settings.
static void store_fact_failed(str_t filename, int line_no, str_t pred_name)
Definition: err.cpp:573
static void read_failed(str_t filename, str_t msg)
Definition: err.cpp:325
static void reset()
Definition: err.cpp:53
static void dump_uint(unsigned int n)
Definition: err.cpp:759
static void list_capacity_limit(str_t name, int curr_length)
Definition: err.cpp:204
static void hashtab_limit(str_t tab_name, int hash_size, int hash_pages, int max_pages)
Definition: err.cpp:224
static void bad_request_method()
Definition: err.cpp:344
static void dump_char(char c)
Definition: err.cpp:726
static bool open_alert(str_t filename)
Definition: err.cpp:100
static bool ok()
Definition: err.cpp:62
static void debug_output_disabled()
Definition: err.cpp:669
static void flexarr_capacity_limit(str_t name, int curr_length)
Definition: err.cpp:184
static void dump_end()
Definition: err.cpp:811
static void syntax_end()
Definition: err.cpp:555
static void cgi_security(str_t filename)
Definition: err.cpp:283
static void dump_int(int n)
Definition: err.cpp:739
static void open_failed(str_t filename, str_t msg)
Definition: err.cpp:296
static void option_missing()
Definition: err.cpp:634
static void bad_cgi_hex()
Definition: err.cpp:383
static void dump_nl()
Definition: err.cpp:717
static void syntax_begin(str_t filename, int line, str_t msg)
Definition: err.cpp:505
static bool close_alert()
Definition: err.cpp:117
static void close_failed(str_t filename, str_t msg)
Definition: err.cpp:311