Skip to content

Commit

Permalink
add getGCInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Apr 16, 2012
1 parent a00d2de commit 31f974a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct AggregateDeclaration : ScopeDsymbol
FuncDeclarations methods; // flat list of all methods for debug information
#endif

Expression *getGCInfo; // pointer to GC info generated by object.GCInfo(this)

AggregateDeclaration(Loc loc, Identifier *id);
void semantic2(Scope *sc);
void semantic3(Scope *sc);
Expand Down
3 changes: 2 additions & 1 deletion src/idgen.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2011 by Digital Mars
// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -66,6 +66,7 @@ Msgtable msgtable[] =
{ "outer" },
{ "Exception" },
{ "AssociativeArray" },
{ "GCInfo" },
{ "Throwable" },
{ "Error" },
{ "withSym", "__withSym" },
Expand Down
1 change: 1 addition & 0 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ ClassDeclaration *Type::typeinfoshared;
ClassDeclaration *Type::typeinfowild;

TemplateDeclaration *Type::associativearray;
TemplateDeclaration *Type::gcinfo;

Type *Type::tvoidptr;
Type *Type::tstring;
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ struct Type : Object
static ClassDeclaration *typeinfowild;

static TemplateDeclaration *associativearray;
static TemplateDeclaration *gcinfo;

static Type *basic[TMAX];
static unsigned char mangleChar[TMAX];
Expand Down
16 changes: 16 additions & 0 deletions src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
noDefaultCtor = FALSE;
#endif
dtor = NULL;
getGCInfo = NULL;
}

enum PROT AggregateDeclaration::prot()
Expand Down Expand Up @@ -95,6 +96,21 @@ void AggregateDeclaration::semantic3(Scope *sc)
s->semantic3(sc);
}
sc->pop();

if (!getGCInfo)
{ // Evaluate: GCInfo!type
Objects *tiargs = new Objects();
tiargs->push(type);
TemplateInstance *ti = new TemplateInstance(loc, Type::gcinfo, tiargs);
ti->semantic(sc);
ti->semantic2(sc);
ti->semantic3(sc);
Dsymbol *s = ti->toAlias();
Expression *e = new DsymbolExp(0, s, 0);
e = e->semantic(ti->tempdecl->scope);
e = e->optimize(WANTvalue | WANTinterpret);
getGCInfo = e;
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,13 @@ void TemplateDeclaration::semantic(Scope *sc)
return; // semantic() already run
semanticRun = PASSsemantic;

if (sc->module && sc->module->ident == Id::object && ident == Id::AssociativeArray)
{ Type::associativearray = this;
// Remember templates defined in module object that we need to know about
if (sc->module && sc->module->ident == Id::object)
{
if (ident == Id::AssociativeArray)
Type::associativearray = this;
else if (ident == Id::GCInfo)
Type::gcinfo = this;
}

if (sc->func)
Expand Down
21 changes: 18 additions & 3 deletions src/toobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ void ClassDeclaration::toObjFile(int multiobj)
void *deallocator;
OffsetTypeInfo[] offTi;
void *defaultConstructor;
const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
//const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
void *xgetGCInfo;
//TypeInfo typeinfo;
}
*/
Expand Down Expand Up @@ -597,13 +598,23 @@ void ClassDeclaration::toObjFile(int multiobj)
dtsize_t(&dt, 0);

#if DMDV2
#if 0
FuncDeclaration *sgetmembers = findGetMembers();
if (sgetmembers)
dtxoff(&dt, sgetmembers->toSymbol(), 0, TYnptr);
else
dtsize_t(&dt, 0); // module getMembers() function
#endif

// xgetGCInfo
if (getGCInfo)
getGCInfo->toDt(&dt);
else if (flags & 2)
dtsize_t(&dt, 0); // no pointers
else
dtsize_t(&dt, 1); // has pointers
#endif

//dtxoff(&dt, type->vtinfo->toSymbol(), 0, TYnptr); // typeinfo

//////////////////////////////////////////////
Expand Down Expand Up @@ -976,7 +987,8 @@ void InterfaceDeclaration::toObjFile(int multiobj)
OffsetTypeInfo[] offTi;
void *defaultConstructor;
#if DMDV2
const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
//const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
void* xgetGCInfo;
#endif
//TypeInfo typeinfo;
}
Expand Down Expand Up @@ -1049,7 +1061,10 @@ void InterfaceDeclaration::toObjFile(int multiobj)

#if DMDV2
// xgetMembers
dtsize_t(&dt, 0);
//dtsize_t(&dt, 0);

// xgetGCInfo
dtsize_t(&dt, 0x12345678);
#endif

//dtxoff(&dt, type->vtinfo->toSymbol(), 0, TYnptr); // typeinfo
Expand Down
16 changes: 14 additions & 2 deletions src/typinf.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,14 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
* int function(in void*, in void*) xopCmp;
* string function(const(void)*) xtoString;
* uint m_flags;
* xgetMembers;
* //xgetMembers;
* xdtor;
* xpostblit;
* uint m_align;
* version (X86_64)
* TypeInfo m_arg1;
* TypeInfo m_arg2;
* xgetGCInfo
*
* name[]
*/
Expand Down Expand Up @@ -646,15 +647,18 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
dtsize_t(pdt, 0);

// uint m_flags;
dtsize_t(pdt, tc->hasPointers());
size_t m_flags = tc->hasPointers();
dtsize_t(pdt, m_flags);

#if DMDV2
#if 0
// xgetMembers
FuncDeclaration *sgetmembers = sd->findGetMembers();
if (sgetmembers)
dtxoff(pdt, sgetmembers->toSymbol(), 0, TYnptr);
else
dtsize_t(pdt, 0); // xgetMembers
#endif

// xdtor
FuncDeclaration *sdtor = sd->dtor;
Expand Down Expand Up @@ -692,6 +696,14 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
}
}

// xgetGCInfo
if (sd->getGCInfo)
sd->getGCInfo->toDt(pdt);
else if (m_flags)
dtsize_t(pdt, 1); // has pointers
else
dtsize_t(pdt, 0); // no pointers

// name[]
dtnbytes(pdt, namelen + 1, name);
}
Expand Down

0 comments on commit 31f974a

Please sign in to comment.