forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsymbol.d
1761 lines (1586 loc) · 51.8 KB
/
dsymbol.d
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
/**
* The base class for a D symbol, which can be a module, variable, function, enum, etc.
*
* Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dsymbol.d, _dsymbol.d)
* Documentation: https://dlang.org/phobos/dmd_dsymbol.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dsymbol.d
*/
module dmd.dsymbol;
import core.stdc.stdarg;
import core.stdc.stdio;
import core.stdc.string;
import core.stdc.stdlib;
import dmd.aggregate;
import dmd.aliasthis;
import dmd.arraytypes;
import dmd.attrib;
import dmd.astenums;
import dmd.ast_node;
import dmd.gluelayer;
import dmd.dclass;
import dmd.declaration;
import dmd.denum;
import dmd.dimport;
import dmd.dmodule;
import dmd.dversion;
import dmd.dscope;
import dmd.dstruct;
import dmd.dtemplate;
import dmd.errors;
import dmd.expression;
import dmd.func;
import dmd.globals;
import dmd.id;
import dmd.identifier;
import dmd.init;
import dmd.lexer;
import dmd.location;
import dmd.mtype;
import dmd.nspace;
import dmd.root.aav;
import dmd.root.rmem;
import dmd.rootobject;
import dmd.root.string;
import dmd.statement;
import dmd.staticassert;
import dmd.tokens;
import dmd.visitor;
import dmd.common.outbuffer;
version (IN_LLVM)
{
// Functions to construct/destruct Dsymbol.ir
extern (C++) void* newIrDsymbol() nothrow @safe;
extern (C++) void deleteIrDsymbol(void*) nothrow;
}
/***************************************
* Calls dg(Dsymbol *sym) for each Dsymbol.
* If dg returns !=0, stops and returns that value else returns 0.
* Params:
* symbols = Dsymbols
* dg = delegate to call for each Dsymbol
* Returns:
* last value returned by dg()
*
* See_Also: $(REF each, dmd, root, array)
*/
int foreachDsymbol(Dsymbols* symbols, scope int delegate(Dsymbol) dg)
{
assert(dg);
if (symbols)
{
/* Do not use foreach, as the size of the array may expand during iteration
*/
for (size_t i = 0; i < symbols.length; ++i)
{
Dsymbol s = (*symbols)[i];
const result = dg(s);
if (result)
return result;
}
}
return 0;
}
/***************************************
* Calls dg(Dsymbol *sym) for each Dsymbol.
* Params:
* symbols = Dsymbols
* dg = delegate to call for each Dsymbol
*
* See_Also: $(REF each, dmd, root, array)
*/
void foreachDsymbol(Dsymbols* symbols, scope void delegate(Dsymbol) dg)
{
assert(dg);
if (symbols)
{
/* Do not use foreach, as the size of the array may expand during iteration
*/
for (size_t i = 0; i < symbols.length; ++i)
{
Dsymbol s = (*symbols)[i];
dg(s);
}
}
}
struct Ungag
{
uint oldgag;
extern (D) this(uint old) nothrow @safe
{
this.oldgag = old;
}
extern (C++) ~this() nothrow
{
global.gag = oldgag;
}
}
struct Visibility
{
///
enum Kind : ubyte
{
undefined,
none, // no access
private_,
package_,
protected_,
public_,
export_,
}
Kind kind;
Package pkg;
extern(C++) this(Visibility.Kind kind, Package pkg = null) pure nothrow @nogc @safe
{
this.kind = kind;
this.pkg = pkg;
}
extern (D):
/**
* Checks if `this` is less or more visible than `other`
*
* Params:
* other = Visibility to compare `this` to.
*
* Returns:
* A value `< 0` if `this` is less visible than `other`,
* a value `> 0` if `this` is more visible than `other`,
* and `0` if they are at the same level.
* Note that `package` visibility with different packages
* will also return `0`.
*/
int opCmp(const Visibility other) const pure nothrow @nogc @safe
{
return this.kind - other.kind;
}
///
unittest
{
assert(Visibility(Visibility.Kind.public_) > Visibility(Visibility.Kind.private_));
assert(Visibility(Visibility.Kind.private_) < Visibility(Visibility.Kind.protected_));
assert(Visibility(Visibility.Kind.package_) >= Visibility(Visibility.Kind.package_));
}
/**
* Checks if `this` is absolutely identical visibility attribute to `other`
*/
bool opEquals(ref const Visibility other) const @safe
{
if (this.kind == other.kind)
{
if (this.kind == Visibility.Kind.package_)
return this.pkg == other.pkg;
return true;
}
return false;
}
}
enum PASS : ubyte
{
initial, // initial state
semantic, // semantic() started
semanticdone, // semantic() done
semantic2, // semantic2() started
semantic2done, // semantic2() done
semantic3, // semantic3() started
semantic3done, // semantic3() done
inline, // inline started
inlinedone, // inline done
obj, // toObjFile() run
}
// Search options
alias SearchOptFlags = uint;
enum SearchOpt : SearchOptFlags
{
all = 0x00, // search for all symbols
ignorePrivateImports = 0x01, // don't search private imports
ignoreErrors = 0x02, // don't give error messages
ignoreAmbiguous = 0x04, // return NULL if ambiguous
localsOnly = 0x08, // only look at locals (don't search imports)
importsOnly = 0x10, // only look in imports
unqualifiedModule = 0x20, // the module scope search is unqualified,
// meaning don't search imports in that scope,
// because qualified module searches search
// their imports
tagNameSpace = 0x40, // search ImportC tag symbol table
ignoreVisibility = 0x80, // also find private and package protected symbols
}
/***********************************************************
* Struct/Class/Union field state.
* Used for transitory information when setting field offsets, such
* as bit fields.
*/
struct FieldState
{
uint offset; /// byte offset for next field
uint fieldOffset; /// byte offset for the start of the bit field
uint fieldSize; /// byte size of field
uint fieldAlign; /// byte alignment of field
uint bitOffset; /// bit offset for field
bool inFlight; /// bit field is in flight
void print() const
{
printf("FieldState.offset = %d bytes\n", offset);
printf(" .fieldOffset = %d bytes\n", fieldOffset);
printf(" .bitOffset = %d bits\n", bitOffset);
printf(" .fieldSize = %d bytes\n", fieldSize);
printf(" .inFlight = %d\n", inFlight);
}
}
// 99.9% of Dsymbols don't have attributes (at least in druntime and Phobos),
// so save memory by grouping them into a separate struct
private struct DsymbolAttributes
{
/// C++ namespace this symbol belongs to
CPPNamespaceDeclaration cppnamespace;
/// customized deprecation message
DeprecatedDeclaration depdecl_;
/// user defined attributes
UserAttributeDeclaration userAttribDecl;
}
/***********************************************************
*/
extern (C++) class Dsymbol : ASTNode
{
Identifier ident;
Dsymbol parent;
version (IN_LLVM)
{
void* ir; // IrDsymbol*
uint llvmInternal;
}
else
{
Symbol* csym; // symbol for code generator
}
const Loc loc; // where defined
Scope* _scope; // !=null means context to use for semantic()
const(char)* prettystring; // cached value of toPrettyChars()
private DsymbolAttributes* atts; /// attached attribute declarations
bool errors; // this symbol failed to pass semantic()
PASS semanticRun = PASS.initial;
ushort localNum; /// perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab
final extern (D) this() nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p)\n", this);
loc = Loc(null, 0, 0);
version (IN_LLVM)
{
this.ir = newIrDsymbol();
}
}
final extern (D) this(Identifier ident) nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this.loc = Loc(null, 0, 0);
this.ident = ident;
version (IN_LLVM)
{
this.ir = newIrDsymbol();
}
}
final extern (D) this(const ref Loc loc, Identifier ident) nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this.loc = loc;
this.ident = ident;
version (IN_LLVM)
{
this.ir = newIrDsymbol();
}
}
version (IN_LLVM)
{
final extern (D) ~this() nothrow
{
deleteIrDsymbol(this.ir);
this.ir = null;
}
}
static Dsymbol create(Identifier ident) nothrow @safe
{
return new Dsymbol(ident);
}
override const(char)* toChars() const
{
return ident ? ident.toChars() : "__anonymous";
}
// Getters / setters for fields stored in `DsymbolAttributes`
final nothrow pure @safe
{
private ref DsymbolAttributes getAtts()
{
if (!atts)
atts = new DsymbolAttributes();
return *atts;
}
inout(DeprecatedDeclaration) depdecl() inout { return atts ? atts.depdecl_ : null; }
inout(CPPNamespaceDeclaration) cppnamespace() inout { return atts ? atts.cppnamespace : null; }
inout(UserAttributeDeclaration) userAttribDecl() inout { return atts ? atts.userAttribDecl : null; }
DeprecatedDeclaration depdecl(DeprecatedDeclaration dd)
{
if (!dd && !atts)
return null;
return getAtts().depdecl_ = dd;
}
CPPNamespaceDeclaration cppnamespace(CPPNamespaceDeclaration ns)
{
if (!ns && !atts)
return null;
return getAtts().cppnamespace = ns;
}
UserAttributeDeclaration userAttribDecl(UserAttributeDeclaration uad)
{
if (!uad && !atts)
return null;
return getAtts().userAttribDecl = uad;
}
}
// helper to print fully qualified (template) arguments
const(char)* toPrettyCharsHelper()
{
return toChars();
}
final const(Loc) getLoc()
{
if (!loc.isValid()) // avoid bug 5861.
if (const m = getModule())
return Loc(m.srcfile.toChars(), 0, 0);
return loc;
}
final const(char)* locToChars()
{
return getLoc().toChars();
}
override bool equals(const RootObject o) const
{
if (this == o)
return true;
const s = o.isDsymbol();
if (!s)
return false;
// Overload sets don't have an ident
// Function-local declarations may have identical names
// if they are declared in different scopes
if (s && ident && s.ident && ident.equals(s.ident) && localNum == s.localNum)
return true;
return false;
}
final bool isAnonymous() const
{
return ident is null || ident.isAnonymous;
}
extern(D) private const(char)[] prettyFormatHelper()
{
const cstr = toPrettyChars();
return '`' ~ cstr.toDString() ~ "`\0";
}
/**********************************
* Determine which Module a Dsymbol is in.
*/
final Module getModule()
{
//printf("Dsymbol::getModule()\n");
if (TemplateInstance ti = isInstantiated())
return ti.tempdecl.getModule();
Dsymbol s = this;
while (s)
{
//printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars());
Module m = s.isModule();
if (m)
return m;
s = s.parent;
}
return null;
}
/**************************************
* Does this Dsymbol come from a C file?
* Returns:
* true if it does
*/
final bool isCsymbol()
{
if (Module m = getModule())
return m.filetype == FileType.c;
return false;
}
/**********************************
* Determine which Module a Dsymbol is in, as far as access rights go.
*/
final Module getAccessModule()
{
//printf("Dsymbol::getAccessModule()\n");
if (TemplateInstance ti = isInstantiated())
return ti.tempdecl.getAccessModule();
Dsymbol s = this;
while (s)
{
//printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars());
Module m = s.isModule();
if (m)
return m;
TemplateInstance ti = s.isTemplateInstance();
if (ti && ti.enclosing)
{
/* Because of local template instantiation, the parent isn't where the access
* rights come from - it's the template declaration
*/
s = ti.tempdecl;
}
else
s = s.parent;
}
return null;
}
/**
* `pastMixin` returns the enclosing symbol if this is a template mixin.
*
* `pastMixinAndNspace` does likewise, additionally skipping over Nspaces that
* are mangleOnly.
*
* See also `parent`, `toParent` and `toParent2`.
*/
final inout(Dsymbol) pastMixin() inout @safe
{
//printf("Dsymbol::pastMixin() %s\n", toChars());
if (!isTemplateMixin() && !isForwardingAttribDeclaration() && !isForwardingScopeDsymbol())
return this;
if (!parent)
return null;
return parent.pastMixin();
}
/**********************************
* `parent` field returns a lexically enclosing scope symbol this is a member of.
*
* `toParent()` returns a logically enclosing scope symbol this is a member of.
* It skips over TemplateMixin's.
*
* `toParent2()` returns an enclosing scope symbol this is living at runtime.
* It skips over both TemplateInstance's and TemplateMixin's.
* It's used when looking for the 'this' pointer of the enclosing function/class.
*
* `toParentDecl()` similar to `toParent2()` but always follows the template declaration scope
* instead of the instantiation scope.
*
* `toParentLocal()` similar to `toParentDecl()` but follows the instantiation scope
* if a template declaration is non-local i.e. global or static.
*
* Examples:
* ---
* module mod;
* template Foo(alias a) { mixin Bar!(); }
* mixin template Bar() {
* public { // VisibilityDeclaration
* void baz() { a = 2; }
* }
* }
* void test() {
* int v = 1;
* alias foo = Foo!(v);
* foo.baz();
* assert(v == 2);
* }
*
* // s == FuncDeclaration('mod.test.Foo!().Bar!().baz()')
* // s.parent == TemplateMixin('mod.test.Foo!().Bar!()')
* // s.toParent() == TemplateInstance('mod.test.Foo!()')
* // s.toParent2() == FuncDeclaration('mod.test')
* // s.toParentDecl() == Module('mod')
* // s.toParentLocal() == FuncDeclaration('mod.test')
* ---
*/
final inout(Dsymbol) toParent() inout @safe
{
return parent ? parent.pastMixin() : null;
}
/// ditto
final inout(Dsymbol) toParent2() inout @safe
{
if (!parent || !parent.isTemplateInstance && !parent.isForwardingAttribDeclaration() && !parent.isForwardingScopeDsymbol())
return parent;
return parent.toParent2;
}
/// ditto
final inout(Dsymbol) toParentDecl() inout
{
return toParentDeclImpl(false);
}
/// ditto
final inout(Dsymbol) toParentLocal() inout
{
return toParentDeclImpl(true);
}
private inout(Dsymbol) toParentDeclImpl(bool localOnly) inout
{
auto p = toParent();
if (!p || !p.isTemplateInstance())
return p;
auto ti = p.isTemplateInstance();
if (ti.tempdecl && (!localOnly || !(cast(TemplateDeclaration)ti.tempdecl).isstatic))
return ti.tempdecl.toParentDeclImpl(localOnly);
return parent.toParentDeclImpl(localOnly);
}
/**
* Returns the declaration scope scope of `this` unless any of the symbols
* `p1` or `p2` resides in its enclosing instantiation scope then the
* latter is returned.
*/
final Dsymbol toParentP(Dsymbol p1, Dsymbol p2 = null)
{
return followInstantiationContext(p1, p2) ? toParent2() : toParentLocal();
}
final inout(TemplateInstance) isInstantiated() inout
{
if (!parent)
return null;
auto ti = parent.isTemplateInstance();
if (ti && !ti.isTemplateMixin())
return ti;
return parent.isInstantiated();
}
/***
* Returns true if any of the symbols `p1` or `p2` resides in the enclosing
* instantiation scope of `this`.
*/
final bool followInstantiationContext(Dsymbol p1, Dsymbol p2 = null)
{
static bool has2This(Dsymbol s)
{
if (auto f = s.isFuncDeclaration())
return f.hasDualContext();
if (auto ad = s.isAggregateDeclaration())
return ad.vthis2 !is null;
return false;
}
if (has2This(this))
{
assert(p1);
auto outer = toParent();
while (outer)
{
auto ti = outer.isTemplateInstance();
if (!ti)
break;
foreach (oarg; *ti.tiargs)
{
auto sa = getDsymbol(oarg);
if (!sa)
continue;
sa = sa.toAlias().toParent2();
if (!sa)
continue;
if (sa == p1)
return true;
else if (p2 && sa == p2)
return true;
}
outer = ti.tempdecl.toParent();
}
return false;
}
return false;
}
// Check if this function is a member of a template which has only been
// instantiated speculatively, eg from inside is(typeof()).
// Return the speculative template instance it is part of,
// or NULL if not speculative.
final inout(TemplateInstance) isSpeculative() inout
{
if (!parent)
return null;
auto ti = parent.isTemplateInstance();
if (ti && ti.gagged)
return ti;
if (!parent.toParent())
return null;
return parent.isSpeculative();
}
final Ungag ungagSpeculative() const
{
uint oldgag = global.gag;
if (global.gag && !isSpeculative() && !toParent2().isFuncDeclaration())
global.gag = 0;
return Ungag(oldgag);
}
// kludge for template.isSymbol()
override final DYNCAST dyncast() const
{
return DYNCAST.dsymbol;
}
/*************************************
* Do syntax copy of an array of Dsymbol's.
*/
extern (D) static Dsymbols* arraySyntaxCopy(Dsymbols* a)
{
Dsymbols* b = null;
if (a)
{
b = a.copy();
for (size_t i = 0; i < b.length; i++)
{
(*b)[i] = (*b)[i].syntaxCopy(null);
}
}
return b;
}
Identifier getIdent()
{
return ident;
}
const(char)* toPrettyChars(bool QualifyTypes = false)
{
if (prettystring && !QualifyTypes)
return prettystring; // value cached for speed
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
if (!parent)
{
auto s = toChars();
if (!QualifyTypes)
prettystring = s;
return s;
}
OutBuffer buf;
void addQualifiers(Dsymbol p)
{
if (p.parent)
{
addQualifiers(p.parent);
buf.writeByte('.');
}
const s = QualifyTypes ? p.toPrettyCharsHelper() : p.toChars();
buf.writestring(s);
}
addQualifiers(this);
auto s = buf.extractSlice(true).ptr;
if (!QualifyTypes)
prettystring = s;
return s;
}
const(char)* kind() const pure nothrow @nogc @safe
{
return "symbol";
}
/*********************************
* If this symbol is really an alias for another,
* return that other.
* If needed, semantic() is invoked due to resolve forward reference.
*/
Dsymbol toAlias()
{
return this;
}
/*********************************
* Resolve recursive tuple expansion in eponymous template.
*/
Dsymbol toAlias2()
{
return toAlias();
}
bool overloadInsert(Dsymbol s)
{
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
return false;
}
/*********************************
* Returns:
* SIZE_INVALID when the size cannot be determined
*/
uinteger_t size(const ref Loc loc)
{
.error(loc, "%s `%s` symbol `%s` has no size", kind, toPrettyChars, toChars());
return SIZE_INVALID;
}
bool isforwardRef()
{
return false;
}
// is a 'this' required to access the member
inout(AggregateDeclaration) isThis() inout
{
return null;
}
// is Dsymbol exported?
bool isExport() const
{
return false;
}
// is Dsymbol imported?
bool isImportedSymbol() const
{
return false;
}
// is Dsymbol deprecated?
bool isDeprecated() @safe @nogc pure nothrow const
{
return false;
}
bool isOverloadable() const
{
return false;
}
// is this a LabelDsymbol()?
LabelDsymbol isLabel()
{
return null;
}
/// Returns an AggregateDeclaration when toParent() is that.
final inout(AggregateDeclaration) isMember() inout
{
//printf("Dsymbol::isMember() %s\n", toChars());
auto p = toParent();
//printf("parent is %s %s\n", p.kind(), p.toChars());
return p ? p.isAggregateDeclaration() : null;
}
/// Returns an AggregateDeclaration when toParent2() is that.
final inout(AggregateDeclaration) isMember2() inout
{
//printf("Dsymbol::isMember2() '%s'\n", toChars());
auto p = toParent2();
//printf("parent is %s %s\n", p.kind(), p.toChars());
return p ? p.isAggregateDeclaration() : null;
}
/// Returns an AggregateDeclaration when toParentDecl() is that.
final inout(AggregateDeclaration) isMemberDecl() inout
{
//printf("Dsymbol::isMemberDecl() '%s'\n", toChars());
auto p = toParentDecl();
//printf("parent is %s %s\n", p.kind(), p.toChars());
return p ? p.isAggregateDeclaration() : null;
}
/// Returns an AggregateDeclaration when toParentLocal() is that.
final inout(AggregateDeclaration) isMemberLocal() inout
{
//printf("Dsymbol::isMemberLocal() '%s'\n", toChars());
auto p = toParentLocal();
//printf("parent is %s %s\n", p.kind(), p.toChars());
return p ? p.isAggregateDeclaration() : null;
}
// is this a member of a ClassDeclaration?
final ClassDeclaration isClassMember()
{
auto ad = isMember();
return ad ? ad.isClassDeclaration() : null;
}
// is this a type?
Type getType()
{
return null;
}
// need a 'this' pointer?
bool needThis()
{
return false;
}
/*************************************
*/
Visibility visible() pure nothrow @nogc @safe
{
return Visibility(Visibility.Kind.public_);
}
/**************************************
* Copy the syntax.
* Used for template instantiations.
* If s is NULL, allocate the new object, otherwise fill it in.
*/
Dsymbol syntaxCopy(Dsymbol s)
{
printf("%s %s\n", kind(), toChars());
assert(0);
}
/**************************************
* Determine if this symbol is only one.
* Returns:
* false, ps = null: There are 2 or more symbols
* true, ps = null: There are zero symbols
* true, ps = symbol: The one and only one symbol
*/
bool oneMember(out Dsymbol ps, Identifier ident)
{
//printf("Dsymbol::oneMember()\n");
ps = this;
return true;
}
/*****************************************
* Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
*/
extern (D) static bool oneMembers(Dsymbols* members, out Dsymbol ps, Identifier ident)
{
//printf("Dsymbol::oneMembers() %d\n", members ? members.length : 0);
Dsymbol s = null;
if (!members)
{
ps = null;
return true;
}
for (size_t i = 0; i < members.length; i++)
{
Dsymbol sx = (*members)[i];
bool x = sx.oneMember(ps, ident);
//printf("\t[%d] kind %s = %d, s = %p\n", i, sx.kind(), x, *ps);
if (!x)
{
//printf("\tfalse 1\n");
assert(ps is null);
return false;
}
if (ps)
{
assert(ident);
if (!ps.ident || !ps.ident.equals(ident))
continue;
if (!s)
s = ps;
else if (s.isOverloadable() && ps.isOverloadable())
{
// keep head of overload set
FuncDeclaration f1 = s.isFuncDeclaration();
FuncDeclaration f2 = ps.isFuncDeclaration();
if (f1 && f2)
{
assert(!f1.isFuncAliasDeclaration());
assert(!f2.isFuncAliasDeclaration());
for (; f1 != f2; f1 = f1.overnext0)
{
if (f1.overnext0 is null)
{
f1.overnext0 = f2;
break;
}
}
}
}
else // more than one symbol
{
ps = null;
//printf("\tfalse 2\n");
return false;
}
}
}
ps = s; // s is the one symbol, null if none
//printf("\ttrue\n");
return true;
}
/*****************************************
* Is Dsymbol a variable that contains pointers?
*/
bool hasPointers()
{
//printf("Dsymbol::hasPointers() %s\n", toChars());
return false;
}
bool hasStaticCtorOrDtor()
{
//printf("Dsymbol::hasStaticCtorOrDtor() %s\n", toChars());
return false;
}
void addObjcSymbols(ClassDeclarations* classes, ClassDeclarations* categories)
{
}
void checkCtorConstInit()
{
}
/****************************************
* Add documentation comment to Dsymbol.
* Ignore NULL comments.
*/
void addComment(const(char)* comment)
{
if (!comment || !*comment)
return;
//printf("addComment '%s' to Dsymbol %p '%s'\n", comment, this, toChars());
void* h = cast(void*)this; // just the pointer is the key
auto p = h in commentHashTable;
if (!p)
{
commentHashTable[h] = comment;
return;
}
if (strcmp(*p, comment) != 0)
{
// Concatenate the two