aboutsummaryrefslogtreecommitdiff
path: root/gcc/cpplib.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r--gcc/cpplib.c139
1 files changed, 75 insertions, 64 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 47dd977f3..52c3940 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -107,7 +107,7 @@ static U_CHAR *dequote_string PARAMS ((cpp_reader *, const U_CHAR *,
unsigned int));
static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int,
unsigned long *));
-static void do_diagnostic PARAMS ((cpp_reader *, enum error_type, int));
+static void do_diagnostic PARAMS ((cpp_reader *, int, int));
static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *));
static void do_include_common PARAMS ((cpp_reader *, enum include_type));
static struct pragma_entry *lookup_pragma_entry
@@ -225,8 +225,8 @@ check_eol (pfile)
cpp_reader *pfile;
{
if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF)
- cpp_pedwarn (pfile, "extra tokens at end of #%s directive",
- pfile->directive->name);
+ cpp_error (pfile, DL_PEDWARN, "extra tokens at end of #%s directive",
+ pfile->directive->name);
}
/* Called when entering a directive, _Pragma or command-line directive. */
@@ -278,7 +278,7 @@ directive_diagnostics (pfile, dir, indented)
if (CPP_PEDANTIC (pfile)
&& ! pfile->state.skipping
&& dir->origin == EXTENSION)
- cpp_pedwarn (pfile, "#%s is a GCC extension", dir->name);
+ cpp_error (pfile, DL_PEDWARN, "#%s is a GCC extension", dir->name);
/* Traditionally, a directive is ignored unless its # is in
column 1. Therefore in code intended to work with K+R
@@ -289,15 +289,16 @@ directive_diagnostics (pfile, dir, indented)
if (CPP_WTRADITIONAL (pfile))
{
if (dir == &dtable[T_ELIF])
- cpp_warning (pfile, "suggest not using #elif in traditional C");
+ cpp_error (pfile, DL_WARNING,
+ "suggest not using #elif in traditional C");
else if (indented && dir->origin == KANDR)
- cpp_warning (pfile,
- "traditional C ignores #%s with the # indented",
- dir->name);
+ cpp_error (pfile, DL_WARNING,
+ "traditional C ignores #%s with the # indented",
+ dir->name);
else if (!indented && dir->origin != KANDR)
- cpp_warning (pfile,
- "suggest hiding #%s from traditional C with an indented #",
- dir->name);
+ cpp_error (pfile, DL_WARNING,
+ "suggest hiding #%s from traditional C with an indented #",
+ dir->name);
}
}
@@ -319,7 +320,7 @@ _cpp_handle_directive (pfile, indented)
if (was_parsing_args)
{
if (CPP_OPTION (pfile, pedantic))
- cpp_pedwarn (pfile,
+ cpp_error (pfile, DL_PEDWARN,
"embedding a directive within macro arguments is not portable");
pfile->state.parsing_args = 0;
pfile->state.prevent_expansion = 0;
@@ -339,7 +340,8 @@ _cpp_handle_directive (pfile, indented)
dir = &linemarker_dir;
if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed)
&& ! pfile->state.skipping)
- cpp_pedwarn (pfile, "style of line directive is a GCC extension");
+ cpp_error (pfile, DL_PEDWARN,
+ "style of line directive is a GCC extension");
}
if (dir)
@@ -388,7 +390,7 @@ _cpp_handle_directive (pfile, indented)
if (CPP_OPTION (pfile, lang) == CLK_ASM)
skip = 0;
else if (!pfile->state.skipping)
- cpp_error (pfile, "invalid preprocessing directive #%s",
+ cpp_error (pfile, DL_ERROR, "invalid preprocessing directive #%s",
cpp_token_as_text (pfile, dname));
}
@@ -466,14 +468,14 @@ lex_macro_node (pfile)
if (token->type != CPP_NAME)
{
if (token->type == CPP_EOF)
- cpp_error (pfile, "no macro name given in #%s directive",
+ cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive",
pfile->directive->name);
else if (token->flags & NAMED_OP)
- cpp_error (pfile,
+ cpp_error (pfile, DL_ERROR,
"\"%s\" cannot be used as a macro name as it is an operator in C++",
NODE_NAME (token->val.node));
else
- cpp_error (pfile, "macro names must be identifiers");
+ cpp_error (pfile, DL_ERROR, "macro names must be identifiers");
return 0;
}
@@ -484,7 +486,7 @@ lex_macro_node (pfile)
if (node == pfile->spec_nodes.n_defined)
{
- cpp_error (pfile, "\"%s\" cannot be used as a macro name",
+ cpp_error (pfile, DL_ERROR, "\"%s\" cannot be used as a macro name",
NODE_NAME (node));
return 0;
}
@@ -522,7 +524,7 @@ do_undef (pfile)
(*pfile->cb.undef) (pfile, pfile->directive_line, node);
if (node->flags & NODE_WARN)
- cpp_warning (pfile, "undefining \"%s\"", NODE_NAME (node));
+ cpp_error (pfile, DL_WARNING, "undefining \"%s\"", NODE_NAME (node));
_cpp_free_definition (node);
}
@@ -565,7 +567,7 @@ glue_header_name (pfile)
}
if (token->type == CPP_EOF)
- cpp_error (pfile, "missing terminating > character");
+ cpp_error (pfile, DL_ERROR, "missing terminating > character");
else
{
unsigned char *token_mem = _cpp_unaligned_alloc (pfile, total_len + 1);
@@ -603,7 +605,8 @@ parse_include (pfile)
{
if (header->type != CPP_LESS)
{
- cpp_error (pfile, "#%s expects \"FILENAME\" or <FILENAME>", dir);
+ cpp_error (pfile, DL_ERROR,
+ "#%s expects \"FILENAME\" or <FILENAME>", dir);
return NULL;
}
@@ -614,7 +617,7 @@ parse_include (pfile)
if (header->val.str.len == 0)
{
- cpp_error (pfile, "empty file name in #%s", dir);
+ cpp_error (pfile, DL_ERROR, "empty file name in #%s", dir);
return NULL;
}
@@ -633,13 +636,13 @@ do_include_common (pfile, type)
use the normal search logic. */
if (type == IT_INCLUDE_NEXT && ! pfile->buffer->prev)
{
- cpp_warning (pfile, "#include_next in primary source file");
+ cpp_error (pfile, DL_WARNING, "#include_next in primary source file");
type = IT_INCLUDE;
}
else if (type == IT_IMPORT && CPP_OPTION (pfile, warn_import))
{
CPP_OPTION (pfile, warn_import) = 0;
- cpp_warning (pfile,
+ cpp_error (pfile, DL_WARNING,
"#import is obsolete, use an #ifndef wrapper in the header file");
}
@@ -648,7 +651,7 @@ do_include_common (pfile, type)
{
/* Prevent #include recursion. */
if (pfile->line_maps.depth >= CPP_STACK_MAX)
- cpp_fatal (pfile, "#include nested too deeply");
+ cpp_error (pfile, DL_FATAL, "#include nested too deeply");
else
{
check_eol (pfile);
@@ -706,7 +709,7 @@ read_flag (pfile, last)
}
if (token->type != CPP_EOF)
- cpp_error (pfile, "invalid flag \"%s\" in line directive",
+ cpp_error (pfile, DL_ERROR, "invalid flag \"%s\" in line directive",
cpp_token_as_text (pfile, token));
return 0;
}
@@ -788,13 +791,14 @@ do_line (pfile)
|| strtoul_for_line (token->val.str.text, token->val.str.len,
&new_lineno))
{
- cpp_error (pfile, "\"%s\" after #line is not a positive integer",
+ cpp_error (pfile, DL_ERROR,
+ "\"%s\" after #line is not a positive integer",
cpp_token_as_text (pfile, token));
return;
}
if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
- cpp_pedwarn (pfile, "line number out of range");
+ cpp_error (pfile, DL_PEDWARN, "line number out of range");
token = cpp_get_token (pfile);
if (token->type == CPP_STRING)
@@ -805,7 +809,7 @@ do_line (pfile)
}
else if (token->type != CPP_EOF)
{
- cpp_error (pfile, "\"%s\" is not a valid filename",
+ cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename",
cpp_token_as_text (pfile, token));
return;
}
@@ -840,7 +844,7 @@ do_linemarker (pfile)
|| strtoul_for_line (token->val.str.text, token->val.str.len,
&new_lineno))
{
- cpp_error (pfile, "\"%s\" after # is not a positive integer",
+ cpp_error (pfile, DL_ERROR, "\"%s\" after # is not a positive integer",
cpp_token_as_text (pfile, token));
return;
}
@@ -876,7 +880,7 @@ do_linemarker (pfile)
}
else if (token->type != CPP_EOF)
{
- cpp_error (pfile, "\"%s\" is not a valid filename",
+ cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename",
cpp_token_as_text (pfile, token));
return;
}
@@ -909,10 +913,12 @@ _cpp_do_file_change (pfile, reason, to_file, file_line, sysp)
static void
do_diagnostic (pfile, code, print_dir)
cpp_reader *pfile;
- enum error_type code;
+ int code;
int print_dir;
{
- if (_cpp_begin_message (pfile, code, 0, 0))
+ if (_cpp_begin_message (pfile, code,
+ pfile->cur_token[-1].line,
+ pfile->cur_token[-1].col))
{
if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name);
@@ -926,7 +932,7 @@ static void
do_error (pfile)
cpp_reader *pfile;
{
- do_diagnostic (pfile, ERROR, 1);
+ do_diagnostic (pfile, DL_ERROR, 1);
}
static void
@@ -934,7 +940,7 @@ do_warning (pfile)
cpp_reader *pfile;
{
/* We want #warning diagnostics to be emitted in system headers too. */
- do_diagnostic (pfile, WARNING_SYSHDR, 1);
+ do_diagnostic (pfile, DL_WARNING_SYSHDR, 1);
}
/* Report program identification. */
@@ -945,7 +951,7 @@ do_ident (pfile)
const cpp_token *str = cpp_get_token (pfile);
if (str->type != CPP_STRING)
- cpp_error (pfile, "invalid #ident directive");
+ cpp_error (pfile, DL_ERROR, "invalid #ident directive");
else if (pfile->cb.ident)
(*pfile->cb.ident) (pfile, pfile->directive_line, &str->val.str);
@@ -1032,13 +1038,14 @@ cpp_register_pragma (pfile, space, name, handler)
{
if (entry->is_nspace)
clash:
- cpp_ice (pfile,
+ cpp_error (pfile, DL_ICE,
"registering \"%s\" as both a pragma and a pragma namespace",
NODE_NAME (node));
else if (space)
- cpp_ice (pfile, "#pragma %s %s is already registered", space, name);
+ cpp_error (pfile, DL_ICE, "#pragma %s %s is already registered",
+ space, name);
else
- cpp_ice (pfile, "#pragma %s is already registered", name);
+ cpp_error (pfile, DL_ICE, "#pragma %s is already registered", name);
}
else
insert_pragma_entry (pfile, chain, node, handler);
@@ -1113,10 +1120,10 @@ static void
do_pragma_once (pfile)
cpp_reader *pfile;
{
- cpp_warning (pfile, "#pragma once is obsolete");
+ cpp_error (pfile, DL_WARNING, "#pragma once is obsolete");
if (pfile->buffer->prev == NULL)
- cpp_warning (pfile, "#pragma once in main file");
+ cpp_error (pfile, DL_WARNING, "#pragma once in main file");
else
_cpp_never_reread (pfile->buffer->inc);
@@ -1140,7 +1147,7 @@ do_pragma_poison (pfile)
break;
if (tok->type != CPP_NAME)
{
- cpp_error (pfile, "invalid #pragma GCC poison directive");
+ cpp_error (pfile, DL_ERROR, "invalid #pragma GCC poison directive");
break;
}
@@ -1149,7 +1156,8 @@ do_pragma_poison (pfile)
continue;
if (hp->type == NT_MACRO)
- cpp_warning (pfile, "poisoning existing macro \"%s\"", NODE_NAME (hp));
+ cpp_error (pfile, DL_WARNING, "poisoning existing macro \"%s\"",
+ NODE_NAME (hp));
_cpp_free_definition (hp);
hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC;
}
@@ -1169,7 +1177,8 @@ do_pragma_system_header (pfile)
cpp_buffer *buffer = pfile->buffer;
if (buffer->prev == 0)
- cpp_warning (pfile, "#pragma system_header ignored outside include file");
+ cpp_error (pfile, DL_WARNING,
+ "#pragma system_header ignored outside include file");
else
{
check_eol (pfile);
@@ -1194,16 +1203,16 @@ do_pragma_dependency (pfile)
ordering = _cpp_compare_file_date (pfile, header);
if (ordering < 0)
- cpp_warning (pfile, "cannot find source %s",
- cpp_token_as_text (pfile, header));
+ cpp_error (pfile, DL_WARNING, "cannot find source %s",
+ cpp_token_as_text (pfile, header));
else if (ordering > 0)
{
- cpp_warning (pfile, "current file is older than %s",
- cpp_token_as_text (pfile, header));
+ cpp_error (pfile, DL_WARNING, "current file is older than %s",
+ cpp_token_as_text (pfile, header));
if (cpp_get_token (pfile)->type != CPP_EOF)
{
_cpp_backup_tokens (pfile, 1);
- do_diagnostic (pfile, WARNING, 0);
+ do_diagnostic (pfile, DL_WARNING, 0);
}
}
}
@@ -1273,7 +1282,8 @@ _cpp_do__Pragma (pfile)
const cpp_token *string = get__Pragma_string (pfile);
if (!string)
- cpp_error (pfile, "_Pragma takes a parenthesized string literal");
+ cpp_error (pfile, DL_ERROR,
+ "_Pragma takes a parenthesized string literal");
else
{
/* Ideally, we'd like
@@ -1372,13 +1382,13 @@ do_else (pfile)
struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL)
- cpp_error (pfile, "#else without #if");
+ cpp_error (pfile, DL_ERROR, "#else without #if");
else
{
if (ifs->type == T_ELSE)
{
- cpp_error (pfile, "#else after #else");
- cpp_error_with_line (pfile, ifs->line, 0,
+ cpp_error (pfile, DL_ERROR, "#else after #else");
+ cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"the conditional began here");
}
ifs->type = T_ELSE;
@@ -1406,13 +1416,13 @@ do_elif (pfile)
struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL)
- cpp_error (pfile, "#elif without #if");
+ cpp_error (pfile, DL_ERROR, "#elif without #if");
else
{
if (ifs->type == T_ELSE)
{
- cpp_error (pfile, "#elif after #else");
- cpp_error_with_line (pfile, ifs->line, 0,
+ cpp_error (pfile, DL_ERROR, "#elif after #else");
+ cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"the conditional began here");
}
ifs->type = T_ELIF;
@@ -1442,7 +1452,7 @@ do_endif (pfile)
struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL)
- cpp_error (pfile, "#endif without #if");
+ cpp_error (pfile, DL_ERROR, "#endif without #if");
else
{
/* Only check EOL if was not originally skipping. */
@@ -1525,7 +1535,7 @@ parse_answer (pfile, answerp, type)
if (type == T_UNASSERT && paren->type == CPP_EOF)
return 0;
- cpp_error (pfile, "missing '(' after predicate");
+ cpp_error (pfile, DL_ERROR, "missing '(' after predicate");
return 1;
}
@@ -1540,7 +1550,7 @@ parse_answer (pfile, answerp, type)
if (token->type == CPP_EOF)
{
- cpp_error (pfile, "missing ')' to complete answer");
+ cpp_error (pfile, DL_ERROR, "missing ')' to complete answer");
return 1;
}
@@ -1560,7 +1570,7 @@ parse_answer (pfile, answerp, type)
if (acount == 0)
{
- cpp_error (pfile, "predicate's answer is empty");
+ cpp_error (pfile, DL_ERROR, "predicate's answer is empty");
return 1;
}
@@ -1590,9 +1600,9 @@ parse_assertion (pfile, answerp, type)
*answerp = 0;
predicate = cpp_get_token (pfile);
if (predicate->type == CPP_EOF)
- cpp_error (pfile, "assertion without predicate");
+ cpp_error (pfile, DL_ERROR, "assertion without predicate");
else if (predicate->type != CPP_NAME)
- cpp_error (pfile, "predicate must be an identifier");
+ cpp_error (pfile, DL_ERROR, "predicate must be an identifier");
else if (parse_answer (pfile, answerp, type) == 0)
{
unsigned int len = NODE_LEN (predicate->val.node);
@@ -1674,7 +1684,8 @@ do_assert (pfile)
{
if (*find_answer (node, new_answer))
{
- cpp_warning (pfile, "\"%s\" re-asserted", NODE_NAME (node) + 1);
+ cpp_error (pfile, DL_WARNING, "\"%s\" re-asserted",
+ NODE_NAME (node) + 1);
return;
}
new_answer->next = node->value.answers;
@@ -1903,7 +1914,7 @@ _cpp_pop_buffer (pfile)
/* Walk back up the conditional stack till we reach its level at
entry to this file, issuing error messages. */
for (ifs = buffer->if_stack; ifs; ifs = ifs->next)
- cpp_error_with_line (pfile, ifs->line, 0,
+ cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0,
"unterminated #%s", dtable[ifs->type].name);
/* In case of a missing #endif. */