[DDMD] Reasoning behind converting new Type -> Type::create
Iain Buclaw
ibuclaw at ubuntu.com
Mon Jan 27 05:57:55 PST 2014
Question aimed at Daniel.
I noticed this change in the frontend merge:
---
@@ -4539,6 +4736,11 @@ TypeAArray::TypeAArray(Type *t, Type
*index)
this->sc = NULL;
}
+TypeAArray *TypeAArray::create(Type *t, Type *index)
+{
+ return new TypeAArray(t, index);
+}
+
const char *TypeAArray::kind()
{
return "aarray";
---
I couldn't see any reference to this in the frontend, so did a
quick diff 2.064 from master and saw the following at a glance.
---
@@ -5179,7 +5020,7 @@ elem *AssocArrayLiteralExp::toElem(IRState
*irs)
else
{ // It's the AssociativeArray type.
// Turn it back into a TypeAArray
- ta = new TypeAArray((*values)[0]->type,
(*keys)[0]->type);
+ ta = TypeAArray::create((*values)[0]->type,
(*keys)[0]->type);
ta = ta->semantic(loc, NULL);
}
---
Assuming this needs to be done for all new'ing of classes across
C++ -> D, it looks like you've only done half a job? Surely you
should define a ::create for all Type's on the chance that the
backend might *actually* need it irrespective of what DMD does?
This is what I see in gdc's code.
---
$ grep "Type.*::create" d/dfrontend/mtype.c
TypeAArray *TypeAArray::create(Type *t, Type *index)
TypeFunction *TypeFunction::create(Parameters *parameters, Type
*treturn, int varargs, LINK linkage, StorageClass stc)
TypeTuple *TypeTuple::create(Parameters *arguments)
$ grep "new Type" d/*
d-builtins.c: return new TypePointer (d);
d-builtins.c: d = new TypePointer (d);
d-builtins.c: d = new TypeVector (Loc(), d);
d-builtins.c: sdecl->type = new TypeStruct (sdecl);
d-builtins.c: d = new TypeFunction (t_args, typefunc_ret,
t_varargs, LINKc);
d-codegen.cc: TypeFunction *tf = new TypeFunction (NULL,
decl->type, false, LINKd);
d-codegen.cc: TypeDelegate *t = new TypeDelegate (tf);
d-codegen.cc: TypeFunction *tf = new TypeFunction (NULL,
arg->type, false, LINKd);
d-codegen.cc: TypeDelegate *t = new TypeDelegate (tf);
d-codegen.cc: aatype = new TypeAArray (Type::tvoidptr,
Type::tvoidptr);
d-elem.cc: aa_type = new TypeAArray ((*values)[0]->type,
(*keys)[0]->type);
d-objfile.cc: TypeFunction *func_type = new TypeFunction (0,
Type::tvoid, 0, LINKc);
---
I guess this means that things would be broken if I switched to
DDMD today... =)
Regards
Iain.
More information about the Digitalmars-d
mailing list