static void expand_name_space PARAMS ((cpp_toklist *));
static void expand_token_space PARAMS ((cpp_toklist *));
static void init_token_list PARAMS ((cpp_reader *, cpp_toklist *, int));
+static void pedantic_whitespace PARAMS ((cpp_reader *, U_CHAR *,
+ unsigned int));
/* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
list->namebuf = (unsigned char *) xmalloc (list->name_cap);
}
- list->line = pfile->buffer->lineno;
+ if (pfile->buffer)
+ list->line = pfile->buffer->lineno;
list->dir_handler = 0;
list->dir_flags = 0;
}
int i, col;
long written, len;
enum cpp_ttype type;
+ int space_before;
init_token_list (pfile, list, 1);
written = CPP_WRITTEN (pfile);
i = 0;
+ space_before = 0;
for (;;)
{
col = CPP_BUFFER (pfile)->cur - CPP_BUFFER (pfile)->line_base;
len = CPP_WRITTEN (pfile) - written;
CPP_SET_WRITTEN (pfile, written);
if (type == CPP_HSPACE)
- continue;
+ {
+ if (CPP_PEDANTIC (pfile))
+ pedantic_whitespace (pfile, pfile->token_buffer + written, len);
+ space_before = 1;
+ continue;
+ }
if (list->tokens_used >= list->tokens_cap)
expand_token_space (list);
if (list->name_used + len >= list->name_cap)
expand_name_space (list);
+ if (type == CPP_MACRO)
+ type = CPP_NAME;
+
list->tokens_used++;
list->tokens[i].type = type;
list->tokens[i].col = col;
-
+ list->tokens[i].flags = space_before ? HSPACE_BEFORE : 0;
+
if (type == CPP_VSPACE)
break;
memcpy (list->namebuf + list->name_used, CPP_PWRITTEN (pfile), len);
list->name_used += len;
i++;
+ space_before = 0;
}
list->tokens[i].aux = CPP_BUFFER (pfile)->lineno + 1;
+
+ /* XXX Temporary kluge: put back the newline. */
+ FORWARD(-1);
}
For -traditional, a comment is equivalent to nothing. */
if (!CPP_OPTION (pfile, discard_comments))
return CPP_COMMENT;
- else if (CPP_TRADITIONAL (pfile)
- && ! is_space (PEEKC ()))
- {
- if (pfile->parsing_define_directive)
- return CPP_COMMENT;
- else
- goto get_next;
- }
+ else if (CPP_TRADITIONAL (pfile))
+ goto get_next;
else
{
CPP_PUTC (pfile, c);
return CPP_OTHER;
}
- if (pfile->parsing_define_directive && ! CPP_TRADITIONAL (pfile))
+ if (pfile->parsing_define_directive)
{
c2 = PEEKC ();
if (c2 == '#')
return 1;
}
+/* Complain about \v or \f in a preprocessing directive (constraint
+ violation, C99 6.10 para 5). Caller has checked CPP_PEDANTIC. */
+static void
+pedantic_whitespace (pfile, p, len)
+ cpp_reader *pfile;
+ U_CHAR *p;
+ unsigned int len;
+{
+ while (len)
+ {
+ if (*p == '\v')
+ cpp_pedwarn (pfile, "vertical tab in preprocessing directive");
+ else if (*p == '\f')
+ cpp_pedwarn (pfile, "form feed in preprocessing directive");
+ p++;
+ len--;
+ }
+}
+
+
enum cpp_ttype
cpp_get_token (pfile)
cpp_reader *pfile;
}
/* Like cpp_get_token, except that it does not execute directives,
- does not consume vertical space, and automatically pops off macro
- buffers.
-
- XXX This function will exist only till collect_expansion doesn't
- need to see whitespace anymore, then it'll be merged with
- _cpp_get_directive_token (below). */
+ does not consume vertical space, discards horizontal space, and
+ automatically pops off macro buffers. */
enum cpp_ttype
-_cpp_get_define_token (pfile)
+_cpp_get_directive_token (pfile)
cpp_reader *pfile;
{
long old_written;
case CPP_HSPACE:
if (CPP_PEDANTIC (pfile))
- {
- U_CHAR *p, *limit;
- p = pfile->token_buffer + old_written;
- limit = CPP_PWRITTEN (pfile);
- while (p < limit)
- {
- if (*p == '\v' || *p == '\f')
- cpp_pedwarn (pfile, "%s in preprocessing directive",
- *p == '\f' ? "formfeed" : "vertical tab");
- p++;
- }
- }
+ pedantic_whitespace (pfile, pfile->token_buffer + old_written,
+ CPP_WRITTEN (pfile) - old_written);
+ CPP_SET_WRITTEN (pfile, old_written);
+ goto get_next;
return CPP_HSPACE;
case CPP_DIRECTIVE:
}
}
-/* Just like _cpp_get_define_token except that it discards horizontal
- whitespace. */
-
-enum cpp_ttype
-_cpp_get_directive_token (pfile)
- cpp_reader *pfile;
-{
- int old_written = CPP_WRITTEN (pfile);
- for (;;)
- {
- enum cpp_ttype token = _cpp_get_define_token (pfile);
- if (token != CPP_COMMENT && token != CPP_HSPACE)
- return token;
- CPP_SET_WRITTEN (pfile, old_written);
- }
-}
-
/* Determine the current line and column. Used only by read_and_prescan. */
static U_CHAR *
find_position (start, limit, linep)
U_CHAR *tmp;
init_chartab ();
+ init_token_list (pfile, &pfile->directbuf, 0);
/* Determine the appropriate size for the input buffer. Normal C
source files are smaller than eight K. */