Commit 6ab3e7dd by Neil Booth Committed by Neil Booth

cppinit.c (cpp_reader_init): Initialise col_adjust and default tab stop size.

	* 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.

From-SVN: r33982
parent fc5b2138
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> 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 * configure.in (NO_MINUS_C_MINUS_O): Macro made availabe for AC_OUTPUT
......
...@@ -3155,6 +3155,13 @@ Because of the clash with @samp{-l}, you must use the awkward syntax ...@@ -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 above. In a future release, this option will be replaced by
@samp{-flint} or @samp{-Wlint}; we are not sure which yet. @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 -$ @item -$
@findex -$ @findex -$
Forbid the use of @samp{$} in identifiers. The C standard does not Forbid the use of @samp{$} in identifiers. The C standard does not
......
...@@ -545,6 +545,7 @@ cpp_reader_init (pfile) ...@@ -545,6 +545,7 @@ cpp_reader_init (pfile)
CPP_OPTION (pfile, warn_import) = 1; CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, show_column) = 1; CPP_OPTION (pfile, show_column) = 1;
CPP_OPTION (pfile, tabstop) = 8;
CPP_OPTION (pfile, pending) = CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
...@@ -1079,6 +1080,7 @@ new_pending_directive (pend, text, handler) ...@@ -1079,6 +1080,7 @@ new_pending_directive (pend, text, handler)
#define no_fil N_("File name missing after %s") #define no_fil N_("File name missing after %s")
#define no_mac N_("Macro name missing after %s") #define no_mac N_("Macro name missing after %s")
#define no_pth N_("Path 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 /* This is the list of all command line options, with the leading
"-" removed. It must be sorted in ASCII collating order. */ "-" removed. It must be sorted in ASCII collating order. */
...@@ -1108,6 +1110,7 @@ new_pending_directive (pend, text, handler) ...@@ -1108,6 +1110,7 @@ new_pending_directive (pend, text, handler)
DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \ DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \ DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
DEF_OPT("fshow-column", 0, OPT_fshow_column) \ 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("g", no_arg, OPT_g) /* arg optional */ \
DEF_OPT("h", 0, OPT_h) \ DEF_OPT("h", 0, OPT_h) \
DEF_OPT("idirafter", no_dir, OPT_idirafter) \ DEF_OPT("idirafter", no_dir, OPT_idirafter) \
...@@ -1312,6 +1315,16 @@ handle_option (pfile, argc, argv) ...@@ -1312,6 +1315,16 @@ handle_option (pfile, argc, argv)
case OPT_fno_show_column: case OPT_fno_show_column:
CPP_OPTION (pfile, show_column) = 0; CPP_OPTION (pfile, show_column) = 0;
break; 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: case OPT_w:
CPP_OPTION (pfile, inhibit_warnings) = 1; CPP_OPTION (pfile, inhibit_warnings) = 1;
break; break;
...@@ -1833,6 +1846,7 @@ Switches:\n\ ...@@ -1833,6 +1846,7 @@ Switches:\n\
-dD Preserve macro definitions in output\n\ -dD Preserve macro definitions in output\n\
-dN As -dD except that only the names are preserved\n\ -dN As -dD except that only the names are preserved\n\
-dI Include #include directives in the output\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\ -P Do not generate #line directives\n\
-$ Do not allow '$' in identifiers\n\ -$ Do not allow '$' in identifiers\n\
-remap Remap file names when including files.\n\ -remap Remap file names when including files.\n\
......
...@@ -96,7 +96,6 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *, ...@@ -96,7 +96,6 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *,
(name).text = (list)->namebuf + (list)->name_used;} while (0) (name).text = (list)->namebuf + (list)->name_used;} while (0)
#define IS_DIRECTIVE(list) (TOK_TYPE (list, 0) == CPP_HASH) #define IS_DIRECTIVE(list) (TOK_TYPE (list, 0) == CPP_HASH)
#define COLUMN(cur) ((cur) - buffer->line_base)
/* Maybe put these in the ISTABLE eventually. */ /* Maybe put these in the ISTABLE eventually. */
#define IS_HSPACE(c) ((c) == ' ' || (c) == '\t') #define IS_HSPACE(c) ((c) == ' ' || (c) == '\t')
...@@ -109,6 +108,7 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *, ...@@ -109,6 +108,7 @@ typedef unsigned int (* speller) PARAMS ((unsigned char *, cpp_toklist *,
if ((cur) < (limit) && *(cur) == '\r' + '\n' - c) \ if ((cur) < (limit) && *(cur) == '\r' + '\n' - c) \
(cur)++; \ (cur)++; \
CPP_BUMP_LINE_CUR (pfile, (cur)); \ CPP_BUMP_LINE_CUR (pfile, (cur)); \
pfile->col_adjust = 0; \
} while (0) } while (0)
#define IMMED_TOKEN() (!(cur_token->flags & PREV_WHITESPACE)) #define IMMED_TOKEN() (!(cur_token->flags & PREV_WHITESPACE))
...@@ -2506,7 +2506,9 @@ skip_line_comment2 (pfile) ...@@ -2506,7 +2506,9 @@ skip_line_comment2 (pfile)
return multiline; 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 static void
skip_whitespace (pfile, in_directive) skip_whitespace (pfile, in_directive)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -2520,6 +2522,12 @@ skip_whitespace (pfile, in_directive) ...@@ -2520,6 +2522,12 @@ skip_whitespace (pfile, in_directive)
{ {
unsigned char c = *cur++; 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. */ if (IS_HSPACE(c)) /* FIXME: Fix ISTABLE. */
continue; continue;
if (!is_space(c) || IS_NEWLINE (c)) /* Main loop handles newlines. */ if (!is_space(c) || IS_NEWLINE (c)) /* Main loop handles newlines. */
...@@ -2847,6 +2855,7 @@ _cpp_lex_line (pfile, list) ...@@ -2847,6 +2855,7 @@ _cpp_lex_line (pfile, list)
register const unsigned char *cur = buffer->cur; register const unsigned char *cur = buffer->cur;
unsigned char flags = 0; unsigned char flags = 0;
pfile->col_adjust = 0;
expanded: expanded:
token_limit = list->tokens + list->tokens_cap; token_limit = list->tokens + list->tokens_cap;
cur_token = list->tokens + list->tokens_used; cur_token = list->tokens + list->tokens_used;
...@@ -2855,17 +2864,16 @@ _cpp_lex_line (pfile, list) ...@@ -2855,17 +2864,16 @@ _cpp_lex_line (pfile, list)
{ {
unsigned char c = *cur++; unsigned char c = *cur++;
/* Optimize whitespace skipping, in particular the case of a /* Optimize whitespace skipping, as most tokens are probably
single whitespace character, as every other token is probably separated by whitespace. (' ' '\t' '\v' '\f' '\0'). */
whitespace. (' ' '\t' '\v' '\f' '\0'). */
if (is_hspace ((unsigned int) c)) if (is_hspace ((unsigned int) c))
{ {
if (c == '\0' || (cur < buffer->rlimit && is_hspace (*cur))) /* Step back to get the null warning and tab correction. */
{ buffer->cur = cur - 1;
buffer->cur = cur - (c == '\0'); /* Get the null warning. */ skip_whitespace (pfile, IS_DIRECTIVE (list));
skip_whitespace (pfile, IS_DIRECTIVE (list)); cur = buffer->cur;
cur = buffer->cur;
}
flags = PREV_WHITESPACE; flags = PREV_WHITESPACE;
if (cur == buffer->rlimit) if (cur == buffer->rlimit)
break; break;
...@@ -2873,7 +2881,7 @@ _cpp_lex_line (pfile, list) ...@@ -2873,7 +2881,7 @@ _cpp_lex_line (pfile, list)
} }
/* Initialize current token. Its type is set in the switch. */ /* 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; cur_token->flags = flags;
flags = 0; flags = 0;
...@@ -2947,7 +2955,7 @@ _cpp_lex_line (pfile, list) ...@@ -2947,7 +2955,7 @@ _cpp_lex_line (pfile, list)
} }
do_parse_string: do_parse_string:
/* Here c is one of ' " > or ). */ /* Here c is one of ' " or >. */
INIT_NAME (list, cur_token->val.name); INIT_NAME (list, cur_token->val.name);
buffer->cur = cur; buffer->cur = cur;
parse_string2 (pfile, list, &cur_token->val.name, c); parse_string2 (pfile, list, &cur_token->val.name, c);
......
...@@ -302,6 +302,9 @@ struct cpp_options ...@@ -302,6 +302,9 @@ struct cpp_options
const char *in_fname; const char *in_fname;
const char *out_fname; const char *out_fname;
/* Characters between tab stops. */
unsigned int tabstop;
/* Pending options - -D, -U, -A, -I, -ixxx. */ /* Pending options - -D, -U, -A, -I, -ixxx. */
struct cpp_pending *pending; struct cpp_pending *pending;
...@@ -510,6 +513,9 @@ struct cpp_reader ...@@ -510,6 +513,9 @@ struct cpp_reader
struct if_stack *if_stack; struct if_stack *if_stack;
const unsigned char *potential_control_macro; const unsigned char *potential_control_macro;
/* Token column position adjustment owing to tabs in whitespace. */
unsigned int col_adjust;
/* Buffer of -M output. */ /* Buffer of -M output. */
struct deps *deps; struct deps *deps;
...@@ -586,7 +592,8 @@ struct cpp_printer ...@@ -586,7 +592,8 @@ struct cpp_printer
#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
#define CPP_BUFFER(PFILE) ((PFILE)->buffer) #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
#define CPP_BUF_LINE(BUF) ((BUF)->lineno) #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. */ /* Name under which this program was invoked. */
extern const char *progname; extern const char *progname;
......
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