[antlr-interest] C-Target $label.text / toString malfunction
Gavin Lambert
antlr at mirality.co.nz
Sat Mar 31 13:35:17 PDT 2007
At 04:25 1/04/2007, Tobias Pape wrote:
>unaryPattern returns [ pASTPattern p ]
> : s=unarySelector
> { $p = (pASTPattern) ASTUnaryPattern_new((char *) $s.text-
> >chars); }
> ;
>
>binaryPattern returns [ pASTPattern p ]
> : s=binarySelector v=argument
> { $p = (pASTPattern) ASTBinaryPattern_new((char *) $s.text-
> >chars, v.v); }
> ;
I don't think you're allowed to upcast like that in the C-language
parsers. At least not if 'ASTBinaryPattern' inherits from
ASTPattern, anyway, rather than simply being an ASTPattern with a
different constructor (in which case you probably don't need the
cast). Inheritance is usually faked via containment and you're
not going to get the compiler's help to convert pointers, so
unless the structure is laid out in a very specific way then
you're going to end up with an invalid pointer.
More information about the antlr-interest
mailing list