Skip to content

Commit

Permalink
Move a couple of functions out of dsymbol.d (dlang/dmd!15789)
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 authored Nov 9, 2023
1 parent b5e90c8 commit c698ccc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 93 deletions.
91 changes: 0 additions & 91 deletions dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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;
Expand Down Expand Up @@ -875,64 +874,6 @@ 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());
Expand Down Expand Up @@ -1704,38 +1645,6 @@ 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:
Expand Down
1 change: 0 additions & 1 deletion dmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ 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: 2 additions & 1 deletion dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ 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 @@ -8228,6 +8227,8 @@ extern bool isSpeculativeType(Type* t);

extern bool builtinTypeInfo(Type* t);

extern FuncDeclaration* findGetMembers(ScopeDsymbol* dsym);

class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
{
public:
Expand Down
58 changes: 58 additions & 0 deletions dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,64 @@ 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: 36 additions & 0 deletions dmd/typinf.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ 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 @@ -271,3 +275,35 @@ 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: 3 additions & 0 deletions dmd/typinf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
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);

0 comments on commit c698ccc

Please sign in to comment.