2015-07-22 15:30:57 +02:00
|
|
|
/* Code dealing with "using" directives for GDB.
|
2019-01-01 07:01:51 +01:00
|
|
|
Copyright (C) 2003-2019 Free Software Foundation, Inc.
|
2015-07-22 15:30:57 +02:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "namespace.h"
|
|
|
|
|
|
|
|
/* Add a using directive to USING_DIRECTIVES. If the using directive
|
|
|
|
in question has already been added, don't add it twice.
|
|
|
|
|
|
|
|
Create a new struct using_direct which imports the namespace SRC
|
|
|
|
into the scope DEST. ALIAS is the name of the imported namespace
|
|
|
|
in the current scope. If ALIAS is NULL then the namespace is known
|
|
|
|
by its original name. DECLARATION is the name if the imported
|
|
|
|
varable if this is a declaration import (Eg. using A::x), otherwise
|
|
|
|
it is NULL. EXCLUDES is a list of names not to import from an
|
|
|
|
imported module or NULL. If COPY_NAMES is non-zero, then the
|
|
|
|
arguments are copied into newly allocated memory so they can be
|
|
|
|
temporaries. For EXCLUDES the VEC pointers are copied but the
|
|
|
|
pointed to characters are not copied. */
|
|
|
|
|
|
|
|
void
|
|
|
|
add_using_directive (struct using_direct **using_directives,
|
|
|
|
const char *dest,
|
|
|
|
const char *src,
|
|
|
|
const char *alias,
|
|
|
|
const char *declaration,
|
2017-09-07 01:18:23 +02:00
|
|
|
const std::vector<const char *> &excludes,
|
2015-07-22 15:30:57 +02:00
|
|
|
int copy_names,
|
|
|
|
struct obstack *obstack)
|
|
|
|
{
|
|
|
|
struct using_direct *current;
|
|
|
|
struct using_direct *newobj;
|
2015-09-25 20:08:06 +02:00
|
|
|
int alloc_len;
|
2015-07-22 15:30:57 +02:00
|
|
|
|
|
|
|
/* Has it already been added? */
|
|
|
|
|
|
|
|
for (current = *using_directives; current != NULL; current = current->next)
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
if (strcmp (current->import_src, src) != 0)
|
|
|
|
continue;
|
|
|
|
if (strcmp (current->import_dest, dest) != 0)
|
|
|
|
continue;
|
|
|
|
if ((alias == NULL && current->alias != NULL)
|
|
|
|
|| (alias != NULL && current->alias == NULL)
|
|
|
|
|| (alias != NULL && current->alias != NULL
|
|
|
|
&& strcmp (alias, current->alias) != 0))
|
|
|
|
continue;
|
|
|
|
if ((declaration == NULL && current->declaration != NULL)
|
|
|
|
|| (declaration != NULL && current->declaration == NULL)
|
|
|
|
|| (declaration != NULL && current->declaration != NULL
|
|
|
|
&& strcmp (declaration, current->declaration) != 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Compare the contents of EXCLUDES. */
|
2017-09-07 01:18:23 +02:00
|
|
|
for (ix = 0; ix < excludes.size (); ++ix)
|
2015-07-22 15:30:57 +02:00
|
|
|
if (current->excludes[ix] == NULL
|
2017-09-07 01:18:23 +02:00
|
|
|
|| strcmp (excludes[ix], current->excludes[ix]) != 0)
|
2015-07-22 15:30:57 +02:00
|
|
|
break;
|
2017-09-07 01:18:23 +02:00
|
|
|
if (ix < excludes.size () || current->excludes[ix] != NULL)
|
2015-07-22 15:30:57 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Parameters exactly match CURRENT. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-25 20:08:06 +02:00
|
|
|
alloc_len = (sizeof(*newobj)
|
2017-09-07 01:18:23 +02:00
|
|
|
+ (excludes.size () * sizeof(*newobj->excludes)));
|
2015-09-25 20:08:06 +02:00
|
|
|
newobj = (struct using_direct *) obstack_alloc (obstack, alloc_len);
|
2015-07-22 15:30:57 +02:00
|
|
|
memset (newobj, 0, sizeof (*newobj));
|
|
|
|
|
|
|
|
if (copy_names)
|
|
|
|
{
|
2015-09-25 20:08:06 +02:00
|
|
|
newobj->import_src
|
|
|
|
= (const char *) obstack_copy0 (obstack, src, strlen (src));
|
|
|
|
newobj->import_dest
|
|
|
|
= (const char *) obstack_copy0 (obstack, dest, strlen (dest));
|
2015-07-22 15:30:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newobj->import_src = src;
|
|
|
|
newobj->import_dest = dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alias != NULL && copy_names)
|
2015-09-25 20:08:06 +02:00
|
|
|
newobj->alias
|
|
|
|
= (const char *) obstack_copy0 (obstack, alias, strlen (alias));
|
2015-07-22 15:30:57 +02:00
|
|
|
else
|
|
|
|
newobj->alias = alias;
|
|
|
|
|
|
|
|
if (declaration != NULL && copy_names)
|
2015-09-25 20:08:06 +02:00
|
|
|
newobj->declaration
|
|
|
|
= (const char *) obstack_copy0 (obstack, declaration,
|
|
|
|
strlen (declaration));
|
2015-07-22 15:30:57 +02:00
|
|
|
else
|
|
|
|
newobj->declaration = declaration;
|
|
|
|
|
2018-07-27 01:48:40 +02:00
|
|
|
if (!excludes.empty ())
|
|
|
|
memcpy (newobj->excludes, excludes.data (),
|
|
|
|
excludes.size () * sizeof (*newobj->excludes));
|
2017-09-07 01:18:23 +02:00
|
|
|
newobj->excludes[excludes.size ()] = NULL;
|
2015-07-22 15:30:57 +02:00
|
|
|
|
|
|
|
newobj->next = *using_directives;
|
|
|
|
*using_directives = newobj;
|
|
|
|
}
|