mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 12:40:11 +03:00
Moved _foreach and indirect dep getLocalClasses from dmodule to dsymbolsem (#21236)
This commit is contained in:
parent
03c8f2723f
commit
c296cb1ec2
4 changed files with 82 additions and 82 deletions
|
@ -112,11 +112,6 @@ void mangleToBuffer(TemplateInstance ti, ref OutBuffer buf)
|
|||
/***********************************************************
|
||||
* dmodule.d
|
||||
*/
|
||||
void getLocalClasses(Module mod, ref ClassDeclarations aclasses)
|
||||
{
|
||||
return dmd.dmodule.getLocalClasses(mod, aclasses);
|
||||
}
|
||||
|
||||
FuncDeclaration findGetMembers(ScopeDsymbol dsym)
|
||||
{
|
||||
return dmd.dmodule.findGetMembers(dsym);
|
||||
|
@ -204,6 +199,12 @@ bool hasPointers(Dsymbol d)
|
|||
return dmd.dsymbolsem.hasPointers(d);
|
||||
}
|
||||
|
||||
void getLocalClasses(Module mod, ref ClassDeclarations aclasses)
|
||||
{
|
||||
import dmd.dsymbolsem;
|
||||
return dmd.dsymbolsem.getLocalClasses(mod, aclasses);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* dtemplate.d
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,7 @@ import dmd.dmacro;
|
|||
import dmd.doc;
|
||||
import dmd.dscope;
|
||||
import dmd.dsymbol;
|
||||
import dmd.dsymbolsem : dsymbolSemantic, importAll, load, include;
|
||||
import dmd.dsymbolsem : dsymbolSemantic, importAll, load;
|
||||
import dmd.errors;
|
||||
import dmd.errorsink;
|
||||
import dmd.expression;
|
||||
|
@ -1306,83 +1306,8 @@ extern (C++) struct ModuleDeclaration
|
|||
}
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* Create array of the local classes in the Module, suitable
|
||||
* for inclusion in ModuleInfo
|
||||
* Params:
|
||||
* mod = the Module
|
||||
* aclasses = array to fill in
|
||||
* Returns: array of local classes
|
||||
*/
|
||||
void getLocalClasses(Module mod, ref ClassDeclarations aclasses)
|
||||
{
|
||||
//printf("members.length = %d\n", mod.members.length);
|
||||
int pushAddClassDg(size_t n, Dsymbol sm)
|
||||
{
|
||||
if (!sm)
|
||||
return 0;
|
||||
|
||||
if (auto cd = sm.isClassDeclaration())
|
||||
{
|
||||
// compatibility with previous algorithm
|
||||
if (cd.parent && cd.parent.isTemplateMixin())
|
||||
return 0;
|
||||
|
||||
if (cd.classKind != ClassKind.objc)
|
||||
aclasses.push(cd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_foreach(null, mod.members, &pushAddClassDg);
|
||||
}
|
||||
|
||||
|
||||
alias ForeachDg = int delegate(size_t idx, Dsymbol s);
|
||||
|
||||
/***************************************
|
||||
* Expands attribute declarations in members in depth first
|
||||
* order. Calls dg(size_t symidx, Dsymbol *sym) for each
|
||||
* member.
|
||||
* If dg returns !=0, stops and returns that value else returns 0.
|
||||
* Use this function to avoid the O(N + N^2/2) complexity of
|
||||
* calculating dim and calling N times getNth.
|
||||
* Returns:
|
||||
* last value returned by dg()
|
||||
*/
|
||||
int _foreach(Scope* sc, Dsymbols* members, scope ForeachDg dg, size_t* pn = null)
|
||||
{
|
||||
assert(dg);
|
||||
if (!members)
|
||||
return 0;
|
||||
size_t n = pn ? *pn : 0; // take over index
|
||||
int result = 0;
|
||||
foreach (size_t i; 0 .. members.length)
|
||||
{
|
||||
import dmd.attrib : AttribDeclaration;
|
||||
import dmd.dtemplate : TemplateMixin;
|
||||
|
||||
Dsymbol s = (*members)[i];
|
||||
if (AttribDeclaration a = s.isAttribDeclaration())
|
||||
result = _foreach(sc, a.include(sc), dg, &n);
|
||||
else if (TemplateMixin tm = s.isTemplateMixin())
|
||||
result = _foreach(sc, tm.members, dg, &n);
|
||||
else if (s.isTemplateInstance())
|
||||
{
|
||||
}
|
||||
else if (s.isUnitTestDeclaration())
|
||||
{
|
||||
}
|
||||
else
|
||||
result = dg(n++, s);
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
if (pn)
|
||||
*pn = n; // update index
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the content of a source file
|
||||
*
|
||||
|
|
|
@ -8926,3 +8926,77 @@ private extern(C++) class HasPointersVisitor : Visitor
|
|||
result = ns.members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************
|
||||
* Expands attribute declarations in members in depth first
|
||||
* order. Calls dg(size_t symidx, Dsymbol *sym) for each
|
||||
* member.
|
||||
* If dg returns !=0, stops and returns that value else returns 0.
|
||||
* Use this function to avoid the O(N + N^2/2) complexity of
|
||||
* calculating dim and calling N times getNth.
|
||||
* Returns:
|
||||
* last value returned by dg()
|
||||
*/
|
||||
int _foreach(Scope* sc, Dsymbols* members, scope ForeachDg dg, size_t* pn = null)
|
||||
{
|
||||
assert(dg);
|
||||
if (!members)
|
||||
return 0;
|
||||
size_t n = pn ? *pn : 0; // take over index
|
||||
int result = 0;
|
||||
foreach (size_t i; 0 .. members.length)
|
||||
{
|
||||
import dmd.attrib : AttribDeclaration;
|
||||
import dmd.dtemplate : TemplateMixin;
|
||||
|
||||
Dsymbol s = (*members)[i];
|
||||
if (AttribDeclaration a = s.isAttribDeclaration())
|
||||
result = _foreach(sc, a.include(sc), dg, &n);
|
||||
else if (TemplateMixin tm = s.isTemplateMixin())
|
||||
result = _foreach(sc, tm.members, dg, &n);
|
||||
else if (s.isTemplateInstance())
|
||||
{
|
||||
}
|
||||
else if (s.isUnitTestDeclaration())
|
||||
{
|
||||
}
|
||||
else
|
||||
result = dg(n++, s);
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
if (pn)
|
||||
*pn = n; // update index
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* Create array of the local classes in the Module, suitable
|
||||
* for inclusion in ModuleInfo
|
||||
* Params:
|
||||
* mod = the Module
|
||||
* aclasses = array to fill in
|
||||
* Returns: array of local classes
|
||||
*/
|
||||
void getLocalClasses(Module mod, ref ClassDeclarations aclasses)
|
||||
{
|
||||
//printf("members.length = %d\n", mod.members.length);
|
||||
int pushAddClassDg(size_t n, Dsymbol sm)
|
||||
{
|
||||
if (!sm)
|
||||
return 0;
|
||||
|
||||
if (auto cd = sm.isClassDeclaration())
|
||||
{
|
||||
// compatibility with previous algorithm
|
||||
if (cd.parent && cd.parent.isTemplateMixin())
|
||||
return 0;
|
||||
|
||||
if (cd.classKind != ClassKind.objc)
|
||||
aclasses.push(cd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_foreach(null, mod.members, &pushAddClassDg);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import dmd.dmodule;
|
|||
import dmd.dscope;
|
||||
import dmd.dstruct;
|
||||
import dmd.dsymbol;
|
||||
import dmd.dsymbolsem : hasPointers, hasStaticCtorOrDtor, include, isFuncHidden, isAbstract;
|
||||
import dmd.dsymbolsem : getLocalClasses, hasPointers, hasStaticCtorOrDtor, include, isFuncHidden, isAbstract;
|
||||
import dmd.dtemplate;
|
||||
import dmd.errors;
|
||||
import dmd.errorsink;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue