Commit 1368ee70 by Zack Weinberg

cpplib.h (enum cpp_ttype): Add token types for all punctuators.

	* cpplib.h (enum cpp_ttype): Add token types for all
	punctuators.  Distinguish pp-numbers from valid C numbers.
	Give some tokens better names.  Initialize from macro.
	(struct cpp_name, cpp_token, cpp_toklist): New data
	structures.
	Update prototypes.
	* cpplex.c (bump_column, expand_name_space,
	expand_token_space, init_token_list, cpp_output_list,
	_cpp_scan_line):  New functions.
	(output_line_command): Add third argument, new line number.
	* cpphash.h: Update prototypes.
	* cppexp.c, cpphash.c, cpplib.c, scan-decls.c: Update for new
	token names.

From-SVN: r33289
parent 70994f30
2000-04-20 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.h (enum cpp_ttype): Add token types for all
punctuators. Distinguish pp-numbers from valid C numbers.
Give some tokens better names. Initialize from macro.
(struct cpp_name, cpp_token, cpp_toklist): New data
structures.
Update prototypes.
* cpplex.c (bump_column, expand_name_space,
expand_token_space, init_token_list, cpp_output_list,
_cpp_scan_line): New functions.
(output_line_command): Add third argument, new line number.
* cpphash.h: Update prototypes.
* cppexp.c, cpphash.c, cpplib.c, scan-decls.c: Update for new
token names.
2000-04-20 Richard Henderson <rth@cygnus.com> 2000-04-20 Richard Henderson <rth@cygnus.com>
* config/alpha/alpha.c (alpha_emit_floatuns): Emit missing barrier. * config/alpha/alpha.c (alpha_emit_floatuns): Emit missing barrier.
...@@ -1836,7 +1852,7 @@ Wed Apr 5 12:35:18 2000 Hans-Peter Nilsson <hp@axis.com> ...@@ -1836,7 +1852,7 @@ Wed Apr 5 12:35:18 2000 Hans-Peter Nilsson <hp@axis.com>
all (op (minus A B) 0) with (op A B). all (op (minus A B) 0) with (op A B).
Wed Apr 5 18:03:31 2000 Toshiyasu Morita (toshi.morita@sega.com) Wed Apr 5 18:03:31 2000 Toshiyasu Morita (toshi.morita@sega.com)
J"orn Rennecke <amylaar@cygnus.co.uk> J"orn Rennecke <amylaar@cygnus.co.uk>
* sh.md (block_lump_real_i4): Add missing clobber of T_REG * sh.md (block_lump_real_i4): Add missing clobber of T_REG
(block_lump_real): Likewise. (block_lump_real): Likewise.
......
...@@ -348,7 +348,7 @@ parse_defined (pfile) ...@@ -348,7 +348,7 @@ parse_defined (pfile)
pfile->no_macro_expand++; pfile->no_macro_expand++;
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
if (token == CPP_LPAREN) if (token == CPP_OPEN_PAREN)
{ {
paren++; paren++;
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
...@@ -364,7 +364,7 @@ parse_defined (pfile) ...@@ -364,7 +364,7 @@ parse_defined (pfile)
if (paren) if (paren)
{ {
if (_cpp_get_directive_token (pfile) != CPP_RPAREN) if (_cpp_get_directive_token (pfile) != CPP_CLOSE_PAREN)
goto oops; goto oops;
} }
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
......
...@@ -335,7 +335,7 @@ collect_expansion (pfile, arglist) ...@@ -335,7 +335,7 @@ collect_expansion (pfile, arglist)
CPP_SET_WRITTEN (pfile, here); CPP_SET_WRITTEN (pfile, here);
break; break;
case CPP_STRINGIZE: case CPP_HASH:
/* # is not special in object-like macros. It is special in /* # is not special in object-like macros. It is special in
function-like macros with no args. (6.10.3.2 para 1.) */ function-like macros with no args. (6.10.3.2 para 1.) */
if (arglist == NULL) if (arglist == NULL)
...@@ -348,7 +348,7 @@ collect_expansion (pfile, arglist) ...@@ -348,7 +348,7 @@ collect_expansion (pfile, arglist)
CPP_SET_WRITTEN (pfile, here); /* delete from replacement text */ CPP_SET_WRITTEN (pfile, here); /* delete from replacement text */
break; break;
case CPP_TOKPASTE: case CPP_PASTE:
/* If the last token was an argument, discard this token and /* If the last token was an argument, discard this token and
any hspace between it and the argument's position. Then any hspace between it and the argument's position. Then
mark the arg raw_after. */ mark the arg raw_after. */
...@@ -577,10 +577,10 @@ collect_formal_parameters (pfile) ...@@ -577,10 +577,10 @@ collect_formal_parameters (pfile)
old_written = CPP_WRITTEN (pfile); old_written = CPP_WRITTEN (pfile);
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
if (token != CPP_LPAREN) if (token != CPP_OPEN_PAREN)
{ {
cpp_ice (pfile, "first token = %d not %d in collect_formal_parameters", cpp_ice (pfile, "first token = %d not %d in collect_formal_parameters",
token, CPP_LPAREN); token, CPP_OPEN_PAREN);
goto invalid; goto invalid;
} }
...@@ -626,10 +626,10 @@ collect_formal_parameters (pfile) ...@@ -626,10 +626,10 @@ collect_formal_parameters (pfile)
argv[argc].len = 0; argv[argc].len = 0;
break; break;
case CPP_RPAREN: case CPP_CLOSE_PAREN:
goto done; goto done;
case CPP_3DOTS: case CPP_ELLIPSIS:
goto rest_arg; goto rest_arg;
case CPP_VSPACE: case CPP_VSPACE:
...@@ -668,7 +668,7 @@ collect_formal_parameters (pfile) ...@@ -668,7 +668,7 @@ collect_formal_parameters (pfile)
argv[argc].rest_arg = 1; argv[argc].rest_arg = 1;
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
if (token != CPP_RPAREN) if (token != CPP_CLOSE_PAREN)
{ {
cpp_error (pfile, "another parameter follows `...'"); cpp_error (pfile, "another parameter follows `...'");
goto invalid; goto invalid;
...@@ -776,10 +776,10 @@ macarg (pfile, rest_args) ...@@ -776,10 +776,10 @@ macarg (pfile, rest_args)
if (!CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) if (!CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
return token; return token;
break; break;
case CPP_LPAREN: case CPP_OPEN_PAREN:
paren++; paren++;
break; break;
case CPP_RPAREN: case CPP_CLOSE_PAREN:
if (--paren < 0) if (--paren < 0)
goto found; goto found;
break; break;
...@@ -1042,7 +1042,7 @@ _cpp_macroexpand (pfile, hp) ...@@ -1042,7 +1042,7 @@ _cpp_macroexpand (pfile, hp)
pfile->no_directives++; pfile->no_directives++;
token = cpp_get_non_space_token (pfile); token = cpp_get_non_space_token (pfile);
if (token != CPP_LPAREN) if (token != CPP_OPEN_PAREN)
cpp_ice (pfile, "macroexpand: unexpected token %d (wanted LPAREN)", cpp_ice (pfile, "macroexpand: unexpected token %d (wanted LPAREN)",
token); token);
CPP_ADJUST_WRITTEN (pfile, -1); CPP_ADJUST_WRITTEN (pfile, -1);
...@@ -1072,7 +1072,7 @@ _cpp_macroexpand (pfile, hp) ...@@ -1072,7 +1072,7 @@ _cpp_macroexpand (pfile, hp)
CPP_OPTION (pfile, discard_comments)--; CPP_OPTION (pfile, discard_comments)--;
pfile->no_macro_expand--; pfile->no_macro_expand--;
pfile->no_directives--; pfile->no_directives--;
if (token != CPP_RPAREN) if (token != CPP_CLOSE_PAREN)
return; return;
/* foo ( ) is equivalent to foo () unless foo takes exactly one /* foo ( ) is equivalent to foo () unless foo takes exactly one
......
...@@ -120,12 +120,6 @@ struct hashnode ...@@ -120,12 +120,6 @@ struct hashnode
enum node_type type; /* type of special token */ enum node_type type; /* type of special token */
}; };
/* Directive flags. */
#define SYNTAX_INCLUDE (1 << 8)
#define SYNTAX_ASSERT (1 << 9)
typedef int (* directive_handler) PARAMS ((cpp_reader *));
/* List of directories to look for include files in. */ /* List of directories to look for include files in. */
struct file_name_list struct file_name_list
{ {
...@@ -315,6 +309,7 @@ extern enum cpp_ttype _cpp_get_directive_token ...@@ -315,6 +309,7 @@ extern enum cpp_ttype _cpp_get_directive_token
PARAMS ((cpp_reader *)); PARAMS ((cpp_reader *));
extern enum cpp_ttype _cpp_get_define_token extern enum cpp_ttype _cpp_get_define_token
PARAMS ((cpp_reader *)); PARAMS ((cpp_reader *));
extern void _cpp_scan_line PARAMS ((cpp_reader *, cpp_toklist *));
/* In cpplib.c */ /* In cpplib.c */
extern int _cpp_handle_directive PARAMS ((cpp_reader *)); extern int _cpp_handle_directive PARAMS ((cpp_reader *));
......
...@@ -50,7 +50,13 @@ static void null_warning PARAMS ((cpp_reader *, unsigned int)); ...@@ -50,7 +50,13 @@ static void null_warning PARAMS ((cpp_reader *, unsigned int));
static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *, static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *,
size_t, FILE *)); size_t, FILE *));
static void output_line_command PARAMS ((cpp_reader *, cpp_printer *)); static void output_line_command PARAMS ((cpp_reader *, cpp_printer *,
unsigned int));
static void bump_column PARAMS ((cpp_printer *, unsigned int,
unsigned int));
static void expand_name_space PARAMS ((cpp_toklist *));
static void expand_token_space PARAMS ((cpp_toklist *));
static void init_token_list PARAMS ((cpp_reader *, cpp_toklist *, int));
/* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */ /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
...@@ -149,23 +155,18 @@ safe_fwrite (pfile, buf, len, fp) ...@@ -149,23 +155,18 @@ safe_fwrite (pfile, buf, len, fp)
or the current file name has changed. */ or the current file name has changed. */
static void static void
output_line_command (pfile, print) output_line_command (pfile, print, line)
cpp_reader *pfile; cpp_reader *pfile;
cpp_printer *print; cpp_printer *print;
unsigned int line;
{ {
unsigned int line; cpp_buffer *ip = cpp_file_buffer (pfile);
cpp_buffer *ip;
enum { same = 0, enter, leave, rname } change; enum { same = 0, enter, leave, rname } change;
static const char * const codes[] = { "", " 1", " 2", "" }; static const char * const codes[] = { "", " 1", " 2", "" };
if (CPP_OPTION (pfile, no_line_commands)) if (CPP_OPTION (pfile, no_line_commands))
return; return;
ip = cpp_file_buffer (pfile);
if (ip == NULL)
return;
line = CPP_BUF_LINE (ip);
/* Determine whether the current filename has changed, and if so, /* Determine whether the current filename has changed, and if so,
how. 'nominal_fname' values are unique, so they can be compared how. 'nominal_fname' values are unique, so they can be compared
by comparing pointers. */ by comparing pointers. */
...@@ -224,6 +225,8 @@ cpp_output_tokens (pfile, print) ...@@ -224,6 +225,8 @@ cpp_output_tokens (pfile, print)
cpp_reader *pfile; cpp_reader *pfile;
cpp_printer *print; cpp_printer *print;
{ {
cpp_buffer *ip;
if (CPP_WRITTEN (pfile) - print->written) if (CPP_WRITTEN (pfile) - print->written)
{ {
if (CPP_PWRITTEN (pfile)[-1] == '\n' && print->lineno) if (CPP_PWRITTEN (pfile)[-1] == '\n' && print->lineno)
...@@ -231,10 +234,79 @@ cpp_output_tokens (pfile, print) ...@@ -231,10 +234,79 @@ cpp_output_tokens (pfile, print)
safe_fwrite (pfile, pfile->token_buffer, safe_fwrite (pfile, pfile->token_buffer,
CPP_WRITTEN (pfile) - print->written, print->outf); CPP_WRITTEN (pfile) - print->written, print->outf);
} }
output_line_command (pfile, print);
ip = cpp_file_buffer (pfile);
if (ip)
output_line_command (pfile, print, CPP_BUF_LINE (ip));
CPP_SET_WRITTEN (pfile, print->written); CPP_SET_WRITTEN (pfile, print->written);
} }
/* Helper for cpp_output_list - increases the column number to match
what we expect it to be. */
static void
bump_column (print, from, to)
cpp_printer *print;
unsigned int from, to;
{
unsigned int tabs, spcs;
unsigned int delta = to - from;
/* Only if FROM is 0, advance by tabs. */
if (from == 0)
tabs = delta / 8, spcs = delta % 8;
else
tabs = 0, spcs = delta;
while (tabs--) putc ('\t', print->outf);
while (spcs--) putc (' ', print->outf);
}
/* Write out the list L onto pfile->token_buffer. This function is
incomplete:
1) pfile->token_buffer is not going to continue to exist.
2) At the moment, tokens don't carry the information described
in cpplib.h; they are all strings.
3) The list has to be a complete line, and has to be written starting
at the beginning of a line. */
void
cpp_output_list (pfile, print, list)
cpp_reader *pfile;
cpp_printer *print;
const cpp_toklist *list;
{
unsigned int i;
unsigned int curcol = 1;
/* XXX Probably does not do what is intended. */
if (print->lineno != list->line)
output_line_command (pfile, print, list->line);
for (i = 0; i < list->tokens_used; i++)
{
if (list->tokens[i].type == CPP_VSPACE)
{
output_line_command (pfile, print, list->tokens[i].aux);
continue;
}
if (curcol < list->tokens[i].col)
{
/* Insert space to bring the column to what it should be. */
bump_column (print, curcol - 1, list->tokens[i].col);
curcol = list->tokens[i].col;
}
/* XXX We may have to insert space to prevent an accidental
token paste. */
safe_fwrite (pfile, list->namebuf + list->tokens[i].val.name.offset,
list->tokens[i].val.name.len, print->outf);
curcol += list->tokens[i].val.name.len;
}
}
/* Scan a string (which may have escape marks), perform macro expansion, /* Scan a string (which may have escape marks), perform macro expansion,
and write the result to the token_buffer. */ and write the result to the token_buffer. */
...@@ -353,6 +425,107 @@ cpp_file_buffer (pfile) ...@@ -353,6 +425,107 @@ cpp_file_buffer (pfile)
return NULL; return NULL;
} }
/* Token-buffer helper functions. */
/* Expand a token list's string space. */
static void
expand_name_space (list)
cpp_toklist *list;
{
list->name_cap *= 2;
list->namebuf = (unsigned char *) xrealloc (list->namebuf,
list->name_cap);
}
/* Expand the number of tokens in a list. */
static void
expand_token_space (list)
cpp_toklist *list;
{
list->tokens_cap *= 2;
list->tokens = (cpp_token *)
xrealloc (list->tokens, list->tokens_cap * sizeof (cpp_token));
}
/* Initialise a token list. */
static void
init_token_list (pfile, list, recycle)
cpp_reader *pfile;
cpp_toklist *list;
int recycle;
{
/* Recycling a used list saves 2 free-malloc pairs. */
if (recycle)
{
list->tokens_used = 0;
list->name_used = 0;
}
else
{
/* Initialise token space. */
list->tokens_cap = 256; /* 4K on Intel. */
list->tokens_used = 0;
list->tokens = (cpp_token *)
xmalloc (list->tokens_cap * sizeof (cpp_token));
/* Initialise name space. */
list->name_cap = 1024;
list->name_used = 0;
list->namebuf = (unsigned char *) xmalloc (list->name_cap);
}
list->line = pfile->buffer->lineno;
list->dir_handler = 0;
list->dir_flags = 0;
}
/* Scan an entire line and create a token list for it. Does not
macro-expand or execute directives. */
void
_cpp_scan_line (pfile, list)
cpp_reader *pfile;
cpp_toklist *list;
{
int i, col;
long written, len;
enum cpp_ttype type;
init_token_list (pfile, list, 1);
written = CPP_WRITTEN (pfile);
i = 0;
for (;;)
{
col = CPP_BUFFER (pfile)->cur - CPP_BUFFER (pfile)->line_base;
type = _cpp_lex_token (pfile);
len = CPP_WRITTEN (pfile) - written;
CPP_SET_WRITTEN (pfile, written);
if (type == CPP_HSPACE)
continue;
if (list->tokens_used >= list->tokens_cap)
expand_token_space (list);
if (list->name_used + len >= list->name_cap)
expand_name_space (list);
list->tokens_used++;
list->tokens[i].type = type;
list->tokens[i].col = col;
if (type == CPP_VSPACE)
break;
list->tokens[i].val.name.len = len;
list->tokens[i].val.name.offset = list->name_used;
memcpy (list->namebuf + list->name_used, CPP_PWRITTEN (pfile), len);
list->name_used += len;
i++;
}
list->tokens[i].aux = CPP_BUFFER (pfile)->lineno + 1;
}
/* Skip a C-style block comment. We know it's a comment, and point is /* Skip a C-style block comment. We know it's a comment, and point is
at the second character of the starter. */ at the second character of the starter. */
static void static void
...@@ -904,9 +1077,9 @@ _cpp_lex_token (pfile) ...@@ -904,9 +1077,9 @@ _cpp_lex_token (pfile)
CPP_PUTC_Q (pfile, GETC ()); CPP_PUTC_Q (pfile, GETC ());
} }
else else
return CPP_STRINGIZE; return CPP_HASH;
return CPP_TOKPASTE; return CPP_PASTE;
} }
if (!pfile->only_seen_white) if (!pfile->only_seen_white)
...@@ -959,7 +1132,7 @@ _cpp_lex_token (pfile) ...@@ -959,7 +1132,7 @@ _cpp_lex_token (pfile)
CPP_RESERVE (pfile, 2); CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, c2); CPP_PUTC_Q (pfile, c2);
return CPP_RBRACE; return CPP_OPEN_BRACE;
} }
/* else fall through */ /* else fall through */
...@@ -1042,7 +1215,7 @@ _cpp_lex_token (pfile) ...@@ -1042,7 +1215,7 @@ _cpp_lex_token (pfile)
CPP_RESERVE (pfile, 2); CPP_RESERVE (pfile, 2);
CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c);
CPP_PUTC_Q (pfile, c2); CPP_PUTC_Q (pfile, c2);
return CPP_LBRACE; return CPP_CLOSE_BRACE;
} }
else if (c2 == ':') else if (c2 == ':')
goto op2; goto op2;
...@@ -1082,7 +1255,7 @@ _cpp_lex_token (pfile) ...@@ -1082,7 +1255,7 @@ _cpp_lex_token (pfile)
CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.');
CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.');
FORWARD (2); FORWARD (2);
return CPP_3DOTS; return CPP_ELLIPSIS;
} }
goto randomchar; goto randomchar;
...@@ -1228,12 +1401,12 @@ _cpp_lex_token (pfile) ...@@ -1228,12 +1401,12 @@ _cpp_lex_token (pfile)
CPP_PUTC (pfile, c); CPP_PUTC (pfile, c);
return CPP_VSPACE; return CPP_VSPACE;
case '(': token = CPP_LPAREN; goto char1; case '(': token = CPP_OPEN_PAREN; goto char1;
case ')': token = CPP_RPAREN; goto char1; case ')': token = CPP_CLOSE_PAREN; goto char1;
case '{': token = CPP_LBRACE; goto char1; case '{': token = CPP_OPEN_BRACE; goto char1;
case '}': token = CPP_RBRACE; goto char1; case '}': token = CPP_CLOSE_BRACE; goto char1;
case ',': token = CPP_COMMA; goto char1; case ',': token = CPP_COMMA; goto char1;
case ';': token = CPP_SEMICOLON; goto char1; case ';': token = CPP_SEMICOLON; goto char1;
randomchar: randomchar:
default: default:
......
...@@ -377,7 +377,7 @@ do_define (pfile) ...@@ -377,7 +377,7 @@ do_define (pfile)
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
if (token == CPP_VSPACE) if (token == CPP_VSPACE)
empty = 0; /* Empty definition of object like macro. */ empty = 0; /* Empty definition of object like macro. */
else if (token == CPP_LPAREN && ADJACENT_TO_MARK (pfile)) else if (token == CPP_OPEN_PAREN && ADJACENT_TO_MARK (pfile))
funlike = 1; funlike = 1;
else if (ADJACENT_TO_MARK (pfile)) else if (ADJACENT_TO_MARK (pfile))
/* If this is an object-like macro, C99 requires white space after /* If this is an object-like macro, C99 requires white space after
...@@ -688,11 +688,13 @@ do_line (pfile) ...@@ -688,11 +688,13 @@ do_line (pfile)
if (action_number == 1) if (action_number == 1)
{ {
pfile->buffer_stack_depth++; pfile->buffer_stack_depth++;
ip->system_header_p = 0;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
else if (action_number == 2) else if (action_number == 2)
{ {
pfile->buffer_stack_depth--; pfile->buffer_stack_depth--;
ip->system_header_p = 0;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
if (action_number == 3) if (action_number == 3)
...@@ -1108,7 +1110,7 @@ detect_if_not_defined (pfile) ...@@ -1108,7 +1110,7 @@ detect_if_not_defined (pfile)
/* ...then an optional '(' and the name, */ /* ...then an optional '(' and the name, */
token_offset = CPP_WRITTEN (pfile); token_offset = CPP_WRITTEN (pfile);
token = _cpp_get_directive_token (pfile); token = _cpp_get_directive_token (pfile);
if (token == CPP_LPAREN) if (token == CPP_OPEN_PAREN)
{ {
token_offset = CPP_WRITTEN (pfile); token_offset = CPP_WRITTEN (pfile);
need_rparen = 1; need_rparen = 1;
...@@ -1120,7 +1122,7 @@ detect_if_not_defined (pfile) ...@@ -1120,7 +1122,7 @@ detect_if_not_defined (pfile)
token_len = CPP_WRITTEN (pfile) - token_offset; token_len = CPP_WRITTEN (pfile) - token_offset;
/* ...then the ')', if necessary, */ /* ...then the ')', if necessary, */
if (need_rparen && _cpp_get_directive_token (pfile) != CPP_RPAREN) if (need_rparen && _cpp_get_directive_token (pfile) != CPP_CLOSE_PAREN)
goto restore; goto restore;
/* ...and make sure there's nothing else on the line. */ /* ...and make sure there's nothing else on the line. */
......
...@@ -32,36 +32,156 @@ typedef struct cpp_reader cpp_reader; ...@@ -32,36 +32,156 @@ typedef struct cpp_reader cpp_reader;
typedef struct cpp_buffer cpp_buffer; typedef struct cpp_buffer cpp_buffer;
typedef struct cpp_options cpp_options; typedef struct cpp_options cpp_options;
typedef struct cpp_printer cpp_printer; typedef struct cpp_printer cpp_printer;
typedef struct cpp_token cpp_token;
typedef struct cpp_toklist cpp_toklist;
/* Put operators that can appear in a preprocessor expression first.
This allows a lookup table to be implemented in _cpp_parse_expr.
Ordering within this group is currently not significant, apart
from those ending in '=' being at the end. */
#define TTYPE_TABLE \
T(CPP_PLUS = 0, "+") /* math */ \
T(CPP_MINUS, "-") \
T(CPP_MULT, "*") \
T(CPP_DIV, "/") \
T(CPP_MOD, "%") \
T(CPP_AND, "&") /* bit ops */ \
T(CPP_OR, "|") \
T(CPP_XOR, "^") \
T(CPP_COMPL, "~") \
T(CPP_RSHIFT, ">>") \
T(CPP_LSHIFT, "<<") \
T(CPP_NOT, "!") /* logicals */ \
T(CPP_AND_AND, "&&") \
T(CPP_OR_OR, "||") \
T(CPP_QUERY, "?") \
T(CPP_COLON, ":") \
T(CPP_COMMA, ",") /* grouping */ \
T(CPP_OPEN_PAREN, "(") \
T(CPP_CLOSE_PAREN, ")") \
T(CPP_GREATER, ">") /* compare */ \
T(CPP_LESS, "<") \
T(CPP_EQ_EQ, "==") \
T(CPP_NOT_EQ, "!=") \
T(CPP_GREATER_EQ, ">=") \
T(CPP_LESS_EQ, "<=") \
\
/* The remainder of the punctuation. Order is not significant. */ \
T(CPP_PLUS_EQ, "+=") /* math */ \
T(CPP_MINUS_EQ, "-=") \
T(CPP_MULT_EQ, "*=") \
T(CPP_DIV_EQ, "/=") \
T(CPP_MOD_EQ, "%=") \
T(CPP_AND_EQ, "&=") /* bit ops */ \
T(CPP_OR_EQ, "|=") \
T(CPP_XOR_EQ, "^=") \
T(CPP_COMPL_EQ, "~=") \
T(CPP_RSHIFT_EQ, ">>=") \
T(CPP_LSHIFT_EQ, "<<=") \
T(CPP_EQ, "=") /* assign */ \
T(CPP_PLUS_PLUS, "++") /* increment */ \
T(CPP_MINUS_MINUS, "--") \
T(CPP_DEREF, "->") /* accessors */ \
T(CPP_DOT, ".") \
T(CPP_OPEN_SQUARE, "[") \
T(CPP_CLOSE_SQUARE, "]") \
T(CPP_SCOPE, "::") \
T(CPP_DEREF_STAR, "->*") \
T(CPP_DOT_STAR, ".*") \
T(CPP_OPEN_BRACE, "{") /* structure */ \
T(CPP_CLOSE_BRACE, "}") \
T(CPP_SEMICOLON, ";") \
T(CPP_ELLIPSIS, "...") \
T(CPP_HASH, "#") \
T(CPP_PASTE, "##") \
T(CPP_BACKSLASH, "\\") \
T(CPP_MIN, "<?") /* extension */ \
T(CPP_MAX, ">?") \
T(CPP_OTHER, spell_other) /* stray punctuation */ \
\
T(CPP_NAME, spell_name) /* word */ \
T(CPP_INT, 0) /* 23 */ \
T(CPP_FLOAT, 0) /* 3.14159 */ \
T(CPP_NUMBER, spell_name) /* 34_be+ta */ \
T(CPP_CHAR, spell_char) /* 'char' */ \
T(CPP_WCHAR, spell_char) /* L'char' */ \
T(CPP_STRING, spell_string) /* "string" */ \
T(CPP_WSTRING, spell_string) /* L"string" */ \
\
T(CPP_COMMENT, spell_comment) /* Only if output comments. */ \
T(CPP_VSPACE, "\n") /* End of line. */ \
T(CPP_EOF, 0) /* End of file. */ \
T(CPP_HEADER_NAME, 0) /* <stdio.h> in #include */ \
T(CPP_ASSERTION, 0) /* (...) in #assert */ \
\
/* Obsolete - will be removed when no code uses them still. */ \
T(CPP_HSPACE, 0) /* Horizontal white space. */ \
T(CPP_POP, 0) /* End of buffer. */ \
T(CPP_DIRECTIVE, 0) /* #define and the like */ \
T(CPP_MACRO, 0) /* Like a NAME, but expanded. */
#define T(e, s) e,
enum cpp_ttype enum cpp_ttype
{ {
CPP_EOF = -1, TTYPE_TABLE
CPP_OTHER = 0, N_TTYPES
CPP_COMMENT = 1, };
CPP_HSPACE, #undef T
CPP_VSPACE, /* newlines and #line directives */
CPP_NAME, /* Payload of a NAME, NUMBER, FLOAT, STRING, or COMMENT token. */
CPP_MACRO, struct cpp_name
CPP_NUMBER, {
CPP_CHAR, unsigned int len;
CPP_WCHAR, unsigned int offset; /* from list->namebuf */
CPP_STRING, };
CPP_WSTRING,
CPP_DIRECTIVE, /* A preprocessing token.
CPP_ASSERTION, /* #machine(a29k) */ This has been carefully packed and should occupy 16 bytes on
CPP_STRINGIZE, /* stringize macro argument */ both 32- and 64-bit hosts. */
CPP_TOKPASTE, /* paste macro arg with next/prev token */ struct cpp_token
CPP_LPAREN, /* "(" */ {
CPP_RPAREN, /* ")" */ unsigned short col; /* starting column of this token */
CPP_LBRACE, /* "{" */ #ifdef ENUM_BITFIELDS_ARE_UNSIGNED
CPP_RBRACE, /* "}" */ enum cpp_ttype type : CHAR_BIT; /* node type */
CPP_COMMA, /* "," */ #else
CPP_SEMICOLON, /* ";" */ unsigned char type;
CPP_3DOTS, /* "..." */ #endif
CPP_POP /* We're about to pop the buffer stack. */ unsigned char flags; /* flags - not presently used */
unsigned int aux; /* hash of a NAME, or something -
see uses in the code */
union
{
struct cpp_name name; /* a string */
HOST_WIDEST_INT integer; /* an integer */
} val;
}; };
typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *)); /* Directive flags. */
#define SYNTAX_INCLUDE (1 << 8)
#define SYNTAX_ASSERT (1 << 9)
typedef int (*directive_handler) PARAMS ((cpp_reader *));
typedef int (*parse_cleanup_t) PARAMS ((cpp_buffer *, cpp_reader *));
struct cpp_toklist
{
struct cpp_token *tokens; /* actual tokens as an array */
unsigned int tokens_used; /* tokens used */
unsigned int tokens_cap; /* tokens allocated */
unsigned char *namebuf; /* names buffer */
unsigned int name_used; /* _bytes_ used */
unsigned int name_cap; /* _bytes_ allocated */
unsigned int line; /* starting line number */
/* Only used if tokens[0].type == CPP_DIRECTIVE. This is the
handler to call after lexing the rest of this line. The flags
indicate whether the rest of the line gets special treatment
during lexing (#include, #if, #assert, #unassert). */
directive_handler dir_handler;
unsigned short dir_flags;
};
struct cpp_buffer struct cpp_buffer
{ {
...@@ -442,6 +562,8 @@ extern void cpp_reader_init PARAMS ((cpp_reader *)); ...@@ -442,6 +562,8 @@ extern void cpp_reader_init PARAMS ((cpp_reader *));
extern cpp_printer *cpp_printer_init PARAMS ((cpp_reader *, cpp_printer *)); extern cpp_printer *cpp_printer_init PARAMS ((cpp_reader *, cpp_printer *));
extern int cpp_start_read PARAMS ((cpp_reader *, cpp_printer *, const char *)); extern int cpp_start_read PARAMS ((cpp_reader *, cpp_printer *, const char *));
extern void cpp_output_tokens PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_output_tokens PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_output_list PARAMS ((cpp_reader *, cpp_printer *,
const cpp_toklist *));
extern void cpp_finish PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_finish PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_cleanup PARAMS ((cpp_reader *)); extern void cpp_cleanup PARAMS ((cpp_reader *));
...@@ -487,6 +609,8 @@ extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *)); ...@@ -487,6 +609,8 @@ extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *)); extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
/* In cpphash.c */ /* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *, extern int cpp_defined PARAMS ((cpp_reader *,
const unsigned char *, int)); const unsigned char *, int));
......
...@@ -48,9 +48,9 @@ skip_to_closing_brace (pfile) ...@@ -48,9 +48,9 @@ skip_to_closing_brace (pfile)
enum cpp_ttype token = cpp_get_token (pfile); enum cpp_ttype token = cpp_get_token (pfile);
if (token == CPP_EOF) if (token == CPP_EOF)
break; break;
if (token == CPP_LBRACE) if (token == CPP_OPEN_BRACE)
nesting++; nesting++;
if (token == CPP_RBRACE && --nesting == 0) if (token == CPP_CLOSE_BRACE && --nesting == 0)
break; break;
} }
} }
...@@ -101,7 +101,7 @@ scan_decls (pfile, argc, argv) ...@@ -101,7 +101,7 @@ scan_decls (pfile, argc, argv)
current_extern_C = 0; current_extern_C = 0;
saw_extern = 0; saw_extern = 0;
saw_inline = 0; saw_inline = 0;
if (token == CPP_RBRACE) if (token == CPP_OPEN_BRACE)
{ {
/* Pop an 'extern "C"' nesting level, if appropriate. */ /* Pop an 'extern "C"' nesting level, if appropriate. */
if (extern_C_braces_length if (extern_C_braces_length
...@@ -110,7 +110,7 @@ scan_decls (pfile, argc, argv) ...@@ -110,7 +110,7 @@ scan_decls (pfile, argc, argv)
brace_nesting--; brace_nesting--;
goto new_statement; goto new_statement;
} }
if (token == CPP_LBRACE) if (token == CPP_OPEN_BRACE)
{ {
brace_nesting++; brace_nesting++;
goto new_statement; goto new_statement;
...@@ -128,7 +128,7 @@ scan_decls (pfile, argc, argv) ...@@ -128,7 +128,7 @@ scan_decls (pfile, argc, argv)
{ {
switch (token) switch (token)
{ {
case CPP_LPAREN: case CPP_OPEN_PAREN:
/* Looks like this is the start of a formal parameter list. */ /* Looks like this is the start of a formal parameter list. */
if (prev_id_start) if (prev_id_start)
{ {
...@@ -139,9 +139,9 @@ scan_decls (pfile, argc, argv) ...@@ -139,9 +139,9 @@ scan_decls (pfile, argc, argv)
for (;;) for (;;)
{ {
token = cpp_get_token (pfile); token = cpp_get_token (pfile);
if (token == CPP_LPAREN) if (token == CPP_OPEN_PAREN)
nesting++; nesting++;
else if (token == CPP_RPAREN) else if (token == CPP_CLOSE_PAREN)
{ {
nesting--; nesting--;
if (nesting == 0) if (nesting == 0)
...@@ -149,7 +149,7 @@ scan_decls (pfile, argc, argv) ...@@ -149,7 +149,7 @@ scan_decls (pfile, argc, argv)
} }
else if (token == CPP_EOF) else if (token == CPP_EOF)
break; break;
else if (token == CPP_NAME || token == CPP_3DOTS) else if (token == CPP_NAME || token == CPP_ELLIPSIS)
have_arg_list = 1; have_arg_list = 1;
} }
recognized_function (pfile->token_buffer + prev_id_start, recognized_function (pfile->token_buffer + prev_id_start,
...@@ -161,7 +161,7 @@ scan_decls (pfile, argc, argv) ...@@ -161,7 +161,7 @@ scan_decls (pfile, argc, argv)
have_arg_list, have_arg_list,
fbuf->nominal_fname, func_lineno); fbuf->nominal_fname, func_lineno);
token = cpp_get_non_space_token (pfile); token = cpp_get_non_space_token (pfile);
if (token == CPP_LBRACE) if (token == CPP_OPEN_BRACE)
{ {
/* skip body of (normally) inline function */ /* skip body of (normally) inline function */
skip_to_closing_brace (pfile); skip_to_closing_brace (pfile);
...@@ -218,7 +218,7 @@ scan_decls (pfile, argc, argv) ...@@ -218,7 +218,7 @@ scan_decls (pfile, argc, argv)
CPP_SET_WRITTEN (pfile, start_written); CPP_SET_WRITTEN (pfile, start_written);
current_extern_C = 1; current_extern_C = 1;
token = cpp_get_non_space_token (pfile); token = cpp_get_non_space_token (pfile);
if (token == CPP_LBRACE) if (token == CPP_OPEN_BRACE)
{ {
brace_nesting++; brace_nesting++;
extern_C_braces[extern_C_braces_length++] extern_C_braces[extern_C_braces_length++]
...@@ -238,7 +238,7 @@ scan_decls (pfile, argc, argv) ...@@ -238,7 +238,7 @@ scan_decls (pfile, argc, argv)
case CPP_EOF: case CPP_EOF:
return 0; return 0;
case CPP_LBRACE: case CPP_RBRACE: case CPP_DIRECTIVE: case CPP_OPEN_BRACE: case CPP_CLOSE_BRACE: case CPP_DIRECTIVE:
goto new_statement; /* handle_statement? */ goto new_statement; /* handle_statement? */
case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP: case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment