aboutsummaryrefslogtreecommitdiff
path: root/gdb/macrotab.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-07-18 20:55:33 +0000
committerTom Tromey <tromey@redhat.com>2008-07-18 20:55:33 +0000
commitd7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8 (patch)
tree350b57eb105730c6e52b961f7c55b0821f6b222e /gdb/macrotab.c
parenta9dc948127c2cb5127cec5ca87dbc19f17dd16cf (diff)
downloadgdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.zip
gdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.tar.gz
gdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.tar.bz2
gdb
PR gdb/855: * NEWS: Add entry for macro commands. * Makefile.in (macrocmd.o): Add gdb_string.h. * macroscope.h (user_macro_scope): Declare. (default_macro_scope): Update documentation. (macro_user_macros): Declare. * c-lang.c (c_preprocess_and_parse): Always attempt macro lookup. Use user_macro_scope. (null_macro_lookup): Remove. * macrotab.h (macro_callback_fn): Declare. (macro_for_each): Likewise. (macro_allow_redefinitions): Likewise. * macrotab.c (foreach_macro): New function (macro_for_each): Likewise. (struct macro_table) <redef_ok>: New field. (macro_allow_redefinitions): New function. (new_macro_table): Update. (macro_define_function): Likewise. (macro_define_object): Likewise. * macroscope.c (user_macro_scope): New function. (default_macro_scope): Use it. (macro_user_macros): New global. (standard_macro_lookup): Look in macro_user_macros. (_initialize_macroscope): New function. * macroexp.h (macro_is_whitespace, macro_is_digit, macro_is_identifier_nondigit): Declare. * macroexp.c (macro_is_whitespace): Rename. No longer static. (macro_is_digit): Likewise. (macro_is_identifier_nondigit): Likewise. (get_identifier): Update. (get_pp_number): Likewise. (get_token): Likewise. * macrocmd.c (skip_ws): New function. (extract_identifier): Likewise. (free_macro_definition_ptr): Likewise. (user_macros): Remove. (macro_define_command): Implement. (_initialize_macrocmd): Update. (macro_undef_command): Implement. (print_one_macro): New function. (macro_list_command): Implement. gdb/doc * gdb.texinfo (Macros): Update. Use @code rather than @command. gdb/testsuite * gdb.base/macscp.exp: Add macro tests.
Diffstat (limited to 'gdb/macrotab.c')
-rw-r--r--gdb/macrotab.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index 27e6fe6..7633c98 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -46,6 +46,10 @@ struct macro_table
#inclusion tree; everything else is #included from here. */
struct macro_source_file *main_source;
+ /* True if macros in this table can be redefined without issuing an
+ error. */
+ int redef_ok;
+
/* The table of macro definitions. This is a splay tree (an ordered
binary tree that stays balanced, effectively), sorted by macro
name. Where a macro gets defined more than once (presumably with
@@ -427,6 +431,14 @@ macro_main (struct macro_table *t)
}
+void
+macro_allow_redefinitions (struct macro_table *t)
+{
+ gdb_assert (! t->obstack);
+ t->redef_ok = 1;
+}
+
+
struct macro_source_file *
macro_include (struct macro_source_file *source,
int line,
@@ -731,13 +743,14 @@ macro_define_object (struct macro_source_file *source, int line,
const char *name, const char *replacement)
{
struct macro_table *t = source->table;
- struct macro_key *k;
+ struct macro_key *k = NULL;
struct macro_definition *d;
- k = check_for_redefinition (source, line,
- name, macro_object_like,
- 0, 0,
- replacement);
+ if (! t->redef_ok)
+ k = check_for_redefinition (source, line,
+ name, macro_object_like,
+ 0, 0,
+ replacement);
/* If we're redefining a symbol, and the existing key would be
identical to our new key, then the splay_tree_insert function
@@ -764,13 +777,14 @@ macro_define_function (struct macro_source_file *source, int line,
const char *replacement)
{
struct macro_table *t = source->table;
- struct macro_key *k;
+ struct macro_key *k = NULL;
struct macro_definition *d;
- k = check_for_redefinition (source, line,
- name, macro_function_like,
- argc, argv,
- replacement);
+ if (! t->redef_ok)
+ k = check_for_redefinition (source, line,
+ name, macro_function_like,
+ argc, argv,
+ replacement);
/* See comments about duplicate keys in macro_define_object. */
if (k && ! key_compare (k, name, source, line))
@@ -873,6 +887,28 @@ macro_definition_location (struct macro_source_file *source,
}
+/* Helper function for macro_for_each. */
+static int
+foreach_macro (splay_tree_node node, void *fnp)
+{
+ macro_callback_fn *fn = (macro_callback_fn *) fnp;
+ struct macro_key *key = (struct macro_key *) node->key;
+ struct macro_definition *def = (struct macro_definition *) node->value;
+ (**fn) (key->name, def);
+ return 0;
+}
+
+/* Call FN for every macro in TABLE. */
+void
+macro_for_each (struct macro_table *table, macro_callback_fn fn)
+{
+ /* Note that we pass in the address of 'fn' because, pedantically
+ speaking, we can't necessarily cast a pointer-to-function to a
+ void*. */
+ splay_tree_foreach (table->definitions, foreach_macro, &fn);
+}
+
+
/* Creating and freeing macro tables. */
@@ -893,6 +929,7 @@ new_macro_table (struct obstack *obstack,
t->obstack = obstack;
t->bcache = b;
t->main_source = NULL;
+ t->redef_ok = 0;
t->definitions = (splay_tree_new_with_allocator
(macro_tree_compare,
((splay_tree_delete_key_fn) macro_tree_delete_key),