-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdsymbol.c
1452 lines (1252 loc) · 36.5 KB
/
dsymbol.c
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
// Compiler implementation of the D programming language
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
// License for redistribution is by either the Artistic License
// in artistic.txt, or the GNU General Public License in gnu.txt.
// See the included readme.txt for details.
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "rmem.h"
#include "speller.h"
#include "aav.h"
#include "mars.h"
#include "dsymbol.h"
#include "aggregate.h"
#include "identifier.h"
#include "module.h"
#include "mtype.h"
#include "expression.h"
#include "statement.h"
#include "declaration.h"
#include "id.h"
#include "scope.h"
#include "init.h"
#include "import.h"
#include "template.h"
#include "attrib.h"
/****************************** Dsymbol ******************************/
Dsymbol::Dsymbol()
{
//printf("Dsymbol::Dsymbol(%p)\n", this);
this->ident = NULL;
this->c_ident = NULL;
this->parent = NULL;
this->csym = NULL;
this->isym = NULL;
this->loc = 0;
this->comment = NULL;
this->scope = NULL;
this->suppress_js_output = 0;
}
Dsymbol::Dsymbol(Identifier *ident)
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this->ident = ident;
this->c_ident = NULL;
this->parent = NULL;
this->csym = NULL;
this->isym = NULL;
this->loc = 0;
this->comment = NULL;
this->scope = NULL;
this->suppress_js_output = 0;
}
int Dsymbol::equals(Object *o)
{ Dsymbol *s;
if (this == o)
return TRUE;
s = (Dsymbol *)(o);
// Overload sets don't have an ident
if (s && ident && s->ident && ident->equals(s->ident))
return TRUE;
return FALSE;
}
/**************************************
* Copy the syntax.
* Used for template instantiations.
* If s is NULL, allocate the new object, otherwise fill it in.
*/
Dsymbol *Dsymbol::syntaxCopy(Dsymbol *s)
{
print();
printf("%s %s\n", kind(), toChars());
assert(0);
return NULL;
}
/**************************************
* 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
*/
int Dsymbol::oneMember(Dsymbol **ps, Identifier *ident)
{
//printf("Dsymbol::oneMember()\n");
*ps = this;
return TRUE;
}
/*****************************************
* Same as Dsymbol::oneMember(), but look at an array of Dsymbols.
*/
int Dsymbol::oneMembers(Dsymbols *members, Dsymbol **ps, Identifier *ident)
{
//printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0);
Dsymbol *s = NULL;
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *sx = (*members)[i];
int 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 == NULL);
return FALSE;
}
if (*ps)
{
if (ident)
{
if (!(*ps)->ident || !(*ps)->ident->equals(ident))
continue;
}
if (s) // more than one symbol
{ *ps = NULL;
//printf("\tfalse 2\n");
return FALSE;
}
s = *ps;
}
}
}
*ps = s; // s is the one symbol, NULL if none
//printf("\ttrue\n");
return TRUE;
}
/*****************************************
* Is Dsymbol a variable that contains pointers?
*/
int Dsymbol::hasPointers()
{
//printf("Dsymbol::hasPointers() %s\n", toChars());
return 0;
}
bool Dsymbol::hasStaticCtorOrDtor()
{
//printf("Dsymbol::hasStaticCtorOrDtor() %s\n", toChars());
return FALSE;
}
char *Dsymbol::toChars()
{
return ident ? ident->toChars() : (char *)"__anonymous";
}
const char *Dsymbol::toPrettyChars()
{ Dsymbol *p;
char *s;
char *q;
size_t len;
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
if (!parent)
return toChars();
len = 0;
for (p = this; p; p = p->parent)
len += strlen(p->toChars()) + 1;
s = (char *)mem.malloc(len);
q = s + len - 1;
*q = 0;
for (p = this; p; p = p->parent)
{
char *t = p->toChars();
len = strlen(t);
q -= len;
memcpy(q, t, len);
if (q == s)
break;
q--;
#if TARGET_NET
if (AggregateDeclaration* ad = p->isAggregateDeclaration())
{
if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration())
{
*q = '/';
continue;
}
}
#endif
*q = '.';
}
return s;
}
char *Dsymbol::locToChars()
{
OutBuffer buf;
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
return loc.toChars();
}
const char *Dsymbol::kind()
{
return "symbol";
}
/*********************************
* If this symbol is really an alias for another,
* return that other.
*/
Dsymbol *Dsymbol::toAlias()
{
return this;
}
Dsymbol *Dsymbol::toParent()
{
return parent ? parent->pastMixin() : NULL;
}
Dsymbol *Dsymbol::pastMixin()
{
Dsymbol *s = this;
//printf("Dsymbol::pastMixin() %s\n", toChars());
while (s && s->isTemplateMixin())
s = s->parent;
return s;
}
/**********************************
* Use this instead of toParent() when looking for the
* 'this' pointer of the enclosing function/class.
*/
Dsymbol *Dsymbol::toParent2()
{
Dsymbol *s = parent;
while (s && s->isTemplateInstance())
s = s->parent;
return s;
}
TemplateInstance *Dsymbol::inTemplateInstance()
{
for (Dsymbol *parent = this->parent; parent; parent = parent->parent)
{
TemplateInstance *ti = parent->isTemplateInstance();
if (ti)
return ti;
}
return NULL;
}
int Dsymbol::isAnonymous()
{
return ident ? 0 : 1;
}
/*************************************
* Set scope for future semantic analysis so we can
* deal better with forward references.
*/
void Dsymbol::setScope(Scope *sc)
{
//printf("Dsymbol::setScope() %p %s\n", this, toChars());
if (!sc->nofree)
sc->setNoFree(); // may need it even after semantic() finishes
scope = sc;
}
void Dsymbol::importAll(Scope *sc)
{
}
/*************************************
* Does semantic analysis on the public face of declarations.
*/
void Dsymbol::semantic0(Scope *sc)
{
}
void Dsymbol::semantic(Scope *sc)
{
error("%p has no semantic routine", this);
}
/*************************************
* Does semantic analysis on initializers and members of aggregates.
*/
void Dsymbol::semantic2(Scope *sc)
{
// Most Dsymbols have no further semantic analysis needed
}
/*************************************
* Does semantic analysis on function bodies.
*/
void Dsymbol::semantic3(Scope *sc)
{
// Most Dsymbols have no further semantic analysis needed
}
/*************************************
* Look for function inlining possibilities.
*/
void Dsymbol::inlineScan()
{
// Most Dsymbols aren't functions
}
/*********************************************
* Search for ident as member of s.
* Input:
* flags: 1 don't find private members
* 2 don't give error messages
* 4 return NULL if ambiguous
* Returns:
* NULL if not found
*/
Dsymbol *Dsymbol::search(Loc loc, Identifier *ident, int flags)
{
//printf("Dsymbol::search(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
return NULL;
}
/***************************************************
* Search for symbol with correct spelling.
*/
void *symbol_search_fp(void *arg, const char *seed)
{
Dsymbol *s = (Dsymbol *)arg;
Identifier id(seed, 0);
Module::clearCache();
s = s->search(0, &id, 4|2);
return s;
}
Dsymbol *Dsymbol::search_correct(Identifier *ident)
{
if (global.gag)
return NULL; // don't do it for speculative compiles; too time consuming
return (Dsymbol *)speller(ident->toChars(), &symbol_search_fp, this, idchars);
}
/***************************************
* Search for identifier id as a member of 'this'.
* id may be a template instance.
* Returns:
* symbol found, NULL if not
*/
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Dsymbol *s = toAlias();
Dsymbol *sm;
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, id, 0);
break;
case DYNCAST_DSYMBOL:
{ // It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
id = ti->name;
sm = s->search(loc, id, 0);
if (!sm)
{ error("template identifier %s is not a member of %s %s",
id->toChars(), s->kind(), s->toChars());
return NULL;
}
sm = sm->toAlias();
TemplateDeclaration *td = sm->isTemplateDeclaration();
if (!td)
{
error("%s is not a template, it is a %s", id->toChars(), sm->kind());
return NULL;
}
ti->tempdecl = td;
if (!ti->semanticRun)
ti->semantic(sc);
sm = ti->toAlias();
break;
}
default:
assert(0);
}
return sm;
}
int Dsymbol::overloadInsert(Dsymbol *s)
{
//printf("Dsymbol::overloadInsert('%s')\n", s->toChars());
return FALSE;
}
void Dsymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring(toChars());
}
unsigned Dsymbol::size(Loc loc)
{
error("Dsymbol '%s' has no size\n", toChars());
return 0;
}
int Dsymbol::isforwardRef()
{
return FALSE;
}
AggregateDeclaration *Dsymbol::isThis()
{
return NULL;
}
AggregateDeclaration *Dsymbol::isAggregateMember() // are we a member of an aggregate?
{
Dsymbol *parent = toParent();
if (parent && parent->isAggregateDeclaration())
return (AggregateDeclaration *)parent;
return NULL;
}
ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class?
{
AggregateDeclaration *ad = isAggregateMember();
return ad ? ad->isClassDeclaration() : NULL;
}
void Dsymbol::defineRef(Dsymbol *s)
{
assert(0);
}
int Dsymbol::isExport()
{
return FALSE;
}
int Dsymbol::isImportedSymbol()
{
return FALSE;
}
int Dsymbol::isDeprecated()
{
return FALSE;
}
#if DMDV2
int Dsymbol::isOverloadable()
{
return 0;
}
#endif
LabelDsymbol *Dsymbol::isLabel() // is this a LabelDsymbol()?
{
return NULL;
}
AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration?
{
//printf("Dsymbol::isMember() %s\n", toChars());
Dsymbol *parent = toParent();
//printf("parent is %s %s\n", parent->kind(), parent->toChars());
return parent ? parent->isAggregateDeclaration() : NULL;
}
Type *Dsymbol::getType()
{
return NULL;
}
int Dsymbol::needThis()
{
return FALSE;
}
int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
//printf("Dsymbol::addMember('%s')\n", toChars());
//printf("Dsymbol::addMember(this = %p, '%s' scopesym = '%s')\n", this, toChars(), sd->toChars());
//printf("Dsymbol::addMember(this = %p, '%s' sd = %p, sd->symtab = %p)\n", this, toChars(), sd, sd->symtab);
parent = sd;
if (!isAnonymous()) // no name, so can't add it to symbol table
{
if (!sd->symtabInsert(this)) // if name is already defined
{
Dsymbol *s2;
s2 = sd->symtab->lookup(ident);
if (!s2->overloadInsert(this))
{
sd->multiplyDefined(0, this, s2);
}
}
if (sd->isAggregateDeclaration() || sd->isEnumDeclaration())
{
if (ident == Id::__sizeof || ident == Id::__xalignof || ident == Id::mangleof)
error(".%s property cannot be redefined", ident->toChars());
}
return 1;
}
return 0;
}
void Dsymbol::error(const char *format, ...)
{
//printf("Dsymbol::error()\n");
if (!loc.filename) // avoid bug 5861.
{
Module *m = getModule();
if (m && m->srcfile)
loc.filename = m->srcfile->toChars();
}
va_list ap;
va_start(ap, format);
verror(loc, format, ap);
va_end(ap);
}
void Dsymbol::error(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verror(loc, format, ap);
va_end(ap);
}
void Dsymbol::verror(Loc loc, const char *format, va_list ap)
{
if (!global.gag)
{
char *p = loc.toChars();
if (!*p)
p = locToChars();
if (*p)
fprintf(stdmsg, "%s: ", p);
mem.free(p);
fprintf(stdmsg, "Error: ");
fprintf(stdmsg, "%s %s ", kind(), toPrettyChars());
vfprintf(stdmsg, format, ap);
fprintf(stdmsg, "\n");
fflush(stdmsg);
//halt();
}
else
{
global.gaggedErrors++;
}
global.errors++;
//fatal();
}
void Dsymbol::checkDeprecated(Loc loc, Scope *sc)
{
if (!global.params.useDeprecated && isDeprecated())
{
// Don't complain if we're inside a deprecated symbol's scope
for (Dsymbol *sp = sc->parent; sp; sp = sp->parent)
{ if (sp->isDeprecated())
goto L1;
}
for (Scope *sc2 = sc; sc2; sc2 = sc2->enclosing)
{
if (sc2->scopesym && sc2->scopesym->isDeprecated())
goto L1;
// If inside a StorageClassDeclaration that is deprecated
if (sc2->stc & STCdeprecated)
goto L1;
}
error(loc, "is deprecated");
}
L1:
Declaration *d = isDeclaration();
if (d && d->storage_class & STCdisable)
{
if (!(sc->func && sc->func->storage_class & STCdisable))
{
if (d->ident == Id::cpctor && d->toParent())
d->toParent()->error(loc, "is not copyable because it is annotated with @disable");
else
error(loc, "is not callable because it is annotated with @disable");
}
}
}
/**********************************
* Determine which Module a Dsymbol is in.
*/
Module *Dsymbol::getModule()
{
//printf("Dsymbol::getModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->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;
}
/**********************************
* Determine which Module a Dsymbol is in, as far as access rights go.
*/
Module *Dsymbol::getAccessModule()
{
//printf("Dsymbol::getAccessModule()\n");
TemplateDeclaration *td = getFuncTemplateDecl(this);
if (td)
return td->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->isnested)
/* 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;
}
/*************************************
*/
enum PROT Dsymbol::prot()
{
return PROTpublic;
}
/*************************************
* Do syntax copy of an array of Dsymbol's.
*/
Dsymbols *Dsymbol::arraySyntaxCopy(Dsymbols *a)
{
Dsymbols *b = NULL;
if (a)
{
b = a->copy();
for (size_t i = 0; i < b->dim; i++)
{
Dsymbol *s = (*b)[i];
s = s->syntaxCopy(NULL);
(*b)[i] = s;
}
}
return b;
}
/****************************************
* Add documentation comment to Dsymbol.
* Ignore NULL comments.
*/
void Dsymbol::addComment(unsigned char *comment)
{
//if (comment)
//printf("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars());
if (!this->comment)
this->comment = comment;
#if 1
else if (comment && strcmp((char *)comment, (char *)this->comment))
{ // Concatenate the two
this->comment = Lexer::combineComments(this->comment, comment);
}
#endif
}
/********************************* OverloadSet ****************************/
#if DMDV2
OverloadSet::OverloadSet()
: Dsymbol()
{
}
void OverloadSet::push(Dsymbol *s)
{
a.push(s);
}
const char *OverloadSet::kind()
{
return "overloadset";
}
#endif
/********************************* ScopeDsymbol ****************************/
ScopeDsymbol::ScopeDsymbol()
: Dsymbol()
{
members = NULL;
symtab = NULL;
imports = NULL;
prots = NULL;
}
ScopeDsymbol::ScopeDsymbol(Identifier *id)
: Dsymbol(id)
{
members = NULL;
symtab = NULL;
imports = NULL;
prots = NULL;
}
Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s)
{
//printf("ScopeDsymbol::syntaxCopy('%s')\n", toChars());
ScopeDsymbol *sd;
if (s)
sd = (ScopeDsymbol *)s;
else
sd = new ScopeDsymbol(ident);
sd->members = arraySyntaxCopy(members);
return sd;
}
Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
{
//printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags);
//if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0;
// Look in symbols declared in this module
Dsymbol *s = symtab ? symtab->lookup(ident) : NULL;
//printf("\ts = %p, imports = %p, %d\n", s, imports, imports ? imports->dim : 0);
if (s)
{
//printf("\ts = '%s.%s'\n",toChars(),s->toChars());
}
else if (imports)
{
OverloadSet *a = NULL;
// Look in imported modules
for (size_t i = 0; i < imports->dim; i++)
{ Dsymbol *ss = (*imports)[i];
Dsymbol *s2;
// If private import, don't search it
if (flags & 1 && prots[i] == PROTprivate)
continue;
//printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport());
/* Don't find private members if ss is a module
*/
s2 = ss->search(loc, ident, ss->isImport() ? 1 : 0);
if (!s)
s = s2;
else if (s2 && s != s2)
{
if (s->toAlias() == s2->toAlias())
{
/* After following aliases, we found the same symbol,
* so it's not an ambiguity.
* But if one alias is deprecated, prefer the other.
*/
if (s->isDeprecated())
s = s2;
}
else
{
/* Two imports of the same module should be regarded as
* the same.
*/
Import *i1 = s->isImport();
Import *i2 = s2->isImport();
if (!(i1 && i2 &&
(i1->mod == i2->mod ||
(!i1->parent->isImport() && !i2->parent->isImport() &&
i1->ident->equals(i2->ident))
)
)
)
{
/* If both s2 and s are overloadable (though we only
* need to check s once)
*/
if (s2->isOverloadable() && (a || s->isOverloadable()))
{ if (!a)
a = new OverloadSet();
/* Don't add to a[] if s2 is alias of previous sym
*/
for (size_t j = 0; j < a->a.dim; j++)
{ Dsymbol *s3 = a->a[j];
if (s2->toAlias() == s3->toAlias())
{
if (s3->isDeprecated())
a->a[j] = s2;
goto Lcontinue;
}
}
a->push(s2);
Lcontinue:
continue;
}
if (flags & 4) // if return NULL on ambiguity
return NULL;
if (!(flags & 2))
ScopeDsymbol::multiplyDefined(loc, s, s2);
break;
}
}
}
}
/* Build special symbol if we had multiple finds
*/
if (a)
{ assert(s);
a->push(s);
s = a;
}
if (s)
{
Declaration *d = s->isDeclaration();
if (d && d->protection == PROTprivate &&
!d->parent->isTemplateMixin() &&
!(flags & 2))
error(loc, "%s is private", d->toPrettyChars());
}
}
return s;
}
void ScopeDsymbol::importScope(Dsymbol *s, enum PROT protection)
{
//printf("%s->ScopeDsymbol::importScope(%s, %d)\n", toChars(), s->toChars(), protection);
// No circular or redundant import's
if (s != this)
{
if (!imports)
imports = new Dsymbols();
else
{
for (size_t i = 0; i < imports->dim; i++)
{ Dsymbol *ss = (*imports)[i];
if (ss == s) // if already imported
{
if (protection > prots[i])
prots[i] = protection; // upgrade access
return;
}
}
}
imports->push(s);
prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0]));
prots[imports->dim - 1] = protection;
}
}
int ScopeDsymbol::isforwardRef()
{
return (members == NULL);
}
void ScopeDsymbol::defineRef(Dsymbol *s)
{
ScopeDsymbol *ss;
ss = s->isScopeDsymbol();
members = ss->members;
ss->members = NULL;
}
void ScopeDsymbol::multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2)
{
#if 0
printf("ScopeDsymbol::multiplyDefined()\n");
printf("s1 = %p, '%s' kind = '%s', parent = %s\n", s1, s1->toChars(), s1->kind(), s1->parent ? s1->parent->toChars() : "");
printf("s2 = %p, '%s' kind = '%s', parent = %s\n", s2, s2->toChars(), s2->kind(), s2->parent ? s2->parent->toChars() : "");
#endif
if (loc.filename)
{ ::error(loc, "%s at %s conflicts with %s at %s",
s1->toPrettyChars(),
s1->locToChars(),
s2->toPrettyChars(),
s2->locToChars());
}
else
{
s1->error(loc, "conflicts with %s %s at %s",
s2->kind(),
s2->toPrettyChars(),
s2->locToChars());
}
}
Dsymbol *ScopeDsymbol::nameCollision(Dsymbol *s)
{
Dsymbol *sprev;
// Look to see if we are defining a forward referenced symbol
sprev = symtab->lookup(s->ident);
assert(sprev);
if (s->equals(sprev)) // if the same symbol
{
if (s->isforwardRef()) // if second declaration is a forward reference
return sprev;
if (sprev->isforwardRef())
{
sprev->defineRef(s); // copy data from s into sprev
return sprev;
}
}
multiplyDefined(0, s, sprev);
return sprev;
}
const char *ScopeDsymbol::kind()
{
return "ScopeDsymbol";
}
Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s)
{