Skip to content

Commit

Permalink
more type refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 28, 2013
1 parent 6b6230f commit bed3a48
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
13 changes: 4 additions & 9 deletions src/e2ir.c
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2012 by Digital Mars
// Copyright (c) 1999-2013 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -1612,8 +1612,7 @@ elem *StringExp::toElem(IRState *irs)
toDt(&dt);
dtnzeros(&dt, sz); // leave terminating 0

::type *t = type_allocn(TYarray, tschar);
t->Tdim = sz * len;
::type *t = type_static_array(sz * len, tschar);
Symbol *si = symbol_generate(SCstatic, t);
si->Sdt = dt;
si->Sfl = FLdata;
Expand Down Expand Up @@ -3672,13 +3671,9 @@ elem *CallExp::toElem(IRState *irs)
// Replace with an array allocated on the stack
// of the same size: char[sz] tmp;

Symbol *stmp;
::type *t;

assert(!ehidden);
t = type_allocn(TYarray, tschar);
t->Tdim = sz;
stmp = symbol_genauto(t);
::type *t = type_static_array(sz, tschar); // BUG: fix extra Tcount++
Symbol *stmp = symbol_genauto(t);
ec = el_ptr(stmp);
el_setLoc(ec,loc);
return ec;
Expand Down
54 changes: 20 additions & 34 deletions src/tocsym.c
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2011 by Digital Mars
// Copyright (c) 1999-2013 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -172,54 +172,48 @@ Symbol *VarDeclaration::toSymbol()
//if (needThis()) *(char*)0=0;
assert(!needThis());
if (!csym)
{ Symbol *s;
{
TYPE *t;
const char *id;

if (isDataseg())
id = mangle();
else
id = ident->toChars();
s = symbol_calloc(id);
Symbol *s = symbol_calloc(id);
s->Salignment = alignment;

if (storage_class & (STCout | STCref))
{
if (global.params.symdebug && storage_class & STCparameter)
{
t = type_alloc(TYnptr); // should be TYref, but problems in back end
t->Tnext = type->toCtype();
t->Tnext->Tcount++;
}
else
t = type_fake(TYnptr);
// should be TYref, but problems in back end
t = type_pointer(type->toCtype());
}
else if (storage_class & STClazy)
{
if (config.exe == EX_WIN64 && isParameter())
t = type_fake(TYnptr);
else
t = type_fake(TYdelegate); // Tdelegate as C type
t->Tcount++;
}
else if (isParameter())
{
if (config.exe == EX_WIN64 && type->size(0) > REGSIZE)
{
if (global.params.symdebug)
{
t = type_alloc(TYnptr); // should be TYref, but problems in back end
t->Tnext = type->toCtype();
t->Tnext->Tcount++;
}
else
t = type_fake(TYnptr);
// should be TYref, but problems in back end
t = type_pointer(type->toCtype());
}
else
t = type->toCParamtype();
{
t = type->toCParamtype();
t->Tcount++;
}
}
else
{
t = type->toCtype();
t->Tcount++;
t->Tcount++;
}

if (isDataseg())
{
Expand Down Expand Up @@ -610,9 +604,7 @@ Symbol *ClassDeclaration::toVtblSymbol()
if (!csym)
toSymbol();

t = type_alloc(TYnptr | mTYconst);
t->Tnext = tsvoid;
t->Tnext->Tcount++;
t = type_allocn(TYnptr | mTYconst, tsvoid);
t->Tmangle = mTYman_d;
s = toSymbolX("__vtbl", SCextern, t, "Z");
s->Sflags |= SFLnodebug;
Expand Down Expand Up @@ -646,13 +638,10 @@ Symbol *AggregateDeclaration::toInitializer()

Symbol *TypedefDeclaration::toInitializer()
{
Symbol *s;
Classsym *stag;

if (!sinit)
{
stag = fake_classsym(Id::ClassInfo);
s = toSymbolX("__init", SCextern, stag->Stype, "Z");
Classsym *stag = fake_classsym(Id::ClassInfo);
Symbol *s = toSymbolX("__init", SCextern, stag->Stype, "Z");
s->Sfl = FLextern;
s->Sflags |= SFLnodebug;
slist_add(s);
Expand All @@ -663,16 +652,13 @@ Symbol *TypedefDeclaration::toInitializer()

Symbol *EnumDeclaration::toInitializer()
{
Symbol *s;
Classsym *stag;

if (!sinit)
{
stag = fake_classsym(Id::ClassInfo);
Classsym *stag = fake_classsym(Id::ClassInfo);
Identifier *ident_save = ident;
if (!ident)
ident = Lexer::uniqueId("__enum");
s = toSymbolX("__init", SCextern, stag->Stype, "Z");
Symbol *s = toSymbolX("__init", SCextern, stag->Stype, "Z");
ident = ident_save;
s->Sfl = FLextern;
s->Sflags |= SFLnodebug;
Expand Down
12 changes: 5 additions & 7 deletions src/toctype.c
Expand Up @@ -136,6 +136,7 @@ type *TypeFunction::toCtype()
t->Tnext = next->toCtype();
t->Tnext->Tcount++;
t->Tparamtypes = paramtypes;
t->Tcount++;

ctype = t;
return t;
Expand Down Expand Up @@ -305,9 +306,7 @@ type *TypeTypedef::toCParamtype()
}

type *TypeClass::toCtype()
{ type *t;
Symbol *s;

{
//printf("TypeClass::toCtype() %s\n", toChars());
if (ctype)
return ctype;
Expand All @@ -316,23 +315,22 @@ type *TypeClass::toCtype()
*/
const char *name = sym->isCPPinterface() ? sym->ident->toChars()
: sym->toPrettyChars();
s = symbol_calloc(name);
Symbol *s = symbol_calloc(name);
s->Sclass = SCstruct;
s->Sstruct = struct_calloc();
s->Sstruct->Sflags |= STRclass;
s->Sstruct->Salignsize = sym->alignsize;
// s->Sstruct->Sstructalign = sym->structalign;
s->Sstruct->Sstructsize = sym->structsize;

t = type_alloc(TYstruct);
type *t = type_alloc(TYstruct);
t->Ttag = (Classsym *)s; // structure tag name
t->Tcount++;
s->Stype = t;
slist_add(s);

t = type_allocn(TYnptr, t);
t = type_pointer(t);

t->Tcount++;
ctype = t;

/* Add in fields of the class
Expand Down

0 comments on commit bed3a48

Please sign in to comment.