[antlr-interest] Duplicate members when generating code with 2 import levels in Java with ANTLR-3.1.1
Gavin Lambert
antlr at mirality.co.nz
Mon Oct 27 17:05:28 PDT 2008
At 12:04 28/10/2008, Loring Craymer wrote:
>Just my 2 cents, but shouldn't duplicate imports be supported at
>the language level, as is true for Java, C#, and even C/C++ with
>the usual #ifdef wrapping? It seems to me that leaving
dependency
>management to the user limits the convenience of composition.
If you think of grammar imports as class inheritance (which is
what they behave most like), then I think you'll find that those
other languages don't really support it all that well either :)
In C#, multiple inheritance of interfaces is supported cleanly,
but interfaces carry no implementation. Since the
implementation-inheritance model is single-inheritance, there's no
possibility of a serious clash. I'm not sure about Java exactly,
but I believe it's similar.
In C++, if you try to make class C inherit from both B1 and B2
(where B2 inherits from B1), then it will indeed include an extra
copy of B1 (in what's known as a "deadly diamond"), unless B1 is a
virtual base class. This seems like the same behaviour as what
ANTLR exhibits, except that (currently at least) ANTLR provides no
means to make it a virtual base :)
More information about the antlr-interest
mailing list