Skip to content

Commit

Permalink
lazily evaluate ident
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 16, 2013
1 parent bd98b63 commit bd0ff25
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/dsymbol.c
Expand Up @@ -176,6 +176,11 @@ void Dsymbol::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool i
{
}

Identifier *Dsymbol::getIdent()
{
return ident;
}

char *Dsymbol::toChars()
{
return ident ? ident->toChars() : (char *)"__anonymous";
Expand Down
1 change: 1 addition & 0 deletions src/dsymbol.h
Expand Up @@ -150,6 +150,7 @@ class Dsymbol : public Object

static Dsymbols *arraySyntaxCopy(Dsymbols *a);

virtual Identifier *getIdent();
virtual const char *toPrettyChars();
virtual const char *kind();
virtual Dsymbol *toAlias(); // resolve real symbol
Expand Down
7 changes: 4 additions & 3 deletions src/mangle.c
Expand Up @@ -46,7 +46,7 @@ char *mangle(Declaration *sthis, bool isv)
do
{
//printf("mangle: s = %p, '%s', parent = %p\n", s, s->toChars(), s->parent);
if (s->ident)
if (s->getIdent())
{
FuncDeclaration *fd = s->isFuncDeclaration();
if (s != sthis && fd)
Expand Down Expand Up @@ -174,8 +174,8 @@ const char *FuncDeclaration::mangle(bool isv)
#endif
{
if (mangleOverride)
return mangleOverride;
return mangleOverride;

if (isMain())
return (char *)"_Dmain";

Expand Down Expand Up @@ -272,6 +272,7 @@ const char *TemplateInstance::mangle(bool isv)
printf(" parent = %s %s", parent->kind(), parent->toChars());
printf("\n");
#endif
getIdent();
const char *id = ident ? ident->toChars() : toChars();
if (!tempdecl)
error("is not defined");
Expand Down
13 changes: 12 additions & 1 deletion src/template.c
Expand Up @@ -5109,7 +5109,7 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
parent = tempdecl->parent;
//printf("parent = '%s'\n", parent->kind());

ident = genIdent(tiargs); // need an identifier for name mangling purposes.
//getIdent();

#if 1
if (enclosing)
Expand Down Expand Up @@ -6202,6 +6202,17 @@ Identifier *TemplateInstance::genIdent(Objects *args)
return Lexer::idPool(id);
}

/*************************************
* Lazily generate identifier for template instance.
* This is because 75% of the ident's are never needed.
*/

Identifier *TemplateInstance::getIdent()
{
if (!ident && inst)
ident = genIdent(tiargs); // need an identifier for name mangling purposes.
return ident;
}

/****************************************************
* Declare parameters of template instance, initialize them with the
Expand Down
1 change: 1 addition & 0 deletions src/template.h
Expand Up @@ -339,6 +339,7 @@ class TemplateInstance : public ScopeDsymbol
char *toChars();
const char *mangle(bool isv = false);
void printInstantiationTrace();
Identifier *getIdent();

void toObjFile(int multiobj); // compile to .obj file

Expand Down

0 comments on commit bd0ff25

Please sign in to comment.