Permalink
Browse files

add getGCInfo

  • Loading branch information...
1 parent a00d2de commit 31f974a03de4372a7f95801b3e4f5a09f052ee1e @WalterBright WalterBright committed Apr 16, 2012
Showing with 61 additions and 8 deletions.
  1. +2 −0 src/aggregate.h
  2. +2 −1 src/idgen.c
  3. +1 −0 src/mtype.c
  4. +1 −0 src/mtype.h
  5. +16 −0 src/struct.c
  6. +7 −2 src/template.c
  7. +18 −3 src/toobj.c
  8. +14 −2 src/typinf.c
View
@@ -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);
View
@@ -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
@@ -66,6 +66,7 @@ Msgtable msgtable[] =
{ "outer" },
{ "Exception" },
{ "AssociativeArray" },
+ { "GCInfo" },
{ "Throwable" },
{ "Error" },
{ "withSym", "__withSym" },
View
@@ -114,6 +114,7 @@ ClassDeclaration *Type::typeinfoshared;
ClassDeclaration *Type::typeinfowild;
TemplateDeclaration *Type::associativearray;
+TemplateDeclaration *Type::gcinfo;
Type *Type::tvoidptr;
Type *Type::tstring;
View
@@ -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];
View
@@ -57,6 +57,7 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
noDefaultCtor = FALSE;
#endif
dtor = NULL;
+ getGCInfo = NULL;
}
enum PROT AggregateDeclaration::prot()
@@ -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;
+ }
}
}
View
@@ -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)
View
@@ -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;
}
*/
@@ -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
//////////////////////////////////////////////
@@ -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;
}
@@ -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
View
@@ -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[]
*/
@@ -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;
@@ -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);
}

0 comments on commit 31f974a

Please sign in to comment.