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

Johannes Luber jaluber at gmx.de
Mon Jan 7 15:38:56 PST 2008


Harald Mueller schrieb:
> Hi -
> 
> My "idea" is that there is a small bug in the initialization ... Johannes - HELP!!!???
> What might work - but it's more a hack - is to switch on output=AST - then the generated return class could work ...
> Or, for the moment, you declare your return value as DateTime?, which can be set to null.
> However, both these weird ideas are straws ... the init of a strcut value should be correct(ed).
> 
> Regards
> Harald

"Small" bug indeed... The entire problem is based on the fact, that
there is only a limited map in CSharp.stg, which includes basically only
the inbuilt value types (edited to include DateTime):

csharpTypeInitMap ::= [
	"int":"0",
	"uint":"0",
	"long":"0",
	"ulong":"0",
	"float":"0.0",
	"double":"0.0",
	"bool":"false",
	"byte":"0",
	"sbyte":"0",
	"short":"0",
	"ushort":"0",
	"char":"char.MinValue",
	"DateTime":"DateTime.MinValue",
	default:"null" // anything other than an atomic type
]

The default is, as you see, null. Adding new types to this structure is
an open-ended task. So we'd need a new way to tell ANTLR, that there is
a special case. Maybe "prog: dt(DateTime.MinValue)=datetime"? Ter?

In any case, I'm reluctant to change the official template for this
special case. I suggest to rebuild ANTLR yourself with the delivered
sources, along with the change in CSharp.stg, until Ter can make a real fix.

Johannes


More information about the antlr-interest mailing list