Replace utils_make_human_readable_str() with g_format_size()
[geany-mirror.git] / ctags / parsers / cpreprocessor.h
blobfe031bd21a2493025293ed3e061aac509be29fb0
1 /*
2 * Copyright (c) 1998-2002, Darren Hiebert
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
7 * External interface to get.c
8 */
9 #ifndef CTAGS_MAIN_GET_H
10 #define CTAGS_MAIN_GET_H
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
16 #include "types.h"
17 #include "vstring.h"
20 * MACROS
24 * cppIs... macros are for the value returned from cppGetc(). Don't
25 * use "char" value. Don't pass a value stored to C-string
26 * (char*... or char[]) or vString.
28 * cppGetc() can return the value out of range of unsigned char.
29 * cppGetc calls skipToEndOfString() and skipToEndOfString() internally.
30 * They return STRING_SYMBOL (== 338) and CHAR_SYMBOL (== 322) in a
31 * case. (cppGetc() can return EOF (== -1). However, it is not an issue
32 * here.)
34 * is...() macros/functions defined in ctype.h can handle the value of
35 * an unsigned char or EOF; we cannot pass STRING_SYMBOL or CHAR_SYMBOL
36 * returned from cppGetc().
38 * Depending on the platform, isalpha(338) returns different value.
39 * As far as Fedora22, it returns 0. On Windows 2010, it returns 1.
41 * So, we need cppIs... macros.
42 * cppIs... macros considers STRING_SYMBOL and CHAR_SYMBOL */
44 #define cppIsascii(c) ((c >= 0) && (c < 0x80))
45 /* isascii is not portable enough. */
47 /* Is the character valid as a character of a C identifier?
48 * VMS allows '$' in identifiers.
50 #define cppIsalnum(c) (cppIsascii(c) && isalnum(c))
51 #define cppIsident(c) (cppIsalnum(c) \
52 || (c) == '_' || (c) == '$')
54 /* Is the character valid as the first character of a C identifier?
55 * C++ allows '~' in destructors.
56 * VMS allows '$' in identifiers.
58 #define cppIsalpha(c) (cppIsascii(c) && isalpha(c))
59 #define cppIsident1(c) (cppIsalpha(c) \
60 || (c) == '_' || (c) == '~' || (c) == '$')
62 #define cppIsspace(c) (cppIsascii(c) && isspace(c))
63 #define cppIsdigit(c) (cppIsascii(c) && isdigit(c))
66 #define RoleTemplateUndef { true, "undef", "undefined" }
68 #define RoleTemplateSystem { true, "system", "system header" }
69 #define RoleTemplateLocal { true, "local", "local header" }
72 * FUNCTION PROTOTYPES
74 extern bool cppIsBraceFormat (void);
75 extern unsigned int cppGetDirectiveNestLevel (void);
77 /* Don't forget to set useCort true in your parser.
78 * The corkQueue is needed to capture macro parameters.
80 extern void cppInit (const bool state,
81 const bool hasAtLiteralStrings,
82 const bool hasCxxRawLiteralStrings,
83 const bool hasSingleQuoteLiteralNumbers,
84 int defineMacroKindIndex,
85 int macroUndefRoleIndex,
86 int headerKindIndex,
87 int headerSystemRoleIndex, int headerLocalRoleIndex,
88 int macroParamKindIndex,
89 int macrodefFieldIndex);
91 extern void cppTerminate (void);
92 extern void cppBeginStatement (void);
93 extern void cppEndStatement (void);
94 extern void cppUngetc (const int c);
95 extern int cppUngetBufferSize();
96 extern void cppUngetString(const char * string,int len);
97 extern int cppGetc (void);
98 extern const vString * cppGetLastCharOrStringContents (void);
100 /* Notify the external parser state for the purpose of conditional
101 * branch choice. The CXX parser stores the block level here. */
102 extern void cppPushExternalParserBlock(void);
103 extern void cppPopExternalParserBlock(void);
105 #define CPP_MACRO_REPLACEMENT_FLAG_VARARGS 1
106 #define CPP_MACRO_REPLACEMENT_FLAG_STRINGIFY 2
108 typedef struct sCppMacroReplacementPartInfo {
109 int parameterIndex; /* -1 if this part is a constant */
110 int flags;
111 vString * constant; /* not NULL only if parameterIndex != -1 */
112 struct sCppMacroReplacementPartInfo * next;
113 } cppMacroReplacementPartInfo;
115 typedef struct sCppMacroInfo {
116 bool hasParameterList; /* true if the macro has a trailing () */
117 cppMacroReplacementPartInfo * replacements;
118 int useCount;
119 struct sCppMacroInfo * next;
120 } cppMacroInfo;
122 extern cppMacroInfo * cppFindMacro (const char *const name);
123 extern void cppUngetStringBuiltByMacro (const char * string,int len, cppMacroInfo *macro);
126 * Build a replacement string for the specified macro.
127 * If the macro has parameters, they will be used.
128 * Parameters not found in the list will be assumed to be empty.
129 * May return NULL or equivalently an empty replacement string.
131 extern vString * cppBuildMacroReplacement(
132 const cppMacroInfo * macro,
133 const char ** parameters, /* may be NULL */
134 int parameterCount
137 #endif /* CTAGS_MAIN_GET_H */