This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Enable C++-specific preprocessor defines
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Enable C++-specific preprocessor defines
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 07 Feb 2001 11:05:52 -0800
- Organization: CodeSourcery, LLC
By popular demand, this patch provides a mechanism for providing a a
C++ CPP_SPEC that is different from the C version. You just define
CPLUSCPLUS_CPP_SPEC in your target machine header.
I am already verifying that this patch fixes the -ansi problems on
AIX, and will check in that patch RSN.
I am not planning on figuring out how this feature should be used on
every platform support by GCC. :-) But, in general, we should be able
to eliminate most of the cruft in V3's config/os/<foo>/os_defines.h in
favor of CPLUSCPLUS_CPP_SPEC, which will avoid the ordering problems.
Tested on i686-pc-linux-gnu and powerpc-ibm-aix4.3.2.0.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2001-02-07 Mark Mitchell <mark@codesourcery.com>
* defaults.h (CPLUSPLUS_CPP_SPEC): New macro.
* gcc.c (struct compiler): Add cpp_spec field.
(input_file_compiler): New variable.
(do_spec_1): Allow a particular compiler to handle `%C'
specially.
(main): Store the current compiler in input_file_compiler.
* tm.texi (CPLUSPLUS_CPP_SPEC): Document.
2001-02-07 Mark Mitchell <mark@codesourcery.com>
* lang-specs.h: Use CPLUSPLUS_CPP_SPEC for the preprocessor
spec.
Index: defaults.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/defaults.h,v
retrieving revision 1.30
diff -c -p -r1.30 defaults.h
*** defaults.h 2001/02/04 08:29:46 1.30
--- defaults.h 2001/02/07 18:50:00
*************** do { \
*** 296,300 ****
--- 296,308 ----
#define BUILD_VA_LIST_TYPE(X) ((X) = ptr_type_node)
#endif
+ /* By default, the preprocessor should be invoked the same way in C++
+ as in C. */
+ #ifndef CPLUSPLUS_CPP_SPEC
+ #ifdef CPP_SPEC
+ #define CPLUSPLUS_CPP_SPEC CPP_SPEC
+ #endif
+ #endif
+
#endif /* GCC_DEFAULTS_H */
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.203
diff -c -p -r1.203 gcc.c
*** gcc.c 2001/02/02 17:41:59 1.203
--- gcc.c 2001/02/07 18:50:10
*************** struct compiler
*** 698,703 ****
--- 698,707 ----
whose names end in this suffix. */
const char *spec; /* To use this compiler, run this spec. */
+
+ const char *cpp_spec; /* If non-NULL, substitute this spec
+ for `%C', rather than the usual
+ cpp_spec. */
};
/* Pointer to a vector of `struct compiler' that gives the spec for
*************** static int suffixed_basename_length;
*** 3870,3875 ****
--- 3874,3882 ----
static const char *input_basename;
static const char *input_suffix;
+ /* The compiler used to process the current input file. */
+ static struct compiler *input_file_compiler;
+
/* These are variables used within do_spec and do_spec_1. */
/* Nonzero if an arg has been started and not yet terminated
*************** do_spec_1 (spec, inswitch, soft_matched_
*** 4441,4449 ****
break;
case 'C':
! value = do_spec_1 (cpp_spec, 0, NULL_PTR);
! if (value != 0)
! return value;
break;
case 'E':
--- 4448,4462 ----
break;
case 'C':
! {
! const char* spec
! = (input_file_compiler->cpp_spec
! ? input_file_compiler->cpp_spec
! : cpp_spec);
! value = do_spec_1 (spec, 0, NULL_PTR);
! if (value != 0)
! return value;
! }
break;
case 'E':
*************** main (argc, argv)
*** 5795,5801 ****
for (i = 0; (int) i < n_infiles; i++)
{
- register struct compiler *cp = 0;
int this_file_error = 0;
/* Tell do_spec what to substitute for %i. */
--- 5808,5813 ----
*************** main (argc, argv)
*** 5808,5825 ****
outfiles[i] = input_filename;
/* Figure out which compiler from the file's suffix. */
-
- cp = lookup_compiler (infiles[i].name, input_filename_length,
- infiles[i].language);
! if (cp)
{
/* Ok, we found an applicable compiler. Run its spec. */
! if (cp->spec[0] == '#')
error ("%s: %s compiler not installed on this system",
! input_filename, &cp->spec[1]);
! value = do_spec (cp->spec);
if (value < 0)
this_file_error = 1;
}
--- 5820,5838 ----
outfiles[i] = input_filename;
/* Figure out which compiler from the file's suffix. */
! input_file_compiler
! = lookup_compiler (infiles[i].name, input_filename_length,
! infiles[i].language);
!
! if (input_file_compiler)
{
/* Ok, we found an applicable compiler. Run its spec. */
! if (input_file_compiler->spec[0] == '#')
error ("%s: %s compiler not installed on this system",
! input_filename, &input_file_compiler->spec[1]);
! value = do_spec (input_file_compiler->spec);
if (value < 0)
this_file_error = 1;
}
Index: tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tm.texi,v
retrieving revision 1.168
diff -c -p -r1.168 tm.texi
*** tm.texi 2001/01/30 05:42:06 1.168
--- tm.texi 2001/02/07 18:50:18
*************** give to GCC into options for GCC to pass
*** 109,114 ****
--- 109,120 ----
Do not define this macro if it does not need to do anything.
+ @findex CPLUSPLUS_CPP_SPEC
+ @item CPLUSPLUS_CPP_SPEC
+ This macro is just like @code{CPP_SPEC}, but is used for C++, rather
+ than C. If you do not define this macro, then the value of
+ @code{CPP_SPEC} (if any) will be used instead.
+
@findex NO_BUILTIN_SIZE_TYPE
@item NO_BUILTIN_SIZE_TYPE
If this macro is defined, the preprocessor will not define the builtin macro
Index: cp/lang-specs.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lang-specs.h,v
retrieving revision 1.36
diff -c -p -r1.36 lang-specs.h
*** lang-specs.h 2001/01/19 15:12:33 1.36
--- lang-specs.h 2001/02/07 18:50:27
*************** Boston, MA 02111-1307, USA. */
*** 68,73 ****
--- 68,76 ----
%(cc1_options) %2 %{+e*}\
%{!fsyntax-only:%(invoke_as)}}}}"
#endif
+ #ifdef CPLUSPLUS_CPP_SPEC
+ , CPLUSPLUS_CPP_SPEC
+ #endif
},
{".ii", "@c++-cpp-output"},
{"@c++-cpp-output",