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