suggestion of implicit new

shinichiro.h hamaji at nii.ac.jp
Wed May 31 15:31:11 PDT 2006


Hi all,

I guess D syntax can allow implicit new expression like following:

class C {
  this() {}
  this(int x) {}
}
void func() {
  C c = C();  // not new C()
  c = C(3);   // not new C(3)
}

I think the syntax is cute. And the syntax is not ambiguous and does
not make DMD slower. I have succeeded to implement the syntax into
GDC-0.18 (based on DMD-0.157). The following patch worked.

4076,4078c4076,4080
< //        fd = search_function(ad, Id::call);
< //        if (fd)
<           {
---
>           Expression *e = new DotIdExp(loc, e1, Id::call);
>           if (dynamic_cast<TypeExp *>(e1)) {
>               e = new NewExp(loc, NULL, e1->type, arguments);
>               return e->semantic(sc);
>           } else {
4080d4081
<               Expression *e = new DotIdExp(loc, e1, Id::call);

Any thought?

------------------
 shinichiro.h



More information about the Digitalmars-d mailing list