summaryrefslogtreecommitdiffstats
path: root/gcc/cppinit.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2000-10-28 17:59:06 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2000-10-28 17:59:06 +0000
commit79bd622b1c2d25fb1e8d671a87c2d6157d249628 (patch)
treeb1f50a88de9fbdd6a784d0c03fa8cd31e4ac5916 /gcc/cppinit.c
parent195ac9616ec58d2d9f065e61980a73d5a8783fcc (diff)
downloadppe42-gcc-79bd622b1c2d25fb1e8d671a87c2d6157d249628.tar.gz
ppe42-gcc-79bd622b1c2d25fb1e8d671a87c2d6157d249628.zip
2000-10-28 Neil Booth <neilb@earthling.net>
New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37098 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r--gcc/cppinit.c224
1 files changed, 115 insertions, 109 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 3fbf77e4748..20dfc633e3c 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -427,8 +427,19 @@ void
cpp_reader_init (pfile)
cpp_reader *pfile;
{
+ struct spec_nodes *s;
+
memset ((char *) pfile, 0, sizeof (cpp_reader));
+ /* If cpp_init hasn't been called, generate a fatal error (by hand)
+ and call it here. */
+ if (!cpp_init_completed)
+ {
+ fputs ("cpp_reader_init: internal error: cpp_init not called.\n", stderr);
+ pfile->errors = CPP_FATAL_LIMIT;
+ cpp_init ();
+ }
+
CPP_OPTION (pfile, dollars_in_ident) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, warn_import) = 1;
@@ -441,44 +452,45 @@ cpp_reader_init (pfile)
CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
- /* If cpp_init hasn't been called, generate a fatal error (by hand)
- and call it here. */
- if (!cpp_init_completed)
- {
- fputs ("cpp_reader_init: internal error: cpp_init not called.\n", stderr);
- pfile->errors = CPP_FATAL_LIMIT;
- cpp_init ();
- }
+ /* Initialize comment saving state. */
+ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
+
+ /* Indicate date and time not yet calculated. */
+ pfile->date.type = CPP_EOF;
+
+ /* Initialise the base context. */
+ pfile->context = &pfile->base_context;
+ pfile->base_context.macro = 0;
+ pfile->base_context.prev = pfile->base_context.next = 0;
+
+ /* Identifier pool initially 8K. Unaligned, permanent pool. */
+ _cpp_init_pool (&pfile->ident_pool, 8 * 1024, 1, 0);
+
+ /* String and number pool initially 4K. Unaligned, temporary pool. */
+ _cpp_init_pool (&pfile->temp_string_pool, 4 * 1024, 1, 1);
+
+ /* Argument pool initially 8K. Aligned, temporary pool. */
+ _cpp_init_pool (&pfile->argument_pool, 8 * 1024, 0, 1);
+
+ /* Macro pool initially 8K. Aligned, permanent pool. */
+ _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
- _cpp_init_macros (pfile);
+ /* Start with temporary pool. */
+ pfile->string_pool = &pfile->temp_string_pool;
+
+ _cpp_init_hashtable (pfile);
_cpp_init_stacks (pfile);
_cpp_init_includes (pfile);
_cpp_init_internal_pragmas (pfile);
-}
-/* Initialize a cpp_printer structure. As a side effect, open the
- output file. */
-cpp_printer *
-cpp_printer_init (pfile, print)
- cpp_reader *pfile;
- cpp_printer *print;
-{
- memset (print, '\0', sizeof (cpp_printer));
- if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
-
- if (CPP_OPTION (pfile, out_fname)[0] == '\0')
- print->outf = stdout;
- else
- {
- print->outf = fopen (CPP_OPTION (pfile, out_fname), "w");
- if (! print->outf)
- {
- cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
- return NULL;
- }
- }
- return print;
+ /* Initialize the special nodes. */
+ s = &pfile->spec_nodes;
+ s->n_L = cpp_lookup (pfile, DSC("L"));
+ s->n_defined = cpp_lookup (pfile, DSC("defined"));
+ s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
+ s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
+ s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
+ s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
}
/* Free resources used by PFILE.
@@ -487,69 +499,84 @@ void
cpp_cleanup (pfile)
cpp_reader *pfile;
{
- struct file_name_list *dir, *next;
+ struct file_name_list *dir, *dirn;
+ cpp_context *context, *contextn;
while (CPP_BUFFER (pfile) != NULL)
cpp_pop_buffer (pfile);
+ if (pfile->macro_buffer)
+ free ((PTR) pfile->macro_buffer);
+
if (pfile->deps)
deps_free (pfile->deps);
- if (pfile->spec_nodes)
- free (pfile->spec_nodes);
-
- _cpp_free_temp_tokens (pfile);
_cpp_cleanup_includes (pfile);
_cpp_cleanup_stacks (pfile);
- _cpp_cleanup_macros (pfile);
+ _cpp_cleanup_hashtable (pfile);
+
+ _cpp_free_lookaheads (pfile);
- for (dir = CPP_OPTION (pfile, quote_include); dir; dir = next)
+ _cpp_free_pool (&pfile->ident_pool);
+ _cpp_free_pool (&pfile->temp_string_pool);
+ _cpp_free_pool (&pfile->macro_pool);
+ _cpp_free_pool (&pfile->argument_pool);
+
+ for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
{
- next = dir->next;
+ dirn = dir->next;
free (dir->name);
free (dir);
}
+
+ for (context = pfile->base_context.next; context; context = contextn)
+ {
+ contextn = context->next;
+ free (context);
+ }
}
-/* This structure defines one built-in macro. A node of type TYPE will
- be entered in the macro hash table under the name NAME, with value
- VALUE (if any). If TYPE is T_OPERATOR, the CODE field is used instead.
+/* This structure defines one built-in identifier. A node will be
+ entered in the hash table under the name NAME, with value VALUE (if
+ any). If flags has OPERATOR, the node's operator field is used; if
+ flags has BUILTIN the node's builtin field is used.
Two values are not compile time constants, so we tag
them in the FLAGS field instead:
VERS value is the global version_string, quoted
ULP value is the global user_label_prefix
- Also, macros with CPLUS set in the flags field are entered only for C++.
- */
+ Also, macros with CPLUS set in the flags field are entered only for C++. */
struct builtin
{
const U_CHAR *name;
const char *value;
- unsigned char code;
- unsigned char type;
+ unsigned char builtin;
+ unsigned char operator;
unsigned short flags;
- unsigned int len;
+ unsigned short len;
};
-#define VERS 0x01
-#define ULP 0x02
-#define CPLUS 0x04
-
-#define B(n, t) { U n, 0, 0, t, 0, sizeof n - 1 }
-#define C(n, v) { U n, v, 0, T_MACRO, 0, sizeof n - 1 }
-#define X(n, f) { U n, 0, 0, T_MACRO, f, sizeof n - 1 }
-#define O(n, c, f) { U n, 0, c, T_OPERATOR, f, sizeof n - 1 }
+#define VERS 0x01
+#define ULP 0x02
+#define CPLUS 0x04
+#define BUILTIN 0x08
+#define OPERATOR 0x10
+
+#define B(n, t) { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
+#define C(n, v) { U n, v, 0, 0, 0, sizeof n - 1 }
+#define X(n, f) { U n, 0, 0, 0, f, sizeof n - 1 }
+#define O(n, c, f) { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
static const struct builtin builtin_array[] =
{
- B("__TIME__", T_TIME),
- B("__DATE__", T_DATE),
- B("__FILE__", T_FILE),
- B("__BASE_FILE__", T_BASE_FILE),
- B("__LINE__", T_SPECLINE),
- B("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL),
- B("__STDC__", T_STDC),
+ B("__TIME__", BT_TIME),
+ B("__DATE__", BT_DATE),
+ B("__FILE__", BT_FILE),
+ B("__BASE_FILE__", BT_BASE_FILE),
+ B("__LINE__", BT_SPECLINE),
+ B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
+ B("__STDC__", BT_STDC),
X("__VERSION__", VERS),
X("__USER_LABEL_PREFIX__", ULP),
@@ -570,9 +597,8 @@ static const struct builtin builtin_array[] =
/* Named operators known to the preprocessor. These cannot be #defined
and always have their stated meaning. They are treated like normal
- string tokens except for the type code and the meaning. Most of them
+ identifiers except for the type code and the meaning. Most of them
are only for C++ (but see iso646.h). */
- O("defined", CPP_DEFINED, 0),
O("and", CPP_AND_AND, CPLUS),
O("and_eq", CPP_AND_EQ, CPLUS),
O("bitand", CPP_AND, CPLUS),
@@ -583,7 +609,7 @@ static const struct builtin builtin_array[] =
O("or", CPP_OR_OR, CPLUS),
O("or_eq", CPP_OR_EQ, CPLUS),
O("xor", CPP_XOR, CPLUS),
- O("xor_eq", CPP_XOR_EQ, CPLUS),
+ O("xor_eq", CPP_XOR_EQ, CPLUS)
};
#undef B
#undef C
@@ -601,10 +627,25 @@ initialize_builtins (pfile)
for(b = builtin_array; b < builtin_array_end; b++)
{
- if (b->flags & CPLUS && ! CPP_OPTION (pfile, cplusplus))
+ if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
continue;
- if (b->type == T_MACRO)
+ if (b->flags & (OPERATOR | BUILTIN))
+ {
+ cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
+ if (b->flags & OPERATOR)
+ {
+ hp->flags |= NODE_OPERATOR;
+ hp->value.operator = b->operator;
+ }
+ else
+ {
+ hp->type = NT_MACRO;
+ hp->flags |= NODE_BUILTIN;
+ hp->value.builtin = b->builtin;
+ }
+ }
+ else /* A standard macro of some kind. */
{
const char *val;
char *str;
@@ -629,17 +670,13 @@ initialize_builtins (pfile)
_cpp_define_builtin (pfile, str);
}
- else
- {
- cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
- hp->type = b->type;
- if (b->type == T_OPERATOR)
- hp->value.code = b->code;
- }
}
}
+#undef BUILTIN
+#undef OPERATOR
#undef VERS
#undef ULP
+#undef CPLUS
#undef builtin_array_end
/* Another subroutine of cpp_start_read. This one sets up to do
@@ -799,9 +836,8 @@ initialize_standard_includes (pfile)
*/
int
-cpp_start_read (pfile, print, fname)
+cpp_start_read (pfile, fname)
cpp_reader *pfile;
- cpp_printer *print;
const char *fname;
{
struct pending_option *p, *q;
@@ -829,19 +865,6 @@ cpp_start_read (pfile, print, fname)
if (CPP_OPTION (pfile, user_label_prefix) == NULL)
CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
- /* Figure out if we need to save function macro parameter spellings.
- We don't use CPP_PEDANTIC() here because that depends on whether
- or not the current file is a system header, and there is no
- current file yet. */
- pfile->save_parameter_spellings =
- CPP_OPTION (pfile, pedantic)
- || CPP_OPTION (pfile, debug_output)
- || CPP_OPTION (pfile, dump_macros) == dump_definitions
- || CPP_OPTION (pfile, dump_macros) == dump_only;
-
- /* Set up the tables used by read_and_prescan. */
- _cpp_init_input_buffer (pfile);
-
/* Set up the include search path now. */
if (! CPP_OPTION (pfile, no_standard_includes))
initialize_standard_includes (pfile);
@@ -893,13 +916,6 @@ cpp_start_read (pfile, print, fname)
}
pfile->done_initializing = 1;
- /* We start at line 1 of the main input file. */
- if (print)
- {
- print->last_fname = CPP_BUFFER (pfile)->nominal_fname;
- print->lineno = 1;
- }
-
/* The -imacros files can be scanned now, but the -include files
have to be pushed onto the include stack and processed later,
in the main loop calling cpp_get_token. */
@@ -934,9 +950,8 @@ cpp_start_read (pfile, print, fname)
clear macro definitions, such that you could call cpp_start_read
with a new filename to restart processing. */
void
-cpp_finish (pfile, print)
+cpp_finish (pfile)
cpp_reader *pfile;
- cpp_printer *print;
{
if (CPP_BUFFER (pfile))
{
@@ -971,15 +986,6 @@ cpp_finish (pfile, print)
}
}
- /* Flush any pending output. */
- if (print)
- {
- if (pfile->need_newline)
- putc ('\n', print->outf);
- if (ferror (print->outf) || fclose (print->outf))
- cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
- }
-
/* Report on headers that could use multiple include guards. */
if (CPP_OPTION (pfile, print_include_names))
_cpp_report_missing_guards (pfile);
OpenPOWER on IntegriCloud