Merge pull request #15802 from dlang/revert-15789-dsymbol_sema2

Revert "Move a couple of functions out of dsymbol.d"
This commit is contained in:
Iain Buclaw 2023-11-21 09:04:55 +00:00 committed by GitHub
commit fc8a07b8c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 101 deletions

View file

@ -44,6 +44,7 @@ import dmd.lexer;
import dmd.location;
import dmd.mtype;
import dmd.nspace;
import dmd.opover;
import dmd.root.aav;
import dmd.root.rmem;
import dmd.rootobject;
@ -797,6 +798,64 @@ extern (C++) class Dsymbol : ASTNode
return speller!symbol_search_fp(ident.toString());
}
/***************************************
* 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:
default:
assert(0);
}
return sm;
}
bool overloadInsert(Dsymbol s)
{
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
@ -1409,6 +1468,38 @@ public:
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;
return fdx;
}
/********************************
* Insert Dsymbol in table.
* Params:

View file

@ -342,6 +342,7 @@ public:
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;

View file

@ -630,6 +630,7 @@ public:
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;
@ -8215,8 +8216,6 @@ extern bool isSpeculativeType(Type* t);
extern bool builtinTypeInfo(Type* t);
extern FuncDeclaration* findGetMembers(ScopeDsymbol* dsym);
class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
{
public:

View file

@ -48,7 +48,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;

View file

@ -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.

View file

@ -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;
/****************************************************
@ -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;
}

View file

@ -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);

View file

@ -1179,7 +1179,7 @@ public:
if (mi->needmoduleinfo)
mi->accept(this);
}
(void)findGetMembers(d);
(void)d->findGetMembers();
(void)d->sctor;
(void)d->sdtor;
(void)d->ssharedctor;