Merge pull request #3560 from techee/cancel_popups
[geany-mirror.git] / ctags / parsers / cpreprocessor.h
blob3bd78bb654ee9b0f53770e08a76c3fba858be3c8
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 */
17 #include "debug.h"
18 #include "ptrarray.h"
19 #include "types.h"
20 #include "vstring.h"
23 * MACROS
25 /* symbolic representations, above 0xFF not to conflict with any byte */
26 #define CPP_STRING_SYMBOL ('S' + 0xff)
27 #define CPP_CHAR_SYMBOL ('C' + 0xff)
30 * cppIs... macros are for the value returned from cppGetc(). Don't
31 * use "char" value. Don't pass a value stored to C-string
32 * (char*... or char[]) or vString.
34 * cppGetc() can return the value out of range of unsigned char.
35 * cppGetc calls skipToEndOfString() and skipToEndOfString() internally.
36 * They return STRING_SYMBOL (== 338) and CHAR_SYMBOL (== 322) in a
37 * case. (cppGetc() can return EOF (== -1). However, it is not an issue
38 * here.)
40 * is...() macros/functions defined in ctype.h can handle the value of
41 * an unsigned char or EOF; we cannot pass STRING_SYMBOL or CHAR_SYMBOL
42 * returned from cppGetc().
44 * Depending on the platform, isalpha(338) returns different value.
45 * As far as Fedora22, it returns 0. On Windows 2010, it returns 1.
47 * So, we need cppIs... macros.
48 * cppIs... macros considers STRING_SYMBOL and CHAR_SYMBOL */
50 #define cppIsascii(c) ((c >= 0) && (c < 0x80))
51 /* isascii is not portable enough. */
53 /* Is the character valid as a character of a C identifier?
54 * VMS allows '$' in identifiers.
56 #define cppIsalnum(c) (cppIsascii(c) && isalnum(c))
57 #define cppIsident(c) (cppIsalnum(c) \
58 || (c) == '_' || (c) == '$')
60 /* Is the character valid as the first character of a C identifier?
61 * C++ allows '~' in destructors.
62 * VMS allows '$' in identifiers.
64 #define cppIsalpha(c) (cppIsascii(c) && isalpha(c))
65 #define cppIsident1(c) (cppIsalpha(c) \
66 || (c) == '_' || (c) == '~' || (c) == '$')
68 #define cppIsspace(c) (cppIsascii(c) && isspace(c))
69 #define cppIsdigit(c) (cppIsascii(c) && isdigit(c))
72 #define RoleTemplateUndef { true, "undef", "undefined" }
73 #define RoleTemplateCondition { false, "condition", "used in part of #if/#ifdef/#elif conditions" }
75 #define RoleTemplateSystem { true, "system", "system header" }
76 #define RoleTemplateLocal { true, "local", "local header" }
79 * FUNCTION PROTOTYPES
81 extern bool cppIsBraceFormat (void);
82 extern unsigned int cppGetDirectiveNestLevel (void);
84 /* Don't forget to set useCort true in your parser.
85 * The corkQueue is needed to capture macro parameters.
87 extern void cppInit (const bool state,
88 const bool hasAtLiteralStrings,
89 const bool hasCxxRawLiteralStrings,
90 const bool hasSingleQuoteLiteralNumbers,
91 int defineMacroKindIndex,
92 int macroUndefRoleIndex,
93 int macroConditionRoleIndex,
94 int headerKindIndex,
95 int headerSystemRoleIndex, int headerLocalRoleIndex,
96 int macroParamKindIndex,
97 int macrodefFieldIndex);
99 extern void cppTerminate (void);
100 extern void cppBeginStatement (void);
101 extern void cppEndStatement (void);
102 extern void cppUngetc (const int c);
103 extern int cppUngetBufferSize(void);
104 extern void cppUngetString(const char * string,int len);
105 extern int cppGetc (void);
106 extern const vString * cppGetLastCharOrStringContents (void);
109 * Replacement for vStringPut that can handle c > 0xff
111 extern void cppVStringPut (vString * string, const int c);
113 /* Notify the external parser state for the purpose of conditional
114 * branch choice. The CXX parser stores the block level here. */
115 extern void cppPushExternalParserBlock(void);
116 extern void cppPopExternalParserBlock(void);
118 #define CPP_MACRO_REPLACEMENT_FLAG_VARARGS 1
119 #define CPP_MACRO_REPLACEMENT_FLAG_STRINGIFY 2
121 typedef struct sCppMacroReplacementPartInfo {
122 int parameterIndex; /* -1 if this part is a constant */
123 int flags;
124 vString * constant; /* not NULL only if parameterIndex != -1 */
125 struct sCppMacroReplacementPartInfo * next;
126 } cppMacroReplacementPartInfo;
128 typedef struct sCppMacroInfo {
129 char *name; /* the name of macro. Useful for debugging. */
130 bool hasParameterList; /* true if the macro has a trailing () */
131 cppMacroReplacementPartInfo * replacements;
132 int useCount;
133 struct sCppMacroInfo * next;
134 } cppMacroInfo;
136 extern cppMacroInfo * cppFindMacro (const char *const name);
137 extern void cppUngetStringBuiltByMacro (const char * string,int len, cppMacroInfo *macro);
140 * Build a replacement string for the specified macro.
141 * If the macro has parameters, they will be used.
142 * Parameters not found in the list will be assumed to be empty.
143 * May return NULL or equivalently an empty replacement string.
145 extern vString * cppBuildMacroReplacement(
146 const cppMacroInfo * macro,
147 const char ** parameters, /* may be NULL */
148 int parameterCount
151 /* Do the same as cppBuildMacroReplacement with ptrArray<const char*>,
152 * and unget the result of expansion to input cpp stream. */
153 extern void cppBuildMacroReplacementWithPtrArrayAndUngetResult(
154 cppMacroInfo * macro,
155 const ptrArray * args);
157 #ifdef DEBUG
158 extern void cppDebugPutc (const int level, const int c);
159 #endif
161 #endif /* CTAGS_MAIN_GET_H */