Doxygen
Loading...
Searching...
No Matches
code.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 */
15%option never-interactive
16%option prefix="codeYY"
17%option reentrant
18%option extra-type="struct codeYY_state *"
19%top{
20#include <stdint.h>
21// forward declare yyscan_t to improve type safety
22#define YY_TYPEDEF_YY_SCANNER_T
23#define yyguts_t codeYYguts_t
24struct yyguts_t;
yyguts_t * yyscan_t
Definition code.l:25
#define yyguts_t
Definition code.l:23
26}
27
28%{
29
30// own header
31#include "code.h"
32
33// standard includes
34#include <algorithm>
35#include <cctype>
36#include <cstdint>
37#include <memory>
38#include <mutex>
39#include <stack>
40#include <string>
41#include <unordered_map>
42#include <unordered_set>
43#include <utility>
44#include <vector>
45
46// other includes
47#include "arguments.h"
48#include "classlist.h"
49#include "conceptdef.h"
50#include "config.h"
51#include "debug.h"
52#include "dir.h"
53#include "doxygen.h"
54#include "entry.h"
55#include "filedef.h"
56#include "filename.h"
57#include "groupdef.h"
58#include "membername.h"
59#include "message.h"
60#include "moduledef.h"
61#include "namespacedef.h"
62#include "outputlist.h"
63#include "scopedtypevariant.h"
64#include "searchindex.h"
65#include "symbolresolver.h"
66#include "tooltip.h"
67#include "util.h"
68
69// Toggle for some debugging info
70//#define DBG_CTX(x) fprintf x
71#define DBG_CTX(x) do { } while(0)
72
73#define YY_NO_UNISTD_H 1
74
75#define CLASSBLOCK 1
76#define SCOPEBLOCK 2
77#define INNERBLOCK 3
78
79// context for an Objective-C method call
93
95{
96 OutputCodeList * code = nullptr;
97
98 std::unordered_map< std::string, ScopedTypeVariant > codeClassMap;
101
104
105 const char * inputString = nullptr; //!< the code fragment as text
106 yy_size_t inputPosition = 0; //!< read offset during parsing
109 int inputLines = 0; //!< number of line in the code fragment
110 int yyLineNr = 0; //!< current line number
111 bool insideCodeLine = false;
112 bool skipCodify = false; //!< for CSharp files scoped namespace {
113
114 bool exampleBlock = false;
117
118 bool insideTemplate = false;
124 std::stack<int> scopeStack; //!< 1 if bracket starts a scope,
125 // 2 for internal blocks
126 int anchorCount = 0;
127 std::unique_ptr<FileDef> exampleFileDef;
128 const FileDef * sourceFileDef = nullptr;
129 bool lineNumbers = false;
130 const Definition * currentDefinition = nullptr;
131 const MemberDef * currentMemberDef = nullptr;
133 const char * currentFontClass = nullptr;
134 bool searchingForBody = false;
135 bool insideBody = false;
140
142 int curlyCount = 0;
143 int sharpCount = 0;
144 bool inFunctionTryBlock = false;
146
156
157 SrcLangExt lang = SrcLangExt::Unknown;
158 bool insideObjC = false;
159 bool insideProtocolList = false;
161
162 bool lexInit = false;
163
164 std::vector<int> scopeNameLengthStack;
165
167 const Definition *searchCtx = nullptr;
168 bool collectXRefs = false;
169
176 std::stack<ObjCCallCtx*> contextStack;
177 std::unordered_map< int,std::unique_ptr<ObjCCallCtx> > contextMap;
178 std::unordered_map< int, DString> nameMap;
179 std::unordered_map< int, DString> objectMap;
180 std::unordered_map< int, DString> wordMap;
181 std::unordered_map< int, DString> commentMap;
183
184 using UsingContext = std::map<std::string,const NamespaceDef*>;
185
191 std::vector<const Definition *> foldStack;
192};
193
194static bool isCastKeyword(const char *s);
195
196//-------------------------------------------------------------------
197[[maybe_unused]] static const char *stateToString(int state);
198
199static void saveObjCContext(yyscan_t yyscanner);
200static void restoreObjCContext(yyscan_t yyscanner);
201static void pushScope(yyscan_t yyscanner,const DString &s);
202static void popScope(yyscan_t yyscanner);
203static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor);
204static void addToSearchIndex(yyscan_t yyscanner,const DString &text);
205static void setClassScope(yyscan_t yyscanner,const DString &name);
206static void startCodeLine(yyscan_t yyscanner);
207static void endCodeLine(yyscan_t yyscanner);
208static void nextCodeLine(yyscan_t yyscanner);
209static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment=false);
210static void endFontClass(yyscan_t yyscanner,bool specialComment=false);
211static void codifyLines(yyscan_t yyscanner,const DString &text);
212static void incrementFlowKeyWordCount(yyscan_t yyscanner);
213static void writeMultiLineCodeLink(yyscan_t yyscanner,OutputCodeList &ol,
214 const Definition *d,
215 const DString &text);
216static void addType(yyscan_t yyscanner);
217static void addParmType(yyscan_t yyscanner);
218static void addUsingDirective(yyscan_t yyscanner,const DString &name);
219static void setParameterList(yyscan_t yyscanner,const MemberDef *md);
220static const ClassDef *stripClassName(yyscan_t yyscanner,const DString &s,const Definition *d);
221static const MemberDef *setCallContextForVar(yyscan_t yyscanner,const DString &name);
222static void updateCallContextForSmartPointer(yyscan_t yyscanner);
223static bool getLinkInScope(yyscan_t yyscanner,const DString &c, // scope
224 const DString &m, // member
225 const DString &memberText, // exact text
226 OutputCodeList &ol,
227 const DString &text,
228 bool varOnly=false
229 );
230static bool getLink(yyscan_t yyscanner,const DString &className,
231 const DString &memberName,
232 OutputCodeList &ol,
233 const DString &text=DString(),
234 bool varOnly=false);
235static void generateClassOrGlobalLink(yyscan_t yyscanner,OutputCodeList &ol,const DString &clName,
236 bool typeOnly=false,bool varOnly=false);
237static bool generateClassMemberLink(yyscan_t yyscanner,OutputCodeList &ol,const MemberDef *xmd,const DString &memName);
238static bool generateClassMemberLink(yyscan_t yyscanner,OutputCodeList &ol,const Definition *def,const DString &memName);
239static void generateMemberLink(yyscan_t yyscanner,OutputCodeList &ol,const DString &varName,
240 const DString &memName);
241static void generatePHPVariableLink(yyscan_t yyscanner,OutputCodeList &ol,const char *varName);
242static void generateFunctionLink(yyscan_t yyscanner,OutputCodeList &ol,const DString &funcName);
243static int countLines(yyscan_t yyscanner);
244static void writeObjCMethodCall(yyscan_t yyscanner,ObjCCallCtx *ctx);
245static DString escapeName(yyscan_t yyscanner,const DString &s);
246static DString escapeObject(yyscan_t yyscanner,const DString &s);
247static DString escapeWord(yyscan_t yyscanner,const DString &s);
248static DString escapeComment(yyscan_t yyscanner,const DString &s);
249static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *kw);
250static int yyread(yyscan_t yyscanner,char *buf,int max_size);
251static void addVariable(yyscan_t yyscanner,DString type,DString name);
252static bool startsWithKeyword(const DString &str,const DString &kw);
253static void endCodeFold(yyscan_t yyscanner);
254
255/* -----------------------------------------------------------------
256 */
257#undef YY_INPUT
258#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
259
260// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
261static inline const char *getLexerFILE() {return __FILE__;}
262#include "doxygen_lex.h"
263
Represents the call context.
A abstract class representing of a compound symbol.
Definition classdef.h:100
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
The common base class of all entity definitions found in the sources.
Definition definition.h:77
A model of a file symbol.
Definition filedef.h:97
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
Class representing a list of different code generators.
Definition outputlist.h:162
Text streaming class that buffers data.
Definition textstream.h:36
Class that manages the tooltips for a source file.
Definition tooltip.h:27
static bool isCastKeyword(const char *s)
Definition code.l:3974
static void generateClassOrGlobalLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &clName, bool typeOnly=false, bool varOnly=false)
Definition code.l:2917
static bool getLinkInScope(yyscan_t yyscanner, const DString &c, const DString &m, const DString &memberText, OutputCodeList &ol, const DString &text, bool varOnly=false)
Definition code.l:2808
static void endCodeLine(yyscan_t yyscanner)
Definition code.l:2488
static bool skipLanguageSpecificKeyword(yyscan_t yyscanner, const char *kw)
Definition code.l:3933
static void pushScope(yyscan_t yyscanner, const DString &s)
Definition code.l:2253
static bool getLink(yyscan_t yyscanner, const DString &className, const DString &memberName, OutputCodeList &ol, const DString &text=DString(), bool varOnly=false)
Definition code.l:2892
static DString escapeComment(yyscan_t yyscanner, const DString &s)
Definition code.l:3923
static void restoreObjCContext(yyscan_t yyscanner)
Definition code.l:4030
static void nextCodeLine(yyscan_t yyscanner)
Definition code.l:2497
static void setClassScope(yyscan_t yyscanner, const DString &name)
Definition code.l:2311
static void popScope(yyscan_t yyscanner)
Definition code.l:2271
static DString escapeName(yyscan_t yyscanner, const DString &s)
Definition code.l:3893
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2419
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
Definition code.l:2287
static void incrementFlowKeyWordCount(yyscan_t yyscanner)
Definition code.l:2542
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition code.l:3983
static int countLines(yyscan_t yyscanner)
Definition code.l:3474
static const char * stateToString(int state)
static void addParmType(yyscan_t yyscanner)
Definition code.l:2610
static void updateCallContextForSmartPointer(yyscan_t yyscanner)
Definition code.l:2791
static DString escapeWord(yyscan_t yyscanner, const DString &s)
Definition code.l:3913
static const MemberDef * setCallContextForVar(yyscan_t yyscanner, const DString &name)
Definition code.l:2681
static void generateFunctionLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &funcName)
Definition code.l:3356
static void addToSearchIndex(yyscan_t yyscanner, const DString &text)
Definition code.l:2303
static void addVariable(yyscan_t yyscanner, DString type, DString name)
Definition code.l:2188
static void addUsingDirective(yyscan_t yyscanner, const DString &name)
Definition code.l:2619
static void generateMemberLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &varName, const DString &memName)
Definition code.l:3251
static void codifyLines(yyscan_t yyscanner, const DString &text)
Definition code.l:2515
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
Definition code.l:3507
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
Definition code.l:3492
static void writeMultiLineCodeLink(yyscan_t yyscanner, OutputCodeList &ol, const Definition *d, const DString &text)
Definition code.l:2560
static const char * getLexerFILE()
Definition code.l:261
static bool startsWithKeyword(const DString &str, const DString &kw)
Definition code.l:2181
static const ClassDef * stripClassName(yyscan_t yyscanner, const DString &s, const Definition *d)
Definition code.l:2650
static void setParameterList(yyscan_t yyscanner, const MemberDef *md)
Definition code.l:2633
static void addType(yyscan_t yyscanner)
Definition code.l:2598
static DString escapeObject(yyscan_t yyscanner, const DString &s)
Definition code.l:3903
static void saveObjCContext(yyscan_t yyscanner)
Definition code.l:3999
static void writeObjCMethodCall(yyscan_t yyscanner, ObjCCallCtx *ctx)
Definition code.l:3523
static void endCodeFold(yyscan_t yyscanner)
Definition code.l:2340
static void generatePHPVariableLink(yyscan_t yyscanner, OutputCodeList &ol, const char *varName)
Definition code.l:3344
static bool generateClassMemberLink(yyscan_t yyscanner, OutputCodeList &ol, const MemberDef *xmd, const DString &memName)
Definition code.l:3146
std::vector< std::string > StringVector
Definition containers.h:33
Web server based search engine.
const MemberDef * method
Definition code.l:88
DString methodName
Definition code.l:83
int braceCount
Definition code.l:91
int lexState
Definition code.l:90
TextStream comment
Definition code.l:85
const MemberDef * objectVar
Definition code.l:87
DString objectTypeOrName
Definition code.l:84
const ClassDef * objectType
Definition code.l:86
DString format
Definition code.l:89
int memCallContext
Definition code.l:153
std::unordered_map< int, DString > nameMap
Definition code.l:178
StringVector curClassBases
Definition code.l:100
bool lineNumbers
Definition code.l:129
int bodyCurlyCount
Definition code.l:136
CallContext theCallContext
Definition code.l:188
int lastCContext
Definition code.l:154
bool includeCodeFragment
Definition code.l:132
bool insideTemplate
Definition code.l:118
const Definition * currentDefinition
Definition code.l:130
DString delimiter
Definition code.l:139
std::unique_ptr< FileDef > exampleFileDef
Definition code.l:127
int lastSpecialCContext
Definition code.l:148
DString absFileName
Definition code.l:108
DString saveName
Definition code.l:137
DString scopeName
Definition code.l:122
bool inFunctionTryBlock
Definition code.l:144
int braceCount
Definition code.l:182
DString parmType
Definition code.l:102
bool collectXRefs
Definition code.l:168
const char * currentFontClass
Definition code.l:133
bool insideBody
Definition code.l:135
std::stack< int > scopeStack
1 if bracket starts a scope,
Definition code.l:124
const FileDef * sourceFileDef
Definition code.l:128
ObjCCallCtx * currentCtx
Definition code.l:170
bool exampleBlock
Definition code.l:114
std::unordered_map< int, std::unique_ptr< ObjCCallCtx > > contextMap
Definition code.l:177
bool inForEachExpression
Definition code.l:145
DString realScope
Definition code.l:123
VariableContext theVarContext
Definition code.l:186
std::unordered_map< int, DString > wordMap
Definition code.l:180
bool lexInit
Definition code.l:162
int bracketCount
Definition code.l:141
DString type
Definition code.l:119
int anchorCount
Definition code.l:126
DString parmName
Definition code.l:103
int lastSkipCppContext
Definition code.l:150
int curlyCount
Definition code.l:142
TooltipManager tooltipManager
Definition code.l:190
std::vector< int > scopeNameLengthStack
Definition code.l:164
DString name
Definition code.l:120
int currentCommentId
Definition code.l:175
int sharpCount
Definition code.l:143
DString exampleName
Definition code.l:115
std::map< std::string, const NamespaceDef * > UsingContext
Definition code.l:184
bool insideCodeLine
Definition code.l:111
DString curClassName
Definition code.l:99
const char * inputString
the code fragment as text
Definition code.l:105
const Definition * searchCtx
Definition code.l:167
std::unordered_map< int, DString > commentMap
Definition code.l:181
DString exampleFile
Definition code.l:116
int isPrefixedWithThis
Definition code.l:166
bool searchingForBody
Definition code.l:134
int lastTemplCastContext
Definition code.l:147
SrcLangExt lang
Definition code.l:157
SymbolResolver symbolResolver
Definition code.l:189
int currentObjId
Definition code.l:173
int currentWordId
Definition code.l:174
int lastObjCCallContext
Definition code.l:152
yy_size_t inputPosition
read offset during parsing
Definition code.l:106
bool insideObjC
Definition code.l:158
bool insideSpecialComment
Definition code.l:160
int lastStringContext
Definition code.l:149
std::unordered_map< int, DString > objectMap
Definition code.l:179
int yyLineNr
current line number
Definition code.l:110
int currentCtxId
Definition code.l:171
std::vector< const Definition * > foldStack
Definition code.l:191
DString fileName
Definition code.l:107
bool insideProtocolList
Definition code.l:159
OutputCodeList * code
Definition code.l:96
int lastVerbStringContext
Definition code.l:151
int inputLines
number of line in the code fragment
Definition code.l:109
const MemberDef * currentMemberDef
Definition code.l:131
std::unordered_map< std::string, ScopedTypeVariant > codeClassMap
Definition code.l:98
UsingContext theUsingContext
Definition code.l:187
bool skipCodify
for CSharp files scoped namespace {
Definition code.l:112
int currentNameId
Definition code.l:172
std::stack< ObjCCallCtx * > contextStack
Definition code.l:176
int skipInlineInitContext
Definition code.l:155
DString args
Definition code.l:121
DString saveType
Definition code.l:138
SrcLangExt
Definition types.h:207
A bunch of utility functions.
264%}
265
266B [ \t]
267Bopt {B}*
268BN [ \t\n\r]
269ID [$a-z_A-Z\x80-\xFF][$a-z_A-Z0-9\x80-\xFF]*
270SEP ("::"|"\\")
271SCOPENAME ("::"{BN}*)?({ID}{BN}*{SEP}{BN}*)*("~"{BN}*)?{ID}
272TEMPLIST "<"[^\"\}\{\‍(\‍)\/\n>]*">"
273SCOPETNAME (((({ID}{TEMPLIST}?){BN}*)?{SEP}{BN}*)*)((~{BN}*)?{ID})
274SCOPEPREFIX ({ID}{TEMPLIST}?{BN}*{SEP}{BN}*)+
275KEYWORD_OBJC ("@public"|"@private"|"@protected"|"@class"|"@implementation"|"@interface"|"@end"|"@selector"|"@protocol"|"@optional"|"@required"|"@throw"|"@synthesize"|"@property")
276 /* please also pay attention to skipLanguageSpecificKeyword when changing the list of keywords. */
277KEYWORD ("asm"|"__assume"|"auto"|"class"|"const"|"delete"|"enum"|"explicit"|"extern"|"false"|"friend"|"gcnew"|"gcroot"|"set"|"get"|"inline"|"internal"|"mutable"|"namespace"|"new"|"null"|"nullptr"|"override"|"operator"|"pin_ptr"|"private"|"protected"|"public"|"raise"|"record"|"register"|"remove"|"self"|"sizeof"|"static"|"struct"|"__super"|"function"|"template"|"generic"|"this"|"true"|"typedef"|"typeid"|"typename"|"union"|"using"|"virtual"|"volatile"|"abstract"|"sealed"|"final"|"import"|"synchronized"|"transient"|"alignas"|"alignof"|"concept"|"requires"|"decltype"|{KEYWORD_OBJC}|"constexpr"|"consteval"|"constinit"|"co_await"|"co_return"|"co_yield"|"static_assert"|"_Static_assert"|"noexcept"|"thread_local"|"enum"{B}+("class"|"struct"))
278FLOWKW ("break"|"catch"|"continue"|"default"|"do"|"else"|"finally"|"return"|"switch"|"throw"|"throws"|"@catch"|"@finally")
279FLOWCONDITION ("case"|"for"|"foreach"|"for each"|"goto"|"if"|"try"|"while"|"@try")
280TYPEKW ("bool"|"byte"|"char"|"char8_t"|"char16_t"|"char32_t"|"double"|"float"|"int"|"long"|"object"|"short"|"signed"|"unsigned"|"void"|"wchar_t"|"size_t"|"boolean"|"id"|"SEL"|"string"|"nullptr")
281TYPEKWSL ("LocalObject"|"Object"|"Value")
282CASTKW ("const_cast"|"dynamic_cast"|"reinterpret_cast"|"static_cast")
283CHARLIT (("'"\\‍[0-7]{1,3}"'")|("'"\\."'")|("'"[^' \\\n]{1,4}"'"))
284ARITHOP "+"|"-"|"/"|"*"|"%"|"--"|"++"
285ASSIGNOP "="|"*="|"/="|"%="|"+="|"-="|"<<="|">>="|"&="|"^="|"|="
286LOGICOP "=="|"!="|">"|"<"|">="|"<="|"&&"|"||"|"!"|"<=>"
287BITOP "&"|"|"|"^"|"<<"|">>"|"~"
288OPERATOR {ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}
289RAWBEGIN (u|U|L|u8)?R\"[^ \t\‍(\‍)\\‍]{0,16}"("
290RAWEND ")"[^ \t\‍(\‍)\\‍]{0,16}\"
291MODULE_ID ({ID}".")*{ID}
292
293 /* no comment start / end signs inside square brackets */
294NCOMM [^/\*]
295 //- start: NUMBER -------------------------------------------------------------------------
296 // Note same defines in commentcnv.l: keep in sync
297DECIMAL_INTEGER [1-9][0-9']*[0-9]?[uU]?[lL]?[lL]?
298HEXADECIMAL_INTEGER "0"[xX][0-9a-zA-Z']+[0-9a-zA-Z]?
299OCTAL_INTEGER "0"[0-7][0-7']+[0-7]?
300BINARY_INTEGER "0"[bB][01][01']*[01]?
301INTEGER_NUMBER {DECIMAL_INTEGER}|{HEXADECIMAL_INTEGER}|{OCTAL_INTEGER}|{BINARY_INTEGER}
302
303FP_SUF [fFlL]
304
305DIGIT_SEQ [0-9][0-9']*[0-9]?
306FRAC_CONST {DIGIT_SEQ}"."|{DIGIT_SEQ}?"."{DIGIT_SEQ}
307FP_EXP [eE][+-]?{DIGIT_SEQ}
308DEC_FP1 {FRAC_CONST}{FP_EXP}?{FP_SUF}?
309DEC_FP2 {DIGIT_SEQ}{FP_EXP}{FP_SUF}
310
311HEX_DIGIT_SEQ [0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]?
312HEX_FRAC_CONST {HEX_DIGIT_SEQ}"."|{HEX_DIGIT_SEQ}?"."{HEX_DIGIT_SEQ}
313BIN_EXP [pP][+-]?{DIGIT_SEQ}
314HEX_FP1 "0"[xX]{HEX_FRAC_CONST}{BIN_EXP}{FP_SUF}?
315HEX_FP2 "0"[xX]{HEX_DIGIT_SEQ}{BIN_EXP}{FP_SUF}?
316
317FLOAT_DECIMAL {DEC_FP1}|{DEC_FP2}
318FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
319FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
320NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
321 //- end: NUMBER ---------------------------------------------------------------------------
322
323 // C start comment
324CCS "/\*"
325 // C end comment
326CCE "*\/"
327 // Cpp comment
328CPPC "/\/"
329
330 // ENDIDopt
331ENDIDopt ("::"{ID})*
332 // Optional end qualifiers
333ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"sealed"|"override"))*
334
335%option noyywrap
336
337%x SkipString
338%x SkipStringS
339%x SkipVerbString
340%x SkipCPP
341%x SkipComment
342%x SkipCxxComment
343%x Body
344%x BodyVar
345%x FuncCall
346%x MemberCall
347%x MemberCall2
348%x SkipInits
349%x ClassName
350%x AlignAs
351%x AlignAsEnd
352%x PackageName
353%x ClassVar
354%x CppCliTypeModifierFollowup
355%x Bases
356%x SkipSharp
357%x ReadInclude
358%x TemplDecl
359%x TemplCast
360%x CallEnd
361%x ObjCMethod
362%x ObjCParams
363%x ObjCParamType
364%x ObjCCall
365%x ObjCMName
366%x ObjCSkipStr
367%x ObjCCallComment
368%x OldStyleArgs
369%x ConceptName
370%x UsingName
371%x RawString
372%x InlineInit
373%x ModuleName
374%x ModuleImport
375
377
378<*>\x0d
379<Body>^([ \t]*"#"[ \t]*("include"|"import")[ \t]*)("<"|"\"") {
380 startFontClass(yyscanner,"preprocessor");
381 yyextra->code->codify(yytext);
382 BEGIN( ReadInclude );
383 }
384<Body>("@interface"|"@implementation"|"@protocol")[ \t\n]+ {
385 yyextra->insideObjC=true;
386 startFontClass(yyscanner,"keyword");
387 codifyLines(yyscanner,yytext);
388 endFontClass(yyscanner);
389 if (!yyextra->insideTemplate)
390 BEGIN( ClassName );
391 }
392<Body>(("public"|"private"){B}+)?("ref"|"value"|"interface"|"enum"){B}+("class"|"struct") {
393 if (yyextra->insideTemplate) REJECT;
394 startFontClass(yyscanner,"keyword");
395 codifyLines(yyscanner,yytext);
396 endFontClass(yyscanner);
397 BEGIN( ClassName );
398 }
399<Body>"property"|"event"/{BN}* {
400 if (yyextra->insideTemplate) REJECT;
401 startFontClass(yyscanner,"keyword");
402 codifyLines(yyscanner,yytext);
403 endFontClass(yyscanner);
404 }
405<Body>("partial"{B}+)?("class"|"struct"|"union"|"record"|"namespace"|"interface"){B}+ {
406 startFontClass(yyscanner,"keyword");
407 codifyLines(yyscanner,yytext);
408 endFontClass(yyscanner);
409 if (!yyextra->insideTemplate)
410 BEGIN( ClassName );
411 }
412<Body>("package")[ \t\n]+ {
413 startFontClass(yyscanner,"keyword");
414 codifyLines(yyscanner,yytext);
415 endFontClass(yyscanner);
416 BEGIN( PackageName );
417 }
418<ClassVar>\n {
419 if (!yyextra->insideObjC) REJECT;
420 codifyLines(yyscanner,yytext);
421 BEGIN(Body);
422 }
423<Body,ClassVar,Bases>"-"|"+" {
424 if (!yyextra->insideObjC || yyextra->insideBody)
425 {
426 yyextra->code->codify(yytext);
427 }
428 else // Start of Objective-C method
429 {
430 DBG_CTX((stderr,"Start of Objective-C method!\n"));
431 yyextra->code->codify(yytext);
432 BEGIN(ObjCMethod);
433 }
434 }
#define DBG_CTX(x)
Definition code.l:71
435<ObjCMethod>":" {
436 yyextra->code->codify(yytext);
437 BEGIN(ObjCParams);
438 }
439<ObjCParams>"(" {
440 yyextra->code->codify(yytext);
441 BEGIN(ObjCParamType);
442 }
443<ObjCParams,ObjCMethod>";"|"{" {
444 yyextra->code->codify(yytext);
445 if (*yytext=='{')
446 {
447 if (yyextra->searchingForBody)
448 {
449 yyextra->searchingForBody=false;
450 yyextra->insideBody=true;
451 }
452 if (yyextra->insideBody) yyextra->bodyCurlyCount++;
453 if (!yyextra->curClassName.empty()) // valid class name
454 {
455 pushScope(yyscanner,yyextra->curClassName);
456 DBG_CTX((stderr,"** scope stack push SCOPEBLOCK\n"));
457 yyextra->scopeStack.push(SCOPEBLOCK);
458 }
459 }
460 yyextra->type.clear();
461 yyextra->name.clear();
462 BEGIN(Body);
463 }
#define SCOPEBLOCK
Definition code.l:76
464<ObjCParams>{ID}{B}*":" {
465 yyextra->code->codify(yytext);
466 }
467<ObjCParamType>{TYPEKW} {
468 startFontClass(yyscanner,"keywordtype");
469 yyextra->code->codify(yytext);
470 endFontClass(yyscanner);
471 yyextra->parmType=yytext;
472 }
473<ObjCParamType>{ID} {
474 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
475 yyextra->parmType=yytext;
476 }
477<ObjCParamType>")" {
478 yyextra->code->codify(yytext);
479 BEGIN(ObjCParams);
480 }
481<ObjCParams>{ID} {
482 yyextra->code->codify(yytext);
483 yyextra->parmName=yytext;
484 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
485 yyextra->parmType.clear();yyextra->parmName.clear();
486 }
487<ObjCMethod,ObjCParams,ObjCParamType>{ID} {
488 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
489 }
490<ObjCMethod,ObjCParams,ObjCParamType>. {
491 yyextra->code->codify(yytext);
492 }
493<ObjCMethod,ObjCParams,ObjCParamType>\n {
494 codifyLines(yyscanner,yytext);
495 }
496<ReadInclude>[^\n\">]+/(">"|"\"") {
497 //FileInfo *f;
498 bool found = false;
499 bool ambig = false;
500 DString absIncFileName = determineAbsoluteIncludeName(yyextra->absFileName,yytext);
501 const FileDef *fd=Doxygen::inputNameLinkedMap->findFileDef(absIncFileName,ambig);
502 //printf("looking for include %s -> %s fd=%p\n",yytext,qPrint(absPath),fd);
503 if (fd && fd->isLinkable())
504 {
505 if (ambig) // multiple input files match the name
506 {
507 DBG_CTX((stderr,"===== yes %s is ambiguous\n",yytext));
509 if (!name.empty() && yyextra->sourceFileDef)
510 {
511 const FileName *fn = Doxygen::inputNameLinkedMap->find(name);
512 if (fn)
513 {
514 // see if this source file actually includes the file
515 auto it = std::find_if(fn->begin(),
516 fn->end(),
517 [&sfd=yyextra->sourceFileDef]
518 (const auto &lfd)
519 { return sfd->isIncluded(lfd->absFilePath()); });
520 found = it!=fn->end();
521 }
522 }
523 }
524 else // not ambiguous
525 {
526 found = true;
527 }
528 }
529 DBG_CTX((stderr," include file %s found=%d\n",fd ? qPrint(fd->absFilePath()) : "<none>",found));
530 if (found)
531 {
532 writeMultiLineCodeLink(yyscanner,*yyextra->code,fd,yytext);
533 }
534 else
535 {
536 yyextra->code->codify(yytext);
537 }
538 char c=(char)yyinput(yyscanner);
539 DString text;
540 text+=c;
541 yyextra->code->codify(text);
542 endFontClass(yyscanner);
543 BEGIN( Body );
544 }
virtual bool isLinkable() const =0
static std::string cleanDirPath(const std::string &path)
Definition dir.cpp:362
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
virtual DString absFilePath() const =0
Class representing all files with a certain base name.
Definition filename.h:31
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Definition filename.cpp:38
const T * find(const std::string &key) const
Definition linkedmap.h:47
const char * qPrint(const char *s)
Definition dstring.h:783
const char * name(int level)
Definition latexgen.h:368
DString determineAbsoluteIncludeName(const DString &curFile, const DString &incFileName)
Definition util.cpp:3061
545<Body,Bases>^[ \t]*"#" {
546 startFontClass(yyscanner,"preprocessor");
547 yyextra->lastSkipCppContext = YY_START;
548 yyextra->code->codify(yytext);
549 BEGIN( SkipCPP ) ;
550 }
551<SkipCPP>\" {
552 yyextra->code->codify(yytext);
553 yyextra->lastStringContext=YY_START;
554 BEGIN( SkipString ) ;
555 }
556<SkipCPP>. {
557 yyextra->code->codify(yytext);
558 }
559<SkipCPP>[^\n\/\\\"]+ {
560 yyextra->code->codify(yytext);
561 }
562<SkipCPP>\\‍[\r]?\n {
563 codifyLines(yyscanner,yytext);
564 }
565<SkipCPP>{CPPC}/[^/!] {
566 REJECT;
567 }
568<Body,FuncCall,MemberCall,MemberCall2>"}" {
569 yyextra->theVarContext.popScope();
570 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
571 yyextra->type.clear();
572 yyextra->name.clear();
573
574 if (!yyextra->scopeStack.empty())
575 {
576 int scope = yyextra->scopeStack.top();
577 yyextra->scopeStack.pop();
578 DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK));
579 if (scope==SCOPEBLOCK || scope==CLASSBLOCK)
580 {
581 popScope(yyscanner);
582 }
583 }
584
585 yyextra->code->codify(yytext);
586
587 DBG_CTX((stderr,"yyextra->bodyCurlyCount=%d\n",yyextra->bodyCurlyCount));
588 if (--yyextra->bodyCurlyCount<=0)
589 {
590 yyextra->insideBody=false;
591 yyextra->currentMemberDef=nullptr;
592 if (yyextra->currentDefinition)
593 yyextra->currentDefinition=yyextra->currentDefinition->getOuterScope();
594 }
595 BEGIN(Body);
596 }
#define CLASSBLOCK
Definition code.l:75
597<Body,ClassVar>"@end" {
598 DBG_CTX((stderr,"End of objc scope fd=%s\n",qPrint(yyextra->sourceFileDef->name())));
599 if (yyextra->sourceFileDef)
600 {
601 const FileDef *fd=yyextra->sourceFileDef;
602 yyextra->insideObjC = fd->name().lower().endsWith(".m") ||
603 fd->name().lower().endsWith(".mm");
604 DBG_CTX((stderr,"insideObjC=%d\n",yyextra->insideObjC));
605 }
606 else
607 {
608 yyextra->insideObjC = false;
609 }
610 if (yyextra->insideBody)
611 {
612 yyextra->theVarContext.popScope();
613
614 if (!yyextra->scopeStack.empty())
615 {
616 int scope = yyextra->scopeStack.top();
617 yyextra->scopeStack.pop();
618 DBG_CTX((stderr,"** scope stack pop SCOPEBLOCK=%d\n",scope==SCOPEBLOCK));
619 if (scope==SCOPEBLOCK || scope==CLASSBLOCK)
620 {
621 popScope(yyscanner);
622 }
623 }
624 yyextra->insideBody=false;
625 }
626
627 startFontClass(yyscanner,"keyword");
628 yyextra->code->codify(yytext);
629 endFontClass(yyscanner);
630
631 yyextra->currentMemberDef=nullptr;
632 if (yyextra->currentDefinition)
633 yyextra->currentDefinition=yyextra->currentDefinition->getOuterScope();
634 BEGIN(Body);
635 }
DString lower() const
Definition dstring.h:326
bool endsWith(const char *s) const
Definition dstring.h:617
virtual const DString & name() const =0
636<ClassName,ClassVar>";" {
637 if (yyextra->lang==SrcLangExt::CSharp)
638 {
639 yyextra->code->codify(yytext);
640 yyextra->skipCodify = true;
641 unput('{');
642 }
643 else
644 {
645 yyextra->code->codify(yytext);
646 yyextra->searchingForBody=false;
647 BEGIN( Body );
648 }
649 }
650<ClassName,ClassVar>[*&^%]+ {
651 yyextra->type=yyextra->curClassName;
652 yyextra->name.clear();
653 yyextra->code->codify(yytext);
654 BEGIN( Body ); // variable of type struct *
655 }
656<ClassName>"__declspec"{B}*"("{B}*{ID}{B}*")" {
657 startFontClass(yyscanner,"keyword");
658 yyextra->code->codify(yytext);
659 endFontClass(yyscanner);
660 }
661<ClassName>{ID}("."{ID})* |
662<ClassName>{ID}("::"{ID})* {
663 if (yyextra->lang==SrcLangExt::CSharp)
664 yyextra->curClassName=substitute(yytext,".","::");
665 else
666 yyextra->curClassName=yytext;
667 addType(yyscanner);
668 if (yyextra->curClassName=="alignas")
669 {
670 startFontClass(yyscanner,"keyword");
671 yyextra->code->codify(yytext);
672 endFontClass(yyscanner);
673 BEGIN( AlignAs );
674 }
675 else
676 {
677 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
678 BEGIN( ClassVar );
679 }
680 }
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
681<AlignAs>"(" {
682 yyextra->bracketCount=1;
683 yyextra->code->codify(yytext);
684 BEGIN( AlignAsEnd );
685 }
686<AlignAs>\n { yyextra->yyLineNr++;
687 codifyLines(yyscanner,yytext);
688 }
689<AlignAs>. { yyextra->code->codify(yytext); }
690<AlignAsEnd>"(" { yyextra->code->codify(yytext);
691 yyextra->bracketCount++;
692 }
693<AlignAsEnd>")" {
694 yyextra->code->codify(yytext);
695 if (--yyextra->bracketCount<=0)
696 {
697 BEGIN(ClassName);
698 }
699 }
700<AlignAsEnd>\n { yyextra->yyLineNr++;
701 codifyLines(yyscanner,yytext);
702 }
703<AlignAsEnd>. { yyextra->code->codify(yytext); }
704<ClassName>{ID}("\\"{ID})* { // PHP namespace
705 yyextra->curClassName=substitute(yytext,"\\","::");
706 yyextra->scopeStack.push(CLASSBLOCK);
707 pushScope(yyscanner,yyextra->curClassName);
708 addType(yyscanner);
709 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
710 BEGIN( ClassVar );
711 }
712<ClassName>{ID}{B}*"("{ID}")" { // Obj-C category
713 yyextra->curClassName=removeRedundantWhiteSpace(yytext);
714 yyextra->scopeStack.push(CLASSBLOCK);
715 pushScope(yyscanner,yyextra->curClassName);
716 addType(yyscanner);
717 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
718 BEGIN( ClassVar );
719 }
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
720<PackageName>{ID}("."{ID})* {
721 yyextra->curClassName=substitute(yytext,".","::");
722 DBG_CTX((stderr,"found package: %s\n",qPrint(yyextra->curClassName)));
723 addType(yyscanner);
724 codifyLines(yyscanner,yytext);
725 }
726<ClassVar>"=" {
727 unput(*yytext);
728 BEGIN( Body );
729 }
730<ClassVar>("extends"|"implements") { // Java, Slice
731 startFontClass(yyscanner,"keyword");
732 codifyLines(yyscanner,yytext);
733 endFontClass(yyscanner);
734 yyextra->curClassBases.clear();
735 BEGIN( Bases );
736 }
737<ClassVar>("sealed"|"abstract")/{BN}*(":"|"{") {
738 DBG_CTX((stderr,"***** C++/CLI modifier %s on yyextra->curClassName=%s\n",yytext,qPrint(yyextra->curClassName)));
739 startFontClass(yyscanner,"keyword");
740 codifyLines(yyscanner,yytext);
741 endFontClass(yyscanner);
742 BEGIN( CppCliTypeModifierFollowup );
743 }
744<ClassVar>{ID} {
745 yyextra->type = yyextra->curClassName;
746 yyextra->name = yytext;
747 if (yyextra->insideBody)
748 {
749 addVariable(yyscanner,yyextra->type,yyextra->name);
750 }
751 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
752 }
753<ClassName,ClassVar,CppCliTypeModifierFollowup>{B}*":"{B}* {
754 codifyLines(yyscanner,yytext);
755 yyextra->curClassBases.clear();
756 BEGIN( Bases );
757 }
758<PackageName>[ \t]*";" |
759<Bases>^{Bopt}/"@"{ID} | // Objective-C interface
760<Bases,ClassName,ClassVar,CppCliTypeModifierFollowup>{B}*"{"{B}* {
761 yyextra->theVarContext.pushScope();
762 if (!yyextra->skipCodify) yyextra->code->codify(yytext);
763 yyextra->skipCodify = false;
764 if (YY_START==ClassVar && yyextra->curClassName.empty())
765 {
766 yyextra->curClassName = yyextra->name;
767 }
768 if (yyextra->searchingForBody)
769 {
770 yyextra->searchingForBody=false;
771 yyextra->insideBody=true;
772 }
773 if (yyextra->insideBody) yyextra->bodyCurlyCount++;
774 if (!yyextra->curClassName.empty()) // valid class name
775 {
776 DBG_CTX((stderr,"** scope stack push CLASSBLOCK\n"));
777 yyextra->scopeStack.push(CLASSBLOCK);
778 pushScope(yyscanner,yyextra->curClassName);
779 DBG_CTX((stderr,"***** yyextra->curClassName=%s\n",qPrint(yyextra->curClassName)));
780 if (yyextra->symbolResolver.resolveClass(yyextra->currentDefinition,yyextra->curClassName,true)==nullptr)
781 {
782 DBG_CTX((stderr,"Adding new class %s\n",qPrint(yyextra->curClassName)));
783 ScopedTypeVariant var(yyextra->curClassName);
784 // insert base classes.
785 for (const auto &s : yyextra->curClassBases)
786 {
787 const ClassDef *bcd=nullptr;
788 auto it = yyextra->codeClassMap.find(s);
789 if (it!=yyextra->codeClassMap.end())
790 {
791 bcd = toClassDef(it->second.globalDef());
792 }
793 if (bcd==nullptr) bcd=yyextra->symbolResolver.resolveClass(yyextra->currentDefinition,s,true);
794 if (bcd && bcd->name()!=yyextra->curClassName)
795 {
796 var.localDef()->insertBaseClass(bcd->name());
797 }
798 }
799 yyextra->codeClassMap.emplace(yyextra->curClassName.str(),std::move(var));
800 }
801 //printf("yyextra->codeClassList.count()=%d\n",yyextra->codeClassList.count());
802 }
803 else // not a class name -> assume inner block
804 {
805 DBG_CTX((stderr,"** scope stack push INNERBLOCK\n"));
806 yyextra->scopeStack.push(INNERBLOCK);
807 }
808 yyextra->curClassName.clear();
809 yyextra->curClassBases.clear();
810 BEGIN( Body );
811 }
ClassDef * toClassDef(Definition *d)
#define INNERBLOCK
Definition code.l:77
812<Bases>"virtual"|"public"|"protected"|"private"|"@public"|"@private"|"@protected" {
813 startFontClass(yyscanner,"keyword");
814 yyextra->code->codify(yytext);
815 endFontClass(yyscanner);
816 }
817<Bases>{SEP}?({ID}{SEP})*{ID} {
818 DBG_CTX((stderr,"%s:addBase(%s)\n",qPrint(yyextra->curClassName),yytext));
819 yyextra->curClassBases.emplace_back(yytext);
820 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
821 }
822<Bases>"<" {
823 yyextra->code->codify(yytext);
824 if (!yyextra->insideObjC)
825 {
826 yyextra->sharpCount=1;
827 BEGIN ( SkipSharp );
828 }
829 else
830 {
831 yyextra->insideProtocolList=true;
832 }
833 }
834<Bases>">" {
835 yyextra->code->codify(yytext);
836 yyextra->insideProtocolList=false;
837 }
838<SkipSharp>"<" {
839 yyextra->code->codify(yytext);
840 ++yyextra->sharpCount;
841 }
842<SkipSharp>">" {
843 yyextra->code->codify(yytext);
844 if (--yyextra->sharpCount<=0)
845 BEGIN ( Bases );
846 }
847<SkipSharp>"\"" {
848 yyextra->code->codify(yytext);
849 yyextra->lastStringContext=YY_START;
850 BEGIN(SkipString);
851 }
852<SkipSharp>"\'" {
853 yyextra->code->codify(yytext);
854 yyextra->lastStringContext=YY_START;
855 BEGIN(SkipStringS);
856 }
857<Bases>"(" {
858 yyextra->code->codify(yytext);
859 yyextra->sharpCount=1;
860 BEGIN ( SkipSharp );
861 }
862<SkipSharp>"(" {
863 yyextra->code->codify(yytext);
864 ++yyextra->sharpCount;
865 }
866<SkipSharp>")" {
867 yyextra->code->codify(yytext);
868 if (--yyextra->sharpCount<=0)
869 BEGIN ( Bases );
870 }
871
872
873<Bases>"," {
874 yyextra->code->codify(yytext);
875 }
876
877
878<Body>{SCOPEPREFIX}?"operator"{B}*"()"{Bopt}/"(" {
879 addType(yyscanner);
880 generateFunctionLink(yyscanner,*yyextra->code,yytext);
881 yyextra->bracketCount=0;
882 yyextra->args.clear();
883 yyextra->name+=yytext;
884 BEGIN( FuncCall );
885 }
886<Body>{SCOPEPREFIX}?"operator"/"(" {
887 addType(yyscanner);
888 generateFunctionLink(yyscanner,*yyextra->code,yytext);
889 yyextra->bracketCount=0;
890 yyextra->args.clear();
891 yyextra->name+=yytext;
892 BEGIN( FuncCall );
893 }
894<Body>{SCOPEPREFIX}?"operator"[^a-z_A-Z0-9\‍(\n]+/"(" {
895 addType(yyscanner);
896 generateFunctionLink(yyscanner,*yyextra->code,yytext);
897 yyextra->bracketCount=0;
898 yyextra->args.clear();
899 yyextra->name+=yytext;
900 BEGIN( FuncCall );
901 }
902<Body,TemplDecl>("template"|"generic")/([^a-zA-Z0-9]) {
903 startFontClass(yyscanner,"keyword");
904 codifyLines(yyscanner,yytext);
905 endFontClass(yyscanner);
906 yyextra->insideTemplate=true;
907 yyextra->sharpCount=0;
908 }
909<Body>"concept"{BN}+ {
910 startFontClass(yyscanner,"keyword");
911 codifyLines(yyscanner,yytext);
912 endFontClass(yyscanner);
913 BEGIN(ConceptName);
914 }
915<Body>"using"{BN}+"namespace"{BN}+ {
916 startFontClass(yyscanner,"keyword");
917 codifyLines(yyscanner,yytext);
918 endFontClass(yyscanner);
919 BEGIN(UsingName);
920 }
921<Body>"using"{BN}+ {
922 startFontClass(yyscanner,"keyword");
923 codifyLines(yyscanner,yytext);
924 endFontClass(yyscanner);
925 BEGIN(UsingName);
926 }
927<Body>"module"/{B}*[:;]? { // 'module X' or 'module : private' or 'module;'
928 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
929 if (!yyextra->type.empty() || !yyextra->name.empty()) REJECT;
930 startFontClass(yyscanner,"keyword");
931 codifyLines(yyscanner,yytext);
932 endFontClass(yyscanner);
933 BEGIN(ModuleName);
934 }
935<Body>"import"/{B}*[<":]? {
936 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
937 startFontClass(yyscanner,"keyword");
938 codifyLines(yyscanner,yytext);
939 endFontClass(yyscanner);
940 BEGIN(ModuleImport);
941 }
942<ConceptName>{ID}("::"{ID})* {
943 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
944 }
945<ConceptName>"=" { codifyLines(yyscanner,yytext); BEGIN(Body); }
946<UsingName>{ID}(("::"|"."){ID})* {
947 addUsingDirective(yyscanner,substitute(yytext,".","::"));
948 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
949 BEGIN(Body);
950 }
951<UsingName>\n { codifyLines(yyscanner,yytext); BEGIN(Body); }
952<UsingName>. { codifyLines(yyscanner,yytext); BEGIN(Body); }
953<Body,FuncCall>"$"?"this"("->"|".") { yyextra->code->codify(yytext); // this-> for C++, this. for C#
954 yyextra->isPrefixedWithThis = true;
955 }
956<Body>{KEYWORD}/([^a-z_A-Z0-9]) {
957 if (yyextra->lang==SrcLangExt::Java && dstrcmp("internal",yytext) ==0) REJECT;
958 if (skipLanguageSpecificKeyword(yyscanner,yytext)) REJECT;
959 DString text=yytext;
960 startFontClass(yyscanner,"keyword");
961 codifyLines(yyscanner,yytext);
962 if (text=="typedef" || text.find("enum ")!=DString::npos) // typedef or strong enum
963 {
964 addType(yyscanner);
965 yyextra->name+=yytext;
966 }
967 endFontClass(yyscanner);
968 }
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50
969<Body>{KEYWORD}/{B}* {
970 if (skipLanguageSpecificKeyword(yyscanner,yytext)) REJECT;
971 startFontClass(yyscanner,"keyword");
972 codifyLines(yyscanner,yytext);
973 endFontClass(yyscanner);
974 }
975<Body>{KEYWORD}/{BN}*"(" {
976 if (skipLanguageSpecificKeyword(yyscanner,yytext)) REJECT;
977 startFontClass(yyscanner,"keyword");
978 codifyLines(yyscanner,yytext);
979 endFontClass(yyscanner);
980 yyextra->name.clear();yyextra->type.clear();
981 }
982<FuncCall>"in"/{BN}* {
983 if (!yyextra->inForEachExpression) REJECT;
984 startFontClass(yyscanner,"keywordflow");
985 codifyLines(yyscanner,yytext);
986 endFontClass(yyscanner);
987 // insert the variable in the parent scope, see bug 546158
988 yyextra->theVarContext.popScope();
989 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
990 yyextra->theVarContext.pushScope();
991 yyextra->name.clear();yyextra->type.clear();
992 }
993<Body>{FLOWKW}/{BN}*"(" {
994 startFontClass(yyscanner,"keywordflow");
995 codifyLines(yyscanner,yytext);
996 endFontClass(yyscanner);
997 yyextra->name.clear();yyextra->type.clear();
998 yyextra->inForEachExpression = (dstrcmp(yytext,"for each")==0 || dstrcmp(yytext, "foreach")==0);
999 BEGIN(FuncCall);
1000 }
1001<Body>{FLOWCONDITION}/{BN}*"(" {
1002 incrementFlowKeyWordCount(yyscanner);
1003 startFontClass(yyscanner,"keywordflow");
1004 codifyLines(yyscanner,yytext);
1005 endFontClass(yyscanner);
1006 yyextra->name.clear();yyextra->type.clear();
1007 yyextra->inForEachExpression = (strcmp(yytext,"for each")==0 || strcmp(yytext, "foreach")==0);
1008 BEGIN(FuncCall);
1009 }
1010<Body>{FLOWKW}/([^a-z_A-Z0-9]) {
1011 startFontClass(yyscanner,"keywordflow");
1012 codifyLines(yyscanner,yytext);
1013 endFontClass(yyscanner);
1014 if (yyextra->inFunctionTryBlock && (dstrcmp(yytext,"catch")==0 || dstrcmp(yytext,"finally")==0))
1015 {
1016 yyextra->inFunctionTryBlock=false;
1017 }
1018 }
1019<Body>{FLOWCONDITION}/([^a-z_A-Z0-9]) {
1020 incrementFlowKeyWordCount(yyscanner);
1021 startFontClass(yyscanner,"keywordflow");
1022 codifyLines(yyscanner,yytext);
1023 endFontClass(yyscanner);
1024 if (yyextra->inFunctionTryBlock && (strcmp(yytext,"catch")==0 || strcmp(yytext,"finally")==0))
1025 {
1026 yyextra->inFunctionTryBlock=false;
1027 }
1028 }
1029<Body>{FLOWKW}/{B}* {
1030 startFontClass(yyscanner,"keywordflow");
1031 codifyLines(yyscanner,yytext);
1032 endFontClass(yyscanner);
1033 }
1034<Body>{FLOWCONDITION}/{B}* {
1035 incrementFlowKeyWordCount(yyscanner);
1036 startFontClass(yyscanner,"keywordflow");
1037 codifyLines(yyscanner,yytext);
1038 endFontClass(yyscanner);
1039 }
1040<Body>"*"{B}*")" { // end of cast?
1041 yyextra->code->codify(yytext);
1042 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1043 yyextra->bracketCount--;
1044 yyextra->parmType = yyextra->name;
1045 BEGIN(FuncCall);
1046 }
1047<Body>"\\‍)"|"\\‍(" {
1048 yyextra->code->codify(yytext);
1049 }
1050<Body>[\\|\‍)\+\-\/\%\~\!] {
1051 yyextra->code->codify(yytext);
1052 yyextra->name.clear();yyextra->type.clear();
1053 if (*yytext==')')
1054 {
1055 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1056 yyextra->bracketCount--;
1057 if (yyextra->bracketCount<=0)
1058 {
1059 BEGIN(FuncCall);
1060 }
1061 }
1062 }
1063<Body,TemplDecl,ObjCMethod>{TYPEKW}/{B}* {
1064 startFontClass(yyscanner,"keywordtype");
1065 yyextra->code->codify(yytext);
1066 endFontClass(yyscanner);
1067 addType(yyscanner);
1068 yyextra->name+=yytext;
1069 }
1070<Body,TemplDecl,ObjCMethod>{TYPEKWSL}/{B}* {
1071 if (yyextra->lang!=SrcLangExt::Slice)
1072 {
1073 REJECT;
1074 }
1075 else
1076 {
1077 startFontClass(yyscanner,"keywordtype");
1078 yyextra->code->codify(yytext);
1079 endFontClass(yyscanner);
1080 addType(yyscanner);
1081 yyextra->name+=yytext;
1082 }
1083 }
1084<Body>"generic"/{B}*"<"[^\n\/\-\.\{\">]*">"{B}* {
1085 startFontClass(yyscanner,"keyword");
1086 yyextra->code->codify(yytext);
1087 endFontClass(yyscanner);
1088 yyextra->sharpCount=0;
1089 BEGIN(TemplDecl);
1090 }
1091<Body>"template"/{B}*"<"[^\n\/\-\.\{\">]*">"{B}* { // template<...>
1092 startFontClass(yyscanner,"keyword");
1093 yyextra->code->codify(yytext);
1094 endFontClass(yyscanner);
1095 yyextra->sharpCount=0;
1096 BEGIN(TemplDecl);
1097 }
1098<TemplDecl>"class"|"typename" {
1099 startFontClass(yyscanner,"keyword");
1100 codifyLines(yyscanner,yytext);
1101 endFontClass(yyscanner);
1102 }
1103<TemplDecl>"<" {
1104 yyextra->code->codify(yytext);
1105 yyextra->sharpCount++;
1106 }
1107<TemplDecl>">" {
1108 yyextra->code->codify(yytext);
1109 yyextra->sharpCount--;
1110 if (yyextra->sharpCount<=0)
1111 {
1112 BEGIN(Body);
1113 }
1114 }
1115<TemplCast>">" {
1116 startFontClass(yyscanner,"keyword");
1117 codifyLines(yyscanner,yytext);
1118 endFontClass(yyscanner);
1119 BEGIN( yyextra->lastTemplCastContext );
1120 }
1121<TemplCast>{ID}("::"{ID})* {
1122 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1123 }
1124<TemplCast>("const"|"volatile"){B}* {
1125 startFontClass(yyscanner,"keyword");
1126 codifyLines(yyscanner,yytext);
1127 endFontClass(yyscanner);
1128 }
1129<TemplCast>[*^]* {
1130 codifyLines(yyscanner,yytext);
1131 }
1132<Body,MemberCall2,FuncCall>{CASTKW}{B}*"<" { // static_cast<T>(
1133 startFontClass(yyscanner,"keyword");
1134 codifyLines(yyscanner,yytext);
1135 endFontClass(yyscanner);
1136 yyextra->lastTemplCastContext = YY_START;
1137 BEGIN(TemplCast);
1138 }
1139<Body>"$this->"{SCOPENAME}/{BN}*[;,)\‍]] { // PHP member variable
1140 addType(yyscanner);
1141 generatePHPVariableLink(yyscanner,*yyextra->code,yytext);
1142 yyextra->name+=yytext+7;
1143 }
1144<Body,TemplCast>{SCOPENAME}{B}*"<"[^\n\/\-\.\{\">\‍(']*">"{ENDIDopt}/{B}* { // A<T> *pt;
1145 if (isCastKeyword(yytext) && YY_START==Body)
1146 {
1147 REJECT;
1148 }
1149 addType(yyscanner);
1150 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1151 yyextra->name+=yytext;
1152 }
1153<ModuleName,ModuleImport>{MODULE_ID}({BN}*":"{BN}*{MODULE_ID})? {
1154 DString name = yytext;
1155 size_t i = name.find(':');
1156 DString partition;
1157 if (i!=DString::npos)
1158 {
1159 partition = name.mid(i+1).stripWhiteSpace();
1160 name = name.left(i).stripWhiteSpace();
1161 }
1163 if (mod)
1164 {
1165 writeMultiLineCodeLink(yyscanner,*yyextra->code,mod,yytext);
1166 }
1167 else
1168 {
1169 codifyLines(yyscanner,yytext);
1170 }
1171 }
static ModuleManager & instance()
ModuleDef * getPrimaryInterface(const DString &moduleName) const
1172<ModuleName>":"{BN}+"private" {
1173 DString text=yytext;
1174 size_t i=text.find('p');
1175 codifyLines(yyscanner,text.left(i));
1176 startFontClass(yyscanner,"keyword");
1177 codifyLines(yyscanner,text.mid(i));
1178 endFontClass(yyscanner);
1179 }
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString left(size_t len) const
Definition dstring.h:306
1180<ModuleName>";" { yyextra->code->codify(yytext); BEGIN(Body); }
1181<ModuleName>. { yyextra->code->codify(yytext); }
1182<ModuleName>\n { codifyLines(yyscanner,yytext); }
1183<ModuleImport>["<] { yyextra->code->codify(yytext); BEGIN(ReadInclude); }
1184<ModuleImport>";" { yyextra->code->codify(yytext); BEGIN(Body); }
1185<ModuleImport>. { yyextra->code->codify(yytext); }
1186<ModuleImport>\n { codifyLines(yyscanner,yytext); }
1187
1188<Body>{SCOPENAME}/{BN}*[:;,)\‍]] { // "int var;" or "var, var2" or "debug(f) macro" , or int var : 5;
1189 if (startsWithKeyword(yytext,"typedef") || startsWithKeyword(yytext,"using"))
1190 {
1191 REJECT;
1192 }
1193 addType(yyscanner);
1194 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1195 yyextra->name+=yytext;
1196 }
1197<Body>{ID}("."{ID})+/{BN}+ { // CSharp/Java scope
1198 if (yyextra->lang==SrcLangExt::CSharp || yyextra->lang==SrcLangExt::Java)
1199 {
1200 addType(yyscanner);
1201 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1202 yyextra->name+=yytext;
1203 }
1204 else
1205 {
1206 REJECT;
1207 }
1208 }
1209<Body>"export"/{B}* {
1210 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
1211 startFontClass(yyscanner,"keyword");
1212 codifyLines(yyscanner,yytext);
1213 endFontClass(yyscanner);
1214 }
1215<Body>{SCOPENAME}/{B}* { // p->func()
1216 if (startsWithKeyword(yytext,"typedef") || startsWithKeyword(yytext,"using"))
1217 {
1218 REJECT;
1219 }
1220 addType(yyscanner);
1221 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1222 yyextra->name+=yytext;
1223 }
1224<Body>"("{B}*("*"{B}*)+{SCOPENAME}+{B}*")"/{B}* { // (*p)->func() but not "if (p) ..."
1225 yyextra->code->codify(yytext);
1226 uint32_t s=0;while (s<(uint32_t)yyleng && !isId(yytext[s])) s++;
1227 uint32_t e=(uint32_t)yyleng-1;while (e>1 && !isId(yytext[e])) e--;
1228 DString varname = ((DString)yytext).mid(s,e-s+1);
1229 addType(yyscanner);
1230 yyextra->name=std::move(varname);
1231 }
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
1232<Body>{SCOPETNAME}{B}*"<"[^\n\/\-\.\{\">]*">"/{BN}*"(" |
1233<Body>{SCOPETNAME}/{BN}*"(" { // a() or c::a() or t<A,B>::a() or A\B\foo()
1234 if (isCastKeyword(yytext))
1235 {
1236 REJECT;
1237 }
1238 addType(yyscanner);
1239 generateFunctionLink(yyscanner,*yyextra->code,yytext);
1240 yyextra->bracketCount=0;
1241 yyextra->args.clear();
1242 yyextra->name+=yytext;
1243 BEGIN( FuncCall );
1244 }
1245<FuncCall,Body,MemberCall,MemberCall2,SkipInits,InlineInit>{RAWBEGIN} {
1246 DString text(yytext);
1247 size_t i=text.find('R');
1248 yyextra->code->codify(text.left(i+1));
1249 startFontClass(yyscanner,"stringliteral");
1250 yyextra->code->codify(yytext+i+1);
1251 yyextra->lastStringContext=YY_START;
1252 yyextra->inForEachExpression = false;
1253 yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
1254 BEGIN( RawString );
1255 }
DString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:5514
1256<FuncCall,Body,MemberCall,MemberCall2,SkipInits,InlineInit,ClassVar,OldStyleArgs>\" {
1257 startFontClass(yyscanner,"stringliteral");
1258 yyextra->code->codify(yytext);
1259 yyextra->lastStringContext=YY_START;
1260 yyextra->inForEachExpression = false;
1261 BEGIN( SkipString );
1262 }
1263<FuncCall,Body,MemberCall,MemberCall2,SkipInits,InlineInit>{NUMBER} { //Note similar code in commentcnv.l
1264 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
1265 yyextra->code->codify(yytext);
1266 }
1267<FuncCall,Body,MemberCall,MemberCall2,SkipInits,InlineInit>\' {
1268 startFontClass(yyscanner,"stringliteral");
1269 yyextra->code->codify(yytext);
1270 yyextra->lastStringContext=YY_START;
1271 yyextra->inForEachExpression = false;
1272 BEGIN( SkipStringS );
1273 }
1274<SkipString>[^\"\\\r\n]{1,100} {
1275 yyextra->code->codify(yytext);
1276 }
1277<SkipStringS>[^\'\\\r\n]{1,100} {
1278 yyextra->code->codify(yytext);
1279 }
1280<SkipString,SkipStringS>{CPPC}|{CCS} {
1281 yyextra->code->codify(yytext);
1282 }
1283<SkipString>@?\" {
1284 yyextra->code->codify(yytext);
1285 if (yyextra->lastStringContext!=SkipCPP)
1286 {
1287 endFontClass(yyscanner);
1288 }
1289 BEGIN( yyextra->lastStringContext );
1290 }
1291<SkipStringS>\' {
1292 yyextra->code->codify(yytext);
1293 endFontClass(yyscanner);
1294 BEGIN( yyextra->lastStringContext );
1295 }
1296<SkipString,SkipStringS>\\. {
1297 yyextra->code->codify(yytext);
1298 }
1299<RawString>{RAWEND} {
1300 yyextra->code->codify(yytext);
1301 if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
1302 {
1303 BEGIN( yyextra->lastStringContext );
1304 }
1305 }
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5522
1306<RawString>[^)\n]+ { yyextra->code->codify(yytext); }
1307<RawString>. { yyextra->code->codify(yytext); }
1308<RawString>\n { codifyLines(yyscanner,yytext); }
1309<SkipVerbString>[^"\n]+ {
1310 yyextra->code->codify(yytext);
1311 }
1312<SkipVerbString>\"\" { // escaped quote
1313 yyextra->code->codify(yytext);
1314 }
1315<SkipVerbString>\" { // end of string
1316 yyextra->code->codify(yytext);
1317 endFontClass(yyscanner);
1318 BEGIN( yyextra->lastVerbStringContext );
1319 }
1320<SkipVerbString>. {
1321 yyextra->code->codify(yytext);
1322 }
1323<SkipVerbString>\n {
1324 codifyLines(yyscanner,yytext);
1325 }
1326<Body>":" {
1327 yyextra->code->codify(yytext);
1328 yyextra->name.clear();yyextra->type.clear();
1329 }
1330<Body>"<" {
1331 if (yyextra->insideTemplate)
1332 {
1333 yyextra->sharpCount++;
1334 }
1335 yyextra->code->codify(yytext);
1336 }
1337<Body>">" {
1338 if (yyextra->insideTemplate)
1339 {
1340 if (--yyextra->sharpCount<=0)
1341 {
1342 yyextra->insideTemplate=false;
1343 }
1344 }
1345 yyextra->code->codify(yytext);
1346 }
1347<Body,MemberCall,MemberCall2,FuncCall,OldStyleArgs>"'"((\\0[Xx0-9]+)|(\\.)|(.))"'" {
1348 startFontClass(yyscanner,"charliteral");
1349 yyextra->code->codify(yytext);
1350 endFontClass(yyscanner);
1351 }
1352<Body>"."|"->" {
1353 if (yytext[0]=='-') // -> could be overloaded
1354 {
1356 }
1357 yyextra->code->codify(yytext);
1358 yyextra->memCallContext = YY_START;
1359 BEGIN( MemberCall );
1360 }
1361<MemberCall>{SCOPETNAME}/{BN}*"(" {
1362 DBG_CTX((stderr,"MemberCall: '%s'\n",qPrint(yytext)));
1363 if (yyextra->theCallContext.getScope().globalDef())
1364 {
1365 if (!generateClassMemberLink(yyscanner,*yyextra->code,yyextra->theCallContext.getScope().globalDef(),yytext))
1366 {
1367 codifyLines(yyscanner,yytext);
1368 addToSearchIndex(yyscanner,yytext);
1369 }
1370 yyextra->name.clear();
1371 }
1372 else
1373 {
1374 codifyLines(yyscanner,yytext);
1375 addToSearchIndex(yyscanner,yytext);
1376 yyextra->name.clear();
1377 }
1378 yyextra->type.clear();
1379 if (yyextra->memCallContext==Body)
1380 {
1381 BEGIN(FuncCall);
1382 }
1383 else
1384 {
1385 BEGIN(yyextra->memCallContext);
1386 }
1387 }
1388<MemberCall>{SCOPENAME}/{B}* {
1389 if (yyextra->theCallContext.getScope().globalDef())
1390 {
1391 DBG_CTX((stderr,"yyextra->theCallContext.getClass()=%p\n",(void*)yyextra->theCallContext.getScope().globalDef()));
1392 if (!generateClassMemberLink(yyscanner,*yyextra->code,yyextra->theCallContext.getScope().globalDef(),yytext))
1393 {
1394 codifyLines(yyscanner,yytext);
1395 addToSearchIndex(yyscanner,yytext);
1396 }
1397 yyextra->name.clear();
1398 }
1399 else
1400 {
1401 DBG_CTX((stderr,"no class context!\n"));
1402 codifyLines(yyscanner,yytext);
1403 addToSearchIndex(yyscanner,yytext);
1404 yyextra->name.clear();
1405 }
1406 yyextra->type.clear();
1407 BEGIN(yyextra->memCallContext);
1408 }
1409<Body>[,=;\‍[{] {
1410 if (yyextra->insideObjC && *yytext=='[')
1411 {
1412 DBG_CTX((stderr,"Found start of ObjC call!\n"));
1413 // start of a method call
1414 yyextra->contextMap.clear();
1415 yyextra->nameMap.clear();
1416 yyextra->objectMap.clear();
1417 yyextra->wordMap.clear();
1418 yyextra->commentMap.clear();
1419 yyextra->currentCtxId = 0;
1420 yyextra->currentNameId = 0;
1421 yyextra->currentObjId = 0;
1422 yyextra->currentCtx = nullptr;
1423 yyextra->braceCount = 0;
1424 unput('[');
1425 BEGIN(ObjCCall);
1426 }
1427 else
1428 {
1429 if (*yytext!='{') yyextra->code->codify(yytext);
1430 yyextra->saveName = yyextra->name;
1431 yyextra->saveType = yyextra->type;
1432 if (*yytext!='[' && !yyextra->type.empty())
1433 {
1434 //printf("yyextra->scopeStack.bottom()=%p\n",yyextra->scopeStack.bottom());
1435 //if (yyextra->scopeStack.top()!=CLASSBLOCK) // commented out for bug731363
1436 {
1437 //printf("AddVariable: '%s' '%s' context=%d\n",
1438 // qPrint(yyextra->type),qPrint(yyextra->name),yyextra->theVarContext.count());
1439 addVariable(yyscanner,yyextra->type,yyextra->name);
1440 }
1441 yyextra->name.clear();
1442 }
1443 if (*yytext==';' || *yytext=='=' || *yytext=='{')
1444 {
1445 yyextra->type.clear();
1446 yyextra->name.clear();
1447 }
1448 else if (*yytext=='[')
1449 {
1450 yyextra->theCallContext.pushScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1451 }
1452 yyextra->args.clear();
1453 yyextra->parmType.clear();
1454 yyextra->parmName.clear();
1455 if (*yytext=='{')
1456 {
1457 BEGIN( BodyVar );
1458 unput('{');
1459 }
1460 }
1461 }
1462<Body,FuncCall,BodyVar>"{" {
1463 yyextra->theVarContext.pushScope();
1464 yyextra->theCallContext.pushScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1465 yyextra->bracketCount = 0;
1466
1467 DBG_CTX((stderr,"** type='%s' name='%s'\n",qPrint(yyextra->type),qPrint(yyextra->name)));
1468 if (yyextra->type.find("enum ")!=DString::npos)
1469 { // for strong enums we need to start a scope
1470 DBG_CTX((stderr,"** scope stack push SCOPEBLOCK\n"));
1471 pushScope(yyscanner,yyextra->name);
1472 yyextra->scopeStack.push(SCOPEBLOCK);
1473 }
1474 else
1475 {
1476 DBG_CTX((stderr,"** scope stack push INNERBLOCK\n"));
1477 yyextra->scopeStack.push(INNERBLOCK);
1478 }
1479
1480 if (yyextra->searchingForBody)
1481 {
1482 yyextra->searchingForBody=false;
1483 yyextra->insideBody=true;
1484 }
1485 yyextra->code->codify(yytext);
1486 if (yyextra->insideBody)
1487 {
1488 yyextra->bodyCurlyCount++;
1489 }
1490 yyextra->type.clear();
1491 yyextra->name.clear();
1492 BEGIN( Body );
1493 }
1494<ObjCCall,ObjCMName>"["|"{" {
1495 saveObjCContext(yyscanner);
1496 yyextra->currentCtx->format+=*yytext;
1497 BEGIN(ObjCCall);
1498 DBG_CTX((stderr,"open\n"));
1499 }
1500<ObjCCall,ObjCMName>"]"|"}" {
1501 yyextra->currentCtx->format+=*yytext;
1502 restoreObjCContext(yyscanner);
1503 BEGIN(ObjCMName);
1504 if (yyextra->currentCtx==nullptr)
1505 {
1506 // end of call
1507 ObjCCallCtx *ctx = nullptr;
1508 auto it = yyextra->contextMap.find(0);
1509 if (it!=yyextra->contextMap.end())
1510 {
1511 ctx = it->second.get();
1512 }
1513 writeObjCMethodCall(yyscanner,ctx);
1514 BEGIN(Body);
1515 }
1516 DBG_CTX((stderr,"close\n"));
1517 }
1518<ObjCCall,ObjCMName>{CPPC}.* {
1519 yyextra->currentCtx->format+=escapeComment(yyscanner,yytext);
1520 }
1521<ObjCCall,ObjCMName>{CCS} {
1522 yyextra->lastObjCCallContext = YY_START;
1523 yyextra->currentCtx->comment.str(yytext);
1524 BEGIN(ObjCCallComment);
1525 }
1526<ObjCCallComment>{CCE} {
1527 yyextra->currentCtx->comment << yytext;
1528 yyextra->currentCtx->format+=escapeComment(yyscanner,yyextra->currentCtx->comment.str());
1529 BEGIN(yyextra->lastObjCCallContext);
1530 }
1531<ObjCCallComment>[^*\n]+ { yyextra->currentCtx->comment << yytext; }
1532<ObjCCallComment>{CPPC}|{CCS} { yyextra->currentCtx->comment << yytext; }
1533<ObjCCallComment>\n { yyextra->currentCtx->comment << *yytext; }
1534<ObjCCallComment>. { yyextra->currentCtx->comment << *yytext; }
1535<ObjCCall>{ID}({B}*"."{B}*{ID})* {
1536 yyextra->currentCtx->format+=escapeObject(yyscanner,yytext);
1537 if (yyextra->braceCount==0)
1538 {
1539 yyextra->currentCtx->objectTypeOrName=yytext;
1540 DBG_CTX((stderr,"new type=%s\n",qPrint(yyextra->currentCtx->objectTypeOrName)));
1541 BEGIN(ObjCMName);
1542 }
1543 }
1544<ObjCMName>{ID}/{BN}*"]" {
1545 if (yyextra->braceCount==0 &&
1546 yyextra->currentCtx->methodName.empty())
1547 {
1548 yyextra->currentCtx->methodName=yytext;
1549 yyextra->currentCtx->format+=escapeName(yyscanner,yytext);
1550 }
1551 else
1552 {
1553 yyextra->currentCtx->format+=escapeWord(yyscanner,yytext);
1554 }
1555 }
1556<ObjCMName>{ID}/{BN}*":" {
1557 if (yyextra->braceCount==0)
1558 {
1559 yyextra->currentCtx->methodName+=yytext;
1560 yyextra->currentCtx->methodName+=":";
1561 }
1562 yyextra->currentCtx->format+=escapeName(yyscanner,yytext);
1563 }
1564<ObjCSkipStr>[^\n\"$\\‍]* { yyextra->currentCtx->format+=yytext; }
1565<ObjCSkipStr>\\. { yyextra->currentCtx->format+=yytext; }
1566<ObjCSkipStr>"\"" { yyextra->currentCtx->format+=yytext;
1567 BEGIN(yyextra->lastStringContext);
1568 }
1569<ObjCCall,ObjCMName>{CHARLIT} { yyextra->currentCtx->format+=yytext; }
1570<ObjCCall,ObjCMName>"@"?"\"" { yyextra->currentCtx->format+=yytext;
1571 yyextra->lastStringContext=YY_START;
1572 BEGIN(ObjCSkipStr);
1573 }
1574<ObjCCall,ObjCMName,ObjCSkipStr>"$" { yyextra->currentCtx->format+="$$"; }
1575<ObjCCall,ObjCMName>"(" { yyextra->currentCtx->format+=*yytext; yyextra->braceCount++; }
1576<ObjCCall,ObjCMName>")" { yyextra->currentCtx->format+=*yytext; yyextra->braceCount--; }
1577<ObjCSkipStr>"@"/"\"" { // needed to prevent matching the global rule (for C#)
1578 yyextra->currentCtx->format+=yytext;
1579 }
1580<ObjCCall,ObjCMName,ObjCSkipStr>{ID} { yyextra->currentCtx->format+=escapeWord(yyscanner,yytext); }
1581<ObjCCall,ObjCMName,ObjCSkipStr>. { yyextra->currentCtx->format+=*yytext; }
1582<ObjCCall,ObjCMName,ObjCSkipStr>\n { yyextra->currentCtx->format+=*yytext; }
1583
1584<Body>"]" {
1585 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1586 yyextra->code->codify(yytext);
1587 // TODO: nested arrays like: a[b[0]->func()]->func()
1588 yyextra->name = yyextra->saveName;
1589 yyextra->type = yyextra->saveType;
1590 }
1591<Body>[0-9]+ {
1592 yyextra->code->codify(yytext);
1593 }
1594<Body>[0-9]+[xX][0-9A-Fa-f]+ {
1595 yyextra->code->codify(yytext);
1596 }
1597<MemberCall2,FuncCall>{KEYWORD}/([^a-z_A-Z0-9]) {
1598 //addParmType(yyscanner);
1599 //yyextra->parmName=yytext;
1600 if (skipLanguageSpecificKeyword(yyscanner,yytext)) REJECT;
1601 startFontClass(yyscanner,"keyword");
1602 yyextra->code->codify(yytext);
1603 endFontClass(yyscanner);
1604 }
1605<MemberCall2,FuncCall,OldStyleArgs,TemplCast>{TYPEKW}/([^a-z_A-Z0-9]) {
1606 addParmType(yyscanner);
1607 yyextra->parmName=yytext;
1608 startFontClass(yyscanner,"keywordtype");
1609 yyextra->code->codify(yytext);
1610 endFontClass(yyscanner);
1611 }
1612<MemberCall2,FuncCall,OldStyleArgs,TemplCast>{TYPEKWSL}/([^a-z_A-Z0-9]) {
1613 if (yyextra->lang!=SrcLangExt::Slice)
1614 {
1615 REJECT;
1616 }
1617 else
1618 {
1619 addParmType(yyscanner);
1620 yyextra->parmName=yytext;
1621 startFontClass(yyscanner,"keywordtype");
1622 yyextra->code->codify(yytext);
1623 endFontClass(yyscanner);
1624 }
1625 }
1626<MemberCall2,FuncCall>{FLOWKW}/([^a-z_A-Z0-9]) {
1627 addParmType(yyscanner);
1628 yyextra->parmName=yytext;
1629 startFontClass(yyscanner,"keywordflow");
1630 yyextra->code->codify(yytext);
1631 endFontClass(yyscanner);
1632 }
1633<MemberCall2,FuncCall>{FLOWCONDITION}/([^a-z_A-Z0-9]) {
1634 incrementFlowKeyWordCount(yyscanner);
1635 addParmType(yyscanner);
1636 yyextra->parmName=yytext;
1637 startFontClass(yyscanner,"keywordflow");
1638 yyextra->code->codify(yytext);
1639 endFontClass(yyscanner);
1640 }
1641<MemberCall2,FuncCall>("::")?{ID}(({B}*"<"[^\n\‍[\‍](){}<>']*">")?({B}*"::"{B}*{ID})?)* {
1642 if (isCastKeyword(yytext))
1643 {
1644 REJECT;
1645 }
1646 addParmType(yyscanner);
1647 yyextra->parmName=yytext;
1648 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext,!yyextra->insideBody);
1649 }
1650<FuncCall>";" { // probably a cast, not a function call
1651 yyextra->code->codify(yytext);
1652 yyextra->inForEachExpression = false;
1653 BEGIN( Body );
1654 }
1655<MemberCall2,FuncCall>, {
1656 yyextra->code->codify(yytext);
1657 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
1658 yyextra->parmType.clear();yyextra->parmName.clear();
1659 }
1660<MemberCall2,FuncCall>"{" {
1661 if (yyextra->bracketCount>0)
1662 {
1663 yyextra->code->codify(yytext);
1664 yyextra->skipInlineInitContext=YY_START;
1665 yyextra->curlyCount=0;
1666 BEGIN(InlineInit);
1667 }
1668 else
1669 {
1670 REJECT;
1671 }
1672 }
1673<InlineInit>"{" { yyextra->curlyCount++;
1674 yyextra->code->codify(yytext);
1675 }
1676<InlineInit>"}" {
1677 yyextra->code->codify(yytext);
1678 if (--yyextra->curlyCount<=0)
1679 {
1680 BEGIN(yyextra->skipInlineInitContext);
1681 }
1682 }
1683<InlineInit>\n {
1684 codifyLines(yyscanner,yytext);
1685 }
1686<InlineInit>. {
1687 yyextra->code->codify(yytext);
1688 }
1689<MemberCall2,FuncCall>"(" {
1690 yyextra->parmType.clear();yyextra->parmName.clear();
1691 yyextra->code->codify(yytext);
1692 yyextra->bracketCount++;
1693 yyextra->theCallContext.pushScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1694 if (YY_START==FuncCall && !yyextra->insideBody)
1695 {
1696 yyextra->theVarContext.pushScope();
1697 }
1698 }
1699<MemberCall2,FuncCall>{OPERATOR} { // operator
1700 if (dstrcmp(yytext,"*") &&
1701 dstrcmp(yytext,"&") &&
1702 dstrcmp(yytext,"^") &&
1703 dstrcmp(yytext,"%")) // typically a pointer or reference
1704 {
1705 // not a * or &, or C++/CLI's ^ or %
1706 yyextra->parmType.clear();yyextra->parmName.clear();
1707 }
1708 yyextra->code->codify(yytext);
1709 }
1710<MemberCall,MemberCall2,FuncCall>("*"{B}*)?")" {
1711 if (yytext[0]==')') // no a pointer cast
1712 {
1713 DBG_CTX((stderr,"addVariable(%s,%s)\n",qPrint(yyextra->parmType),qPrint(yyextra->parmName)));
1714 if (yyextra->parmType.empty())
1715 {
1716 yyextra->parmType=yyextra->parmName;
1717 yyextra->parmName.clear();
1718 }
1719 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
1720 }
1721 else
1722 {
1723 yyextra->parmType = yyextra->parmName;
1724 yyextra->parmName.clear();
1725 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
1726 }
1727 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
1728 yyextra->inForEachExpression = false;
1729 //yyextra->theCallContext.setClass(0); // commented out, otherwise a()->b() does not work for b().
1730 yyextra->code->codify(yytext);
1731 if (--yyextra->bracketCount<=0)
1732 {
1733 if (yyextra->name.empty())
1734 {
1735 BEGIN( Body );
1736 }
1737 else
1738 {
1739 BEGIN( CallEnd );
1740 }
1741 }
1742 }
1743<MemberCall,MemberCall2,FuncCall>[;:] { // recover from unexpected end of call
1744 //if (yytext[0]==';' || yyextra->bracketCount<=0)
1745 if (yyextra->bracketCount<=0)
1746 {
1747 unput(*yytext);
1748 BEGIN(CallEnd);
1749 }
1750 else
1751 {
1752 yyextra->code->codify(yytext);
1753 }
1754 }
1755<CallEnd>[ \t\n]* { codifyLines(yyscanner,yytext); }
1756<CallEnd>[;:] {
1757 codifyLines(yyscanner,yytext);
1758 yyextra->bracketCount=0;
1759 if (*yytext==';') yyextra->searchingForBody=false;
1760 if (!yyextra->type.empty())
1761 {
1762 DBG_CTX((stderr,"add variable yyextra->type=%s yyextra->name=%s)\n",qPrint(yyextra->type),qPrint(yyextra->name)));
1763 addVariable(yyscanner,yyextra->type,yyextra->name);
1764 }
1765 yyextra->parmType.clear();yyextra->parmName.clear();
1766 yyextra->theCallContext.setScope(ScopedTypeVariant());
1767 if (*yytext==';' || yyextra->insideBody)
1768 {
1769 if (!yyextra->insideBody)
1770 {
1771 yyextra->theVarContext.popScope();
1772 }
1773 yyextra->name.clear();yyextra->type.clear();
1774 BEGIN( Body );
1775 }
1776 else
1777 {
1778 yyextra->bracketCount=0;
1779 BEGIN( SkipInits );
1780 }
1781 }
1782<CallEnd>"=>" { // C# Expression Body
1783 if (yyextra->lang!=SrcLangExt::CSharp || yyextra->insideBody)
1784 {
1785 REJECT;
1786 }
1787 else
1788 {
1789 yyextra->code->codify("=>");
1790 BEGIN( Body );
1791 }
1792 }
1793<CallEnd>{ENDQopt}/{BN}*(";"|"="|"throw"{BN}*"(") {
1794 startFontClass(yyscanner,"keyword");
1795 codifyLines(yyscanner,yytext);
1796 endFontClass(yyscanner);
1797 }
1798<CallEnd,OldStyleArgs>("const"|"volatile"|"sealed"|"override")*({BN}+("const"|"volatile"|"sealed"|"override"))*{BN}*"{" {
1799 if (yyextra->insideBody)
1800 {
1801 yyextra->theVarContext.pushScope();
1802 }
1803 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
1804 //yyextra->theCallContext.popScope(yyextra->name, yyextra->type);
1805 yyextra->parmType.clear();yyextra->parmName.clear();
1806 size_t index = yyextra->name.rfind("::");
1807 DBG_CTX((stderr,"yyextra->name=%s\n",qPrint(yyextra->name)));
1808 if (index!=DString::npos)
1809 {
1810 DString scope = yyextra->name.left(index);
1811 if (!yyextra->scopeName.empty()) scope.prepend((yyextra->scopeName+"::"));
1812 const ClassDef *cd=yyextra->symbolResolver.resolveClass(Doxygen::globalScope,scope,true);
1813 if (cd)
1814 {
1815 setClassScope(yyscanner,cd->name());
1816 yyextra->scopeStack.push(SCOPEBLOCK);
1817 DBG_CTX((stderr,"** scope stack push SCOPEBLOCK\n"));
1818 }
1819 else
1820 {
1821 //setClassScope(yyscanner,yyextra->realScope);
1822 yyextra->scopeStack.push(INNERBLOCK);
1823 DBG_CTX((stderr,"** scope stack push INNERBLOCK\n"));
1824 }
1825 }
1826 else
1827 {
1828 DBG_CTX((stderr,"** scope stack push INNERBLOCK\n"));
1829 yyextra->scopeStack.push(INNERBLOCK);
1830 }
1831 yytext[yyleng-1]='\0';
1832 DString cv(yytext);
1833 if (!cv.stripWhiteSpace().empty())
1834 {
1835 startFontClass(yyscanner,"keyword");
1836 codifyLines(yyscanner,yytext);
1837 endFontClass(yyscanner);
1838 }
1839 else // just whitespace
1840 {
1841 codifyLines(yyscanner,yytext);
1842 }
1843 yyextra->code->codify("{");
1844 if (yyextra->searchingForBody)
1845 {
1846 yyextra->searchingForBody=false;
1847 yyextra->insideBody=true;
1848 }
1849 if (yyextra->insideBody) yyextra->bodyCurlyCount++;
1850 yyextra->type.clear(); yyextra->name.clear();
1851 BEGIN( Body );
1852 }
DString & prepend(const char *s)
Definition dstring.h:515
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
1853<CallEnd>"try" { // function-try-block
1854 startFontClass(yyscanner,"keyword");
1855 yyextra->code->codify(yytext);
1856 endFontClass(yyscanner);
1857 yyextra->inFunctionTryBlock=true;
1858 }
1859<CallEnd>"requires" { // function-try-block
1860 startFontClass(yyscanner,"keyword");
1861 yyextra->code->codify(yytext);
1862 endFontClass(yyscanner);
1863 }
1864<CallEnd>{ID} {
1865 if (yyextra->insideBody || !yyextra->parmType.empty())
1866 {
1867 REJECT;
1868 }
1869 // could be K&R style definition
1870 addParmType(yyscanner);
1871 yyextra->parmName=yytext;
1872 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext,!yyextra->insideBody);
1873 BEGIN(OldStyleArgs);
1874 }
1875<OldStyleArgs>{ID} {
1876 addParmType(yyscanner);
1877 yyextra->parmName=yytext;
1878 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext,!yyextra->insideBody);
1879 }
1880<OldStyleArgs>[,;] {
1881 yyextra->code->codify(yytext);
1882 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
1883 if (*yytext==';') yyextra->parmType.clear();
1884 yyextra->parmName.clear();
1885 }
1886<CallEnd,OldStyleArgs>"#" {
1887 startFontClass(yyscanner,"preprocessor");
1888 yyextra->lastSkipCppContext = Body;
1889 yyextra->code->codify(yytext);
1890 BEGIN( SkipCPP );
1891 }
1892<CallEnd>. {
1893 unput(*yytext);
1894 if (!yyextra->insideBody)
1895 {
1896 yyextra->theVarContext.popScope();
1897 }
1898 yyextra->name.clear();yyextra->args.clear();
1899 yyextra->parmType.clear();yyextra->parmName.clear();
1900 BEGIN( Body );
1901 }
1902<SkipInits>";" {
1903 yyextra->code->codify(yytext);
1904 yyextra->type.clear(); yyextra->name.clear();
1905 BEGIN( Body );
1906 }
1907<SkipInits>"{" {
1908 yyextra->code->codify(yytext);
1909 if (yyextra->searchingForBody)
1910 {
1911 yyextra->searchingForBody=false;
1912 yyextra->insideBody=true;
1913 }
1914 if (yyextra->insideBody) yyextra->bodyCurlyCount++;
1915 if (yyextra->name.find("::")!=DString::npos)
1916 {
1917 DBG_CTX((stderr,"** scope stack push SCOPEBLOCK\n"));
1918 yyextra->scopeStack.push(SCOPEBLOCK);
1919 setClassScope(yyscanner,yyextra->realScope);
1920 }
1921 else
1922 {
1923 DBG_CTX((stderr,"** scope stack push INNERBLOCK\n"));
1924 yyextra->scopeStack.push(INNERBLOCK);
1925 }
1926 yyextra->type.clear(); yyextra->name.clear();
1927 BEGIN( Body );
1928 }
1929<SkipInits>{ID}{B}*"{" {
1930 DString text(yytext);
1931 size_t bracketPos = text.find('{');
1932 size_t spacePos = text.find(' ');
1933 size_t len = spacePos==DString::npos ? bracketPos : spacePos;
1934 generateClassOrGlobalLink(yyscanner,*yyextra->code,text.left(len));
1935 yyextra->code->codify(yytext+len);
1936 }
1937<SkipInits>{ID} {
1938 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1939 }
1940<FuncCall>{ID}/"(" {
1941 generateFunctionLink(yyscanner,*yyextra->code,yytext);
1942 }
1943<FuncCall>{ID}/("."|"->") {
1944 yyextra->name=yytext;
1945 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1946 BEGIN( MemberCall2 );
1947 }
1948<FuncCall,MemberCall2>("("{B}*("*"{B}*)+{ID}+{B}*")"{B}*)/("."|"->") {
1949 yyextra->code->codify(yytext);
1950 uint32_t s=0;while (!isId(yytext[s])) s++;
1951 uint32_t e=(uint32_t)yyleng-1;while (e>1 && !isId(yytext[e])) e--;
1952 yyextra->name=((DString)yytext).mid(s,e-s+1);
1953 BEGIN( MemberCall2 );
1954 }
1955<MemberCall2>{ID}/([ \t\n]*"(") {
1956 if (!yyextra->args.empty())
1957 generateMemberLink(yyscanner,*yyextra->code,yyextra->args,yytext);
1958 else
1959 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1960 yyextra->args.clear();
1961 BEGIN( FuncCall );
1962 }
1963<MemberCall2>{ID}/([ \t\n]*("."|"->")) {
1964 //yyextra->code->codify(yytext);
1965 yyextra->name=yytext;
1966 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
1967 BEGIN( MemberCall2 );
1968 }
1969<MemberCall2>"->"|"." {
1970 if (yytext[0]=='-') // -> could be overloaded
1971 {
1973 }
1974 yyextra->code->codify(yytext);
1975 yyextra->memCallContext = YY_START;
1976 BEGIN( MemberCall );
1977 }
1978<SkipComment>{CCS}("!"?){CCE} {
1979 yyextra->code->codify(yytext);
1980 endFontClass(yyscanner,true);
1981 BEGIN( yyextra->lastCContext ) ;
1982 }
1983<SkipComment>{CPPC}|{CCS} {
1984 yyextra->code->codify(yytext);
1985 }
1986<SkipComment>[^*\/\n]+ {
1987 yyextra->code->codify(yytext);
1988 }
1989<SkipComment>[ \t]*{CCE} {
1990 yyextra->code->codify(yytext);
1991 endFontClass(yyscanner,true);
1992 if (yyextra->lastCContext==SkipCPP)
1993 {
1994 startFontClass(yyscanner,"preprocessor");
1995 }
1996 BEGIN( yyextra->lastCContext ) ;
1997 }
1998<SkipCxxComment>[^\r\n]*"\\"[\r]?\n { // line continuation
1999 codifyLines(yyscanner,yytext);
2000 }
2001<SkipCxxComment>[^\r\n]+ {
2002 yyextra->code->codify(yytext);
2003 }
2004<SkipCxxComment>\r
2005<SkipCxxComment>\n {
2006 unput('\n');
2007 endFontClass(yyscanner);
2008 BEGIN( yyextra->lastCContext ) ;
2009 }
2010<SkipCxxComment>. {
2011 yyextra->code->codify(yytext);
2012 }
2013<MemberCall>[^a-z_A-Z0-9(\n] {
2014 yyextra->code->codify(yytext);
2015 yyextra->type.clear();
2016 yyextra->name.clear();
2017 BEGIN(yyextra->memCallContext);
2018 }
2019<*>\n({B}*{CPPC}[!/][^\n]*\n)+ { // remove special one-line comment
2020 if (YY_START==SkipCPP) REJECT;
2021 startFontClass(yyscanner,"comment",true);
2022 codifyLines(yyscanner,DString(yytext).left(yyleng-1));
2023 endFontClass(yyscanner,true);
2024 codifyLines(yyscanner,"\n");
2025 if (YY_START==SkipCxxComment)
2026 {
2027 BEGIN( yyextra->lastCContext ) ;
2028 }
2029 }
2030<SkipCPP>\n/(.|\n) {
2031 endFontClass(yyscanner);
2032 BEGIN( yyextra->lastSkipCppContext ) ;
2033 unput('\n');
2034 }
2035<*>\n{B}*{CPPC}"@"[{}].*\n { // remove one-line group marker
2036 startFontClass(yyscanner,"comment",true);
2037 codifyLines(yyscanner,DString(yytext).left(yyleng-1));
2038 endFontClass(yyscanner,true);
2039 codifyLines(yyscanner,"\n");
2040 if (YY_START==SkipCxxComment)
2041 {
2042 BEGIN( yyextra->lastCContext ) ;
2043 }
2044 }
2045<*>\n{B}*{CCS}"@"[{}] { // remove one-line group marker
2046 // check is to prevent getting stuck in skipping C++ comments
2047 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2048 {
2049 yyextra->lastCContext = YY_START ;
2050 }
2051 startFontClass(yyscanner,"comment",true);
2052 codifyLines(yyscanner,yytext);
2053 BEGIN(SkipComment);
2054 }
2055<*>^{B}*{CPPC}"@"[{}].*\n { // remove one-line group marker
2056 startFontClass(yyscanner,"comment",true);
2057 codifyLines(yyscanner,DString(yytext).left(yyleng-1));
2058 endFontClass(yyscanner,true);
2059 codifyLines(yyscanner,"\n");
2060 }
2061<*>^{B}*{CCS}"@"[{}] { // remove multi-line group marker
2062 // check is to prevent getting stuck in skipping C++ comments
2063 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2064 {
2065 yyextra->lastCContext = YY_START ;
2066 }
2067 startFontClass(yyscanner,"comment",true);
2068 yyextra->code->codify(yytext);
2069 BEGIN(SkipComment);
2070 }
2071<*>^{B}*{CPPC}[!/][^\n]* { // remove special one-line comment
2072 startFontClass(yyscanner,"comment",true);
2073 codifyLines(yyscanner,yytext);
2074 endFontClass(yyscanner,true);
2075 }
2076<*>{CPPC}[!/][^\n]* { // strip special one-line comment
2077 if (YY_START==SkipComment || YY_START==SkipString) REJECT;
2078 startFontClass(yyscanner,"comment",true);
2079 codifyLines(yyscanner,yytext);
2080 endFontClass(yyscanner,true);
2081 }
2082<*>\n{B}*{CCS}[!*]/{NCOMM} {
2083 // check is to prevent getting stuck in skipping C++ comments
2084 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2085 {
2086 yyextra->lastCContext = YY_START ;
2087 }
2088 startFontClass(yyscanner,"comment",true);
2089 codifyLines(yyscanner,yytext);
2090 BEGIN(SkipComment);
2091 }
2092<*>^{B}*{CCS}"*"[*]+/[^/] {
2093 // check is to prevent getting stuck in skipping C++ comments
2094 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2095 {
2096 yyextra->lastCContext = YY_START ;
2097 }
2098 // special C "banner" comment block at a new line
2099 startFontClass(yyscanner,"comment",Config_getBool(JAVADOC_BANNER));
2100 yyextra->code->codify(yytext);
2101 BEGIN(SkipComment);
2102 }
#define Config_getBool(name)
Definition config.h:33
2103<*>^{B}*{CCS}[!*]/{NCOMM} { // special C comment block at a new line
2104 // check is to prevent getting stuck in skipping C++ comments
2105 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2106 {
2107 yyextra->lastCContext = YY_START ;
2108 }
2109 startFontClass(yyscanner,"comment",true);
2110 yyextra->code->codify(yytext);
2111 BEGIN(SkipComment);
2112 }
2113<*>{CCS}[!*]/{NCOMM} { // special C comment block half way a line
2114 if (YY_START==SkipString) REJECT;
2115 // check is to prevent getting stuck in skipping C++ comments
2116 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2117 {
2118 yyextra->lastCContext = YY_START ;
2119 }
2120 startFontClass(yyscanner,"comment",true);
2121 yyextra->code->codify(yytext);
2122 BEGIN(SkipComment);
2123 }
2124<*>{CCS}("!"?){CCE} {
2125 if (YY_START==SkipString) REJECT;
2126 bool specialComment = DString(yytext).find('!')!=DString::npos;
2127 startFontClass(yyscanner,"comment",specialComment);
2128 yyextra->code->codify(yytext);
2129 endFontClass(yyscanner,specialComment);
2130 }
2131<SkipComment>[^\*\n]+ {
2132 yyextra->code->codify(yytext);
2133 }
2134<*>{CCS} {
2135 startFontClass(yyscanner,"comment");
2136 yyextra->code->codify(yytext);
2137 // check is to prevent getting stuck in skipping C++ comments
2138 if (YY_START != SkipComment && YY_START != SkipCxxComment)
2139 {
2140 yyextra->lastCContext = YY_START ;
2141 }
2142 BEGIN( SkipComment ) ;
2143 }
2144<*>[$]?@\" { // C# (interpolated) verbatim string
2145 startFontClass(yyscanner,"stringliteral");
2146 yyextra->code->codify(yytext);
2147 yyextra->lastVerbStringContext=YY_START;
2148 BEGIN(SkipVerbString);
2149 }
2150<*>{CPPC} {
2151 startFontClass(yyscanner,"comment");
2152 yyextra->code->codify(yytext);
2153 yyextra->lastCContext = YY_START ;
2154 BEGIN( SkipCxxComment ) ;
2155 }
2156<*>"("|"[" {
2157 if (yytext[0]=='(') yyextra->bracketCount++;
2158 yyextra->code->codify(yytext);
2159 yyextra->theCallContext.pushScope(yyextra->name, yyextra->type, yyextra->bracketCount);
2160 }
2161<*>")"|"]" {
2162 if (yytext[0]==')') yyextra->bracketCount--;
2163 yyextra->code->codify(yytext);
2164 yyextra->theCallContext.popScope(yyextra->name, yyextra->type, yyextra->bracketCount);
2165 }
2166<*>\n {
2167 codifyLines(yyscanner,yytext);
2168 }
2169<*>[\x80-\xFF]* { // keep utf8 characters together...
2170 yyextra->code->codify(yytext);
2171 }
2172<*>. {
2173 yyextra->code->codify(yytext);
2174 }
2175
2176%%
2177
2178/*@ ----------------------------------------------------------------------------
2179 */
2180
2181static bool startsWithKeyword(const DString &str,const DString &kw)
2182{
2183 if (str.length()<kw.length()) return false; // string too short to match
2184 return str==kw || // exact match
2185 (str.startsWith(kw) && !isId(str.at(kw.length()))); // match that is not a substring
2186}
2187
2188static void addVariable(yyscan_t yyscanner,DString type,DString name)
2189{
2190 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2191 DBG_CTX((stderr,"VariableContext::addVariable(%s,%s)\n",qPrint(type),qPrint(name)));
2192 DString ltype = type.simplifyWhiteSpace();
2193 DString lname = name.simplifyWhiteSpace();
2194 ltype.stripPrefix("struct ");
2195 ltype.stripPrefix("record ");
2196 ltype.stripPrefix("union ");
2197 if (ltype.empty() || lname.empty()) return;
2198 ltype = substitute(ltype,".","::");
2199 DBG_CTX((stderr,"** addVariable trying: type='%s' name='%s' currentDefinition=%s\n",
2200 qPrint(ltype),qPrint(lname),yyextra->currentDefinition?qPrint(yyextra->currentDefinition->name()):"<none>"));
2201 auto it = yyextra->codeClassMap.find(ltype.str());
2202 if (it!=yyextra->codeClassMap.end()) // look for class definitions inside the code block
2203 {
2204 DBG_CTX((stderr,"** addVariable type='%s' name='%s'\n",qPrint(ltype),qPrint(lname)));
2205 yyextra->theVarContext.addVariable(lname,std::move(it->second)); // add it to a list
2206 }
2207 else
2208 {
2209 auto findVariableType = [&yyscanner,&yyg,&ltype,&lname,&name](const Definition *d) -> const ClassDef *
2210 {
2211 const ClassDef *varDef = yyextra->symbolResolver.resolveClass(d,ltype,true);
2212 if (varDef)
2213 {
2214 DBG_CTX((stderr,"** addVariable type='%s' name='%s'\n",qPrint(ltype),qPrint(lname)));
2215 yyextra->theVarContext.addVariable(lname,ScopedTypeVariant(varDef)); // add it to a list
2216 }
2217 else if (size_t i=ltype.find('<') ; i!=DString::npos)
2218 {
2219 // probably a template class
2220 addVariable(yyscanner,ltype.left(i),name);
2221 }
2222 return varDef;
2223 };
2224 const ClassDef *varDef = findVariableType(yyextra->currentDefinition);
2225 if (varDef==nullptr) // also check via using directive
2226 {
2227 for (const auto &[usingName,namespaceDef] : yyextra->theUsingContext)
2228 {
2229 varDef = findVariableType(namespaceDef);
2230 if (varDef) break;
2231 }
2232 }
2233 if (varDef==nullptr)
2234 {
2235 if (!yyextra->theVarContext.atGlobalScope()) // for local variables add a dummy entry so the name
2236 // is hidden to avoid false links to global variables with the same name
2237 // TODO: make this work for namespaces as well!
2238 {
2239 DBG_CTX((stderr,"** addVariable: dummy context for '%s'\n",qPrint(lname)));
2240 yyextra->theVarContext.addVariable(lname,ScopedTypeVariant());
2241 }
2242 else
2243 {
2244 DBG_CTX((stderr,"** addVariable: not adding variable!\n"));
2245 }
2246 }
2247 }
2248}
2249
2250//-------------------------------------------------------------------
2251
2252/*! add class/namespace name s to the scope */
2253static void pushScope(yyscan_t yyscanner,const DString &s)
2254{
2255 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2256 yyextra->scopeNameLengthStack.push_back(int(yyextra->scopeName.length()));
2257 if (yyextra->scopeName.empty() || leftScopeMatch(s,yyextra->scopeName))
2258 {
2259 yyextra->scopeName = s;
2260 }
2261 else
2262 {
2263 yyextra->scopeName += "::";
2264 yyextra->scopeName += s;
2265 }
2266 DBG_CTX((stderr,"pushScope(%s) result: '%s'\n",qPrint(s),qPrint(yyextra->scopeName)));
2267}
2268
2269
2270/*! remove the top class/namespace name from the scope */
2271static void popScope(yyscan_t yyscanner)
2272{
2273 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2274 if (!yyextra->scopeNameLengthStack.empty())
2275 {
2276 int length = yyextra->scopeNameLengthStack.back();
2277 yyextra->scopeNameLengthStack.pop_back();
2278 yyextra->scopeName.resize(length);
2279 }
2280 else
2281 {
2282 //err("Too many end of scopes found!\n");
2283 }
2284 DBG_CTX((stderr,"popScope() result: '%s'\n",qPrint(yyextra->scopeName)));
2285}
2286
2287static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor)
2288{
2289 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2290 if (Doxygen::searchIndex.enabled())
2291 {
2292 if (yyextra->searchCtx)
2293 {
2294 Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),false);
2295 }
2296 else
2297 {
2298 Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,true);
2299 }
2300 }
2301}
2302
2303static void addToSearchIndex(yyscan_t /*yyscanner*/,const DString &text)
2304{
2305 if (Doxygen::searchIndex.enabled())
2306 {
2307 Doxygen::searchIndex.addWord(text,false);
2308 }
2309}
2310
2311static void setClassScope(yyscan_t yyscanner,const DString &name)
2312{
2313 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2314 DBG_CTX((stderr,"setClassScope(%s)\n",qPrint(name)));
2315 DString n=name;
2316 n=n.simplifyWhiteSpace();
2317 size_t ts=n.find('<'); // start of template
2318 size_t te=n.rfind('>'); // end of template
2319 DBG_CTX((stderr,"ts=%zu te=%zu\n",ts,te));
2320 if (ts!=DString::npos && te!=DString::npos && te>ts)
2321 {
2322 // remove template from scope
2323 n=n.left(ts)+n.mid(te+1);
2324 }
2325 while (!yyextra->scopeNameLengthStack.empty())
2326 {
2327 popScope(yyscanner);
2328 }
2329 yyextra->scopeName.clear();
2330 size_t i;
2331 while ((i=n.find("::"))!=DString::npos)
2332 {
2333 pushScope(yyscanner,n.left(i));
2334 n = n.mid(i+2);
2335 }
2336 pushScope(yyscanner,n);
2337 DBG_CTX((stderr,"--->New class scope '%s'\n",qPrint(yyextra->scopeName)));
2338}
2339
2340static void endCodeFold(yyscan_t yyscanner)
2341{
2342 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2343 while (!yyextra->foldStack.empty())
2344 {
2345 const Definition *dd = yyextra->foldStack.back();
2346 if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
2347 {
2348 yyextra->code->endFold();
2349 //fprintf(stderr,"%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
2350 yyextra->foldStack.pop_back();
2351 }
2352 else
2353 {
2354 //fprintf(stderr,"no end of block dd=%s end=%d\n",qPrint(dd->qualifiedName()),dd->getEndBodyLine());
2355 break;
2356 }
2357 }
2358}
2359
2360
2361static void codeFolding(yyscan_t yyscanner,const Definition *d)
2362{
2363 if (Config_getBool(HTML_CODE_FOLDING))
2364 {
2365 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2366 //fprintf(stderr,"codeFolding at %d\n",yyextra->yyLineNr);
2367 //if (d)
2368 // fprintf(stderr,"%d: codeFolding: candidate=%s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->qualifiedName()),d->getStartDefLine(),d->getEndBodyLine());
2369 endCodeFold(yyscanner);
2370 if (d)
2371 {
2372 int startLine = d->getStartDefLine();
2373 int endLine = d->getEndBodyLine();
2374 if (endLine!=-1 && startLine!=endLine &&
2375 // since the end of a section is closed after the last line, we need to avoid starting a
2376 // new section if the previous section ends at the same line, i.e. something like
2377 // struct X {
2378 // ...
2379 // }; struct S { <- start of S and end of X at the same line
2380 // ...
2381 // };
2382 (yyextra->foldStack.empty() || yyextra->foldStack.back()->getEndBodyLine()!=startLine))
2383 {
2384 //printf("%d: start codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->name()),d->getStartDefLine(),d->getEndBodyLine());
2386 {
2387 const MemberDef *md = toMemberDef(d);
2388 if (md && md->isDefine())
2389 {
2390 yyextra->code->startFold(yyextra->yyLineNr,"",""); // #define X ...
2391 }
2392 else if (md && md->isCallable())
2393 {
2394 yyextra->code->startFold(yyextra->yyLineNr,"{","}"); // func() { ... }
2395 }
2396 else
2397 {
2398 yyextra->code->startFold(yyextra->yyLineNr,"{","};"); // enum X { ... }
2399 }
2400 }
2402 {
2403 yyextra->code->startFold(yyextra->yyLineNr,"{","};"); // class X { ... };
2404 }
2405 else
2406 {
2407 yyextra->code->startFold(yyextra->yyLineNr,"{","}"); // namespace X {...}
2408 }
2409 yyextra->foldStack.push_back(d);
2410 }
2411 }
2412 }
2413}
2414
2415/*! start a new line of code, inserting a line number if yyextra->sourceFileDef
2416 * is true. If a definition starts at the current line, then the line
2417 * number is linked to the documentation of that definition.
2418 */
2419static void startCodeLine(yyscan_t yyscanner)
2420{
2421 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2422 //if (yyextra->currentFontClass) { yyextra->code->endFontClass(yyscanner); }
2423 if (yyextra->sourceFileDef && yyextra->lineNumbers)
2424 {
2425 //DString lineNumber,lineAnchor;
2426 //lineNumber.sprintf("%05d",yyextra->yyLineNr);
2427 //lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
2428
2429 const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
2430 //printf("%s:startCodeLine(%d)=%p\n",qPrint(yyextra->sourceFileDef->name()),yyextra->yyLineNr,(void*)d);
2431 DBG_CTX((stderr,"%s:startCodeLine(%d)=%p\n",qPrint(yyextra->sourceFileDef->name()),yyextra->yyLineNr,(void*)d));
2432 if (!yyextra->includeCodeFragment && d)
2433 {
2434 yyextra->currentDefinition = d;
2435 yyextra->currentMemberDef = yyextra->sourceFileDef->getSourceMember(yyextra->yyLineNr);
2436 yyextra->insideBody = false;
2437 yyextra->searchingForBody = true;
2438 yyextra->realScope = d!=Doxygen::globalScope ? d->name() : "";
2439 yyextra->type.clear();
2440 yyextra->name.clear();
2441 yyextra->args.clear();
2442 yyextra->parmType.clear();
2443 yyextra->parmName.clear();
2444 DBG_CTX((stderr,"Real scope: '%s'\n",qPrint(yyextra->realScope)));
2445 yyextra->bodyCurlyCount = 0;
2446 DString lineAnchor;
2447 lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
2448 if (yyextra->currentMemberDef)
2449 {
2450 codeFolding(yyscanner,yyextra->currentMemberDef);
2451 yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
2452 yyextra->currentMemberDef->getOutputFileBase(),
2453 yyextra->currentMemberDef->anchor(),
2454 yyextra->yyLineNr,!yyextra->includeCodeFragment);
2455 setCurrentDoc(yyscanner,lineAnchor);
2456 }
2457 else if (d->isLinkableInProject())
2458 {
2459 codeFolding(yyscanner,d);
2460 yyextra->code->writeLineNumber(d->getReference(),
2461 d->getOutputFileBase(),
2462 DString(),yyextra->yyLineNr,!yyextra->includeCodeFragment);
2463 setCurrentDoc(yyscanner,lineAnchor);
2464 }
2465 else
2466 {
2467 codeFolding(yyscanner,nullptr);
2468 }
2469 }
2470 else
2471 {
2472 codeFolding(yyscanner,nullptr);
2473 yyextra->code->writeLineNumber(DString(),DString(),DString(),yyextra->yyLineNr,
2474 !yyextra->includeCodeFragment);
2475 }
2476 }
2477 DBG_CTX((stderr,"startCodeLine(%d)\n",yyextra->yyLineNr));
2478 yyextra->code->startCodeLine(yyextra->yyLineNr);
2479 yyextra->insideCodeLine = true;
2480 if (yyextra->currentFontClass)
2481 {
2482 yyextra->code->startFontClass(yyextra->currentFontClass);
2483 }
2484}
2485
2486
2487
2488static void endCodeLine(yyscan_t yyscanner)
2489{
2490 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2491 DBG_CTX((stderr,"endCodeLine(%d)\n",yyextra->yyLineNr));
2492 endFontClass(yyscanner);
2493 yyextra->code->endCodeLine();
2494 yyextra->insideCodeLine = false;
2495}
2496
2497static void nextCodeLine(yyscan_t yyscanner)
2498{
2499 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2500 const char * fc = yyextra->currentFontClass;
2501 if (yyextra->insideCodeLine)
2502 {
2503 endCodeLine(yyscanner);
2504 }
2505 if (yyextra->yyLineNr<yyextra->inputLines)
2506 {
2507 yyextra->currentFontClass = fc;
2508 startCodeLine(yyscanner);
2509 }
2510}
2511
2512/*! write a code fragment 'text' that may span multiple lines, inserting
2513 * line numbers for each line.
2514 */
2515static void codifyLines(yyscan_t yyscanner,const DString &text)
2516{
2517 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2518 DBG_CTX((stderr,"codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,qPrint(text)));
2519 if (text.empty()) return;
2520 const char *p=text.data(),*sp=p;
2521 char c;
2522 bool done=false;
2523 while (!done)
2524 {
2525 sp=p;
2526 while ((c=*p++) && c!='\n');
2527 if (c=='\n')
2528 {
2529 yyextra->yyLineNr++;
2530 size_t l = static_cast<size_t>(p-sp-1);
2531 yyextra->code->codify(DString(sp,l));
2532 nextCodeLine(yyscanner);
2533 }
2534 else
2535 {
2536 yyextra->code->codify(sp);
2537 done=true;
2538 }
2539 }
2540}
2541
2543{
2544 std::lock_guard<std::mutex> lock(Doxygen::countFlowKeywordsMutex);
2545 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2546 if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction())
2547 {
2548 MemberDefMutable *md = toMemberDefMutable(const_cast<MemberDef*>(yyextra->currentMemberDef));
2549 if (md)
2550 {
2552 }
2553 }
2554}
2555
2556/*! writes a link to a fragment \a text that may span multiple lines, inserting
2557 * line numbers for each line. If \a text contains newlines, the link will be
2558 * split into multiple links with the same destination, one for each line.
2559 */
2561 const Definition *d,
2562 const DString &text)
2563{
2564 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2565 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
2566 yyextra->tooltipManager.addTooltip(d);
2567 DString ref = d->getReference();
2568 DString file = d->getOutputFileBase();
2569 DString anchor = d->anchor();
2570 DString tooltip;
2571 if (!sourceTooltips) // fall back to simple "title" tooltips
2572 {
2573 tooltip = d->briefDescriptionAsTooltip();
2574 }
2575 bool done=false;
2576 const char *p=text.data();
2577 while (!done)
2578 {
2579 const char *sp=p;
2580 char c = 0;
2581 while ((c=*p++) && c!='\n') { }
2582 if (c=='\n')
2583 {
2584 yyextra->yyLineNr++;
2585 DBG_CTX((stderr,"writeCodeLink(%s,%s,%s,%s)\n",qPrint(ref),qPrint(file),qPrint(anchor),qPrint(DString(sp,p-sp-1))));
2586 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,DString(sp,p-sp-1),tooltip);
2587 nextCodeLine(yyscanner);
2588 }
2589 else
2590 {
2591 DBG_CTX((stderr,"writeCodeLink(%s,%s,%s,%s)\n",qPrint(ref),qPrint(file),qPrint(anchor),sp));
2592 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,sp,tooltip);
2593 done=true;
2594 }
2595 }
2596}
2597
2598static void addType(yyscan_t yyscanner)
2599{
2600 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2601 if (yyextra->name=="const") { yyextra->name.clear(); return; }
2602 if (!yyextra->type.empty()) yyextra->type += ' ' ;
2603 yyextra->type += yyextra->name ;
2604 yyextra->name.clear() ;
2605 if (!yyextra->type.empty()) yyextra->type += ' ' ;
2606 yyextra->type += yyextra->args ;
2607 yyextra->args.clear() ;
2608}
2609
2610static void addParmType(yyscan_t yyscanner)
2611{
2612 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2613 if (yyextra->parmName=="const") { yyextra->parmName.clear(); return; }
2614 if (!yyextra->parmType.empty()) yyextra->parmType += ' ' ;
2615 yyextra->parmType += yyextra->parmName ;
2616 yyextra->parmName.clear() ;
2617}
2618
2619static void addUsingDirective(yyscan_t yyscanner,const DString &name)
2620{
2621 //printf("AddUsingDirective(%s)\n",qPrint(name));
2622 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2623 if (yyextra->sourceFileDef && !name.empty())
2624 {
2626 if (nd)
2627 {
2628 yyextra->theUsingContext.emplace(name.str(),nd);
2629 }
2630 }
2631}
2632
2633static void setParameterList(yyscan_t yyscanner,const MemberDef *md)
2634{
2635 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2636 for (const Argument &a : md->argumentList())
2637 {
2638 yyextra->parmName = a.name;
2639 yyextra->parmType = a.type;
2640 size_t i = yyextra->parmType.find('*');
2641 if (i!=DString::npos) yyextra->parmType = yyextra->parmType.left(i);
2642 i = yyextra->parmType.find('&');
2643 if (i!=DString::npos) yyextra->parmType = yyextra->parmType.left(i);
2644 yyextra->parmType.stripPrefix("const ");
2645 yyextra->parmType=yyextra->parmType.stripWhiteSpace();
2646 addVariable(yyscanner,yyextra->parmType,yyextra->parmName);
2647 }
2648}
2649
2650static const ClassDef *stripClassName(yyscan_t yyscanner,const DString &s,const Definition *d)
2651{
2652 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2653 DBG_CTX((stderr,"stripClassName(scope=%s,type=%s) scopeName=%s\n",
2654 qPrint(d?d->name():""),qPrint(s),qPrint(yyextra->scopeName)));
2655 int pos=0;
2656 DString type = s;
2657 DString className;
2658 DString templSpec;
2659 while (extractClassNameFromType(type,pos,className,templSpec)!=-1)
2660 {
2661 DString clName=className+templSpec;
2662 const ClassDef *cd=nullptr;
2663 if (!yyextra->scopeName.empty())
2664 {
2665 cd=yyextra->symbolResolver.resolveClass(d,yyextra->scopeName+"::"+clName,true);
2666 }
2667 if (cd==nullptr)
2668 {
2669 cd=yyextra->symbolResolver.resolveClass(d,clName,true);
2670 }
2671 DBG_CTX((stderr,"stripClass trying '%s' = %p\n",qPrint(clName),(void*)cd));
2672 if (cd)
2673 {
2674 return cd;
2675 }
2676 }
2677
2678 return nullptr;
2679}
2680
2681static const MemberDef *setCallContextForVar(yyscan_t yyscanner,const DString &name)
2682{
2683 if (name.empty()) return nullptr;
2684 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2685 DBG_CTX((stderr,"setCallContextForVar(%s) yyextra->scopeName=%s\n",qPrint(name),qPrint(yyextra->scopeName)));
2686
2687 size_t scopeEnd = name.rfind("::");
2688 if (scopeEnd!=DString::npos) // name with explicit scope
2689 {
2690 DString scope = name.left(scopeEnd);
2691 DString locName = name.mid(scopeEnd+2);
2692 DBG_CTX((stderr,"explicit scope: name=%s scope=%s\n",qPrint(locName),qPrint(scope)));
2693 const ClassDef *mcd = getClass(scope);
2694 if (mcd && !locName.empty())
2695 {
2696 const MemberDef *md=mcd->getMemberByName(locName);
2697 if (md)
2698 {
2699 DBG_CTX((stderr,"name=%s scope=%s\n",qPrint(locName),qPrint(scope)));
2700 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,md->typeString(),md->getOuterScope())));
2701 return md;
2702 }
2703 }
2704 else // check namespace as well
2705 {
2706 const NamespaceDef *mnd = getResolvedNamespace(scope);
2707 if (mnd && !locName.empty())
2708 {
2709 const MemberDef *md=mnd->getMemberByName(locName);
2710 if (md)
2711 {
2712 DBG_CTX((stderr,"name=%s scope=%s\n",qPrint(locName),qPrint(scope)));
2713 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,md->typeString(),md->getOuterScope())));
2714 return md;
2715 }
2716 }
2717 }
2718 }
2719
2720 const ScopedTypeVariant *mcv = yyextra->theVarContext.findVariable(name);
2721 if (mcv)
2722 {
2723 DBG_CTX((stderr,"local variable?\n"));
2724 if (!mcv->isDummy()) // locally found variable
2725 {
2726 DBG_CTX((stderr,"local var '%s' mcd=%s\n",qPrint(name),qPrint(mcv->name())));
2727 yyextra->theCallContext.setScope(*mcv);
2728 }
2729 }
2730 else
2731 {
2732 DBG_CTX((stderr,"class member? scope=%s\n",qPrint(yyextra->scopeName)));
2733 // look for a class member
2734 const ClassDef *mcd = getClass(yyextra->scopeName);
2735 if (mcd)
2736 {
2737 DBG_CTX((stderr,"Inside class %s\n",qPrint(mcd->name())));
2738 const MemberDef *md=mcd->getMemberByName(name);
2739 if (md)
2740 {
2741 DBG_CTX((stderr,"Found member %s\n",qPrint(md->name())));
2742 if (yyextra->scopeStack.empty() || yyextra->scopeStack.top()!=CLASSBLOCK)
2743 {
2744 DBG_CTX((stderr,"class member '%s' mcd=%s\n",qPrint(name),qPrint(mcd->name())));
2745 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,md->typeString(),md->getOuterScope())));
2746 }
2747 return md;
2748 }
2749 }
2750 }
2751
2752 // look for a global member
2754 if (mn)
2755 {
2756 DBG_CTX((stderr,"global var '%s'\n",qPrint(name)));
2757 if (mn->size()==1) // global defined only once
2758 {
2759 const std::unique_ptr<MemberDef> &md=mn->front();
2760 if (!md->isStatic() || md->getBodyDef()==yyextra->sourceFileDef)
2761 {
2762 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,md->typeString(),md->getOuterScope())));
2763 return md.get();
2764 }
2765 return nullptr;
2766 }
2767 else if (mn->size()>1) // global defined more than once
2768 {
2769 for (const auto &md : *mn)
2770 {
2771 //printf("mn=%p md=%p md->getBodyDef()=%p yyextra->sourceFileDef=%p\n",
2772 // mn,md,
2773 // md->getBodyDef(),yyextra->sourceFileDef);
2774
2775 // in case there are multiple members we could link to, we
2776 // only link to members if defined in the same file or
2777 // defined as external.
2778 if (!md->isStatic() || md->getBodyDef()==yyextra->sourceFileDef)
2779 {
2780 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,md->typeString(),md->getOuterScope())));
2781 DBG_CTX((stderr,"returning member %s in source file %s\n",qPrint(md->name()),qPrint(yyextra->sourceFileDef->name())));
2782 return md.get();
2783 }
2784 }
2785 return nullptr;
2786 }
2787 }
2788 return nullptr;
2789}
2790
2792{
2793 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2794 const Definition *d = yyextra->theCallContext.getScope().globalDef();
2795 //printf("updateCallContextForSmartPointer() cd=%s\n",cd ? qPrint(d->name()) : "<none>");
2796 const MemberDef *md = nullptr;
2797 if (d && d->definitionType()==Definition::TypeClass && (md=(toClassDef(d))->isSmartPointer()))
2798 {
2799 const ClassDef *ncd = stripClassName(yyscanner,md->typeString(),md->getOuterScope());
2800 if (ncd)
2801 {
2802 yyextra->theCallContext.setScope(ScopedTypeVariant(ncd));
2803 //printf("Found smart pointer call %s->%s!\n",qPrint(cd->name()),qPrint(ncd->name()));
2804 }
2805 }
2806}
2807
2808static bool getLinkInScope(yyscan_t yyscanner,
2809 const DString &c, // scope
2810 const DString &m, // member
2811 const DString &memberText, // exact text
2812 OutputCodeList &ol,
2813 const DString &text,
2814 bool varOnly
2815 )
2816{
2817 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2818 DBG_CTX((stderr,"getLinkInScope: trying '%s'::'%s' varOnly=%d\n",qPrint(c),qPrint(m),varOnly));
2819 GetDefInput input(c,m,"()");
2820 input.currentFile = yyextra->sourceFileDef;
2821 input.insideCode = true;
2822 GetDefResult result = getDefs(input);
2823 DBG_CTX((stderr,"scopeNameLengthStack.size()=%zu\n",yyextra->scopeNameLengthStack.size()));
2824 if (!result.found && !yyextra->scopeNameLengthStack.empty() && c==yyextra->scopeName)
2825 {
2826 DString localName = yyextra->scopeName.mid(yyextra->scopeNameLengthStack[0]+2); // try also without leading scope
2827 auto it = yyextra->codeClassMap.find(localName.str());
2828 if (it!=yyextra->codeClassMap.end())
2829 {
2830 ScopedTypeVariant ccd = it->second;
2831 if (ccd.localDef() && !ccd.localDef()->baseClasses().empty())
2832 {
2833 for (const auto &bcName : ccd.localDef()->baseClasses())
2834 {
2835 DBG_CTX((stderr,"trying lookup via base class %s\n",qPrint(bcName)));
2836 input.scopeName = bcName;
2837 result = getDefs(input);
2838 if (result.found) break;
2839 }
2840 }
2841 }
2842 }
2843 if (result.found && result.md && (!varOnly || result.md->isVariable()))
2844 {
2845 if (result.md->isLinkable())
2846 {
2847 DBG_CTX((stderr,"found it %s!\n",qPrint(result.md->qualifiedName())));
2848 if (yyextra->exampleBlock)
2849 {
2850 std::lock_guard<std::mutex> lock(Doxygen::addExampleMutex);
2851 DString anchor;
2852 anchor.sprintf("a%d",yyextra->anchorCount);
2853 DBG_CTX((stderr,"addExampleFile(%s,%s,%s)\n",qPrint(anchor),qPrint(yyextra->exampleName),
2854 qPrint(yyextra->exampleFile)));
2855 MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(result.md));
2856 if (mdm && mdm->addExample(anchor,yyextra->exampleName,yyextra->exampleFile))
2857 {
2858 ol.writeCodeAnchor(anchor);
2859 yyextra->anchorCount++;
2860 }
2861 }
2862
2863 const Definition *d = result.md->getOuterScope()==Doxygen::globalScope ?
2864 result.md->resolveAlias()->getFileDef() : result.md->getOuterScope();
2865 if (result.md->resolveAlias()->getGroupDef()) d = result.md->resolveAlias()->getGroupDef();
2866 if (d && d->isLinkable())
2867 {
2868 const ClassDef *ncd = stripClassName(yyscanner,result.md->typeString(),result.md->getOuterScope());
2869 if (ncd)
2870 {
2871 yyextra->theCallContext.setScope(ScopedTypeVariant(ncd));
2872 }
2873 DBG_CTX((stderr,"yyextra->currentDefinition=%p yyextra->currentMemberDef=%p yyextra->insideBody=%d\n",
2874 (void*)yyextra->currentDefinition,(void*)yyextra->currentMemberDef,yyextra->insideBody));
2875
2876 if (yyextra->currentDefinition && yyextra->currentMemberDef &&
2877 yyextra->insideBody && yyextra->collectXRefs)
2878 {
2879 addDocCrossReference(yyextra->currentMemberDef,result.md);
2880 }
2881 DBG_CTX((stderr,"d->getReference()='%s' d->getOutputBase()='%s' name='%s' member name='%s'\n",qPrint(d->getReference()),qPrint(d->getOutputFileBase()),qPrint(d->name()),qPrint(result.md->name())));
2882
2883 writeMultiLineCodeLink(yyscanner,ol,result.md, !text.empty() ? text : memberText);
2884 addToSearchIndex(yyscanner,!text.empty() ? text : memberText);
2885 return true;
2886 }
2887 }
2888 }
2889 return false;
2890}
2891
2892static bool getLink(yyscan_t yyscanner,
2893 const DString &className,
2894 const DString &memberName,
2895 OutputCodeList &ol,
2896 const DString &text,
2897 bool varOnly)
2898{
2899 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2900 DBG_CTX((stderr,"getLink(%s,%s) yyextra->curClassName=%s\n",
2901 qPrint(className),qPrint(memberName),qPrint(yyextra->curClassName)));
2902 DString m=removeRedundantWhiteSpace(memberName);
2903 DString c=className;
2904 if (!getLinkInScope(yyscanner,c,m,memberName,ol,text,varOnly))
2905 {
2906 if (!yyextra->curClassName.empty())
2907 {
2908 if (!c.empty()) c.prepend("::");
2909 c.prepend(yyextra->curClassName);
2910 return getLinkInScope(yyscanner,c,m,memberName,ol,text,varOnly);
2911 }
2912 return false;
2913 }
2914 return true;
2915}
2916
2918 OutputCodeList &ol,
2919 const DString &scName,
2920 bool typeOnly,
2921 bool varOnly)
2922{
2923 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2924 DString scopeName=scName;
2925 if (!scopeName.empty() && scopeName[0]=='~') // correct for matching negated values i.s.o. destructors.
2926 {
2927 scopeName=scopeName.mid(1);
2928 }
2929 if (scopeName.empty())
2930 {
2931 yyextra->code->codify("~");
2932 return;
2933 }
2934 if (yyextra->insideProtocolList) // for Obj-C
2935 {
2936 scopeName+="-p";
2937 }
2938 if (yyextra->lang==SrcLangExt::PHP)
2939 {
2940 scopeName = substitute(scopeName,"\\","::"); // for PHP namespaces
2941 }
2942 else if (yyextra->lang==SrcLangExt::CSharp || yyextra->lang==SrcLangExt::Java)
2943 {
2944 scopeName = substitute(scopeName,".","::"); // for C#/Java namespaces
2945 }
2946 if (yyextra->currentDefinition==nullptr && !yyextra->scopeName.empty())
2947 {
2948 scopeName = yyextra->scopeName+"::"+scopeName;
2949 }
2950 const ScopedTypeVariant *lcd=nullptr;
2951 const Definition *sym=nullptr;
2952 bool isLocal=false;
2953
2954 DBG_CTX((stderr,"generateClassOrGlobalLink(name=%s) yyextra->scopeName=%s scopeName=%s\n",qPrint(scName),qPrint(yyextra->scopeName),qPrint(scopeName)));
2955 if (!yyextra->isPrefixedWithThis || (lcd=yyextra->theVarContext.findVariable(scopeName))==nullptr) // not a local variable
2956 {
2957 DString bareName = scopeName;
2958 if (size_t i=scopeName.find('<') ; i!=DString::npos) bareName = bareName.left(i);
2959
2960 auto checkForSymbol = [&yyg,&bareName,&scopeName](const Definition *parent,
2961 const Definition *&sym_)
2962 {
2963 sym_ = yyextra->symbolResolver.resolveSymbol(parent,scopeName,DString(),false,true);
2964 DBG_CTX((stderr,"non-local variable name=%s sym=%s!\n",
2965 qPrint(scopeName),sym_?qPrint(sym_->name()):"<none>"));
2966 if (sym_==nullptr && !bareName.empty())
2967 {
2968 DBG_CTX((stderr,"bareName=%s\n",qPrint(bareName)));
2969 if (bareName!=scopeName)
2970 {
2971 sym_ = yyextra->symbolResolver.resolveSymbol(parent,bareName,DString(),false,true); // try unspecialized version
2972 }
2973 }
2974 };
2975 const Definition *d = yyextra->currentDefinition;
2976 DBG_CTX((stderr,"d=%s yyextra->sourceFileDef=%s\n",d?qPrint(d->name()):"<none>",yyextra->sourceFileDef?qPrint(yyextra->sourceFileDef->name()):"<none>"));
2977 checkForSymbol(d,sym);
2978 if (sym==nullptr && d && d->definitionType()==Definition::TypeClass)
2979 {
2980 const FileDef *fd = toClassDef(d)->getFileDef();
2981 if (fd)
2982 {
2983 // also check for using directive in the file that defines this class
2984 for (const auto &nd : fd->getUsedNamespaces())
2985 {
2986 checkForSymbol(nd,sym);
2987 if (sym) break;
2988 }
2989 }
2990 }
2991 if (sym==nullptr)
2992 {
2993 // also check via using directive
2994 for (const auto &[usingName,namespaceDef] : yyextra->theUsingContext)
2995 {
2996 checkForSymbol(namespaceDef,sym);
2997 if (sym) break;
2998 }
2999 }
3000
3001 const NamespaceDef *nd = getResolvedNamespace(scopeName);
3002 if (nd && nd->isLinkable())
3003 {
3004 yyextra->theCallContext.setScope(ScopedTypeVariant(nd));
3005 addToSearchIndex(yyscanner,scopeName);
3006 writeMultiLineCodeLink(yyscanner,*yyextra->code,nd,scName);
3007 return;
3008 }
3009 const ConceptDef *conceptDef = getResolvedConcept(d,bareName);
3010 if (conceptDef && conceptDef->isLinkable())
3011 {
3012 yyextra->theCallContext.setScope(ScopedTypeVariant(conceptDef));
3013 addToSearchIndex(yyscanner,scopeName);
3014 writeMultiLineCodeLink(yyscanner,*yyextra->code,conceptDef,scName);
3015 return;
3016 }
3017 DBG_CTX((stderr,"sym=%s\n",sym?qPrint(sym->name()):"<none>"));
3018 DBG_CTX((stderr,"is found as a type sym=%s nd=%s\n",
3019 sym?qPrint(sym->name()):"<null>",
3020 nd?qPrint(nd->name()):"<null>"));
3021 if (sym==nullptr) // also see if it is variable or enum or enum value
3022 {
3023 if (getLink(yyscanner,yyextra->scopeName,scName,ol,scName,varOnly))
3024 {
3025 return;
3026 }
3027 }
3028 }
3029 else
3030 {
3031 DBG_CTX((stderr,"local variable!\n"));
3032 if (!lcd->isDummy())
3033 {
3034 DBG_CTX((stderr,"non-dummy context lcd=%s!\n",qPrint(lcd->name())));
3035 yyextra->theCallContext.setScope(*lcd);
3036
3037 // to following is needed for links to a global variable, but is
3038 // no good for a link to a local variable that is also a global symbol.
3039
3040 //if (getLink(yyscanner,yyextra->scopeName,scName,ol,scName))
3041 //{
3042 //return;
3043 //}
3044 }
3045 isLocal=true;
3046 DBG_CTX((stderr,"is a local variable sym=%p!\n",(void*)sym));
3047 }
3048 yyextra->isPrefixedWithThis = false; // discard the "this" prefix for the next calls
3049
3050 if (sym && sym->isLinkable()) // is it a linkable class
3051 {
3052 DBG_CTX((stderr,"%s is linkable type=%d\n",qPrint(sym->name()),int(sym->definitionType())));
3053 if (yyextra->exampleBlock)
3054 {
3055 std::lock_guard<std::mutex> lock(Doxygen::addExampleMutex);
3056 DString anchor;
3057 anchor.sprintf("_a%d",yyextra->anchorCount);
3058 DBG_CTX((stderr,"addExampleClass(%s,%s,%s)\n",qPrint(anchor),qPrint(yyextra->exampleName),
3059 qPrint(yyextra->exampleFile)));
3061 {
3062 ClassDefMutable *cdm = toClassDefMutable(const_cast<Definition*>(sym));
3063 if (cdm && cdm->addExample(anchor,yyextra->exampleName,yyextra->exampleFile))
3064 {
3065 ol.writeCodeAnchor(anchor);
3066 yyextra->anchorCount++;
3067 }
3068 }
3069 else if (sym->definitionType()==Definition::TypeMember)
3070 {
3071 MemberDefMutable *mdm = toMemberDefMutable(const_cast<Definition*>(sym));
3072 if (mdm && mdm->addExample(anchor,yyextra->exampleName,yyextra->exampleFile))
3073 {
3074 ol.writeCodeAnchor(anchor);
3075 yyextra->anchorCount++;
3076 }
3077 }
3078 }
3079 writeMultiLineCodeLink(yyscanner,ol,sym,scName);
3080 addToSearchIndex(yyscanner,scopeName);
3081 if (sym && sym->definitionType()==Definition::TypeMember)
3082 {
3083 const MemberDef *md = toMemberDef(sym);
3084 const Definition *d = sym->getOuterScope()==Doxygen::globalScope ?
3085 md->getFileDef() : md->getOuterScope();
3086 if (md->getGroupDef()) d = md->getGroupDef();
3087 if (d && d->isLinkable() && md->isLinkable() &&
3088 yyextra->currentMemberDef && yyextra->collectXRefs)
3089 {
3090 addDocCrossReference(yyextra->currentMemberDef,md);
3091 }
3092 setCallContextForVar(yyscanner,scName);
3093 }
3094 else
3095 {
3096 yyextra->theCallContext.setScope(ScopedTypeVariant(sym));
3097 }
3098 }
3099 else // not a class, maybe a global member
3100 {
3101 const MemberDef *md = sym && sym->definitionType()==Definition::TypeMember ? toMemberDef(sym) : nullptr;
3102 DBG_CTX((stderr,"class %s not linkable! cd=%p typeOnly=%d\n",qPrint(scName),(void*)sym,typeOnly));
3103 if (!isLocal && (md || (!sym && !typeOnly))) // not a class, see if it is a global enum/variable/typedef.
3104 {
3105 if (md==nullptr) // not found as a typedef
3106 {
3107 md = setCallContextForVar(yyscanner,scName);
3108 DBG_CTX((stderr,"setCallContextForVar(%s) md=%p yyextra->currentDefinition=%s\n",qPrint(scName),(void*)md,yyextra->currentDefinition ? qPrint(yyextra->currentDefinition->name()) : "<none>"));
3109 if (md && yyextra->currentDefinition)
3110 {
3111 DBG_CTX((stderr,"%s accessible from %s? %d md->getOuterScope=%s\n",
3112 qPrint(md->name()),qPrint(yyextra->currentDefinition->name()),
3113 yyextra->symbolResolver.isAccessibleFrom(yyextra->currentDefinition,md),
3114 qPrint(md->getOuterScope()->name())));
3115 }
3116
3117 if (md && yyextra->currentDefinition &&
3118 yyextra->symbolResolver.isAccessibleFrom(yyextra->currentDefinition,md)==-1)
3119 {
3120 md=nullptr; // variable not accessible
3121 }
3122 }
3123 if (md && (!varOnly || md->isVariable()))
3124 {
3125 DBG_CTX((stderr,"is a global md=%p yyextra->currentDefinition=%s linkable=%d\n",(void*)md,yyextra->currentDefinition?qPrint(yyextra->currentDefinition->name()):"<none>",md->isLinkable()));
3126 if (md->isLinkable())
3127 {
3128 writeMultiLineCodeLink(yyscanner,ol,md,scName);
3129 addToSearchIndex(yyscanner,scName);
3130 if (yyextra->currentMemberDef && yyextra->collectXRefs)
3131 {
3132 addDocCrossReference(yyextra->currentMemberDef,md);
3133 }
3134 return;
3135 }
3136 }
3137 }
3138
3139 // nothing found, just write out the word
3140 DBG_CTX((stderr,"not found!\n"));
3141 codifyLines(yyscanner,scName);
3142 addToSearchIndex(yyscanner,scName);
3143 }
3144}
3145
3146static bool generateClassMemberLink(yyscan_t yyscanner,
3147 OutputCodeList &ol,
3148 const MemberDef *xmd,
3149 const DString &memName)
3150{
3151 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3152 // extract class definition of the return type in order to resolve
3153 // a->b()->c() like call chains
3154
3155 DBG_CTX((stderr,"type='%s' args='%s' class=%s\n",
3156 qPrint(xmd->typeString()),qPrint(xmd->argsString()),
3157 qPrint(xmd->getClassDef()->name())));
3158
3159 if (yyextra->exampleBlock)
3160 {
3161 std::lock_guard<std::mutex> lock(Doxygen::addExampleMutex);
3162 DString anchor;
3163 anchor.sprintf("a%d",yyextra->anchorCount);
3164 DBG_CTX((stderr,"addExampleFile(%s,%s,%s)\n",qPrint(anchor),qPrint(yyextra->exampleName),
3165 qPrint(yyextra->exampleFile)));
3166 MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(xmd));
3167 if (mdm && mdm->addExample(anchor,yyextra->exampleName,yyextra->exampleFile))
3168 {
3169 ol.writeCodeAnchor(anchor);
3170 yyextra->anchorCount++;
3171 }
3172 }
3173
3174 const ClassDef *typeClass = stripClassName(yyscanner,removeAnonymousScopes(xmd->typeString()),xmd->getOuterScope());
3175 DBG_CTX((stderr,"%s -> typeName=%p\n",qPrint(xmd->typeString()),(void*)typeClass));
3176 yyextra->theCallContext.setScope(ScopedTypeVariant(typeClass));
3177
3178 const Definition *xd = xmd->getOuterScope()==Doxygen::globalScope ?
3179 xmd->getFileDef() : xmd->getOuterScope();
3180 if (xmd->getGroupDef()) xd = xmd->getGroupDef();
3181 if (xd && xd->isLinkable())
3182 {
3183
3184 DBG_CTX((stderr,"yyextra->currentDefinition=%p yyextra->currentMemberDef=%p xmd=%p yyextra->insideBody=%d\n",
3185 (void*)yyextra->currentDefinition,(void*)yyextra->currentMemberDef,(void*)xmd,yyextra->insideBody));
3186
3187 if (xmd->templateMaster()) xmd = xmd->templateMaster();
3188
3189 if (xmd->isLinkable())
3190 {
3191 // add usage reference
3192 if (yyextra->currentDefinition && yyextra->currentMemberDef &&
3193 yyextra->insideBody && yyextra->collectXRefs)
3194 {
3195 addDocCrossReference(yyextra->currentMemberDef,xmd);
3196 }
3197
3198 // write the actual link
3199 writeMultiLineCodeLink(yyscanner,ol,xmd,memName);
3200 addToSearchIndex(yyscanner,memName);
3201 return true;
3202 }
3203 }
3204
3205 return false;
3206}
3207
3208static bool generateClassMemberLink(yyscan_t yyscanner,
3209 OutputCodeList &ol,
3210 const Definition *def,
3211 const DString &memName)
3212{
3213 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3214 if (def && def->definitionType()==Definition::TypeClass)
3215 {
3216 const ClassDef *cd = toClassDef(def);
3217 const MemberDef *xmd = cd->getMemberByName(memName);
3218 DBG_CTX((stderr,"generateClassMemberLink(class=%s,member=%s)=%p\n",qPrint(def->name()),qPrint(memName),(void*)xmd));
3219 if (xmd)
3220 {
3221 return generateClassMemberLink(yyscanner,ol,xmd,memName);
3222 }
3223 else
3224 {
3225 const Definition *innerDef = cd->findInnerCompound(memName);
3226 if (innerDef)
3227 {
3228 yyextra->theCallContext.setScope(ScopedTypeVariant(innerDef));
3229 addToSearchIndex(yyscanner,memName);
3230 writeMultiLineCodeLink(yyscanner,*yyextra->code,innerDef,memName);
3231 return true;
3232 }
3233 }
3234 }
3235 else if (def && def->definitionType()==Definition::TypeNamespace)
3236 {
3237 const NamespaceDef *nd = toNamespaceDef(def);
3238 DBG_CTX((stderr,"Looking for %s inside namespace %s\n",qPrint(memName),qPrint(nd->name())));
3239 const Definition *innerDef = nd->findInnerCompound(memName);
3240 if (innerDef)
3241 {
3242 yyextra->theCallContext.setScope(ScopedTypeVariant(innerDef));
3243 addToSearchIndex(yyscanner,memName);
3244 writeMultiLineCodeLink(yyscanner,*yyextra->code,innerDef,memName);
3245 return true;
3246 }
3247 }
3248 return false;
3249}
3250
3251static void generateMemberLink(yyscan_t yyscanner,
3252 OutputCodeList &ol,
3253 const DString &varName,
3254 const DString &memName)
3255{
3256 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3257 DBG_CTX((stderr,"generateMemberLink(object=%s,mem=%s) classScope=%s\n",
3258 qPrint(varName),qPrint(memName),qPrint(yyextra->scopeName)));
3259
3260 if (varName.empty()) return;
3261
3262 // look for the variable in the current context
3263 const ScopedTypeVariant *stv = yyextra->theVarContext.findVariable(varName);
3264 if (stv)
3265 {
3266 if (!stv->isDummy())
3267 {
3268 DBG_CTX((stderr,"Class found!\n"));
3269 if (getLink(yyscanner,stv->name(),memName,ol))
3270 {
3271 DBG_CTX((stderr,"Found result!\n"));
3272 return;
3273 }
3274 if (stv->localDef() && !stv->localDef()->baseClasses().empty())
3275 {
3276 for (const auto &bcName : stv->localDef()->baseClasses())
3277 {
3278 if (getLink(yyscanner,bcName,memName,ol))
3279 {
3280 DBG_CTX((stderr,"Found result!\n"));
3281 return;
3282 }
3283 }
3284 }
3285 }
3286 }
3287 else // variable not in current context, maybe it is in a parent context
3288 {
3289 const ClassDef *vcd = yyextra->symbolResolver.resolveClass(yyextra->currentDefinition,yyextra->scopeName,true);
3290 if (vcd && vcd->isLinkable())
3291 {
3292 DBG_CTX((stderr,"Found class %s for variable '%s'\n",qPrint(yyextra->scopeName),qPrint(varName)));
3294 if (vmn==nullptr)
3295 {
3296 DString vn=varName;
3297 if (size_t vi=vn.rfind("::"); vi!=DString::npos || (vi=vn.rfind('.'))!=DString::npos) // explicit scope A::b(), probably static member
3298 {
3299 const ClassDef *jcd = getClass(vn.left(vi));
3300 vn=vn.mid(vi+2);
3302 //printf("Trying name '%s' scope=%s\n",qPrint(vn),qPrint(scope));
3303 if (vmn)
3304 {
3305 for (const auto &vmd : *vmn)
3306 {
3307 if (vmd->getClassDef()==jcd)
3308 {
3309 DBG_CTX((stderr,"Found variable type=%s\n",qPrint(vmd->typeString())));
3310 const ClassDef *mcd=stripClassName(yyscanner,vmd->typeString(),vmd->getOuterScope());
3311 if (mcd && mcd->isLinkable())
3312 {
3313 if (generateClassMemberLink(yyscanner,ol,mcd,memName)) return;
3314 }
3315 }
3316 }
3317 }
3318 }
3319 }
3320 if (vmn)
3321 {
3322 DBG_CTX((stderr,"There is a variable with name '%s'\n",qPrint(varName)));
3323 for (const auto &vmd : *vmn)
3324 {
3325 if (vmd->getClassDef()==vcd)
3326 {
3327 DBG_CTX((stderr,"Found variable type=%s\n",qPrint(vmd->typeString())));
3328 const ClassDef *mcd=stripClassName(yyscanner,vmd->typeString(),vmd->getOuterScope());
3329 if (mcd && mcd->isLinkable())
3330 {
3331 if (generateClassMemberLink(yyscanner,ol,mcd,memName)) return;
3332 }
3333 }
3334 }
3335 }
3336 }
3337 }
3338 // nothing found -> write result as is
3339 codifyLines(yyscanner,memName);
3340 addToSearchIndex(yyscanner,memName);
3341 return;
3342}
3343
3344static void generatePHPVariableLink(yyscan_t yyscanner,OutputCodeList &ol,const char *varName)
3345{
3346 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3347 DString name(varName+7); // strip $this->
3348 name.prepend("$");
3349 DBG_CTX((stderr,"generatePHPVariableLink(%s) name=%s scope=%s\n",varName,qPrint(name),qPrint(yyextra->scopeName)));
3350 if (!getLink(yyscanner,yyextra->scopeName,name,ol,varName))
3351 {
3352 codifyLines(yyscanner,varName);
3353 }
3354}
3355
3356static void generateFunctionLink(yyscan_t yyscanner,OutputCodeList &ol,const DString &funcName)
3357{
3358 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3359 //CodeClassDef *ccd=nullptr;
3360 DString locScope=yyextra->scopeName;
3361 DString locFunc=removeRedundantWhiteSpace(funcName);
3362 if (yyextra->lang==SrcLangExt::PHP && locFunc.startsWith("self::")) locFunc=locFunc.mid(4);
3363 DString funcScope;
3364 DString funcWithScope=locFunc;
3365 DString funcWithFullScope=locFunc;
3366 DString fullScope=locScope;
3367 DBG_CTX((stderr,"*** locScope=%s locFunc=%s\n",qPrint(locScope),qPrint(locFunc)));
3368 size_t len=2;
3369 size_t i=locFunc.rfind("::");
3370 if (yyextra->currentMemberDef && yyextra->currentMemberDef->resolveAlias()->getClassDef() &&
3371 funcName==yyextra->currentMemberDef->localName() &&
3372 yyextra->currentMemberDef->getDefLine()==yyextra->yyLineNr &&
3373 generateClassMemberLink(yyscanner,ol,yyextra->currentMemberDef,funcName)
3374 )
3375 {
3376 // special case where funcName is the name of a method that is also
3377 // defined on this line. In this case we can directly link to
3378 // yyextra->currentMemberDef, which is not only faster, but
3379 // in case of overloaded methods, this will make sure that we link to
3380 // the correct method, and thereby get the correct reimplemented relations.
3381 // See also bug 549022.
3382 goto exit;
3383 }
3384 if (i==DString::npos)
3385 {
3386 i=locFunc.rfind(".");
3387 len=1;
3388 }
3389 if (i==DString::npos)
3390 {
3391 i=locFunc.rfind("\\");
3392 len=1; // for PHP
3393 }
3394 if (i!=DString::npos && i>0)
3395 {
3396 funcScope=locFunc.left(i);
3397 locFunc=locFunc.mid(i+len).stripWhiteSpace();
3398 size_t ts=locScope.find('<'); // start of template
3399 size_t te=locScope.rfind('>'); // end of template
3400 DBG_CTX((stderr,"ts=%zu te=%zu\n",ts,te));
3401 if (ts!=DString::npos && te!=DString::npos && te>ts)
3402 {
3403 // remove template from scope
3404 locScope=locScope.left(ts)+locScope.mid(te+1);
3405 }
3406 ts=funcScope.find('<'); // start of template
3407 te=funcScope.rfind('>'); // end of template
3408 DBG_CTX((stderr,"ts=%zu te=%zu\n",ts,te));
3409 if (ts!=DString::npos && te!=DString::npos && te>ts)
3410 {
3411 // remove template from scope
3412 funcScope=funcScope.left(ts)+funcScope.mid(te+1);
3413 }
3414 if (!funcScope.empty())
3415 {
3416 funcWithScope = funcScope+"::"+locFunc;
3417 if (!locScope.empty())
3418 {
3419 fullScope=locScope+"::"+funcScope;
3420 }
3421 }
3422 if (!locScope.empty())
3423 {
3424 funcWithFullScope = locScope+"::"+funcWithScope;
3425 }
3426 }
3427
3428 if (!fullScope.empty())
3429 {
3430 auto it = yyextra->codeClassMap.find(fullScope.str());
3431 if (it!=yyextra->codeClassMap.end())
3432 {
3433 ScopedTypeVariant ccd = it->second;
3434 if (ccd.localDef() && !ccd.localDef()->baseClasses().empty())
3435 {
3436 for (const auto &bcName : ccd.localDef()->baseClasses())
3437 {
3438 if (getLink(yyscanner,bcName,locFunc,ol,funcName))
3439 {
3440 goto exit;
3441 }
3442 }
3443 }
3444 }
3445 }
3446
3447 if (!locScope.empty() && fullScope!=locScope)
3448 {
3449 auto it = yyextra->codeClassMap.find(locScope.str());
3450 if (it!=yyextra->codeClassMap.end())
3451 {
3452 ScopedTypeVariant ccd = it->second;
3453 if (ccd.localDef() && !ccd.localDef()->baseClasses().empty())
3454 {
3455 for (const auto &bcName : ccd.localDef()->baseClasses())
3456 {
3457 if (getLink(yyscanner,bcName,funcWithScope,ol,funcName))
3458 {
3459 goto exit;
3460 }
3461 }
3462 }
3463 }
3464 }
3465 if (!getLink(yyscanner,locScope,funcWithScope,ol,funcName))
3466 {
3467 generateClassOrGlobalLink(yyscanner,ol,funcName);
3468 }
3469exit:
3470 return;
3471}
3472
3473/*! counts the number of lines in the input */
3474static int countLines(yyscan_t yyscanner)
3475{
3476 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3477 const char *p=yyextra->inputString;
3478 char c = 0;
3479 int count=1;
3480 while ((c=*p))
3481 {
3482 p++ ;
3483 if (c=='\n') count++;
3484 }
3485 if (p>yyextra->inputString && *(p-1)!='\n')
3486 { // last line does not end with a \n, so we add an extra
3487 count++;
3488 }
3489 return count;
3490}
3491
3492static void endFontClass(yyscan_t yyscanner,bool specialComment)
3493{
3494 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3495 if (yyextra->currentFontClass)
3496 {
3497 yyextra->code->endFontClass();
3498 yyextra->currentFontClass=nullptr;
3499 }
3500 if (specialComment && yyextra->insideSpecialComment)
3501 {
3502 yyextra->code->endSpecialComment();
3503 yyextra->insideSpecialComment = false;
3504 }
3505}
3506
3507static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment)
3508{
3509 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3510 endFontClass(yyscanner);
3511 if (specialComment)
3512 {
3513 yyextra->code->startSpecialComment();
3514 yyextra->insideSpecialComment = true;
3515 }
3516 yyextra->code->startFontClass(s);
3517 yyextra->currentFontClass=s;
3518}
3519
3520//----------------------------------------------------------------------------
3521
3522// recursively writes a linkified Objective-C method call
3523static void writeObjCMethodCall(yyscan_t yyscanner,ObjCCallCtx *ctx)
3524{
3525 if (ctx==nullptr) return;
3526 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3527 char c = 0;
3528 if (!ctx->methodName.empty())
3529 {
3530 DBG_CTX((stderr,"writeObjCMethodCall(%s) obj=%s method=%s\n",
3532 if (!ctx->objectTypeOrName.empty() && ctx->objectTypeOrName.at(0)!='$')
3533 {
3534 DBG_CTX((stderr,"Looking for object=%s method=%s\n",qPrint(ctx->objectTypeOrName),
3535 qPrint(ctx->methodName)));
3536 const ScopedTypeVariant *stv = yyextra->theVarContext.findVariable(ctx->objectTypeOrName);
3537 if (stv!=nullptr) // local variable
3538 {
3539 DBG_CTX((stderr," object is local variable\n"));
3540 if (stv->globalDef() && !ctx->methodName.empty())
3541 {
3542 const ClassDef *cd = toClassDef(stv->globalDef());
3543 if (cd)
3544 {
3545 ctx->method = cd->getMemberByName(ctx->methodName);
3546 }
3547 DBG_CTX((stderr," class=%p method=%p\n",(void*)cd,(void*)ctx->method));
3548 }
3549 }
3550 }
3551 }
3552
3553 DBG_CTX((stderr,"["));
3554 if (!ctx->format.empty())
3555 {
3556 const char *p = ctx->format.data();
3557 bool skip = false;
3558 char skipChar = ' ';
3559 while ((c=*p++)) // for each character in ctx->format
3560 {
3561 if (skip)
3562 {
3563 char s[2];
3564 s[0]=c;s[1]=0;
3565 codifyLines(yyscanner,s);
3566 if (c==skipChar)
3567 {
3568 skip = false;
3569 skipChar = ' ';
3570 }
3571 else if (c=='\\')
3572 {
3573 c = *p++;
3574 s[0]=c;
3575 codifyLines(yyscanner,s);
3576 }
3577 }
3578 else if (c=='$')
3579 {
3580 char nc=*p++;
3581 if (nc=='$') // escaped $
3582 {
3583 yyextra->code->codify("$");
3584 }
3585 else // name fragment or reference to a nested call
3586 {
3587 if (nc=='n') // name fragment
3588 {
3589 nc=*p++;
3590 DString refIdStr;
3591 while (nc!=0 && isdigit(nc)) { refIdStr+=nc; nc=*p++; }
3592 p--;
3593 int refId=refIdStr.toInt();
3594 auto it = yyextra->nameMap.find(refId);
3595 if (it!=yyextra->nameMap.end())
3596 {
3597 DString name = it->second;
3598 if (ctx->method && ctx->method->isLinkable())
3599 {
3600 writeMultiLineCodeLink(yyscanner,*yyextra->code,ctx->method,name);
3601 if (yyextra->currentMemberDef && yyextra->collectXRefs)
3602 {
3603 addDocCrossReference(yyextra->currentMemberDef,ctx->method);
3604 }
3605 }
3606 else
3607 {
3608 codifyLines(yyscanner,name);
3609 }
3610 }
3611 else
3612 {
3613 DBG_CTX((stderr,"Invalid name: id=%d\n",refId));
3614 }
3615 }
3616 else if (nc=='o') // reference to potential object name, e.g. 'self', or 'self.var1' or 'self.var1.var2'
3617 {
3618 nc=*p++;
3619 DString refIdStr;
3620 while (nc!=0 && isdigit(nc)) { refIdStr+=nc; nc=*p++; }
3621 p--;
3622 int refId=refIdStr.toInt();
3623 auto it = yyextra->objectMap.find(refId);
3624 if (it!=yyextra->objectMap.end())
3625 {
3626 DString object = it->second;
3627 if (object=="self")
3628 {
3629 if (yyextra->currentDefinition &&
3630 yyextra->currentDefinition->definitionType()==Definition::TypeClass)
3631 {
3632 ctx->objectType = toClassDef(yyextra->currentDefinition);
3633 if (ctx->objectType->categoryOf())
3634 {
3635 ctx->objectType = ctx->objectType->categoryOf();
3636 }
3637 if (ctx->objectType && !ctx->methodName.empty())
3638 {
3639 ctx->method = ctx->objectType->getMemberByName(ctx->methodName);
3640 }
3641 }
3642 startFontClass(yyscanner,"keyword");
3643 codifyLines(yyscanner,object);
3644 endFontClass(yyscanner);
3645 }
3646 else if (object=="super")
3647 {
3648 if (yyextra->currentDefinition &&
3649 yyextra->currentDefinition->definitionType()==Definition::TypeClass)
3650 {
3651 const ClassDef *cd = toClassDef(yyextra->currentDefinition);
3652 if (cd->categoryOf())
3653 {
3654 cd = cd->categoryOf();
3655 }
3656 for (const auto &bclass : cd->baseClasses())
3657 {
3658 if (bclass.classDef->compoundType()!=ClassDef::Protocol)
3659 {
3660 ctx->objectType = bclass.classDef;
3661 if (ctx->objectType && !ctx->methodName.empty())
3662 {
3663 ctx->method = ctx->objectType->getMemberByName(ctx->methodName);
3664 }
3665 }
3666 }
3667 }
3668 startFontClass(yyscanner,"keyword");
3669 codifyLines(yyscanner,object);
3670 endFontClass(yyscanner);
3671 }
3672 else if (ctx->objectVar && ctx->objectVar->isLinkable()) // object is class variable
3673 {
3674 writeMultiLineCodeLink(yyscanner,*yyextra->code,ctx->objectVar,object);
3675 if (yyextra->currentMemberDef && yyextra->collectXRefs)
3676 {
3677 addDocCrossReference(yyextra->currentMemberDef,ctx->objectVar);
3678 }
3679 }
3680 else if (ctx->objectType && ctx->objectType->isLinkable()) // object is class name
3681 {
3682 const ClassDef *cd = ctx->objectType;
3683 writeMultiLineCodeLink(yyscanner,*yyextra->code,cd,object);
3684 }
3685 else // object still needs to be resolved
3686 {
3687 size_t pp = 0;
3688 size_t dotPos = object.find('.',pp);
3689 size_t len = object.length();
3690 if (dotPos==DString::npos) dotPos=len;
3691 const Definition *scope = yyextra->currentDefinition;
3692 //printf("initial scope=%s\n",scope?qPrint(scope->name()):"none");
3693 for (;;)
3694 {
3695 DString fragment = object.mid(pp,dotPos-pp);
3696 DString fragmentStripped = fragment.stripWhiteSpace();
3697 //printf("fragment=%s\n",qPrint(fragment));
3698 if (fragmentStripped=="self")
3699 {
3700 if (scope && scope->definitionType()==Definition::TypeClass)
3701 {
3702 scope = ctx->objectType = toClassDef(scope);
3703 }
3704 //printf("self scope=%s\n",scope?qPrint(scope->name()):"none");
3705 startFontClass(yyscanner,"keyword");
3706 codifyLines(yyscanner,fragment);
3707 endFontClass(yyscanner);
3708 }
3709 else
3710 {
3711 const Definition *symbol = yyextra->symbolResolver.resolveSymbol(scope,fragmentStripped,DString(),false,true);
3712 //printf("scope=%s name=%s -> symbol=%s\n",scope?qPrint(scope->name()):"none",qPrint(fragment),
3713 // symbol?qPrint(symbol->name()):"none");
3714 if (symbol && symbol->definitionType()==Definition::TypeClass)
3715 {
3716 scope = ctx->objectType = toClassDef(symbol);
3717 ctx->method = yyextra->symbolResolver.getTypedef();
3718 }
3719 else if (symbol && symbol->definitionType()==Definition::TypeMember)
3720 {
3721 scope = ctx->objectType = stripClassName(yyscanner,toMemberDef(symbol)->typeString(),scope);
3722 }
3723 if (scope && scope!=Doxygen::globalScope)
3724 {
3725 writeMultiLineCodeLink(yyscanner,*yyextra->code,scope,fragment);
3726 }
3727 else
3728 {
3729 codifyLines(yyscanner,fragment);
3730 }
3731 //printf("new scope=%s\n",scope?qPrint(scope->name()):"none");
3732 }
3733 if (dotPos==len)
3734 {
3735 break;
3736 }
3737 else // find next fragment
3738 {
3739 codifyLines(yyscanner,".");
3740 pp=dotPos+1;
3741 dotPos=object.find('.',pp);
3742 if (dotPos==DString::npos) dotPos=len;
3743 }
3744 }
3745 DBG_CTX((stderr," object is class? %p\n",(void*)ctx->objectType));
3746 if (ctx->objectType) // found class
3747 {
3748 ctx->method = ctx->objectType->getMemberByName(ctx->methodName);
3749 DBG_CTX((stderr," yes->method=%s\n",ctx->method?qPrint(ctx->method->name()):"<none>"));
3750 }
3751 else if (ctx->method==nullptr) // search for class variable with the same name
3752 {
3753 DBG_CTX((stderr," no\n"));
3754 DBG_CTX((stderr,"yyextra->currentDefinition=%p\n",(void*)yyextra->currentDefinition));
3755 if (yyextra->currentDefinition &&
3756 yyextra->currentDefinition->definitionType()==Definition::TypeClass)
3757 {
3758 ctx->objectVar = (toClassDef(yyextra->currentDefinition))->getMemberByName(ctx->objectTypeOrName);
3759 DBG_CTX((stderr," ctx->objectVar=%p\n",(void*)ctx->objectVar));
3760 if (ctx->objectVar)
3761 {
3762 ctx->objectType = stripClassName(yyscanner,ctx->objectVar->typeString(),yyextra->currentDefinition);
3763 DBG_CTX((stderr," ctx->objectType=%p\n",(void*)ctx->objectType));
3764 if (ctx->objectType && !ctx->methodName.empty())
3765 {
3766 ctx->method = ctx->objectType->getMemberByName(ctx->methodName);
3767 DBG_CTX((stderr," ctx->method=%p\n",(void*)ctx->method));
3768 }
3769 }
3770 }
3771 }
3772 }
3773 }
3774 else
3775 {
3776 DBG_CTX((stderr,"Invalid object: id=%d\n",refId));
3777 }
3778 }
3779 else if (nc=='c') // reference to nested call
3780 {
3781 nc=*p++;
3782 DString refIdStr;
3783 while (nc!=0 && isdigit(nc)) { refIdStr+=nc; nc=*p++; }
3784 p--;
3785 int refId=refIdStr.toInt();
3786 auto it = yyextra->contextMap.find(refId);
3787 if (it!=yyextra->contextMap.end()) // recurse into nested call
3788 {
3789 ObjCCallCtx *ictx = it->second.get();
3790 writeObjCMethodCall(yyscanner,ictx);
3791 if (ictx->method) // link to nested call successfully
3792 {
3793 // get the ClassDef representing the method's return type
3794 if (ictx->method->typeString()=="id")
3795 {
3796 // see if the method name is unique, if so we link to it
3798 //printf("mn->count=%d ictx->method=%s ctx->methodName=%s\n",
3799 // mn==0?-1:(int)mn->count(),
3800 // qPrint(ictx->method->name()),
3801 // qPrint(ctx->methodName));
3802 if (mn && mn->size()==1) // member name unique
3803 {
3804 ctx->method = mn->front().get();
3805 }
3806 }
3807 else
3808 {
3809 ctx->objectType = stripClassName(yyscanner,ictx->method->typeString(),yyextra->currentDefinition);
3810 if (ctx->objectType && !ctx->methodName.empty())
3811 {
3812 ctx->method = ctx->objectType->getMemberByName(ctx->methodName);
3813 }
3814 }
3815 DBG_CTX((stderr," ***** method=%s -> object=%p\n",qPrint(ictx->method->name()),(void*)ctx->objectType));
3816 }
3817 }
3818 else
3819 {
3820 DBG_CTX((stderr,"Invalid context: id=%d\n",refId));
3821 }
3822 }
3823 else if (nc=='w') // some word
3824 {
3825 nc=*p++;
3826 DString refIdStr;
3827 while (nc!=0 && isdigit(nc)) { refIdStr+=nc; nc=*p++; }
3828 p--;
3829 int refId=refIdStr.toInt();
3830 auto it = yyextra->wordMap.find(refId);
3831 if (it!=yyextra->wordMap.end())
3832 {
3833 DString word = it->second;
3834 bool isKeyword = word=="self";
3835 if (isKeyword)
3836 {
3837 startFontClass(yyscanner,"keyword");
3838 }
3839 codifyLines(yyscanner,word);
3840 if (isKeyword)
3841 {
3842 endFontClass(yyscanner);
3843 }
3844 }
3845 }
3846 else if (nc=='d') // comment block
3847 {
3848 nc=*p++;
3849 DString refIdStr;
3850 while (nc!=0 && isdigit(nc)) { refIdStr+=nc; nc=*p++; }
3851 p--;
3852 int refId=refIdStr.toInt();
3853 auto it = yyextra->commentMap.find(refId);
3854 if (it!=yyextra->commentMap.end())
3855 {
3856 DString comment = it->second;
3857 startFontClass(yyscanner,"comment");
3858 codifyLines(yyscanner,comment);
3859 endFontClass(yyscanner);
3860 }
3861 }
3862 else // illegal marker
3863 {
3864 ASSERT(0); // "invalid escape sequence"
3865 }
3866 }
3867 }
3868 else if (c=='\'' || c == '"')
3869 {
3870 char s[2];
3871 s[0]=c;s[1]=0;
3872 codifyLines(yyscanner,s);
3873 skip = true;
3874 skipChar = c;
3875 }
3876 else // normal non-marker character
3877 {
3878 char s[2];
3879 s[0]=c;s[1]=0;
3880 codifyLines(yyscanner,s);
3881 }
3882 }
3883 }
3884 DBG_CTX((stderr,"%s %s]\n",qPrint(ctx->objectTypeOrName),qPrint(ctx->methodName)));
3885 DBG_CTX((stderr,"}=(type='%s',name='%s')",
3887 qPrint(ctx->methodName)));
3888}
3889
3890// Replaces an Objective-C method name fragment s by a marker of the form
3891// $n12, the number (12) can later be used as a key for obtaining the name
3892// fragment, from yyextra->nameMap
3893static DString escapeName(yyscan_t yyscanner,const DString &s)
3894{
3895 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3896 DString result;
3897 result.sprintf("$n%d",yyextra->currentNameId);
3898 yyextra->nameMap.emplace(yyextra->currentNameId,s);
3899 yyextra->currentNameId++;
3900 return result;
3901}
3902
3903static DString escapeObject(yyscan_t yyscanner,const DString &s)
3904{
3905 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3906 DString result;
3907 result.sprintf("$o%d",yyextra->currentObjId);
3908 yyextra->objectMap.emplace(yyextra->currentObjId,s);
3909 yyextra->currentObjId++;
3910 return result;
3911}
3912
3913static DString escapeWord(yyscan_t yyscanner,const DString &s)
3914{
3915 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3916 DString result;
3917 result.sprintf("$w%d",yyextra->currentWordId);
3918 yyextra->wordMap.emplace(yyextra->currentWordId,s);
3919 yyextra->currentWordId++;
3920 return result;
3921}
3922
3923static DString escapeComment(yyscan_t yyscanner,const DString &s)
3924{
3925 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3926 DString result;
3927 result.sprintf("$d%d",yyextra->currentCommentId);
3928 yyextra->commentMap.emplace(yyextra->currentCommentId,s);
3929 yyextra->currentCommentId++;
3930 return result;
3931}
3932
3933static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
3934{
3935 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3936 static const std::unordered_set<std::string> non_cpp_keywords = {
3937 "__assume", "__super", "abstract", "function",
3938 "gcnew", "gcroot", "generic", "get",
3939 "internal", "null", "pin_ptr", "raise",
3940 "remove", "self", "set", "transient",
3941 "sealed", "record"
3942 };
3943 static const std::unordered_set<std::string> non_java_keywords = {
3944 "alignas", "alignof", "and", "and_eq", "asm",
3945 "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand",
3946 "bitor", "bool", "char8_t", "char16_t", "char32_t",
3947 "compl", "concept", "consteval", "constexpr", "constinit",
3948 "const_cast", "co_await", "co_return", "co_yield", "decltype",
3949 "delete", "dynamic_cast", "explicit", "export", "extern",
3950 "friend", "inline", "mutable", "namespace", "noexcept",
3951 "not", "not_eq", "nullptr", "operator", "or",
3952 "or_eq", "reflexpr", "register", "reinterpret_cast", "requires",
3953 "signed", "sizeof", "static_assert", "_Static_assert", "static_cast", "struct",
3954 "template", "thread_local", "typedef", "typeid", "typename",
3955 "union", "unsigned", "using", "virtual", "wchar_t",
3956 "xor", "xor_eq", "override", "sealed"
3957 };
3958 bool retval = false;
3959 switch (yyextra->lang)
3960 {
3961 case SrcLangExt::Cpp:
3962 retval = (non_cpp_keywords.find(keyword) != non_cpp_keywords.end());
3963 break;
3964 case SrcLangExt::Java:
3965 retval = (non_java_keywords.find(keyword) != non_java_keywords.end());
3966 break;
3967 default:
3968 retval = false;
3969 break;
3970 }
3971 return retval;
3972}
3973
3974static bool isCastKeyword(const char *keyword)
3975{
3976 DString s(keyword);
3977 size_t i=s.find('<');
3978 if (i==DString::npos) return false;
3979 DString kw = s.left(i).stripWhiteSpace();
3980 return kw=="const_cast" || kw=="static_cast" || kw=="dynamic_cast" || kw=="reinterpret_cast";
3981}
3982
3983static int yyread(yyscan_t yyscanner,char *buf,int max_size)
3984{
3985 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3986 yy_size_t inputPosition = yyextra->inputPosition;
3987 const char *s = yyextra->inputString + inputPosition;
3988 int c=0;
3989 while( c < max_size && *s )
3990 {
3991 *buf++ = *s++;
3992 c++;
3993 }
3994 yyextra->inputPosition += c;
3995 return c;
3996}
3997
3998
3999static void saveObjCContext(yyscan_t yyscanner)
4000{
4001 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4002 if (yyextra->currentCtx)
4003 {
4004 yyextra->currentCtx->format+=DString().sprintf("$c%d",yyextra->currentCtxId);
4005 if (yyextra->braceCount==0 && YY_START==ObjCCall)
4006 {
4007 yyextra->currentCtx->objectTypeOrName=yyextra->currentCtx->format.mid(1);
4008 DBG_CTX((stderr,"new type=%s\n",qPrint(yyextra->currentCtx->objectTypeOrName)));
4009 }
4010 yyextra->contextStack.push(yyextra->currentCtx);
4011 }
4012 else
4013 {
4014 DBG_CTX((stderr,"Trying to save NULL context!\n"));
4015 }
4016 auto newCtx = std::make_unique<ObjCCallCtx>();
4017 newCtx->id = yyextra->currentCtxId;
4018 newCtx->lexState = YY_START;
4019 newCtx->braceCount = yyextra->braceCount;
4020 newCtx->objectType = nullptr;
4021 newCtx->objectVar = nullptr;
4022 newCtx->method = nullptr;
4023 DBG_CTX((stderr,"save state=%d\n",YY_START));
4024 yyextra->currentCtx = newCtx.get();
4025 yyextra->contextMap.emplace(yyextra->currentCtxId,std::move(newCtx));
4026 yyextra->braceCount = 0;
4027 yyextra->currentCtxId++;
4028}
4029
4030static void restoreObjCContext(yyscan_t yyscanner)
4031{
4032 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4033 DBG_CTX((stderr,"restore state=%d->%d\n",YY_START,yyextra->currentCtx->lexState));
4034 BEGIN(yyextra->currentCtx->lexState);
4035 yyextra->braceCount = yyextra->currentCtx->braceCount;
4036 if (!yyextra->contextStack.empty())
4037 {
4038 yyextra->currentCtx = yyextra->contextStack.top();
4039 yyextra->contextStack.pop();
4040 }
4041 else
4042 {
4043 yyextra->currentCtx = nullptr;
4044 DBG_CTX((stderr,"Trying to pop context while yyextra->contextStack is empty!\n"));
4045 }
4046}
4047
4053
4055{
4056 codeYYlex_init_extra(&p->state,&p->yyscanner);
4057#ifdef FLEX_DEBUG
4058 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4059#endif
4061}
4062
4064{
4065 codeYYlex_destroy(p->yyscanner);
4066}
4067
4069{
4070 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4071 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4072 yyextra->theVarContext.clear();
4073 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4074 yyextra->codeClassMap.clear();
4075 yyextra->curClassBases.clear();
4076 yyextra->anchorCount = 0;
4077 yyextra->insideCodeLine = false;
4078}
4079
4081{
4082 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4083 yyextra->insideCodeLine = inp;
4084}
4085
4087{
4088 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4089 return yyextra->insideCodeLine;
4090}
4091
4092void CCodeParser::parseCode(OutputCodeList &od,const DString &scopeName,const DString &s,
4093 SrcLangExt lang,bool stripCodeComments,const CodeParserOptions &options)
4094{
4095 yyscan_t yyscanner = p->yyscanner;
4096 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4097 DBG_CTX((stderr,"***parseCode() exBlock=%d exName=%s fd=%p scopeName=%s searchCtx=%s\n",
4098 options.isExample(),qPrint(options.exampleName()),(void*)options.fileDef(),
4099 qPrint(scopeName),options.searchCtx()?qPrint(options.searchCtx()->name()):"<none>"));
4100
4101 if (s.empty()) return;
4102
4103 DebugLex debugLex(Debug::Lex_code, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()) :
4104 !options.exampleName().empty() ? qPrint(options.exampleName()) : nullptr);
4105
4106 od.stripCodeComments(stripCodeComments);
4107 yyextra->code = &od;
4108 yyextra->inputString = s.data();
4109 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
4110 yyextra->absFileName = options.fileDef() ? options.fileDef()->absFilePath():"";
4111 yyextra->inputPosition = 0;
4112 codeYYrestart(nullptr,yyscanner);
4113 yyextra->currentFontClass = nullptr;
4114 yyextra->searchCtx = options.searchCtx();
4115 yyextra->collectXRefs = options.collectXRefs();
4116 yyextra->inFunctionTryBlock = false;
4117 yyextra->symbolResolver.setFileScope(options.fileDef());
4118 yyextra->foldStack.clear();
4119 yyextra->insideSpecialComment = false;
4120 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
4121 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
4122 yyextra->curlyCount = 0;
4123 yyextra->bodyCurlyCount = 0;
4124 yyextra->bracketCount = 0;
4125 yyextra->sharpCount = 0;
4126 yyextra->insideTemplate = false;
4127 yyextra->theCallContext.clear();
4128 while (!yyextra->scopeStack.empty()) yyextra->scopeStack.pop();
4129 yyextra->scopeName = scopeName;
4130 DBG_CTX((stderr,"parseCCode %s\n",qPrint(scopeName)));
4131 yyextra->exampleBlock = options.isExample();
4132 yyextra->exampleName = options.exampleName();
4133 yyextra->sourceFileDef = options.fileDef();
4134 yyextra->lineNumbers = options.fileDef() && options.showLineNumbers();
4135 if (options.fileDef()==nullptr)
4136 {
4137 // create a dummy filedef for the example
4138 yyextra->exampleFileDef = createFileDef(DString(),(!options.exampleName().empty()?options.exampleName():"generated"));
4139 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
4140 }
4141 yyextra->lang = lang;
4142 yyextra->insideObjC = lang==SrcLangExt::ObjC;
4143 if (yyextra->sourceFileDef)
4144 {
4145 setCurrentDoc(yyscanner,"l00001");
4146 }
4147 yyextra->currentDefinition = options.searchCtx() ? options.searchCtx() : getResolvedNamespace(scopeName);
4148 yyextra->currentMemberDef = nullptr;
4149 yyextra->searchingForBody = options.isExample();
4150 yyextra->insideBody = false;
4151 yyextra->bracketCount = 0;
4152 if (!yyextra->exampleName.empty())
4153 {
4154 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example",false,true);
4155 DBG_CTX((stderr,"yyextra->exampleFile=%s\n",qPrint(yyextra->exampleFile)));
4156 }
4157 yyextra->includeCodeFragment = options.inlineFragment();
4158 DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",options.isExample(),qPrint(options.exampleName()),options.inlineFragment()));
4159 if (!yyextra->insideCodeLine)
4160 {
4161 startCodeLine(yyscanner);
4162 }
4163 yyextra->type.clear();
4164 yyextra->name.clear();
4165 yyextra->args.clear();
4166 yyextra->parmName.clear();
4167 yyextra->parmType.clear();
4168 if (options.memberDef()) setParameterList(yyscanner,options.memberDef());
4169 BEGIN( Body );
4170 codeYYlex(yyscanner);
4171 yyextra->lexInit=true;
4172 if (yyextra->insideCodeLine)
4173 {
4174 endCodeLine(yyscanner);
4175 }
4176 if (Config_getBool(HTML_CODE_FOLDING))
4177 {
4178 while (!yyextra->foldStack.empty())
4179 {
4180 yyextra->code->endFold();
4181 yyextra->foldStack.pop_back();
4182 }
4183 }
4184 if (yyextra->exampleFileDef)
4185 {
4186 // delete the temporary file definition used for this example
4187 yyextra->exampleFileDef.reset();
4188 yyextra->sourceFileDef=nullptr;
4189 }
4190 // write the tooltips
4191 yyextra->tooltipManager.writeTooltips(od);
4192}
4193
4194#include "code.l.h"
This class contains the information about the argument of a function or template.
Definition arguments.h:27
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4068
CCodeParser()
Definition code.l:4054
void setInsideCodeLine(bool inp)
Definition code.l:4080
~CCodeParser() override
Definition code.l:4063
std::unique_ptr< Private > p
Definition code.h:42
void parseCode(OutputCodeList &codeOutIntf, const DString &scopeName, const DString &input, SrcLangExt lang, bool stripCodeComments, const CodeParserOptions &options) override
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
Definition code.l:4092
bool insideCodeLine() const
Definition code.l:4086
virtual const MemberDef * getMemberByName(const DString &) const =0
Returns the member with the given name.
virtual const BaseClassList & baseClasses() const =0
Returns the list of base classes from which this class directly inherits.
virtual ClassDef * categoryOf() const =0
Returns the class of which this is a category (Objective-C only).
virtual FileDef * getFileDef() const =0
Returns the file in which this compound's definition can be found.
virtual bool addExample(const DString &anchor, const DString &name, const DString &file)=0
void clear()
Definition dstring.h:214
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
Definition dstring.cpp:127
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
int toInt(bool *ok=nullptr, int base=10) const
Definition dstring.cpp:191
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
const std::string & str() const
Definition dstring.h:645
bool stripPrefix(const DString &prefix)
Definition dstring.h:290
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
bool startsWith(const char *s) const
Definition dstring.h:600
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
@ Lex_code
Definition debug.h:54
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
virtual int getEndBodyLine() const =0
virtual DefType definitionType() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual bool isLinkableInProject() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual int getStartDefLine() const =0
virtual DString getReference() const =0
virtual CodeSymbolType codeSymbolType() const =0
virtual Definition * getOuterScope() const =0
virtual const Definition * findInnerCompound(const DString &name) const =0
virtual DString getOutputFileBase() const =0
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static std::mutex countFlowKeywordsMutex
Definition doxygen.h:132
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static SearchIndexIntf searchIndex
Definition doxygen.h:117
static std::mutex addExampleMutex
Definition doxygen.h:133
virtual DString fileName() const =0
virtual const LinkedRefMap< NamespaceDef > & getUsedNamespaces() const =0
std::vector< DString > baseClasses() const
virtual DString argsString() const =0
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual const FileDef * getFileDef() const =0
virtual const ArgumentList & argumentList() const =0
virtual MemberDef * resolveAlias()=0
virtual bool isDefine() const =0
virtual bool isVariable() const =0
virtual DString typeString() const =0
virtual bool isCallable() const =0
virtual void incrementFlowKeyWordCount()=0
virtual bool addExample(const DString &anchor, const DString &name, const DString &file)=0
Ptr & front()
Definition membername.h:49
size_t size() const
Definition membername.h:46
An abstract interface of a namespace symbol.
virtual const MemberDef * getMemberByName(const DString &) const =0
void writeCodeAnchor(const DString &name)
Definition outputlist.h:273
void writeCodeLink(CodeSymbolType type, const DString &ref, const DString &file, const DString &anchor, const DString &name, const DString &tooltip)
Definition outputlist.h:247
void stripCodeComments(bool b)
Definition outputlist.h:235
DString name() const
const Definition * globalDef() const
void addWord(const DString &word, bool hiPriority)
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
ClassDefMutable * toClassDefMutable(Definition *d)
ClassDef * getClass(const DString &n)
static void codeFolding(yyscan_t yyscanner, const Definition *d)
Definition code.l:2361
ConceptDef * getResolvedConcept(const Definition *d, const DString &name)
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:1335
std::unique_ptr< FileDef > createFileDef(const DString &p, const DString &n, const DString &ref, const DString &dn)
Definition filedef.cpp:270
void addDocCrossReference(const MemberDef *s, const MemberDef *d)
MemberDefMutable * toMemberDefMutable(Definition *d)
MemberDef * toMemberDef(Definition *d)
#define ASSERT(x)
Definition message.h:142
NamespaceDef * getResolvedNamespace(const DString &name)
NamespaceDef * toNamespaceDef(Definition *d)
Definition dstring.h:913
codeYY_state state
Definition code.l:4051
yyscan_t yyscanner
Definition code.l:4050
Options to configure the code parser.
Definition parserintf.h:77
bool isExample() const
Definition parserintf.h:80
const Definition * searchCtx() const
Definition parserintf.h:88
DString exampleName() const
Definition parserintf.h:81
const FileDef * fileDef() const
Definition parserintf.h:82
int endLine() const
Definition parserintf.h:84
const MemberDef * memberDef() const
Definition parserintf.h:86
bool showLineNumbers() const
Definition parserintf.h:87
bool inlineFragment() const
Definition parserintf.h:85
int startLine() const
Definition parserintf.h:83
bool collectXRefs() const
Definition parserintf.h:89
const FileDef * currentFile
Definition util.h:103
bool insideCode
Definition util.h:105
DString scopeName
Definition util.h:99
const MemberDef * md
Definition util.h:113
bool found
Definition util.h:112
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2995
bool leftScopeMatch(const DString &scope, const DString &name)
Definition util.cpp:745
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1926
int extractClassNameFromType(const DString &type, int &pos, DString &name, DString &templSpec, SrcLangExt lang)
Definition util.cpp:3512
DString removeAnonymousScopes(const DString &str)
Definition util.cpp:98