Doxygen
Loading...
Searching...
No Matches
pre.l
Go to the documentation of this file.
-1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
13%option never-interactive
14%option prefix="preYY"
15%option reentrant
16%option extra-type="struct preYY_state *"
17%top{
18#include <stdint.h>
19// forward declare yyscan_t to improve type safety
20#define YY_TYPEDEF_YY_SCANNER_T
21struct yyguts_t;
22typedef yyguts_t *yyscan_t;
yyguts_t * yyscan_t
Definition code.l:24
23}
25%{
26
27/*
28 * includes
29 */
30
31#include "doxygen.h"
32
33#include <stack>
34#include <deque>
35#include <algorithm>
36#include <utility>
37#include <mutex>
38#include <thread>
39#include <algorithm>
40#include <cstdio>
41#include <cassert>
42#include <cctype>
43#include <cerrno>
44
45#include "qcstring.h"
46#include "containers.h"
47#include "pre.h"
48#include "constexp.h"
49#include "define.h"
50#include "message.h"
51#include "util.h"
52#include "defargs.h"
53#include "debug.h"
54#include "portable.h"
55#include "arguments.h"
56#include "entry.h"
57#include "condparser.h"
58#include "config.h"
59#include "filedef.h"
60#include "regex.h"
61#include "fileinfo.h"
62#include "trace.h"
63#include "debug.h"
64#include "stringutil.h"
65
66#define YY_NO_UNISTD_H 1
67
68[[maybe_unused]] static const char *stateToString(int state);
69
71{
72 preYY_CondCtx(const QCString &file,int line,const QCString &id,bool b)
73 : fileName(file), lineNr(line), sectionId(id), skip(b) {}
77 bool skip;
78};
80struct FileState
81{
82 int lineNr = 1;
83 int curlyCount = 0;
84 std::string fileBuf;
85 const std::string *oldFileBuf = nullptr;
87 YY_BUFFER_STATE bufState = 0;
89 bool lexRulesPart = false;
90};
92struct PreIncludeInfo
93{
94 PreIncludeInfo(const QCString &fn,FileDef *srcFd, FileDef *dstFd,const QCString &iName,bool loc, bool imp)
95 : fileName(fn), fromFileDef(srcFd), toFileDef(dstFd), includeName(iName), local(loc), imported(imp)
96 {
97 }
98 QCString fileName; // file name in which the include statement was found
99 FileDef *fromFileDef; // filedef in which the include statement was found
100 FileDef *toFileDef; // filedef to which the include is pointing
101 QCString includeName; // name used in the #include statement
102 bool local; // is it a "local" or <global> include
103 bool imported; // include via "import" keyword (Objective-C)
106/** A dictionary of managed Define objects. */
107typedef std::map< std::string, Define > DefineMap;
108
109/** @brief Class that manages the defines available while
110 * preprocessing files.
111 */
112class DefineManager
113{
114 private:
115 /** Local class used to hold the defines for a single file */
116 class DefinesPerFile
117 {
118 public:
119 /** Creates an empty container for defines */
123 }
124 void addInclude(const std::string &fileName)
125 {
126 m_includedFiles.insert(fileName);
127 }
128 void store(const DefineMap &fromMap)
129 {
130 for (auto &[name,define] : fromMap)
131 {
132 m_defines.emplace(name,define);
133 }
134 //printf(" m_defines.size()=%zu\n",m_defines.size());
135 m_stored=true;
136 }
137 void retrieve(DefineMap &toMap)
138 {
139 StringUnorderedSet includeStack;
140 retrieveRec(toMap,includeStack);
141 }
142 void retrieveRec(DefineMap &toMap,StringUnorderedSet &includeStack)
143 {
144 //printf(" retrieveRec #includedFiles=%zu\n",m_includedFiles.size());
145 for (auto incFile : m_includedFiles)
146 {
147 DefinesPerFile *dpf = m_parent->find(incFile);
148 if (dpf && includeStack.find(incFile)==includeStack.end())
149 {
150 includeStack.insert(incFile);
151 dpf->retrieveRec(toMap,includeStack);
152 //printf(" retrieveRec: processing include %s: #toMap=%zu\n",qPrint(incFile),toMap.size());
153 }
154 }
155 for (auto &[name,define] : m_defines)
156 {
157 toMap.emplace(name,define);
158 }
159 }
160 bool stored() const { return m_stored; }
161 private:
165 bool m_stored = false;
166 };
168 friend class DefinesPerFile;
169 public:
171 void addInclude(const std::string &fromFileName,const std::string &toFileName)
172 {
173 //printf("DefineManager::addInclude('%s'->'%s')\n",qPrint(fromFileName),qPrint(toFileName));
174 auto it = m_fileMap.find(fromFileName);
175 if (it==m_fileMap.end())
176 {
177 it = m_fileMap.emplace(fromFileName,std::make_unique<DefinesPerFile>(this)).first;
178 }
179 auto &dpf = it->second;
180 dpf->addInclude(toFileName);
181 }
182
183 void store(const std::string &fileName,const DefineMap &fromMap)
184 {
185 //printf("DefineManager::store(%s,#=%zu)\n",qPrint(fileName),fromMap.size());
186 auto it = m_fileMap.find(fileName);
187 if (it==m_fileMap.end())
188 {
189 it = m_fileMap.emplace(fileName,std::make_unique<DefinesPerFile>(this)).first;
190 }
191 it->second->store(fromMap);
192 }
193
194 void retrieve(const std::string &fileName,DefineMap &toMap)
195 {
196 auto it = m_fileMap.find(fileName);
197 if (it!=m_fileMap.end())
198 {
199 auto &dpf = it->second;
200 dpf->retrieve(toMap);
201 }
202 //printf("DefineManager::retrieve(%s,#=%zu)\n",qPrint(fileName),toMap.size());
203 }
204
205 bool alreadyProcessed(const std::string &fileName) const
206 {
207 auto it = m_fileMap.find(fileName);
208 if (it!=m_fileMap.end())
209 {
210 return it->second->stored();
211 }
212 return false;
213 }
214
215 private:
216 /** Helper function to return the DefinesPerFile object for a given file name. */
217 DefinesPerFile *find(const std::string &fileName) const
218 {
219 auto it = m_fileMap.find(fileName);
220 return it!=m_fileMap.end() ? it->second.get() : nullptr;
221 }
222
223 std::unordered_map< std::string, std::unique_ptr<DefinesPerFile> > m_fileMap;
224};
226
227/* -----------------------------------------------------------------
228 *
229 * global state
230 */
231static std::mutex g_debugMutex;
232static std::mutex g_globalDefineMutex;
233static std::mutex g_updateGlobals;
237/* -----------------------------------------------------------------
238 *
239 * scanner's state
240 */
241
242struct preYY_state
243{
244 int yyLineNr = 1;
245 int yyMLines = 1;
246 int yyColNr = 1;
248 FileDef *yyFileDef = nullptr;
250 int ifcount = 0;
251 int defArgs = -1;
257 bool defContinue = false;
258 bool defVarArgs = false;
261 const std::string *inputBuf = nullptr;
262 int inputBufPos = 0;
263 std::string *outputBuf = nullptr;
264 int roundCount = 0;
265 bool quoteArg = false;
266 bool idStart = false;
268 bool expectGuard = false;
273 int curlyCount = 0;
274 bool nospaces = false; // add extra spaces during macro expansion
275 int javaBlock = 0;
277 bool macroExpansion = false; // from the configuration
278 bool expandOnlyPredef = false; // from the configuration
281 bool insideComment = false;
282 bool isImported = false;
284 int condCtx = 0;
285 bool skip = false;
286 bool insideIDL = false;
287 bool insideCS = false; // C# has simpler preprocessor
288 bool insideFtn = false;
289 bool isSource = false;
291 yy_size_t fenceSize = 0;
292 char fenceChar = ' ';
293 bool ccomment = false;
295 bool isSpecialComment = false;
299 std::stack< std::unique_ptr<preYY_CondCtx> > condStack;
300 std::deque< std::unique_ptr<FileState> > includeStack;
301 std::unordered_map<std::string,Define*> expandedDict;
304 DefineMap contextDefines; // macros imported from other files
305 DefineMap localDefines; // macros defined in this file
310 int lastContext = 0;
311 bool lexRulesPart = false;
312 char prevChar=0;
315// stateless functions
316static QCString escapeAt(const QCString &text);
318static char resolveTrigraph(char c);
319
320// stateful functions
321static inline void outputArray(yyscan_t yyscanner,const char *a,yy_size_t len);
322static inline void outputString(yyscan_t yyscanner,const QCString &s);
323static inline void outputChar(yyscan_t yyscanner,char c);
324static inline void outputSpaces(yyscan_t yyscanner,char *s);
325static inline void outputSpace(yyscan_t yyscanner,char c);
326static inline void extraSpacing(yyscan_t yyscanner);
327static QCString expandMacro(yyscan_t yyscanner,const QCString &name);
328static void readIncludeFile(yyscan_t yyscanner,const QCString &inc);
329static void incrLevel(yyscan_t yyscanner);
330static void decrLevel(yyscan_t yyscanner);
331static void setCaseDone(yyscan_t yyscanner,bool value);
332static bool otherCaseDone(yyscan_t yyscanner);
333static bool computeExpression(yyscan_t yyscanner,const QCString &expr);
334static void startCondSection(yyscan_t yyscanner,const QCString &sectId);
335static void endCondSection(yyscan_t yyscanner);
336static void addMacroDefinition(yyscan_t yyscanner);
337static void addDefine(yyscan_t yyscanner);
338static void setFileName(yyscan_t yyscanner,const QCString &name);
339static int yyread(yyscan_t yyscanner,char *buf,int max_size);
340static Define * isDefined(yyscan_t yyscanner,const QCString &name);
341static void determineBlockName(yyscan_t yyscanner);
342static yy_size_t getFenceSize(char *txt, yy_size_t leng);
343
344/* ----------------------------------------------------------------- */
345
346#undef YY_INPUT
347#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
348
349// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
350static inline const char *getLexerFILE() {return __FILE__;}
351#include "doxygen_lex.h"
353/* ----------------------------------------------------------------- */
354
constant expression parser used for the C preprocessor
Definition constexp.h:26
A class representing a macro definition.
Definition define.h:31
Local class used to hold the defines for a single file.
Definition pre.l:119
void addInclude(const std::string &fileName)
Definition pre.l:126
DefinesPerFile(DefineManager *parent)
Creates an empty container for defines.
Definition pre.l:122
DefineManager * m_parent
Definition pre.l:164
void retrieveRec(DefineMap &toMap, StringUnorderedSet &includeStack)
Definition pre.l:144
void store(const DefineMap &fromMap)
Definition pre.l:130
StringUnorderedSet m_includedFiles
Definition pre.l:166
void retrieve(DefineMap &toMap)
Definition pre.l:139
Class that manages the defines available while preprocessing files.
Definition pre.l:115
bool alreadyProcessed(const std::string &fileName) const
Definition pre.l:207
void addInclude(const std::string &fromFileName, const std::string &toFileName)
Definition pre.l:173
friend class DefinesPerFile
Definition pre.l:170
void store(const std::string &fileName, const DefineMap &fromMap)
Definition pre.l:185
std::unordered_map< std::string, std::unique_ptr< DefinesPerFile > > m_fileMap
Definition pre.l:225
void retrieve(const std::string &fileName, DefineMap &toMap)
Definition pre.l:196
DefinesPerFile * find(const std::string &fileName) const
Helper function to return the DefinesPerFile object for a given file name.
Definition pre.l:219
A model of a file symbol.
Definition filedef.h:99
Container class representing a vector of objects with keys.
Definition linkedmap.h:36
This is an alternative implementation of QCString.
Definition qcstring.h:101
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition code.l:3971
static const char * stateToString(int state)
static const char * getLexerFILE()
Definition code.l:263
static void startCondSection(yyscan_t yyscanner, const QCString &sectId)
static void endCondSection(yyscan_t yyscanner)
static bool readIncludeFile(yyscan_t yyscanner, const QCString &inc, const QCString &blockId)
std::stack< bool > BoolStack
Definition containers.h:35
std::unordered_set< std::string > StringUnorderedSet
Definition containers.h:29
std::vector< std::string > StringVector
Definition containers.h:33
std::map< std::string, int > IntMap
Definition containers.h:37
std::vector< Define > DefineList
List of all macro definitions.
Definition define.h:49
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1330
Portable versions of functions that are platform dependent.
std::map< std::string, Define > DefineMap
A dictionary of managed Define objects.
Definition pre.l:109
static void setCaseDone(yyscan_t yyscanner, bool value)
Definition pre.l:2279
static void addMacroDefinition(yyscan_t yyscanner)
Definition pre.l:3555
static void decrLevel(yyscan_t yyscanner)
Definition pre.l:2251
static void addDefine(yyscan_t yyscanner)
Definition pre.l:3526
static void determineBlockName(yyscan_t yyscanner)
Definition pre.l:3647
static void incrLevel(yyscan_t yyscanner)
Definition pre.l:2244
static QCString expandMacro(yyscan_t yyscanner, const QCString &name)
Definition pre.l:3512
static void outputSpaces(yyscan_t yyscanner, char *s)
Definition pre.l:3623
static Define * isDefined(yyscan_t yyscanner, const QCString &name)
Returns a reference to a Define object given its name or 0 if the Define does not exist.
Definition pre.l:3979
static void outputString(yyscan_t yyscanner, const QCString &s)
Definition pre.l:3611
static void setFileName(yyscan_t yyscanner, const QCString &name)
Definition pre.l:2223
static std::mutex g_globalDefineMutex
Definition pre.l:234
static void outputChar(yyscan_t yyscanner, char c)
Definition pre.l:3599
static QCString extractTrailingComment(const QCString &s)
Definition pre.l:2417
static char resolveTrigraph(char c)
Definition pre.l:3889
static DefineManager g_defineManager
Definition pre.l:236
yyguts_t * yyscan_t
Definition pre.l:24
static yy_size_t getFenceSize(char *txt, yy_size_t leng)
Definition pre.l:2212
static std::mutex g_updateGlobals
Definition pre.l:235
static bool otherCaseDone(yyscan_t yyscanner)
Definition pre.l:2265
static void outputArray(yyscan_t yyscanner, const char *a, yy_size_t len)
Definition pre.l:3605
static void extraSpacing(yyscan_t yyscanner)
Definition pre.l:3634
static QCString escapeAt(const QCString &text)
Definition pre.l:3874
static bool computeExpression(yyscan_t yyscanner, const QCString &expr)
Definition pre.l:3493
static void outputSpace(yyscan_t yyscanner, char c)
Definition pre.l:3617
static std::mutex g_debugMutex
Definition pre.l:233
Some helper functions for std::string.
std::string fileBuf
Definition pre.l:86
YY_BUFFER_STATE bufState
Definition pre.l:89
int lineNr
Definition pre.l:84
QCString fileName
Definition pre.l:90
bool lexRulesPart
Definition pre.l:91
int curlyCount
Definition pre.l:85
const std::string * oldFileBuf
Definition pre.l:87
int oldFileBufPos
Definition pre.l:88
QCString fileName
Definition pre.l:100
FileDef * toFileDef
Definition pre.l:102
bool local
Definition pre.l:104
bool imported
Definition pre.l:105
PreIncludeInfo(const QCString &fn, FileDef *srcFd, FileDef *dstFd, const QCString &iName, bool loc, bool imp)
Definition pre.l:96
FileDef * fromFileDef
Definition pre.l:101
QCString includeName
Definition pre.l:103
QCString fileName
Definition pre.l:76
bool skip
Definition pre.l:79
QCString sectionId
Definition pre.l:78
preYY_CondCtx(const QCString &file, int line, const QCString &id, bool b)
Definition pre.l:74
int lineNr
Definition pre.l:77
bool expectGuard
Definition pre.l:270
int commentCount
Definition pre.l:282
BoolStack levelGuard
Definition pre.l:300
bool macroExpansion
Definition pre.l:279
FileDef * inputFileDef
Definition pre.l:251
QCString potentialDefine
Definition pre.l:281
char prevChar
Definition pre.l:314
bool defContinue
Definition pre.l:259
bool insideFtn
Definition pre.l:290
StringUnorderedSet expanded
Definition pre.l:304
QCString defLitText
Definition pre.l:256
LinkedMap< PreIncludeInfo > includeRelations
Definition pre.l:309
int yyColNr
Definition pre.l:248
QCString defExtraSpacing
Definition pre.l:258
int lastContext
Definition pre.l:312
bool isSource
Definition pre.l:291
StringUnorderedSet pragmaSet
Definition pre.l:310
bool lexRulesPart
Definition pre.l:313
char fenceChar
Definition pre.l:294
bool skip
Definition pre.l:287
yy_size_t fenceSize
Definition pre.l:293
QCString defName
Definition pre.l:254
IntMap argMap
Definition pre.l:299
bool expandOnlyPredef
Definition pre.l:280
ConstExpressionParser constExpParser
Definition pre.l:305
QCString defText
Definition pre.l:255
int roundCount
Definition pre.l:266
bool idStart
Definition pre.l:268
int curlyCount
Definition pre.l:275
int lastCContext
Definition pre.l:261
std::unordered_map< std::string, Define * > expandedDict
Definition pre.l:303
QCString guardName
Definition pre.l:271
bool insideCS
Definition pre.l:289
bool isSpecialComment
Definition pre.l:297
int yyLineNr
Definition pre.l:246
FileDef * yyFileDef
Definition pre.l:250
int javaBlock
Definition pre.l:277
bool nospaces
Definition pre.l:276
std::deque< std::unique_ptr< FileState > > includeStack
Definition pre.l:302
bool quoteArg
Definition pre.l:267
int yyMLines
Definition pre.l:247
int defArgs
Definition pre.l:253
bool isImported
Definition pre.l:284
DefineMap localDefines
Definition pre.l:307
QCString defArgsStr
Definition pre.l:257
QCString blockName
Definition pre.l:285
DefineMap contextDefines
Definition pre.l:306
StringVector pathList
Definition pre.l:298
QCString delimiter
Definition pre.l:296
int ifcount
Definition pre.l:252
std::stack< std::unique_ptr< preYY_CondCtx > > condStack
Definition pre.l:301
QCString guardExpr
Definition pre.l:274
int lastCPPContext
Definition pre.l:262
bool ccomment
Definition pre.l:295
const std::string * inputBuf
Definition pre.l:263
QCString incName
Definition pre.l:273
QCString lastGuardName
Definition pre.l:272
bool insideComment
Definition pre.l:283
std::string * outputBuf
Definition pre.l:265
QCString fileName
Definition pre.l:249
int findDefArgContext
Definition pre.l:269
int inputBufPos
Definition pre.l:264
int condCtx
Definition pre.l:286
bool insideIDL
Definition pre.l:288
bool defVarArgs
Definition pre.l:260
DefineList macroDefinitions
Definition pre.l:308
A bunch of utility functions.
355%}
356
357IDSTART [a-z_A-Z\x80-\xFF]
358ID {IDSTART}[a-z_A-Z0-9\x80-\xFF]*
359B [ \t]
360Bopt {B}*
361BN [ \t\r\n]
362RAWBEGIN (u|U|L|u8)?R\"[^ \t\‍(\‍)\\‍]{0,16}"("
363RAWEND ")"[^ \t\‍(\‍)\\‍]{0,16}\"
364CHARLIT (("'"\\‍[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
365
366CMD [\\@]
367FORMULA_START {CMD}("f{"|"f$"|"f["|"f(")
368FORMULA_END {CMD}("f}"|"f$"|"f]"|"f)")
369VERBATIM_START {CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly"|"dot"|"msc"|"startuml"|"code"("{"[^}]*"}")?){BN}+
370VERBATIM_END {CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endmsc"|"enduml"|"endcode")
371VERBATIM_LINE {CMD}"noop"{B}+
372LITERAL_BLOCK {FORMULA_START}|{VERBATIM_START}
373LITERAL_BLOCK_END {FORMULA_END}|{VERBATIM_END}
374
375 // some rule pattern information for rules to handle lex files
376nl (\r\n|\r|\n)
377RulesDelim "%%"{nl}
378RulesSharp "<"[^>\n]*">"
379RulesCurly "{"[^{}\n]*"}"
380StartSquare "["
381StartDouble "\""
382StartRound "("
383StartRoundQuest "(?"
384EscapeRulesCharOpen "\\‍["|"\<"|"\\{"|"\\‍("|"\\\""|"\\ "|"\\\\"
385EscapeRulesCharClose "\\‍]"|"\>"|"\\}"|"\\‍)"
386EscapeRulesChar {EscapeRulesCharOpen}|{EscapeRulesCharClose}
387CHARCE "[:"[^:]*":]"
388
389 // C start comment
390CCS "/\*"
391 // C end comment
392CCE "*\/"
393 // Cpp comment
394CPPC "/\/"
395 // optional characters after import
396ENDIMPORTopt [^\\\n]*
397 // Optional white space
398WSopt [ \t\r]*
399
400 //- begin: NUMBER
401 // Note same defines in commentcnv.l: keep in sync
402DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
403HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
404OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
405BINARY_INTEGER "0"[bB][01][01']*[01]?
406INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
407
408FP_SUF [fFlL]
409
410DIGIT_SEQ [0-9][0-9']*[0-9]?
411FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
412FP_EXP [eE][+-]?{DIGIT_SEQ}
413DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
414DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
415
416HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
417HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
418BIN_EXP [pP][+-]?{DIGIT_SEQ}
419HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
420HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
421
422FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
423FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
424FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
425NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
426 //- end: NUMBER ---------------------------------------------------------------------------
427
428
429%option noyywrap
430
431%x Start
432%x Command
433%x SkipCommand
434%x SkipLine
435%x SkipString
436%x CopyLine
437%x LexCopyLine
438%x CopyString
439%x CopyStringCs
440%x CopyStringFtn
441%x CopyStringFtnDouble
442%x CopyRawString
443%x Include
444%x IncludeID
445%x EndImport
446%x DefName
447%x DefineArg
448%x DefineText
449%x CmakeDefName01
450%x SkipCPPBlock
451%x SkipCComment
452%x ArgCopyCComment
453%x ArgCopyCppComment
454%x CopyCComment
455%x SkipVerbatim
456%x SkipCondVerbatim
457%x SkipCPPComment
458%x JavaDocVerbatimCode
459%x RemoveCComment
460%x RemoveCPPComment
461%x Guard
462%x DefinedExpr1
463%x DefinedExpr2
464%x SkipDoubleQuote
465%x SkipSingleQuote
466%x UndefName
467%x IgnoreLine
468%x FindDefineArgs
469%x ReadString
470%x CondLineC
471%x CondLineCpp
472%x SkipCond
473%x IDLquote
474%x RulesPattern
475%x RulesDouble
476%x RulesRoundDouble
477%x RulesSquare
478%x RulesRoundSquare
479%x RulesRound
480%x RulesRoundQuest
481%x PragmaOnce
482
483%%
484
485<*>\x06
486<*>\x00
487<*>\r
488<*>"??"[=/'()!<>-] { // Trigraph
489 unput(resolveTrigraph(yytext[2]));
490 }
491<Start>^{B}*"#" {
492 yyextra->yyColNr+=(int)yyleng;
493 yyextra->yyMLines=0;
494 yyextra->potentialDefine=yytext;
495 BEGIN(Command);
496 }
497<Start>^("%top{"|"%{") {
498 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Lex) REJECT
499 outputArray(yyscanner,yytext,yyleng);
500 BEGIN(LexCopyLine);
501 }
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5153
502<Start>^{Bopt}"cpp_quote"{Bopt}"("{Bopt}\" {
503 if (yyextra->insideIDL)
504 {
505 BEGIN(IDLquote);
506 }
507 else
508 {
509 REJECT;
510 }
511 }
512<IDLquote>"\\\\" {
513 outputArray(yyscanner,"\\",1);
514 }
515<IDLquote>"\\\"" {
516 outputArray(yyscanner,"\"",1);
517 }
518<IDLquote>"\""{Bopt}")" {
519 BEGIN(Start);
520 }
521<IDLquote>\n {
522 outputChar(yyscanner,'\n');
523 yyextra->yyLineNr++;
524 }
525<IDLquote>. {
526 outputArray(yyscanner,yytext,yyleng);
527 }
528<Start>^{Bopt}/[^#] {
529 outputArray(yyscanner,yytext,yyleng);
530 BEGIN(CopyLine);
531 }
532<Start>^{B}*[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]+{B}*"("[^\‍)\n]*")"/{BN}{1,10}*[:{] { // constructors?
533 int i;
534 for (i=(int)yyleng-1;i>=0;i--)
535 {
536 unput(yytext[i]);
537 }
538 BEGIN(CopyLine);
539 }
540<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\‍(\‍)\n]*"("[^\‍)\n]*")"[^\‍)\n]*")"{B}*\n | // function list macro with one (...) argument, e.g. for K_GLOBAL_STATIC_WITH_ARGS
541<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\‍)\n]*")"{B}*\n | // function like macro
542<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\‍(\‍)\n]*"("[^\‍)\n]*")"[^\‍)\n]*")"/{B}*("//"|"/\*") | // function list macro with one (...) argument followed by comment
543<Start>^{B}*[_A-Z][_A-Z0-9]+{B}*"("[^\‍)\n]*")"/{B}*("//"|"/\*") { // function like macro followed by comment
544 bool skipFuncMacros = Config_getBool(SKIP_FUNCTION_MACROS);
545 QCString name(yytext);
546 int pos = name.find('(');
547 if (pos<0) pos=0; // should never happen
548 name=name.left(pos).stripWhiteSpace();
549
550 Define *def=nullptr;
551 if (skipFuncMacros && !yyextra->insideFtn &&
552 name!="Q_PROPERTY" &&
553 !(
554 (yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
555 yyextra->macroExpansion &&
556 (def=isDefined(yyscanner,name)) &&
557 /*macroIsAccessible(def) &&*/
558 (!yyextra->expandOnlyPredef || def->isPredefined)
559 )
560 )
561 {
562 // Only when ends on \n
563 if (yytext[yyleng-1] == '\n')
564 {
565 outputChar(yyscanner,'\n');
566 yyextra->yyLineNr++;
567 }
568 }
569 else // don't skip
570 {
571 int i;
572 for (i=(int)yyleng-1;i>=0;i--)
573 {
574 unput(yytext[i]);
575 }
576 BEGIN(CopyLine);
577 }
578 }
bool isPredefined
Definition define.h:43
#define Config_getBool(name)
Definition config.h:33
579<CopyLine,LexCopyLine>"extern"{BN}*"\""[^\"]+"\""{BN}*("{")? {
580 QCString text=yytext;
581 yyextra->yyLineNr+=text.contains('\n');
582 outputArray(yyscanner,yytext,yyleng);
583 }
int contains(char c, bool cs=TRUE) const
Definition qcstring.cpp:148
584<CopyLine,LexCopyLine>{RAWBEGIN} {
585 yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
586 outputArray(yyscanner,yytext,yyleng);
587 BEGIN(CopyRawString);
588 }
QCString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:6890
589<CopyLine,LexCopyLine>"{" { // count brackets inside the main file
590 if (yyextra->includeStack.empty())
591 {
592 yyextra->curlyCount++;
593 }
594 outputChar(yyscanner,*yytext);
595 }
596<LexCopyLine>^"%}" {
597 outputArray(yyscanner,yytext,yyleng);
598 }
599<CopyLine,LexCopyLine>"}" { // count brackets inside the main file
600 if (yyextra->includeStack.empty() && yyextra->curlyCount>0)
601 {
602 yyextra->curlyCount--;
603 }
604 outputChar(yyscanner,*yytext);
605 }
606<CopyLine,LexCopyLine>"'"\\‍[0-7]{1,3}"'" {
607 outputArray(yyscanner,yytext,yyleng);
608 }
609<CopyLine,LexCopyLine>"'"\\."'" {
610 outputArray(yyscanner,yytext,yyleng);
611 }
612<CopyLine,LexCopyLine>"'"."'" {
613 outputArray(yyscanner,yytext,yyleng);
614 }
615<CopyLine,LexCopyLine>[$]?@\" {
616 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::CSharp) REJECT;
617 outputArray(yyscanner,yytext,yyleng);
618 BEGIN( CopyStringCs );
619 }
620<CopyLine,LexCopyLine>\" {
621 outputChar(yyscanner,*yytext);
622 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Fortran)
623 {
624 BEGIN( CopyString );
625 }
626 else
627 {
628 BEGIN( CopyStringFtnDouble );
629 }
630 }
631<CopyLine,LexCopyLine>\' {
632 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Fortran) REJECT;
633 outputChar(yyscanner,*yytext);
634 BEGIN( CopyStringFtn );
635 }
636<CopyString>[^\"\\\r\n]{1,1000} {
637 outputArray(yyscanner,yytext,yyleng);
638 }
639<CopyStringCs>[^\"\r\n]{1,1000} {
640 outputArray(yyscanner,yytext,yyleng);
641 }
642<CopyStringCs>\"\" {
643 outputArray(yyscanner,yytext,yyleng);
644 }
645<CopyString>\\. {
646 outputArray(yyscanner,yytext,yyleng);
647 }
648<CopyString,CopyStringCs>\" {
649 outputChar(yyscanner,*yytext);
650 BEGIN( CopyLine );
651 }
652<CopyStringFtnDouble>[^\"\\\r\n]{1,1000} {
653 outputArray(yyscanner,yytext,yyleng);
654 }
655<CopyStringFtnDouble>\\. {
656 outputArray(yyscanner,yytext,yyleng);
657 }
658<CopyStringFtnDouble>\" {
659 outputChar(yyscanner,*yytext);
660 BEGIN( CopyLine );
661 }
662<CopyStringFtn>[^\'\\\r\n]{1,1000} {
663 outputArray(yyscanner,yytext,yyleng);
664 }
665<CopyStringFtn>\\. {
666 outputArray(yyscanner,yytext,yyleng);
667 }
668<CopyStringFtn>\' {
669 outputChar(yyscanner,*yytext);
670 BEGIN( CopyLine );
671 }
672<CopyRawString>{RAWEND} {
673 outputArray(yyscanner,yytext,yyleng);
674 if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
675 {
676 BEGIN( CopyLine );
677 }
678 }
QCString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:6898
679<CopyRawString>[^)]{1,1000} {
680 outputArray(yyscanner,yytext,yyleng);
681 }
682<CopyRawString>. {
683 outputChar(yyscanner,*yytext);
684 }
685<CopyLine,LexCopyLine>{ID}/{BN}{0,80}"(" {
686 yyextra->expectGuard = FALSE;
687 Define *def=nullptr;
688 //def=yyextra->globalDefineDict->find(yytext);
689 //def=isDefined(yyscanner,yytext);
690 //printf("Search for define %s found=%d yyextra->includeStack.empty()=%d "
691 // "yyextra->curlyCount=%d yyextra->macroExpansion=%d yyextra->expandOnlyPredef=%d "
692 // "isPreDefined=%d\n",yytext,def ? 1 : 0,
693 // yyextra->includeStack.empty(),yyextra->curlyCount,yyextra->macroExpansion,yyextra->expandOnlyPredef,
694 // def ? def->isPredefined : -1
695 // );
696 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
697 yyextra->macroExpansion &&
698 (def=isDefined(yyscanner,yytext)) &&
699 (!yyextra->expandOnlyPredef || def->isPredefined)
700 )
701 {
702 //printf("Found it! #args=%d\n",def->nargs);
703 yyextra->roundCount=0;
704 yyextra->defArgsStr=yytext;
705 if (def->nargs==-1) // no function macro
706 {
707 QCString result = def->isPredefined && !def->expandAsDefined ?
708 def->definition :
709 expandMacro(yyscanner,yyextra->defArgsStr);
710 outputString(yyscanner,result);
711 }
712 else // zero or more arguments
713 {
714 yyextra->findDefArgContext = CopyLine;
715 BEGIN(FindDefineArgs);
716 }
717 }
718 else
719 {
720 outputArray(yyscanner,yytext,yyleng);
721 }
722 }
QCString definition
Definition define.h:34
int nargs
Definition define.h:40
bool expandAsDefined
Definition define.h:45
#define FALSE
Definition qcstring.h:34
723<CopyLine>{RulesDelim} {
724 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Lex) REJECT;
725 yyextra->lexRulesPart = !yyextra->lexRulesPart;
726 outputArray(yyscanner,yytext,yyleng);
727 }
728 /* start lex rule handling */
729<CopyLine>{RulesSharp} {
730 if (!yyextra->lexRulesPart) REJECT;
731 if (yyextra->curlyCount) REJECT;
732 outputArray(yyscanner,yytext,yyleng);
733 BEGIN(RulesPattern);
734 }
735<RulesPattern>{EscapeRulesChar} {
736 outputArray(yyscanner,yytext,yyleng);
737 }
738<RulesPattern>{RulesCurly} {
739 outputArray(yyscanner,yytext,yyleng);
740 }
741<RulesPattern>{StartDouble} {
742 outputArray(yyscanner,yytext,yyleng);
743 yyextra->lastContext = YY_START;
744 BEGIN(RulesDouble);
745 }
746<RulesDouble,RulesRoundDouble>"\\\\" {
747 outputArray(yyscanner,yytext,yyleng);
748 }
749<RulesDouble,RulesRoundDouble>"\\\"" {
750 outputArray(yyscanner,yytext,yyleng);
751 }
752<RulesDouble>"\"" {
753 outputArray(yyscanner,yytext,yyleng);
754 BEGIN( yyextra->lastContext ) ;
755 }
756<RulesRoundDouble>"\"" {
757 outputArray(yyscanner,yytext,yyleng);
758 BEGIN(RulesRound) ;
759 }
760<RulesDouble,RulesRoundDouble>. {
761 outputArray(yyscanner,yytext,yyleng);
762 }
763<RulesPattern>{StartSquare} {
764 outputArray(yyscanner,yytext,yyleng);
765 yyextra->lastContext = YY_START;
766 BEGIN(RulesSquare);
767 }
768<RulesSquare,RulesRoundSquare>{CHARCE} {
769 outputArray(yyscanner,yytext,yyleng);
770 }
771<RulesSquare,RulesRoundSquare>"\\‍[" |
772<RulesSquare,RulesRoundSquare>"\\‍]" {
773 outputArray(yyscanner,yytext,yyleng);
774 }
775<RulesSquare>"]" {
776 outputArray(yyscanner,yytext,yyleng);
777 BEGIN(RulesPattern);
778 }
779<RulesRoundSquare>"]" {
780 outputArray(yyscanner,yytext,yyleng);
781 BEGIN(RulesRound) ;
782 }
783<RulesSquare,RulesRoundSquare>"\\\\" {
784 outputArray(yyscanner,yytext,yyleng);
785 }
786<RulesSquare,RulesRoundSquare>. {
787 outputArray(yyscanner,yytext,yyleng);
788 }
789<RulesPattern>{StartRoundQuest} {
790 outputArray(yyscanner,yytext,yyleng);
791 yyextra->lastContext = YY_START;
792 BEGIN(RulesRoundQuest);
793 }
794<RulesRoundQuest>{nl} {
795 outputArray(yyscanner,yytext,yyleng);
796 }
797<RulesRoundQuest>[^)] {
798 outputArray(yyscanner,yytext,yyleng);
799 }
800<RulesRoundQuest>")" {
801 outputArray(yyscanner,yytext,yyleng);
802 BEGIN(yyextra->lastContext);
803 }
804<RulesPattern>{StartRound} {
805 yyextra->roundCount++;
806 outputArray(yyscanner,yytext,yyleng);
807 yyextra->lastContext = YY_START;
808 BEGIN(RulesRound);
809 }
810<RulesRound>{RulesCurly} {
811 outputArray(yyscanner,yytext,yyleng);
812 }
813<RulesRound>{StartSquare} {
814 outputArray(yyscanner,yytext,yyleng);
815 BEGIN(RulesRoundSquare);
816 }
817<RulesRound>{StartDouble} {
818 outputArray(yyscanner,yytext,yyleng);
819 BEGIN(RulesRoundDouble);
820 }
821<RulesRound>{EscapeRulesChar} {
822 outputArray(yyscanner,yytext,yyleng);
823 }
824<RulesRound>"(" {
825 yyextra->roundCount++;
826 outputArray(yyscanner,yytext,yyleng);
827 }
828<RulesRound>")" {
829 yyextra->roundCount--;
830 outputArray(yyscanner,yytext,yyleng);
831 if (!yyextra->roundCount) BEGIN( yyextra->lastContext ) ;
832 }
833<RulesRound>{nl} {
834 outputArray(yyscanner,yytext,yyleng);
835 }
836<RulesRound>{B} {
837 outputArray(yyscanner,yytext,yyleng);
838 }
839<RulesRound>. {
840 outputArray(yyscanner,yytext,yyleng);
841 }
842<RulesPattern>{B} {
843 outputArray(yyscanner,yytext,yyleng);
844 BEGIN(CopyLine);
845 }
846<RulesPattern>. {
847 outputArray(yyscanner,yytext,yyleng);
848 }
849 /* end lex rule handling */
850<CopyLine,LexCopyLine>{ID} {
851 Define *def=nullptr;
852 if ((yyextra->includeStack.empty() || yyextra->curlyCount>0) &&
853 yyextra->macroExpansion &&
854 (def=isDefined(yyscanner,yytext)) &&
855 def->nargs==-1 &&
856 (!yyextra->expandOnlyPredef || def->isPredefined)
857 )
858 {
859 QCString result=def->isPredefined && !def->expandAsDefined ?
860 def->definition :
861 expandMacro(yyscanner,yytext);
862 outputString(yyscanner,result);
863 }
864 else
865 {
866 outputArray(yyscanner,yytext,yyleng);
867 }
868 }
869<CopyLine,LexCopyLine>"\\"\r?/\n { // strip line continuation characters
870 if (getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran) outputChar(yyscanner,*yytext);
871 }
872<CopyLine,LexCopyLine>\\. {
873 outputArray(yyscanner,yytext,(int)yyleng);
874 }
875<CopyLine,LexCopyLine>. {
876 outputChar(yyscanner,*yytext);
877 }
878<CopyLine,LexCopyLine>\n {
879 outputChar(yyscanner,'\n');
880 BEGIN(Start);
881 yyextra->yyLineNr++;
882 yyextra->yyColNr=1;
883 }
884<FindDefineArgs>"(" {
885 yyextra->defArgsStr+='(';
886 yyextra->roundCount++;
887 }
888<FindDefineArgs>")" {
889 yyextra->defArgsStr+=')';
890 yyextra->roundCount--;
891 if (yyextra->roundCount==0)
892 {
893 QCString result=expandMacro(yyscanner,yyextra->defArgsStr);
894 //printf("yyextra->defArgsStr='%s'->'%s'\n",qPrint(yyextra->defArgsStr),qPrint(result));
895 if (yyextra->findDefArgContext==CopyLine)
896 {
897 outputString(yyscanner,result);
898 BEGIN(yyextra->findDefArgContext);
899 }
900 else // yyextra->findDefArgContext==IncludeID
901 {
902 readIncludeFile(yyscanner,result);
903 yyextra->nospaces=FALSE;
904 BEGIN(Start);
905 }
906 }
907 }
908 /*
909<FindDefineArgs>")"{B}*"(" {
910 yyextra->defArgsStr+=yytext;
911 }
912 */
913<FindDefineArgs>{CHARLIT} {
914 yyextra->defArgsStr+=yytext;
915 }
916<FindDefineArgs>{CCS}[*!]? {
917 yyextra->defArgsStr+=yytext;
918 BEGIN(ArgCopyCComment);
919 }
920<FindDefineArgs>{CPPC}[/!].*\n/{B}*{CPPC}[/!] { // replace multi line C++ style comment by C style comment
921 if (Config_getBool(MULTILINE_CPP_IS_BRIEF) && !Config_getBool(QT_AUTOBRIEF))
922 {
923 if (yytext[3]=='<') // preserve < before @brief
924 {
925 yyextra->defArgsStr+=QCString("/**< @brief ")+&yytext[4];
926 }
927 else
928 {
929 yyextra->defArgsStr+=QCString("/** @brief ")+&yytext[3];
930 }
931 }
932 else
933 {
934 yyextra->defArgsStr+=QCString("/**")+&yytext[3];
935 }
936 BEGIN(ArgCopyCppComment);
937 }
938<FindDefineArgs>{CPPC}[/!].*\n { // replace C++ single line style comment by C style comment
939 if (Config_getBool(QT_AUTOBRIEF))
940 {
941 yyextra->defArgsStr+=QCString("/**")+&yytext[3]+" */";
942 }
943 else // add brief command explicitly when translating C++ to C comment style
944 {
945 if (yytext[3]=='<') // preserve < before @brief
946 {
947 yyextra->defArgsStr+=QCString("/**< @brief ")+&yytext[4]+" */";
948 }
949 else
950 {
951 yyextra->defArgsStr+=QCString("/** @brief ")+&yytext[3]+" */";
952 }
953 }
954 }
955<FindDefineArgs>{CPPC}.*\n { // replace C++ single line style comment by C style comment
956 yyextra->defArgsStr+=QCString("/*")+&yytext[2]+" */";
957 }
958<FindDefineArgs>\" {
959 yyextra->defArgsStr+=*yytext;
960 BEGIN(ReadString);
961 }
962<FindDefineArgs>' {
963 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Fortran) REJECT;
964 yyextra->defArgsStr+=*yytext;
965 BEGIN(ReadString);
966 }
967<FindDefineArgs>\n {
968 yyextra->defArgsStr+=' ';
969 yyextra->yyLineNr++;
970 outputChar(yyscanner,'\n');
971 }
972<FindDefineArgs>"@" {
973 yyextra->defArgsStr+="@@";
974 }
975<FindDefineArgs>. {
976 yyextra->defArgsStr+=*yytext;
977 }
978<ArgCopyCComment>[^*\n]+ {
979 yyextra->defArgsStr+=yytext;
980 }
981<ArgCopyCComment>{CCE} {
982 yyextra->defArgsStr+=yytext;
983 BEGIN(FindDefineArgs);
984 }
985<ArgCopyCComment>\n {
986 yyextra->defArgsStr+=yytext;
987 yyextra->yyLineNr++;
988 }
989<ArgCopyCComment>. {
990 yyextra->defArgsStr+=yytext;
991 }
992<ArgCopyCppComment>^{B}*
993<ArgCopyCppComment>{CPPC}[/!].*\n/{B}*{CPPC}[/!] { // replace multi line C++ style comment by C style comment
994 const char *startContent = &yytext[3];
995 if (startContent[0]=='<') startContent++;
996 yyextra->defArgsStr+=startContent;
997 }
998<ArgCopyCppComment>{CPPC}[/!].*\n { // replace C++ multie line style comment by C style comment
999 const char *startContent = &yytext[3];
1000 if (startContent[0]=='<') startContent++;
1001 yyextra->defArgsStr+=QCString(startContent)+" */";
1002 BEGIN(FindDefineArgs);
1003 }
1004<ArgCopyCppComment>. { // unexpected character
1005 unput(*yytext);
1006 yyextra->defArgsStr+=" */";
1007 BEGIN(FindDefineArgs);
1008 }
1009<ReadString>"\"" {
1010 yyextra->defArgsStr+=*yytext;
1011 BEGIN(FindDefineArgs);
1012 }
1013<ReadString>"'" {
1014 if (getLanguageFromFileName(yyextra->fileName)!=SrcLangExt::Fortran) REJECT;
1015 yyextra->defArgsStr+=*yytext;
1016 BEGIN(FindDefineArgs);
1017 }
1018
1019<ReadString>{CPPC}|{CCS} {
1020 yyextra->defArgsStr+=yytext;
1021 }
1022<ReadString>\\/\r?\n { // line continuation
1023 }
1024<ReadString>\\. {
1025 yyextra->defArgsStr+=yytext;
1026 }
1027<ReadString>. {
1028 yyextra->defArgsStr+=*yytext;
1029 }
1030<Command>("include"|"import"){B}+/{ID} {
1031 yyextra->isImported = yytext[1]=='m';
1032 if (yyextra->macroExpansion)
1033 BEGIN(IncludeID);
1034 }
1035<Command>("include"|"import"){B}*[<"] {
1036 yyextra->isImported = yytext[1]=='m';
1037 char c[2];
1038 c[0]=yytext[yyleng-1];c[1]='\0';
1039 yyextra->incName=c;
1040 BEGIN(Include);
1041 }
1042<Command>("cmake")?"define"{B}+ {
1043 yyextra->potentialDefine += substitute(yytext,"cmake"," ");
1044 //printf("!!!DefName\n");
1045 yyextra->yyColNr+=(int)yyleng;
1046 BEGIN(DefName);
1047 }
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:571
1048<Command>"cmakedefine01"{B}+ {
1049 yyextra->potentialDefine += substitute(yytext,"cmakedefine01"," define ");
1050 //printf("!!!DefName\n");
1051 yyextra->yyColNr+=(int)yyleng;
1052 BEGIN(CmakeDefName01);
1053 }
1054<Command>"ifdef"/{B}*"(" {
1055 incrLevel(yyscanner);
1056 yyextra->guardExpr.clear();
1057 BEGIN(DefinedExpr2);
1058 }
1059<Command>"ifdef"/{B}+ {
1060 //printf("Pre.l: ifdef\n");
1061 incrLevel(yyscanner);
1062 yyextra->guardExpr.clear();
1063 BEGIN(DefinedExpr1);
1064 }
1065<Command>"ifndef"/{B}*"(" {
1066 incrLevel(yyscanner);
1067 yyextra->guardExpr="! ";
1068 BEGIN(DefinedExpr2);
1069 }
1070<Command>"ifndef"/{B}+ {
1071 incrLevel(yyscanner);
1072 yyextra->guardExpr="! ";
1073 BEGIN(DefinedExpr1);
1074 }
1075<Command>"if"/[ \t(!] {
1076 incrLevel(yyscanner);
1077 yyextra->guardExpr.clear();
1078 BEGIN(Guard);
1079 }
1080<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1081 if (!otherCaseDone(yyscanner))
1082 {
1083 yyextra->guardExpr.clear();
1084 BEGIN(Guard);
1085 }
1086 else
1087 {
1088 yyextra->ifcount=0;
1089 BEGIN(SkipCPPBlock);
1090 }
1091 }
1092<Command>"else"/[^a-z_A-Z0-9\x80-\xFF] {
1093 if (otherCaseDone(yyscanner))
1094 {
1095 yyextra->ifcount=0;
1096 BEGIN(SkipCPPBlock);
1097 }
1098 else
1099 {
1100 setCaseDone(yyscanner,TRUE);
1101 }
1102 }
#define TRUE
Definition qcstring.h:37
1103<Command>"undef"{B}+ {
1104 BEGIN(UndefName);
1105 }
1106<Command>("elif"|"else"{B}*"if")/[ \t(!] {
1107 if (!otherCaseDone(yyscanner))
1108 {
1109 yyextra->guardExpr.clear();
1110 BEGIN(Guard);
1111 }
1112 }
1113<Command>"endif"/[^a-z_A-Z0-9\x80-\xFF] {
1114 //printf("Pre.l: #endif\n");
1115 decrLevel(yyscanner);
1116 }
1117<Command,IgnoreLine>\n {
1118 outputChar(yyscanner,'\n');
1119 BEGIN(Start);
1120 yyextra->yyLineNr++;
1121 }
1122<Command>"pragma"{B}+"once" {
1123 yyextra->expectGuard = FALSE;
1124 if (yyextra->pragmaSet.find(yyextra->fileName.str())!=yyextra->pragmaSet.end())
1125 {
1126 outputChar(yyscanner,'\n');
1127 BEGIN(PragmaOnce);
1128 }
1129 else
1130 {
1131 yyextra->pragmaSet.insert(yyextra->fileName.data());
1132 }
1133 }
1134<PragmaOnce>. {}
1135<PragmaOnce>\n {}
1136<PragmaOnce><<EOF>> {
1137 yyextra->expectGuard = FALSE;
1138 BEGIN(Start);
1139 }
1140<Command>{ID} { // unknown directive
1141 BEGIN(IgnoreLine);
1142 }
1143<IgnoreLine>\\‍[\r]?\n {
1144 outputChar(yyscanner,'\n');
1145 yyextra->yyLineNr++;
1146 }
1147<IgnoreLine>.
1148<Command>. { yyextra->potentialDefine += yytext[0]=='\t' ? '\t' : ' ';
1149 yyextra->yyColNr+=(int)yyleng;
1150 }
1151<UndefName>{ID} {
1152 Define *def;
1153 if ((def=isDefined(yyscanner,yytext))
1154 /*&& !def->isPredefined*/
1155 && !def->nonRecursive
1156 )
1157 {
1158 //printf("undefining %s\n",yytext);
1159 def->undef=TRUE;
1160 }
1161 BEGIN(Start);
1162 }
bool nonRecursive
Definition define.h:44
bool undef
Definition define.h:41
1163<Guard>\\‍[\r]?\n {
1164 outputChar(yyscanner,'\n');
1165 yyextra->guardExpr+=' ';
1166 yyextra->yyLineNr++;
1167 }
1168<Guard>"defined"/{B}*"(" {
1169 BEGIN(DefinedExpr2);
1170 }
1171<Guard>"defined"/{B}+ {
1172 BEGIN(DefinedExpr1);
1173 }
1174<Guard>"true"/{B}|{B}*[\r]?\n { yyextra->guardExpr+="1L"; }
1175<Guard>"false"/{B}|{B}*[\r]?\n { yyextra->guardExpr+="0L"; }
1176<Guard>"not"/{B} { yyextra->guardExpr+='!'; }
1177<Guard>"not_eq"/{B} { yyextra->guardExpr+="!="; }
1178<Guard>"and"/{B} { yyextra->guardExpr+="&&"; }
1179<Guard>"or"/{B} { yyextra->guardExpr+="||"; }
1180<Guard>"bitand"/{B} { yyextra->guardExpr+="&"; }
1181<Guard>"bitor"/{B} { yyextra->guardExpr+="|"; }
1182<Guard>"xor"/{B} { yyextra->guardExpr+="^"; }
1183<Guard>"compl"/{B} { yyextra->guardExpr+="~"; }
1184<Guard>{ID} { yyextra->guardExpr+=yytext; }
1185<Guard>"@" { yyextra->guardExpr+="@@"; }
1186<Guard>. { yyextra->guardExpr+=*yytext; }
1187<Guard>\n {
1188 unput(*yytext);
1189 //printf("Guard: '%s'\n",
1190 // qPrint(yyextra->guardExpr));
1191 bool guard=computeExpression(yyscanner,yyextra->guardExpr);
1192 setCaseDone(yyscanner,guard);
1193 if (guard)
1194 {
1195 BEGIN(Start);
1196 }
1197 else
1198 {
1199 yyextra->ifcount=0;
1200 BEGIN(SkipCPPBlock);
1201 }
1202 }
1203<DefinedExpr1,DefinedExpr2>\\\n { yyextra->yyLineNr++; outputChar(yyscanner,'\n'); }
1204<DefinedExpr1>{ID} {
1205 if (isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1206 yyextra->guardExpr+=" 1L ";
1207 else
1208 yyextra->guardExpr+=" 0L ";
1209 yyextra->lastGuardName=yytext;
1210 BEGIN(Guard);
1211 }
1212<DefinedExpr2>{ID} {
1213 if (isDefined(yyscanner,yytext) || yyextra->guardName==yytext)
1214 yyextra->guardExpr+=" 1L ";
1215 else
1216 yyextra->guardExpr+=" 0L ";
1217 yyextra->lastGuardName=yytext;
1218 }
1219<DefinedExpr1,DefinedExpr2>\n { // should not happen, handle anyway
1220 yyextra->yyLineNr++;
1221 yyextra->ifcount=0;
1222 BEGIN(SkipCPPBlock);
1223 }
1224<DefinedExpr2>")" {
1225 BEGIN(Guard);
1226 }
1227<DefinedExpr1,DefinedExpr2>.
1228<SkipCPPBlock>^{B}*"#" { BEGIN(SkipCommand); }
1229<SkipCPPBlock>^{Bopt}/[^#] { BEGIN(SkipLine); }
1230<SkipCPPBlock>\n { yyextra->yyLineNr++; outputChar(yyscanner,'\n'); }
1231<SkipCPPBlock>.
1232<SkipCommand>"if"(("n")?("def"))?/[ \t(!] {
1233 incrLevel(yyscanner);
1234 yyextra->ifcount++;
1235 //printf("#if... depth=%d\n",yyextra->ifcount);
1236 }
1237<SkipCommand>"else" {
1238 //printf("Else! yyextra->ifcount=%d otherCaseDone=%d\n",yyextra->ifcount,otherCaseDone());
1239 if (yyextra->ifcount==0 && !otherCaseDone(yyscanner))
1240 {
1241 setCaseDone(yyscanner,TRUE);
1242 //outputChar(yyscanner,'\n');
1243 BEGIN(Start);
1244 }
1245 }
1246<SkipCommand>("elif"|"else"{B}*"if")/[ \t(!] {
1247 if (yyextra->ifcount==0)
1248 {
1249 if (!otherCaseDone(yyscanner))
1250 {
1251 yyextra->guardExpr.clear();
1252 yyextra->lastGuardName.clear();
1253 BEGIN(Guard);
1254 }
1255 else
1256 {
1257 BEGIN(SkipCPPBlock);
1258 }
1259 }
1260 }
1261<SkipCommand>"endif" {
1262 yyextra->expectGuard = FALSE;
1263 decrLevel(yyscanner);
1264 if (--yyextra->ifcount<0)
1265 {
1266 //outputChar(yyscanner,'\n');
1267 BEGIN(Start);
1268 }
1269 }
1270<SkipCommand>\n {
1271 outputChar(yyscanner,'\n');
1272 yyextra->yyLineNr++;
1273 BEGIN(SkipCPPBlock);
1274 }
1275<SkipCommand>{ID} { // unknown directive
1276 BEGIN(SkipLine);
1277 }
1278<SkipCommand>.
1279<SkipLine>[^'"/\n]+
1280<SkipLine>{CHARLIT} { }
1281<SkipLine>\" {
1282 BEGIN(SkipString);
1283 }
1284<SkipLine>.
1285<SkipString>{CPPC}/[^\n]* {
1286 }
1287<SkipLine,SkipCommand,SkipCPPBlock>{CPPC}[^\n]* {
1288 yyextra->lastCPPContext=YY_START;
1289 BEGIN(RemoveCPPComment);
1290 }
1291<SkipString>{CCS}/[^\n]* {
1292 }
1293<SkipLine,SkipCommand,SkipCPPBlock>{CCS}/[^\n]* {
1294 yyextra->lastCContext=YY_START;
1295 BEGIN(RemoveCComment);
1296 }
1297<SkipLine>\n {
1298 outputChar(yyscanner,'\n');
1299 yyextra->yyLineNr++;
1300 BEGIN(SkipCPPBlock);
1301 }
1302<SkipString>[^"\\\n]+ { }
1303<SkipString>\\. { }
1304<SkipString>\" {
1305 BEGIN(SkipLine);
1306 }
1307<SkipString>. { }
1308<IncludeID>{ID}{Bopt}/"(" {
1309 yyextra->nospaces=TRUE;
1310 yyextra->roundCount=0;
1311 yyextra->defArgsStr=yytext;
1312 yyextra->findDefArgContext = IncludeID;
1313 BEGIN(FindDefineArgs);
1314 }
1315<IncludeID>{ID} {
1316 yyextra->nospaces=TRUE;
1317 readIncludeFile(yyscanner,expandMacro(yyscanner,yytext));
1318 BEGIN(Start);
1319 }
1320<Include>[^\">\n]+[\">] {
1321 yyextra->incName+=yytext;
1322 if (yyextra->isImported)
1323 {
1324 BEGIN(EndImport);
1325 }
1326 else
1327 {
1328 readIncludeFile(yyscanner,yyextra->incName);
1329 BEGIN(Start);
1330 }
1331 }
1332<EndImport>{ENDIMPORTopt}/\n {
1333 readIncludeFile(yyscanner,yyextra->incName);
1334 BEGIN(Start);
1335 }
1336<EndImport>\\‍[\r]?"\n" {
1337 outputChar(yyscanner,'\n');
1338 yyextra->yyLineNr++;
1339 }
1340<EndImport>. {
1341 }
1342<DefName>{ID}/("\\\n")*"(" { // define with argument
1343 //printf("Define() '%s'\n",yytext);
1344 yyextra->argMap.clear();
1345 yyextra->defArgs = 0;
1346 yyextra->defArgsStr.clear();
1347 yyextra->defText.clear();
1348 yyextra->defLitText.clear();
1349 yyextra->defName = yytext;
1350 yyextra->defVarArgs = FALSE;
1351 yyextra->defExtraSpacing.clear();
1352 yyextra->defContinue = false;
1353 BEGIN(DefineArg);
1354 }
1355<DefName>{ID}{B}+"1"/[ \r\t\n] { // special case: define with 1 -> can be "guard"
1356 //printf("Define '%s'\n",yytext);
1357 yyextra->argMap.clear();
1358 yyextra->defArgs = -1;
1359 yyextra->defArgsStr.clear();
1360 yyextra->defName = QCString(yytext).left(yyleng-1).stripWhiteSpace();
1361 yyextra->defVarArgs = FALSE;
1362 //printf("Guard check: %s!=%s || %d\n",
1363 // qPrint(yyextra->defName),qPrint(yyextra->lastGuardName),yyextra->expectGuard);
1364 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1365 { // define may appear in the output
1366 QCString def = yyextra->potentialDefine +
1367 yyextra->defName ;
1368 outputString(yyscanner,def);
1369 outputSpaces(yyscanner,yytext+yyextra->defName.length());
1370 yyextra->quoteArg=FALSE;
1371 yyextra->insideComment=FALSE;
1372 yyextra->lastGuardName.clear();
1373 yyextra->defText="1";
1374 yyextra->defLitText="1";
1375 BEGIN(DefineText);
1376 }
1377 else // define is a guard => hide
1378 {
1379 //printf("Found a guard %s\n",yytext);
1380 yyextra->defText.clear();
1381 yyextra->defLitText.clear();
1382 BEGIN(Start);
1383 }
1384 yyextra->expectGuard=FALSE;
1385 }
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
QCString left(size_t len) const
Definition qcstring.h:229
1386<DefName,CmakeDefName01>{ID}/{B}*"\n" { // empty define
1387 yyextra->argMap.clear();
1388 yyextra->defArgs = -1;
1389 yyextra->defName = yytext;
1390 yyextra->defArgsStr.clear();
1391 yyextra->defText.clear();
1392 yyextra->defLitText.clear();
1393 yyextra->defVarArgs = FALSE;
1394 //printf("Guard check: %s!=%s || %d\n",
1395 // qPrint(yyextra->defName),qPrint(yyextra->lastGuardName),yyextra->expectGuard);
1396 if (yyextra->curlyCount>0 || yyextra->defName!=yyextra->lastGuardName || !yyextra->expectGuard)
1397 { // define may appear in the output
1398 QCString def = yyextra->potentialDefine + yyextra->defName;
1399 outputString(yyscanner,def);
1400 yyextra->quoteArg=FALSE;
1401 yyextra->insideComment=FALSE;
1402 if (YY_START == CmakeDefName01) yyextra->defText = "0";
1403 else if (yyextra->insideCS) yyextra->defText="1"; // for C#, use "1" as define text
1404 BEGIN(DefineText);
1405 }
1406 else // define is a guard => hide
1407 {
1408 //printf("Found a guard %s\n",yytext);
1409 yyextra->guardName = yytext;
1410 yyextra->lastGuardName.clear();
1411 BEGIN(Start);
1412 }
1413 yyextra->expectGuard=FALSE;
1414 }
1415<DefName>{ID}/{B}* { // define with content
1416 //printf("Define '%s'\n",yytext);
1417 yyextra->argMap.clear();
1418 yyextra->defArgs = -1;
1419 yyextra->defArgsStr.clear();
1420 yyextra->defText.clear();
1421 yyextra->defLitText.clear();
1422 yyextra->defName = yytext;
1423 yyextra->defVarArgs = FALSE;
1424 QCString def = yyextra->potentialDefine +
1425 yyextra->defName +
1426 yyextra->defArgsStr ;
1427 outputString(yyscanner,def);
1428 yyextra->quoteArg=FALSE;
1429 yyextra->insideComment=FALSE;
1430 BEGIN(DefineText);
1431 }
1432<DefineArg>"\\\n" {
1433 yyextra->defExtraSpacing+="\n";
1434 yyextra->defContinue = true;
1435 yyextra->yyLineNr++;
1436 }
1437<DefineArg>{B}* { yyextra->defExtraSpacing+=yytext; }
1438<DefineArg>","{B}* { yyextra->defArgsStr+=yytext; }
1439<DefineArg>"("{B}* { yyextra->defArgsStr+=yytext; }
1440<DefineArg>{B}*")"{B}* {
1441 extraSpacing(yyscanner);
1442 yyextra->defArgsStr+=yytext;
1443 QCString def = yyextra->potentialDefine +
1444 yyextra->defName +
1445 yyextra->defArgsStr +
1446 yyextra->defExtraSpacing ;
1447 outputString(yyscanner,def);
1448 yyextra->quoteArg=FALSE;
1449 yyextra->insideComment=FALSE;
1450 BEGIN(DefineText);
1451 }
1452<DefineArg>"..." { // Variadic macro
1453 yyextra->defVarArgs = TRUE;
1454 yyextra->defArgsStr+=yytext;
1455 yyextra->argMap.emplace(std::string("__VA_ARGS__"),yyextra->defArgs);
1456 yyextra->defArgs++;
1457 }
1458<DefineArg>{ID}{B}*("..."?) {
1459 //printf("Define addArg(%s)\n",yytext);
1460 QCString argName=yytext;
1461 yyextra->defVarArgs = yytext[yyleng-1]=='.';
1462 if (yyextra->defVarArgs) // strip ellipsis
1463 {
1464 argName=argName.left(argName.length()-3);
1465 }
1466 argName = argName.stripWhiteSpace();
1467 yyextra->defArgsStr+=yytext;
1468 yyextra->argMap.emplace(toStdString(argName),yyextra->defArgs);
1469 yyextra->defArgs++;
1470 extraSpacing(yyscanner);
1471 }
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
std::string toStdString(const QCString &s)
Definition qcstring.h:702
1472 /*
1473<DefineText>"/ **"|"/ *!" {
1474 yyextra->defText+=yytext;
1475 yyextra->defLitText+=yytext;
1476 yyextra->insideComment=TRUE;
1477 }
1478<DefineText>"* /" {
1479 yyextra->defText+=yytext;
1480 yyextra->defLitText+=yytext;
1481 yyextra->insideComment=FALSE;
1482 }
1483 */
1484<DefineText>{CCS}[!*]? {
1485 yyextra->defText+=yytext;
1486 yyextra->defLitText+=yytext;
1487 yyextra->lastCContext=YY_START;
1488 yyextra->commentCount=1;
1489 BEGIN(CopyCComment);
1490 }
1491<DefineText>{CPPC}[!/]? {
1492 outputArray(yyscanner,yytext,yyleng);
1493 yyextra->lastCPPContext=YY_START;
1494 yyextra->defLitText+=' ';
1495 BEGIN(SkipCPPComment);
1496 }
1497<SkipCComment>[/]?{CCE} {
1498 if (yytext[0]=='/') outputChar(yyscanner,'/');
1499 outputChar(yyscanner,'*');outputChar(yyscanner,'/');
1500 if (--yyextra->commentCount<=0)
1501 {
1502 if (yyextra->lastCContext==Start)
1503 // small hack to make sure that ^... rule will
1504 // match when going to Start... Example: "/*...*/ some stuff..."
1505 {
1506 YY_CURRENT_BUFFER->yy_at_bol=1;
1507 }
1508 BEGIN(yyextra->lastCContext);
1509 }
1510 }
1511<SkipCComment>{CPPC}("/")* {
1512 outputArray(yyscanner,yytext,yyleng);
1513 }
1514<SkipCComment>{CCS} {
1515 outputChar(yyscanner,'/');outputChar(yyscanner,'*');
1516 //yyextra->commentCount++;
1517 }
1518<SkipCond>{CMD}{CMD} { }
1519<SkipCond>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1520 bool markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
1521 if (!markdownSupport || !yyextra->isSpecialComment)
1522 {
1523 REJECT;
1524 }
1525 else
1526 {
1527 yyextra->fenceChar='~';
1528 yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
1529 BEGIN(SkipCondVerbatim);
1530 }
1531 }
1532<SkipCond>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1533 bool markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
1534 if (!markdownSupport || !yyextra->isSpecialComment)
1535 {
1536 REJECT;
1537 }
1538 else
1539 {
1540 yyextra->fenceChar='`';
1541 yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
1542 BEGIN(SkipCondVerbatim);
1543 }
1544 }
1545<SkipCComment>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1546 bool markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
1547 if (!markdownSupport || !yyextra->isSpecialComment)
1548 {
1549 REJECT;
1550 }
1551 else
1552 {
1553 outputArray(yyscanner,yytext,yyleng);
1554 yyextra->fenceChar='~';
1555 yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
1556 BEGIN(SkipVerbatim);
1557 }
1558 }
1559<SkipCComment>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1560 bool markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
1561 if (!markdownSupport || !yyextra->isSpecialComment)
1562 {
1563 REJECT;
1564 }
1565 else
1566 {
1567 outputArray(yyscanner,yytext,yyleng);
1568 yyextra->fenceChar='`';
1569 yyextra->fenceSize=(int)getFenceSize(yytext,yyleng);
1570 BEGIN(SkipVerbatim);
1571 }
1572 }
1573<SkipCComment>{CMD}{VERBATIM_LINE} |
1574<SkipCComment>{CMD}{LITERAL_BLOCK} { // escaped command
1575 outputArray(yyscanner,yytext,yyleng);
1576 yyextra->yyLineNr+=QCString(yytext).contains('\n');
1577 }
1578<SkipCComment>{VERBATIM_LINE}.*/\n { // normal command
1579 outputArray(yyscanner,yytext,yyleng);
1580 }
1581<SkipCComment>{LITERAL_BLOCK} { // normal block command
1582 outputArray(yyscanner,yytext,yyleng);
1583 yyextra->yyLineNr+=QCString(yytext).contains('\n');
1584 determineBlockName(yyscanner);
1585 BEGIN(SkipVerbatim);
1586 }
1587<SkipCond>{CMD}{CMD}"cond"[ \t]+ {}// escaped cond command
1588<SkipCond>{CMD}"cond"/\n |
1589<SkipCond>{CMD}"cond"[ \t]+ { // cond command in a skipped cond section, this section has to be skipped as well
1590 // but has to be recorded to match the endcond command
1591 startCondSection(yyscanner," ");
1592 }
1593<SkipCComment>"{"[ \t]*"@code"/[ \t\n] {
1594 outputArray(yyscanner,"@iliteral{code}",15);
1595 yyextra->javaBlock=1;
1596 BEGIN(JavaDocVerbatimCode);
1597 }
1598<SkipCComment>"{"[ \t]*"@literal"/[ \t\n] {
1599 outputArray(yyscanner,"@iliteral",9);
1600 yyextra->javaBlock=1;
1601 BEGIN(JavaDocVerbatimCode);
1602 }
1603<SkipCComment,SkipCPPComment>{CMD}{CMD}"cond"[ \t\n]+ { // escaped cond command
1604 outputArray(yyscanner,yytext,yyleng);
1605 }
1606<SkipCPPComment>{CMD}"cond"[ \t]+ { // conditional section
1607 yyextra->ccomment=TRUE;
1608 yyextra->condCtx=YY_START;
1609 BEGIN(CondLineCpp);
1610 }
1611<SkipCComment>{CMD}"cond"[ \t]+ { // conditional section
1612 yyextra->ccomment=FALSE;
1613 yyextra->condCtx=YY_START;
1614 BEGIN(CondLineC);
1615 }
1616<CondLineC,CondLineCpp>[!()&| \ta-z_A-Z0-9\x80-\xFF.\-]+ {
1617 startCondSection(yyscanner,yytext);
1618 if (yyextra->skip)
1619 {
1620 if (YY_START==CondLineC)
1621 {
1622 // end C comment
1623 outputArray(yyscanner,"*/",2);
1624 yyextra->ccomment=TRUE;
1625 }
1626 else
1627 {
1628 yyextra->ccomment=FALSE;
1629 }
1630 BEGIN(SkipCond);
1631 }
1632 else
1633 {
1634 BEGIN(yyextra->condCtx);
1635 }
1636 }
1637<CondLineC,CondLineCpp>. { // non-guard character
1638 unput(*yytext);
1639 startCondSection(yyscanner," ");
1640 if (yyextra->skip)
1641 {
1642 if (YY_START==CondLineC)
1643 {
1644 // end C comment
1645 outputArray(yyscanner,"*/",2);
1646 yyextra->ccomment=TRUE;
1647 }
1648 else
1649 {
1650 yyextra->ccomment=FALSE;
1651 }
1652 BEGIN(SkipCond);
1653 }
1654 else
1655 {
1656 BEGIN(yyextra->condCtx);
1657 }
1658 }
1659<SkipCComment,SkipCPPComment>{CMD}"cond"{WSopt}/\n { // no guard
1660 if (YY_START==SkipCComment)
1661 {
1662 yyextra->ccomment=TRUE;
1663 // end C comment
1664 outputArray(yyscanner,"*/",2);
1665 }
1666 else
1667 {
1668 yyextra->ccomment=FALSE;
1669 }
1670 yyextra->condCtx=YY_START;
1671 startCondSection(yyscanner," ");
1672 BEGIN(SkipCond);
1673 }
1674<SkipCond>\n { yyextra->yyLineNr++; outputChar(yyscanner,'\n'); }
1675<SkipCond>{VERBATIM_LINE}.*/\n { }
1676<SkipCond>{LITERAL_BLOCK} {
1677 auto numNLs = QCString(yytext).contains('\n');
1678 yyextra->yyLineNr+=numNLs;
1679 for (int i = 0; i < numNLs; i++) outputChar(yyscanner,'\n');
1680 determineBlockName(yyscanner);
1681 BEGIN(SkipCondVerbatim);
1682 }
1683
1684<SkipCond>. { }
1685<SkipCond>[^\/\!*\\@\n]+ { }
1686<SkipCond>{CPPC}[/!] { yyextra->ccomment=FALSE; }
1687<SkipCond>{CCS}[*!] { yyextra->ccomment=TRUE; }
1688<SkipCond,SkipCComment,SkipCPPComment>{CMD}{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1689 if (!yyextra->skip)
1690 {
1691 outputArray(yyscanner,yytext,yyleng);
1692 }
1693 }
1694<SkipCond>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1695 bool oldSkip = yyextra->skip;
1696 endCondSection(yyscanner);
1697 if (oldSkip && !yyextra->skip)
1698 {
1699 if (yyextra->ccomment)
1700 {
1701 outputArray(yyscanner,"/** ",4); // */
1702 }
1703 BEGIN(yyextra->condCtx);
1704 }
1705 }
1706<SkipCComment,SkipCPPComment>{CMD}"endcond"/[^a-z_A-Z0-9\x80-\xFF] {
1707 bool oldSkip = yyextra->skip;
1708 endCondSection(yyscanner);
1709 if (oldSkip && !yyextra->skip)
1710 {
1711 BEGIN(yyextra->condCtx);
1712 }
1713 }
1714<SkipCondVerbatim>{LITERAL_BLOCK_END} { /* end of verbatim block */
1715 if (yytext[1]=='f' && yyextra->blockName==&yytext[2])
1716 {
1717 BEGIN(SkipCond);
1718 }
1719 else if (&yytext[4]==yyextra->blockName)
1720 {
1721 BEGIN(SkipCond);
1722 }
1723 }
1724<SkipVerbatim>{LITERAL_BLOCK_END} { /* end of verbatim block */
1725 outputArray(yyscanner,yytext,yyleng);
1726 if (yytext[1]=='f' && yyextra->blockName==&yytext[2])
1727 {
1728 BEGIN(SkipCComment);
1729 }
1730 else if (&yytext[4]==yyextra->blockName)
1731 {
1732 BEGIN(SkipCComment);
1733 }
1734 }
1735<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1736 if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='~')
1737 {
1738 BEGIN(SkipCond);
1739 }
1740 }
1741<SkipCondVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1742 if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='`')
1743 {
1744 BEGIN(SkipCond);
1745 }
1746 }
1747<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
1748 outputArray(yyscanner,yytext,yyleng);
1749 if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='~')
1750 {
1751 BEGIN(SkipCComment);
1752 }
1753 }
1754<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
1755 outputArray(yyscanner,yytext,yyleng);
1756 if (yyextra->fenceSize==getFenceSize(yytext,yyleng) && yyextra->fenceChar=='`')
1757 {
1758 BEGIN(SkipCComment);
1759 }
1760 }
1761<SkipCondVerbatim>{CCE}|{CCS} { }
1762<SkipVerbatim>{CCE}|{CCS} {
1763 outputArray(yyscanner,yytext,yyleng);
1764 }
1765<JavaDocVerbatimCode>"{" {
1766 if (yyextra->javaBlock==0)
1767 {
1768 REJECT;
1769 }
1770 else
1771 {
1772 yyextra->javaBlock++;
1773 outputArray(yyscanner,yytext,(int)yyleng);
1774 }
1775 }
1776<JavaDocVerbatimCode>"}" {
1777 if (yyextra->javaBlock==0)
1778 {
1779 REJECT;
1780 }
1781 else
1782 {
1783 yyextra->javaBlock--;
1784 if (yyextra->javaBlock==0)
1785 {
1786 outputArray(yyscanner," @endiliteral ",14);
1787 BEGIN(SkipCComment);
1788 }
1789 else
1790 {
1791 outputArray(yyscanner,yytext,(int)yyleng);
1792 }
1793 }
1794 }
1795<JavaDocVerbatimCode>\n { /* new line in verbatim block */
1796 outputArray(yyscanner,yytext,(int)yyleng);
1797 }
1798<JavaDocVerbatimCode>. { /* any other character */
1799 outputArray(yyscanner,yytext,(int)yyleng);
1800 }
1801<SkipCondVerbatim>[^{*\\@\x06~`\n\/]+ { }
1802<SkipCComment,SkipVerbatim>[^{*\\@\x06~`\n\/]+ {
1803 outputArray(yyscanner,yytext,yyleng);
1804 }
1805<SkipCComment,SkipVerbatim,SkipCondVerbatim>\n {
1806 yyextra->yyLineNr++;
1807 outputChar(yyscanner,'\n');
1808 }
1809<SkipCondVerbatim>. { }
1810<SkipCComment,SkipVerbatim>. {
1811 outputChar(yyscanner,*yytext);
1812 }
1813<CopyCComment>[^*a-z_A-Z\x80-\xFF\n]*[^*a-z_A-Z\x80-\xFF\\\n] {
1814 yyextra->defLitText+=yytext;
1815 yyextra->defText+=escapeAt(yytext);
1816 }
1817<CopyCComment>\\‍[\r]?\n {
1818 yyextra->defLitText+=yytext;
1819 yyextra->defText+=" ";
1820 yyextra->yyLineNr++;
1821 yyextra->yyMLines++;
1822 }
1823<CopyCComment>{CCE} {
1824 yyextra->defLitText+=yytext;
1825 yyextra->defText+=yytext;
1826 BEGIN(yyextra->lastCContext);
1827 }
1828<CopyCComment>\n {
1829 yyextra->yyLineNr++;
1830 yyextra->defLitText+=yytext;
1831 yyextra->defText+=' ';
1832 }
1833<RemoveCComment>{CCE}{B}*"#" { // see bug 594021 for a usecase for this rule
1834 if (yyextra->lastCContext==SkipCPPBlock)
1835 {
1836 BEGIN(SkipCommand);
1837 }
1838 else
1839 {
1840 REJECT;
1841 }
1842 }
1843<RemoveCComment>{CCE} { BEGIN(yyextra->lastCContext); }
1844<RemoveCComment>{CPPC}
1845<RemoveCComment>{CCS}
1846<RemoveCComment>[^*\x06\n]+
1847<RemoveCComment>\n { yyextra->yyLineNr++; outputChar(yyscanner,'\n'); }
1848<RemoveCComment>.
1849<SkipCPPComment>[^\n\/\\@]+ {
1850 outputArray(yyscanner,yytext,yyleng);
1851 }
1852<SkipCPPComment,RemoveCPPComment>\n {
1853 unput(*yytext);
1854 BEGIN(yyextra->lastCPPContext);
1855 }
1856<SkipCPPComment>{CCS} {
1857 outputChar(yyscanner,'/');outputChar(yyscanner,'*');
1858 }
1859<SkipCPPComment>{CPPC} {
1860 outputChar(yyscanner,'/');outputChar(yyscanner,'/');
1861 }
1862<SkipCPPComment>[^\x06\@\\\n]+ {
1863 outputArray(yyscanner,yytext,yyleng);
1864 }
1865<SkipCPPComment>. {
1866 outputChar(yyscanner,*yytext);
1867 }
1868<RemoveCPPComment>{CCS}
1869<RemoveCPPComment>{CPPC}
1870<RemoveCPPComment>[^\x06\n]+
1871<RemoveCPPComment>.
1872<DefineText>"__VA_OPT__("{B}*"##" {
1873 warn(yyextra->fileName,yyextra->yyLineNr,
1874 "'##' may not appear at the beginning of a __VA_OPT__()",
1875 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1876 yyextra->defText+="__VA_OPT__(";
1877 yyextra->defLitText+="__VA_OPT__(";
1878 }
#define warn(file, line, fmt,...)
Definition message.h:97
1879<DefineText>"#"/"__VA_OPT__" {
1880 yyextra->defText+=yytext;
1881 yyextra->defLitText+=yytext;
1882 }
1883<DefineText>"#"/{IDSTART} {
1884 outputChar(yyscanner,' ');
1885 yyextra->quoteArg=TRUE;
1886 yyextra->idStart=true;
1887 yyextra->defLitText+=yytext;
1888 }
1889<DefineText,CopyCComment>{ID} {
1890 yyextra->defLitText+=yytext;
1891 if (YY_START == DefineText) outputSpaces(yyscanner,yytext);
1892 if (yyextra->quoteArg)
1893 {
1894 yyextra->defText+="\"";
1895 }
1896 if (yyextra->defArgs>0)
1897 {
1898 auto it = yyextra->argMap.find(yytext);
1899 if (it!=yyextra->argMap.end())
1900 {
1901 int n = it->second;
1902 yyextra->defText+='@';
1903 yyextra->defText+=QCString().setNum(n);
1904 }
1905 else
1906 {
1907 if (yyextra->idStart)
1908 {
1909 warn(yyextra->fileName,yyextra->yyLineNr,
1910 "'#' is not followed by a macro parameter '{}': '{}'",
1911 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1912 }
1913 yyextra->defText+=yytext;
1914 }
1915 }
1916 else
1917 {
1918 yyextra->defText+=yytext;
1919 }
1920 if (yyextra->quoteArg)
1921 {
1922 yyextra->defText+="\"";
1923 }
1924 yyextra->quoteArg=FALSE;
1925 yyextra->idStart=false;
1926 }
QCString & setNum(short n)
Definition qcstring.h:459
1927<CopyCComment>. {
1928 yyextra->defLitText+=yytext;
1929 yyextra->defText+=yytext;
1930 }
1931<DefineText>\\‍[\r]?\n {
1932 yyextra->defLitText+=yytext;
1933 outputChar(yyscanner,'\\');
1934 outputChar(yyscanner,'\n');
1935 yyextra->defText += ' ';
1936 yyextra->yyLineNr++;
1937 yyextra->yyMLines++;
1938 }
1939<DefineText>\n {
1940 QCString comment=extractTrailingComment(yyextra->defLitText);
1941 yyextra->defText = yyextra->defText.stripWhiteSpace();
1942 if (yyextra->defText.startsWith("##"))
1943 {
1944 warn(yyextra->fileName,yyextra->yyLineNr,
1945 "'##' cannot occur at the beginning of a macro definition '{}': '{}'",
1946 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1947 }
1948 else if (yyextra->defText.endsWith("##"))
1949 {
1950 warn(yyextra->fileName,yyextra->yyLineNr,
1951 "'##' cannot occur at the end of a macro definition '{}': '{}'",
1952 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1953 }
1954 else if (yyextra->defText.endsWith("#"))
1955 {
1956 warn(yyextra->fileName,yyextra->yyLineNr,
1957 "expected formal parameter after # in macro definition '{}': '{}'",
1958 yyextra->defName,yyextra->defLitText.stripWhiteSpace());
1959 }
1960 if (!comment.isEmpty())
1961 {
1962 outputString(yyscanner,comment);
1963 yyextra->defLitText=yyextra->defLitText.left(yyextra->defLitText.length()-comment.length()-1);
1964 }
1965 outputChar(yyscanner,'\n');
1966 yyextra->defLitText+=yytext;
1967 Define *def=nullptr;
1968 //printf("Define name='%s' text='%s' litTexti='%s'\n",qPrint(yyextra->defName),qPrint(yyextra->defText),qPrint(yyextra->defLitText));
1969 if (yyextra->includeStack.empty() || yyextra->curlyCount>0)
1970 {
1971 addMacroDefinition(yyscanner);
1972 }
1973 def=isDefined(yyscanner,yyextra->defName);
1974 if (def==0) // new define
1975 {
1976 //printf("new define '%s'!\n",qPrint(yyextra->defName));
1977 addDefine(yyscanner);
1978 }
1979 else if (def /*&& macroIsAccessible(def)*/)
1980 // name already exists
1981 {
1982 //printf("existing define!\n");
1983 //printf("define found\n");
1984 if (def->undef) // undefined name
1985 {
1986 def->undef = FALSE;
1987 def->name = yyextra->defName;
1988 def->definition = yyextra->defText.stripWhiteSpace();
1989 def->nargs = yyextra->defArgs;
1990 def->fileName = yyextra->fileName;
1991 def->lineNr = yyextra->yyLineNr-yyextra->yyMLines;
1992 def->columnNr = yyextra->yyColNr;
1993 }
1994 else
1995 {
1996 if (def->fileName != yyextra->fileName && !yyextra->expandOnlyPredef) addDefine(yyscanner);
1997 //printf("error: define %s is defined more than once!\n",qPrint(yyextra->defName));
1998 }
1999 }
2000 yyextra->argMap.clear();
2001 yyextra->yyLineNr++;
2002 yyextra->yyColNr=1;
2003 yyextra->lastGuardName.clear();
2004 BEGIN(Start);
2005 }
int lineNr
Definition define.h:38
QCString fileName
Definition define.h:35
QCString name
Definition define.h:33
int columnNr
Definition define.h:39
const char * comment
2006<DefineText>{B}* { outputString(yyscanner,yytext);
2007 yyextra->defText += ' ';
2008 yyextra->defLitText+=yytext;
2009 }
2010<DefineText>{B}*"##"{B}* { outputString(yyscanner,substitute(yytext,"##"," "));
2011 yyextra->defText += "##";
2012 yyextra->defLitText+=yytext;
2013 }
2014<DefineText>"@" { outputString(yyscanner,substitute(yytext,"@@"," "));
2015 yyextra->defText += "@@";
2016 yyextra->defLitText+=yytext;
2017 }
2018<DefineText>\" {
2019 outputChar(yyscanner,' ');
2020 yyextra->defText += *yytext;
2021 yyextra->defLitText+=yytext;
2022 if (!yyextra->insideComment)
2023 {
2024 BEGIN(SkipDoubleQuote);
2025 }
2026 }
2027<DefineText>{NUMBER} {
2028 outputSpaces(yyscanner,yytext);
2029 yyextra->defText += yytext;
2030 yyextra->defLitText+=yytext;
2031 }
2032<DefineText>\' {
2033 outputChar(yyscanner,' ');
2034 yyextra->defText += *yytext;
2035 yyextra->defLitText+=yytext;
2036 if (!yyextra->insideComment)
2037 {
2038 BEGIN(SkipSingleQuote);
2039 }
2040 }
2041<SkipDoubleQuote>{CPPC}[/]? { outputSpaces(yyscanner,yytext);
2042 yyextra->defText += yytext;
2043 yyextra->defLitText+=yytext;
2044 }
2045<SkipDoubleQuote>{CCS}[*]? { outputSpaces(yyscanner,yytext);
2046 yyextra->defText += yytext;
2047 yyextra->defLitText+=yytext;
2048 }
2049<SkipDoubleQuote>\" {
2050 outputChar(yyscanner,' ');
2051 yyextra->defText += *yytext;
2052 yyextra->defLitText+=yytext;
2053 BEGIN(DefineText);
2054 }
2055<SkipSingleQuote,SkipDoubleQuote>\\. {
2056 outputSpaces(yyscanner,yytext);
2057 yyextra->defText += yytext;
2058 yyextra->defLitText+=yytext;
2059 }
2060<SkipSingleQuote>\' {
2061 outputChar(yyscanner,' ');
2062 yyextra->defText += *yytext;
2063 yyextra->defLitText+=yytext;
2064 BEGIN(DefineText);
2065 }
2066<SkipDoubleQuote,SkipSingleQuote>. { outputSpace(yyscanner,yytext[0]);
2067 yyextra->defText += *yytext;
2068 yyextra->defLitText += *yytext;
2069 }
2070<DefineText>. { outputSpace(yyscanner,yytext[0]);
2071 yyextra->defText += *yytext;
2072 yyextra->defLitText += *yytext;
2073 }
2074<<EOF>> {
2075 TRACE("End of include file");
2076 //printf("Include stack depth=%d\n",yyextra->includeStack.size());
2077 if (yyextra->includeStack.empty())
2078 {
2079 TRACE("Terminating scanner");
2080 yyterminate();
2081 }
2082 else
2083 {
2084 QCString toFileName = yyextra->fileName;
2085 const std::unique_ptr<FileState> &fs=yyextra->includeStack.back();
2086 //fileDefineCache->merge(yyextra->fileName,fs->fileName);
2087 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
2088 yy_switch_to_buffer( fs->bufState, yyscanner );
2089 yy_delete_buffer( oldBuf, yyscanner );
2090 yyextra->yyLineNr = fs->lineNr;
2091 //preYYin = fs->oldYYin;
2092 yyextra->inputBuf = fs->oldFileBuf;
2093 yyextra->inputBufPos = fs->oldFileBufPos;
2094 yyextra->curlyCount = fs->curlyCount;
2095 setFileName(yyscanner,fs->fileName);
2096 TRACE("switching to {}",yyextra->fileName);
2097
2098 // Deal with file changes due to
2099 // #include's within { .. } blocks
2100 QCString lineStr(15+yyextra->fileName.length(), QCString::ExplicitSize);
2101 lineStr.sprintf("# %d \"%s\" 2",yyextra->yyLineNr,qPrint(yyextra->fileName));
2102 outputString(yyscanner,lineStr);
2103
2104 yyextra->includeStack.pop_back();
2105
2106 {
2107 std::lock_guard<std::mutex> lock(g_globalDefineMutex);
2108 // to avoid deadlocks we allow multiple threads to process the same header file.
2109 // The first one to finish will store the results globally. After that the
2110 // next time the same file is encountered, the stored data is used and the file
2111 // is not processed again.
2112 if (!g_defineManager.alreadyProcessed(toFileName.str()))
2113 {
2114 // now that the file is completely processed, prevent it from processing it again
2115 g_defineManager.addInclude(yyextra->fileName.str(),toFileName.str());
2116 g_defineManager.store(toFileName.str(),yyextra->localDefines);
2117 }
2118 else
2119 {
2121 {
2122 Debug::print(Debug::Preprocessor,0,"#include {}: was already processed by another thread! not storing data...\n",toFileName);
2123 }
2124 }
2125 }
2126 // move the local macros definitions for in this file to the translation unit context
2127 for (const auto &kv : yyextra->localDefines)
2128 {
2129 auto pair = yyextra->contextDefines.insert(kv);
2130 if (!pair.second) // define already in context -> replace with local version
2131 {
2132 yyextra->contextDefines.erase(pair.first);
2133 yyextra->contextDefines.insert(kv);
2134 }
2135 }
2136 yyextra->localDefines.clear();
2137 }
2138 }
@ Preprocessor
Definition debug.h:30
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:76
const std::string & str() const
Definition qcstring.h:552
@ ExplicitSize
Definition qcstring.h:146
#define yyterminate()
const char * qPrint(const char *s)
Definition qcstring.h:687
#define TRACE(...)
Definition trace.h:77
2139<*>{CCS}/{CCE} |
2140<*>{CCS}[*!]? {
2141 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || YY_START==IDLquote || YY_START == PragmaOnce)
2142 {
2143 REJECT;
2144 }
2145 else
2146 {
2147 outputArray(yyscanner,yytext,yyleng);
2148 yyextra->lastCContext=YY_START;
2149 yyextra->commentCount=1;
2150 if (yyleng==3)
2151 {
2152 yyextra->isSpecialComment = true;
2153 yyextra->lastGuardName.clear(); // reset guard in case the #define is documented!
2154 }
2155 else
2156 {
2157 yyextra->isSpecialComment = false;
2158 }
2159 BEGIN(SkipCComment);
2160 }
2161 }
2162<*>{CPPC}[/!]? {
2163 if (YY_START==SkipVerbatim || YY_START == SkipCondVerbatim || YY_START==SkipCond || getLanguageFromFileName(yyextra->fileName)==SrcLangExt::Fortran || YY_START==IDLquote || YY_START == PragmaOnce)
2164 {
2165 REJECT;
2166 }
2167 else if (YY_START==RulesRoundDouble)
2168 {
2169 REJECT;
2170 }
2171 else
2172 {
2173 outputArray(yyscanner,yytext,yyleng);
2174 yyextra->lastCPPContext=YY_START;
2175 if (yyleng==3)
2176 {
2177 yyextra->isSpecialComment = true;
2178 yyextra->lastGuardName.clear(); // reset guard in case the #define is documented!
2179 }
2180 else
2181 {
2182 yyextra->isSpecialComment = false;
2183 }
2184 BEGIN(SkipCPPComment);
2185 }
2186 }
2187<*>\n {
2188 outputChar(yyscanner,'\n');
2189 yyextra->yyLineNr++;
2190 }
2191<*>. {
2192 yyextra->expectGuard = FALSE;
2193 outputChar(yyscanner,*yytext);
2194 }
2195
2196%%
2197
2198/////////////////////////////////////////////////////////////////////////////////////
2199
2200static int yyread(yyscan_t yyscanner,char *buf,int max_size)
2201{
2202 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2203 int bytesInBuf = static_cast<int>(state->inputBuf->size())-state->inputBufPos;
2204 int bytesToCopy = std::min(max_size,bytesInBuf);
2205 memcpy(buf,state->inputBuf->data()+state->inputBufPos,bytesToCopy);
2206 state->inputBufPos+=bytesToCopy;
2207 return bytesToCopy;
2208}
2209
2210static yy_size_t getFenceSize(char *txt, yy_size_t leng)
2211{
2212 yy_size_t fenceSize = 0;
2213 for (size_t i = 0; i < leng; i++)
2214 {
2215 if (txt[i] != ' ' && txt[i] != '*' && txt[i] != '\t') break;
2216 fenceSize++;
2217 }
2218 return leng-fenceSize;
2219}
2220
2221static void setFileName(yyscan_t yyscanner,const QCString &name)
2222{
2223 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2224 bool ambig = false;
2225 FileInfo fi(name.str());
2226 state->fileName=fi.absFilePath();
2227 state->yyFileDef=findFileDef(Doxygen::inputNameLinkedMap,state->fileName,ambig);
2228 if (state->yyFileDef==nullptr) // if this is not an input file check if it is an include file
2229 {
2230 state->yyFileDef=findFileDef(Doxygen::includeNameLinkedMap,state->fileName,ambig);
2231 }
2232 //printf("setFileName(%s) state->fileName=%s state->yyFileDef=%p\n",
2233 // name,qPrint(state->fileName),state->yyFileDef);
2234 if (state->yyFileDef && state->yyFileDef->isReference()) state->yyFileDef=nullptr;
2235 state->insideIDL = getLanguageFromFileName(state->fileName)==SrcLangExt::IDL;
2236 state->insideCS = getLanguageFromFileName(state->fileName)==SrcLangExt::CSharp;
2237 state->insideFtn = getLanguageFromFileName(state->fileName)==SrcLangExt::Fortran;
2238 EntryType section = guessSection(state->fileName);
2239 state->isSource = section.isHeader() || section.isSource();
2240}
2241
2242static void incrLevel(yyscan_t yyscanner)
2243{
2244 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2245 state->levelGuard.push(false);
2246 //printf("%s line %d: incrLevel %d\n",qPrint(yyextra->fileName),yyextra->yyLineNr,yyextra->levelGuard.size());
2247}
2248
2249static void decrLevel(yyscan_t yyscanner)
2250{
2251 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2252 //printf("%s line %d: decrLevel %d\n",qPrint(state->fileName),state->yyLineNr,state->levelGuard.size());
2253 if (!state->levelGuard.empty())
2254 {
2255 state->levelGuard.pop();
2256 }
2257 else
2258 {
2259 warn(state->fileName,state->yyLineNr,"More #endif's than #if's found.");
2260 }
2261}
2262
2263static bool otherCaseDone(yyscan_t yyscanner)
2264{
2265 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2266 if (state->levelGuard.empty())
2267 {
2268 warn(state->fileName,state->yyLineNr,"Found an #else without a preceding #if.");
2269 return TRUE;
2270 }
2271 else
2272 {
2273 return state->levelGuard.top();
2274 }
2275}
2276
2277static void setCaseDone(yyscan_t yyscanner,bool value)
2278{
2279 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2280 state->levelGuard.top()=value;
2281}
2282
2283
2284static std::unique_ptr<FileState> checkAndOpenFile(yyscan_t yyscanner,const QCString &fileName,bool &alreadyProcessed)
2285{
2286 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2287 alreadyProcessed = FALSE;
2288 std::unique_ptr<FileState> fs;
2289 //printf("checkAndOpenFile(%s)\n",qPrint(fileName));
2290 FileInfo fi(fileName.str());
2291 if (fi.exists() && fi.isFile())
2292 {
2293 const StringVector &exclPatterns = Config_getList(EXCLUDE_PATTERNS);
2294 if (patternMatch(fi,exclPatterns)) return nullptr;
2295
2296 QCString absName = fi.absFilePath();
2297
2298 // global guard
2299 if (state->curlyCount==0) // not #include inside { ... }
2300 {
2301 std::lock_guard<std::mutex> lock(g_globalDefineMutex);
2302 if (g_defineManager.alreadyProcessed(absName.str()))
2303 {
2304 alreadyProcessed = TRUE;
2305 //printf(" already included 1\n");
2306 return 0; // already done
2307 }
2308 }
2309 // check include stack for absName
2310
2311 alreadyProcessed = std::any_of(
2312 state->includeStack.begin(),
2313 state->includeStack.end(),
2314 [absName](const std::unique_ptr<FileState> &lfs)
2315 { return lfs->fileName==absName; }
2316 );
2317
2318 if (alreadyProcessed)
2319 {
2320 //printf(" already included 2\n");
2321 return nullptr;
2322 }
2323 //printf("#include %s\n",qPrint(absName));
2324
2325 fs = std::make_unique<FileState>();
2326 if (!readInputFile(absName,fs->fileBuf))
2327 { // error
2328 //printf(" error reading\n");
2329 fs.reset();
2330 }
2331 else
2332 {
2333 addTerminalCharIfMissing(fs->fileBuf,'\n');
2334 fs->oldFileBuf = state->inputBuf;
2335 fs->oldFileBufPos = state->inputBufPos;
2336 }
2337 }
2338 return fs;
2339}
2340
2341static std::unique_ptr<FileState> findFile(yyscan_t yyscanner, const QCString &fileName,bool localInclude,bool &alreadyProcessed)
2342{
2343 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
2344 //printf("** findFile(%s,%d) state->fileName=%s\n",qPrint(fileName),localInclude,qPrint(state->fileName));
2345 if (Portable::isAbsolutePath(fileName))
2346 {
2347 auto fs = checkAndOpenFile(yyscanner,fileName,alreadyProcessed);
2348 if (fs)
2349 {
2350 setFileName(yyscanner,fileName);
2351 state->yyLineNr=1;
2352 return fs;
2353 }
2354 else if (alreadyProcessed)
2355 {
2356 return nullptr;
2357 }
2358 }
2359 if (localInclude && !state->fileName.isEmpty())
2360 {
2361 FileInfo fi(state->fileName.str());
2362 if (fi.exists())
2363 {
2364 QCString absName = QCString(fi.dirPath(TRUE))+"/"+fileName;
2365 auto fs = checkAndOpenFile(yyscanner,absName,alreadyProcessed);
2366 if (fs)
2367 {
2368 setFileName(yyscanner,absName);
2369 state->yyLineNr=1;
2370 return fs;
2371 }
2372 else if (alreadyProcessed)
2373 {
2374 return nullptr;
2375 }
2376 }
2377 }
2378 if (state->pathList.empty())
2379 {
2380 return nullptr;
2381 }
2382 for (auto path : state->pathList)
2383 {
2384 QCString absName = path+"/"+fileName;
2385 //printf(" Looking for %s in %s\n",fileName,qPrint(path));
2386 auto fs = checkAndOpenFile(yyscanner,absName,alreadyProcessed);
2387 if (fs)
2388 {
2389 setFileName(yyscanner,absName);
2390 state->yyLineNr=1;
2391 //printf(" -> found it\n");
2392 return fs;
2393 }
2394 else if (alreadyProcessed)
2395 {
2396 return nullptr;
2397 }
2398 }
2399 bool ambig = false;
2401 if (fd && !ambig) // fallback in case the file is uniquely named in the input, use that one
2402 {
2403 auto fs = checkAndOpenFile(yyscanner,fd->absFilePath(),alreadyProcessed);
2404 if (fs)
2405 {
2406 setFileName(yyscanner,fd->absFilePath());
2407 state->yyLineNr=1;
2408 //printf(" -> found it\n");
2409 return fs;
2410 }
2411 }
2412 return nullptr;
2413}
2414
2416{
2417 if (s.isEmpty()) return "";
2418 int i=(int)s.length()-1;
2419 while (i>=0)
2420 {
2421 char c=s[i];
2422 switch (c)
2423 {
2424 case '/':
2425 {
2426 i--;
2427 if (i>=0 && s[i]=='*') // end of a comment block
2428 {
2429 i--;
2430 while (i>0 && !(s[i-1]=='/' && s[i]=='*')) i--;
2431 if (i==0)
2432 {
2433 i++;
2434 }
2435 // only /*!< ... */ or /**< ... */ are treated as a comment for the macro name,
2436 // otherwise the comment is treated as part of the macro definition
2437 return ((s[i+1]=='*' || s[i+1]=='!') && s[i+2]=='<') ? &s[i-1] : "";
2438 }
2439 else
2440 {
2441 return "";
2442 }
2443 }
2444 break;
2445 // whitespace or line-continuation
2446 case ' ':
2447 case '\t':
2448 case '\r':
2449 case '\n':
2450 case '\\':
2451 break;
2452 default:
2453 return "";
2454 }
2455 i--;
2456 }
2457 return "";
2458}
2459
2460static int getNextChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t &pos);
2461static int getCurrentChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t pos);
2462static void unputChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t &pos,char c);
2463static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,int pos,int level);
2464
2465static QCString stringize(const QCString &s)
2466{
2467 QCString result;
2468 uint32_t i=0;
2469 bool inString=FALSE;
2470 bool inChar=FALSE;
2471 char c,pc;
2472 while (i<s.length())
2473 {
2474 if (!inString && !inChar)
2475 {
2476 while (i<s.length() && !inString && !inChar)
2477 {
2478 c=s.at(i++);
2479 if (c=='"')
2480 {
2481 result+="\\\"";
2482 inString=TRUE;
2483 }
2484 else if (c=='\'')
2485 {
2486 result+=c;
2487 inChar=TRUE;
2488 }
2489 else
2490 {
2491 result+=c;
2492 }
2493 }
2494 }
2495 else if (inChar)
2496 {
2497 while (i<s.length() && inChar)
2498 {
2499 c=s.at(i++);
2500 if (c=='\'')
2501 {
2502 result+='\'';
2503 inChar=FALSE;
2504 }
2505 else if (c=='\\')
2506 {
2507 result+="\\\\";
2508 }
2509 else
2510 {
2511 result+=c;
2512 }
2513 }
2514 }
2515 else
2516 {
2517 pc=0;
2518 while (i<s.length() && inString)
2519 {
2520 c=s.at(i++);
2521 if (c=='"')
2522 {
2523 result+="\\\"";
2524 inString= pc=='\\';
2525 }
2526 else if (c=='\\')
2527 result+="\\\\";
2528 else
2529 result+=c;
2530 pc=c;
2531 }
2532 }
2533 }
2534 //printf("stringize '%s'->'%s'\n",qPrint(s),qPrint(result));
2535 return result;
2536}
2537
2538/*! Execute all ## operators in expr.
2539 * If the macro name before or after the operator contains a no-rescan
2540 * marker (@-) then this is removed (before the concatenated macro name
2541 * may be expanded again.
2542 */
2543static void processConcatOperators(QCString &expr)
2544{
2545 if (expr.isEmpty()) return;
2546 //printf("processConcatOperators: in='%s'\n",qPrint(expr));
2547 std::string e = expr.str();
2548 static const reg::Ex r(R"(\s*##\s*)");
2550
2551 size_t i=0;
2552 for (;;)
2553 {
2554 reg::Iterator it(e,r,i);
2555 if (it!=end)
2556 {
2557 const auto &match = *it;
2558 size_t n = match.position();
2559 size_t l = match.length();
2560 //printf("Match: '%s'\n",qPrint(expr.mid(i)));
2561 if (n+l+1<e.length() && e[static_cast<int>(n+l)]=='@' && expr[static_cast<int>(n+l+1)]=='-')
2562 {
2563 // remove no-rescan marker after ID
2564 l+=2;
2565 }
2566 //printf("found '%s'\n",qPrint(expr.mid(n,l)));
2567 // remove the ## operator and the surrounding whitespace
2568 e=e.substr(0,n)+e.substr(n+l);
2569 int k=static_cast<int>(n)-1;
2570 while (k>=0 && isId(e[k])) k--;
2571 if (k>0 && e[k]=='-' && e[k-1]=='@')
2572 {
2573 // remove no-rescan marker before ID
2574 e=e.substr(0,k-1)+e.substr(k+1);
2575 n-=2;
2576 }
2577 i=n;
2578 }
2579 else
2580 {
2581 break;
2582 }
2583 }
2584
2585 expr = e;
2586
2587 //printf("processConcatOperators: out='%s'\n",qPrint(expr));
2588}
2589
2590static void returnCharToStream(yyscan_t yyscanner,char c)
2591{
2592 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2593 unput(c);
2594}
2595
2596static inline void addTillEndOfString(yyscan_t yyscanner,const QCString &expr,QCString *rest,
2597 uint32_t &pos,char term,QCString &arg)
2599 int cc;
2600 while ((cc=getNextChar(yyscanner,expr,rest,pos))!=EOF && cc!=0)
2601 {
2602 if (cc=='\\')
2603 {
2604 arg+=(char)cc;
2605 cc=getNextChar(yyscanner,expr,rest,pos);
2606 }
2607 else if (cc==term)
2608 {
2609 return;
2610 }
2611 arg+=(char)cc;
2612 }
2613}
2614
2615static void skipCommentMacroName(yyscan_t yyscanner, const QCString &expr, QCString *rest,
2616 int &cc, uint32_t &j, int &len)
2618 bool changed = false;
2619
2620 do
2621 {
2622 changed = false;
2623 while ((cc=getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc!='\n' && isspace(cc))
2624 {
2625 len++;
2626 getNextChar(yyscanner,expr,rest,j);
2627 }
2628
2629 if (cc=='/') // possible start of a comment
2630 {
2631 int prevChar = '\0';
2632 getNextChar(yyscanner,expr,rest,j);
2633 if ((cc=getCurrentChar(yyscanner,expr,rest,j))!=EOF && cc == '*') // we have a comment
2634 {
2635 while ((cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2636 {
2637 if (cc == '/' && prevChar == '*') break; // we have an end of comment
2638 prevChar = cc;
2639 }
2640 if (cc != EOF) changed = true;
2641 }
2642 }
2643 } while (changed);
2644}
2645
2646// Expand C++20's __VA_OPT__(x) to either x if hasOptionalArgs==true or to the empty string if false
2647static QCString expandVAOpt(const QCString &vaStr,bool hasOptionalArgs)
2648{
2649 //printf("expandVAOpt(vaStr=%s,hasOptionalArgs=%d)\n",qPrint(vaStr),hasOptionalArgs);
2650 QCString result;
2651 int vo=0, vp=0;
2652 result.clear();
2653 int vl = static_cast<int>(vaStr.length());
2654 while ((vo = vaStr.find("__VA_OPT__(",vp))!=-1)
2655 {
2656 bool hasHash = vo>0 && vaStr.at(vo-1)=='#';
2657 if (hasHash)
2658 {
2659 result+=vaStr.mid(vp,vo-vp-1); // don't copy #
2660 result+="\"";
2661 }
2662 else
2663 {
2664 result+=vaStr.mid(vp,vo-vp);
2665 }
2666 int ve=vo+11; // skip over '__VA_OPT__(' part
2667 int bc=1;
2668 while (bc>0 && ve<vl)
2669 {
2670 if (vaStr[ve]==')') bc--;
2671 else if (vaStr[ve]=='(') bc++;
2672 ve++;
2673 }
2674 // ve points to end of __VA_OPT__(....)
2675 if (bc==0 && hasOptionalArgs)
2676 {
2677 QCString voStr = vaStr.mid(vo+11,ve-vo-12);
2678 //printf("vo=%d ve=%d voStr=%s\n",vo,ve,qPrint(voStr));
2679 result+=voStr; // take 'x' from __VA_OPT__(x)
2680 }
2681 if (hasHash)
2682 {
2683 result+="\"";
2684 }
2685 vp=ve;
2686 }
2687 result+=vaStr.mid(vp);
2688 //printf("vaStr='%s'\n -> '%s'\n",qPrint(vaStr),qPrint(result));
2689 return result;
2690}
2691
2692/*! replaces the function macro \a def whose argument list starts at
2693 * \a pos in expression \a expr.
2694 * Notice that this routine may scan beyond the \a expr string if needed.
2695 * In that case the characters will be read from the input file.
2696 * The replacement string will be returned in \a result and the
2697 * length of the (unexpanded) argument list is stored in \a len.
2698 */
2699static bool replaceFunctionMacro(yyscan_t yyscanner,const QCString &expr,QCString *rest,int pos,int &len,const Define *def,QCString &result,int level)
2700{
2701 //printf(">replaceFunctionMacro(expr='%s',rest='%s',pos=%d,def='%s') level=%zu\n",qPrint(expr),rest ? qPrint(*rest) : 0,pos,qPrint(def->name),preYYget_extra(yyscanner)->levelGuard.size());
2702 uint32_t j=pos;
2703 len=0;
2704 result.clear();
2705 int cc;
2706
2707 skipCommentMacroName(yyscanner, expr, rest, cc, j, len);
2708
2709 if (cc!='(')
2710 {
2711 if (cc!=':') // don't add spaces for colons
2712 {
2713 unputChar(yyscanner,expr,rest,j,' ');
2714 }
2715 return FALSE;
2716 }
2717 getNextChar(yyscanner,expr,rest,j); // eat the '(' character
2718
2719 std::map<std::string,std::string> argTable; // list of arguments
2720 QCString arg;
2721 int argCount=0;
2722 int argCountNonEmpty=0;
2723 bool done=FALSE;
2724
2725 // PHASE 1: read the macro arguments
2726 if (def->nargs==0)
2727 {
2728 while ((cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2729 {
2730 char c = (char)cc;
2731 if (c==')') break;
2732 }
2733 }
2734 else
2735 {
2736 while (!done && (argCount<def->nargs || def->varArgs) &&
2737 ((cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2738 )
2739 {
2740 char c=(char)cc;
2741 if (c=='(') // argument is a function => search for matching )
2742 {
2743 int lvl=1;
2744 arg+=c;
2745 //char term='\0';
2746 while ((cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2747 {
2748 c=(char)cc;
2749 //printf("processing %c: term=%c (%d)\n",c,term,term);
2750 if (c=='\'' || c=='\"') // skip ('s and )'s inside strings
2751 {
2752 arg+=c;
2753 addTillEndOfString(yyscanner,expr,rest,j,c,arg);
2754 }
2755 if (c==')')
2756 {
2757 lvl--;
2758 arg+=c;
2759 if (lvl==0) break;
2760 }
2761 else if (c=='(')
2762 {
2763 lvl++;
2764 arg+=c;
2765 }
2766 else
2767 {
2768 arg+=c;
2769 }
2770 }
2771 }
2772 else if (c==')' || c==',') // last or next argument found
2773 {
2774 if (c==',' && argCount==def->nargs-1 && def->varArgs)
2775 {
2776 expandExpression(yyscanner,arg,nullptr,0,level+1);
2777 arg=arg.stripWhiteSpace();
2778 arg+=',';
2779 }
2780 else
2781 {
2782 expandExpression(yyscanner,arg,nullptr,0,level+1);
2783 arg=arg.stripWhiteSpace();
2784 QCString argKey;
2785 argKey.sprintf("@%d",argCount++); // key name
2786 if (c==',' || !arg.isEmpty()) argCountNonEmpty++;
2787 // add argument to the lookup table
2788 argTable.emplace(toStdString(argKey), toStdString(arg));
2789 arg.clear();
2790 if (c==')') // end of the argument list
2791 {
2792 done=TRUE;
2793 }
2794 }
2795 }
2796 else if (c=='\"') // append literal strings
2797 {
2798 arg+=c;
2799 bool found=FALSE;
2800 while (!found && (cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2801 {
2802 found = cc=='"';
2803 if (cc=='\\')
2804 {
2805 c=(char)cc;
2806 arg+=c;
2807 if ((cc=getNextChar(yyscanner,expr,rest,j))==EOF || cc==0) break;
2808 }
2809 c=(char)cc;
2810 arg+=c;
2811 }
2812 }
2813 else if (c=='\'') // append literal characters
2814 {
2815 arg+=c;
2816 bool found=FALSE;
2817 while (!found && (cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2818 {
2819 found = cc=='\'';
2820 if (cc=='\\')
2821 {
2822 c=(char)cc;
2823 arg+=c;
2824 if ((cc=getNextChar(yyscanner,expr,rest,j))==EOF || cc==0) break;
2825 }
2826 c=(char)cc;
2827 arg+=c;
2828 }
2829 }
2830 else if (c=='/') // possible start of a comment
2831 {
2832 char prevChar = '\0';
2833 arg+=c;
2834 if ((cc=getCurrentChar(yyscanner,expr,rest,j)) == '*') // we have a comment
2835 {
2836 while ((cc=getNextChar(yyscanner,expr,rest,j))!=EOF && cc!=0)
2837 {
2838 c=(char)cc;
2839 arg+=c;
2840 if (c == '/' && prevChar == '*') break; // we have an end of comment
2841 prevChar = c;
2842 }
2843 }
2844 }
2845 else // append other characters
2846 {
2847 arg+=c;
2848 }
2849 }
2850 }
2851
2852 // PHASE 2: apply the macro function
2853 if (argCount==def->nargs || // same number of arguments
2854 (argCount>=def->nargs-1 && def->varArgs)) // variadic macro with at least as many
2855 // params as the non-variadic part (see bug731985)
2856 {
2857 uint32_t k=0;
2858 // substitution of all formal arguments
2859 QCString resExpr;
2861 //printf("varArgs=%d argCount=%d def->nargs=%d d=%s\n",def->varArgs,argCount,def->nargs,qPrint(d));
2862 if (def->varArgs) d = expandVAOpt(d,argCountNonEmpty!=def->nargs-1);
2863 //printf("Macro definition: '%s'\n",qPrint(d));
2864 bool inString=FALSE;
2865 while (k<d.length())
2866 {
2867 if (d.at(k)=='@') // maybe a marker, otherwise an escaped @
2868 {
2869 if (d.at(k+1)=='@') // escaped @ => copy it (is unescaped later)
2870 {
2871 k+=2;
2872 resExpr+="@@"; // we unescape these later
2873 }
2874 else if (d.at(k+1)=='-') // no-rescan marker
2875 {
2876 k+=2;
2877 resExpr+="@-";
2878 }
2879 else // argument marker => read the argument number
2880 {
2881 QCString key="@";
2882 bool hash=FALSE;
2883 int l=k-1;
2884 // search for ## backward
2885 if (l>=0 && d.at(l)=='"') l--;
2886 while (l>=0 && d.at(l)==' ') l--;
2887 if (l>0 && d.at(l)=='#' && d.at(l-1)=='#') hash=TRUE;
2888 k++;
2889 // scan the number
2890 while (k<d.length() && d.at(k)>='0' && d.at(k)<='9') key+=d.at(k++);
2891 if (!hash)
2892 {
2893 // search for ## forward
2894 l=k;
2895 if (l<(int)d.length() && d.at(l)=='"') l++;
2896 while (l<(int)d.length() && d.at(l)==' ') l++;
2897 if (l<(int)d.length()-1 && d.at(l)=='#' && d.at(l+1)=='#') hash=TRUE;
2898 }
2899 //printf("request key %s result %s\n",qPrint(key),argTable[key]->data());
2900 auto it = argTable.find(key.str());
2901 if (it!=argTable.end())
2902 {
2903 QCString substArg = it->second;
2904 //printf("substArg='%s'\n",qPrint(substArg));
2905 // only if no ## operator is before or after the argument
2906 // marker we do macro expansion.
2907 if (!hash)
2908 {
2909 expandExpression(yyscanner,substArg,nullptr,0,level+1);
2910 }
2911 if (inString)
2912 {
2913 //printf("'%s'=stringize('%s')\n",qPrint(stringize(*subst)),subst->data());
2914
2915 // if the marker is inside a string (because a # was put
2916 // before the macro name) we must escape " and \ characters
2917 resExpr+=stringize(substArg);
2918 }
2919 else
2920 {
2921 if (hash && substArg.isEmpty())
2922 {
2923 resExpr+="@E"; // empty argument will be remove later on
2924 }
2925 resExpr+=substArg;
2926 }
2927 }
2928 }
2929 }
2930 else // no marker, just copy
2931 {
2932 if (!inString && d.at(k)=='\"')
2933 {
2934 inString=TRUE; // entering a literal string
2935 }
2936 else if (k>2 && inString && d.at(k)=='\"' && (d.at(k-1)!='\\' || d.at(k-2)=='\\'))
2937 {
2938 inString=FALSE; // leaving a literal string
2939 }
2940 resExpr+=d.at(k++);
2941 }
2942 }
2943 len=j-pos;
2944 result=resExpr;
2945 //printf("<replaceFunctionMacro(expr='%s',rest='%s',pos=%d,def='%s',result='%s') level=%zu return=TRUE\n",qPrint(expr),rest ? qPrint(*rest) : 0,pos,qPrint(def->name),qPrint(result),preYYget_extra(yyscanner)->levelGuard.size());
2946 return TRUE;
2947 }
2948 //printf("<replaceFunctionMacro(expr='%s',rest='%s',pos=%d,def='%s',result='%s') level=%zu return=FALSE\n",qPrint(expr),rest ? qPrint(*rest) : 0,pos,qPrint(def->name),qPrint(result),preYYget_extra(yyscanner)->levelGuard.size());
2949 return FALSE;
2950}
2951
2952
2953/*! returns the next identifier in string \a expr by starting at position \a p.
2954 * The position of the identifier is returned (or -1 if nothing is found)
2955 * and \a l is its length. Any quoted strings are skipping during the search.
2956 */
2957static int getNextId(const QCString &expr,int p,int *l)
2958{
2959 int n;
2960 while (p<(int)expr.length())
2961 {
2962 char c=expr.at(p++);
2963 if (isdigit(c)) // skip number
2964 {
2965 while (p<(int)expr.length() && isId(expr.at(p))) p++;
2966 }
2967 else if (isalpha(c) || c=='_') // read id
2968 {
2969 n=p-1;
2970 while (p<(int)expr.length() && isId(expr.at(p))) p++;
2971 *l=p-n;
2972 return n;
2973 }
2974 else if (c=='"') // skip string
2975 {
2976 char ppc=0,pc=c;
2977 if (p<(int)expr.length()) c=expr.at(p);
2978 while (p<(int)expr.length() && (c!='"' || (pc=='\\' && ppc!='\\')))
2979 // continue as long as no " is found, but ignoring \", but not \\"
2980 {
2981 ppc=pc;
2982 pc=c;
2983 c=expr.at(p);
2984 p++;
2985 }
2986 if (p<(int)expr.length()) ++p; // skip closing quote
2987 }
2988 else if (c=='/') // skip C Comment
2989 {
2990 //printf("Found C comment at p=%d\n",p);
2991 char pc=c;
2992 if (p<(int)expr.length())
2993 {
2994 c=expr.at(p);
2995 if (c=='*') // Start of C comment
2996 {
2997 p++;
2998 while (p<(int)expr.length() && !(pc=='*' && c=='/'))
2999 {
3000 pc=c;
3001 c=expr.at(p++);
3002 }
3003 }
3004 }
3005 //printf("Found end of C comment at p=%d\n",p);
3006 }
3007 }
3008 return -1;
3009}
3010
3011#define MAX_EXPANSION_DEPTH 50
3012
3013static void addSeparatorsIfNeeded(yyscan_t yyscanner,const QCString &expr,QCString &resultExpr,QCString &restExpr,int pos)
3014{
3015 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3016 if (!state->nospaces)
3017 {
3018 // peek back in the stream, for a colon character
3019 char ccPrev = pos==0 || (int)expr.length()<pos ? state->prevChar : expr.at(pos-1);
3020 QCString leftSpace = ccPrev!=':' && ccPrev!=' ' ? " " : "";
3021 int ccNext = 0;
3022 restExpr=restExpr.stripWhiteSpace();
3023 if (restExpr.isEmpty()) // peek ahead in the stream for non-whitespace
3024 {
3025 uint32_t j=(uint32_t)resultExpr.length();
3026 while ((ccNext=getNextChar(yyscanner,resultExpr,nullptr,j))!=EOF && ccNext==' ') { }
3027 if (ccNext != EOF) unputChar(yyscanner,resultExpr,nullptr,j,(char)ccNext);
3028 }
3029 else // take first char from remainder
3030 {
3031 ccNext=restExpr.at(0);
3032 }
3033 // don't add whitespace before a colon
3034 QCString rightSpace = ccNext!=':' && ccNext!=' ' ? " " : "";
3035 //printf("ccPrev='%c' ccNext='%c' p=%d expr=%zu restExpr='%s' left='%s' right='%s'\n",
3036 // ccPrev,ccNext,pos,expr.length(),qPrint(restExpr),qPrint(leftSpace),qPrint(rightSpace));
3037 resultExpr=leftSpace+resultExpr+rightSpace;
3038 }
3039}
3040
3041/*! performs recursive macro expansion on the string \a expr
3042 * starting at position \a pos.
3043 * May read additional characters from the input while re-scanning!
3044 */
3045static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,int pos,int level)
3046{
3047 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3048 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3049 //printf(">expandExpression(expr='%s',rest='%s',pos=%d,level=%d)\n",qPrint(expr),rest ? qPrint(*rest) : "", pos, level);
3050 if (expr.isEmpty())
3051 {
3052 //printf("<expandExpression: empty\n");
3053 return TRUE;
3054 }
3055 if (state->expanded.find(expr.str())!=state->expanded.end() &&
3056 level>MAX_EXPANSION_DEPTH) // check for too deep recursive expansions
3057 {
3058 //printf("<expandExpression: already expanded expr='%s'\n",qPrint(expr));
3059 return FALSE;
3060 }
3061 else
3062 {
3063 state->expanded.insert(expr.str());
3064 }
3065 QCString macroName;
3066 QCString expMacro;
3067 bool definedTest=FALSE;
3068 int i=pos, l=0, p=0, len=0;
3069 int startPos = pos;
3070 int samePosCount=0;
3071 while ((p=getNextId(expr,i,&l))!=-1) // search for an macro name
3072 {
3073 bool replaced=FALSE;
3074 macroName=expr.mid(p,l);
3075 //printf(" p=%d macroName=%s\n",p,qPrint(macroName));
3076 if (p<2 || !(expr.at(p-2)=='@' && expr.at(p-1)=='-')) // no-rescan marker?
3077 {
3078 if (state->expandedDict.find(macroName.str())==state->expandedDict.end()) // expand macro
3079 {
3080 bool expanded=false;
3081 Define *def=isDefined(yyscanner,macroName);
3082 // In case EXPAND_ONLY_PREDEF is enabled prevent expansion unless the macro was explicitly
3083 // predefined
3084 if (yyextra->expandOnlyPredef && def && !def->isPredefined) def=nullptr;
3085 if (macroName=="defined")
3086 {
3087 //printf("found defined inside macro definition '%s'\n",qPrint(expr.right(expr.length()-p)));
3088 definedTest=TRUE;
3089 }
3090 else if (definedTest) // macro name was found after defined
3091 {
3092 if (def) expMacro = " 1 "; else expMacro = " 0 ";
3093 replaced=TRUE;
3094 len=l;
3095 definedTest=FALSE;
3096 }
3097 else if (def && def->nargs==-1) // simple macro
3098 {
3099 // substitute the definition of the macro
3100 expMacro=def->definition.stripWhiteSpace();
3101 //expMacro=def->definition.stripWhiteSpace();
3102 replaced=TRUE;
3103 len=l;
3104 //printf("simple macro expansion='%s'->'%s'\n",qPrint(macroName),qPrint(expMacro));
3105 }
3106 else if (def && def->nargs>=0) // function macro
3107 {
3108 //printf(" >>>> call replaceFunctionMacro expr='%s'\n",qPrint(expr));
3109 replaced=replaceFunctionMacro(yyscanner,expr,rest,p+l,len,def,expMacro,level);
3110 //printf(" <<<< call replaceFunctionMacro: replaced=%d\n",replaced);
3111 len+=l;
3112 }
3113
3114 if (replaced) // expand the macro and rescan the expression
3115 {
3116 //printf(" replacing '%s'->'%s'\n",qPrint(expr.mid(p,len)),qPrint(expMacro));
3117 QCString resultExpr=expMacro;
3118 QCString restExpr=expr.right(expr.length()-len-p);
3119 addSeparatorsIfNeeded(yyscanner,expr,resultExpr,restExpr,p);
3120 processConcatOperators(resultExpr);
3121 //printf(" macroName=%s restExpr='%s' def->nonRecursive=%d\n",qPrint(macroName),qPrint(restExpr),def ? def->nonRecursive : false);
3122 if (def && !def->nonRecursive)
3123 {
3124 state->expandedDict.emplace(toStdString(macroName),def);
3125 expanded = expandExpression(yyscanner,resultExpr,&restExpr,0,level+1);
3126 state->expandedDict.erase(toStdString(macroName));
3127 }
3128 else if (def && def->nonRecursive)
3129 {
3130 expanded = true;
3131 }
3132 if (expanded)
3133 {
3134 //printf("expanded '%s' + '%s' + '%s'\n",qPrint(expr.left(p)),qPrint(resultExpr),qPrint(restExpr));
3135 expr=expr.left(p)+resultExpr+restExpr;
3136 i=p;
3137 }
3138 else
3139 {
3140 //printf("not expanded '%s' + @- '%s'\n",qPrint(expr.left(p)),qPrint(expr.right(expr.length()-p)));
3141 expr=expr.left(p)+"@-"+expr.right(expr.length()-p);
3142 i=p+l+2;
3143 }
3144 }
3145 else // move to the next macro name
3146 {
3147 //printf(" moving to the next macro old i=%d new i=%d\n",i,p+l);
3148 i=p+l;
3149 }
3150 }
3151 else // move to the next macro name
3152 {
3153 expr=expr.left(p)+"@-"+expr.right(expr.length()-p);
3154 //printf("macro already expanded, moving to the next macro expr=%s\n",qPrint(expr));
3155 i=p+l+2;
3156 //i=p+l;
3157 }
3158 // check for too many inplace expansions without making progress
3159 if (i==startPos)
3160 {
3161 samePosCount++;
3162 }
3163 else
3164 {
3165 startPos=i;
3166 samePosCount=0;
3167 }
3168 if (samePosCount>MAX_EXPANSION_DEPTH)
3169 {
3170 break;
3171 }
3172 }
3173 else // no re-scan marker found, skip the macro name
3174 {
3175 //printf("skipping marked macro\n");
3176 i=p+l;
3177 }
3178 }
3179 //printf("<expandExpression(expr='%s',rest='%s',pos=%d,level=%d)\n",qPrint(expr),rest ? qPrint(*rest) : "", pos,level);
3180 return TRUE;
3181}
3182
3183/*! @brief Process string or character literal.
3184 *
3185 * \a inputStr should point to the start of a string or character literal.
3186 * the routine will return a pointer to just after the end of the literal
3187 * the character making up the literal will be added to \a result.
3188 */
3189static const char *processUntilMatchingTerminator(const char *inputStr,QCString &result)
3190{
3191 if (inputStr==nullptr) return inputStr;
3192 char term = *inputStr; // capture start character of the literal
3193 if (term!='\'' && term!='"') return inputStr; // not a valid literal
3194 char c=term;
3195 // output start character
3196 result+=c;
3197 inputStr++;
3198 while ((c=*inputStr)) // while inside the literal
3199 {
3200 if (c==term) // found end marker of the literal
3201 {
3202 // output end character and stop
3203 result+=c;
3204 inputStr++;
3205 break;
3206 }
3207 else if (c=='\\') // escaped character, process next character
3208 // as well without checking for end marker.
3209 {
3210 result+=c;
3211 inputStr++;
3212 c=*inputStr;
3213 if (c==0) break; // unexpected end of string after escape character
3214 }
3215 result+=c;
3216 inputStr++;
3217 }
3218 return inputStr;
3219}
3220
3221/*! replaces all occurrences of @@@@ in \a s by @@
3222 * and removes all occurrences of @@E.
3223 * All identifiers found are replaced by 0L
3224 */
3225static QCString removeIdsAndMarkers(const QCString &s)
3226{
3227 static const std::vector<std::string> signs = { "signed", "unsigned" };
3228 struct TypeInfo { std::string name; size_t size; };
3229 static const std::vector<TypeInfo> types = {
3230 { "short int", sizeof(short int) },
3231 { "long long int", sizeof(long long int) },
3232 { "long int", sizeof(long int) },
3233 { "long long", sizeof(long long) },
3234 { "long double", sizeof(long double) },
3235 { "int", sizeof(int) },
3236 { "short", sizeof(short) },
3237 { "bool", sizeof(bool) },
3238 { "long", sizeof(long) },
3239 { "char", sizeof(char) },
3240 { "float", sizeof(float) },
3241 { "double", sizeof(double) },
3242 };
3243
3244 // Check if string p starts with basic types ending with a ')', such as 'signed long)' or ' float )'
3245 // and return the pointer just past the ')' and the size of the type as a tuple.
3246 // If the pattern is not found the tuple (nullptr,0) is returned.
3247 auto process_cast_or_sizeof = [](const char *p) -> std::pair<const char *,size_t>
3248 {
3249 const char *q = p;
3250 while (*q==' ' || *q=='\t') q++;
3251 bool found=false;
3252 size_t size = sizeof(int); // '(signed)' or '(unsigned)' is an int type
3253 for (const auto &sgn : signs)
3254 {
3255 if (qstrncmp(q,sgn.c_str(),sgn.length())==0) { q+=sgn.length(); found=true; }
3256 }
3257 if (!found || *q==' ' || *q=='\t' || *q==')') // continue searching
3258 {
3259 while (*q==' ' || *q=='\t') q++;
3260 for (const auto &t : types)
3261 {
3262 if (qstrncmp(q,t.name.c_str(),t.name.length())==0)
3263 {
3264 q += t.name.length();
3265 size = t.size;
3266 break;
3267 }
3268 }
3269 while (*q==' ' || *q=='\t') q++;
3270 if (*q==')') return std::make_pair(++q,size);
3271 }
3272 return std::make_pair(nullptr,0);
3273 };
3274
3275 //printf("removeIdsAndMarkers(%s)\n",qPrint(s));
3276 if (s.isEmpty()) return s;
3277 const char *p=s.data();
3278 bool inNum=FALSE;
3279 QCString result;
3280 if (p)
3281 {
3282 char c = 0;
3283 while ((c=*p))
3284 {
3285 if (c=='(') // potential cast, ignore it
3286 {
3287 const char *q = process_cast_or_sizeof(p+1).first;
3288 //printf("potential cast:\nin: %s\nout: %s\n",p,q);
3289 if (q)
3290 {
3291 p=q;
3292 continue;
3293 }
3294 }
3295 else if (c=='s' && literal_at(p,"sizeof")) // sizeof(...)
3296 {
3297 const char *q = p+6;
3298 while (*q==' ' || *q=='\t') q++;
3299 if (*q=='(')
3300 {
3301 auto r = process_cast_or_sizeof(q+1);
3302 //printf("sizeof:\nin: %s\nout: %zu%s\n--> sizeof=%zu\n",p,r.second,r.first,r.second);
3303 if (r.first)
3304 {
3305 result+=QCString().setNum(r.second);
3306 p=r.first;
3307 continue;
3308 }
3309 }
3310 }
3311
3312 if (c=='@') // replace @@ with @ and remove @E
3313 {
3314 if (*(p+1)=='@')
3315 {
3316 result+=c;
3317 }
3318 else if (*(p+1)=='E')
3319 {
3320 // skip
3321 }
3322 p+=2;
3323 }
3324 else if (isdigit(c)) // number
3325 {
3326 result+=c;
3327 p++;
3328 inNum=TRUE;
3329 }
3330 else if (c=='\'') // quoted character
3331 {
3332 p = processUntilMatchingTerminator(p,result);
3333 }
3334 else if (c=='d' && !inNum) // identifier starting with a 'd'
3335 {
3336 if (literal_at(p,"defined ") || literal_at(p,"defined("))
3337 // defined keyword
3338 {
3339 p+=7; // skip defined
3340 }
3341 else
3342 {
3343 result+="0L";
3344 p++;
3345 while ((c=*p) && isId(c)) p++;
3346 }
3347 }
3348 else if ((isalpha(c) || c=='_') && !inNum) // replace identifier with 0L
3349 {
3350 result+="0L";
3351 p++;
3352 while ((c=*p) && isId(c)) p++;
3353 while ((c=*p) && isspace((uint8_t)c)) p++;
3354 if (*p=='(') // undefined function macro
3355 {
3356 p++;
3357 int count=1;
3358 while ((c=*p++))
3359 {
3360 if (c=='(') count++;
3361 else if (c==')')
3362 {
3363 count--;
3364 if (count==0) break;
3365 }
3366 else if (c=='/')
3367 {
3368 char pc=c;
3369 c=*++p;
3370 if (c=='*') // start of C comment
3371 {
3372 while (*p && !(pc=='*' && c=='/')) // search end of comment
3373 {
3374 pc=c;
3375 c=*++p;
3376 }
3377 p++;
3378 }
3379 }
3380 }
3381 }
3382 }
3383 else if (c=='/') // skip C comments
3384 {
3385 char pc=c;
3386 c=*++p;
3387 if (c=='*') // start of C comment
3388 {
3389 while (*p && !(pc=='*' && c=='/')) // search end of comment
3390 {
3391 pc=c;
3392 c=*++p;
3393 }
3394 p++;
3395 }
3396 else // oops, not comment but division
3397 {
3398 result+=pc;
3399 goto nextChar;
3400 }
3401 }
3402 else
3403 {
3404nextChar:
3405 result+=c;
3406 char lc=(char)tolower(c);
3407 if (!isId(lc) && lc!='.' /*&& lc!='-' && lc!='+'*/) inNum=FALSE;
3408 p++;
3409 }
3410 }
3411 }
3412 //printf("removeIdsAndMarkers(%s)=%s\n",s,qPrint(result));
3413 return result;
3414}
3415
3416/*! replaces all occurrences of @@ in \a s by @
3417 * \par assumption:
3418 * \a s only contains pairs of @@'s
3419 */
3420static QCString removeMarkers(const QCString &s)
3421{
3422 if (s.isEmpty()) return s;
3423 const char *p=s.data();
3424 QCString result;
3425 if (p)
3426 {
3427 char c = 0;
3428 while ((c=*p))
3429 {
3430 switch(c)
3431 {
3432 case '@': // replace @@ with @
3433 {
3434 if (*(p+1)=='@')
3435 {
3436 result+=c;
3437 }
3438 p+=2;
3439 }
3440 break;
3441 case '/': // skip C comments
3442 {
3443 result+=c;
3444 char pc=c;
3445 c=*++p;
3446 if (c=='*') // start of C comment
3447 {
3448 while (*p && !(pc=='*' && c=='/')) // search end of comment
3449 {
3450 if (*p=='@' && *(p+1)=='@')
3451 {
3452 result+=c;
3453 p++;
3454 }
3455 else
3456 {
3457 result+=c;
3458 }
3459 pc=c;
3460 c=*++p;
3461 }
3462 if (*p)
3463 {
3464 result+=c;
3465 p++;
3466 }
3467 }
3468 }
3469 break;
3470 case '"': // skip string literals
3471 case '\'': // skip char literals
3472 p = processUntilMatchingTerminator(p,result);
3473 break;
3474 default:
3475 {
3476 result+=c;
3477 p++;
3478 }
3479 break;
3480 }
3481 }
3482 }
3483 //printf("RemoveMarkers(%s)=%s\n",s,qPrint(result));
3484 return result;
3485}
3486
3487/*! compute the value of the expression in string \a expr.
3488 * If needed the function may read additional characters from the input.
3489 */
3490
3491static bool computeExpression(yyscan_t yyscanner,const QCString &expr)
3492{
3493 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3494 QCString e=expr;
3495 QCString ee=expr;
3496 ee = removeMarkers(ee);
3497 state->expanded.clear();
3498 expandExpression(yyscanner,e,nullptr,0,0);
3499 //printf("after expansion '%s'\n",qPrint(e));
3500 e = removeIdsAndMarkers(e);
3501 if (e.isEmpty()) return FALSE;
3502 //printf("parsing '%s'\n",qPrint(e));
3503 return state->constExpParser.parse(state->fileName.data(),state->yyLineNr,e.str(),ee.str());
3504}
3505
3506/*! expands the macro definition in \a name
3507 * If needed the function may read additional characters from the input
3508 */
3509
3510static QCString expandMacro(yyscan_t yyscanner,const QCString &name)
3511{
3512 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3513 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3514 state->prevChar = yyscanner->yytext_r > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ? *(yyscanner->yytext_r-1) : 0;
3515 QCString n=name;
3516 state->expanded.clear();
3517 expandExpression(yyscanner,n,nullptr,0,0);
3518 n=removeMarkers(n);
3519 state->prevChar=0;
3520 //printf("expandMacro '%s'->'%s'\n",qPrint(name),qPrint(n));
3521 return n;
3522}
3523
3524static void addDefine(yyscan_t yyscanner)
3525{
3526 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3527 Define def;
3528 def.name = state->defName;
3529 def.definition = state->defText.stripWhiteSpace();
3530 def.nargs = state->defArgs;
3531 def.fileName = state->fileName;
3532 def.fileDef = state->yyFileDef;
3533 def.lineNr = state->yyLineNr-state->yyMLines;
3534 def.columnNr = state->yyColNr;
3535 def.varArgs = state->defVarArgs;
3536 //printf("newDefine: %s %s file: %s\n",qPrint(def.name),qPrint(def.definition),
3537 // def.fileDef ? qPrint(def.fileDef->name()) : qPrint(def.fileName));
3538 //printf("newDefine: '%s'->'%s'\n",qPrint(def.name),qPrint(def.definition));
3539 if (!def.name.isEmpty() &&
3541 {
3542 def.isPredefined=TRUE;
3544 }
3545 auto it = state->localDefines.find(def.name.str());
3546 if (it!=state->localDefines.end()) // redefine
3547 {
3548 state->localDefines.erase(it);
3549 }
3550 state->localDefines.emplace(def.name.str(),def);
3551}
3552
3553static void addMacroDefinition(yyscan_t yyscanner)
3554{
3555 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3556 if (state->skip) return; // do not add this define as it is inside a
3557 // conditional section (cond command) that is disabled.
3558
3559 Define define;
3560 define.fileName = state->fileName;
3561 define.lineNr = state->yyLineNr - state->yyMLines;
3562 define.columnNr = state->yyColNr;
3563 define.name = state->defName;
3564 define.args = state->defArgsStr;
3565 define.fileDef = state->inputFileDef;
3566
3567 QCString litText = state->defLitText;
3568 int l=litText.find('\n');
3569 if (l>0 && litText.left(l).stripWhiteSpace()=="\\")
3570 {
3571 // strip first line if it only contains a slash
3572 litText = litText.right(litText.length()-l-1);
3573 }
3574 else if (l>0)
3575 {
3576 // align the items on the first line with the items on the second line
3577 int k=l+1;
3578 const char *p=litText.data()+k;
3579 char c = 0;
3580 while ((c=*p++) && (c==' ' || c=='\t')) k++;
3581 litText=litText.mid(l+1,k-l-1)+litText.stripWhiteSpace();
3582 }
3583 QCString litTextStripped = state->defLitText.stripWhiteSpace();
3584 if (litTextStripped.contains('\n')>=1)
3585 {
3586 define.definition = litText;
3587 }
3588 else
3589 {
3590 define.definition = litTextStripped;
3591 }
3592 {
3593 state->macroDefinitions.push_back(define);
3594 }
3595}
3596
3597static inline void outputChar(yyscan_t yyscanner,char c)
3598{
3599 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3600 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=c;
3601}
3602
3603static inline void outputArray(yyscan_t yyscanner,const char *a,yy_size_t len)
3604{
3605 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3606 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=std::string_view(a,len);
3607}
3608
3609static inline void outputString(yyscan_t yyscanner,const QCString &a)
3610{
3611 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3612 if (state->includeStack.empty() || state->curlyCount>0) (*state->outputBuf)+=a.str();
3613}
3614
3615static inline void outputSpace(yyscan_t yyscanner,char c)
3616{
3617 if (c=='\t') outputChar(yyscanner,'\t');
3618 else outputChar(yyscanner,' ');
3619}
3620
3621static inline void outputSpaces(yyscan_t yyscanner,char *s)
3622{
3623 const char *p=s;
3624 char c = 0;
3625 while ((c=*p++))
3626 {
3627 if (c=='\t') outputChar(yyscanner,'\t');
3628 else outputChar(yyscanner,' ');
3629 }
3630}
3631
3632static inline void extraSpacing(yyscan_t yyscanner)
3633{
3634 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3635 if (!yyextra->defContinue) return;
3636 for (int i=0; i< (int)yyleng; i++)
3637 {
3638 if (yytext[i] == '\t')
3639 yyextra->defExtraSpacing+='\t';
3640 else
3641 yyextra->defExtraSpacing+=' ';
3642 }
3643}
3644
3645static void determineBlockName(yyscan_t yyscanner)
3646{
3647 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3648 yyextra->fenceSize=0;
3649 char c=0;
3650 if (yytext[1]=='f' && ((c=yytext[2])=='[' || c=='{' || c=='(' || c=='$'))
3651 {
3652 switch (c)
3653 {
3654 case '[': yyextra->blockName="]"; break;
3655 case '{': yyextra->blockName="}"; break;
3656 case '(': yyextra->blockName=")"; break;
3657 case '$': yyextra->blockName="$"; break;
3658 default: break;
3659 }
3660 yyextra->blockName=yyextra->blockName.stripWhiteSpace();
3661 }
3662 else
3663 {
3664 QCString bn=QCString(&yytext[1]).stripWhiteSpace();
3665 if (bn=="startuml")
3666 {
3667 yyextra->blockName="uml";
3668 }
3669 else
3670 {
3671 int i = bn.find('{'); // for \code{.c}
3672 if (i!=-1) bn=bn.left(i).stripWhiteSpace();
3673 yyextra->blockName=bn;
3674 }
3675 }
3676}
3677
3678static void readIncludeFile(yyscan_t yyscanner,const QCString &inc)
3679{
3680 AUTO_TRACE("inc={}",inc);
3681 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3682 uint32_t i=0;
3683
3684 // find the start of the include file name
3685 while (i<inc.length() &&
3686 (inc.at(i)==' ' || inc.at(i)=='"' || inc.at(i)=='<')
3687 ) i++;
3688 uint32_t s=i;
3689
3690 // was it a local include?
3691 bool localInclude = s>0 && inc.at(s-1)=='"';
3692
3693 // find the end of the include file name
3694 while (i<inc.length() && inc.at(i)!='"' && inc.at(i)!='>') i++;
3695
3696 if (s<inc.length() && i>s) // valid include file name found
3697 {
3698 // extract include path+name
3699 QCString incFileName=inc.mid(s,i-s).stripWhiteSpace();
3700 if (incFileName.endsWith(".exe") || incFileName.endsWith(".dll") || incFileName.endsWith(".tlb"))
3701 {
3702 // skip imported binary files (e.g. M$ type libraries)
3703 return;
3704 }
3705
3706 QCString oldFileName = state->fileName;
3707 FileDef *oldFileDef = state->yyFileDef;
3708 int oldLineNr = state->yyLineNr;
3709 //printf("Searching for '%s'\n",qPrint(incFileName));
3710
3711 QCString absIncFileName = determineAbsoluteIncludeName(state->fileName,incFileName);
3712
3713 // findFile will overwrite state->yyFileDef if found
3714 std::unique_ptr<FileState> fs;
3715 bool alreadyProcessed = FALSE;
3716 //printf("calling findFile(%s)\n",qPrint(incFileName));
3717 fs=findFile(yyscanner,absIncFileName,localInclude,alreadyProcessed); // see if the absolute include file can be found
3718 if (fs)
3719 {
3720 {
3721 std::lock_guard<std::mutex> lock(g_globalDefineMutex);
3722 g_defineManager.addInclude(oldFileName.str(),absIncFileName.str());
3723 }
3724
3725 //printf("Found include file!\n");
3727 {
3728 for (i=0;i<state->includeStack.size();i++)
3729 {
3731 }
3732 Debug::print(Debug::Preprocessor,0,"#include {}: parsing...\n",incFileName);
3733 }
3734
3735 if (state->includeStack.empty() && oldFileDef)
3736 {
3737 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
3738 if (ii==nullptr)
3739 {
3740 bool ambig = false;
3741 FileDef *incFd = findFileDef(Doxygen::inputNameLinkedMap,absIncFileName,ambig);
3742 state->includeRelations.add(
3743 absIncFileName,
3744 oldFileDef,
3745 ambig ? nullptr : incFd,
3746 incFileName,
3747 localInclude,
3748 state->isImported
3749 );
3750 }
3751 }
3752
3753 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3754 fs->bufState = YY_CURRENT_BUFFER;
3755 fs->lineNr = oldLineNr;
3756 fs->fileName = oldFileName;
3757 fs->curlyCount = state->curlyCount;
3758 //state->curlyCount = 0; // don't reset counter, see issue #10997
3759 fs->lexRulesPart = state->lexRulesPart;
3760 state->lexRulesPart = false;
3761 // push the state on the stack
3762 FileState *fs_ptr = fs.get();
3763 state->includeStack.push_back(std::move(fs));
3764 // set the scanner to the include file
3765
3766 // Deal with file changes due to
3767 // #include's within { .. } blocks
3768 QCString lineStr(state->fileName.length()+20, QCString::ExplicitSize);
3769 lineStr.sprintf("# 1 \"%s\" 1\n",qPrint(state->fileName));
3770 outputString(yyscanner,lineStr);
3771
3772 AUTO_TRACE_ADD("Switching to include file {}",incFileName);
3773 state->expectGuard=TRUE;
3774 state->inputBuf = &fs_ptr->fileBuf;
3775 state->inputBufPos=0;
3776 yy_switch_to_buffer(yy_create_buffer(0, YY_BUF_SIZE, yyscanner),yyscanner);
3777 }
3778 else
3779 {
3780 if (alreadyProcessed) // if this header was already process we can just copy the stored macros
3781 // in the local context
3782 {
3783 std::lock_guard<std::mutex> lock(g_globalDefineMutex);
3784 g_defineManager.addInclude(state->fileName.str(),absIncFileName.str());
3785 g_defineManager.retrieve(absIncFileName.str(),state->contextDefines);
3786 }
3787
3788 if (state->includeStack.empty() && oldFileDef)
3789 {
3790 PreIncludeInfo *ii = state->includeRelations.find(absIncFileName);
3791 if (ii==nullptr)
3792 {
3793 bool ambig = false;
3794 FileDef *incFd = findFileDef(Doxygen::inputNameLinkedMap,absIncFileName,ambig);
3795 ii = state->includeRelations.add(absIncFileName,
3796 oldFileDef,
3797 ambig ? nullptr : incFd,
3798 incFileName,
3799 localInclude,
3800 state->isImported
3801 );
3802 }
3803 }
3804
3806 {
3807 for (i=0;i<state->includeStack.size();i++)
3808 {
3810 }
3811 if (alreadyProcessed)
3812 {
3813 Debug::print(Debug::Preprocessor,0,"#include {}: already processed! skipping...\n",incFileName);
3814 }
3815 else
3816 {
3817 Debug::print(Debug::Preprocessor,0,"#include {}: not found! skipping...\n",incFileName);
3818 }
3819 //printf("error: include file %s not found\n",yytext);
3820 }
3821 if (localInclude && !state->includeStack.empty() && state->curlyCount>0 && !alreadyProcessed) // failed to find #include inside { ... }
3822 {
3823 warn(state->fileName,state->yyLineNr,"include file {} not found, perhaps you forgot to add its directory to INCLUDE_PATH?",incFileName);
3824 }
3825 }
3826 }
3827}
3828
3829/* ----------------------------------------------------------------- */
3830
3831static void startCondSection(yyscan_t yyscanner,const QCString &sectId)
3832{
3833 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3834 //printf("startCondSection: skip=%d stack=%d\n",state->skip,state->condStack.size());
3835 CondParser prs;
3836 bool expResult = prs.parse(state->fileName.data(),state->yyLineNr,sectId.data());
3837 state->condStack.emplace(std::make_unique<preYY_CondCtx>(state->fileName,state->yyLineNr,sectId,state->skip));
3838 if (!expResult)
3839 {
3840 state->skip=TRUE;
3841 }
3842 //printf(" expResult=%d skip=%d\n",expResult,state->skip);
3843}
3844
3845static void endCondSection(yyscan_t yyscanner)
3846{
3847 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3848 if (state->condStack.empty())
3849 {
3850 warn(state->fileName,state->yyLineNr,"the \\endcond does not have a corresponding \\cond in this file");
3851 state->skip=FALSE;
3852 }
3853 else
3854 {
3855 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
3856 state->skip=ctx->skip;
3857 state->condStack.pop();
3858 }
3859 //printf("endCondSection: skip=%d stack=%d\n",state->skip,state->condStack.count());
3860}
3861
3862static void forceEndCondSection(yyscan_t yyscanner)
3863{
3864 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3865 while (!state->condStack.empty())
3866 {
3867 state->condStack.pop();
3868 }
3869 state->skip=FALSE;
3870}
3871
3872static QCString escapeAt(const QCString &text)
3873{
3874 QCString result;
3875 if (!text.isEmpty())
3876 {
3877 char c = 0;
3878 const char *p=text.data();
3879 while ((c=*p++))
3880 {
3881 if (c=='@') result+="@@"; else result+=c;
3882 }
3883 }
3884 return result;
3885}
3886
3887static char resolveTrigraph(char c)
3888{
3889 switch (c)
3890 {
3891 case '=': return '#';
3892 case '/': return '\\';
3893 case '\'': return '^';
3894 case '(': return '[';
3895 case ')': return ']';
3896 case '!': return '|';
3897 case '<': return '{';
3898 case '>': return '}';
3899 case '-': return '~';
3900 }
3901 return '?';
3902}
3903
3904/*@ ----------------------------------------------------------------------------
3905 */
3906
3907static int getNextChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t &pos)
3908{
3909 //printf("getNextChar(%s,%s,%d)\n",qPrint(expr),rest ? rest->data() : 0,pos);
3910 if (pos<expr.length())
3911 {
3912 //printf(" expr()='%c'\n",expr.at(pos));
3913 return expr.at(pos++);
3914 }
3915 else if (rest && !rest->isEmpty())
3916 {
3917 int cc=rest->at(0);
3918 *rest=rest->right(rest->length()-1);
3919 //printf(" rest='%c'\n",cc);
3920 return cc;
3921 }
3922 else
3923 {
3924 int cc=yyinput(yyscanner);
3925 //printf(" yyinput()='%c' %d\n",cc,EOF);
3926 return cc;
3927 }
3928}
3929
3930static int getCurrentChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t pos)
3931{
3932 //printf("getCurrentChar(%s,%s,%d)\n",qPrint(expr),rest ? rest->data() : 0,pos);
3933 if (pos<expr.length())
3934 {
3935 //printf("%c=expr()\n",expr.at(pos));
3936 return expr.at(pos);
3937 }
3938 else if (rest && !rest->isEmpty())
3939 {
3940 int cc=rest->at(0);
3941 //printf("%c=rest\n",cc);
3942 return cc;
3943 }
3944 else
3945 {
3946 int cc=yyinput(yyscanner);
3947 returnCharToStream(yyscanner,(char)cc);
3948 //printf("%c=yyinput()\n",cc);
3949 return cc;
3950 }
3951}
3952
3953static void unputChar(yyscan_t yyscanner,const QCString &expr,QCString *rest,uint32_t &pos,char c)
3954{
3955 //printf("unputChar(%s,%s,%d,%c)\n",qPrint(expr),rest ? rest->data() : 0,pos,c);
3956 if (pos<expr.length())
3957 {
3958 pos++;
3959 }
3960 else if (rest)
3961 {
3962 //printf(" prepending '%c' to rest!\n",c);
3963 char cs[2];cs[0]=c;cs[1]='\0';
3964 rest->prepend(cs);
3965 }
3966 else
3967 {
3968 //printf(" yyunput()='%c'\n",c);
3969 returnCharToStream(yyscanner,c);
3970 }
3971 //printf("result: unputChar(%s,%s,%d,%c)\n",qPrint(expr),rest ? rest->data() : 0,pos,c);
3972}
3973
3974/** Returns a reference to a Define object given its name or 0 if the Define does
3975 * not exist.
3976 */
3977static Define *isDefined(yyscan_t yyscanner,const QCString &name)
3978{
3979 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
3980
3981 bool undef = false;
3982 auto findDefine = [&undef,&name](DefineMap &map)
3983 {
3984 Define *d=nullptr;
3985 auto it = map.find(name.str());
3986 if (it!=map.end())
3987 {
3988 d = &it->second;
3989 if (d->undef)
3990 {
3991 undef=true;
3992 d=nullptr;
3993 }
3994 }
3995 return d;
3996 };
3997
3998 Define *def = findDefine(state->localDefines);
3999 if (def==nullptr && !undef)
4000 {
4001 def = findDefine(state->contextDefines);
4002 }
4003 return def;
4004}
4005
4006static void initPredefined(yyscan_t yyscanner,const QCString &fileName)
4007{
4008 YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
4009
4010 // add predefined macros
4011 const StringVector &predefList = Config_getList(PREDEFINED);
4012 for (const auto &ds : predefList)
4013 {
4014 size_t i_equals=ds.find('=');
4015 size_t i_obrace=ds.find('(');
4016 size_t i_cbrace=ds.find(')');
4017 bool nonRecursive = i_equals!=std::string::npos && i_equals>0 && ds[i_equals-1]==':';
4018
4019 if ((i_obrace==0) || (i_equals==0) || (i_equals==1 && ds[i_equals-1]==':'))
4020 {
4021 continue; // no define name
4022 }
4023
4024 if (i_obrace<i_equals && i_cbrace<i_equals &&
4025 i_obrace!=std::string::npos && i_cbrace!=std::string::npos &&
4026 i_obrace<i_cbrace
4027 ) // predefined function macro definition
4028 {
4029 static const reg::Ex reId(R"(\a\w*)");
4030 std::map<std::string,int> argMap;
4031 std::string args = ds.substr(i_obrace+1,i_cbrace-i_obrace-1); // part between ( and )
4032 bool hasVarArgs = args.find("...")!=std::string::npos;
4033 //printf("predefined function macro '%s'\n",qPrint(ds));
4034 int count = 0;
4035 reg::Iterator arg_it(args,reId,0);
4036 reg::Iterator arg_end;
4037 // gather the formal arguments in a dictionary
4038 for (; arg_it!=arg_end; ++arg_it)
4039 {
4040 argMap.emplace(arg_it->str(),count++);
4041 }
4042 if (hasVarArgs) // add the variable argument if present
4043 {
4044 argMap.emplace("__VA_ARGS__",count++);
4045 }
4046
4047 // strip definition part
4048 std::string definition;
4049 std::string in=ds.substr(i_equals+1);
4050 reg::Iterator re_it(in,reId);
4051 reg::Iterator re_end;
4052 size_t i=0;
4053 // substitute all occurrences of formal arguments by their
4054 // corresponding markers
4055 for (; re_it!=re_end; ++re_it)
4056 {
4057 const auto &match = *re_it;
4058 size_t pi = match.position();
4059 size_t l = match.length();
4060 if (pi>i) definition+=in.substr(i,pi-i);
4061
4062 auto it = argMap.find(match.str());
4063 if (it!=argMap.end())
4064 {
4065 int argIndex = it->second;
4066 QCString marker;
4067 marker.sprintf(" @%d ",argIndex);
4068 definition+=marker.str();
4069 }
4070 else
4071 {
4072 definition+=match.str();
4073 }
4074 i=pi+l;
4075 }
4076 definition+=in.substr(i);
4077
4078 // add define definition to the dictionary of defines for this file
4079 std::string dname = ds.substr(0,i_obrace);
4080 if (!dname.empty())
4081 {
4082 Define def;
4083 def.name = dname;
4084 def.definition = definition;
4085 def.nargs = count;
4086 def.isPredefined = TRUE;
4087 def.nonRecursive = nonRecursive;
4088 def.fileDef = state->yyFileDef;
4089 def.fileName = fileName;
4090 def.varArgs = hasVarArgs;
4091 state->contextDefines.emplace(def.name.str(),def);
4092
4093 //printf("#define '%s' '%s' #nargs=%d hasVarArgs=%d\n",
4094 // qPrint(def.name),qPrint(def.definition),def.nargs,def.varArgs);
4095 }
4096 }
4097 else if (!ds.empty()) // predefined non-function macro definition
4098 {
4099 //printf("predefined normal macro '%s'\n",qPrint(ds));
4100 Define def;
4101 if (i_equals==std::string::npos) // simple define without argument
4102 {
4103 def.name = ds;
4104 def.definition = "1"; // substitute occurrences by 1 (true)
4105 }
4106 else // simple define with argument
4107 {
4108 int ine=static_cast<int>(i_equals) - (nonRecursive ? 1 : 0);
4109 def.name = ds.substr(0,ine);
4110 def.definition = ds.substr(i_equals+1);
4111 }
4112 if (!def.name.isEmpty())
4113 {
4114 def.nargs = -1;
4115 def.isPredefined = TRUE;
4116 def.nonRecursive = nonRecursive;
4117 def.fileDef = state->yyFileDef;
4118 def.fileName = fileName;
4119 state->contextDefines.emplace(def.name.str(),def);
4120 }
4121 }
4122 }
4123}
4124
4125///////////////////////////////////////////////////////////////////////////////////////////////
4126
4128{
4134{
4135 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4136 FileInfo fi(dir.str());
4137 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4138}
4139
4140Preprocessor::Preprocessor() : p(std::make_unique<Private>())
4141{
4142 preYYlex_init_extra(&p->state,&p->yyscanner);
4143 addSearchDir(".");
4144}
4145
4147{
4148 preYYlex_destroy(p->yyscanner);
4149}
4150
4151void Preprocessor::processFile(const QCString &fileName,const std::string &input,std::string &output)
4152{
4153 AUTO_TRACE("fileName={}",fileName);
4154 yyscan_t yyscanner = p->yyscanner;
4155 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4156 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4157
4158#ifdef FLEX_DEBUG
4159 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4160#endif
4161
4162 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4163 //printf("##########################\n%s\n####################\n",
4164 // qPrint(input));
4165
4166 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4167 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4168 state->skip=FALSE;
4169 state->curlyCount=0;
4170 state->lexRulesPart=false;
4171 state->nospaces=FALSE;
4172 state->inputBuf=&input;
4173 state->inputBufPos=0;
4174 state->outputBuf=&output;
4175 state->includeStack.clear();
4176 state->expandedDict.clear();
4177 state->contextDefines.clear();
4178 state->pragmaSet.clear();
4179 while (!state->condStack.empty()) state->condStack.pop();
4180
4181 setFileName(yyscanner,fileName);
4182
4183 state->inputFileDef = state->yyFileDef;
4184 //yyextra->defineManager.startContext(state->fileName);
4185
4186 initPredefined(yyscanner,fileName);
4187
4188 state->yyLineNr = 1;
4189 state->yyColNr = 1;
4190 state->ifcount = 0;
4191
4192 BEGIN( Start );
4193
4194 state->expectGuard = guessSection(fileName).isHeader();
4195 state->guardName.clear();
4196 state->lastGuardName.clear();
4197 state->guardExpr.clear();
4198
4199 preYYlex(yyscanner);
4200
4201 while (!state->condStack.empty())
4202 {
4203 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4204 QCString sectionInfo = " ";
4205 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4206 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4207 "a corresponding \\endcond command within this file.",sectionInfo);
4208 state->condStack.pop();
4209 }
4210 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4211 forceEndCondSection(yyscanner);
4212
4213 if (!state->levelGuard.empty())
4214 {
4215 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4216 }
4217
4219 {
4220 std::lock_guard<std::mutex> lock(g_debugMutex);
4221 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4222 std::string contents;
4224 {
4225 contents=output;
4226 }
4227 else // need to add line numbers
4228 {
4229 int line=1;
4230 bool startOfLine = true;
4231 size_t content_size = output.size() +
4232 output.size()*6/40; // assuming 40 chars per line on average
4233 // and 6 chars extra for the line number
4234 contents.reserve(content_size);
4235 size_t pos=0;
4236 while (pos<output.size())
4237 {
4238 if (startOfLine)
4239 {
4240 char lineNrStr[15];
4241 snprintf(lineNrStr,15,"%05d ",line++);
4242 contents+=lineNrStr;
4243 }
4244 contents += output[pos];
4245 startOfLine = output[pos]=='\n';
4246 pos++;
4247 }
4248 }
4249 char end[2]={0,0};
4250 if (!contents.empty() && contents[contents.length()-1]!='\n')
4251 {
4252 end[0]='\n';
4253 }
4254 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4255 if (yyextra->contextDefines.size()>0)
4256 {
4257 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4258 Debug::print(Debug::Preprocessor,0,"---------\n");
4259 for (auto &kv : yyextra->contextDefines)
4260 {
4261 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4262 }
4263 for (auto &kv : yyextra->localDefines)
4264 {
4265 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4266 }
4267 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4268 }
4269 else
4270 {
4271 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4272 }
4273 }
4274
4275 {
4276 std::lock_guard<std::mutex> lock(g_updateGlobals);
4277 for (const auto &inc : state->includeRelations)
4278 {
4279 auto toKind = [](bool local,bool imported) -> IncludeKind
4280 {
4281 if (local)
4282 {
4283 if (imported)
4284 {
4286 }
4288 }
4289 else if (imported)
4290 {
4292 }
4294 };
4295 if (inc->fromFileDef)
4296 {
4297 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4298 }
4299 if (inc->toFileDef && inc->fromFileDef)
4300 {
4301 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4302 }
4303 }
4304 // add the macro definition for this file to the global map
4305 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4306 }
4307
4308 //yyextra->defineManager.endContext();
4309}
4310
4311#include "pre.l.h"
Copyright (C) 1997-2015 by Dimitri van Heesch.
Definition condparser.h:28
bool parse(const QCString &fileName, int lineNr, const QCString &expr)
Copyright (C) 1997-2015 by Dimitri van Heesch.
@ NoLineNo
Definition debug.h:42
@ Lex_pre
Definition debug.h:64
bool varArgs
Definition define.h:42
QCString args
Definition define.h:36
FileDef * fileDef
Definition define.h:37
static StringUnorderedSet expandAsDefinedSet
Definition doxygen.h:118
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:104
static DefinesPerFileList macroDefinitions
Definition doxygen.h:136
static FileNameLinkedMap * includeNameLinkedMap
Definition doxygen.h:101
Wrapper class for the Entry type.
Definition types.h:813
virtual QCString absFilePath() const =0
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
~Preprocessor()
Definition pre.l:4148
void processFile(const QCString &fileName, const std::string &input, std::string &output)
Definition pre.l:4153
Preprocessor()
Definition pre.l:4142
void addSearchDir(const QCString &dir)
Definition pre.l:4135
std::unique_ptr< Private > p
Definition pre.h:38
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString & prepend(const char *s)
Definition qcstring.h:422
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
bool endsWith(const char *s) const
Definition qcstring.h:524
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:593
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString right(size_t len) const
Definition qcstring.h:234
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:172
void clear()
Definition qcstring.h:182
Class representing a regular expression.
Definition regex.h:39
Class to iterate through matches.
Definition regex.h:230
#define YY_BUF_SIZE
Definition commentcnv.l:19
#define Config_getList(name)
Definition config.h:38
static FILE * findFile(const QCString &fileName)
Definition configimpl.l:941
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
#define AUTO_TRACE(...)
Definition docnode.cpp:46
IncludeKind
Definition filedef.h:47
@ IncludeLocal
Definition filedef.h:50
@ ImportSystemObjC
Definition filedef.h:51
@ ImportLocalObjC
Definition filedef.h:52
@ IncludeSystem
Definition filedef.h:49
#define term(fmt,...)
Definition message.h:137
bool isAbsolutePath(const QCString &fileName)
Definition portable.cpp:498
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:855
static QCString stringize(const QCString &s)
Definition pre.l:2467
static int getCurrentChar(yyscan_t yyscanner, const QCString &expr, QCString *rest, uint32_t pos)
Definition pre.l:3932
static bool expandExpression(yyscan_t yyscanner, QCString &expr, QCString *rest, int pos, int level)
Definition pre.l:3047
#define MAX_EXPANSION_DEPTH
Definition pre.l:3013
static int getNextChar(yyscan_t yyscanner, const QCString &expr, QCString *rest, uint32_t &pos)
Definition pre.l:3909
static QCString removeIdsAndMarkers(const QCString &s)
Definition pre.l:3227
static void initPredefined(yyscan_t yyscanner, const QCString &fileName)
Definition pre.l:4008
static void addSeparatorsIfNeeded(yyscan_t yyscanner, const QCString &expr, QCString &resultExpr, QCString &restExpr, int pos)
Definition pre.l:3015
static int getNextId(const QCString &expr, int p, int *l)
Definition pre.l:2959
static void returnCharToStream(yyscan_t yyscanner, char c)
Definition pre.l:2592
static void addTillEndOfString(yyscan_t yyscanner, const QCString &expr, QCString *rest, uint32_t &pos, char term, QCString &arg)
Definition pre.l:2598
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:3864
static QCString expandVAOpt(const QCString &vaStr, bool hasOptionalArgs)
Definition pre.l:2649
static std::unique_ptr< FileState > checkAndOpenFile(yyscan_t yyscanner, const QCString &fileName, bool &alreadyProcessed)
Definition pre.l:2286
static const char * processUntilMatchingTerminator(const char *inputStr, QCString &result)
Process string or character literal.
Definition pre.l:3191
static void unputChar(yyscan_t yyscanner, const QCString &expr, QCString *rest, uint32_t &pos, char c)
Definition pre.l:3955
static void processConcatOperators(QCString &expr)
Definition pre.l:2545
static QCString removeMarkers(const QCString &s)
Definition pre.l:3422
static bool replaceFunctionMacro(yyscan_t yyscanner, const QCString &expr, QCString *rest, int pos, int &len, const Define *def, QCString &result, int level)
Definition pre.l:2701
static void skipCommentMacroName(yyscan_t yyscanner, const QCString &expr, QCString *rest, int &cc, uint32_t &j, int &len)
Definition pre.l:2617
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75
void addTerminalCharIfMissing(std::string &s, char c)
Definition stringutil.h:84
bool literal_at(const char *data, const char(&str)[N])
returns TRUE iff data points to a substring that matches string literal str
Definition stringutil.h:98
preYY_state state
Definition pre.l:4132
yyscan_t yyscanner
Definition pre.l:4131
bool readInputFile(const QCString &fileName, std::string &contents, bool filter, bool isSourceCode)
read a file name fileName and optionally filter and transcode it
Definition util.cpp:5492
bool patternMatch(const FileInfo &fi, const StringVector &patList)
Definition util.cpp:5646
QCString determineAbsoluteIncludeName(const QCString &curFile, const QCString &incFileName)
Definition util.cpp:3548
EntryType guessSection(const QCString &name)
Definition util.cpp:339
FileDef * findFileDef(const FileNameLinkedMap *fnMap, const QCString &n, bool &ambig)
Definition util.cpp:2844
bool isId(int c)
Definition util.h:207