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 27, 2013
1 parent de8c6e2 commit 1ff8440
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
13 changes: 5 additions & 8 deletions src/e2ir.c
Expand Up @@ -1189,15 +1189,16 @@ elem *StringExp::toElem(IRState *irs)
toDt(&dt);
dtnzeros(&dt, sz); // leave terminating 0

::type *t = type_allocn(TYarray, tschar);
t->Tdim = sz;
::type *t = type_static_array(sz * len, tschar);
Symbol *si = symbol_generate(SCstatic, t);
si->Sdt = dt;
si->Sfl = FLdata;
out_readonly(si);
outdata(si);

e = el_var(si);
e->ET = t;
t->Tcount++;
}
else if (tb->ty == Tpointer)
{
Expand Down Expand Up @@ -3329,13 +3330,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); // fix extra Tcount++
Symbol *stmp = symbol_genauto(t);
ec = el_ptr(stmp);
el_setLoc(ec,loc);
return ec;
Expand Down
61 changes: 22 additions & 39 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 @@ -87,7 +87,7 @@ Symbol *Dsymbol::toSymbolX(const char *prefix, int sclass, type *t, const char *
}
#endif
id = (char *) alloca(2 + nlen + sizeof(size_t) * 3 + strlen(prefix) + strlen(suffix) + 1);
sprintf(id,"_D%s%zu%s%s", n, strlen(prefix), prefix, suffix);
sprintf(id,"_D%s%llu%s%s", n, (ulonglong)strlen(prefix), prefix, suffix);
#if 0
if (global.params.isWindows &&
(type_mangle(t) == mTYman_c || type_mangle(t) == mTYman_std))
Expand Down Expand Up @@ -172,53 +172,47 @@ 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);

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->Tcount++;
}
}
else
{
t = type->toCtype();
t->Tcount++;
t->Tcount++;
}

if (isDataseg())
{
Expand Down Expand Up @@ -585,9 +579,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 All @@ -604,13 +596,10 @@ Symbol *ClassDeclaration::toVtblSymbol()

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

if (!sinit)
{
stag = fake_classsym(NULL);
s = toSymbolX("__init", SCextern, stag->Stype, "Z");
Classsym *stag = fake_classsym(NULL);
Symbol *s = toSymbolX("__init", SCextern, stag->Stype, "Z");
s->Sfl = FLextern;
s->Sflags |= SFLnodebug;
slist_add(s);
Expand All @@ -621,13 +610,10 @@ Symbol *AggregateDeclaration::toInitializer()

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

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

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

if (!sinit)
{
stag = fake_classsym(NULL);
Classsym *stag = fake_classsym(NULL);
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 @@ -131,6 +131,7 @@ type *TypeFunction::toCtype()
t->Tnext = next->toCtype();
t->Tnext->Tcount++;
t->Tparamtypes = paramtypes;
t->Tcount++;

ctype = t;
return t;
Expand Down Expand Up @@ -201,30 +202,27 @@ type *TypeTypedef::toCParamtype()
}

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

{
//printf("TypeClass::toCtype() %s\n", toChars());
if (ctype)
return ctype;

s = symbol_calloc(sym->toPrettyChars());
Symbol *s = symbol_calloc(sym->toPrettyChars());
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 1ff8440

Please sign in to comment.