Commit 1444f2ed by Neil Booth Committed by Neil Booth

cpphash.h (struct cpp_reader): New members line, pseudo_newlines.

	* cpphash.h (struct cpp_reader): New members line, pseudo_newlines.
	* cpplex.c (handle_newline): Update prototype.  Maintain logical
	line number.
	(skip_escaped_newlines, skip_block_comment, parse_string):
	Update accordingly.
	(_cpp_lex_token): Update, and store token position within the token.
	* cpplib.h (struct cpp_token): Add line and column entries.
	* cppmacro.c (replace_args): Position stringified tokens correctly.

From-SVN: r44533
parent 7f8a2125
2001-08-01 Neil Booth <neil@cat.daikokuya.demon.co.uk>
* cpphash.h (struct cpp_reader): New members line, pseudo_newlines.
* cpplex.c (handle_newline): Update prototype. Maintain logical
line number.
(skip_escaped_newlines, skip_block_comment, parse_string):
Update accordingly.
(_cpp_lex_token): Update, and store token position within the token.
* cpplib.h (struct cpp_token): Add line and column entries.
* cppmacro.c (replace_args): Position stringified tokens correctly.
2001-08-01 Andreas Jaeger <aj@suse.de> 2001-08-01 Andreas Jaeger <aj@suse.de>
* basic-block.h: Add prototype for last_loop_beg_note. * basic-block.h: Add prototype for last_loop_beg_note.
......
...@@ -246,6 +246,12 @@ struct cpp_reader ...@@ -246,6 +246,12 @@ struct cpp_reader
/* Lexer state. */ /* Lexer state. */
struct lexer_state state; struct lexer_state state;
/* Source line tracking. Subtract pseudo_newlines from the actual
line number to get the line number of preprocessed output. Used
for escaped newlines and macro args that cross multiple lines. */
unsigned int line;
unsigned int pseudo_newlines;
/* The position of the last lexed token and last lexed directive. */ /* The position of the last lexed token and last lexed directive. */
cpp_lexer_pos lexer_pos; cpp_lexer_pos lexer_pos;
cpp_lexer_pos directive_pos; cpp_lexer_pos directive_pos;
......
...@@ -80,7 +80,7 @@ const struct token_spelling token_spellings [N_TTYPES] = {TTYPE_TABLE }; ...@@ -80,7 +80,7 @@ const struct token_spelling token_spellings [N_TTYPES] = {TTYPE_TABLE };
#define TOKEN_SPELL(token) (token_spellings[(token)->type].category) #define TOKEN_SPELL(token) (token_spellings[(token)->type].category)
#define TOKEN_NAME(token) (token_spellings[(token)->type].name) #define TOKEN_NAME(token) (token_spellings[(token)->type].name)
static cppchar_t handle_newline PARAMS ((cpp_buffer *, cppchar_t)); static cppchar_t handle_newline PARAMS ((cpp_reader *, cppchar_t));
static cppchar_t skip_escaped_newlines PARAMS ((cpp_buffer *, cppchar_t)); static cppchar_t skip_escaped_newlines PARAMS ((cpp_buffer *, cppchar_t));
static cppchar_t get_effective_char PARAMS ((cpp_buffer *)); static cppchar_t get_effective_char PARAMS ((cpp_buffer *));
...@@ -124,12 +124,17 @@ cpp_ideq (token, string) ...@@ -124,12 +124,17 @@ cpp_ideq (token, string)
/* Call when meeting a newline. Returns the character after the newline /* Call when meeting a newline. Returns the character after the newline
(or carriage-return newline combination), or EOF. */ (or carriage-return newline combination), or EOF. */
static cppchar_t static cppchar_t
handle_newline (buffer, newline_char) handle_newline (pfile, newline_char)
cpp_buffer *buffer; cpp_reader *pfile;
cppchar_t newline_char; cppchar_t newline_char;
{ {
cpp_buffer *buffer;
cppchar_t next = EOF; cppchar_t next = EOF;
pfile->line++;
pfile->pseudo_newlines++;
buffer = pfile->buffer;
buffer->col_adjust = 0; buffer->col_adjust = 0;
buffer->lineno++; buffer->lineno++;
buffer->line_base = buffer->cur; buffer->line_base = buffer->cur;
...@@ -264,7 +269,7 @@ skip_escaped_newlines (buffer, next) ...@@ -264,7 +269,7 @@ skip_escaped_newlines (buffer, next)
cpp_warning (buffer->pfile, cpp_warning (buffer->pfile,
"backslash and newline separated by space"); "backslash and newline separated by space");
next = handle_newline (buffer, next1); next = handle_newline (buffer->pfile, next1);
if (next == EOF) if (next == EOF)
cpp_pedwarn (buffer->pfile, "backslash-newline at end of file"); cpp_pedwarn (buffer->pfile, "backslash-newline at end of file");
} }
...@@ -348,7 +353,7 @@ skip_block_comment (pfile) ...@@ -348,7 +353,7 @@ skip_block_comment (pfile)
} }
else if (is_vspace (c)) else if (is_vspace (c))
{ {
prevc = c, c = handle_newline (buffer, c); prevc = c, c = handle_newline (pfile, c);
goto next_char; goto next_char;
} }
else if (c == '\t') else if (c == '\t')
...@@ -706,7 +711,7 @@ parse_string (pfile, token, terminator) ...@@ -706,7 +711,7 @@ parse_string (pfile, token, terminator)
if (pfile->mlstring_pos.line == 0) if (pfile->mlstring_pos.line == 0)
pfile->mlstring_pos = pfile->lexer_pos; pfile->mlstring_pos = pfile->lexer_pos;
c = handle_newline (buffer, c); c = handle_newline (pfile, c);
*dest++ = '\n'; *dest++ = '\n';
goto have_char; goto have_char;
} }
...@@ -866,6 +871,7 @@ _cpp_lex_token (pfile, result) ...@@ -866,6 +871,7 @@ _cpp_lex_token (pfile, result)
buffer->saved_flags = 0; buffer->saved_flags = 0;
next_char: next_char:
pfile->lexer_pos.line = buffer->lineno; pfile->lexer_pos.line = buffer->lineno;
result->line = pfile->line;
next_char2: next_char2:
pfile->lexer_pos.col = CPP_BUF_COLUMN (buffer, buffer->cur); pfile->lexer_pos.col = CPP_BUF_COLUMN (buffer, buffer->cur);
...@@ -875,6 +881,7 @@ _cpp_lex_token (pfile, result) ...@@ -875,6 +881,7 @@ _cpp_lex_token (pfile, result)
c = *buffer->cur++; c = *buffer->cur++;
pfile->lexer_pos.col++; pfile->lexer_pos.col++;
} }
result->col = pfile->lexer_pos.col;
do_switch: do_switch:
buffer->read_ahead = EOF; buffer->read_ahead = EOF;
...@@ -901,7 +908,9 @@ _cpp_lex_token (pfile, result) ...@@ -901,7 +908,9 @@ _cpp_lex_token (pfile, result)
case '\n': case '\r': case '\n': case '\r':
if (!pfile->state.in_directive) if (!pfile->state.in_directive)
{ {
handle_newline (buffer, c); handle_newline (pfile, c);
if (!pfile->state.parsing_args)
pfile->pseudo_newlines = 0;
bol = 1; bol = 1;
pfile->lexer_pos.output_line = buffer->lineno; pfile->lexer_pos.output_line = buffer->lineno;
/* This is a new line, so clear any white space flag. /* This is a new line, so clear any white space flag.
......
...@@ -172,6 +172,8 @@ struct cpp_string ...@@ -172,6 +172,8 @@ struct cpp_string
occupy 12 bytes on 32-bit hosts and 16 bytes on 64-bit hosts. */ occupy 12 bytes on 32-bit hosts and 16 bytes on 64-bit hosts. */
struct cpp_token struct cpp_token
{ {
unsigned int line; /* Logical line of first char of token. */
unsigned short col; /* Column of first char of token. */
ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */ ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */
unsigned char flags; /* flags - see above */ unsigned char flags; /* flags - see above */
......
...@@ -761,7 +761,12 @@ replace_args (pfile, macro, args, list) ...@@ -761,7 +761,12 @@ replace_args (pfile, macro, args, list)
arg = &args[src->val.arg_no - 1]; arg = &args[src->val.arg_no - 1];
if (src->flags & STRINGIFY_ARG) if (src->flags & STRINGIFY_ARG)
from = arg->stringified, count = 1; {
from = arg->stringified, count = 1;
/* Ugh. Maintain position of original argument. */
arg->stringified->line = src->line;
arg->stringified->col = src->col;
}
else if (src->flags & PASTE_LEFT) else if (src->flags & PASTE_LEFT)
count = arg->count, from = arg->first; count = arg->count, from = arg->first;
else if (src > macro->expansion && (src[-1].flags & PASTE_LEFT)) else if (src > macro->expansion && (src[-1].flags & PASTE_LEFT))
...@@ -923,6 +928,7 @@ cpp_get_token (pfile, token) ...@@ -923,6 +928,7 @@ cpp_get_token (pfile, token)
/* PASTE_LEFT tokens can only appear in macro expansions. */ /* PASTE_LEFT tokens can only appear in macro expansions. */
if (token->flags & PASTE_LEFT) if (token->flags & PASTE_LEFT)
{ {
/* Maintains position of original token. */
paste_all_tokens (pfile, token); paste_all_tokens (pfile, token);
pfile->buffer->saved_flags = AVOID_LPASTE; pfile->buffer->saved_flags = AVOID_LPASTE;
} }
...@@ -957,6 +963,7 @@ cpp_get_token (pfile, token) ...@@ -957,6 +963,7 @@ cpp_get_token (pfile, token)
if (node->flags & NODE_BUILTIN) if (node->flags & NODE_BUILTIN)
{ {
/* Maintains position of original token. */
builtin_macro (pfile, token); builtin_macro (pfile, token);
pfile->buffer->saved_flags = AVOID_LPASTE; pfile->buffer->saved_flags = AVOID_LPASTE;
break; break;
......
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