diff options
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/cpp.texi | 7 | ||||
-rw-r--r-- | gcc/cppinit.c | 14 | ||||
-rw-r--r-- | gcc/cpplex.c | 34 | ||||
-rw-r--r-- | gcc/cpplib.h | 9 |
5 files changed, 68 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b80c1df..dc6182a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,21 @@ +2000-05-18 Neil Booth <NeilB@earthling.net> + + * cppinit.c (cpp_reader_init): Initialise col_adjust and + default tab stop size. + (no_num, OPT_ftabstop): New. + (handle_option): Handle "ftabstop=" command-line option. + (print_help): Document it. + * cpplex.c (COLUMN): Remove. + (handle_newline): Reset col_adjust. + (skip_whitespace): Update col_adjust as tabs encountered. + (_cpp_lex_line): Update to use col_adjust. Call + skip_whitespace for all whitespace. + * cpplib.h (struct cpp_options): New member tabstop. + (struct cpp_reader): New member col_adjust. + (CPP_BUF_COL): Update. + (CPP_BUF_COLUMN): New. + * cpp.texi: Document "-ftabstop=" command line option. + Wed May 17 18:19:41 2000 Philippe De Muyter <phdm@macqel.be> * configure.in (NO_MINUS_C_MINUS_O): Macro made availabe for AC_OUTPUT diff --git a/gcc/cpp.texi b/gcc/cpp.texi index ed126f8..9a48f5e 100644 --- a/gcc/cpp.texi +++ b/gcc/cpp.texi @@ -3155,6 +3155,13 @@ Because of the clash with @samp{-l}, you must use the awkward syntax above. In a future release, this option will be replaced by @samp{-flint} or @samp{-Wlint}; we are not sure which yet. +@item -ftabstop=NUMBER +@findex -ftabstop +Indicates the distance between tabstops. This helps the preprocessor +report correct column numbers in warnings or errors, even if tabs appear +on the line. Values less than 1 or greater than 100 are ignored. The +default is 8. + @item -$ @findex -$ Forbid the use of @samp{$} in identifiers. The C standard does not diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 3f47736..120f386 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -545,6 +545,7 @@ cpp_reader_init (pfile) CPP_OPTION (pfile, warn_import) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, show_column) = 1; + CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, pending) = (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); @@ -1079,6 +1080,7 @@ new_pending_directive (pend, text, handler) #define no_fil N_("File name missing after %s") #define no_mac N_("Macro name missing after %s") #define no_pth N_("Path name missing after %s") +#define no_num N_("Number missing after %s") /* This is the list of all command line options, with the leading "-" removed. It must be sorted in ASCII collating order. */ @@ -1108,6 +1110,7 @@ new_pending_directive (pend, text, handler) DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \ DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \ DEF_OPT("fshow-column", 0, OPT_fshow_column) \ + DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \ DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \ DEF_OPT("h", 0, OPT_h) \ DEF_OPT("idirafter", no_dir, OPT_idirafter) \ @@ -1312,6 +1315,16 @@ handle_option (pfile, argc, argv) case OPT_fno_show_column: CPP_OPTION (pfile, show_column) = 0; break; + case OPT_ftabstop: + /* Silently ignore empty string, non-longs and silly values. */ + if (arg[0] != '\0') + { + char *endptr; + long tabstop = strtol (arg, &endptr, 10); + if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100) + CPP_OPTION (pfile, tabstop) = tabstop; + } + break; case OPT_w: CPP_OPTION (pfile, inhibit_warnings) = 1; break; @@ -1833,6 +1846,7 @@ Switches:\n\ -dD Preserve macro definitions in output\n\ -dN As -dD except that only the names are preserved\n\ -dI Include #include directives in the output\n\ + -ftabstop=<number> Distance between tab stops for column reporting\n\ -P Do not generate #line directives\n\ -$ Do not allow '$' in identifiers\n\ -remap Remap file names when including files.\n\ diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 2549d22..f0414a0 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -96,7 +96,6 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *, (name).text = (list)->namebuf + (list)->name_used;} while (0) #define IS_DIRECTIVE(list) (TOK_TYPE (list, 0) == CPP_HASH) -#define COLUMN(cur) ((cur) - buffer->line_base) /* Maybe put these in the ISTABLE eventually. */ #define IS_HSPACE(c) ((c) == ' ' || (c) == '\t') @@ -109,6 +108,7 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *, if ((cur) < (limit) && *(cur) == '\r' + '\n' - c) \ (cur)++; \ CPP_BUMP_LINE_CUR (pfile, (cur)); \ + pfile->col_adjust = 0; \ } while (0) #define IMMED_TOKEN() (!(cur_token->flags & PREV_WHITESPACE)) @@ -2506,7 +2506,9 @@ skip_line_comment2 (pfile) return multiline; } -/* Skips whitespace, stopping at next non-whitespace character. */ +/* Skips whitespace, stopping at next non-whitespace character. + Adjusts pfile->col_adjust to account for tabs. This enables tokens + to be assigned the correct column. */ static void skip_whitespace (pfile, in_directive) cpp_reader *pfile; @@ -2520,6 +2522,12 @@ skip_whitespace (pfile, in_directive) { unsigned char c = *cur++; + if (c == '\t') + { + unsigned int col = CPP_BUF_COLUMN (buffer, cur - 1); + pfile->col_adjust += (CPP_OPTION (pfile, tabstop) - 1 + - col % CPP_OPTION(pfile, tabstop)); + } if (IS_HSPACE(c)) /* FIXME: Fix ISTABLE. */ continue; if (!is_space(c) || IS_NEWLINE (c)) /* Main loop handles newlines. */ @@ -2847,6 +2855,7 @@ _cpp_lex_line (pfile, list) register const unsigned char *cur = buffer->cur; unsigned char flags = 0; + pfile->col_adjust = 0; expanded: token_limit = list->tokens + list->tokens_cap; cur_token = list->tokens + list->tokens_used; @@ -2855,17 +2864,16 @@ _cpp_lex_line (pfile, list) { unsigned char c = *cur++; - /* Optimize whitespace skipping, in particular the case of a - single whitespace character, as every other token is probably - whitespace. (' ' '\t' '\v' '\f' '\0'). */ + /* Optimize whitespace skipping, as most tokens are probably + separated by whitespace. (' ' '\t' '\v' '\f' '\0'). */ + if (is_hspace ((unsigned int) c)) { - if (c == '\0' || (cur < buffer->rlimit && is_hspace (*cur))) - { - buffer->cur = cur - (c == '\0'); /* Get the null warning. */ - skip_whitespace (pfile, IS_DIRECTIVE (list)); - cur = buffer->cur; - } + /* Step back to get the null warning and tab correction. */ + buffer->cur = cur - 1; + skip_whitespace (pfile, IS_DIRECTIVE (list)); + cur = buffer->cur; + flags = PREV_WHITESPACE; if (cur == buffer->rlimit) break; @@ -2873,7 +2881,7 @@ _cpp_lex_line (pfile, list) } /* Initialize current token. Its type is set in the switch. */ - cur_token->col = COLUMN (cur); + cur_token->col = CPP_BUF_COLUMN (buffer, cur); cur_token->flags = flags; flags = 0; @@ -2947,7 +2955,7 @@ _cpp_lex_line (pfile, list) } do_parse_string: - /* Here c is one of ' " > or ). */ + /* Here c is one of ' " or >. */ INIT_NAME (list, cur_token->val.name); buffer->cur = cur; parse_string2 (pfile, list, &cur_token->val.name, c); diff --git a/gcc/cpplib.h b/gcc/cpplib.h index a538887..a46ada3 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -302,6 +302,9 @@ struct cpp_options const char *in_fname; const char *out_fname; + /* Characters between tab stops. */ + unsigned int tabstop; + /* Pending options - -D, -U, -A, -I, -ixxx. */ struct cpp_pending *pending; @@ -510,6 +513,9 @@ struct cpp_reader struct if_stack *if_stack; const unsigned char *potential_control_macro; + /* Token column position adjustment owing to tabs in whitespace. */ + unsigned int col_adjust; + /* Buffer of -M output. */ struct deps *deps; @@ -586,7 +592,8 @@ struct cpp_printer #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) #define CPP_BUFFER(PFILE) ((PFILE)->buffer) #define CPP_BUF_LINE(BUF) ((BUF)->lineno) -#define CPP_BUF_COL(BUF) ((BUF)->cur - (BUF)->line_base) +#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + pfile->col_adjust) +#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur) /* Name under which this program was invoked. */ extern const char *progname; |