mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
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:
commit
fc8a07b8c8
8 changed files with 94 additions and 101 deletions
|
@ -44,6 +44,7 @@ import dmd.lexer;
|
||||||
import dmd.location;
|
import dmd.location;
|
||||||
import dmd.mtype;
|
import dmd.mtype;
|
||||||
import dmd.nspace;
|
import dmd.nspace;
|
||||||
|
import dmd.opover;
|
||||||
import dmd.root.aav;
|
import dmd.root.aav;
|
||||||
import dmd.root.rmem;
|
import dmd.root.rmem;
|
||||||
import dmd.rootobject;
|
import dmd.rootobject;
|
||||||
|
@ -797,6 +798,64 @@ extern (C++) class Dsymbol : ASTNode
|
||||||
return speller!symbol_search_fp(ident.toString());
|
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)
|
bool overloadInsert(Dsymbol s)
|
||||||
{
|
{
|
||||||
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
|
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
|
||||||
|
@ -1409,6 +1468,38 @@ public:
|
||||||
return "ScopeDsymbol";
|
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.
|
* Insert Dsymbol in table.
|
||||||
* Params:
|
* Params:
|
||||||
|
|
|
@ -342,6 +342,7 @@ public:
|
||||||
bool isforwardRef() override final;
|
bool isforwardRef() override final;
|
||||||
static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2);
|
static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2);
|
||||||
const char *kind() const override;
|
const char *kind() const override;
|
||||||
|
FuncDeclaration *findGetMembers();
|
||||||
virtual Dsymbol *symtabInsert(Dsymbol *s);
|
virtual Dsymbol *symtabInsert(Dsymbol *s);
|
||||||
virtual Dsymbol *symtabLookup(Dsymbol *s, Identifier *id);
|
virtual Dsymbol *symtabLookup(Dsymbol *s, Identifier *id);
|
||||||
bool hasStaticCtorOrDtor() override;
|
bool hasStaticCtorOrDtor() override;
|
||||||
|
|
|
@ -630,6 +630,7 @@ public:
|
||||||
bool isforwardRef() final override;
|
bool isforwardRef() final override;
|
||||||
static void multiplyDefined(const Loc& loc, Dsymbol* s1, Dsymbol* s2);
|
static void multiplyDefined(const Loc& loc, Dsymbol* s1, Dsymbol* s2);
|
||||||
const char* kind() const override;
|
const char* kind() const override;
|
||||||
|
FuncDeclaration* findGetMembers();
|
||||||
virtual Dsymbol* symtabInsert(Dsymbol* s);
|
virtual Dsymbol* symtabInsert(Dsymbol* s);
|
||||||
virtual Dsymbol* symtabLookup(Dsymbol* s, Identifier* id);
|
virtual Dsymbol* symtabLookup(Dsymbol* s, Identifier* id);
|
||||||
bool hasStaticCtorOrDtor() override;
|
bool hasStaticCtorOrDtor() override;
|
||||||
|
@ -8215,8 +8216,6 @@ extern bool isSpeculativeType(Type* t);
|
||||||
|
|
||||||
extern bool builtinTypeInfo(Type* t);
|
extern bool builtinTypeInfo(Type* t);
|
||||||
|
|
||||||
extern FuncDeclaration* findGetMembers(ScopeDsymbol* dsym);
|
|
||||||
|
|
||||||
class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
|
class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -48,7 +48,6 @@ import dmd.location;
|
||||||
import dmd.mtype;
|
import dmd.mtype;
|
||||||
import dmd.nspace;
|
import dmd.nspace;
|
||||||
import dmd.objc_glue;
|
import dmd.objc_glue;
|
||||||
import dmd.opover;
|
|
||||||
import dmd.statement;
|
import dmd.statement;
|
||||||
import dmd.staticassert;
|
import dmd.staticassert;
|
||||||
import dmd.target;
|
import dmd.target;
|
||||||
|
|
|
@ -372,64 +372,6 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb
|
||||||
pt = t.merge();
|
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.
|
* We've mistakenly parsed `t` as a type.
|
||||||
* Redo `t` as an Expression only if there are no type modifiers.
|
* Redo `t` as an Expression only if there are no type modifiers.
|
||||||
|
|
|
@ -15,17 +15,13 @@ import dmd.astenums;
|
||||||
import dmd.declaration;
|
import dmd.declaration;
|
||||||
import dmd.dmodule;
|
import dmd.dmodule;
|
||||||
import dmd.dscope;
|
import dmd.dscope;
|
||||||
import dmd.dsymbol;
|
|
||||||
import dmd.dclass;
|
import dmd.dclass;
|
||||||
import dmd.dstruct;
|
import dmd.dstruct;
|
||||||
import dmd.errors;
|
import dmd.errors;
|
||||||
import dmd.expression;
|
import dmd.expression;
|
||||||
import dmd.func;
|
|
||||||
import dmd.globals;
|
import dmd.globals;
|
||||||
import dmd.id;
|
|
||||||
import dmd.location;
|
import dmd.location;
|
||||||
import dmd.mtype;
|
import dmd.mtype;
|
||||||
import dmd.opover;
|
|
||||||
import core.stdc.stdio;
|
import core.stdc.stdio;
|
||||||
|
|
||||||
/****************************************************
|
/****************************************************
|
||||||
|
@ -275,35 +271,3 @@ extern (C++) bool builtinTypeInfo(Type t)
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,11 +15,8 @@
|
||||||
class Expression;
|
class Expression;
|
||||||
class Type;
|
class Type;
|
||||||
struct Scope;
|
struct Scope;
|
||||||
class FuncDeclaration;
|
|
||||||
class ScopeDsymbol;
|
|
||||||
|
|
||||||
bool genTypeInfo(Expression *e, const Loc &loc, Type *torig, Scope *sc);
|
bool genTypeInfo(Expression *e, const Loc &loc, Type *torig, Scope *sc);
|
||||||
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true);
|
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true);
|
||||||
bool isSpeculativeType(Type *t);
|
bool isSpeculativeType(Type *t);
|
||||||
bool builtinTypeInfo(Type *t);
|
bool builtinTypeInfo(Type *t);
|
||||||
FuncDeclaration *findGetMembers(ScopeDsymbol *dsym);
|
|
||||||
|
|
|
@ -1179,7 +1179,7 @@ public:
|
||||||
if (mi->needmoduleinfo)
|
if (mi->needmoduleinfo)
|
||||||
mi->accept(this);
|
mi->accept(this);
|
||||||
}
|
}
|
||||||
(void)findGetMembers(d);
|
(void)d->findGetMembers();
|
||||||
(void)d->sctor;
|
(void)d->sctor;
|
||||||
(void)d->sdtor;
|
(void)d->sdtor;
|
||||||
(void)d->ssharedctor;
|
(void)d->ssharedctor;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue