[antlr-interest] Request for preinclude_c option
gokul007 at gmail.com
Wed Jan 6 21:38:18 PST 2010
I have tried to put forward my argument.
Guess I am not quite following this - would not using the @header section
> solve this? All headers should protect themselves against multiple #include
> of course.
@header section places it in both .h and .c, This makes the headers heavy.
of-course multiple #include is protected. My request is to place the section
only in .c, before placing the ANTLR headers(#include).
> Also, I am not sure that you really need to do this. You should place any
> code using C++ templates and headers etc in external files and create an API
> that you call from action code. That API should have a header and I can't
> see that including that header after <NAME>.h should be a problem. That
> doesn't mean that there isn't one, just that I am not seeing why. Can you
> post an example to the list? If @header won't do it and there is a valid
> reason, then I will certainly add another @option to fix it.
> Well, atleast we have done it in a way, which uses STL and std::bitset in
the action part. Sometimes we are even returning a std::bitset and
boost::variant, which are all template based. Sometimes to decide on which
token to be issued in lexer, we are using the hashmap.
I think ANTLR somewhere uses winsock.h and including winsock2.h after that
causes some issues for us. Basically we are not facing any issues, if we
are including the ANTLR headers after our headers. But there is no way to do
that currently without making the generated header files heavy. So i had to
resort to using @preincludes option.
This is the problem by making the headers heavy. Say i have two headers, one
for CplusplusLexer.h and CplusplusParser.h. Say inside the lexer header, i
have included a C++ library that has templates. Now this should get placed
before the C headers. So CplusplusLexer.h looks like this
Similarly i have CplusplusParser.h, which looks like this
Now in the .cpp file, if i have to do parsing, i have to include both
lexer.h and parser.h. Now there is no way template files can be placed
before the antlr header, unless i do something like this by again
re-declaring the headers before the antlr files
While the fix is straight forward, identifying that this is the problem,
will take sometime.
The code organization will be more better, if i don't include them in the
CplusplusParser.h and CplusplusLexer.h and the round about fixes may not be
required. There is just one stuff to be kept in mind - to include the ANTLR
headers after the C++headers(with templates).
Hope i was able to put forward a case.
More information about the antlr-interest