compile time output

Ary Borenszweig ary at esperanto.org.ar
Tue Jan 20 09:12:43 PST 2009


Trass3r wrote:
> Is there any way to output information at compile time other than 
> pragma(msg?
> pragma is driving me crazy, the following doesn't work:
> 
> auto members = __traits(allMembers, typeof(this));

Kind of offtopic, but I tried this (with typeof(Foo) and Foo is defined 
in the same module) in Descent and I get a NullPointerException. :-(

I thought the port to Java was wrong so I compared to dmd's code.

In traits.c I can see:

---
else if (ident == Id::allMembers || ident == Id::derivedMembers)
     {
	if (dim != 1)
	    goto Ldimerror;
	Object *o = (Object *)args->data[0];
	Dsymbol *s = getDsymbol(o);
---

and in template.c getDsymbol says:

---
Dsymbol *getDsymbol(Object *oarg)
{
     Dsymbol *sa;
     Expression *ea = isExpression(oarg);
     if (ea)
     {
         // (snip)
     }
     else
     {   // Try to convert Type to symbol
	Type *ta = isType(oarg);
	if (ta)
	    sa = ta->toDsymbol(NULL);
	else
	    sa = isDsymbol(oarg);	// if already a symbol
     }
     return sa;
}
---

and of course oarg is a type, it's a TypeTypeof, so 
TypeTypeof::toDsymbol is invoked. Note that in this point sc is NULL.

---
Dsymbol *TypeTypeof::toDsymbol(Scope *sc)
{
     Type *t;

     t = semantic(0, sc);
     if (t == this)
	return NULL;
     return t->toDsymbol(sc);
}
---

and finally...

---
Type *TypeTypeof::semantic(Loc loc, Scope *sc)
{   Expression *e;
     Type *t;

	sc->intypeof++; // sc is NULL!!
	exp = exp->semantic(sc);
	sc->intypeof--;

    // (snip)
}
---

and that's why I get a NPE. But compiling with dmd works fine. 
Unfortunately I don't have with me the necessary stuff to debug dmd... 
does anyone know what's going on?

Thanks,
Ary


More information about the Digitalmars-d-learn mailing list