This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Re: Using C++ within a backend?


Alexandre Courbot <Alexandre dot Courbot at lifl dot fr> writes:

> The only gcc include file I had to change is rtl.h. I've created my own 
> rtl-fix.h file in my backend directory and use this one instead of rtl.h. The 
> only changes are line 109-110:
>
>   rtx rtx;
>   rtvec rtvec;
>
> Changing them to
>
>   rtx_def * rtx;
>   rtvec_def * rtvec;
>
> got me out of trouble. 

OK. I did the same for cp-tree.h. 

I should have done it before: it was rather trivial ! 

Usually, the file cp-tree.h is included as follows :

#include "config.h"
#include "system.h"
#include "tree.h"
#include "cp-tree.h"

There are 2 problems:

system.h includes the file <stdbool.h>, which tries to define the type
bool. 

#define-ing  the variable  __STDBOOL_H__ before  that does  the trick.
(Don't know how much portable this is ...)

The file cp-tree.h has a  structure member called "operator", which is
a keyword of C++. 

So, the  my solution is  to have the  following file, which  I include
instead of including cp-tree.h :

#ifndef __cplusplus

#ifdef GCC_BRANCH_IS_SSA

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"

#else // GCC_BRANCH_IS_SSA

#include "config.h"
#include "system.h"
#include "tree.h"
#include "cp-tree.h"

#endif // GCC_BRANCH_IS_SSA


#else // We are in C++

extern "C" {
#include "config.h"
#define __STDBOOL_H__
#include "system.h"
#include "tree.h"

#define operator cp_operator
#include "cp-tree.h"
#undef operator
}

#endif

#endif

For  now,  this is  an  awfull hack,  but  I  strongly recommand  that
something cleaner be applied to the main branch of GCC :

* Renaming   any    variable   whose    name   is   a    C++   keyword
  (s/operator/cp_operator/g for example)

* Apply the following patch to system.h :

--- system.h~	Wed May 22 01:44:39 2002
+++ system.h	Thu Apr 17 10:35:06 2003
@@ -543,6 +543,7 @@
 #undef TRUE
 #undef FALSE
 
+#ifndef __cplusplus
 #ifdef HAVE_STDBOOL_H
 # include <stdbool.h>
 #else
@@ -552,6 +553,7 @@
 # define bool _Bool
 # define true 1
 # define false 0
+#endif
 #endif
 
 #define TRUE true

-- 
Matthieu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]