[fpc-devel] Language extension: absolute for classes

Michael Van Canneyt michael at freepascal.org
Sun Oct 1 22:26:30 CEST 2006



On Sun, 1 Oct 2006, Micha Nelissen wrote:

> Michael Van Canneyt wrote:
> >> is to be written in a certain format, so you tell the compiler that it
> >> is like that. Why is this a hack ?
> > 
> > Because you do a typecast just as if you would override a property using a
> > read specifier and do the typecast there. Just the typecast is disguised 
> > as an 'absolute'...
> 
> In this case I'm doing a typecast because the compiler is too 'stupid',
> so the motivation for the typecast is different than in the general case.
> 
> I have been thinking of another way, but it's more involved, but also
> 'more correct'. The class A would specify for the 'Field: F' that it has
> an overrideable type, maybe keyword 'virtual' or so. The compiler will
> store the type in the RTTI of the class. Then, B can override the type,
> and the compiler will rewrite the needed type (G) into the RTTI. Then at
> runtime, whenever an assignment to A.Field is done, the compiler will
> generate code that retrieves from the RTTI the 'needed' type, and will
> check the type of the rightside expression to that needed type, like
> 'as' operator does.

I'm more in favour of this approach, actually. 
But I would do it at the property level, not at the field level. 
And only for classes.

Michael.



More information about the fpc-devel mailing list