mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-16 12:53:14 +01:00
Renamed SymbolDeclaration to StaticStructInitDeclaration to make its usage clearer.
This commit is contained in:
@@ -1408,4 +1408,13 @@ Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/********************** StaticStructInitDeclaration ***************************/
|
||||
|
||||
StaticStructInitDeclaration::StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym)
|
||||
: Declaration(new Identifier("", TOKidentifier))
|
||||
{
|
||||
this->loc = loc;
|
||||
this->dsym = dsym;
|
||||
storage_class |= STCconst;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,19 +278,18 @@ struct VarDeclaration : Declaration
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
// This is a shell around a back end symbol
|
||||
// LDC uses this to denote static struct initializers
|
||||
|
||||
struct SymbolDeclaration : Declaration
|
||||
struct StaticStructInitDeclaration : Declaration
|
||||
{
|
||||
Symbol *sym;
|
||||
StructDeclaration *dsym;
|
||||
|
||||
SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym);
|
||||
StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym);
|
||||
|
||||
Symbol *toSymbol();
|
||||
|
||||
// Eliminate need for dynamic_cast
|
||||
SymbolDeclaration *isSymbolDeclaration() { return (SymbolDeclaration *)this; }
|
||||
StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; }
|
||||
};
|
||||
|
||||
struct ClassInfoDeclaration : VarDeclaration
|
||||
|
||||
@@ -65,7 +65,7 @@ struct EnumMember;
|
||||
struct ScopeDsymbol;
|
||||
struct WithScopeSymbol;
|
||||
struct ArrayScopeSymbol;
|
||||
struct SymbolDeclaration;
|
||||
struct StaticStructInitDeclaration;
|
||||
struct Expression;
|
||||
struct DeleteDeclaration;
|
||||
struct HdrGenState;
|
||||
@@ -216,7 +216,7 @@ struct Dsymbol : Object
|
||||
#ifdef _DH
|
||||
virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
|
||||
#endif
|
||||
virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
|
||||
virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; }
|
||||
virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
|
||||
virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
|
||||
virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
|
||||
|
||||
@@ -987,7 +987,7 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d)
|
||||
{
|
||||
Expression *e = EXP_CANT_INTERPRET;
|
||||
VarDeclaration *v = d->isVarDeclaration();
|
||||
SymbolDeclaration *s = d->isSymbolDeclaration();
|
||||
StaticStructInitDeclaration *s = d->isStaticStructInitDeclaration();
|
||||
if (v)
|
||||
{
|
||||
#if DMDV2
|
||||
@@ -1011,11 +1011,9 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d)
|
||||
}
|
||||
else if (s)
|
||||
{
|
||||
if (s->dsym->toInitializer() == s->sym)
|
||||
{ Expressions *exps = new Expressions();
|
||||
e = new StructLiteralExp(0, s->dsym, exps);
|
||||
e = e->semantic(NULL);
|
||||
}
|
||||
Expressions *exps = new Expressions();
|
||||
e = new StructLiteralExp(0, s->dsym, exps);
|
||||
e = e->semantic(NULL);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
@@ -1466,10 +1464,10 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp, int post)
|
||||
if (v->value && v->value->op == TOKvar)
|
||||
{
|
||||
VarExp *ve2 = (VarExp *)v->value;
|
||||
if (ve2->var->isSymbolDeclaration())
|
||||
if (ve2->var->isStaticStructInitDeclaration())
|
||||
{
|
||||
/* This can happen if v is a struct initialized to
|
||||
* 0 using an __initZ SymbolDeclaration from
|
||||
* 0 using an StaticStructInitDeclaration from
|
||||
* TypeStruct::defaultInit()
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -4584,14 +4584,12 @@ unsigned TypeStruct::memalign(unsigned salign)
|
||||
}
|
||||
|
||||
Expression *TypeStruct::defaultInit(Loc loc)
|
||||
{ Symbol *s;
|
||||
Declaration *d;
|
||||
{ Declaration *d;
|
||||
|
||||
#if LOGDEFAULTINIT
|
||||
printf("TypeStruct::defaultInit() '%s'\n", toChars());
|
||||
#endif
|
||||
s = sym->toInitializer();
|
||||
d = new SymbolDeclaration(sym->loc, s, sym);
|
||||
d = new StaticStructInitDeclaration(sym->loc, sym);
|
||||
assert(d);
|
||||
d->type = this;
|
||||
return new VarExp(sym->loc, d);
|
||||
|
||||
@@ -22,16 +22,10 @@
|
||||
#include "attrib.h"
|
||||
#include "lexer.h"
|
||||
|
||||
/********************************* SymbolDeclaration ****************************/
|
||||
|
||||
SymbolDeclaration::SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym)
|
||||
: Declaration(new Identifier("", TOKidentifier))
|
||||
Symbol *StaticStructInitDeclaration::toSymbol()
|
||||
{
|
||||
}
|
||||
|
||||
Symbol *SymbolDeclaration::toSymbol()
|
||||
{
|
||||
return sym;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
|
||||
@@ -179,7 +179,7 @@ DValue* VarExp::toElem(IRState* p)
|
||||
}
|
||||
return new DFuncValue(fdecl, func);
|
||||
}
|
||||
else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration())
|
||||
else if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
|
||||
{
|
||||
// this seems to be the static initialiser for structs
|
||||
Type* sdecltype = sdecl->type->toBasetype();
|
||||
@@ -205,7 +205,7 @@ LLConstant* VarExp::toConstElem(IRState* p)
|
||||
{
|
||||
Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars());
|
||||
LOG_SCOPE;
|
||||
if (SymbolDeclaration* sdecl = var->isSymbolDeclaration())
|
||||
if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
|
||||
{
|
||||
// this seems to be the static initialiser for structs
|
||||
Type* sdecltype = sdecl->type->toBasetype();
|
||||
|
||||
12
tests/mini/bug198_ctfestructinit.d
Normal file
12
tests/mini/bug198_ctfestructinit.d
Normal file
@@ -0,0 +1,12 @@
|
||||
struct Color {
|
||||
uint c;
|
||||
static Color opCall(uint _c) { Color ret; ret.c = _c; return ret; }
|
||||
}
|
||||
|
||||
// run at compile time
|
||||
static const Color white = Color(0xffffffff);
|
||||
|
||||
void main()
|
||||
{
|
||||
assert(white.c == 0xffffffff);
|
||||
}
|
||||
25
tests/mini/bug199_ctfestructinit.d
Normal file
25
tests/mini/bug199_ctfestructinit.d
Normal file
@@ -0,0 +1,25 @@
|
||||
struct Color {
|
||||
uint c;
|
||||
|
||||
}
|
||||
|
||||
struct Vertex {
|
||||
double x, y;
|
||||
Color c;
|
||||
static Vertex opCall(double x, double y, Color c) {
|
||||
Vertex ret;
|
||||
ret.x = x;
|
||||
ret.y = y;
|
||||
ret.c = c;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Color c = {0xffffffff};
|
||||
|
||||
auto v = Vertex(1, 5, c);
|
||||
|
||||
assert(v.x == 1 && v.y == 5); // passes
|
||||
assert(v.c.c == 0xffffffff); // fails in LDC
|
||||
}
|
||||
Reference in New Issue
Block a user