/
docparser.cpp
7486 lines (7046 loc) · 219 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-2015 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 <qfile.h>
#include <qfileinfo.h>
#include <qcstring.h>
#include <qstack.h>
#include <qdict.h>
#include <qregexp.h>
#include <ctype.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"
// debug off
#define DBG(x) do {} while(0)
// debug to stdout
//#define DBG(x) printf x
// debug to stderr
//#define myprintf(x...) fprintf(stderr,x)
//#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 *sectionLevelToName[] =
{
"page",
"section",
"subsection",
"subsubsection",
"paragraph",
"subparagraph"
};
//---------------------------------------------------------------------------
// Parser state: global variables during a call to validatingParseDoc
static Definition * g_scope;
static QCString g_context;
static bool g_inSeeBlock;
static bool g_xmlComment;
static bool g_insideHtmlLink;
static QStack<DocNode> g_nodeStack;
static QStack<DocStyleChange> g_styleStack;
static QStack<DocStyleChange> g_initialStyleStack;
static QList<Definition> g_copyStack;
static QCString g_fileName;
static QCString g_relPath;
static bool g_hasParamCommand;
static bool g_hasReturnCommand;
static QDict<void> g_paramsFound;
static MemberDef * g_memberDef;
static bool g_isExample;
static QCString g_exampleName;
static SectionDict * g_sectionDict;
static QCString g_searchUrl;
static QCString g_includeFileText;
static uint g_includeFileOffset;
static uint g_includeFileLength;
/** Parser's context to store all global variables.
*/
struct DocParserContext
{
Definition *scope;
QCString context;
bool inSeeBlock;
bool xmlComment;
bool insideHtmlLink;
QStack<DocNode> nodeStack;
QStack<DocStyleChange> styleStack;
QStack<DocStyleChange> initialStyleStack;
QList<Definition> copyStack;
QCString fileName;
int lineNo;
QCString relPath;
bool hasParamCommand;
bool hasReturnCommand;
MemberDef * memberDef;
QDict<void> paramsFound;
bool isExample;
QCString exampleName;
SectionDict *sectionDict;
QCString searchUrl;
QCString includeFileText;
uint includeFileOffset;
uint includeFileLength;
TokenInfo *token;
};
static QStack<DocParserContext> g_parserStack;
//---------------------------------------------------------------------------
static void docParserPushContext(bool saveParamInfo=TRUE)
{
//QCString indent;
//indent.fill(' ',g_parserStack.count()*2+2);
//printf("%sdocParserPushContext() count=%d\n",indent.data(),g_nodeStack.count());
doctokenizerYYpushContext();
DocParserContext *ctx = new DocParserContext;
ctx->scope = g_scope;
ctx->context = g_context;
ctx->inSeeBlock = g_inSeeBlock;
ctx->xmlComment = g_xmlComment;
ctx->insideHtmlLink = g_insideHtmlLink;
ctx->nodeStack = g_nodeStack;
ctx->styleStack = g_styleStack;
ctx->initialStyleStack = g_initialStyleStack;
ctx->copyStack = g_copyStack;
ctx->fileName = g_fileName;
ctx->lineNo = doctokenizerYYlineno;
ctx->relPath = g_relPath;
if (saveParamInfo)
{
ctx->hasParamCommand = g_hasParamCommand;
ctx->hasReturnCommand = g_hasReturnCommand;
ctx->paramsFound = g_paramsFound;
}
ctx->memberDef = g_memberDef;
ctx->isExample = g_isExample;
ctx->exampleName = g_exampleName;
ctx->sectionDict = g_sectionDict;
ctx->searchUrl = g_searchUrl;
ctx->includeFileText = g_includeFileText;
ctx->includeFileOffset = g_includeFileOffset;
ctx->includeFileLength = g_includeFileLength;
ctx->token = g_token;
g_token = new TokenInfo;
g_parserStack.push(ctx);
}
static void docParserPopContext(bool keepParamInfo=FALSE)
{
DocParserContext *ctx = g_parserStack.pop();
g_scope = ctx->scope;
g_context = ctx->context;
g_inSeeBlock = ctx->inSeeBlock;
g_xmlComment = ctx->xmlComment;
g_insideHtmlLink = ctx->insideHtmlLink;
g_nodeStack = ctx->nodeStack;
g_styleStack = ctx->styleStack;
g_initialStyleStack = ctx->initialStyleStack;
g_copyStack = ctx->copyStack;
g_fileName = ctx->fileName;
doctokenizerYYlineno = ctx->lineNo;
g_relPath = ctx->relPath;
if (!keepParamInfo)
{
g_hasParamCommand = ctx->hasParamCommand;
g_hasReturnCommand = ctx->hasReturnCommand;
g_paramsFound = ctx->paramsFound;
}
g_memberDef = ctx->memberDef;
g_isExample = ctx->isExample;
g_exampleName = ctx->exampleName;
g_sectionDict = ctx->sectionDict;
g_searchUrl = ctx->searchUrl;
g_includeFileText = ctx->includeFileText;
g_includeFileOffset = ctx->includeFileOffset;
g_includeFileLength = ctx->includeFileLength;
delete g_token;
g_token = ctx->token;
delete ctx;
doctokenizerYYpopContext();
//QCString indent;
//indent.fill(' ',g_parserStack.count()*2+2);
//printf("%sdocParserPopContext() count=%d\n",indent.data(),g_nodeStack.count());
}
//---------------------------------------------------------------------------
// replaces { with < and } with > and also
// replaces > with < and > with > within string s
static void unescapeCRef(QCString &s)
{
QCString tmp(s);
char *p = tmp.rawData();
if (p)
{
char c;
while ((c=*p))
{
if (c=='{') c='<'; else if (c=='}') c='>';
*p++=c;
}
}
tmp=substitute(tmp,"<","<");
tmp=substitute(tmp,">",">");
s = tmp;
}
//---------------------------------------------------------------------------
/*! search for an image in the imageNameDict and if found
* copies the image to the output directory (which depends on the \a type
* parameter).
*/
static QCString findAndCopyImage(const char *fileName,DocImage::Type type)
{
QCString result;
bool ambig;
FileDef *fd;
//printf("Search for %s\n",fileName);
if ((fd=findFileDef(Doxygen::imageNameDict,fileName,ambig)))
{
QCString inputFile = fd->absFilePath();
QFile inImage(inputFile);
if (inImage.open(IO_ReadOnly))
{
result = fileName;
int i;
if ((i=result.findRev('/'))!=-1 || (i=result.findRev('\\'))!=-1)
{
result = result.right(result.length()-i-1);
}
//printf("fileName=%s result=%s\n",fileName,result.data());
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;
}
QCString outputFile = outputDir+"/"+result;
QFileInfo outfi(outputFile);
if (outfi.isSymLink())
{
QFile::remove(outputFile);
warn_doc_error(g_fileName,doctokenizerYYlineno,
"destination of image %s is a symlink, replacing with image",
qPrint(outputFile));
}
if (outputFile!=inputFile) // prevent copying to ourself
{
QFile outImage(outputFile.data());
if (outImage.open(IO_WriteOnly)) // copy the image
{
char *buffer = new char[inImage.size()];
inImage.readBlock(buffer,inImage.size());
outImage.writeBlock(buffer,inImage.size());
outImage.flush();
delete[] buffer;
if (type==DocImage::Html) Doxygen::indexList->addImageFile(result);
}
else
{
warn_doc_error(g_fileName,doctokenizerYYlineno,
"could not write output image %s",qPrint(outputFile));
}
}
else
{
printf("Source & Destination are the same!\n");
}
}
else
{
warn_doc_error(g_fileName,doctokenizerYYlineno,
"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\"",
outputDir.data(), baseName.data(),
outputDir.data(), baseName.data());
portable_sysTimerStart();
if (portable_system("epstopdf",epstopdfArgs)!=0)
{
err("Problems running epstopdf. Check your TeX installation!\n");
}
portable_sysTimerStop();
return baseName;
}
}
else if (ambig)
{
QCString text;
text.sprintf("image file name %s is ambiguous.\n",qPrint(fileName));
text+="Possible candidates:\n";
text+=showFileDefMatches(Doxygen::imageNameDict,fileName);
warn_doc_error(g_fileName,doctokenizerYYlineno,text);
}
else
{
result=fileName;
if (result.left(5)!="http:" && result.left(6)!="https:")
{
warn_doc_error(g_fileName,doctokenizerYYlineno,
"image file %s is not found in IMAGE_PATH: "
"assuming external image.",qPrint(fileName)
);
}
}
return result;
}
/*! Collects the parameters found with \@param or \@retval commands
* in a global list g_paramsFound. If \a isParam is set to TRUE
* and the parameter is not an actual parameter of the current
* member g_memberDef, then a warning is raised (unless warnings
* are disabled altogether).
*/
static void checkArgumentName(const QCString &name,bool isParam)
{
if (!Config_getBool(WARN_IF_DOC_ERROR)) return;
if (g_memberDef==0) return; // not a member
ArgumentList *al=g_memberDef->isDocsForDefinition() ?
g_memberDef->argumentList() :
g_memberDef->declArgumentList();
SrcLangExt lang = g_memberDef->getLanguage();
//printf("isDocsForDefinition()=%d\n",g_memberDef->isDocsForDefinition());
if (al==0) return; // no argument list
static QRegExp re("$?[a-zA-Z0-9_\\x80-\\xFF]+\\.*");
int p=0,i=0,l;
while ((i=re.match(name,p,&l))!=-1) // to handle @param x,y
{
QCString aName=name.mid(i,l);
if (lang==SrcLangExt_Fortran) aName=aName.lower();
//printf("aName=`%s'\n",aName.data());
ArgumentListIterator ali(*al);
Argument *a;
bool found=FALSE;
for (ali.toFirst();(a=ali.current());++ali)
{
QCString argName = g_memberDef->isDefine() ? a->type : a->name;
if (lang==SrcLangExt_Fortran) argName=argName.lower();
argName=argName.stripWhiteSpace();
//printf("argName=`%s' aName=%s\n",argName.data(),aName.data());
if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
if (aName==argName)
{
g_paramsFound.insert(aName,(void *)(0x8));
found=TRUE;
break;
}
}
if (!found && isParam)
{
//printf("member type=%d\n",memberDef->memberType());
QCString scope=g_memberDef->getScopeString();
if (!scope.isEmpty()) scope+="::"; else scope="";
QCString inheritedFrom = "";
QCString docFile = g_memberDef->docFile();
int docLine = g_memberDef->docLine();
MemberDef *inheritedMd = g_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 = g_memberDef->getDefFileName();
docLine = g_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(g_memberDef->name()),
qPrint(alStr), qPrint(inheritedFrom));
}
p=i+l;
}
}
/*! Checks if the parameters that have been specified using \@param are
* indeed all parameters.
* Must be called after checkArgumentName() has been called for each
* argument.
*/
static void checkUndocumentedParams()
{
if (g_memberDef && g_hasParamCommand && Config_getBool(WARN_IF_DOC_ERROR))
{
ArgumentList *al=g_memberDef->isDocsForDefinition() ?
g_memberDef->argumentList() :
g_memberDef->declArgumentList();
SrcLangExt lang = g_memberDef->getLanguage();
if (al!=0)
{
ArgumentListIterator ali(*al);
Argument *a;
bool found=FALSE;
for (ali.toFirst();(a=ali.current());++ali)
{
QCString argName = g_memberDef->isDefine() ? a->type : a->name;
if (lang==SrcLangExt_Fortran) argName = argName.lower();
argName=argName.stripWhiteSpace();
if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
if (g_memberDef->getLanguage()==SrcLangExt_Python && (argName=="self" || argName=="cls"))
{
// allow undocumented self / cls parameter for Python
}
else if (!argName.isEmpty() && g_paramsFound.find(argName)==0 && a->docs.isEmpty())
{
found = TRUE;
break;
}
}
if (found)
{
bool first=TRUE;
QCString errMsg=
"The following parameters of "+
QCString(g_memberDef->qualifiedName()) +
QCString(argListToString(al)) +
" are not documented:\n";
for (ali.toFirst();(a=ali.current());++ali)
{
QCString argName = g_memberDef->isDefine() ? a->type : a->name;
if (lang==SrcLangExt_Fortran) argName = argName.lower();
argName=argName.stripWhiteSpace();
if (g_memberDef->getLanguage()==SrcLangExt_Python && (argName=="self" || argName=="cls"))
{
// allow undocumented self / cls parameter for Python
}
else if (!argName.isEmpty() && g_paramsFound.find(argName)==0)
{
if (!first)
{
errMsg+="\n";
}
else
{
first=FALSE;
}
errMsg+=" parameter '"+argName+"'";
}
}
warn_doc_error(g_memberDef->getDefFileName(),
g_memberDef->getDefLine(),
substitute(errMsg,"%","%%"));
}
}
}
}
/*! Check if a member has documentation for its parameter and or return
* type, if applicable. If found this will be stored in the member, this
* is needed as a member can have brief and detailed documentation, while
* only one of these needs to document the parameters.
*/
static void detectNoDocumentedParams()
{
if (g_memberDef && Config_getBool(WARN_NO_PARAMDOC))
{
ArgumentList *al = g_memberDef->argumentList();
ArgumentList *declAl = g_memberDef->declArgumentList();
QCString returnType = g_memberDef->typeString();
bool isPython = g_memberDef->getLanguage()==SrcLangExt_Python;
if (!g_memberDef->hasDocumentedParams() &&
g_hasParamCommand)
{
//printf("%s->setHasDocumentedParams(TRUE);\n",g_memberDef->name().data());
g_memberDef->setHasDocumentedParams(TRUE);
}
else if (!g_memberDef->hasDocumentedParams())
{
bool allDoc=TRUE; // no paramater => all parameters are documented
if ( // member has parameters
al!=0 && // but the member has a parameter list
al->count()>0 // with at least one parameter (that is not void)
)
{
ArgumentListIterator ali(*al);
Argument *a;
// see if all parameters have documentation
for (ali.toFirst();(a=ali.current()) && allDoc;++ali)
{
if (!a->name.isEmpty() && a->type!="void" &&
!(isPython && (a->name=="self" || a->name=="cls"))
)
{
allDoc = !a->docs.isEmpty();
}
//printf("a->type=%s a->name=%s doc=%s\n",
// a->type.data(),a->name.data(),a->docs.data());
}
if (!allDoc && declAl!=0) // try declaration arguments as well
{
allDoc=TRUE;
ArgumentListIterator ali(*declAl);
Argument *a;
for (ali.toFirst();(a=ali.current()) && allDoc;++ali)
{
if (!a->name.isEmpty() && a->type!="void" &&
!(isPython && (a->name=="self" || a->name=="cls"))
)
{
allDoc = !a->docs.isEmpty();
}
//printf("a->name=%s doc=%s\n",a->name.data(),a->docs.data());
}
}
}
if (allDoc)
{
//printf("%s->setHasDocumentedParams(TRUE);\n",g_memberDef->name().data());
g_memberDef->setHasDocumentedParams(TRUE);
}
}
//printf("Member %s hadDocumentedReturnType()=%d hasReturnCommand=%d\n",
// g_memberDef->name().data(),g_memberDef->hasDocumentedReturnType(),g_hasReturnCommand);
if (!g_memberDef->hasDocumentedReturnType() && // docs not yet found
g_hasReturnCommand)
{
g_memberDef->setHasDocumentedReturnType(TRUE);
}
else if ( // see if return needs to documented
g_memberDef->hasDocumentedReturnType() ||
returnType.isEmpty() || // empty return type
returnType.find("void")!=-1 || // void return type
returnType.find("subroutine")!=-1 || // fortran subroutine
g_memberDef->isConstructor() || // a constructor
g_memberDef->isDestructor() // or destructor
)
{
g_memberDef->setHasDocumentedReturnType(TRUE);
}
else if ( // see if return type is documented in a function w/o return type
g_memberDef->hasDocumentedReturnType() &&
(returnType.isEmpty() || // empty return type
returnType.find("void")!=-1 || // void return type
returnType.find("subroutine")!=-1 || // fortran subroutine
g_memberDef->isConstructor() || // a constructor
g_memberDef->isDestructor() // or destructor
)
)
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"documented empty return type");
}
}
}
//---------------------------------------------------------------------------
/*! Strips known html and tex extensions from \a text. */
static QCString stripKnownExtensions(const char *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;
}
//---------------------------------------------------------------------------
/*! Looks for a documentation block with name commandName in the current
* context (g_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.
*/
static bool findDocsForMemberOrCompound(const char *commandName,
QCString *pDoc,
QCString *pBrief,
Definition **pDef)
{
//printf("findDocsForMemberOrCompound(%s)\n",commandName);
*pDoc="";
*pBrief="";
*pDef=0;
QCString cmdArg=substitute(commandName,"#","::");
int l=cmdArg.length();
if (l==0) return FALSE;
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
MemberDef *md=0;
ClassDef *cd=0;
FileDef *fd=0;
NamespaceDef *nd=0;
GroupDef *gd=0;
PageDef *pd=0;
bool found = getDefs(
g_context.find('.')==-1?g_context.data():"", // `find('.') is a hack to detect files
name,
args.isEmpty()?0:args.data(),
md,cd,fd,nd,gd,FALSE,0,TRUE);
//printf("found=%d context=%s name=%s\n",found,g_context.data(),name.data());
if (found && md)
{
*pDoc=md->documentation();
*pBrief=md->briefDescription();
*pDef=md;
return TRUE;
}
int scopeOffset=g_context.length();
do // for each scope
{
QCString fullName=cmdArg;
if (scopeOffset>0)
{
fullName.prepend(g_context.left(scopeOffset)+"::");
}
//printf("Trying fullName=`%s'\n",fullName.data());
// try class, namespace, group, page, file reference
cd = Doxygen::classSDict->find(fullName);
if (cd) // class
{
*pDoc=cd->documentation();
*pBrief=cd->briefDescription();
*pDef=cd;
return TRUE;
}
nd = Doxygen::namespaceSDict->find(fullName);
if (nd) // namespace
{
*pDoc=nd->documentation();
*pBrief=nd->briefDescription();
*pDef=nd;
return TRUE;
}
gd = Doxygen::groupSDict->find(cmdArg);
if (gd) // group
{
*pDoc=gd->documentation();
*pBrief=gd->briefDescription();
*pDef=gd;
return TRUE;
}
pd = Doxygen::pageSDict->find(cmdArg);
if (pd) // page
{
*pDoc=pd->documentation();
*pBrief=pd->briefDescription();
*pDef=pd;
return TRUE;
}
bool ambig;
fd = findFileDef(Doxygen::inputNameDict,cmdArg,ambig);
if (fd && !ambig) // file
{
*pDoc=fd->documentation();
*pBrief=fd->briefDescription();
*pDef=fd;
return TRUE;
}
if (scopeOffset==0)
{
scopeOffset=-1;
}
else
{
scopeOffset = g_context.findRev("::",scopeOffset-1);
if (scopeOffset==-1) scopeOffset=0;
}
} while (scopeOffset>=0);
return FALSE;
}
//---------------------------------------------------------------------------
// forward declaration
static bool defaultHandleToken(DocNode *parent,int tok,
QList<DocNode> &children,bool
handleWord=TRUE);
static int handleStyleArgument(DocNode *parent,QList<DocNode> &children,
const QCString &cmdName)
{
DBG(("handleStyleArgument(%s)\n",qPrint(cmdName)));
int tok=doctokenizerYYlex();
if (tok!=TK_WHITESPACE)
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command",
qPrint(cmdName));
return tok;
}
while ((tok=doctokenizerYYlex()) &&
tok!=TK_WHITESPACE &&
tok!=TK_NEWPARA &&
tok!=TK_LISTITEM &&
tok!=TK_ENDLIST
)
{
static QRegExp specialChar("[.,|()\\[\\]:;\\?]");
if (tok==TK_WORD && g_token->name.length()==1 &&
g_token->name.find(specialChar)!=-1)
{
// special character that ends the markup command
return tok;
}
if (!defaultHandleToken(parent,tok,children))
{
switch (tok)
{
case TK_COMMAND:
warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command \\%s as the argument of a \\%s command",
qPrint(g_token->name),qPrint(cmdName));
break;
case TK_SYMBOL:
warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found while handling command %s",
qPrint(g_token->name),qPrint(cmdName));
break;
case TK_HTMLTAG:
if (insideLI(parent) && Mappers::htmlTagMapper->map(g_token->name) && g_token->endTag)
{ // ignore </li> as the end of a style command
continue;
}
return tok;
break;
default:
warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s while handling command %s",
tokToString(tok),qPrint(cmdName));
break;
}
break;
}
}
DBG(("handleStyleArgument(%s) end tok=%x\n",qPrint(cmdName),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.
*/
static void handleStyleEnter(DocNode *parent,QList<DocNode> &children,
DocStyleChange::Style s,const HtmlAttribList *attribs)
{
DBG(("HandleStyleEnter\n"));
DocStyleChange *sc= new DocStyleChange(parent,g_nodeStack.count(),s,TRUE,attribs);
children.append(sc);
g_styleStack.push(sc);
}
/*! Called when a style change ends. For instance a \</b\> command is
* encountered.
*/
static void handleStyleLeave(DocNode *parent,QList<DocNode> &children,
DocStyleChange::Style s,const char *tagName)
{
DBG(("HandleStyleLeave\n"));
if (g_styleStack.isEmpty() || // no style change
g_styleStack.top()->style()!=s || // wrong style change
g_styleStack.top()->position()!=g_nodeStack.count() // wrong position
)
{
if (g_styleStack.isEmpty())
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"found </%s> tag without matching <%s>",
qPrint(tagName),qPrint(tagName));
}
else if (g_styleStack.top()->style()!=s)
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"found </%s> tag while expecting </%s>",
qPrint(tagName),qPrint(g_styleStack.top()->styleString()));
}
else
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"found </%s> at different nesting level (%d) than expected (%d)",
qPrint(tagName),g_nodeStack.count(),g_styleStack.top()->position());
}
}
else // end the section
{
DocStyleChange *sc= new DocStyleChange(parent,g_nodeStack.count(),s,FALSE);
children.append(sc);
g_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.
*/
static void handlePendingStyleCommands(DocNode *parent,QList<DocNode> &children)
{
if (!g_styleStack.isEmpty())
{
DocStyleChange *sc = g_styleStack.top();
while (sc && sc->position()>=g_nodeStack.count())
{ // there are unclosed style modifiers in the paragraph
children.append(new DocStyleChange(parent,g_nodeStack.count(),sc->style(),FALSE));
g_initialStyleStack.push(sc);
g_styleStack.pop();
sc = g_styleStack.top();
}
}
}
static void handleInitialStyleCommands(DocPara *parent,QList<DocNode> &children)
{
DocStyleChange *sc;
while ((sc=g_initialStyleStack.pop()))
{
handleStyleEnter(parent,children,sc->style(),&sc->attribs());
}
}
static int handleAHref(DocNode *parent,QList<DocNode> &children,const HtmlAttribList &tagHtmlAttribs)
{
HtmlAttribListIterator li(tagHtmlAttribs);
HtmlAttrib *opt;
int index=0;
int retval = RetVal_OK;
for (li.toFirst();(opt=li.current());++li,++index)
{
if (opt->name=="name") // <a name=label> tag
{
if (!opt->value.isEmpty())
{
DocAnchor *anc = new DocAnchor(parent,opt->value,TRUE);
children.append(anc);
break; // stop looking for other tag attribs
}
else
{