1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
13 ******************************************************************************/
14 #ifndef _Common_Error_HH
15 #define _Common_Error_HH
28 * Class Error_Context. :)
32 /** Counts errors, warnings. */
33 static unsigned int error_count, warning_count;
34 /** Indicates whether the actual chain was printed. */
35 static bool chain_printed;
36 /** The head and tail of the actual chain. */
37 static Error_Context *head, *tail;
39 /** List-linking pointers. This contains the saved chain in a
40 * restorer element. */
41 Error_Context *prev, *next;
42 /** Pointer to the location info structure. */
43 const Location *location;
44 /** The message of the element. */
46 /** Indicates whether this element was already printed. */
48 /** Indicates whether this element contains an outer chain. */
50 /** Indicates whether the outer chain was printed. */
52 /** Maximum number of errors to report */
53 static unsigned int max_errors;
55 /** Copy constructor not implemented. */
56 Error_Context(const Error_Context& p);
57 /** Assignment not implemented */
58 Error_Context& operator=(const Error_Context& p);
60 /** Prints the actual chain of error contexts to fp. */
61 static void print_context(FILE *fp);
63 /** Starts a new chain and preserves/restores the existing chain,
64 * but keeps the n_keep elements of the old chain. */
65 Error_Context(size_t n_keep = 0);
66 /** Adds a new element to the chain. The message shall be set
67 * later with a call to set_message (e.g. in a conditional
69 Error_Context(const Location *p_location);
70 /** Adds a new element to the chain with the given message. */
71 Error_Context(const Location *p_location, const char *p_fmt, ...)
72 __attribute__ ((__format__ (__printf__, 3, 4)));
73 /** Destructor. Removes element from the chain. */
76 /** Assigns the given message to the element */
77 void set_message(const char *p_fmt, ...)
78 __attribute__ ((__format__ (__printf__, 2, 3)));
80 /** Generic error reporting function. */
81 static void report_error(const Location *loc, const char *fmt,
84 /** Generic warning reporting function. */
85 static void report_warning(const Location *loc, const char *fmt,
88 static void report_note(const Location *loc, const char *fmt,
91 /** Returns the number of errors encountered. */
92 static unsigned int get_error_count() { return error_count; }
93 /** Returns the number of warnings encountered. */
94 static unsigned int get_warning_count() { return warning_count; }
95 /** Increments the error counter. */
96 static void increment_error_count();
97 /** Increments the warning counter. */
98 static void increment_warning_count();
100 /** Prints statistics about the number of errors and warnings */
101 static void print_error_statistics();
103 /** Set the maximum number of errors */
104 static void set_max_errors(unsigned int maxe) {
109 } // namespace Common
111 #endif // _Common_Error_HH