/
code.l
3665 lines (3520 loc) · 108 KB
/
code.l
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-2013 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.
*
*/
%{
/*
* includes
*/
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <qregexp.h>
#include <qdir.h>
#include "entry.h"
#include "doxygen.h"
#include "message.h"
#include "outputlist.h"
#include "util.h"
#include "membername.h"
#include "searchindex.h"
#include "arguments.h"
#include "config.h"
#include "groupdef.h"
#include "classlist.h"
#include "filedef.h"
#include "filename.h"
#include "namespacedef.h"
#include "tooltip.h"
// Toggle for some debugging info
//#define DBG_CTX(x) fprintf x
#define DBG_CTX(x) do { } while(0)
#define YY_NEVER_INTERACTIVE 1
#define CLASSBLOCK (int *)4
#define SCOPEBLOCK (int *)8
#define INNERBLOCK (int *)12
/* -----------------------------------------------------------------
* statics
*/
static CodeOutputInterface * g_code;
static ClassSDict *g_codeClassSDict = 0;
static QCString g_curClassName;
static QStrList g_curClassBases;
static QCString g_parmType;
static QCString g_parmName;
static const char * g_inputString; //!< the code fragment as text
static int g_inputPosition; //!< read offset during parsing
static int g_inputLines; //!< number of line in the code fragment
static int g_yyLineNr; //!< current line number
static int g_yyColNr; //!< current column number
static bool g_needsTermination;
static bool g_exampleBlock;
static QCString g_exampleName;
static QCString g_exampleFile;
static bool g_insideTemplate = FALSE;
static QCString g_type;
static QCString g_name;
static QCString g_args;
static QCString g_classScope;
static QCString g_realScope;
static QStack<int> g_scopeStack; //!< 1 if bracket starts a scope,
// 2 for internal blocks
static int g_anchorCount;
static FileDef * g_sourceFileDef;
static bool g_lineNumbers;
static Definition * g_currentDefinition;
static MemberDef * g_currentMemberDef;
static bool g_includeCodeFragment;
static const char * g_currentFontClass;
static bool g_searchingForBody;
static bool g_insideBody;
static int g_bodyCurlyCount;
static QCString g_saveName;
static QCString g_saveType;
static QCString g_delimiter;
static int g_bracketCount = 0;
static int g_curlyCount = 0;
static int g_sharpCount = 0;
static bool g_inFunctionTryBlock = FALSE;
static bool g_inForEachExpression = FALSE;
static int g_lastTemplCastContext;
static int g_lastSpecialCContext;
static int g_lastStringContext;
static int g_lastSkipCppContext;
static int g_lastVerbStringContext;
static int g_memCallContext;
static int g_lastCContext;
static bool g_insideObjC;
static bool g_insideJava;
static bool g_insideCS;
static bool g_insidePHP;
static bool g_insideProtocolList;
static bool g_lexInit = FALSE;
static QStack<int> g_classScopeLengthStack;
static Definition *g_searchCtx;
static bool g_collectXRefs;
// context for an Objective-C method call
struct ObjCCallCtx
{
int id;
QCString methodName;
QCString objectTypeOrName;
ClassDef *objectType;
MemberDef *objectVar;
MemberDef *method;
QCString format;
int lexState;
int braceCount;
};
// globals for objective-C method calls
static ObjCCallCtx *g_currentCtx=0;
static int g_currentCtxId=0;
static int g_currentNameId=0;
static int g_currentObjId=0;
static int g_currentWordId=0;
static QStack<ObjCCallCtx> g_contextStack;
static QIntDict<ObjCCallCtx> g_contextDict;
static QIntDict<QCString> g_nameDict;
static QIntDict<QCString> g_objectDict;
static QIntDict<QCString> g_wordDict;
static int g_braceCount=0;
static void saveObjCContext();
static void restoreObjCContext();
static QCString g_forceTagReference;
//-------------------------------------------------------------------
/*! Represents a stack of variable to class mappings as found in the
* code. Each scope is enclosed in pushScope() and popScope() calls.
* Variables are added by calling addVariables() and one can search
* for variable using findVariable().
*/
class VariableContext
{
public:
static const ClassDef *dummyContext;
class Scope : public SDict<ClassDef>
{
public:
Scope() : SDict<ClassDef>(17) {}
};
VariableContext()
{
m_scopes.setAutoDelete(TRUE);
}
virtual ~VariableContext()
{
}
void pushScope()
{
m_scopes.append(new Scope);
DBG_CTX((stderr,"** Push var context %d\n",m_scopes.count()));
}
void popScope()
{
if (m_scopes.count()>0)
{
DBG_CTX((stderr,"** Pop var context %d\n",m_scopes.count()));
m_scopes.remove(m_scopes.count()-1);
}
else
{
DBG_CTX((stderr,"** ILLEGAL: Pop var context\n"));
}
}
void clear()
{
m_scopes.clear();
m_globalScope.clear();
}
void clearExceptGlobal()
{
DBG_CTX((stderr,"** Clear var context\n"));
m_scopes.clear();
}
void addVariable(const QCString &type,const QCString &name);
ClassDef *findVariable(const QCString &name);
int count() const { return m_scopes.count(); }
private:
Scope m_globalScope;
QList<Scope> m_scopes;
};
void VariableContext::addVariable(const QCString &type,const QCString &name)
{
//printf("VariableContext::addVariable(%s,%s)\n",type.data(),name.data());
QCString ltype = type.simplifyWhiteSpace();
QCString lname = name.simplifyWhiteSpace();
if (ltype.left(7)=="struct ")
{
ltype = ltype.right(ltype.length()-7);
}
else if (ltype.left(6)=="union ")
{
ltype = ltype.right(ltype.length()-6);
}
if (ltype.isEmpty() || lname.isEmpty()) return;
DBG_CTX((stderr,"** addVariable trying: type='%s' name='%s' g_currentDefinition=%s\n",
ltype.data(),lname.data(),g_currentDefinition?g_currentDefinition->name().data():"<none>"));
Scope *scope = m_scopes.count()==0 ? &m_globalScope : m_scopes.getLast();
ClassDef *varType;
int i=0;
if (
(varType=g_codeClassSDict->find(ltype)) || // look for class definitions inside the code block
(varType=getResolvedClass(g_currentDefinition,g_sourceFileDef,ltype)) // look for global class definitions
)
{
DBG_CTX((stderr,"** addVariable type='%s' name='%s'\n",ltype.data(),lname.data()));
scope->append(lname,varType); // add it to a list
}
else if ((i=ltype.find('<'))!=-1)
{
// probably a template class
QCString typeName(ltype.left(i));
ClassDef* newDef = 0;
QCString templateArgs(ltype.right(ltype.length() - i));
if (
( // look for class definitions inside the code block
(varType=g_codeClassSDict->find(typeName)) ||
// otherwise look for global class definitions
(varType=getResolvedClass(g_currentDefinition,g_sourceFileDef,typeName,0,0,TRUE,TRUE))
) && // and it must be a template
varType->templateArguments())
{
newDef = varType->getVariableInstance( templateArgs );
}
if (newDef)
{
DBG_CTX((stderr,"** addVariable type='%s' templ='%s' name='%s'\n",typeName.data(),templateArgs.data(),lname.data()));
scope->append(lname, newDef);
}
else
{
// Doesn't seem to be a template. Try just the base name.
addVariable(typeName,name);
}
}
else
{
if (m_scopes.count()>0) // for local variables add a dummy entry so the name
// is hidden to avoid false links to global variables with the same name
// TODO: make this work for namespaces as well!
{
DBG_CTX((stderr,"** addVariable: dummy context for '%s'\n",lname.data()));
scope->append(lname,dummyContext);
}
else
{
DBG_CTX((stderr,"** addVariable: not adding variable!\n"));
}
}
}
ClassDef *VariableContext::findVariable(const QCString &name)
{
if (name.isEmpty()) return 0;
ClassDef *result = 0;
QListIterator<Scope> sli(m_scopes);
Scope *scope;
QCString key = name;
// search from inner to outer scope
for (sli.toLast();(scope=sli.current());--sli)
{
result = scope->find(key);
if (result)
{
DBG_CTX((stderr,"** findVariable(%s)=%p\n",name.data(),result));
return result;
}
}
// nothing found -> also try the global scope
result=m_globalScope.find(name);
DBG_CTX((stderr,"** findVariable(%s)=%p\n",name.data(),result));
return result;
}
static VariableContext g_theVarContext;
const ClassDef *VariableContext::dummyContext = (ClassDef*)0x8;
//-------------------------------------------------------------------
class CallContext
{
public:
struct Ctx
{
Ctx() : name(g_name), type(g_type), cd(0) {}
QCString name;
QCString type;
ClassDef *cd;
};
CallContext()
{
m_classList.append(new Ctx);
m_classList.setAutoDelete(TRUE);
}
virtual ~CallContext() {}
void setClass(ClassDef *cd)
{
Ctx *ctx = m_classList.getLast();
if (ctx)
{
DBG_CTX((stderr,"** Set call context %s (%p)\n",cd==0 ? "<null>" : cd->name().data(),cd));
ctx->cd=cd;
}
}
void pushScope()
{
m_classList.append(new Ctx);
DBG_CTX((stderr,"** Push call context %d\n",m_classList.count()));
}
void popScope()
{
if (m_classList.count()>1)
{
DBG_CTX((stderr,"** Pop call context %d\n",m_classList.count()));
Ctx *ctx = m_classList.getLast();
if (ctx)
{
g_name = ctx->name;
g_type = ctx->type;
}
m_classList.removeLast();
}
else
{
DBG_CTX((stderr,"** ILLEGAL: Pop call context\n"));
}
}
void clear()
{
DBG_CTX((stderr,"** Clear call context\n"));
m_classList.clear();
m_classList.append(new Ctx);
}
ClassDef *getClass() const
{
Ctx *ctx = m_classList.getLast();
if (ctx) return ctx->cd; else return 0;
}
private:
QList<Ctx> m_classList;
};
static CallContext g_theCallContext;
//-------------------------------------------------------------------
/*! add class/namespace name s to the scope */
static void pushScope(const char *s)
{
g_classScopeLengthStack.push(new int(g_classScope.length()));
if (g_classScope.isEmpty() || leftScopeMatch(s,g_classScope))
{
g_classScope = s;
}
else
{
g_classScope += "::";
g_classScope += s;
}
//printf("pushScope(%s) result: `%s'\n",s,g_classScope.data());
}
/*! remove the top class/namespace name from the scope */
static void popScope()
{
if (!g_classScopeLengthStack.isEmpty())
{
int *pLength = g_classScopeLengthStack.pop();
g_classScope.truncate(*pLength);
delete pLength;
}
else
{
//err("Too many end of scopes found!\n");
}
//printf("popScope() result: `%s'\n",g_classScope.data());
}
static void setCurrentDoc(const QCString &anchor)
{
if (Doxygen::searchIndex)
{
if (g_searchCtx)
{
g_code->setCurrentDoc(g_searchCtx,g_searchCtx->anchor(),FALSE);
}
else
{
g_code->setCurrentDoc(g_sourceFileDef,anchor,TRUE);
}
}
}
static void addToSearchIndex(const char *text)
{
if (Doxygen::searchIndex)
{
g_code->addWord(text,FALSE);
}
}
static void setClassScope(const QCString &name)
{
//printf("setClassScope(%s)\n",name.data());
QCString n=name;
n=n.simplifyWhiteSpace();
int ts=n.find('<'); // start of template
int te=n.findRev('>'); // end of template
//printf("ts=%d te=%d\n",ts,te);
if (ts!=-1 && te!=-1 && te>ts)
{
// remove template from scope
n=n.left(ts)+n.right(n.length()-te-1);
}
while (!g_classScopeLengthStack.isEmpty())
{
popScope();
}
g_classScope.resize(0);
int i;
while ((i=n.find("::"))!=-1)
{
pushScope(n.left(i));
n = n.mid(i+2);
}
pushScope(n);
//printf("--->New class scope `%s'\n",g_classScope.data());
}
/*! start a new line of code, inserting a line number if g_sourceFileDef
* is TRUE. If a definition starts at the current line, then the line
* number is linked to the documentation of that definition.
*/
static void startCodeLine()
{
//if (g_currentFontClass) { g_code->endFontClass(); }
if (g_sourceFileDef && g_lineNumbers)
{
//QCString lineNumber,lineAnchor;
//lineNumber.sprintf("%05d",g_yyLineNr);
//lineAnchor.sprintf("l%05d",g_yyLineNr);
Definition *d = g_sourceFileDef->getSourceDefinition(g_yyLineNr);
//printf("%s:startCodeLine(%d)=%p\n",g_sourceFileDef->name().data(),g_yyLineNr,d);
if (!g_includeCodeFragment && d)
{
g_currentDefinition = d;
g_currentMemberDef = g_sourceFileDef->getSourceMember(g_yyLineNr);
g_insideBody = FALSE;
g_searchingForBody = TRUE;
g_realScope = d->name();
//g_classScope = "";
g_type.resize(0);
g_name.resize(0);
g_args.resize(0);
g_parmType.resize(0);
g_parmName.resize(0);
//printf("Real scope: `%s'\n",g_realScope.data());
g_bodyCurlyCount = 0;
QCString lineAnchor;
lineAnchor.sprintf("l%05d",g_yyLineNr);
if (g_currentMemberDef)
{
g_code->writeLineNumber(g_currentMemberDef->getReference(),
g_currentMemberDef->getOutputFileBase(),
g_currentMemberDef->anchor(),g_yyLineNr);
setCurrentDoc(lineAnchor);
}
else if (d->isLinkableInProject())
{
g_code->writeLineNumber(d->getReference(),
d->getOutputFileBase(),
0,g_yyLineNr);
setCurrentDoc(lineAnchor);
}
}
else
{
g_code->writeLineNumber(0,0,0,g_yyLineNr);
}
}
DBG_CTX((stderr,"startCodeLine(%d)\n",g_yyLineNr));
g_code->startCodeLine(g_sourceFileDef && g_lineNumbers);
if (g_currentFontClass)
{
g_code->startFontClass(g_currentFontClass);
}
}
static void endFontClass();
static void startFontClass(const char *s);
static void endCodeLine()
{
DBG_CTX((stderr,"endCodeLine(%d)\n",g_yyLineNr));
endFontClass();
g_code->endCodeLine();
}
static void nextCodeLine()
{
const char * fc = g_currentFontClass;
endCodeLine();
if (g_yyLineNr<g_inputLines)
{
g_currentFontClass = fc;
startCodeLine();
}
}
/*! write a code fragment `text' that may span multiple lines, inserting
* line numbers for each line.
*/
static void codifyLines(const char *text)
{
//printf("codifyLines(%d,\"%s\")\n",g_yyLineNr,text);
const char *p=text,*sp=p;
char c;
bool done=FALSE;
while (!done)
{
sp=p;
while ((c=*p++) && c!='\n') { g_yyColNr++; }
if (c=='\n')
{
g_yyLineNr++;
g_yyColNr=1;
//*(p-1)='\0';
int l = (int)(p-sp-1);
char *tmp = (char*)malloc(l+1);
memcpy(tmp,sp,l);
tmp[l]='\0';
g_code->codify(tmp);
free(tmp);
nextCodeLine();
}
else
{
g_code->codify(sp);
done=TRUE;
}
}
}
/*! writes a link to a fragment \a text that may span multiple lines, inserting
* line numbers for each line. If \a text contains newlines, the link will be
* split into multiple links with the same destination, one for each line.
*/
static void writeMultiLineCodeLink(CodeOutputInterface &ol,
Definition *d,
const char *text)
{
static bool sourceTooltips = Config_getBool("SOURCE_TOOLTIPS");
TooltipManager::instance()->addTooltip(d);
QCString ref = d->getReference();
QCString file = d->getOutputFileBase();
QCString anchor = d->anchor();
QCString tooltip;
if (!sourceTooltips) // fall back to simple "title" tooltips
{
tooltip = d->briefDescriptionAsTooltip();
}
bool done=FALSE;
char *p=(char *)text;
while (!done)
{
char *sp=p;
char c;
while ((c=*p++) && c!='\n') { }
if (c=='\n')
{
g_yyLineNr++;
*(p-1)='\0';
//printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
ol.writeCodeLink(ref,file,anchor,sp,tooltip);
nextCodeLine();
}
else
{
//printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
ol.writeCodeLink(ref,file,anchor,sp,tooltip);
done=TRUE;
}
}
}
static void addType()
{
if (g_name=="const") { g_name.resize(0); return; }
if (!g_type.isEmpty()) g_type += ' ' ;
g_type += g_name ;
g_name.resize(0) ;
if (!g_type.isEmpty()) g_type += ' ' ;
g_type += g_args ;
g_args.resize(0) ;
}
static void addParmType()
{
if (g_parmName=="const") { g_parmName.resize(0); return; }
if (!g_parmType.isEmpty()) g_parmType += ' ' ;
g_parmType += g_parmName ;
g_parmName.resize(0) ;
}
static void addUsingDirective(const char *name)
{
if (g_sourceFileDef && name)
{
NamespaceDef *nd = Doxygen::namespaceSDict->find(name);
if (nd)
{
g_sourceFileDef->addUsingDirective(nd);
}
}
}
static void setParameterList(MemberDef *md)
{
g_classScope = md->getClassDef() ? md->getClassDef()->name().data() : "";
ArgumentList *al = md->argumentList();
if (al==0) return;
ArgumentListIterator it(*al);
Argument *a;
for (;(a=it.current());++it)
{
g_parmName = a->name.copy();
g_parmType = a->type.copy();
int i = g_parmType.find('*');
if (i!=-1) g_parmType = g_parmType.left(i);
i = g_parmType.find('&');
if (i!=-1) g_parmType = g_parmType.left(i);
g_parmType.stripPrefix("const ");
g_parmType=g_parmType.stripWhiteSpace();
g_theVarContext.addVariable(g_parmType,g_parmName);
}
}
static ClassDef *stripClassName(const char *s,Definition *d=g_currentDefinition)
{
int pos=0;
QCString type = s;
QCString className;
QCString templSpec;
while (extractClassNameFromType(type,pos,className,templSpec)!=-1)
{
QCString clName=className+templSpec;
ClassDef *cd=0;
if (!g_classScope.isEmpty())
{
cd=getResolvedClass(d,g_sourceFileDef,g_classScope+"::"+clName);
}
if (cd==0)
{
cd=getResolvedClass(d,g_sourceFileDef,clName);
}
//printf("stripClass trying `%s' = %p\n",clName.data(),cd);
if (cd)
{
return cd;
}
}
return 0;
}
static MemberDef *setCallContextForVar(const QCString &name)
{
if (name.isEmpty()) return 0;
DBG_CTX((stderr,"setCallContextForVar(%s) g_classScope=%s\n",name.data(),g_classScope.data()));
int scopeEnd = name.findRev("::");
if (scopeEnd!=-1) // name with explicit scope
{
QCString scope = name.left(scopeEnd);
QCString locName = name.right(name.length()-scopeEnd-2);
//printf("explicit scope: name=%s scope=%s\n",locName.data(),scope.data());
ClassDef *mcd = getClass(scope);
if (mcd && !locName.isEmpty())
{
MemberDef *md=mcd->getMemberByName(locName);
if (md)
{
//printf("name=%s scope=%s\n",locName.data(),scope.data());
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
return md;
}
}
else // check namespace as well
{
NamespaceDef *mnd = getResolvedNamespace(scope);
if (mnd && !locName.isEmpty())
{
MemberDef *md=mnd->getMemberByName(locName);
if (md)
{
//printf("name=%s scope=%s\n",locName.data(),scope.data());
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
return md;
}
}
}
}
MemberName *mn;
ClassDef *mcd = g_theVarContext.findVariable(name);
if (mcd) // local variable
{
DBG_CTX((stderr,"local variable?\n"));
if (mcd!=VariableContext::dummyContext)
{
DBG_CTX((stderr,"local var `%s' mcd=%s\n",name.data(),mcd->name().data()));
g_theCallContext.setClass(mcd);
}
}
else
{
DBG_CTX((stderr,"class member? scope=%s\n",g_classScope.data()));
// look for a class member
mcd = getClass(g_classScope);
if (mcd)
{
DBG_CTX((stderr,"Inside class %s\n",mcd->name().data()));
MemberDef *md=mcd->getMemberByName(name);
if (md)
{
DBG_CTX((stderr,"Found member %s\n",md->name().data()));
if (g_scopeStack.top()!=CLASSBLOCK)
{
DBG_CTX((stderr,"class member `%s' mcd=%s\n",name.data(),mcd->name().data()));
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
}
return md;
}
}
}
// look for a global member
if ((mn=Doxygen::functionNameSDict->find(name)))
{
//printf("global var `%s'\n",name.data());
if (mn->count()==1) // global defined only once
{
MemberDef *md=mn->getFirst();
if (!md->isStatic() || md->getBodyDef()==g_sourceFileDef)
{
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
return md;
}
return 0;
}
else if (mn->count()>1) // global defined more than once
{
MemberNameIterator it(*mn);
MemberDef *md;
for (;(md=it.current());++it)
{
//printf("mn=%p md=%p md->getBodyDef()=%p g_sourceFileDef=%p\n",
// mn,md,
// md->getBodyDef(),g_sourceFileDef);
// in case there are multiple members we could link to, we
// only link to members if defined in the same file or
// defined as external.
if ((!md->isStatic() || md->getBodyDef()==g_sourceFileDef) &&
(g_forceTagReference.isEmpty() || g_forceTagReference==md->getReference())
)
{
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
//printf("returning member %s in source file %s\n",md->name().data(),g_sourceFileDef->name().data());
return md;
}
}
return 0;
}
}
return 0;
}
static void updateCallContextForSmartPointer()
{
ClassDef *cd = g_theCallContext.getClass();
//printf("updateCallContextForSmartPointer() cd=%s\n",cd ? cd->name().data() : "<none>");
MemberDef *md;
if (cd && (md=cd->isSmartPointer()))
{
ClassDef *ncd = stripClassName(md->typeString(),md->getOuterScope());
if (ncd)
{
g_theCallContext.setClass(ncd);
//printf("Found smart pointer call %s->%s!\n",cd->name().data(),ncd->name().data());
}
}
}
static bool getLinkInScope(const QCString &c, // scope
const QCString &m, // member
const char *memberText, // exact text
CodeOutputInterface &ol,
const char *text,
bool varOnly=FALSE
)
{
MemberDef *md;
ClassDef *cd;
FileDef *fd;
NamespaceDef *nd;
GroupDef *gd;
DBG_CTX((stderr,"getLinkInScope: trying `%s'::`%s' varOnly=%d\n",c.data(),m.data(),varOnly));
if (getDefs(c,m,"()",md,cd,fd,nd,gd,FALSE,g_sourceFileDef,FALSE,g_forceTagReference) &&
md->isLinkable() && (!varOnly || md->isVariable()))
{
//printf("found it %s!\n",md->qualifiedName().data());
if (g_exampleBlock)
{
QCString anchor;
anchor.sprintf("a%d",g_anchorCount);
//printf("addExampleFile(%s,%s,%s)\n",anchor.data(),g_exampleName.data(),
// g_exampleFile.data());
if (md->addExample(anchor,g_exampleName,g_exampleFile))
{
ol.writeCodeAnchor(anchor);
g_anchorCount++;
}
}
Definition *d = md->getOuterScope()==Doxygen::globalScope ?
md->getFileDef() : md->getOuterScope();
if (md->getGroupDef()) d = md->getGroupDef();
if (d && d->isLinkable())
{
g_theCallContext.setClass(stripClassName(md->typeString(),md->getOuterScope()));
//printf("g_currentDefinition=%p g_currentMemberDef=%p g_insideBody=%d\n",
// g_currentDefinition,g_currentMemberDef,g_insideBody);
if (g_currentDefinition && g_currentMemberDef &&
md!=g_currentMemberDef && g_insideBody && g_collectXRefs)
{
addDocCrossReference(g_currentMemberDef,md);
}
//printf("d->getReference()=`%s' d->getOutputBase()=`%s' name=`%s' member name=`%s'\n",d->getReference().data(),d->getOutputFileBase().data(),d->name().data(),md->name().data());
writeMultiLineCodeLink(ol,md, text ? text : memberText);
addToSearchIndex(text ? text : memberText);
return TRUE;
}
}
return FALSE;
}
static bool getLink(const char *className,
const char *memberName,
CodeOutputInterface &ol,
const char *text=0,
bool varOnly=FALSE)
{
//printf("getLink(%s,%s) g_curClassName=%s\n",className,memberName,g_curClassName.data());
QCString m=removeRedundantWhiteSpace(memberName);
QCString c=className;
if (!getLinkInScope(c,m,memberName,ol,text,varOnly))
{
if (!g_curClassName.isEmpty())
{
if (!c.isEmpty()) c.prepend("::");
c.prepend(g_curClassName);
return getLinkInScope(c,m,memberName,ol,text,varOnly);
}
return FALSE;
}
return TRUE;
}
static void generateClassOrGlobalLink(CodeOutputInterface &ol,const char *clName,
bool typeOnly=FALSE,bool varOnly=FALSE)
{
int i=0;
if (*clName=='~') // correct for matching negated values i.s.o. destructors.
{
g_code->codify("~");
clName++;
}
QCString className=clName;
if (className.isEmpty()) return;
if (g_insideProtocolList) // for Obj-C
{
className+="-p";
}
if (g_insidePHP)
{
className = substitute(className,"\\","::"); // for PHP namespaces
}
else if (g_insideCS || g_insideJava)
{
className = substitute(className,".","::"); // for PHP namespaces
}
ClassDef *cd=0,*lcd=0;
MemberDef *md=0;
bool isLocal=FALSE;
//printf("generateClassOrGlobalLink(className=%s)\n",className.data());
if ((lcd=g_theVarContext.findVariable(className))==0) // not a local variable
{
Definition *d = g_currentDefinition;
//printf("d=%s g_sourceFileDef=%s\n",d?d->name().data():"<none>",g_sourceFileDef?g_sourceFileDef->name().data():"<none>");
cd = getResolvedClass(d,g_sourceFileDef,className,&md);
DBG_CTX((stderr,"non-local variable name=%s context=%d cd=%s md=%s!\n",
className.data(),g_theVarContext.count(),cd?cd->name().data():"<none>",
md?md->name().data():"<none>"));
if (cd==0 && md==0 && (i=className.find('<'))!=-1)
{
QCString bareName = className.left(i); //stripTemplateSpecifiersFromScope(className);
DBG_CTX((stderr,"bareName=%s\n",bareName.data()));
if (bareName!=className)
{
cd=getResolvedClass(d,g_sourceFileDef,bareName,&md); // try unspecialized version
}
}
//printf("md=%s\n",md?md->name().data():"<none>");
DBG_CTX((stderr,"is found as a type %s\n",cd?cd->name().data():"<null>"));
if (cd==0 && md==0) // also see if it is variable or enum or enum value
{
if (getLink(g_classScope,clName,ol,clName,varOnly))
{
return;
}
}
}
else
{
//printf("local variable!\n");
if (lcd!=VariableContext::dummyContext)
{
//printf("non-dummy context lcd=%s!\n",lcd->name().data());
g_theCallContext.setClass(lcd);
// to following is needed for links to a global variable, but is
// no good for a link to a local variable that is also a global symbol.
//if (getLink(g_classScope,clName,ol,clName))
//{
//return;
//}
}
isLocal=TRUE;
DBG_CTX((stderr,"is a local variable cd=%p!\n",cd));
}
if (cd && cd->isLinkable()) // is it a linkable class
{
DBG_CTX((stderr,"is linkable class %s\n",clName));
if (g_exampleBlock)
{