Skip to content

Commit

Permalink
Merge pull request #1988 from yebblies/symbolctor
Browse files Browse the repository at this point in the history
[DDMD] Move SymbolDeclaration constructor into the frontend
  • Loading branch information
yebblies committed May 9, 2013
2 parents ee99b87 + f3c2a74 commit 1290d1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
9 changes: 9 additions & 0 deletions src/declaration.c
Expand Up @@ -2260,6 +2260,15 @@ void ObjectNotFound(Identifier *id)
fatal();
}

/********************************* ClassInfoDeclaration ****************************/

SymbolDeclaration::SymbolDeclaration(Loc loc, StructDeclaration *dsym)
: Declaration(dsym->ident)
{
this->loc = loc;
this->dsym = dsym;
storage_class |= STCconst;
}

/********************************* ClassInfoDeclaration ****************************/

Expand Down
3 changes: 1 addition & 2 deletions src/declaration.h
Expand Up @@ -328,10 +328,9 @@ struct VarDeclaration : Declaration

struct SymbolDeclaration : Declaration
{
Symbol *sym;
StructDeclaration *dsym;

SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym);
SymbolDeclaration(Loc loc, StructDeclaration *dsym);

Symbol *toSymbol();

Expand Down
16 changes: 6 additions & 10 deletions src/interpret.c
Expand Up @@ -1754,16 +1754,12 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d, CtfeGoal goal
}
else if (s)
{ // Struct static initializers, for example
if (s->dsym->toInitializer() == s->sym)
{ e = s->dsym->type->defaultInitLiteral(loc);
e = e->semantic(NULL);
if (e->op == TOKerror)
e = EXP_CANT_INTERPRET;
else // Convert NULL to VoidExp
e = e->interpret(istate, goal);
}
else
error(loc, "cannot interpret symbol %s at compile time", s->toChars());
e = s->dsym->type->defaultInitLiteral(loc);
e = e->semantic(NULL);
if (e->op == TOKerror)
e = EXP_CANT_INTERPRET;
else // Convert NULL to VoidExp
e = e->interpret(istate, goal);
}
else
error(loc, "cannot interpret declaration %s at compile time", d->toChars());
Expand Down
3 changes: 1 addition & 2 deletions src/mtype.c
Expand Up @@ -7999,8 +7999,7 @@ Expression *TypeStruct::defaultInit(Loc loc)
#if LOGDEFAULTINIT
printf("TypeStruct::defaultInit() '%s'\n", toChars());
#endif
Symbol *s = sym->toInitializer();
Declaration *d = new SymbolDeclaration(sym->loc, s, sym);
Declaration *d = new SymbolDeclaration(sym->loc, sym);
assert(d);
d->type = this;
return new VarExp(sym->loc, d);
Expand Down
11 changes: 1 addition & 10 deletions src/tocsym.c
Expand Up @@ -46,18 +46,9 @@ Classsym *fake_classsym(Identifier *id);

/********************************* SymbolDeclaration ****************************/

SymbolDeclaration::SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym)
: Declaration(new Identifier(s->Sident, TOKidentifier))
{
this->loc = loc;
sym = s;
this->dsym = dsym;
storage_class |= STCconst;
}

Symbol *SymbolDeclaration::toSymbol()
{
return sym;
return dsym->toInitializer();
}

/*************************************
Expand Down

0 comments on commit 1290d1b

Please sign in to comment.