cppexp.c, [...]: Eradicate all traces of code dependent on traditional, lang_chill, or lang_fortran.

* cppexp.c, cpphash.c, cpphash.h, cppinit.c, cpplex.c,
	cpplib.c, cpplib.h: Eradicate all traces of code dependent on
	traditional, lang_chill, or lang_fortran.

	* cppfiles.c: #undef strcmp to suppress warning about macros
	used without arguments.
	(_cpp_execute_include): Use f, not fname, in "No include path"
	error.
	(_cpp_pop_file_buffer): New function.
	* cpplib.c: Don't include <sys/mman.h>.
	(cpp_push_buffer): Set line_base and lineno in new buffer.
	(cpp_pop_buffer): Use _cpp_pop_file_buffer.

	* cpplex.c: Move all prototypes and structure declarations to the
	top of the file.  Properly parenthesise some macro arguments.
	(cpp_scan_line): New function.
	(special_symbol [case T_INCLUDE_DEPTH]): Use pfile->include_depth,
	don't need to walk up the stack counting.

From-SVN: r35003
This commit is contained in:
Zack Weinberg 2000-07-13 02:32:41 +00:00 committed by Zack Weinberg
parent d55bb5be91
commit f9a0e96c17
9 changed files with 219 additions and 265 deletions

View file

@ -1,3 +1,24 @@
2000-07-12 Zack Weinberg <zack@wolery.cumb.org>
* cppexp.c, cpphash.c, cpphash.h, cppinit.c, cpplex.c,
cpplib.c, cpplib.h: Eradicate all traces of code dependent on
traditional, lang_chill, or lang_fortran.
* cppfiles.c: #undef strcmp to suppress warning about macros
used without arguments.
(_cpp_execute_include): Use f, not fname, in "No include path"
error.
(_cpp_pop_file_buffer): New function.
* cpplib.c: Don't include <sys/mman.h>.
(cpp_push_buffer): Set line_base and lineno in new buffer.
(cpp_pop_buffer): Use _cpp_pop_file_buffer.
* cpplex.c: Move all prototypes and structure declarations to the
top of the file. Properly parenthesise some macro arguments.
(cpp_scan_line): New function.
(special_symbol [case T_INCLUDE_DEPTH]): Use pfile->include_depth,
don't need to walk up the stack counting.
2000-07-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* c-common.c (combine_strings): Emit a pedantic warning when a

View file

@ -298,7 +298,7 @@ parse_charconst (pfile, tok)
SYNTAX_ERROR ("empty character constant");
else if (num_chars > max_chars)
SYNTAX_ERROR ("character constant too long");
else if (num_chars != 1 && ! CPP_TRADITIONAL (pfile))
else if (num_chars != 1)
cpp_warning (pfile, "multi-character character constant");
/* If char type is signed, sign-extend the constant. */

View file

@ -43,6 +43,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
# define O_BINARY 0
#endif
/* Suppress warning about function macros used w/o arguments in traditional
C. It is unlikely that glibc's strcmp macro helps this file at all. */
#undef strcmp
static struct file_name_map *read_name_map
PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
@ -423,7 +427,7 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start, angle_brackets)
if (!search_start)
{
cpp_error (pfile, "No include path in which to find %s", fname);
cpp_error (pfile, "No include path in which to find %s", f);
return;
}
@ -762,6 +766,44 @@ read_with_read (fp, fd, size)
return offset;
}
/* Do appropriate cleanup when a file buffer is popped off the input
stack. */
void
_cpp_pop_file_buffer (pfile, buf)
cpp_reader *pfile;
cpp_buffer *buf;
{
struct include_file *inc = buf->inc;
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->include_depth)
pfile->include_depth--;
if (pfile->potential_control_macro)
{
if (inc->cmacro != NEVER_REREAD)
inc->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
/* Discard file buffer. XXX Would be better to cache these instead
of the file descriptors. */
#ifdef HAVE_MMAP_FILE
if (buf->mapped)
munmap ((caddr_t) buf->buf, buf->rlimit - buf->buf);
else
#endif
free ((PTR) buf->buf);
/* If the file will not be included again, close it. */
if (DO_NOT_REREAD (inc))
{
close (inc->fd);
inc->fd = -1;
}
}
/* The file_name_map structure holds a mapping of file names for a
particular directory. This mapping is read from the file named
FILE_NAME_MAP_FILE in that directory. Such a file can be used to

View file

@ -502,34 +502,33 @@ save_expansion (pfile, first, first_param, info)
ntokens = len = 0;
for (token = first; token->type != CPP_EOF; token++)
{
const char *msg;
if (token->type == CPP_PASTE)
{
/* Token-paste ##, but is a normal token if traditional. */
if (! CPP_TRADITIONAL (pfile))
/* Token-paste ##, can appear in both object-like and
function-like macros, but not at the ends. Constraint
6.10.3.3.1 */
if (token == first || token[1].type == CPP_EOF)
{
msg = "\"##\" cannot appear at either end of a macro expansion";
/* Constraint 6.10.3.3.1 */
if (token == first || token[1].type == CPP_EOF)
goto error;
continue;
cpp_error_with_line (pfile, token->line, token->col,
"'##' cannot appear at either end of a macro expansion");
return 0;
}
continue;
}
else if (token->type == CPP_HASH)
{
/* Stringifying #, but is a normal character if traditional,
or in object-like macros. Constraint 6.10.3.2.1. */
if (info->paramc >= 0 && ! CPP_TRADITIONAL (pfile))
/* Stringifying #, but a normal character in object-like
macros. Must come before a parameter name. Constraint
6.10.3.2.1. */
if (info->paramc >= 0)
{
if (token[1].type == CPP_NAME
&& find_param (first_param, token + 1))
continue;
if (! CPP_OPTION (pfile, lang_asm))
{
msg = "'#' is not followed by a macro parameter";
error:
cpp_error_with_line (pfile, token->line, token->col, msg);
cpp_error_with_line (pfile, token->line, token->col,
"'#' is not followed by a macro parameter");
return 0;
}
}
@ -583,7 +582,7 @@ save_expansion (pfile, first, first_param, info)
dest->val.aux = param_no - 1;
dest->type = CPP_MACRO_ARG;
if (token[-1].type == CPP_HASH && ! CPP_TRADITIONAL (pfile))
if (token[-1].type == CPP_HASH)
dest->flags = token[-1].flags | STRINGIFY_ARG;
else
dest->flags = token->flags; /* Particularly PREV_WHITE. */
@ -591,17 +590,12 @@ save_expansion (pfile, first, first_param, info)
continue;
case CPP_PASTE:
if (! CPP_TRADITIONAL (pfile))
{
dest[-1].flags |= PASTE_LEFT;
continue;
}
break;
dest[-1].flags |= PASTE_LEFT;
continue;
case CPP_HASH:
/* Stringifying #. Constraint 6.10.3.2.1 */
if (list->paramc >= 0 && ! CPP_TRADITIONAL (pfile)
&& token[1].type == CPP_NAME
if (list->paramc >= 0 && token[1].type == CPP_NAME
&& find_param (first_param, token + 1))
continue;
break;

View file

@ -194,7 +194,6 @@ extern unsigned char _cpp_IStable[256];
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
#define CPP_IN_SYSTEM_HEADER(PFILE) \
(CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
&& CPP_BUFFER (PFILE)->inc->sysp)
@ -228,6 +227,7 @@ extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
extern void _cpp_init_includes PARAMS ((cpp_reader *));
extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
/* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *));

View file

@ -571,12 +571,7 @@ initialize_builtins (pfile)
}
else
{
cpp_hashnode *hp;
if (b->type == T_STDC && CPP_TRADITIONAL (pfile))
continue;
hp = cpp_lookup (pfile, b->name, b->len);
cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
hp->type = b->type;
}
}
@ -762,22 +757,12 @@ cpp_start_read (pfile, print, fname)
return 0;
}
/* Chill should not be used with -trigraphs. */
if (CPP_OPTION (pfile, chill) && CPP_OPTION (pfile, trigraphs))
{
cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
CPP_OPTION (pfile, trigraphs) = 0;
}
/* -Wtraditional is not useful in C++ mode. */
if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0;
/* Do not warn about illegal token pasting if -traditional,
-lang-fortran, or -lang-asm. */
if (CPP_OPTION (pfile, traditional)
|| CPP_OPTION (pfile, lang_fortran)
|| CPP_OPTION (pfile, lang_asm))
/* Do not warn about illegal token pasting if -lang-asm. */
if (CPP_OPTION (pfile, lang_asm))
CPP_OPTION (pfile, warn_paste) = 0;
/* Set this if it hasn't been set already. */
@ -1028,8 +1013,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("lang-c", 0, OPT_lang_c) \
DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
DEF_OPT("lang-c89", 0, OPT_lang_c89) \
DEF_OPT("lang-chill", 0, OPT_lang_chill) \
DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \
DEF_OPT("lang-objc", 0, OPT_lang_objc) \
DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
DEF_OPT("nostdinc", 0, OPT_nostdinc) \
@ -1048,7 +1031,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
DEF_OPT("traditional", 0, OPT_traditional) \
DEF_OPT("trigraphs", 0, OPT_trigraphs) \
DEF_OPT("v", 0, OPT_v) \
DEF_OPT("w", 0, OPT_w)
@ -1267,13 +1249,6 @@ handle_option (pfile, argc, argv)
case OPT_pedantic:
CPP_OPTION (pfile, pedantic) = 1;
break;
case OPT_traditional:
CPP_OPTION (pfile, traditional) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 0;
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, digraphs) = 0;
CPP_OPTION (pfile, warn_trigraphs) = 0;
break;
case OPT_trigraphs:
CPP_OPTION (pfile, trigraphs) = 1;
break;
@ -1321,18 +1296,6 @@ handle_option (pfile, argc, argv)
CPP_OPTION (pfile, dollars_in_ident) = 0;
new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
break;
case OPT_lang_fortran:
CPP_OPTION (pfile, lang_fortran) = 1;
CPP_OPTION (pfile, traditional) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 0;
new_pending_directive (pend, "_LANGUAGE_FORTRAN", cpp_define);
break;
case OPT_lang_chill:
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, chill) = 1;
CPP_OPTION (pfile, traditional) = 1;
break;
case OPT_nostdinc:
/* -nostdinc causes no default include directories.
You must specify all include-file directories with -I. */
@ -1721,18 +1684,15 @@ Switches:\n\
fputs (_("\
-pedantic Issue all warnings demanded by strict ISO C\n\
-pedantic-errors Issue -pedantic warnings as errors instead\n\
-traditional Follow K&R pre-processor behaviour\n\
-trigraphs Support ISO C trigraphs\n\
-lang-c Assume that the input sources are in C\n\
-lang-c89 Assume that the input sources are in C89\n\
-lang-c++ Assume that the input sources are in C++\n\
"), stdout);
fputs (_("\
-lang-c++ Assume that the input sources are in C++\n\
-lang-objc Assume that the input sources are in ObjectiveC\n\
-lang-objc++ Assume that the input sources are in ObjectiveC++\n\
-lang-asm Assume that the input sources are in assembler\n\
-lang-fortran Assume that the input sources are in Fortran\n\
-lang-chill Assume that the input sources are in Chill\n\
"), stdout);
fputs (_("\
-std=<std name> Specify the conformance standard; one of:\n\
@ -1746,9 +1706,8 @@ Switches:\n\
"), stdout);
fputs (_("\
-Wno-comment{s} Do not warn about comments\n\
-Wtraditional Warn if a macro argument is/would be turned into\n\
a string if -traditional is specified\n\
-Wno-traditional Do not warn about stringification\n\
-Wtraditional Warn about features not present in traditional C\n\
-Wno-traditional Do not warn about traditional C\n\
-Wundef Warn if an undefined macro is used by #if\n\
-Wno-undef Do not warn about testing undefined macros\n\
-Wimport Warn about the use of the #import directive\n\

View file

@ -50,6 +50,54 @@ o Correct pastability test for CPP_NAME and CPP_NUMBER.
#include "cpphash.h"
#include "symcat.h"
static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO};
static const cpp_token eof_token = {0, 0, CPP_EOF, 0 UNION_INIT_ZERO};
/* Flags for cpp_context. */
#define CONTEXT_PASTEL (1 << 0) /* An argument context on LHS of ##. */
#define CONTEXT_PASTER (1 << 1) /* An argument context on RHS of ##. */
#define CONTEXT_RAW (1 << 2) /* If argument tokens already expanded. */
#define CONTEXT_ARG (1 << 3) /* If an argument context. */
typedef struct cpp_context cpp_context;
struct cpp_context
{
union
{
const cpp_toklist *list; /* Used for macro contexts only. */
const cpp_token **arg; /* Used for arg contexts only. */
} u;
/* Pushed token to be returned by next call to get_raw_token. */
const cpp_token *pushed_token;
struct macro_args *args; /* 0 for arguments and object-like macros. */
unsigned short posn; /* Current posn, index into u. */
unsigned short count; /* No. of tokens in u. */
unsigned short level;
unsigned char flags;
};
typedef struct macro_args macro_args;
struct macro_args
{
unsigned int *ends;
const cpp_token **tokens;
unsigned int capacity;
unsigned int used;
unsigned short level;
};
static const cpp_token *get_raw_token PARAMS ((cpp_reader *));
static const cpp_token *parse_arg PARAMS ((cpp_reader *, int, unsigned int,
macro_args *, unsigned int *));
static int parse_args PARAMS ((cpp_reader *, cpp_hashnode *, macro_args *));
static void save_token PARAMS ((macro_args *, const cpp_token *));
static int pop_context PARAMS ((cpp_reader *));
static int push_macro_context PARAMS ((cpp_reader *, const cpp_token *));
static void push_arg_context PARAMS ((cpp_reader *, const cpp_token *));
static void free_macro_args PARAMS ((macro_args *));
#define auto_expand_name_space(list) \
_cpp_expand_name_space ((list), 1 + (list)->name_cap / 2)
static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *,
@ -131,9 +179,9 @@ static void process_directive PARAMS ((cpp_reader *, const cpp_token *));
#define IMMED_TOKEN() (!(cur_token->flags & PREV_WHITE))
#define PREV_TOKEN_TYPE (cur_token[-1].type)
#define PUSH_TOKEN(ttype) cur_token++->type = ttype
#define REVISE_TOKEN(ttype) cur_token[-1].type = ttype
#define BACKUP_TOKEN(ttype) (--cur_token)->type = ttype
#define PUSH_TOKEN(ttype) cur_token++->type = (ttype)
#define REVISE_TOKEN(ttype) cur_token[-1].type = (ttype)
#define BACKUP_TOKEN(ttype) (--cur_token)->type = (ttype)
#define BACKUP_DIGRAPH(ttype) do { \
BACKUP_TOKEN(ttype); cur_token->flags |= DIGRAPH;} while (0)
@ -145,6 +193,20 @@ static void process_directive PARAMS ((cpp_reader *, const cpp_token *));
? (token)->val.node->length \
: 0)))
#define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
#define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
#define ASSIGN_FLAGS_AND_POS(d, s) \
do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
if ((d)->flags & BOL) {(d)->col = (s)->col; (d)->line = (s)->line;} \
} while (0)
/* f is flags, just consisting of PREV_WHITE | BOL. */
#define MODIFY_FLAGS_AND_POS(d, s, f) \
do {(d)->flags &= ~(PREV_WHITE | BOL); (d)->flags |= (f); \
if ((f) & BOL) {(d)->col = (s)->col; (d)->line = (s)->line;} \
} while (0)
#define T(e, s) {SPELL_OPERATOR, (const U_CHAR *) s},
#define I(e, s) {SPELL_IDENT, s},
#define S(e, s) {SPELL_STRING, s},
@ -368,7 +430,6 @@ cpp_scan_buffer_nooutput (pfile)
}
/* Scan until CPP_BUFFER (pfile) is exhausted, writing output to PRINT. */
void
cpp_scan_buffer (pfile, print)
cpp_reader *pfile;
@ -401,6 +462,29 @@ cpp_scan_buffer (pfile, print)
}
}
/* Scan a single line of the input into the token_buffer. */
void
cpp_scan_line (pfile)
cpp_reader *pfile;
{
const cpp_token *token, *prev = 0;
do
{
token = cpp_get_token (pfile);
if (token->type == CPP_EOF)
{
cpp_pop_buffer (pfile);
break;
}
output_token (pfile, token, prev);
prev = token;
}
while (pfile->cur_context > 0
|| pfile->contexts[0].posn < pfile->contexts[0].count);
}
/* Helper routine used by parse_include, which can't see spell_token.
Reinterpret the current line as an h-char-sequence (< ... >); we are
looking at the first token after the <. */
@ -872,8 +956,8 @@ skip_block_comment (pfile)
return seen_eof;
}
/* Skip a C++ or Chill line comment. Handles escaped newlines.
Returns non-zero if a multiline comment. */
/* Skip a C++ line comment. Handles escaped newlines. Returns
non-zero if a multiline comment. */
static int
skip_line_comment (pfile)
cpp_reader *pfile;
@ -1092,19 +1176,17 @@ parse_string (pfile, list, token, terminator)
cur--;
/* In Fortran and assembly language, silently terminate
strings of either variety at end of line. This is a
kludge around not knowing where comments are in these
languages. */
if (CPP_OPTION (pfile, lang_fortran)
|| CPP_OPTION (pfile, lang_asm))
/* In assembly language, silently terminate strings of
either variety at end of line. This is a kludge
around not knowing where comments are. */
if (CPP_OPTION (pfile, lang_asm))
goto out;
/* Character constants, headers and asserts may not
extend over multiple lines. In Standard C, neither
may strings. We accept multiline strings as an
/* Character constants and header names may not extend
over multiple lines. In Standard C, neither may
strings. We accept multiline strings as an
extension. (Even in directives - otherwise, glibc's
longlong.h breaks.) */
longlong.h breaks.) */
if (terminator != '"')
goto unterminated;
@ -1175,8 +1257,8 @@ parse_string (pfile, list, token, terminator)
}
/* The character TYPE helps us distinguish comment types: '*' = C
style, '-' = Chill-style and '/' = C++ style. For code simplicity,
the stored comment includes the comment start and any terminator. */
style, '/' = C++ style. For code simplicity, the stored comment
includes the comment start and any terminator. */
#define COMMENT_START_LEN 2
static void
@ -1352,26 +1434,12 @@ lex_line (pfile, list)
break;
case '\'':
/* Character constants are not recognized when processing Fortran,
or if -traditional. */
if (CPP_OPTION (pfile, lang_fortran) || CPP_TRADITIONAL (pfile))
goto other;
/* Fall through. */
case '\"':
/* Traditionally, escaped strings are not strings. */
if (CPP_TRADITIONAL (pfile) && IMMED_TOKEN ()
&& PREV_TOKEN_TYPE == CPP_BACKSLASH)
goto other;
cur_token->type = c == '\'' ? CPP_CHAR : CPP_STRING;
/* Do we have a wide string? */
if (cur_token[-1].type == CPP_NAME && IMMED_TOKEN ()
&& cur_token[-1].val.node == pfile->spec_nodes->n_L
&& !CPP_TRADITIONAL (pfile))
{
(--cur_token)->type = (c == '\'' ? CPP_WCHAR : CPP_WSTRING);
}
&& cur_token[-1].val.node == pfile->spec_nodes->n_L)
BACKUP_TOKEN (c == '\'' ? CPP_WCHAR : CPP_WSTRING);
do_parse_string:
/* Here c is one of ' " or >. */
@ -1423,7 +1491,7 @@ lex_line (pfile, list)
|| (list->directive->flags & COMMENTS)))
save_comment (list, cur_token++, cur,
buffer->cur - cur, c);
else if (!CPP_OPTION (pfile, traditional))
else
flags = PREV_WHITE;
cur = buffer->cur;
@ -1461,7 +1529,7 @@ lex_line (pfile, list)
|| (list->directive->flags & COMMENTS)))
save_comment (list, cur_token++, cur,
buffer->cur - cur, c);
else if (!CPP_OPTION (pfile, traditional))
else
flags = PREV_WHITE;
cur = buffer->cur;
@ -1524,14 +1592,9 @@ lex_line (pfile, list)
But it is still a directive, and therefore disappears
from the output. */
cur_token--;
if (cur_token->flags & PREV_WHITE)
{
if (CPP_WTRADITIONAL (pfile))
cpp_warning (pfile,
"K+R C ignores #\\n with the # indented");
if (CPP_TRADITIONAL (pfile))
cur_token++;
}
if (cur_token->flags & PREV_WHITE
&& CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "K+R C ignores #\\n with the # indented");
}
/* Skip vertical space until we have at least one token to
@ -1543,11 +1606,7 @@ lex_line (pfile, list)
case '-':
if (IMMED_TOKEN () && PREV_TOKEN_TYPE == CPP_MINUS)
{
if (CPP_OPTION (pfile, chill))
goto do_line_comment;
REVISE_TOKEN (CPP_MINUS_MINUS);
}
REVISE_TOKEN (CPP_MINUS_MINUS);
else
PUSH_TOKEN (CPP_MINUS);
break;
@ -1734,7 +1793,6 @@ lex_line (pfile, list)
if (CPP_OPTION (pfile, dollars_in_ident))
goto letter;
/* Fall through */
other:
default:
cur_token->val.aux = c;
PUSH_TOKEN (CPP_OTHER);
@ -1829,13 +1887,12 @@ output_token (pfile, token, prev)
}
else if (token->flags & PREV_WHITE)
CPP_PUTC (pfile, ' ');
/* Check for and prevent accidental token pasting, in ANSI mode. */
else if (!CPP_TRADITIONAL (pfile) && prev)
else if (prev)
{
/* Check for and prevent accidental token pasting. */
if (can_paste (pfile, prev, token, &dummy) != CPP_EOF)
CPP_PUTC (pfile, ' ');
/* can_paste catches most of the accidental paste cases, but not all.
/* can_paste doesn't catch all the accidental pastes.
Consider a + ++b - if there is not a space between the + and ++, it
will be misparsed as a++ + b. */
else if ((prev->type == CPP_PLUS && token->type == CPP_PLUS_PLUS)
@ -1927,67 +1984,6 @@ _cpp_spell_operator (type)
/* Macro expansion algorithm. TODO. */
static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO};
static const cpp_token eof_token = {0, 0, CPP_EOF, 0 UNION_INIT_ZERO};
#define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
#define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
/* Flags for cpp_context. */
#define CONTEXT_PASTEL (1 << 0) /* An argument context on LHS of ##. */
#define CONTEXT_PASTER (1 << 1) /* An argument context on RHS of ##. */
#define CONTEXT_RAW (1 << 2) /* If argument tokens already expanded. */
#define CONTEXT_ARG (1 << 3) /* If an argument context. */
#define ASSIGN_FLAGS_AND_POS(d, s) \
do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
if ((d)->flags & BOL) {(d)->col = (s)->col; (d)->line = (s)->line;} \
} while (0)
/* f is flags, just consisting of PREV_WHITE | BOL. */
#define MODIFY_FLAGS_AND_POS(d, s, f) \
do {(d)->flags &= ~(PREV_WHITE | BOL); (d)->flags |= (f); \
if ((f) & BOL) {(d)->col = (s)->col; (d)->line = (s)->line;} \
} while (0)
typedef struct cpp_context cpp_context;
struct cpp_context
{
union
{
const cpp_toklist *list; /* Used for macro contexts only. */
const cpp_token **arg; /* Used for arg contexts only. */
} u;
/* Pushed token to be returned by next call to get_raw_token. */
const cpp_token *pushed_token;
struct macro_args *args; /* 0 for arguments and object-like macros. */
unsigned short posn; /* Current posn, index into u. */
unsigned short count; /* No. of tokens in u. */
unsigned short level;
unsigned char flags;
};
typedef struct macro_args macro_args;
struct macro_args
{
unsigned int *ends;
const cpp_token **tokens;
unsigned int capacity;
unsigned int used;
unsigned short level;
};
static const cpp_token *get_raw_token PARAMS ((cpp_reader *));
static const cpp_token *parse_arg PARAMS ((cpp_reader *, int, unsigned int,
macro_args *, unsigned int *));
static int parse_args PARAMS ((cpp_reader *, cpp_hashnode *, macro_args *));
static void save_token PARAMS ((macro_args *, const cpp_token *));
static int pop_context PARAMS ((cpp_reader *));
static int push_macro_context PARAMS ((cpp_reader *, const cpp_token *));
static void push_arg_context PARAMS ((cpp_reader *, const cpp_token *));
static void free_macro_args PARAMS ((macro_args *));
/* Free the storage allocated for macro arguments. */
static void
@ -3179,18 +3175,10 @@ special_symbol (pfile, node, token)
break;
case T_INCLUDE_LEVEL:
{
int true_indepth = 0;
/* Do not count the primary source file in the include level. */
ip = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
while (ip)
{
true_indepth++;
ip = CPP_PREV_BUFFER (ip);
}
result = alloc_number_token (pfile, true_indepth);
}
/* pfile->include_depth counts the primary source as level 1,
but historically __INCLUDE_DEPTH__ has called the primary
source level 0. */
result = alloc_number_token (pfile, pfile->include_depth - 1);
break;
case T_SPECLINE:

View file

@ -28,10 +28,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "obstack.h"
#include "symcat.h"
#ifdef HAVE_MMAP_FILE
# include <sys/mman.h>
#endif
/* Stack of conditionals currently in progress
(including both successful and failing conditionals). */
@ -168,9 +164,6 @@ _cpp_check_directive (pfile, token, bol)
if (!bol && dtable[i].origin == KANDR && CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "traditional C ignores #%s with the # indented",
dtable[i].name);
if (!bol && CPP_TRADITIONAL (pfile))
return 0;
/* Issue -pedantic warnings for extended directives. */
if (CPP_PEDANTIC (pfile) && dtable[i].origin == EXTENSION)
@ -212,10 +205,7 @@ _cpp_check_linemarker (pfile, token, bol)
if (!bol && CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "traditional C ignores #%s with the # indented",
dtable[T_LINE].name);
if (!bol && CPP_TRADITIONAL (pfile))
return 0;
return &dtable[T_LINE];
}
@ -977,15 +967,12 @@ parse_ifdef (pfile, name)
const cpp_token *token = _cpp_get_token (pfile);
type = token->type;
if (!CPP_TRADITIONAL (pfile))
{
if (type == CPP_EOF)
cpp_pedwarn (pfile, "#%s with no argument", name);
else if (type != CPP_NAME)
cpp_pedwarn (pfile, "#%s with invalid argument", name);
else if (_cpp_get_token (pfile)->type != CPP_EOF)
cpp_pedwarn (pfile, "garbage at end of #%s", name);
}
if (type == CPP_EOF)
cpp_pedwarn (pfile, "#%s with no argument", name);
else if (type != CPP_NAME)
cpp_pedwarn (pfile, "#%s with invalid argument", name);
else if (_cpp_get_token (pfile)->type != CPP_EOF)
cpp_pedwarn (pfile, "garbage at end of #%s", name);
if (type == CPP_NAME)
node = token->val.node;
@ -995,7 +982,7 @@ parse_ifdef (pfile, name)
node->name);
node = 0;
}
return node;
}
@ -1527,9 +1514,10 @@ cpp_push_buffer (pfile, buffer, length)
new = xobnew (pfile->buffer_ob, cpp_buffer);
memset (new, 0, sizeof (cpp_buffer));
new->buf = new->cur = buffer;
new->line_base = new->buf = new->cur = buffer;
new->rlimit = buffer + length;
new->prev = buf;
new->lineno = 1;
CPP_BUFFER (pfile) = new;
return new;
@ -1542,34 +1530,8 @@ cpp_pop_buffer (pfile)
cpp_buffer *buf = CPP_BUFFER (pfile);
unwind_if_stack (pfile, buf);
#ifdef HAVE_MMAP_FILE
if (buf->mapped)
munmap ((caddr_t) buf->buf, buf->rlimit - buf->buf);
else
#endif
if (buf->inc)
free ((PTR) buf->buf);
if (buf->inc)
{
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->include_depth)
pfile->include_depth--;
if (pfile->potential_control_macro)
{
if (buf->inc->cmacro != NEVER_REREAD)
buf->inc->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
/* If the file will not be included again, then close it. */
if (DO_NOT_REREAD (buf->inc))
{
close (buf->inc->fd);
buf->inc->fd = -1;
}
}
_cpp_pop_file_buffer (pfile, buf);
CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
obstack_free (pfile->buffer_ob, buf);

View file

@ -314,15 +314,6 @@ struct cpp_options
likely to be in comments). */
unsigned char lang_asm;
/* Nonzero means this is Fortran, and we don't know where the
comments are, so permit unbalanced ' strings. Unlike lang_asm,
this does not ignore unrecognized directives. */
unsigned char lang_fortran;
/* Nonzero means handle CHILL comment syntax and output CHILL string
delimiters for __DATE__ etc. */
unsigned char chill;
/* Nonzero means don't copy comments into the output file. */
unsigned char discard_comments;
@ -366,9 +357,8 @@ struct cpp_options
/* Nonzero means warn if #import is used. */
unsigned char warn_import;
/* Nonzero means warn if a macro argument is (or would be)
stringified with -traditional, and warn about directives
with the # indented from the beginning of the line. */
/* Nonzero means warn about various incompatibilities with
traditional C. */
unsigned char warn_traditional;
/* Nonzero means warn if ## is applied to two tokens that cannot be
@ -396,9 +386,6 @@ struct cpp_options
/* Zero means dollar signs are punctuation. */
unsigned char dollars_in_ident;
/* Nonzero means try to imitate old fashioned non-ISO preprocessor. */
unsigned char traditional;
/* Nonzero means warn if undefined identifiers are evaluated in an #if. */
unsigned char warn_undef;
@ -701,6 +688,7 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
extern void cpp_scan_line PARAMS ((cpp_reader *));
extern int cpp_ideq PARAMS ((const cpp_token *,
const char *));