This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpplib chunk of integrated-preprocessor patch
- To: gcc-patches at gcc dot gnu dot org
- Subject: cpplib chunk of integrated-preprocessor patch
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Wed, 23 Aug 2000 11:29:17 -0700
This is the chunk of the integrated-preprocessor patch that applies to
cpplib itself. I'm putting it in right now - unlike the rest of the
patch, it can't break anything.
zw
* cpphash.h (IN_I): New flag for directive table.
* cpplib.c (DIRECTIVE_TABLE): Mark #define, #undef, #ident, and
#pragma with IN_I.
(_cpp_check_directive): If -fpreprocessed, execute directives
marked with IN_I. Issue no warnings in this case.
* cpplex.c (_cpp_get_token): Expand no macros if -fpreprocessed.
===================================================================
Index: cpphash.h
--- cpphash.h 2000/08/18 17:35:57 1.69
+++ cpphash.h 2000/08/23 18:25:27
@@ -66,11 +66,14 @@ struct answer
conditional. EXPAND means that macros are to be expanded on the
directive line. INCL means to treat "..." and <...> as
q-char-sequence and h-char-sequence respectively. COMMENTS means
- preserve comments in the directive if -C. */
+ preserve comments in the directive if -C. IN_I means this directive
+ should be handled even if -fpreprocessed is in effect (these are the
+ directives with callback hooks). */
#define COND (1 << 0)
#define EXPAND (1 << 1)
#define INCL (1 << 2)
#define COMMENTS (1 << 3)
+#define IN_I (1 << 4)
/* Defines one #-directive, including how to handle it. */
typedef void (*directive_handler) PARAMS ((cpp_reader *));
===================================================================
Index: cpplex.c
--- cpplex.c 2000/08/20 21:36:17 1.89
+++ cpplex.c 2000/08/23 18:25:27
@@ -3157,6 +3157,11 @@ _cpp_get_token (pfile)
be taken as a control macro. */
pfile->potential_control_macro = 0;
+ /* If we are rescanning preprocessed input, no macro expansion or
+ token pasting may occur. */
+ if (CPP_OPTION (pfile, preprocessed))
+ return token;
+
old_token = token;
/* See if there's a token to paste with this one. */
===================================================================
Index: cpplib.c
--- cpplib.c 2000/08/18 22:42:14 1.200
+++ cpplib.c 2000/08/23 18:25:28
@@ -79,21 +79,21 @@ static void unwind_if_stack PARAMS ((cpp
#endif
#define DIRECTIVE_TABLE \
-D(define, T_DEFINE = 0, KANDR, COMMENTS) /* 270554 */ \
+D(define, T_DEFINE = 0, KANDR, COMMENTS | IN_I)/* 270554 */ \
D(include, T_INCLUDE, KANDR, EXPAND | INCL) /* 52262 */ \
D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \
D(ifdef, T_IFDEF, KANDR, COND) /* 22000 */ \
D(if, T_IF, KANDR, COND | EXPAND) /* 18162 */ \
D(else, T_ELSE, KANDR, COND) /* 9863 */ \
D(ifndef, T_IFNDEF, KANDR, COND) /* 9675 */ \
-D(undef, T_UNDEF, KANDR, 0) /* 4837 */ \
+D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \
D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \
D(elif, T_ELIF, KANDR, COND | EXPAND) /* 610 */ \
D(error, T_ERROR, STDC89, 0) /* 475 */ \
-D(pragma, T_PRAGMA, STDC89, 0) /* 195 */ \
+D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \
D(warning, T_WARNING, EXTENSION, 0) /* 22 GNU */ \
D(include_next, T_INCLUDE_NEXT, EXTENSION, EXPAND | INCL) /* 19 GNU */ \
-D(ident, T_IDENT, EXTENSION, 0) /* 11 SVR4 */ \
+D(ident, T_IDENT, EXTENSION, IN_I) /* 11 SVR4 */ \
D(import, T_IMPORT, EXTENSION, EXPAND | INCL) /* 0 ObjC */ \
D(assert, T_ASSERT, EXTENSION, 0) /* 0 SVR4 */ \
D(unassert, T_UNASSERT, EXTENSION, 0) /* 0 SVR4 */ \
@@ -140,14 +140,19 @@ _cpp_check_directive (pfile, token, bol)
{
unsigned int i;
- /* If we are rescanning preprocessed input, don't obey any directives
- other than # nnn. */
- if (CPP_OPTION (pfile, preprocessed))
- return 0;
-
for (i = 0; i < N_DIRECTIVES; i++)
if (pfile->spec_nodes->dirs[i] == token->val.node)
{
+ /* If we are rescanning preprocessed input, only directives
+ tagged with IN_I are to be honored, and the warnings below
+ are suppressed. */
+ if (CPP_OPTION (pfile, preprocessed))
+ {
+ if (dtable[i].flags & IN_I)
+ return &dtable[i];
+ return 0;
+ }
+
/* In -traditional mode, a directive is ignored unless its #
is in column 1. In code intended to work with K+R compilers,
therefore, directives added by C89 must have their # indented,