/
docparser.cpp
7741 lines (7299 loc) · 256 KB
/
docparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Copyright (C) 1997-2021 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <ctype.h>
#include "qcstring.h"
#include "regex.h"
#include "doxygen.h"
#include "debug.h"
#include "util.h"
#include "pagedef.h"
#include "docparser.h"
#include "doctokenizer.h"
#include "cmdmapper.h"
#include "printdocvisitor.h"
#include "message.h"
#include "section.h"
#include "searchindex.h"
#include "language.h"
#include "portable.h"
#include "cite.h"
#include "arguments.h"
#include "vhdldocgen.h"
#include "groupdef.h"
#include "classlist.h"
#include "filedef.h"
#include "memberdef.h"
#include "namespacedef.h"
#include "reflist.h"
#include "formula.h"
#include "config.h"
#include "growbuf.h"
#include "markdown.h"
#include "htmlentity.h"
#include "emoji.h"
#include "fileinfo.h"
#include "dir.h"
#define TK_COMMAND_CHAR(token) ((token)==TK_COMMAND_AT ? "@" : "\\")
// debug off
#define DBG(x) do {} while(0)
// debug to stdout
//#define DBG(x) printf x
// debug to stderr
//#define myprintf(...) fprintf(stderr,__VA_ARGS__)
//#define DBG(x) myprintf x
#define INTERNAL_ASSERT(x) do {} while(0)
//#define INTERNAL_ASSERT(x) if (!(x)) DBG(("INTERNAL_ASSERT(%s) failed retval=0x%x: file=%s line=%d\n",#x,retval,__FILE__,__LINE__));
//---------------------------------------------------------------------------
static const char *g_sectionLevelToName[] =
{
"page",
"section",
"subsection",
"subsubsection",
"paragraph",
"subparagraph"
};
static const std::set<std::string> g_plantumlEngine {
"uml", "bpm", "wire", "dot", "ditaa",
"salt", "math", "latex", "gantt", "mindmap",
"wbs", "yaml", "creole", "json", "flow",
"board", "git"
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
using DefinitionStack = std::vector<const Definition *>;
using DocNodeStack = std::stack<const DocNode *>;
//using DocStyleChangeStack = std::stack<const DocStyleChange *>;
template<typename T, typename Container = std::deque<T>>
class iterable_stack
: public std::stack<T, Container>
{
using std::stack<T, Container>::c;
public:
// expose just the iterators of the underlying container
auto begin() { return std::begin(c); }
auto end() { return std::end(c); }
auto begin() const { return std::begin(c); }
auto end() const { return std::end(c); }
};
using DocStyleChangeStack = iterable_stack<const DocStyleChange *>;
/** Parser's context to store all global variables.
*/
struct DocParserContext
{
const Definition *scope;
QCString context;
bool inSeeBlock;
bool xmlComment;
bool insideHtmlLink;
DocNodeStack nodeStack;
DocStyleChangeStack styleStack;
DocStyleChangeStack initialStyleStack;
DefinitionStack copyStack;
QCString fileName;
QCString relPath;
bool hasParamCommand;
bool hasReturnCommand;
StringMultiSet retvalsFound;
StringMultiSet paramsFound;
const MemberDef * memberDef;
bool isExample;
QCString exampleName;
QCString searchUrl;
QCString includeFileName;
QCString includeFileText;
uint includeFileOffset;
uint includeFileLength;
int includeFileLine;
bool includeFileShowLineNo;
TokenInfo *token;
int lineNo;
bool markdownSupport;
};
class DocParser : public IDocParser
{
public:
void pushContext();
void popContext();
void handleImg(DocNode *parent,DocNodeList &children,const HtmlAttribList &tagHtmlAttribs);
int internalValidatingParseDoc(DocNode *parent,DocNodeList &children,
const QCString &doc);
QCString processCopyDoc(const char *data,uint &len);
QCString findAndCopyImage(const QCString &fileName,DocImage::Type type, bool doWarn = true);
void checkArgumentName();
void checkRetvalName();
void checkUnOrMultipleDocumentedParams();
bool findDocsForMemberOrCompound(const QCString &commandName,
QCString *pDoc,
QCString *pBrief,
const Definition **pDef);
bool defaultHandleToken(DocNode *parent,int tok,
DocNodeList &children,bool
handleWord=TRUE);
void errorHandleDefaultToken(DocNode *parent,int tok,
DocNodeList &children,const QCString &txt);
void defaultHandleTitleAndSize(const int cmd, DocNode *parent,
DocNodeList &children, QCString &width,QCString &height);
int handleStyleArgument(DocNode *parent,DocNodeList &children,
const QCString &cmdName);
void handleStyleEnter(DocNode *parent,DocNodeList &children, DocStyleChange::Style s,
const QCString &tagName,const HtmlAttribList *attribs);
void handleStyleLeave(DocNode *parent,DocNodeList &children, DocStyleChange::Style s,
const QCString &tagName);
void handlePendingStyleCommands(DocNode *parent,DocNodeList &children);
void handleInitialStyleCommands(DocPara *parent,DocNodeList &children);
int handleAHref(DocNode *parent,DocNodeList &children,const HtmlAttribList &tagHtmlAttribs);
void handleUnclosedStyleCommands();
void handleLinkedWord(DocNode *parent,DocNodeList &children,bool ignoreAutoLinkFlag=FALSE);
void handleParameterType(DocNode *parent,DocNodeList &children,const QCString ¶mTypes);
DocInternalRef *handleInternalRef(DocNode *parent);
DocAnchor *handleAnchor(DocNode *parent);
void readTextFileByName(const QCString &file,QCString &text);
std::stack< DocParserContext > contextStack;
DocParserContext context;
DocTokenizer tokenizer;
};
std::unique_ptr<IDocParser> createDocParser()
{
return std::make_unique<DocParser>();
}
//---------------------------------------------------------------------------
class AutoNodeStack
{
public:
AutoNodeStack(DocParser &parser,const DocNode* node)
: m_parser(parser), m_node(node) { m_parser.context.nodeStack.push(node); }
~AutoNodeStack() {
#if defined(NDEBUG)
(void)m_node;
if (!m_parser.context.nodeStack.empty()) m_parser.context.nodeStack.pop(); // robust version that does not assert
#else
assert(m_parser.context.nodeStack.top()==m_node); m_parser.context.nodeStack.pop(); // error checking version
#endif
}
private:
DocParser &m_parser;
const DocNode *m_node;
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void DocParser::pushContext()
{
//QCString indent;
//indent.fill(' ',contextStack.size()*2+2);
//printf("%sdocParserPushContext() count=%zu\n",qPrint(indent),context.nodeStack.size());
tokenizer.pushContext();
contextStack.push(DocParserContext());
auto &ctx = contextStack.top();
ctx = context;
ctx.lineNo = tokenizer.getLineNr();
context.token = tokenizer.newToken();
}
void DocParser::popContext()
{
auto &ctx = contextStack.top();
context = ctx;
tokenizer.setLineNr(ctx.lineNo);
context.token = ctx.token;
tokenizer.replaceToken(context.token);
contextStack.pop();
tokenizer.popContext();
//QCString indent;
//indent.fill(' ',contextStack.size()*2+2);
//printf("%sdocParserPopContext() count=%zu\n",qPrint(indent),context.nodeStack.size());
}
//---------------------------------------------------------------------------
// replaces { with < and } with > and also
// replaces > with < and > with > within string s
static void unescapeCRef(QCString &s)
{
QCString result;
const char *p = s.data();
if (p)
{
char c;
while ((c=*p++))
{
if (c=='{') c='<'; else if (c=='}') c='>';
result+=c;
}
}
result=substitute(result,"<","<");
result=substitute(result,">",">");
s = result;
}
//---------------------------------------------------------------------------
/*! search for an image in the imageNameDict and if found
* copies the image to the output directory (which depends on the \a type
* parameter).
*/
QCString DocParser::findAndCopyImage(const QCString &fileName, DocImage::Type type, bool doWarn)
{
QCString result;
bool ambig;
FileDef *fd = findFileDef(Doxygen::imageNameLinkedMap,fileName,ambig);
//printf("Search for %s\n",fileName);
if (fd)
{
if (ambig & doWarn)
{
QCString text;
text.sprintf("image file name %s is ambiguous.\n",qPrint(fileName));
text+="Possible candidates:\n";
text+=showFileDefMatches(Doxygen::imageNameLinkedMap,fileName);
warn_doc_error(context.fileName,tokenizer.getLineNr(),"%s", qPrint(text));
}
QCString inputFile = fd->absFilePath();
FileInfo infi(inputFile.str());
if (infi.exists())
{
result = fileName;
int i;
if ((i=result.findRev('/'))!=-1 || (i=result.findRev('\\'))!=-1)
{
result = result.right((int)result.length()-i-1);
}
//printf("fileName=%s result=%s\n",fileName,qPrint(result));
QCString outputDir;
switch(type)
{
case DocImage::Html:
if (!Config_getBool(GENERATE_HTML)) return result;
outputDir = Config_getString(HTML_OUTPUT);
break;
case DocImage::Latex:
if (!Config_getBool(GENERATE_LATEX)) return result;
outputDir = Config_getString(LATEX_OUTPUT);
break;
case DocImage::DocBook:
if (!Config_getBool(GENERATE_DOCBOOK)) return result;
outputDir = Config_getString(DOCBOOK_OUTPUT);
break;
case DocImage::Rtf:
if (!Config_getBool(GENERATE_RTF)) return result;
outputDir = Config_getString(RTF_OUTPUT);
break;
case DocImage::Xml:
if (!Config_getBool(GENERATE_XML)) return result;
outputDir = Config_getString(XML_OUTPUT);
break;
}
QCString outputFile = outputDir+"/"+result;
FileInfo outfi(outputFile.str());
if (outfi.isSymLink())
{
Dir().remove(outputFile.str());
warn_doc_error(context.fileName,tokenizer.getLineNr(),
"destination of image %s is a symlink, replacing with image",
qPrint(outputFile));
}
if (outputFile!=inputFile) // prevent copying to ourself
{
if (copyFile(inputFile,outputFile) && type==DocImage::Html)
{
Doxygen::indexList->addImageFile(result);
}
}
}
else
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),
"could not open image %s",qPrint(fileName));
}
if (type==DocImage::Latex && Config_getBool(USE_PDFLATEX) &&
fd->name().right(4)==".eps"
)
{ // we have an .eps image in pdflatex mode => convert it to a pdf.
QCString outputDir = Config_getString(LATEX_OUTPUT);
QCString baseName = fd->name().left(fd->name().length()-4);
QCString epstopdfArgs(4096);
epstopdfArgs.sprintf("\"%s/%s.eps\" --outfile=\"%s/%s.pdf\"",
qPrint(outputDir), qPrint(baseName),
qPrint(outputDir), qPrint(baseName));
Portable::sysTimerStart();
if (Portable::system("epstopdf",epstopdfArgs)!=0)
{
err("Problems running epstopdf. Check your TeX installation!\n");
}
Portable::sysTimerStop();
return baseName;
}
}
else
{
result=fileName;
if (result.left(5)!="http:" && result.left(6)!="https:" && doWarn)
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),
"image file %s is not found in IMAGE_PATH: "
"assuming external image.",qPrint(fileName)
);
}
}
return result;
}
/*! Collects the parameters found with \@param command
* in a list context.paramsFound. If
* the parameter is not an actual parameter of the current
* member context.memberDef, then a warning is raised (unless warnings
* are disabled altogether).
*/
void DocParser::checkArgumentName()
{
if (!Config_getBool(WARN_IF_DOC_ERROR)) return;
if (context.memberDef==0) return; // not a member
std::string name = context.token->name.str();
const ArgumentList &al=context.memberDef->isDocsForDefinition() ?
context.memberDef->argumentList() :
context.memberDef->declArgumentList();
SrcLangExt lang = context.memberDef->getLanguage();
//printf("isDocsForDefinition()=%d\n",context.memberDef->isDocsForDefinition());
if (al.empty()) return; // no argument list
static const reg::Ex re(R"(\$?\w+\.*)");
reg::Iterator it(name,re);
reg::Iterator end;
for (; it!=end ; ++it)
{
const auto &match = *it;
QCString aName=match.str();
if (lang==SrcLangExt_Fortran) aName=aName.lower();
//printf("aName='%s'\n",qPrint(aName));
bool found=FALSE;
for (const Argument &a : al)
{
QCString argName = context.memberDef->isDefine() ? a.type : a.name;
if (lang==SrcLangExt_Fortran) argName=argName.lower();
argName=argName.stripWhiteSpace();
//printf("argName='%s' aName=%s\n",qPrint(argName),qPrint(aName));
if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
if (aName==argName)
{
context.paramsFound.insert(aName.str());
found=TRUE;
break;
}
}
if (!found)
{
//printf("member type=%d\n",context.memberDef->memberType());
QCString scope=context.memberDef->getScopeString();
if (!scope.isEmpty()) scope+="::"; else scope="";
QCString inheritedFrom = "";
QCString docFile = context.memberDef->docFile();
int docLine = context.memberDef->docLine();
const MemberDef *inheritedMd = context.memberDef->inheritsDocsFrom();
if (inheritedMd) // documentation was inherited
{
inheritedFrom.sprintf(" inherited from member %s at line "
"%d in file %s",qPrint(inheritedMd->name()),
inheritedMd->docLine(),qPrint(inheritedMd->docFile()));
docFile = context.memberDef->getDefFileName();
docLine = context.memberDef->getDefLine();
}
QCString alStr = argListToString(al);
warn_doc_error(docFile,docLine,
"argument '%s' of command @param "
"is not found in the argument list of %s%s%s%s",
qPrint(aName), qPrint(scope), qPrint(context.memberDef->name()),
qPrint(alStr), qPrint(inheritedFrom));
}
}
}
/*! Collects the return values found with \@retval command
* in a global list g_parserContext.retvalsFound.
*/
void DocParser::checkRetvalName()
{
QCString name = context.token->name;
if (!Config_getBool(WARN_IF_DOC_ERROR)) return;
if (context.memberDef==0 || name.isEmpty()) return; // not a member or no valid name
if (context.retvalsFound.count(name.str())==1) // only report the first double entry
{
warn_doc_error(context.memberDef->getDefFileName(),
context.memberDef->getDefLine(),
"%s",
qPrint("return value '" + name + "' of " +
QCString(context.memberDef->qualifiedName()) +
" has multiple documentation sections"));
}
context.retvalsFound.insert(name.str());
}
/*! Checks if the parameters that have been specified using \@param are
* indeed all parameters and that a parameter does not have multiple
* \@param blocks.
* Must be called after checkArgumentName() has been called for each
* argument.
*/
void DocParser::checkUnOrMultipleDocumentedParams()
{
if (context.memberDef && context.hasParamCommand)
{
const ArgumentList &al=context.memberDef->isDocsForDefinition() ?
context.memberDef->argumentList() :
context.memberDef->declArgumentList();
SrcLangExt lang = context.memberDef->getLanguage();
if (!al.empty())
{
ArgumentList undocParams;
for (const Argument &a: al)
{
QCString argName = context.memberDef->isDefine() ? a.type : a.name;
if (lang==SrcLangExt_Fortran) argName = argName.lower();
argName=argName.stripWhiteSpace();
QCString aName = argName;
if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
if (lang==SrcLangExt_Python && (argName=="self" || argName=="cls"))
{
// allow undocumented self / cls parameter for Python
}
else if (!argName.isEmpty())
{
size_t count = context.paramsFound.count(argName.str());
if (count==0 && a.docs.isEmpty())
{
undocParams.push_back(a);
}
else if (count>1 && Config_getBool(WARN_IF_DOC_ERROR))
{
warn_doc_error(context.memberDef->getDefFileName(),
context.memberDef->getDefLine(),
"%s",
qPrint("argument '" + aName +
"' from the argument list of " +
QCString(context.memberDef->qualifiedName()) +
" has multiple @param documentation sections"));
}
}
}
if (!undocParams.empty() && Config_getBool(WARN_IF_INCOMPLETE_DOC))
{
bool first=TRUE;
QCString errMsg = "The following parameter";
if (undocParams.size()>1) errMsg+="s";
errMsg+=" of "+
QCString(context.memberDef->qualifiedName()) +
QCString(argListToString(al)) +
(undocParams.size()>1 ? " are" : " is") + " not documented:\n";
for (const Argument &a : undocParams)
{
QCString argName = context.memberDef->isDefine() ? a.type : a.name;
if (lang==SrcLangExt_Fortran) argName = argName.lower();
argName=argName.stripWhiteSpace();
if (!first) errMsg+="\n";
first=FALSE;
errMsg+=" parameter '"+argName+"'";
}
warn_incomplete_doc(context.memberDef->getDefFileName(),
context.memberDef->getDefLine(),
"%s",
qPrint(substitute(errMsg,"%","%%")));
}
}
}
}
//---------------------------------------------------------------------------
/*! Strips known html and tex extensions from \a text. */
static QCString stripKnownExtensions(const QCString &text)
{
QCString result=text;
if (result.right(4)==".tex")
{
result=result.left(result.length()-4);
}
else if (result.right(Doxygen::htmlFileExtension.length())==
QCString(Doxygen::htmlFileExtension))
{
result=result.left(result.length()-Doxygen::htmlFileExtension.length());
}
return result;
}
//---------------------------------------------------------------------------
/*! Returns TRUE iff node n is a child of a preformatted node */
static bool insidePRE(DocNode *n)
{
while (n)
{
if (n->isPreformatted()) return TRUE;
n=n->parent();
}
return FALSE;
}
//---------------------------------------------------------------------------
/*! Returns TRUE iff node n is a child of a html list item node */
static bool insideLI(DocNode *n)
{
while (n)
{
if (n->kind()==DocNode::Kind_HtmlListItem) return TRUE;
n=n->parent();
}
return FALSE;
}
//---------------------------------------------------------------------------
/*! Returns TRUE iff node n is a child of a unordered html list node */
static bool insideUL(DocNode *n)
{
while (n)
{
if (n->kind()==DocNode::Kind_HtmlList &&
((DocHtmlList *)n)->type()==DocHtmlList::Unordered) return TRUE;
n=n->parent();
}
return FALSE;
}
//---------------------------------------------------------------------------
/*! Returns TRUE iff node n is a child of a ordered html list node */
static bool insideOL(DocNode *n)
{
while (n)
{
if (n->kind()==DocNode::Kind_HtmlList &&
((DocHtmlList *)n)->type()==DocHtmlList::Ordered) return TRUE;
n=n->parent();
}
return FALSE;
}
//---------------------------------------------------------------------------
static bool insideTable(DocNode *n)
{
while (n)
{
if (n->kind()==DocNode::Kind_HtmlTable) return TRUE;
n=n->parent();
}
return FALSE;
}
static const DocStyleChange *insideDetails(DocStyleChangeStack styleStack)
{
const DocStyleChange *retItem = NULL;
for (auto i : styleStack)
{
if (i->style() == DocStyleChange::Details) retItem = i;
}
return retItem;
}
//---------------------------------------------------------------------------
/*! Looks for a documentation block with name commandName in the current
* context (g_parserContext.context). The resulting documentation string is
* put in pDoc, the definition in which the documentation was found is
* put in pDef.
* @retval TRUE if name was found.
* @retval FALSE if name was not found.
*/
bool DocParser::findDocsForMemberOrCompound(const QCString &commandName,
QCString *pDoc,
QCString *pBrief,
const Definition **pDef)
{
//printf("findDocsForMemberOrCompound(%s)\n",commandName);
*pDoc="";
*pBrief="";
*pDef=0;
QCString cmdArg=commandName;
if (cmdArg.isEmpty()) return FALSE;
const FileDef *fd=0;
const GroupDef *gd=0;
const PageDef *pd=0;
gd = Doxygen::groupLinkedMap->find(cmdArg);
if (gd) // group
{
*pDoc=gd->documentation();
*pBrief=gd->briefDescription();
*pDef=gd;
return TRUE;
}
pd = Doxygen::pageLinkedMap->find(cmdArg);
if (pd) // page
{
*pDoc=pd->documentation();
*pBrief=pd->briefDescription();
*pDef=pd;
return TRUE;
}
bool ambig;
fd = findFileDef(Doxygen::inputNameLinkedMap,cmdArg,ambig);
if (fd && !ambig) // file
{
*pDoc=fd->documentation();
*pBrief=fd->briefDescription();
*pDef=fd;
return TRUE;
}
// for symbols we need to normalize the separator, so A#B, or A\B, or A.B becomes A::B
cmdArg = substitute(cmdArg,"#","::");
cmdArg = substitute(cmdArg,"\\","::");
static bool extractAnonNs = Config_getBool(EXTRACT_ANON_NSPACES);
if (extractAnonNs &&
cmdArg.startsWith("anonymous_namespace{")
)
{
size_t rightBracePos = cmdArg.find("}", static_cast<int>(qstrlen("anonymous_namespace{")));
QCString leftPart = cmdArg.left(rightBracePos + 1);
QCString rightPart = cmdArg.right(cmdArg.size() - rightBracePos - 1);
rightPart = substitute(rightPart, ".", "::");
cmdArg = leftPart + rightPart;
}
else
{
cmdArg = substitute(cmdArg,".","::");
}
int l=(int)cmdArg.length();
int funcStart=cmdArg.find('(');
if (funcStart==-1)
{
funcStart=l;
}
else
{
// Check for the case of operator() and the like.
// beware of scenarios like operator()((foo)bar)
int secondParen = cmdArg.find('(', funcStart+1);
int leftParen = cmdArg.find(')', funcStart+1);
if (leftParen!=-1 && secondParen!=-1)
{
if (leftParen<secondParen)
{
funcStart=secondParen;
}
}
}
QCString name=removeRedundantWhiteSpace(cmdArg.left(funcStart));
QCString args=cmdArg.right(l-funcStart);
// try if the link is to a member
const MemberDef *md=0;
const ClassDef *cd=0;
const NamespaceDef *nd=0;
bool found = getDefs(
context.context.find('.')==-1?context.context:QCString(), // find('.') is a hack to detect files
name,
args.isEmpty() ? QCString() : args,
md,cd,fd,nd,gd,FALSE,0,TRUE);
//printf("found=%d context=%s name=%s\n",found,qPrint(context.context),qPrint(name));
if (found && md)
{
*pDoc=md->documentation();
*pBrief=md->briefDescription();
*pDef=md;
return TRUE;
}
int scopeOffset=(int)context.context.length();
do // for each scope
{
QCString fullName=cmdArg;
if (scopeOffset>0)
{
fullName.prepend(context.context.left(scopeOffset)+"::");
}
//printf("Trying fullName='%s'\n",qPrint(fullName));
// try class, namespace, group, page, file reference
cd = Doxygen::classLinkedMap->find(fullName);
if (cd) // class
{
*pDoc=cd->documentation();
*pBrief=cd->briefDescription();
*pDef=cd;
return TRUE;
}
nd = Doxygen::namespaceLinkedMap->find(fullName);
if (nd) // namespace
{
*pDoc=nd->documentation();
*pBrief=nd->briefDescription();
*pDef=nd;
return TRUE;
}
if (scopeOffset==0)
{
scopeOffset=-1;
}
else
{
scopeOffset = context.context.findRev("::",scopeOffset-1);
if (scopeOffset==-1) scopeOffset=0;
}
} while (scopeOffset>=0);
return FALSE;
}
//---------------------------------------------------------------------------
void DocParser::errorHandleDefaultToken(DocNode *parent,int tok,
DocNodeList &children,const QCString &txt)
{
const char *cmd_start = "\\";
switch (tok)
{
case TK_COMMAND_AT:
cmd_start = "@";
// fall through
case TK_COMMAND_BS:
children.push_back(std::make_unique<DocWord>(*this,parent,TK_COMMAND_CHAR(tok) + context.token->name));
warn_doc_error(context.fileName,tokenizer.getLineNr(),"Illegal command %s as part of a %s",
qPrint(cmd_start + context.token->name),qPrint(txt));
break;
case TK_SYMBOL:
warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unsupported symbol %s found found as part of a %s",
qPrint(context.token->name), qPrint(txt));
break;
default:
children.push_back(std::make_unique<DocWord>(*this,parent,context.token->name));
warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unexpected token %s found as part of a %s",
DocTokenizer::tokToString(tok), qPrint(txt));
break;
}
}
//---------------------------------------------------------------------------
int DocParser::handleStyleArgument(DocNode *parent,DocNodeList &children,const QCString &cmdName)
{
DBG(("handleStyleArgument(%s)\n",qPrint(cmdName)));
QCString saveCmdName = cmdName;
int tok=tokenizer.lex();
if (tok!=TK_WHITESPACE)
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\%s command",
qPrint(saveCmdName));
return tok;
}
while ((tok=tokenizer.lex()) &&
tok!=TK_WHITESPACE &&
tok!=TK_NEWPARA &&
tok!=TK_LISTITEM &&
tok!=TK_ENDLIST
)
{
static const reg::Ex specialChar(R"([.,|()\[\]:;?])");
if (tok==TK_WORD && context.token->name.length()==1 &&
reg::match(context.token->name.str(),specialChar))
{
// special character that ends the markup command
return tok;
}
if (!defaultHandleToken(parent,tok,children))
{
switch (tok)
{
case TK_HTMLTAG:
if (insideLI(parent) && Mappers::htmlTagMapper->map(context.token->name) && context.token->endTag)
{ // ignore </li> as the end of a style command
continue;
}
DBG(("handleStyleArgument(%s) end tok=%s\n",qPrint(saveCmdName), DocTokenizer::tokToString(tok)));
return tok;
break;
default:
errorHandleDefaultToken(parent,tok,children,"\\" + saveCmdName + " command");
break;
}
break;
}
}
DBG(("handleStyleArgument(%s) end tok=%s\n",qPrint(saveCmdName), DocTokenizer::tokToString(tok)));
return (tok==TK_NEWPARA || tok==TK_LISTITEM || tok==TK_ENDLIST
) ? tok : RetVal_OK;
}
/*! Called when a style change starts. For instance a \<b\> command is
* encountered.
*/
void DocParser::handleStyleEnter(DocNode *parent,DocNodeList &children,
DocStyleChange::Style s,const QCString &tagName,const HtmlAttribList *attribs)
{
DBG(("HandleStyleEnter\n"));
DocStyleChange *sc= new DocStyleChange(*this,parent,(uint)context.nodeStack.size(),s,tagName,TRUE,attribs);
children.push_back(std::unique_ptr<DocStyleChange>(sc));
context.styleStack.push(sc);
}
/*! Called when a style change ends. For instance a \</b\> command is
* encountered.
*/
void DocParser::handleStyleLeave(DocNode *parent,DocNodeList &children,
DocStyleChange::Style s,const QCString &tagName)
{
DBG(("HandleStyleLeave\n"));
QCString tagNameLower = QCString(tagName).lower();
if (context.styleStack.empty() || // no style change
context.styleStack.top()->style()!=s || // wrong style change
context.styleStack.top()->tagName()!=tagNameLower || // wrong style change
context.styleStack.top()->position()!=context.nodeStack.size() // wrong position
)
{
if (context.styleStack.empty())
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </%s> tag without matching <%s>",
qPrint(tagName),qPrint(tagName));
}
else if (context.styleStack.top()->tagName()!=tagNameLower)
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </%s> tag while expecting </%s>",
qPrint(tagName),qPrint(context.styleStack.top()->tagName()));
}
else if (context.styleStack.top()->style()!=s)
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </%s> tag while expecting </%s>",
qPrint(tagName),qPrint(context.styleStack.top()->tagName()));
}
else
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </%s> at different nesting level (%zu) than expected (%d)",
qPrint(tagName),context.nodeStack.size(),context.styleStack.top()->position());
}
}
else // end the section
{
children.push_back(
std::make_unique<DocStyleChange>(
*this,parent,(uint)context.nodeStack.size(),s,context.styleStack.top()->tagName(),FALSE));
context.styleStack.pop();
}
}
/*! Called at the end of a paragraph to close all open style changes
* (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
* and entered again at the start of a new paragraph.
*/
void DocParser::handlePendingStyleCommands(DocNode *parent,DocNodeList &children)
{
if (!context.styleStack.empty())
{
const DocStyleChange *sc = context.styleStack.top();
while (sc && sc->position()>=context.nodeStack.size())
{ // there are unclosed style modifiers in the paragraph
children.push_back(std::make_unique<DocStyleChange>(*this,parent,(uint)context.nodeStack.size(),sc->style(),sc->tagName(),FALSE));
context.initialStyleStack.push(sc);
context.styleStack.pop();
sc = !context.styleStack.empty() ? context.styleStack.top() : 0;
}
}
}
void DocParser::handleInitialStyleCommands(DocPara *parent,DocNodeList &children)
{
while (!context.initialStyleStack.empty())
{
const DocStyleChange *sc = context.initialStyleStack.top();
handleStyleEnter(parent,children,sc->style(),sc->tagName(),&sc->attribs());
context.initialStyleStack.pop();
}
}
int DocParser::handleAHref(DocNode *parent,DocNodeList &children,
const HtmlAttribList &tagHtmlAttribs)
{
uint index=0;
int retval = RetVal_OK;
for (const auto &opt : tagHtmlAttribs)
{
if (opt.name=="name" || opt.name=="id") // <a name=label> or <a id=label> tag
{
if (!opt.value.isEmpty())
{
children.push_back(std::make_unique<DocAnchor>(*this,parent,opt.value,TRUE));
break; // stop looking for other tag attribs
}
else
{
warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <a> tag with name option but without value!");
}
}
else if (opt.name=="href") // <a href=url>..</a> tag
{
// copy attributes
HtmlAttribList attrList = tagHtmlAttribs;
// and remove the href attribute
attrList.erase(attrList.begin()+index);
QCString relPath;
if (opt.value.at(0) != '#') relPath = context.relPath;
DocHRef *href = new DocHRef(*this,parent,attrList,opt.value,relPath,convertNameToFile(context.fileName,FALSE,TRUE));
children.push_back(std::unique_ptr<DocHRef>(href));
context.insideHtmlLink=TRUE;
retval = href->parse();
context.insideHtmlLink=FALSE;
break;
}
else // unsupported option for tag a
{
}
++index;