+2000-12-09 Neil Booth <neilb@earthling.net>
+
+ * cppfiles.c (NEVER_REREAD, DO_NOT_REREAD): Move from cpphash.h.
+ * cpphash.h (NEVER_REREAD, DO_NOT_REREAD, ABSOLUTE_PATH): Delete.
+ * cpplex.c (parse_identifier): Improve diagnostic.
+ (_cpp_lex_token): Return unconditionally at the end of a directive.
+ * cpplib.c (read_flag): Verify legality of each flag.
+ (end_directive): Resotre pfile->skipping before skip_rest_of_line.
+ (do_line): Use the new read_flag.
+ * cppmacro.c (struct cpp_macro, parse_arg, replace_args,
+ check_macro_redefinition, parse_params): Rename var_args to
+ variadic.
+
2000-12-09 Joseph S. Myers <jsm28@cam.ac.uk>
* .cvsignore: Add info files.
unsigned char defined; /* cmacro prevents inclusion in this state */
};
+/* The cmacro works like this: If it's NULL, the file is to be
+ included again. If it's NEVER_REREAD, the file is never to be
+ included again. Otherwise it is a macro hashnode, and the file is
+ to be included again if the macro is defined or not as specified by
+ DEFINED. */
+#define NEVER_REREAD ((const cpp_hashnode *)-1)
+#define DO_NOT_REREAD(inc) \
+((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
+ || ((inc)->cmacro->type == NT_MACRO) == (inc)->defined))
+
static struct file_name_map *read_name_map
PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
Only used on MS-DOS and related platforms. */
struct file_name_map *name_map;
};
-#define ABSOLUTE_PATH ((struct file_name_list *)-1)
-
-/* The cmacro works like this: If it's NULL, the file is to be
- included again. If it's NEVER_REREAD, the file is never to be
- included again. Otherwise it is a macro hashnode, and the file is
- to be included again if the macro is defined or not as specified by
- DEFINED. */
-#define NEVER_REREAD ((const cpp_hashnode *)-1)
-#define DO_NOT_REREAD(inc) \
-((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
- || ((inc)->cmacro->type == NT_MACRO) == (inc)->defined))
struct cpp_buffer
{
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_IN_SYSTEM_HEADER(PFILE) \
(CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->sysp)
-#define CPP_PEDANTIC(PF) \
- CPP_OPTION (PF, pedantic)
-#define CPP_WTRADITIONAL(PF) \
- CPP_OPTION (PF, warn_traditional)
+#define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
+#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
/* Hash step. The hash calculation is duplicated in cpp_lookup and
parse_name. */
cpp_error (pfile, "attempt to use poisoned \"%s\"", result->name);
/* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the
- replacement list of a variable-arguments macro. */
+ replacement list of a variadic macro. */
if (result == pfile->spec_nodes.n__VA_ARGS__
&& !pfile->state.va_args_ok)
- cpp_pedwarn (pfile, "__VA_ARGS__ can only appear in the expansion of a C99 variable-argument macro");
+ cpp_pedwarn (pfile, "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro");
}
return result;
buffer->read_ahead = c;
pfile->state.next_bol = 1;
result->type = CPP_EOF;
- break;
+ /* Don't break; pfile->skipping might be true. */
+ return;
case '?':
case '\\':
static int parse_include PARAMS ((cpp_reader *, cpp_token *));
static void push_conditional PARAMS ((cpp_reader *, int, int,
const cpp_hashnode *));
-static unsigned int read_flag PARAMS ((cpp_reader *));
+static unsigned int read_flag PARAMS ((cpp_reader *, 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));
{
cpp_buffer *buffer = pfile->buffer;
+ /* Restore pfile->skipping before skip_rest_of_line, so that e.g.
+ __VA_ARGS__ in the rest of the directive doesn't warn. */
+ pfile->skipping = buffer->was_skipping;
+
/* We don't skip for an assembler #. */
if (skip_line)
skip_rest_of_line (pfile);
- /* Restore pfile->skipping after skip_rest_of_line. Otherwise the
- lexer might not return! */
- pfile->skipping = buffer->was_skipping;
-
/* Restore state. */
pfile->la_write = pfile->la_saved;
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
_cpp_execute_include (pfile, &header, 0, 1);
}
-/* Subroutine of do_line. Read possible flags after file name. If it
- is a number between 1 and 4, return it, otherwise return 0. If
- it's not the end of the directive complain. */
+/* Subroutine of do_line. Read possible flags after file name. LAST
+ is the last flag seen; 0 if this is the first flag. Return the flag
+ if it is valid, 0 at the end of the directive. Otherwise complain. */
static unsigned int
-read_flag (pfile)
+read_flag (pfile, last)
cpp_reader *pfile;
+ unsigned int last;
{
cpp_token token;
_cpp_lex_token (pfile, &token);
if (token.type == CPP_NUMBER && token.val.str.len == 1)
{
- unsigned int flag = token.val.str.text[0] - '1';
- if (flag <= 3)
- return flag + 1;
+ unsigned int flag = token.val.str.text[0] - '0';
+
+ if (flag > last && flag <= 4
+ && (flag != 4 || last == 3)
+ && (flag != 2 || last == 0))
+ return flag;
}
if (token.type != CPP_EOF)
_cpp_simplify_pathname (fname);
buffer->nominal_fname = fname;
- if (pfile->state.line_extension)
+ if (! pfile->state.line_extension)
+ check_eol (pfile);
+ else
{
- int flag, sysp = 0;
+ int flag = 0, sysp = 0;
- flag = read_flag (pfile);
+ flag = read_flag (pfile, flag);
if (flag == 1)
{
reason = FC_ENTER;
- flag = read_flag (pfile);
+ flag = read_flag (pfile, flag);
}
else if (flag == 2)
{
reason = FC_LEAVE;
- flag = read_flag (pfile);
+ flag = read_flag (pfile, flag);
}
if (flag == 3)
{
- flag = read_flag (pfile);
sysp = 1;
+ flag = read_flag (pfile, flag);
+ if (flag == 4)
+ sysp = 2, read_flag (pfile, flag);
}
- cpp_make_system_header (pfile, sysp, flag == 4);
+ cpp_make_system_header (pfile, sysp, sysp == 2);
}
-
- check_eol (pfile);
}
else if (token.type != CPP_EOF)
{
unsigned int count; /* Number of tokens in expansion. */
unsigned short paramc; /* Number of parameters. */
unsigned int fun_like : 1; /* If a function-like macro. */
- unsigned int var_args : 1; /* If a variable-args macro. */
+ unsigned int variadic : 1; /* If a variadic macro. */
unsigned int disabled : 1; /* If macro is disabled. */
};
}
/* Reads the unexpanded tokens of a macro argument into ARG. VAR_ARGS
- is non-zero if this is a variable argument. Returns the type of
- the token that caused reading to finish. */
+ is non-zero if this is a variadic macro. Returns the type of the
+ token that caused reading to finish. */
static enum cpp_ttype
-parse_arg (pfile, arg, var_args)
+parse_arg (pfile, arg, variadic)
cpp_reader *pfile;
struct macro_arg *arg;
- int var_args;
+ int variadic;
{
enum cpp_ttype result;
unsigned int paren = 0;
paren++;
else if (result == CPP_CLOSE_PAREN && paren-- == 0)
break;
- /* Commas are not terminators within parantheses or var_args. */
- else if (result == CPP_COMMA && paren == 0 && !var_args)
+ /* Commas are not terminators within parantheses or variadic. */
+ else if (result == CPP_COMMA && paren == 0 && !variadic)
break;
else if (result == CPP_EOF)
break; /* Error reported by caller. */
{
argc++;
- type = parse_arg (pfile, cur, argc == macro->paramc && macro->var_args);
+ type = parse_arg (pfile, cur, argc == macro->paramc && macro->variadic);
if (type == CPP_CLOSE_PAREN || type == CPP_EOF)
break;
This is exactly the same as if there had been an empty rest
argument - debug("string", ). */
- if (argc + 1 == macro->paramc && macro->var_args)
+ if (argc + 1 == macro->paramc && macro->variadic)
{
if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "ISO C99 requires rest arguments to be used");
given no actual arguments (not merely if b is an
empty argument); otherwise pasting is turned off. */
if (dest[-1].type == CPP_COMMA
- && macro->var_args
+ && macro->variadic
&& src->val.arg_no == macro->paramc)
{
if (count == 0)
if (macro1->count != macro2->count
|| macro1->paramc != macro2->paramc
|| macro1->fun_like != macro2->fun_like
- || macro1->var_args != macro2->var_args)
+ || macro1->variadic != macro2->variadic)
return 0;
/* Check each token. */
continue;
case CPP_ELLIPSIS:
- macro->var_args = 1;
+ macro->variadic = 1;
if (!prev_ident)
{
save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__);
pfile->state.va_args_ok = 1;
if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic))
cpp_pedwarn (pfile,
- "anonymous variable arguments were introduced in C99");
+ "anonymous variadic macros were introduced in C99");
}
else if (CPP_OPTION (pfile, pedantic))
- cpp_pedwarn (pfile,
- "ISO C does not permit named variable arguments");
+ cpp_pedwarn (pfile, "ISO C does not permit named variadic macros");
/* We're at the end, and just expect a closing parenthesis. */
_cpp_lex_token (pfile, &token);
macro->params = 0;
macro->paramc = 0;
macro->fun_like = 0;
- macro->var_args = 0;
+ macro->variadic = 0;
macro->count = 0;
macro->expansion = (cpp_token *) POOL_FRONT (&pfile->macro_pool);
if (i + 1 < macro->paramc)
*buffer++ = ',', *buffer++ = ' ';
- else if (macro->var_args)
+ else if (macro->variadic)
*buffer++ = '.', *buffer++ = '.', *buffer++ = '.';
}
*buffer++ = ')';