Skip to content

Commit

Permalink
Change inNonRoot function to Dsymbol class member
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 18, 2014
1 parent 795e6a5 commit eadab0d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
27 changes: 27 additions & 0 deletions src/dsymbol.c
Expand Up @@ -810,6 +810,33 @@ void Dsymbol::addComment(const utf8_t *comment)
}
}

/****************************************
* Returns true if this symbol is defined in non-root module.
*/

bool Dsymbol::inNonRoot()
{
Dsymbol *s = parent;
for (; s; s = s->parent)
{
if (TemplateInstance *ti = s->isTemplateInstance())
{
if (ti->isTemplateMixin())
continue;
if (!ti->instantiatingModule || !ti->instantiatingModule->isRoot())
return true;
return false;
}
else if (Module *m = s->isModule())
{
if (!m->isRoot())
return true;
break;
}
}
return false;
}

/********************************* OverloadSet ****************************/

OverloadSet::OverloadSet(Identifier *ident)
Expand Down
2 changes: 2 additions & 0 deletions src/dsymbol.h
Expand Up @@ -216,6 +216,8 @@ class Dsymbol : public RootObject
virtual void emitComment(Scope *sc);
void emitDitto(Scope *sc);

bool inNonRoot();

// Backend

virtual Symbol *toSymbol(); // to backend symbol
Expand Down
4 changes: 1 addition & 3 deletions src/glue.c
Expand Up @@ -541,8 +541,6 @@ void Module::genobjfile(int multiobj)

/* ================================================================== */

bool inNonRoot(Dsymbol *s);

void FuncDeclaration::toObjFile(int multiobj)
{
FuncDeclaration *func = this;
Expand Down Expand Up @@ -601,7 +599,7 @@ void FuncDeclaration::toObjFile(int multiobj)
assert(semanticRun == PASSsemantic3done);
assert(ident != Id::empty);

if (!isInstantiated() && inNonRoot(this))
if (!isInstantiated() && inNonRoot())
return;

/* Skip generating code if this part of a TemplateInstance that is instantiated
Expand Down
25 changes: 0 additions & 25 deletions src/struct.c
Expand Up @@ -25,31 +25,6 @@
FuncDeclaration *StructDeclaration::xerreq; // object.xopEquals
FuncDeclaration *StructDeclaration::xerrcmp; // object.xopCmp

bool inNonRoot(Dsymbol *s)
{
if (!s || !s->parent)
return false;
s = s->parent;
for (; s; s = s->parent)
{
if (TemplateInstance *ti = s->isTemplateInstance())
{
if (ti->isTemplateMixin())
continue;
if (!ti->instantiatingModule || !ti->instantiatingModule->isRoot())
return true;
return false;
}
else if (Module *m = s->isModule())
{
if (!m->isRoot())
return true;
break;
}
}
return false;
}

/***************************************
* Search toHash member function for TypeInfo_Struct.
* const hash_t toHash();
Expand Down
5 changes: 2 additions & 3 deletions src/typinf.c
Expand Up @@ -106,7 +106,6 @@ Expression *Type::getInternalTypeInfo(Scope *sc)
}


bool inNonRoot(Dsymbol *s);
FuncDeclaration *search_toHash(StructDeclaration *sd);
FuncDeclaration *search_toString(StructDeclaration *sd);

Expand Down Expand Up @@ -159,9 +158,9 @@ Expression *Type::getTypeInfo(Scope *sc)
sd->xcmp && sd->xcmp != sd->xerrcmp ||
search_toHash(sd) ||
search_toString(sd)
) && inNonRoot(sd))
) && sd->inNonRoot())
{
//printf("deferred sem3 for TypeInfo - sd = %s, inNonRoot = %d\n", sd->toChars(), inNonRoot(sd));
//printf("deferred sem3 for TypeInfo - sd = %s, inNonRoot = %d\n", sd->toChars(), sd->inNonRoot());
Module::addDeferredSemantic3(sd);
}
}
Expand Down

0 comments on commit eadab0d

Please sign in to comment.