Implement demangling for rvalue reference type names
[deliverable/binutils-gdb.git] / gdb / macrotab.c
index 1e02b0a5df9c707f05e284f84c0695ba3e958fb7..1b85c8c37c6f7226be5c993189bc7b245b820fb7 100644 (file)
@@ -1,5 +1,5 @@
 /* C preprocessor macro tables for GDB.
-   Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   Copyright (C) 2002-2017 Free Software Foundation, Inc.
    Contributed by Red Hat, Inc.
 
    This file is part of GDB.
@@ -47,9 +47,8 @@ struct macro_table
      #inclusion tree; everything else is #included from here.  */
   struct macro_source_file *main_source;
 
-  /* Compilation directory for all files of this macro table.  It is allocated
-     on objfile's obstack.  */
-  const char *comp_dir;
+  /* Backlink to containing compilation unit, or NULL if there isn't one.  */
+  struct compunit_symtab *compunit_symtab;
 
   /* True if macros in this table can be redefined without issuing an
      error.  */
@@ -131,7 +130,7 @@ macro_bcache (struct macro_table *t, const void *addr, int len)
 static const char *
 macro_bcache_str (struct macro_table *t, const char *s)
 {
-  return macro_bcache (t, s, strlen (s) + 1);
+  return (const char *) macro_bcache (t, s, strlen (s) + 1);
 }
 
 
@@ -353,7 +352,7 @@ new_macro_key (struct macro_table *t,
                struct macro_source_file *file,
                int line)
 {
-  struct macro_key *k = macro_alloc (sizeof (*k), t);
+  struct macro_key *k = (struct macro_key *) macro_alloc (sizeof (*k), t);
 
   memset (k, 0, sizeof (*k));
   k->table = t;
@@ -386,7 +385,8 @@ new_source_file (struct macro_table *t,
                  const char *filename)
 {
   /* Get space for the source file structure itself.  */
-  struct macro_source_file *f = macro_alloc (sizeof (*f), t);
+  struct macro_source_file *f
+    = (struct macro_source_file *) macro_alloc (sizeof (*f), t);
 
   memset (f, 0, sizeof (*f));
   f->table = t;
@@ -451,7 +451,7 @@ macro_include (struct macro_source_file *source,
                int line,
                const char *included)
 {
-  struct macro_source_file *new;
+  struct macro_source_file *newobj;
   struct macro_source_file **link;
 
   /* Find the right position in SOURCE's `includes' list for the new
@@ -497,13 +497,13 @@ macro_include (struct macro_source_file *source,
   /* At this point, we know that LINE is an unused line number, and
      *LINK points to the entry an #inclusion at that line should
      precede.  */
-  new = new_source_file (source->table, included);
-  new->included_by = source;
-  new->included_at_line = line;
-  new->next_included = *link;
-  *link = new;
+  newobj = new_source_file (source->table, included);
+  newobj->included_by = source;
+  newobj->included_at_line = line;
+  newobj->next_included = *link;
+  *link = newobj;
 
-  return new;
+  return newobj;
 }
 
 
@@ -554,7 +554,8 @@ new_macro_definition (struct macro_table *t,
                       int argc, const char **argv,
                       const char *replacement)
 {
-  struct macro_definition *d = macro_alloc (sizeof (*d), t);
+  struct macro_definition *d
+    = (struct macro_definition *) macro_alloc (sizeof (*d), t);
 
   memset (d, 0, sizeof (*d));
   d->table = t;
@@ -569,12 +570,13 @@ new_macro_definition (struct macro_table *t,
       int cached_argv_size = argc * sizeof (*cached_argv);
 
       /* Bcache all the arguments.  */
-      cached_argv = alloca (cached_argv_size);
+      cached_argv = (const char **) alloca (cached_argv_size);
       for (i = 0; i < argc; i++)
         cached_argv[i] = macro_bcache_str (t, argv[i]);
 
       /* Now bcache the array of argument pointers itself.  */
-      d->argv = macro_bcache (t, cached_argv, cached_argv_size);
+      d->argv = ((const char * const *)
+                macro_bcache (t, cached_argv, cached_argv_size));
     }
 
   /* We don't bcache the entire definition structure because it's got
@@ -963,8 +965,7 @@ macro_definition_location (struct macro_source_file *source,
    the FILE and LINE fields.  */
 struct macro_for_each_data
 {
-  macro_callback_fn fn;
-  void *user_data;
+  gdb::function_view<macro_callback_fn> fn;
   struct macro_source_file *file;
   int line;
 };
@@ -983,20 +984,18 @@ foreach_macro (splay_tree_node node, void *arg)
                          (struct macro_definition *) node->value);
   xfree (key_fullname);
 
-  (*datum->fn) (key->name, def, key->start_file, key->start_line,
-               datum->user_data);
+  datum->fn (key->name, def, key->start_file, key->start_line);
   return 0;
 }
 
 /* Call FN for every macro in TABLE.  */
 void
-macro_for_each (struct macro_table *table, macro_callback_fn fn,
-               void *user_data)
+macro_for_each (struct macro_table *table,
+               gdb::function_view<macro_callback_fn> fn)
 {
   struct macro_for_each_data datum;
 
   datum.fn = fn;
-  datum.user_data = user_data;
   datum.file = NULL;
   datum.line = 0;
   splay_tree_foreach (table->definitions, foreach_macro, &datum);
@@ -1022,20 +1021,18 @@ foreach_macro_in_scope (splay_tree_node node, void *info)
       && (!key->end_file
          || compare_locations (key->end_file, key->end_line,
                                datum->file, datum->line) >= 0))
-    (*datum->fn) (key->name, def, key->start_file, key->start_line,
-                 datum->user_data);
+    datum->fn (key->name, def, key->start_file, key->start_line);
   return 0;
 }
 
 /* Call FN for every macro is visible in SCOPE.  */
 void
 macro_for_each_in_scope (struct macro_source_file *file, int line,
-                        macro_callback_fn fn, void *user_data)
+                        gdb::function_view<macro_callback_fn> fn)
 {
   struct macro_for_each_data datum;
 
   datum.fn = fn;
-  datum.user_data = user_data;
   datum.file = file;
   datum.line = line;
   splay_tree_foreach (file->table->definitions,
@@ -1049,21 +1046,21 @@ macro_for_each_in_scope (struct macro_source_file *file, int line,
 
 struct macro_table *
 new_macro_table (struct obstack *obstack, struct bcache *b,
-                const char *comp_dir)
+                struct compunit_symtab *cust)
 {
   struct macro_table *t;
 
   /* First, get storage for the `struct macro_table' itself.  */
   if (obstack)
-    t = obstack_alloc (obstack, sizeof (*t));
+    t = XOBNEW (obstack, struct macro_table);
   else
-    t = xmalloc (sizeof (*t));
+    t = XNEW (struct macro_table);
 
   memset (t, 0, sizeof (*t));
   t->obstack = obstack;
   t->bcache = b;
   t->main_source = NULL;
-  t->comp_dir = comp_dir;
+  t->compunit_symtab = cust;
   t->redef_ok = 0;
   t->definitions = (splay_tree_new_with_allocator
                     (macro_tree_compare,
@@ -1092,8 +1089,13 @@ free_macro_table (struct macro_table *table)
 char *
 macro_source_fullname (struct macro_source_file *file)
 {
-  if (file->table->comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
+  const char *comp_dir = NULL;
+
+  if (file->table->compunit_symtab != NULL)
+    comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
+
+  if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
     return xstrdup (file->filename);
 
-  return concat (file->table->comp_dir, SLASH_STRING, file->filename, NULL);
+  return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL);
 }
This page took 0.026234 seconds and 4 git commands to generate.