From: Zack Weinberg Date: Thu, 20 Apr 2000 19:33:11 +0000 (+0000) Subject: cpplib.h (enum cpp_ttype): Add token types for all punctuators. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1368ee700d0d2fd0f0c118e182dda14218dcff5b;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a71cc2d8b87..8488dd919be 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2000-04-20 Zack Weinberg + + * 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 * config/alpha/alpha.c (alpha_emit_floatuns): Emit missing barrier. @@ -1836,7 +1852,7 @@ Wed Apr 5 12:35:18 2000 Hans-Peter Nilsson all (op (minus A B) 0) with (op A B). Wed Apr 5 18:03:31 2000 Toshiyasu Morita (toshi.morita@sega.com) - J"orn Rennecke + J"orn Rennecke * sh.md (block_lump_real_i4): Add missing clobber of T_REG (block_lump_real): Likewise. diff --git a/gcc/cppexp.c b/gcc/cppexp.c index 91ffc5d20e7..1489dc96123 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -348,7 +348,7 @@ parse_defined (pfile) pfile->no_macro_expand++; token = _cpp_get_directive_token (pfile); - if (token == CPP_LPAREN) + if (token == CPP_OPEN_PAREN) { paren++; CPP_SET_WRITTEN (pfile, old_written); @@ -364,7 +364,7 @@ parse_defined (pfile) if (paren) { - if (_cpp_get_directive_token (pfile) != CPP_RPAREN) + if (_cpp_get_directive_token (pfile) != CPP_CLOSE_PAREN) goto oops; } CPP_SET_WRITTEN (pfile, old_written); diff --git a/gcc/cpphash.c b/gcc/cpphash.c index 70d1147465d..439cc805f45 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -335,7 +335,7 @@ collect_expansion (pfile, arglist) CPP_SET_WRITTEN (pfile, here); break; - case CPP_STRINGIZE: + case CPP_HASH: /* # is not special in object-like macros. It is special in function-like macros with no args. (6.10.3.2 para 1.) */ if (arglist == NULL) @@ -348,7 +348,7 @@ collect_expansion (pfile, arglist) CPP_SET_WRITTEN (pfile, here); /* delete from replacement text */ break; - case CPP_TOKPASTE: + case CPP_PASTE: /* If the last token was an argument, discard this token and any hspace between it and the argument's position. Then mark the arg raw_after. */ @@ -577,10 +577,10 @@ collect_formal_parameters (pfile) old_written = CPP_WRITTEN (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", - token, CPP_LPAREN); + token, CPP_OPEN_PAREN); goto invalid; } @@ -626,10 +626,10 @@ collect_formal_parameters (pfile) argv[argc].len = 0; break; - case CPP_RPAREN: + case CPP_CLOSE_PAREN: goto done; - case CPP_3DOTS: + case CPP_ELLIPSIS: goto rest_arg; case CPP_VSPACE: @@ -668,7 +668,7 @@ collect_formal_parameters (pfile) argv[argc].rest_arg = 1; token = _cpp_get_directive_token (pfile); - if (token != CPP_RPAREN) + if (token != CPP_CLOSE_PAREN) { cpp_error (pfile, "another parameter follows `...'"); goto invalid; @@ -776,10 +776,10 @@ macarg (pfile, rest_args) if (!CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) return token; break; - case CPP_LPAREN: + case CPP_OPEN_PAREN: paren++; break; - case CPP_RPAREN: + case CPP_CLOSE_PAREN: if (--paren < 0) goto found; break; @@ -1042,7 +1042,7 @@ _cpp_macroexpand (pfile, hp) pfile->no_directives++; 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)", token); CPP_ADJUST_WRITTEN (pfile, -1); @@ -1072,7 +1072,7 @@ _cpp_macroexpand (pfile, hp) CPP_OPTION (pfile, discard_comments)--; pfile->no_macro_expand--; pfile->no_directives--; - if (token != CPP_RPAREN) + if (token != CPP_CLOSE_PAREN) return; /* foo ( ) is equivalent to foo () unless foo takes exactly one diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 9779fad1764..b0ac3c654b7 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -120,12 +120,6 @@ struct hashnode 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. */ struct file_name_list { @@ -315,6 +309,7 @@ extern enum cpp_ttype _cpp_get_directive_token PARAMS ((cpp_reader *)); extern enum cpp_ttype _cpp_get_define_token PARAMS ((cpp_reader *)); +extern void _cpp_scan_line PARAMS ((cpp_reader *, cpp_toklist *)); /* In cpplib.c */ extern int _cpp_handle_directive PARAMS ((cpp_reader *)); diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 9d0a792ef4e..deae87e9447 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -50,7 +50,13 @@ static void null_warning PARAMS ((cpp_reader *, unsigned int)); static void safe_fwrite PARAMS ((cpp_reader *, const U_CHAR *, 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. */ @@ -149,23 +155,18 @@ safe_fwrite (pfile, buf, len, fp) or the current file name has changed. */ static void -output_line_command (pfile, print) +output_line_command (pfile, print, line) cpp_reader *pfile; cpp_printer *print; + unsigned int line; { - unsigned int line; - cpp_buffer *ip; + cpp_buffer *ip = cpp_file_buffer (pfile); enum { same = 0, enter, leave, rname } change; static const char * const codes[] = { "", " 1", " 2", "" }; if (CPP_OPTION (pfile, no_line_commands)) 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, how. 'nominal_fname' values are unique, so they can be compared by comparing pointers. */ @@ -224,6 +225,8 @@ cpp_output_tokens (pfile, print) cpp_reader *pfile; cpp_printer *print; { + cpp_buffer *ip; + if (CPP_WRITTEN (pfile) - print->written) { if (CPP_PWRITTEN (pfile)[-1] == '\n' && print->lineno) @@ -231,10 +234,79 @@ cpp_output_tokens (pfile, print) safe_fwrite (pfile, pfile->token_buffer, 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); } +/* 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, and write the result to the token_buffer. */ @@ -353,6 +425,107 @@ cpp_file_buffer (pfile) 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 at the second character of the starter. */ static void @@ -904,9 +1077,9 @@ _cpp_lex_token (pfile) CPP_PUTC_Q (pfile, GETC ()); } else - return CPP_STRINGIZE; + return CPP_HASH; - return CPP_TOKPASTE; + return CPP_PASTE; } if (!pfile->only_seen_white) @@ -959,7 +1132,7 @@ _cpp_lex_token (pfile) CPP_RESERVE (pfile, 2); CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c2); - return CPP_RBRACE; + return CPP_OPEN_BRACE; } /* else fall through */ @@ -1042,7 +1215,7 @@ _cpp_lex_token (pfile) CPP_RESERVE (pfile, 2); CPP_PUTC_Q (pfile, c); CPP_PUTC_Q (pfile, c2); - return CPP_LBRACE; + return CPP_CLOSE_BRACE; } else if (c2 == ':') goto op2; @@ -1082,7 +1255,7 @@ _cpp_lex_token (pfile) CPP_PUTC_Q (pfile, '.'); CPP_PUTC_Q (pfile, '.'); FORWARD (2); - return CPP_3DOTS; + return CPP_ELLIPSIS; } goto randomchar; @@ -1228,12 +1401,12 @@ _cpp_lex_token (pfile) CPP_PUTC (pfile, c); return CPP_VSPACE; - case '(': token = CPP_LPAREN; goto char1; - case ')': token = CPP_RPAREN; goto char1; - case '{': token = CPP_LBRACE; goto char1; - case '}': token = CPP_RBRACE; goto char1; - case ',': token = CPP_COMMA; goto char1; - case ';': token = CPP_SEMICOLON; goto char1; + case '(': token = CPP_OPEN_PAREN; goto char1; + case ')': token = CPP_CLOSE_PAREN; goto char1; + case '{': token = CPP_OPEN_BRACE; goto char1; + case '}': token = CPP_CLOSE_BRACE; goto char1; + case ',': token = CPP_COMMA; goto char1; + case ';': token = CPP_SEMICOLON; goto char1; randomchar: default: diff --git a/gcc/cpplib.c b/gcc/cpplib.c index b42f6b6eb3f..fb6b7709949 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -377,7 +377,7 @@ do_define (pfile) token = _cpp_get_directive_token (pfile); if (token == CPP_VSPACE) 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; else if (ADJACENT_TO_MARK (pfile)) /* If this is an object-like macro, C99 requires white space after @@ -688,11 +688,13 @@ do_line (pfile) if (action_number == 1) { pfile->buffer_stack_depth++; + ip->system_header_p = 0; read_line_number (pfile, &action_number); } else if (action_number == 2) { pfile->buffer_stack_depth--; + ip->system_header_p = 0; read_line_number (pfile, &action_number); } if (action_number == 3) @@ -1108,7 +1110,7 @@ detect_if_not_defined (pfile) /* ...then an optional '(' and the name, */ token_offset = CPP_WRITTEN (pfile); token = _cpp_get_directive_token (pfile); - if (token == CPP_LPAREN) + if (token == CPP_OPEN_PAREN) { token_offset = CPP_WRITTEN (pfile); need_rparen = 1; @@ -1120,7 +1122,7 @@ detect_if_not_defined (pfile) token_len = CPP_WRITTEN (pfile) - token_offset; /* ...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; /* ...and make sure there's nothing else on the line. */ diff --git a/gcc/cpplib.h b/gcc/cpplib.h index e6f2529b98a..6e3561ac01b 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -32,36 +32,156 @@ typedef struct cpp_reader cpp_reader; typedef struct cpp_buffer cpp_buffer; typedef struct cpp_options cpp_options; 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, "?") \ + 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) /* 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 { - CPP_EOF = -1, - CPP_OTHER = 0, - CPP_COMMENT = 1, - CPP_HSPACE, - CPP_VSPACE, /* newlines and #line directives */ - CPP_NAME, - CPP_MACRO, - CPP_NUMBER, - CPP_CHAR, - CPP_WCHAR, - CPP_STRING, - CPP_WSTRING, - CPP_DIRECTIVE, - CPP_ASSERTION, /* #machine(a29k) */ - CPP_STRINGIZE, /* stringize macro argument */ - CPP_TOKPASTE, /* paste macro arg with next/prev token */ - CPP_LPAREN, /* "(" */ - CPP_RPAREN, /* ")" */ - CPP_LBRACE, /* "{" */ - CPP_RBRACE, /* "}" */ - CPP_COMMA, /* "," */ - CPP_SEMICOLON, /* ";" */ - CPP_3DOTS, /* "..." */ - CPP_POP /* We're about to pop the buffer stack. */ + TTYPE_TABLE + N_TTYPES +}; +#undef T + +/* Payload of a NAME, NUMBER, FLOAT, STRING, or COMMENT token. */ +struct cpp_name +{ + unsigned int len; + unsigned int offset; /* from list->namebuf */ +}; + +/* A preprocessing token. + This has been carefully packed and should occupy 16 bytes on + both 32- and 64-bit hosts. */ +struct cpp_token +{ + unsigned short col; /* starting column of this token */ +#ifdef ENUM_BITFIELDS_ARE_UNSIGNED + enum cpp_ttype type : CHAR_BIT; /* node type */ +#else + unsigned char type; +#endif + 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 { @@ -442,6 +562,8 @@ extern void cpp_reader_init PARAMS ((cpp_reader *)); extern cpp_printer *cpp_printer_init PARAMS ((cpp_reader *, cpp_printer *)); 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_list PARAMS ((cpp_reader *, cpp_printer *, + const cpp_toklist *)); extern void cpp_finish PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_cleanup 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_nooutput PARAMS ((cpp_reader *)); + + /* In cpphash.c */ extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int)); diff --git a/gcc/scan-decls.c b/gcc/scan-decls.c index a0b8de0664f..3c33a1cc659 100644 --- a/gcc/scan-decls.c +++ b/gcc/scan-decls.c @@ -48,9 +48,9 @@ skip_to_closing_brace (pfile) enum cpp_ttype token = cpp_get_token (pfile); if (token == CPP_EOF) break; - if (token == CPP_LBRACE) + if (token == CPP_OPEN_BRACE) nesting++; - if (token == CPP_RBRACE && --nesting == 0) + if (token == CPP_CLOSE_BRACE && --nesting == 0) break; } } @@ -101,7 +101,7 @@ scan_decls (pfile, argc, argv) current_extern_C = 0; saw_extern = 0; saw_inline = 0; - if (token == CPP_RBRACE) + if (token == CPP_OPEN_BRACE) { /* Pop an 'extern "C"' nesting level, if appropriate. */ if (extern_C_braces_length @@ -110,7 +110,7 @@ scan_decls (pfile, argc, argv) brace_nesting--; goto new_statement; } - if (token == CPP_LBRACE) + if (token == CPP_OPEN_BRACE) { brace_nesting++; goto new_statement; @@ -128,7 +128,7 @@ scan_decls (pfile, argc, argv) { switch (token) { - case CPP_LPAREN: + case CPP_OPEN_PAREN: /* Looks like this is the start of a formal parameter list. */ if (prev_id_start) { @@ -139,9 +139,9 @@ scan_decls (pfile, argc, argv) for (;;) { token = cpp_get_token (pfile); - if (token == CPP_LPAREN) + if (token == CPP_OPEN_PAREN) nesting++; - else if (token == CPP_RPAREN) + else if (token == CPP_CLOSE_PAREN) { nesting--; if (nesting == 0) @@ -149,7 +149,7 @@ scan_decls (pfile, argc, argv) } else if (token == CPP_EOF) break; - else if (token == CPP_NAME || token == CPP_3DOTS) + else if (token == CPP_NAME || token == CPP_ELLIPSIS) have_arg_list = 1; } recognized_function (pfile->token_buffer + prev_id_start, @@ -161,7 +161,7 @@ scan_decls (pfile, argc, argv) have_arg_list, fbuf->nominal_fname, func_lineno); token = cpp_get_non_space_token (pfile); - if (token == CPP_LBRACE) + if (token == CPP_OPEN_BRACE) { /* skip body of (normally) inline function */ skip_to_closing_brace (pfile); @@ -218,7 +218,7 @@ scan_decls (pfile, argc, argv) CPP_SET_WRITTEN (pfile, start_written); current_extern_C = 1; token = cpp_get_non_space_token (pfile); - if (token == CPP_LBRACE) + if (token == CPP_OPEN_BRACE) { brace_nesting++; extern_C_braces[extern_C_braces_length++] @@ -238,7 +238,7 @@ scan_decls (pfile, argc, argv) case CPP_EOF: 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? */ case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP: