Commit 50410426 by Neil Booth Committed by Neil Booth

cpphash.h (struct cpp_reader): Remove lexer_pos, directive_pos.

	* cpphash.h (struct cpp_reader): Remove lexer_pos, directive_pos.
	Split mlstring_pos into mls_line and mls_col.
	* cppinit.c (cpp_create_reader): Initialize line to 1.
	(cpp_destroy): Free tokenruns.
	(push_include): Don't update lexer_pos.
	* cpplex.c (unterminated, parse_string): Update.
	(lex_token): Don't update lexer_pos, update.
	* cpplib.c (if_stack): Save line instead of line + col.
	(start_directive, _cpp_do__Pragma, do_else, do_elif,
	push_conditional, _cpp_pop_buffer): Update.
	* cppmacro.c (funlike_invocation_p): Don't save lexer_pos.
	(_cpp_create_definition): Update.

From-SVN: r45627
parent 6131fd23
2001-09-15 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (struct cpp_reader): Remove lexer_pos, directive_pos.
Split mlstring_pos into mls_line and mls_col.
* cppinit.c (cpp_create_reader): Initialize line to 1.
(cpp_destroy): Free tokenruns.
(push_include): Don't update lexer_pos.
* cpplex.c (unterminated, parse_string): Update.
(lex_token): Don't update lexer_pos, update.
* cpplib.c (if_stack): Save line instead of line + col.
(start_directive, _cpp_do__Pragma, do_else, do_elif,
push_conditional, _cpp_pop_buffer): Update.
* cppmacro.c (funlike_invocation_p): Don't save lexer_pos.
(_cpp_create_definition): Update.
2001-09-15 Eric Christopher <echristo@redhat.com> 2001-09-15 Eric Christopher <echristo@redhat.com>
* config/mips/abi64.h: Add support for MEABI. * config/mips/abi64.h: Add support for MEABI.
......
...@@ -242,9 +242,7 @@ struct cpp_reader ...@@ -242,9 +242,7 @@ struct cpp_reader
const struct line_map *map; const struct line_map *map;
unsigned int line; unsigned int line;
/* The position of the last lexed token and last lexed directive. */ /* The line of the '#' of the current directive. */
cpp_lexer_pos lexer_pos;
cpp_lexer_pos directive_pos;
unsigned int directive_line; unsigned int directive_line;
/* Memory pools. */ /* Memory pools. */
...@@ -278,7 +276,8 @@ struct cpp_reader ...@@ -278,7 +276,8 @@ struct cpp_reader
/* Line and column where a newline was first seen in a string /* Line and column where a newline was first seen in a string
constant (multi-line strings). */ constant (multi-line strings). */
cpp_lexer_pos mlstring_pos; unsigned int mls_line;
unsigned int mls_col;
/* Buffer to hold macro definition string. */ /* Buffer to hold macro definition string. */
unsigned char *macro_buffer; unsigned char *macro_buffer;
......
...@@ -502,8 +502,10 @@ cpp_create_reader (table, lang) ...@@ -502,8 +502,10 @@ cpp_create_reader (table, lang)
be needed. */ be needed. */
pfile->deps = deps_init (); pfile->deps = deps_init ();
/* Initialise the line map. */ /* Initialise the line map. Start at logical line 1, so we can use
a line number of zero for special states. */
init_line_maps (&pfile->line_maps); init_line_maps (&pfile->line_maps);
pfile->line = 1;
/* Initialize lexer state. */ /* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
...@@ -564,6 +566,7 @@ cpp_destroy (pfile) ...@@ -564,6 +566,7 @@ cpp_destroy (pfile)
int result; int result;
struct search_path *dir, *dirn; struct search_path *dir, *dirn;
cpp_context *context, *contextn; cpp_context *context, *contextn;
tokenrun *run, *runn;
while (CPP_BUFFER (pfile) != NULL) while (CPP_BUFFER (pfile) != NULL)
_cpp_pop_buffer (pfile); _cpp_pop_buffer (pfile);
...@@ -585,6 +588,14 @@ cpp_destroy (pfile) ...@@ -585,6 +588,14 @@ cpp_destroy (pfile)
_cpp_free_pool (&pfile->macro_pool); _cpp_free_pool (&pfile->macro_pool);
_cpp_free_pool (&pfile->argument_pool); _cpp_free_pool (&pfile->argument_pool);
for (run = &pfile->base_run; run; run = runn)
{
runn = run->next;
free (run->base);
if (run != &pfile->base_run)
free (run);
}
for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn) for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
{ {
dirn = dir->next; dirn = dir->next;
...@@ -886,7 +897,7 @@ push_include (pfile, p) ...@@ -886,7 +897,7 @@ push_include (pfile, p)
header.val.str.text = (const unsigned char *) p->arg; header.val.str.text = (const unsigned char *) p->arg;
header.val.str.len = strlen (p->arg); header.val.str.len = strlen (p->arg);
/* Make the command line directive take up a line. */ /* Make the command line directive take up a line. */
pfile->lexer_pos.line = ++pfile->line; pfile->line++;
return _cpp_execute_include (pfile, &header, IT_CMDLINE); return _cpp_execute_include (pfile, &header, IT_CMDLINE);
} }
......
...@@ -656,13 +656,11 @@ unterminated (pfile, term) ...@@ -656,13 +656,11 @@ unterminated (pfile, term)
{ {
cpp_error (pfile, "missing terminating %c character", term); cpp_error (pfile, "missing terminating %c character", term);
if (term == '\"' && pfile->mlstring_pos.line if (term == '\"' && pfile->mls_line && pfile->mls_line != pfile->line)
&& pfile->mlstring_pos.line != pfile->lexer_pos.line)
{ {
cpp_error_with_line (pfile, pfile->mlstring_pos.line, cpp_error_with_line (pfile, pfile->mls_line, pfile->mls_col,
pfile->mlstring_pos.col,
"possible start of unterminated string literal"); "possible start of unterminated string literal");
pfile->mlstring_pos.line = 0; pfile->mls_line = 0;
} }
} }
...@@ -760,8 +758,11 @@ parse_string (pfile, token, terminator) ...@@ -760,8 +758,11 @@ parse_string (pfile, token, terminator)
cpp_pedwarn (pfile, "multi-line string literals are deprecated"); cpp_pedwarn (pfile, "multi-line string literals are deprecated");
} }
if (pfile->mlstring_pos.line == 0) if (pfile->mls_line == 0)
pfile->mlstring_pos = pfile->lexer_pos; {
pfile->mls_line = token->line;
pfile->mls_col = token->col;
}
c = handle_newline (pfile, c); c = handle_newline (pfile, c);
*dest++ = '\n'; *dest++ = '\n';
...@@ -998,7 +999,6 @@ lex_token (pfile, result) ...@@ -998,7 +999,6 @@ lex_token (pfile, result)
result->flags = buffer->saved_flags; result->flags = buffer->saved_flags;
buffer->saved_flags = 0; buffer->saved_flags = 0;
update_tokens_line: update_tokens_line:
pfile->lexer_pos.line = pfile->line;
result->line = pfile->line; result->line = pfile->line;
skipped_white: skipped_white:
...@@ -1006,7 +1006,6 @@ lex_token (pfile, result) ...@@ -1006,7 +1006,6 @@ lex_token (pfile, result)
if (c == EOF && buffer->cur < buffer->rlimit) if (c == EOF && buffer->cur < buffer->rlimit)
c = *buffer->cur++; c = *buffer->cur++;
result->col = CPP_BUF_COLUMN (buffer, buffer->cur); result->col = CPP_BUF_COLUMN (buffer, buffer->cur);
pfile->lexer_pos.col = result->col;
buffer->read_ahead = EOF; buffer->read_ahead = EOF;
trigraph: trigraph:
...@@ -1171,9 +1170,7 @@ lex_token (pfile, result) ...@@ -1171,9 +1170,7 @@ lex_token (pfile, result)
/* Skip_line_comment updates buffer->read_ahead. */ /* Skip_line_comment updates buffer->read_ahead. */
if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments)) if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
cpp_warning_with_line (pfile, pfile->lexer_pos.line, cpp_warning (pfile, "multi-line comment");
pfile->lexer_pos.col,
"multi-line comment");
} }
/* Skipping the comment has updated buffer->read_ahead. */ /* Skipping the comment has updated buffer->read_ahead. */
......
...@@ -40,7 +40,7 @@ struct answer ...@@ -40,7 +40,7 @@ struct answer
struct if_stack struct if_stack
{ {
struct if_stack *next; struct if_stack *next;
cpp_lexer_pos pos; /* line and column where condition started */ unsigned int line; /* Line where condition started. */
const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */ const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */
bool skip_elses; /* Can future #else / #elif be skipped? */ bool skip_elses; /* Can future #else / #elif be skipped? */
bool was_skipping; /* If were skipping on entry. */ bool was_skipping; /* If were skipping on entry. */
...@@ -220,8 +220,6 @@ start_directive (pfile) ...@@ -220,8 +220,6 @@ start_directive (pfile)
pfile->state.save_comments = 0; pfile->state.save_comments = 0;
/* Some handlers need the position of the # for diagnostics. */ /* Some handlers need the position of the # for diagnostics. */
pfile->directive_pos = pfile->lexer_pos;
pfile->directive_pos.line = pfile->line;
pfile->directive_line = pfile->line; pfile->directive_line = pfile->line;
} }
...@@ -1154,18 +1152,27 @@ _cpp_do__Pragma (pfile) ...@@ -1154,18 +1152,27 @@ _cpp_do__Pragma (pfile)
cpp_token string; cpp_token string;
unsigned char *buffer; unsigned char *buffer;
unsigned int len; unsigned int len;
cpp_lexer_pos orig_pos;
orig_pos = pfile->lexer_pos;
if (get__Pragma_string (pfile, &string)) if (get__Pragma_string (pfile, &string))
cpp_error (pfile, "_Pragma takes a parenthesized string literal"); cpp_error (pfile, "_Pragma takes a parenthesized string literal");
else else
{ {
/* Ideally, we'd like
token1 _Pragma ("foo") token2
to be output as
token1
# 7 "file.c"
#pragma foo
# 7 "file.c"
token2
Getting these correct line markers is a little tricky. */
unsigned int orig_line = pfile->line;
buffer = destringize (&string.val.str, &len); buffer = destringize (&string.val.str, &len);
run_directive (pfile, T_PRAGMA, (char *) buffer, len); run_directive (pfile, T_PRAGMA, (char *) buffer, len);
free ((PTR) buffer); free ((PTR) buffer);
pfile->lexer_pos = orig_pos; pfile->line = orig_line;
pfile->line = pfile->lexer_pos.line; pfile->buffer->saved_flags = BOL;
} }
} }
...@@ -1254,7 +1261,7 @@ do_else (pfile) ...@@ -1254,7 +1261,7 @@ do_else (pfile)
if (ifs->type == T_ELSE) if (ifs->type == T_ELSE)
{ {
cpp_error (pfile, "#else after #else"); cpp_error (pfile, "#else after #else");
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, cpp_error_with_line (pfile, ifs->line, 0,
"the conditional began here"); "the conditional began here");
} }
ifs->type = T_ELSE; ifs->type = T_ELSE;
...@@ -1289,7 +1296,7 @@ do_elif (pfile) ...@@ -1289,7 +1296,7 @@ do_elif (pfile)
if (ifs->type == T_ELSE) if (ifs->type == T_ELSE)
{ {
cpp_error (pfile, "#elif after #else"); cpp_error (pfile, "#elif after #else");
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, cpp_error_with_line (pfile, ifs->line, 0,
"the conditional began here"); "the conditional began here");
} }
ifs->type = T_ELIF; ifs->type = T_ELIF;
...@@ -1355,7 +1362,7 @@ push_conditional (pfile, skip, type, cmacro) ...@@ -1355,7 +1362,7 @@ push_conditional (pfile, skip, type, cmacro)
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
ifs = xobnew (&pfile->buffer_ob, struct if_stack); ifs = xobnew (&pfile->buffer_ob, struct if_stack);
ifs->pos = pfile->directive_pos; ifs->line = pfile->directive_line;
ifs->next = buffer->if_stack; ifs->next = buffer->if_stack;
ifs->skip_elses = pfile->state.skipping || !skip; ifs->skip_elses = pfile->state.skipping || !skip;
ifs->was_skipping = pfile->state.skipping; ifs->was_skipping = pfile->state.skipping;
...@@ -1778,7 +1785,7 @@ _cpp_pop_buffer (pfile) ...@@ -1778,7 +1785,7 @@ _cpp_pop_buffer (pfile)
/* Walk back up the conditional stack till we reach its level at /* Walk back up the conditional stack till we reach its level at
entry to this file, issuing error messages. */ entry to this file, issuing error messages. */
for (ifs = buffer->if_stack; ifs; ifs = ifs->next) for (ifs = buffer->if_stack; ifs; ifs = ifs->next)
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, cpp_error_with_line (pfile, ifs->line, 0,
"unterminated #%s", dtable[ifs->type].name); "unterminated #%s", dtable[ifs->type].name);
/* In case of a missing #endif. */ /* In case of a missing #endif. */
......
...@@ -605,9 +605,7 @@ funlike_invocation_p (pfile, node, list) ...@@ -605,9 +605,7 @@ funlike_invocation_p (pfile, node, list)
{ {
cpp_token maybe_paren; cpp_token maybe_paren;
macro_arg *args = 0; macro_arg *args = 0;
cpp_lexer_pos macro_pos;
macro_pos = pfile->lexer_pos;
pfile->state.parsing_args = 1; pfile->state.parsing_args = 1;
pfile->state.prevent_expansion++; pfile->state.prevent_expansion++;
...@@ -630,10 +628,6 @@ funlike_invocation_p (pfile, node, list) ...@@ -630,10 +628,6 @@ funlike_invocation_p (pfile, node, list)
pfile->state.parsing_args = 0; pfile->state.parsing_args = 0;
pfile->keep_tokens--; pfile->keep_tokens--;
/* Reset the position in case of failure. If success, the macro's
expansion appears where the name would have. */
pfile->lexer_pos = macro_pos;
if (args) if (args)
{ {
if (node->value.macro->paramc > 0) if (node->value.macro->paramc > 0)
...@@ -1247,7 +1241,7 @@ _cpp_create_definition (pfile, node) ...@@ -1247,7 +1241,7 @@ _cpp_create_definition (pfile, node)
macro = (cpp_macro *) _cpp_pool_alloc (&pfile->macro_pool, macro = (cpp_macro *) _cpp_pool_alloc (&pfile->macro_pool,
sizeof (cpp_macro)); sizeof (cpp_macro));
macro->line = pfile->directive_pos.line; macro->line = pfile->directive_line;
macro->params = 0; macro->params = 0;
macro->paramc = 0; macro->paramc = 0;
macro->fun_like = 0; macro->fun_like = 0;
...@@ -1345,8 +1339,7 @@ _cpp_create_definition (pfile, node) ...@@ -1345,8 +1339,7 @@ _cpp_create_definition (pfile, node)
{ {
if (warn_of_redefinition (pfile, node, macro)) if (warn_of_redefinition (pfile, node, macro))
{ {
cpp_pedwarn_with_line (pfile, pfile->directive_pos.line, cpp_pedwarn_with_line (pfile, pfile->directive_line, 0,
pfile->directive_pos.col,
"\"%s\" redefined", NODE_NAME (node)); "\"%s\" redefined", NODE_NAME (node));
if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
......
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