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