[antlr-interest] Value types - can't be set to null in C#

Johannes Luber jaluber at gmx.de
Tue Jan 8 03:42:17 PST 2008


Gavin Lambert schrieb:
> Mere moments ago, I wrote:
>>Of course from a Java-based code-generation standpoint you have no
>>way of knowing whether a given type is a value type or a reference
>>type, which complicates matters.  So if the 'default' keyword thing
>>I suggested a moment ago doesn't work (or if you don't want to
>>restrict yourself to C# 2.0) then you'll have to have some kind of
>>syntax to tell ANTLR whether types are value or reference.
> 
> Actually, another thing that could work is simply detecting whether the
> variables are used within an @init block.  If so, you could assume that
> they're being initialised properly there and simply not do any
> initialisation at declaration time.

The latter is interesting as it allows to remain compatible with C# 1.
"default(Type)" would work otherwise. If I get around to change the
sources, so the C# 2-build uses everywhere enhanced techniques, I'll
remember that. The question is then, if Ter is willing to change ANTLR
to implement that behaviour.

Wait a minute - how can the map know, which typename should go between
the parentheses? Can some template replacement be used in that case? My
StringTemplate skills don't go far enough.

> That'd work.  It could be mildly annoying if these types were used
> commonly (so a global "this is how you init DateTimes" specifier or
> getting "default" to work would be better), but it'd be a simple
> quick-fix solution.

Depending on Ter's decision, I may add a line to the map, as a special
exception.

Johannes



More information about the antlr-interest mailing list