[antlr-interest] Custom data in ANTLR3_BASE_TREE in C runtime
Jim Idle
jimi at temporal-wave.com
Thu May 6 10:33:21 PDT 2010
Dear Elvis,
I think that I have changed this so it is NULLed in the current development version, but you should be able to do this:
1) Set it to NULL yourself at an appropriate place.
2) In the ANTLR source code, you will find:
#ifndef ANTLR3_MALLOC
/// Default definition of ANTLR3_MALLOC. You can override this before including
/// antlr3.h if you wish to use your own implementation.
///
#define ANTLR3_MALLOC(request) malloc ((size_t)(request))
#endif
Change that to
#ifndef ANTLR3_MALLOC
/// Default definition of ANTLR3_MALLOC. You can override this before including
/// antlr3.h if you wish to use your own implementation.
///
#define ANTLR3_MALLOC(request) calloc (1, (size_t)(request))
#endif
And rebuild the runtime and you will sacrifice a little performance for nulled space.
3) Find the code that creates new nodes from a tree factory (the function newPooltree in antlr3commontree.c) and before the return statement, add:
tree->baseTree.u = NULL;
This is essentially the fix in the current development branch.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Elvis Presley
> Sent: Thursday, May 06, 2010 10:12 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Custom data in ANTLR3_BASE_TREE in C runtime
>
> I'm using the ANTLR3 C runtime and I'd like to be able to add custom
> data to
> my AST. I see there is a "u" field in the ANTLR3_BASE_TREE, which I
> would
> like to use to point to my own struct that contains the data I need for
> that
> node in the tree. My problem is that it doesn't look like "u" is ever
> initialized to NULL so I don't have a way to determine if I need to
> allocate
> new memory for my struct or not.
>
> I can't quite figure out by looking at the code if there is a way to
> override the behavior in ANTLR3_BASE_TREE or in the adaptor so that I
> can
> always guarantee that "u" is always NULL or points to one of my custom
> structs. Any help here would be appreciated. Thanks
>
> --Bryce
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list