Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Move a couple of functions out of dsymbol.d (#15789)" #15854

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 92 additions & 0 deletions compiler/src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import dmd.denum;
import dmd.dimport;
import dmd.dmodule;
import dmd.dsymbolsem;
import dmd.dversion;
import dmd.dscope;
import dmd.dstruct;
Expand All @@ -43,6 +44,7 @@
import dmd.location;
import dmd.mtype;
import dmd.nspace;
import dmd.opover;
import dmd.root.aav;
import dmd.root.rmem;
import dmd.rootobject;
Expand Down Expand Up @@ -732,6 +734,64 @@
{
}

/***************************************
* Search for identifier id as a member of `this`.
* `id` may be a template instance.
*
* Params:
* loc = location to print the error messages
* sc = the scope where the symbol is located
* id = the id of the symbol
* flags = the search flags which can be `SearchLocalsOnly` or `IgnorePrivateImports`
*
* Returns:
* symbol found, NULL if not
*/
extern (D) final Dsymbol searchX(const ref Loc loc, Scope* sc, RootObject id, int flags)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
Dsymbol s = toAlias();
Dsymbol sm;
if (Declaration d = s.isDeclaration())
{
if (d.inuse)
{
.error(loc, "circular reference to `%s`", d.toPrettyChars());
return null;
}
}
switch (id.dyncast())
{
case DYNCAST.identifier:
sm = s.search(loc, cast(Identifier)id, flags);
break;
case DYNCAST.dsymbol:
{
// It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol st = cast(Dsymbol)id;
TemplateInstance ti = st.isTemplateInstance();
sm = s.search(loc, ti.name);
if (!sm)
return null;
sm = sm.toAlias();
TemplateDeclaration td = sm.isTemplateDeclaration();
if (!td)
return null; // error but handled later
ti.tempdecl = td;
if (!ti.semanticRun)
ti.dsymbolSemantic(sc);
sm = ti.toAlias();
break;
}
case DYNCAST.type:
case DYNCAST.expression:

Check warning on line 788 in compiler/src/dmd/dsymbol.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbol.d#L787-L788

Added lines #L787 - L788 were not covered by tests
default:
assert(0);
}
return sm;
}

bool overloadInsert(Dsymbol s)
{
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
Expand Down Expand Up @@ -1344,6 +1404,38 @@
return "ScopeDsymbol";
}

/*******************************************
* Look for member of the form:
* const(MemberInfo)[] getMembers(string);
* Returns NULL if not found
*/
final FuncDeclaration findGetMembers()
{
Dsymbol s = search_function(this, Id.getmembers);
FuncDeclaration fdx = s ? s.isFuncDeclaration() : null;
version (none)
{
// Finish
__gshared TypeFunction tfgetmembers;
if (!tfgetmembers)
{
Scope sc;
sc.eSink = global.errorSink;
auto parameters = new Parameters();
Parameters* p = new Parameter(STC.in_, Type.tchar.constOf().arrayOf(), null, null);
parameters.push(p);
Type tret = null;
TypeFunction tf = new TypeFunction(parameters, tret, VarArg.none, LINK.d);
tfgetmembers = tf.dsymbolSemantic(Loc.initial, &sc).isTypeFunction();
}
if (fdx)
fdx = fdx.overloadExactMatch(tfgetmembers);
}
if (fdx && fdx.isVirtual())
fdx = null;

Check warning on line 1435 in compiler/src/dmd/dsymbol.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbol.d#L1435

Added line #L1435 was not covered by tests
return fdx;
}

/********************************
* Insert Dsymbol in table.
* Params:
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class ScopeDsymbol : public Dsymbol
bool isforwardRef() override final;
static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2);
const char *kind() const override;
FuncDeclaration *findGetMembers();
virtual Dsymbol *symtabInsert(Dsymbol *s);
virtual Dsymbol *symtabLookup(Dsymbol *s, Identifier *id);
bool hasStaticCtorOrDtor() override;
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ class ScopeDsymbol : public Dsymbol
bool isforwardRef() final override;
static void multiplyDefined(const Loc& loc, Dsymbol* s1, Dsymbol* s2);
const char* kind() const override;
FuncDeclaration* findGetMembers();
virtual Dsymbol* symtabInsert(Dsymbol* s);
virtual Dsymbol* symtabLookup(Dsymbol* s, Identifier* id);
bool hasStaticCtorOrDtor() override;
Expand Down Expand Up @@ -8214,8 +8215,6 @@ extern bool isSpeculativeType(Type* t);

extern bool builtinTypeInfo(Type* t);

extern FuncDeclaration* findGetMembers(ScopeDsymbol* dsym);

class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
{
public:
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import dmd.location;
import dmd.mtype;
import dmd.nspace;
import dmd.objc_glue;
import dmd.opover;
import dmd.statement;
import dmd.staticassert;
import dmd.target;
Expand Down
58 changes: 0 additions & 58 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -372,64 +372,6 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb
pt = t.merge();
}

/***************************************
* Search for identifier id as a member of `this`.
* `id` may be a template instance.
*
* Params:
* loc = location to print the error messages
* sc = the scope where the symbol is located
* id = the id of the symbol
* flags = the search flags which can be `SearchLocalsOnly` or `IgnorePrivateImports`
*
* Returns:
* symbol found, NULL if not
*/
private Dsymbol searchX(Dsymbol dsym, const ref Loc loc, Scope* sc, RootObject id, int flags)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
Dsymbol s = dsym.toAlias();
Dsymbol sm;
if (Declaration d = s.isDeclaration())
{
if (d.inuse)
{
.error(loc, "circular reference to `%s`", d.toPrettyChars());
return null;
}
}
switch (id.dyncast())
{
case DYNCAST.identifier:
sm = s.search(loc, cast(Identifier)id, flags);
break;
case DYNCAST.dsymbol:
{
// It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol st = cast(Dsymbol)id;
TemplateInstance ti = st.isTemplateInstance();
sm = s.search(loc, ti.name);
if (!sm)
return null;
sm = sm.toAlias();
TemplateDeclaration td = sm.isTemplateDeclaration();
if (!td)
return null; // error but handled later
ti.tempdecl = td;
if (!ti.semanticRun)
ti.dsymbolSemantic(sc);
sm = ti.toAlias();
break;
}
case DYNCAST.type:
case DYNCAST.expression:
default:
assert(0);
}
return sm;
}

/******************************************
* We've mistakenly parsed `t` as a type.
* Redo `t` as an Expression only if there are no type modifiers.
Expand Down
36 changes: 0 additions & 36 deletions compiler/src/dmd/typinf.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ import dmd.astenums;
import dmd.declaration;
import dmd.dmodule;
import dmd.dscope;
import dmd.dsymbol;
import dmd.dclass;
import dmd.dstruct;
import dmd.errors;
import dmd.expression;
import dmd.func;
import dmd.globals;
import dmd.id;
import dmd.location;
import dmd.mtype;
import dmd.opover;
import core.stdc.stdio;

/****************************************************
Expand Down Expand Up @@ -275,35 +271,3 @@ extern (C++) bool builtinTypeInfo(Type t)
}
return false;
}

/*******************************************
* Look for member of the form:
* const(MemberInfo)[] getMembers(string);
* Returns NULL if not found
*/
extern(C++) FuncDeclaration findGetMembers(ScopeDsymbol dsym)
{
Dsymbol s = search_function(dsym, Id.getmembers);
FuncDeclaration fdx = s ? s.isFuncDeclaration() : null;
version (none)
{
// Finish
__gshared TypeFunction tfgetmembers;
if (!tfgetmembers)
{
Scope sc;
sc.eSink = global.errorSink;
auto parameters = new Parameters();
Parameters* p = new Parameter(STC.in_, Type.tchar.constOf().arrayOf(), null, null);
parameters.push(p);
Type tret = null;
TypeFunction tf = new TypeFunction(parameters, tret, VarArg.none, LINK.d);
tfgetmembers = tf.dsymbolSemantic(Loc.initial, &sc).isTypeFunction();
}
if (fdx)
fdx = fdx.overloadExactMatch(tfgetmembers);
}
if (fdx && fdx.isVirtual())
fdx = null;
return fdx;
}
3 changes: 0 additions & 3 deletions compiler/src/dmd/typinf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
class Expression;
class Type;
struct Scope;
class FuncDeclaration;
class ScopeDsymbol;

bool genTypeInfo(Expression *e, const Loc &loc, Type *torig, Scope *sc);
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true);
bool isSpeculativeType(Type *t);
bool builtinTypeInfo(Type *t);
FuncDeclaration *findGetMembers(ScopeDsymbol *dsym);
2 changes: 1 addition & 1 deletion compiler/src/tests/cxxfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ class MiniGlueVisitor : public Visitor
if (mi->needmoduleinfo)
mi->accept(this);
}
(void)findGetMembers(d);
(void)d->findGetMembers();
(void)d->sctor;
(void)d->sdtor;
(void)d->ssharedctor;
Expand Down