+2001-08-04 Neil Booth <neil@cat.daikokuya.demon.co.uk>
+
+ * Makefile.in (CPPLIB_H): New, so that dependencies on cpplib.h
+ are also on line-map.h.
+ * cppfiles.c (stack_include_file): Update.
+ * cpphash.h (struct cpp_buffer): New member return_at_eof.
+ (_cpp_pop_buffer): New.
+ * cppinit.c (cpp_destroy, cpp_finish): Update.
+ (do_includes): Mark each buffer to return at EOF.
+ * cpplex.c (_cpp_lex_token): Pop buffers at EOF. Continue or
+ return as requested.
+ * cpplib.c (run_directive, do_line, cpp_push_buffer): Update.
+ (cpp_pop_buffer): Rename _cpp_pop_buffer. Stop skipping.
+ * cpplib.h (cpp_pop_buffer): Remove.
+ (cpp_scan_buffer_nooutput): Rename cpp_scan_nooutput.
+ * cppmacro.c (cpp_scan_buffer_nooutput): Similarly. No need to pop
+ buffers.
+ * cppmain.c (scan_buffer): Rename scan_translation_unit. No need
+ to pop buffers.
+ (do_preprocessing): Update.
+ * fix-header.c (read_scan_file): Update. No need to pop buffers.
+ * c-parse.in (_yylex): Similarly.
+ * scan-decls.c (scan_decls): Similarly.
+ * line-map.h: Update comments.
+
+ * objc/Make-lang.in (objc-act.o): Update dependencies.
+
2001-08-04 Stephane Carrez <Stephane.Carrez@worldnet.fr>
* config/m68hc11/m68hc11.md ("cmphi_1", "cmpqi_1"): Allow memory
C_TREE_H = c-tree.h $(C_COMMON_H)
SYSTEM_H = system.h hwint.h $(srcdir)/../include/libiberty.h
PREDICT_H = predict.h predict.def
+CPPLIB_H = cpplib.h line-map.h
# sed inserts variable overrides after the following line.
####target overrides
c-errors.o: c-errors.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) flags.h \
diagnostic.h $(TM_P_H)
c-parse.o : $(srcdir)/c-parse.c $(CONFIG_H) $(TREE_H) c-lex.h $(GGC_H) intl.h \
- $(C_TREE_H) input.h flags.h $(SYSTEM_H) toplev.h output.h cpplib.h \
+ $(C_TREE_H) input.h flags.h $(SYSTEM_H) toplev.h output.h $(CPPLIB_H) \
diagnostic.h
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $(srcdir)/c-parse.c
c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) c-lex.h \
debug.h $(C_TREE_H) \
c-pragma.h input.h intl.h flags.h toplev.h output.h \
- mbchar.h cpplib.h $(EXPR_H) $(TM_P_H)
+ mbchar.h $(CPPLIB_H) $(EXPR_H) $(TM_P_H)
c-aux-info.o : c-aux-info.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
flags.h toplev.h
c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) flags.h toplev.h
cpphash.o cpperror.o cppinit.o cppdefault.o \
hashtable.o line-map.o mkdeps.o prefix.o version.o mbchar.o
-LIBCPP_DEPS = cpplib.h cpphash.h line-map.h hashtable.h intl.h \
+LIBCPP_DEPS = $(CPPLIB_H) cpphash.h line-map.h hashtable.h intl.h \
$(OBSTACK_H) $(SYSTEM_H)
# Most of the other archives built/used by this makefile are for
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o cpp0$(exeext) cppmain.o \
intl.o libcpp.a $(LIBS)
-cppmain.o: cppmain.c $(CONFIG_H) cpplib.h intl.h $(SYSTEM_H)
+cppmain.o: cppmain.c $(CONFIG_H) $(CPPLIB_H) intl.h $(SYSTEM_H)
cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS)
cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS)
scan-decls.o scan.o libcpp.a $(LIBS)
fix-header.o: fix-header.c $(OBSTACK_H) scan.h \
- xsys-protos.h $(HCONFIG_H) $(SYSTEM_H) cpplib.h
+ xsys-protos.h $(HCONFIG_H) $(SYSTEM_H) $(CPPLIB_H)
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/fix-header.c
-scan-decls.o: scan-decls.c scan.h cpplib.h $(HCONFIG_H) $(SYSTEM_H)
+scan-decls.o: scan-decls.c scan.h $(CPPLIB_H) $(HCONFIG_H) $(SYSTEM_H)
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/scan-decls.c
# stmp-fixproto depends on this, not on fix-header directly.
case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
case CPP_EOF:
- if (cpp_pop_buffer (parse_in) == 0)
- return 0;
- goto get_next;
+ return 0;
case CPP_NAME:
return yylexname ();
+2001-08-04 Neil Booth <neil@cat.daikokuya.demon.co.uk>
+
+ * cp/spew.c (read_token): No need to pop buffers.
+
2001-08-02 Stan Shebs <shebs@apple.com>
* cp-tree.h (FNADDR_FROM_VTABLE_ENTRY): Remove, no longer used.
#undef YYCODE
case CPP_EOF:
- if (cpp_pop_buffer (parse_in) != 0)
- goto retry;
t->yychar = 0;
break;
}
/* Push a buffer. */
- fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, inc->name);
+ fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, inc->name, 0);
fp->inc = inc;
fp->inc->refcnt++;
fp->sysp = sysp;
include files has been calculated and stored in "dir" below. */
unsigned char search_cached;
+ /* At EOF, a buffer is automatically popped. If RETURN_AT_EOF is
+ true, a CPP_EOF token is then returned. Otherwise, the next
+ token from the enclosing buffer is returned. */
+ bool return_at_eof;
+
/* Buffer type. */
ENUM_BITFIELD (cpp_buffer_type) type : 8;
extern void _cpp_init_directives PARAMS ((cpp_reader *));
extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum lc_reason));
+extern void _cpp_pop_buffer PARAMS ((cpp_reader *));
/* Utility routines and macros. */
#define DSC(str) (const U_CHAR *)str, sizeof str - 1
cpp_context *context, *contextn;
while (CPP_BUFFER (pfile) != NULL)
- cpp_pop_buffer (pfile);
+ _cpp_pop_buffer (pfile);
if (pfile->macro_buffer)
{
header.val.str.text = (const unsigned char *) p->arg;
header.val.str.len = strlen (p->arg);
if (_cpp_execute_include (pfile, &header, IT_CMDLINE) && scan)
- cpp_scan_buffer_nooutput (pfile, 0);
+ {
+ pfile->buffer->return_at_eof = true;
+ cpp_scan_nooutput (pfile);
+ }
}
q = p->next;
free (p);
{
cpp_ice (pfile, "buffers still stacked in cpp_finish");
while (CPP_BUFFER (pfile))
- cpp_pop_buffer (pfile);
+ _cpp_pop_buffer (pfile);
}
/* Don't write the deps file if preprocessing has failed. */
switch (c)
{
case EOF:
- /* Non-empty files should end in a newline. Checking "bol" too
- prevents multiple warnings when hitting the EOF more than
- once, like in a directive. Don't warn for command line and
- _Pragma buffers. */
- if (pfile->lexer_pos.col != 0 && !bol && !buffer->from_stage3)
- cpp_pedwarn (pfile, "no newline at end of file");
+ if (!pfile->state.in_directive)
+ {
+ unsigned char ret = pfile->buffer->return_at_eof;
+
+ /* Non-empty files should end in a newline. Don't warn for
+ command line and _Pragma buffers. */
+ if (pfile->lexer_pos.col != 0 && !buffer->from_stage3)
+ cpp_pedwarn (pfile, "no newline at end of file");
+ _cpp_pop_buffer (pfile);
+ if (pfile->buffer && !ret)
+ {
+ bol = 1;
+ goto done_directive;
+ }
+ }
pfile->state.next_bol = 1;
- pfile->state.skipping = 0; /* In case missing #endif. */
result->type = CPP_EOF;
- /* Don't do MI optimisation. */
return;
case ' ': case '\t': case '\f': case '\v': case '\0':
unsigned int output_line = pfile->lexer_pos.output_line;
cpp_buffer *buffer;
- buffer = cpp_push_buffer (pfile, (const U_CHAR *) buf, count, type, 0);
+ buffer = cpp_push_buffer (pfile, (const U_CHAR *) buf, count, type, 0, 1);
if (dir_no == T_PRAGMA)
{
pfile->state.prevent_expansion--;
check_eol (pfile);
end_directive (pfile, 1);
-
- cpp_pop_buffer (pfile);
+ _cpp_pop_buffer (pfile);
}
/* Checks for validity the macro name in #define, #undef, #ifdef and
if (reason == LC_ENTER)
{
/* Fake a buffer stack for diagnostics. */
- cpp_push_buffer (pfile, 0, 0, BUF_FAKE, fname);
+ cpp_push_buffer (pfile, 0, 0, BUF_FAKE, fname, 0);
/* Fake an include for cpp_included. */
_cpp_fake_include (pfile, fname);
buffer = pfile->buffer;
buffer->nominal_fname);
else
{
- cpp_pop_buffer (pfile);
+ _cpp_pop_buffer (pfile);
buffer = pfile->buffer;
#ifdef ENABLE_CHECKING
if (strcmp (buffer->nominal_fname, fname))
doesn't fail. It does not generate a file change call back; that
is the responsibility of the caller. */
cpp_buffer *
-cpp_push_buffer (pfile, buffer, len, type, filename)
+cpp_push_buffer (pfile, buffer, len, type, filename, return_at_eof)
cpp_reader *pfile;
const U_CHAR *buffer;
size_t len;
enum cpp_buffer_type type;
const char *filename;
+ int return_at_eof;
{
cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer);
new->pfile = pfile;
new->include_stack_listed = 0;
new->lineno = 1;
+ new->return_at_eof = return_at_eof;
pfile->state.next_bol = 1;
pfile->buffer_stack_depth++;
/* If called from do_line, pops a single buffer. Otherwise pops all
buffers until a real file is reached. Generates appropriate
call-backs. */
-cpp_buffer *
-cpp_pop_buffer (pfile)
+void
+_cpp_pop_buffer (pfile)
cpp_reader *pfile;
{
cpp_buffer *buffer;
}
obstack_free (&pfile->buffer_ob, buffer);
- return pfile->buffer;
+
+ pfile->state.skipping = 0; /* In case missing #endif. */
}
void
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
const unsigned char *, size_t,
enum cpp_buffer_type,
- const char *));
-extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
+ const char *, int));
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
/* N.B. The error-message-printer prototypes have not been nicely
cpp_cb, void *));
/* In cppmacro.c */
-extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *, int));
+extern void cpp_scan_nooutput PARAMS ((cpp_reader *));
extern void cpp_start_lookahead PARAMS ((cpp_reader *));
extern void cpp_stop_lookahead PARAMS ((cpp_reader *, int));
extern int cpp_sys_macro_p PARAMS ((cpp_reader *));
/* Read each token in, until EOF. Directives are transparently
processed. */
void
-cpp_scan_buffer_nooutput (pfile, all_buffers)
+cpp_scan_nooutput (pfile)
cpp_reader *pfile;
- int all_buffers;
{
cpp_token token;
- cpp_buffer *buffer = all_buffers ? 0: pfile->buffer->prev;
do
- do
- cpp_get_token (pfile, &token);
- while (token.type != CPP_EOF);
- while (cpp_pop_buffer (pfile) != buffer);
+ cpp_get_token (pfile, &token);
+ while (token.type != CPP_EOF);
}
/* Lookahead handling. */
static void setup_callbacks PARAMS ((void));
/* General output routines. */
-static void scan_buffer PARAMS ((cpp_reader *));
+static void scan_translation_unit PARAMS ((cpp_reader *));
static void check_multiline_token PARAMS ((cpp_string *));
static int printer_init PARAMS ((cpp_reader *));
static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *));
if (cpp_start_read (pfile, options->in_fname))
{
/* A successful cpp_start_read guarantees that we can call
- cpp_scan_buffer_nooutput or cpp_get_token next. */
+ cpp_scan_nooutput or cpp_get_token next. */
if (options->no_output)
- cpp_scan_buffer_nooutput (pfile, 1);
+ cpp_scan_nooutput (pfile);
else
- scan_buffer (pfile);
+ scan_translation_unit (pfile);
/* -dM command line option. Should this be in cpp_finish? */
if (options->dump_macros == dump_only)
/* Writes out the preprocessed file. Alternates between two tokens,
so that we can avoid accidental token pasting. */
static void
-scan_buffer (pfile)
+scan_translation_unit (pfile)
cpp_reader *pfile;
{
unsigned int index, line;
cpp_token tokens[2], *token;
- do
+ for (index = 0;; index = 1 - index)
{
- for (index = 0;; index = 1 - index)
- {
- token = &tokens[index];
- cpp_get_token (pfile, token);
+ token = &tokens[index];
+ cpp_get_token (pfile, token);
- if (token->type == CPP_EOF)
- break;
+ if (token->type == CPP_EOF)
+ break;
- line = cpp_get_line (pfile)->output_line;
- if (print.lineno != line)
+ line = cpp_get_line (pfile)->output_line;
+ if (print.lineno != line)
+ {
+ unsigned int col = cpp_get_line (pfile)->col;
+
+ /* Supply enough whitespace to put this token in its original
+ column. Don't bother trying to reconstruct tabs; we can't
+ get it right in general, and nothing ought to care. (Yes,
+ some things do care; the fault lies with them.) */
+ maybe_print_line (line);
+ if (col > 1)
{
- unsigned int col = cpp_get_line (pfile)->col;
-
- /* Supply enough whitespace to put this token in its original
- column. Don't bother trying to reconstruct tabs; we can't
- get it right in general, and nothing ought to care. (Yes,
- some things do care; the fault lies with them.) */
- maybe_print_line (line);
- if (col > 1)
- {
- if (token->flags & PREV_WHITE)
- col--;
- while (--col)
- putc (' ', print.outf);
- }
+ if (token->flags & PREV_WHITE)
+ col--;
+ while (--col)
+ putc (' ', print.outf);
}
- else if ((token->flags & (PREV_WHITE | AVOID_LPASTE))
- == AVOID_LPASTE
- && cpp_avoid_paste (pfile, &tokens[1 - index], token))
- token->flags |= PREV_WHITE;
- /* Special case '# <directive name>': insert a space between
- the # and the token. This will prevent it from being
- treated as a directive when this code is re-preprocessed.
- XXX Should do this only at the beginning of a line, but how? */
- else if (token->type == CPP_NAME && token->val.node->directive_index
- && tokens[1 - index].type == CPP_HASH)
- token->flags |= PREV_WHITE;
-
- cpp_output_token (token, print.outf);
- print.printed = 1;
- if (token->type == CPP_STRING || token->type == CPP_WSTRING
- || token->type == CPP_COMMENT)
- check_multiline_token (&token->val.str);
}
+ else if ((token->flags & (PREV_WHITE | AVOID_LPASTE))
+ == AVOID_LPASTE
+ && cpp_avoid_paste (pfile, &tokens[1 - index], token))
+ token->flags |= PREV_WHITE;
+ /* Special case '# <directive name>': insert a space between
+ the # and the token. This will prevent it from being
+ treated as a directive when this code is re-preprocessed.
+ XXX Should do this only at the beginning of a line, but how? */
+ else if (token->type == CPP_NAME && token->val.node->directive_index
+ && tokens[1 - index].type == CPP_HASH)
+ token->flags |= PREV_WHITE;
+
+ cpp_output_token (token, print.outf);
+ print.printed = 1;
+ if (token->type == CPP_STRING || token->type == CPP_WSTRING
+ || token->type == CPP_COMMENT)
+ check_multiline_token (&token->val.str);
}
- while (cpp_pop_buffer (pfile) != 0);
}
/* Adjust print.lineno for newlines embedded in tokens. */
/* Scan the macro expansion of "getchar();". */
cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1,
- BUF_BUILTIN, in_fname);
+ BUF_BUILTIN, in_fname, 1);
for (;;)
{
cpp_token t;
else if (cpp_ideq (&t, "_filbuf"))
seen_filbuf++;
}
- cpp_pop_buffer (scan_in);
if (seen_filbuf)
{
/* The logical line FROM_LINE maps to physical source file TO_FILE at
line TO_LINE, and subsequently one-to-one until the next line_map
- structure in the set. */
+ structure in the set. INCLUDED_FROM is an index into the set that
+ gives the line mapping at whose end the current one was included.
+ File(s) at the bottom of the include stack have this set to -1. */
struct line_map
{
const char *to_file;
int included_from;
};
-/* Contains a sequence of chronological line_map structures. */
+/* A set of chronological line_map structures. */
struct line_maps
{
struct line_map *maps;
of the #include, or other directive, that caused a map change. */
#define LAST_SOURCE_LINE(MAP) SOURCE_LINE (MAP, (MAP)[1].from_line - 1)
+/* Non-zero if the map is at the bottom of the include stack. */
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
#endif /* !GCC_LINE_MAP_H */
$(CONFIG_H) $(TREE_H) $(srcdir)/toplev.h $(srcdir)/ggc.h \
$(srcdir)/c-lex.h $(srcdir)/c-tree.h $(srcdir)/c-common.h \
$(srcdir)/input.h $(srcdir)/flags.h $(srcdir)/output.h \
- $(srcdir)/objc/objc-act.h $(SYSTEM_H) cpplib.h
+ $(srcdir)/objc/objc-act.h $(SYSTEM_H) $(CPPLIB_H)
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -I$(srcdir)/objc \
-c $(srcdir)/objc/objc-parse.c $(OUTPUT_OPTION)
brace_nesting++;
goto new_statement;
}
+
if (token.type == CPP_EOF)
- {
- if (cpp_pop_buffer (pfile) == 0)
- return 0;
+ return 0;
- goto new_statement;
- }
if (token.type == CPP_SEMICOLON)
goto new_statement;
if (token.type != CPP_NAME)
goto new_statement;
case CPP_EOF:
- if (cpp_pop_buffer (pfile) == 0)
- return 0;
- break;
+ return 0;
case CPP_OPEN_PAREN:
/* Looks like this is the start of a formal parameter list. */