GDB (xrefs)
/tmp/gdb-8.1/gdb/namespace.c
Go to the documentation of this file.
1 /* Code dealing with "using" directives for GDB.
2  Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 
4  This file is part of GDB.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 
19 #include "defs.h"
20 #include "namespace.h"
21 
22 /* Add a using directive to USING_DIRECTIVES. If the using directive
23  in question has already been added, don't add it twice.
24 
25  Create a new struct using_direct which imports the namespace SRC
26  into the scope DEST. ALIAS is the name of the imported namespace
27  in the current scope. If ALIAS is NULL then the namespace is known
28  by its original name. DECLARATION is the name if the imported
29  varable if this is a declaration import (Eg. using A::x), otherwise
30  it is NULL. EXCLUDES is a list of names not to import from an
31  imported module or NULL. If COPY_NAMES is non-zero, then the
32  arguments are copied into newly allocated memory so they can be
33  temporaries. For EXCLUDES the VEC pointers are copied but the
34  pointed to characters are not copied. */
35 
36 void
38  const char *dest,
39  const char *src,
40  const char *alias,
41  const char *declaration,
42  const std::vector<const char *> &excludes,
43  int copy_names,
44  struct obstack *obstack)
45 {
46  struct using_direct *current;
47  struct using_direct *newobj;
48  int alloc_len;
49 
50  /* Has it already been added? */
51 
52  for (current = *using_directives; current != NULL; current = current->next)
53  {
54  int ix;
55 
56  if (strcmp (current->import_src, src) != 0)
57  continue;
58  if (strcmp (current->import_dest, dest) != 0)
59  continue;
60  if ((alias == NULL && current->alias != NULL)
61  || (alias != NULL && current->alias == NULL)
62  || (alias != NULL && current->alias != NULL
63  && strcmp (alias, current->alias) != 0))
64  continue;
65  if ((declaration == NULL && current->declaration != NULL)
66  || (declaration != NULL && current->declaration == NULL)
67  || (declaration != NULL && current->declaration != NULL
68  && strcmp (declaration, current->declaration) != 0))
69  continue;
70 
71  /* Compare the contents of EXCLUDES. */
72  for (ix = 0; ix < excludes.size (); ++ix)
73  if (current->excludes[ix] == NULL
74  || strcmp (excludes[ix], current->excludes[ix]) != 0)
75  break;
76  if (ix < excludes.size () || current->excludes[ix] != NULL)
77  continue;
78 
79  /* Parameters exactly match CURRENT. */
80  return;
81  }
82 
83  alloc_len = (sizeof(*newobj)
84  + (excludes.size () * sizeof(*newobj->excludes)));
85  newobj = (struct using_direct *) obstack_alloc (obstack, alloc_len);
86  memset (newobj, 0, sizeof (*newobj));
87 
88  if (copy_names)
89  {
90  newobj->import_src
91  = (const char *) obstack_copy0 (obstack, src, strlen (src));
92  newobj->import_dest
93  = (const char *) obstack_copy0 (obstack, dest, strlen (dest));
94  }
95  else
96  {
97  newobj->import_src = src;
98  newobj->import_dest = dest;
99  }
100 
101  if (alias != NULL && copy_names)
102  newobj->alias
103  = (const char *) obstack_copy0 (obstack, alias, strlen (alias));
104  else
105  newobj->alias = alias;
106 
107  if (declaration != NULL && copy_names)
108  newobj->declaration
109  = (const char *) obstack_copy0 (obstack, declaration,
110  strlen (declaration));
111  else
112  newobj->declaration = declaration;
113 
114  memcpy (newobj->excludes, excludes.data (),
115  excludes.size () * sizeof (*newobj->excludes));
116  newobj->excludes[excludes.size ()] = NULL;
117 
118  newobj->next = *using_directives;
119  *using_directives = newobj;
120 }
const char * import_dest
Definition: namespace.h:93
const char * alias
Definition: namespace.h:95
const char * import_src
Definition: namespace.h:92
const char * alias
Definition: nds32-tdep.c:114
void * memset(T *s, int c, size_t n)=delete
const char * excludes[1]
Definition: namespace.h:106
struct using_direct * next
Definition: namespace.h:98
void add_using_directive(struct using_direct **using_directives, const char *dest, const char *src, const char *alias, const char *declaration, const std::vector< const char *> &excludes, int copy_names, struct obstack *obstack)
Definition: namespace.c:37
static struct using_direct ** using_directives(enum language)
Definition: dwarf2read.c:11233
const char * declaration
Definition: namespace.h:96