Commit 1a76916c by Neil Booth

Makefile.in: Update cppmain.o.

	* Makefile.in: Update cppmain.o.
	* cpphash.h (struct cpp_reader): Move some members to a
	nested structure.
	(trad_line): Rename saved_line.
	(_cpp_read_logical_line_trad): Update.
	(_cpp_remove_overlay): New.
	* cppinit.c (cpp_create_reader): No need to set saved_line.
	(cpp_destroy): Update.
	(cpp_read_main_file): Only overlay if compiling.
	* cpplex.c (continue_after_nul): Return false if in directive.
	* cpplib.c (EXPAND): New.
	(directive_table, SEEN_EOL): Update.
	(end_directive): Remove overlay if traditional; don't skip
	line in traditional #define.
	(prepare_directive_trad): New.
	(_cpp_handle_directive, run_directive): Update for traditional
	directives.
	(lex_macro_node): Simplify, don't use lex_identifier_trad.
	* cpplib.h (struct options): Add preprocess_only.
	* cppmain.c: Don't include intl.h.
	(cpp_preprocess_file): Set options->preprocess_only.
	(scan_translation_unit_trad): Fix, and print line numbers.
	* cpptrad.c (check_output_buffer, lex_identifier, scan_parameters,
	maybe_start_funlike, scan_out_logical_line, replace_args_and_push,
	save_replacement_text, _cpp_create_trad_definition): Update for
	variable renaming.
	(_cpp_overlay_buffer): Save line number.
	(_cpp_remove_overlay): Rename from restore_buff, restore line.
	(_cpp_read_logical_line_trad): Don't handle overlays here.
	(scan_out_logical_line): Process directives.

From-SVN: r54485
parent b25bb36a
......@@ -2084,7 +2084,7 @@ libcpp.a: $(LIBCPP_OBJS)
$(AR) $(AR_FLAGS) libcpp.a $(LIBCPP_OBJS)
-$(RANLIB) libcpp.a
cppmain.o: cppmain.c $(CONFIG_H) $(CPPLIB_H) intl.h $(SYSTEM_H)
cppmain.o: cppmain.c $(CONFIG_H) $(LIBCPP_DEPS)
cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS)
cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS)
......
......@@ -406,10 +406,18 @@ struct cpp_reader
/* Whether cpplib owns the hashtable. */
unsigned char our_hashtable;
/* Traditional preprocessing output buffer. */
uchar *trad_out_base, *trad_out_limit;
uchar *trad_out_cur;
unsigned int trad_line;
/* Traditional preprocessing output buffer (a logical line). */
struct
{
uchar *base;
uchar *limit;
uchar *cur;
unsigned int first_line;
} out;
/* Used to save the original line number during traditional
preprocessing. */
unsigned int saved_line;
};
/* Character classes. Based on the more primitive macros in safe-ctype.h.
......@@ -510,9 +518,10 @@ extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum lc_reason,
extern void _cpp_pop_buffer PARAMS ((cpp_reader *));
/* In cpptrad.c. */
extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *, int));
extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *));
extern void _cpp_overlay_buffer PARAMS ((cpp_reader *pfile, const uchar *,
size_t));
extern void _cpp_remove_overlay PARAMS ((cpp_reader *));
extern cpp_hashnode *_cpp_lex_identifier_trad PARAMS ((cpp_reader *));
extern void _cpp_set_trad_context PARAMS ((cpp_reader *));
extern bool _cpp_create_trad_definition PARAMS ((cpp_reader *, cpp_macro *));
......
......@@ -506,7 +506,7 @@ cpp_create_reader (lang)
/* 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);
pfile->trad_line = pfile->line = 1;
pfile->line = 1;
/* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
......@@ -561,8 +561,8 @@ cpp_destroy (pfile)
while (CPP_BUFFER (pfile) != NULL)
_cpp_pop_buffer (pfile);
if (pfile->trad_out_base)
free (pfile->trad_out_base);
if (pfile->out.base)
free (pfile->out.base);
if (pfile->macro_buffer)
{
......@@ -941,7 +941,8 @@ cpp_read_main_file (pfile, fname, table)
if (CPP_OPTION (pfile, preprocessed))
read_original_filename (pfile);
/* Overlay an empty buffer to seed traditional preprocessing. */
else if (CPP_OPTION (pfile, traditional))
else if (CPP_OPTION (pfile, traditional)
&& !CPP_OPTION (pfile, preprocess_only))
_cpp_overlay_buffer (pfile, U"", 0);
return pfile->map->to_file;
......
......@@ -891,7 +891,16 @@ continue_after_nul (pfile)
buffer->saved_flags = BOL;
if (CPP_OPTION (pfile, traditional))
more = _cpp_read_logical_line_trad (pfile, true);
{
if (pfile->state.in_directive)
return false;
_cpp_remove_overlay (pfile);
more = _cpp_read_logical_line_trad (pfile);
_cpp_overlay_buffer (pfile, pfile->out.base,
pfile->out.cur - pfile->out.base);
pfile->line = pfile->out.first_line;
}
else
{
/* Stop parsing arguments with a CPP_EOF. When we finally come
......
......@@ -70,11 +70,16 @@ struct pragma_entry
conditional; IF_COND an opening conditional. INCL means to treat
"..." and <...> as q-char and h-char sequences respectively. IN_I
means this directive should be handled even if -fpreprocessed is in
effect (these are the directives with callback hooks). */
effect (these are the directives with callback hooks).
EXPAND is set on directives that are always macro-expanded. If
INCL is set, macro expansion is special-cased and EXPAND should not
be set. */
#define COND (1 << 0)
#define IF_COND (1 << 1)
#define INCL (1 << 2)
#define IN_I (1 << 3)
#define EXPAND (1 << 4)
/* Defines one #-directive, including how to handle it. */
typedef void (*directive_handler) PARAMS ((cpp_reader *));
......@@ -93,6 +98,7 @@ struct directive
static void skip_rest_of_line PARAMS ((cpp_reader *));
static void check_eol PARAMS ((cpp_reader *));
static void start_directive PARAMS ((cpp_reader *));
static void prepare_directive_trad PARAMS ((cpp_reader *));
static void end_directive PARAMS ((cpp_reader *, int));
static void directive_diagnostics
PARAMS ((cpp_reader *, const directive *, int));
......@@ -144,12 +150,12 @@ D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \
D(include, T_INCLUDE, KANDR, INCL) /* 52262 */ \
D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \
D(ifdef, T_IFDEF, KANDR, COND | IF_COND) /* 22000 */ \
D(if, T_IF, KANDR, COND | IF_COND) /* 18162 */ \
D(if, T_IF, KANDR, COND | IF_COND | EXPAND) /* 18162 */ \
D(else, T_ELSE, KANDR, COND) /* 9863 */ \
D(ifndef, T_IFNDEF, KANDR, COND | IF_COND) /* 9675 */ \
D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \
D(line, T_LINE, KANDR, 0) /* 2465 */ \
D(elif, T_ELIF, STDC89, COND) /* 610 */ \
D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \
D(elif, T_ELIF, STDC89, COND | EXPAND) /* 610 */ \
D(error, T_ERROR, STDC89, 0) /* 475 */ \
D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \
D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \
......@@ -202,8 +208,7 @@ static const directive linemarker_dir =
do_linemarker, U"#", 1, KANDR, IN_I
};
#define SEEN_EOL() (CPP_OPTION (pfile, traditional) \
|| pfile->cur_token[-1].type == CPP_EOF)
#define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF)
/* Skip any remaining tokens in a directive. */
static void
......@@ -249,6 +254,14 @@ end_directive (pfile, skip_line)
cpp_reader *pfile;
int skip_line;
{
if (CPP_OPTION (pfile, traditional))
{
if (pfile->directive == &dtable[T_DEFINE])
skip_line = false;
else
_cpp_remove_overlay (pfile);
}
/* We don't skip for an assembler #. */
if (skip_line)
{
......@@ -267,6 +280,27 @@ end_directive (pfile, skip_line)
pfile->directive = 0;
}
/* Prepare to handle the directive in pfile->directive. */
static void
prepare_directive_trad (pfile)
cpp_reader *pfile;
{
if (pfile->directive == &dtable[T_DEFINE])
CUR (pfile->context) = pfile->buffer->cur;
else
{
bool no_expand = ! (pfile->directive->flags & EXPAND);
if (no_expand)
pfile->state.prevent_expansion++;
_cpp_read_logical_line_trad (pfile);
if (no_expand)
pfile->state.prevent_expansion--;
_cpp_overlay_buffer (pfile, pfile->out.base,
pfile->out.cur - pfile->out.base);
}
}
/* Output diagnostics for a directive DIR. INDENTED is non-zero if
the '#' was indented. */
static void
......@@ -405,6 +439,8 @@ _cpp_handle_directive (pfile, indented)
! CPP_OPTION (pfile, discard_comments_in_macro_exp);
pfile->directive = dir;
if (CPP_OPTION (pfile, traditional))
prepare_directive_trad (pfile);
(*pfile->directive->handler) (pfile);
}
else if (skip == 0)
......@@ -436,6 +472,8 @@ run_directive (pfile, dir_no, buf, count)
/* We don't want a leading # to be interpreted as a directive. */
pfile->buffer->saved_flags = 0;
pfile->directive = &dtable[dir_no];
if (CPP_OPTION (pfile, traditional))
prepare_directive_trad (pfile);
(void) (*pfile->directive->handler) (pfile);
end_directive (pfile, 1);
_cpp_pop_buffer (pfile);
......@@ -447,7 +485,7 @@ static cpp_hashnode *
lex_macro_node (pfile)
cpp_reader *pfile;
{
cpp_hashnode *node;
const cpp_token *token = _cpp_lex_token (pfile);
/* The token immediately after #define must be an identifier. That
identifier may not be "defined", per C99 6.10.8p4.
......@@ -459,41 +497,31 @@ lex_macro_node (pfile)
Note that if we're copying comments into macro expansions, we
could encounter comment tokens here, so eat them all up first. */
if (CPP_OPTION (pfile, traditional))
node = _cpp_lex_identifier_trad (pfile);
else
if (! CPP_OPTION (pfile, discard_comments_in_macro_exp))
{
const cpp_token *token = _cpp_lex_token (pfile);
while (token->type == CPP_COMMENT)
token = _cpp_lex_token (pfile);
}
if (! CPP_OPTION (pfile, discard_comments_in_macro_exp))
{
while (token->type == CPP_COMMENT)
token = _cpp_lex_token (pfile);
}
if (token->type == CPP_NAME)
{
cpp_hashnode *node = token->val.node;
if (token->type == CPP_EOF)
{
cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive",
pfile->directive->name);
return NULL;
}
if (token->type == CPP_NAME || (token->flags & NAMED_OP))
node = token->val.node;
else
node = NULL;
if (node == pfile->spec_nodes.n_defined)
cpp_error (pfile, DL_ERROR,
"\"defined\" cannot be used as a macro name");
else if (! (node->flags & NODE_POISONED))
return node;
}
if (!node)
cpp_error (pfile, DL_ERROR, "macro names must be identifiers");
else if (node->flags & NODE_OPERATOR)
else if (token->flags & NAMED_OP)
cpp_error (pfile, DL_ERROR,
"\"%s\" cannot be used as a macro name as it is an operator in C++",
NODE_NAME (node));
else if (node == pfile->spec_nodes.n_defined)
cpp_error (pfile, DL_ERROR, "\"defined\" cannot be used as a macro name");
else if (! (node->flags & NODE_POISONED))
return node;
NODE_NAME (token->val.node));
else if (token->type == CPP_EOF)
cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive",
pfile->directive->name);
else
cpp_error (pfile, DL_ERROR, "macro names must be identifiers");
return NULL;
}
......
......@@ -393,6 +393,9 @@ struct cpp_options
/* True for traditional preprocessing. */
unsigned char traditional;
/* True if only preprocessing and not compiling. */
unsigned char preprocess_only;
/* Target-specific features set by the front end or client. */
/* Precision for target CPP arithmetic, target characters, target
......
......@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "system.h"
#include "cpplib.h"
#include "cpphash.h"
#include "intl.h"
/* Encapsulates state used to convert the stream of tokens coming from
cpp_get_token back into a text file. */
......@@ -73,6 +72,10 @@ cpp_preprocess_file (pfile)
{
options = cpp_get_options (pfile);
/* Let preprocessor know if it's only preprocessing. It would be
nice to lose this somehow. */
options->preprocess_only = 1;
/* Initialize the printer structure. Setting print.line to -1 here
is a trick to guarantee that the first token of the file will
cause a linemarker to be output by maybe_print_line. */
......@@ -221,20 +224,22 @@ check_multiline_token (str)
print.line++;
}
/* Writes out a traditionally preprocessed file. */
static void
scan_translation_unit_trad (pfile)
cpp_reader *pfile;
{
bool more;
size_t len;
do
for (;;)
{
more = _cpp_read_logical_line_trad (pfile, false);
len = pfile->trad_out_cur - pfile->trad_out_base;
fwrite (pfile->trad_out_base, 1, len, print.outf);
size_t len;
if (!_cpp_read_logical_line_trad (pfile))
break;
len = pfile->out.cur - pfile->out.base;
maybe_print_line (print.map, pfile->out.first_line);
fwrite (pfile->out.base, 1, len, print.outf);
print.printed = 1;
}
while (more);
}
/* If the token read on logical line LINE needs to be output on a
......
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