Debian Codegraph @

debug.c

raw
1 /*
2 * $Id: debug.c 558 2007-06-15 19:17:02Z elliotth $
3 *
4 * Copyright (c) 1996-2002, Darren Hiebert
5 *
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
8 *
9 * This module contains debugging functions.
10 */
11
12 /*
13 * INCLUDE FILES
14 */
15 #include "general.h" /* must always come first */
16
17 #include <ctype.h>
18 #include <stdarg.h>
19
20 #include "debug.h"
21 #include "options.h"
22 #include "read.h"
23
24 /*
25 * FUNCTION DEFINITIONS
26 */
27
28 #ifdef DEBUG
29
30 extern void lineBreak (void) {} /* provides a line-specified break point */
31
32 extern void debugPrintf (
33 const enum eDebugLevels level, const char *const format, ... )
34 {
35 va_list ap;
36
37 va_start (ap, format);
38 if (debug (level))
39 vprintf (format, ap);
40 fflush (stdout);
41 va_end (ap);
42 }
43
44 extern void debugPutc (const int level, const int c)
45 {
46 if (debug (level) && c != EOF)
47 {
48 if (c == STRING_SYMBOL) printf ("\"string\"");
49 else if (c == CHAR_SYMBOL) printf ("'c'");
50 else putchar (c);
51
52 fflush (stdout);
53 }
54 }
55
56 extern void debugParseNest (const boolean increase, const unsigned int level)
57 {
58 debugPrintf (DEBUG_PARSE, "<*%snesting:%d*>", increase ? "++" : "--", level);
59 }
60
61 extern void debugCppNest (const boolean begin, const unsigned int level)
62 {
63 debugPrintf (DEBUG_CPP, "<*cpp:%s level %d*>", begin ? "begin":"end", level);
64 }
65
66 extern void debugCppIgnore (const boolean ignore)
67 {
68 debugPrintf (DEBUG_CPP, "<*cpp:%s ignore*>", ignore ? "begin":"end");
69 }
70
71 extern void debugEntry (const tagEntryInfo *const tag)
72 {
73 const char *const scope = tag->isFileScope ? "{fs}" : "";
74
75 if (debug (DEBUG_PARSE))
76 {
77 printf ("<#%s%s:%s", scope, tag->kindName, tag->name);
78
79 if (tag->extensionFields.scope [0] != NULL &&
80 tag->extensionFields.scope [1] != NULL)
81 printf (" [%s:%s]", tag->extensionFields.scope [0],
82 tag->extensionFields.scope [1]);
83
84 if (Option.extensionFields.inheritance &&
85 tag->extensionFields.inheritance != NULL)
86 printf (" [inherits:%s]", tag->extensionFields.inheritance);
87
88 if (Option.extensionFields.fileScope &&
89 tag->isFileScope && ! isHeaderFile ())
90 printf (" [file:]");
91
92 if (Option.extensionFields.access &&
93 tag->extensionFields.access != NULL)
94 printf (" [access:%s]", tag->extensionFields.access);
95
96 if (Option.extensionFields.implementation &&
97 tag->extensionFields.implementation != NULL)
98 printf (" [imp:%s]", tag->extensionFields.implementation);
99
100 if (Option.extensionFields.typeRef &&
101 tag->extensionFields.typeRef [0] != NULL &&
102 tag->extensionFields.typeRef [1] != NULL)
103 printf (" [%s:%s]", tag->extensionFields.typeRef [0],
104 tag->extensionFields.typeRef [1]);
105
106 printf ("#>");
107 fflush (stdout);
108 }
109 }
110
111 #endif
112
113 /* vi:set tabstop=4 shiftwidth=4: */