Skip to content

Commit 73e603f

Browse files
committed
[dsymbol.d] move overloadInsert to dsymbolsem.d
1 parent beced98 commit 73e603f

File tree

8 files changed

+246
-278
lines changed

8 files changed

+246
-278
lines changed

compiler/src/dmd/declaration.d

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -449,132 +449,6 @@ extern (C++) final class AliasDeclaration : Declaration
449449
return sa;
450450
}
451451

452-
override bool overloadInsert(Dsymbol s)
453-
{
454-
//printf("[%s] AliasDeclaration::overloadInsert('%s') s = %s %s @ [%s]\n",
455-
// loc.toChars(), toChars(), s.kind(), s.toChars(), s.loc.toChars());
456-
457-
/** Aliases aren't overloadable themselves, but if their Aliasee is
458-
* overloadable they are converted to an overloadable Alias (either
459-
* FuncAliasDeclaration or OverDeclaration).
460-
*
461-
* This is done by moving the Aliasee into such an overloadable alias
462-
* which is then used to replace the existing Aliasee. The original
463-
* Alias (_this_) remains a useless shell.
464-
*
465-
* This is a horrible mess. It was probably done to avoid replacing
466-
* existing AST nodes and references, but it needs a major
467-
* simplification b/c it's too complex to maintain.
468-
*
469-
* A simpler approach might be to merge any colliding symbols into a
470-
* simple Overload class (an array) and then later have that resolve
471-
* all collisions.
472-
*/
473-
if (semanticRun >= PASS.semanticdone)
474-
{
475-
/* Semantic analysis is already finished, and the aliased entity
476-
* is not overloadable.
477-
*/
478-
if (type)
479-
{
480-
/*
481-
If type has been resolved already we could
482-
still be inserting an alias from an import.
483-
484-
If we are handling an alias then pretend
485-
it was inserting and return true, if not then
486-
false since we didn't even pretend to insert something.
487-
*/
488-
return this._import && this.equals(s);
489-
}
490-
491-
// https://issues.dlang.org/show_bug.cgi?id=23865
492-
// only insert if the symbol can be part of a set
493-
const s1 = s.toAlias();
494-
const isInsertCandidate = s1.isFuncDeclaration() || s1.isOverDeclaration() || s1.isTemplateDeclaration();
495-
496-
/* When s is added in member scope by static if, mixin("code") or others,
497-
* aliassym is determined already. See the case in: test/compilable/test61.d
498-
*/
499-
auto sa = aliassym.toAlias();
500-
501-
if (auto td = s.toAlias().isTemplateDeclaration())
502-
s = td.funcroot ? td.funcroot : td;
503-
504-
if (auto fd = sa.isFuncDeclaration())
505-
{
506-
auto fa = new FuncAliasDeclaration(ident, fd);
507-
fa.visibility = visibility;
508-
fa.parent = parent;
509-
aliassym = fa;
510-
if (isInsertCandidate)
511-
return aliassym.overloadInsert(s);
512-
}
513-
if (auto td = sa.isTemplateDeclaration())
514-
{
515-
auto od = new OverDeclaration(ident, td.funcroot ? td.funcroot : td);
516-
od.visibility = visibility;
517-
od.parent = parent;
518-
aliassym = od;
519-
if (isInsertCandidate)
520-
return aliassym.overloadInsert(s);
521-
}
522-
if (auto od = sa.isOverDeclaration())
523-
{
524-
if (sa.ident != ident || sa.parent != parent)
525-
{
526-
od = new OverDeclaration(ident, od);
527-
od.visibility = visibility;
528-
od.parent = parent;
529-
aliassym = od;
530-
}
531-
if (isInsertCandidate)
532-
return od.overloadInsert(s);
533-
}
534-
if (auto os = sa.isOverloadSet())
535-
{
536-
if (sa.ident != ident || sa.parent != parent)
537-
{
538-
os = new OverloadSet(ident, os);
539-
// TODO: visibility is lost here b/c OverloadSets have no visibility attribute
540-
// Might no be a practical issue, b/c the code below fails to resolve the overload anyhow.
541-
// ----
542-
// module os1;
543-
// import a, b;
544-
// private alias merged = foo; // private alias to overload set of a.foo and b.foo
545-
// ----
546-
// module os2;
547-
// import a, b;
548-
// public alias merged = bar; // public alias to overload set of a.bar and b.bar
549-
// ----
550-
// module bug;
551-
// import os1, os2;
552-
// void test() { merged(123); } // should only look at os2.merged
553-
//
554-
// os.visibility = visibility;
555-
os.parent = parent;
556-
aliassym = os;
557-
}
558-
if (isInsertCandidate)
559-
{
560-
os.push(s);
561-
return true;
562-
}
563-
}
564-
return false;
565-
}
566-
567-
/* Don't know yet what the aliased symbol is, so assume it can
568-
* be overloaded and check later for correctness.
569-
*/
570-
if (overnext)
571-
return overnext.overloadInsert(s);
572-
if (s is this)
573-
return true;
574-
overnext = s;
575-
return true;
576-
}
577-
578452
override const(char)* kind() const
579453
{
580454
return "alias";
@@ -639,17 +513,6 @@ extern (C++) final class OverDeclaration : Declaration
639513
return this.aliassym == s;
640514
}
641515

642-
override bool overloadInsert(Dsymbol s)
643-
{
644-
//printf("OverDeclaration::overloadInsert('%s') aliassym = %p, overnext = %p\n", s.toChars(), aliassym, overnext);
645-
if (overnext)
646-
return overnext.overloadInsert(s);
647-
if (s == this)
648-
return true;
649-
overnext = s;
650-
return true;
651-
}
652-
653516
override bool isOverloadable() const
654517
{
655518
return true;

compiler/src/dmd/declaration.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class AliasDeclaration final : public Declaration
200200

201201
static AliasDeclaration *create(Loc loc, Identifier *id, Type *type);
202202
AliasDeclaration *syntaxCopy(Dsymbol *) override;
203-
bool overloadInsert(Dsymbol *s) override;
204203
const char *kind() const override;
205204
Type *getType() override;
206205
bool isOverloadable() const override;
@@ -218,7 +217,6 @@ class OverDeclaration final : public Declaration
218217

219218
const char *kind() const override;
220219
bool equals(const RootObject * const o) const override;
221-
bool overloadInsert(Dsymbol *s) override;
222220

223221
Dsymbol *isUnique();
224222
bool isOverloadable() const override;
@@ -699,7 +697,6 @@ class FuncDeclaration : public Declaration
699697
Expressions *fdensureParams(Expressions *fdep);
700698
bool equals(const RootObject * const o) const override final;
701699

702-
bool overloadInsert(Dsymbol *s) override;
703700
bool inUnittest();
704701
LabelDsymbol *searchLabel(Identifier *ident, Loc loc);
705702
const char *toPrettyChars(bool QualifyTypes = false) override;
@@ -787,7 +784,6 @@ class PostBlitDeclaration final : public FuncDeclaration
787784
bool isVirtual() const override;
788785
bool addPreInvariant() override;
789786
bool addPostInvariant() override;
790-
bool overloadInsert(Dsymbol *s) override;
791787

792788
void accept(Visitor *v) override { v->visit(this); }
793789
};
@@ -800,7 +796,6 @@ class DtorDeclaration final : public FuncDeclaration
800796
bool isVirtual() const override;
801797
bool addPreInvariant() override;
802798
bool addPostInvariant() override;
803-
bool overloadInsert(Dsymbol *s) override;
804799

805800
void accept(Visitor *v) override { v->visit(this); }
806801
};

compiler/src/dmd/dimport.d

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,6 @@ extern (C++) final class Import : Dsymbol
141141
scopesym.addAccessiblePackage(mod, visibility); // d
142142
}
143143

144-
override bool overloadInsert(Dsymbol s)
145-
{
146-
/* Allow multiple imports with the same package base, but disallow
147-
* alias collisions
148-
* https://issues.dlang.org/show_bug.cgi?id=5412
149-
*/
150-
assert(ident && ident == s.ident);
151-
if (aliasId)
152-
return false;
153-
const imp = s.isImport();
154-
return imp && !imp.aliasId;
155-
}
156-
157144
override void accept(Visitor v)
158145
{
159146
v.visit(this);

compiler/src/dmd/dsymbol.d

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,6 @@ extern (C++) class Dsymbol : ASTNode
677677
return "symbol";
678678
}
679679

680-
bool overloadInsert(Dsymbol s)
681-
{
682-
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
683-
return false;
684-
}
685-
686680
/*********************************
687681
* Returns:
688682
* SIZE_INVALID when the size cannot be determined

0 commit comments

Comments
 (0)