[PATCH] Re: Using C++ within a backend? (contd)
Matthieu Moy
Matthieu.Moy@imag.fr
Fri Apr 18 11:34:00 GMT 2003
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
> OK. I did the same for cp-tree.h.
>
> I should have done it before: it was rather trivial !
Hmm, not so much ;-)
Including the file tree.h from a C++ file was easy, but using it
requires some more work, because there are some uses of implicit cast
between enums (typically c_tree_code and tree_code).
The first thing to do is to allow comparison between them :
#ifdef __cplusplus
inline bool operator==(tree_code tc, c_tree_code ctc) {
return (c_tree_code)tc == ctc;
}
inline bool operator==(c_tree_code ctc, tree_code tc) {
return (c_tree_code)tc == ctc;
}
inline bool operator!=(tree_code tc, c_tree_code ctc) {
return (c_tree_code)tc != ctc;
}
inline bool operator!=(c_tree_code ctc, tree_code tc) {
return (c_tree_code)tc != ctc;
}
#endif
(Note that it would probably be cleaner to add the explicit casts in
the right places instead of defining new operators)
Then, we have to add explicit casts when required. For now, the
following seems to be sufficient for me :
--- tree.h~ Mon Apr 14 19:59:14 2003
+++ tree.h Fri Apr 18 11:04:03 2003
@@ -291,7 +291,7 @@
#define TREE_CHECK(t, code) __extension__ \
({ const tree __t = (t); \
if (TREE_CODE(__t) != (code)) \
- tree_check_failed (__t, code, __FILE__, __LINE__, __FUNCTION__); \
+ tree_check_failed (__t, (tree_code)code, __FILE__, __LINE__, __FUNCTION__); \
__t; })
#define TREE_CLASS_CHECK(t, class) __extension__ \
({ const tree __t = (t); \
--
Matthieu
More information about the Gcc
mailing list