1 /* Code dealing with "using" directives for GDB.
2 Copyright (C) 2003-2016 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
20 #include "namespace.h"
22 /* Add a using directive to USING_DIRECTIVES. If the using directive
23 in question has already been added, don't add it twice.
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. */
37 add_using_directive (struct using_direct
**using_directives
,
41 const char *declaration
,
42 VEC (const_char_ptr
) *excludes
,
44 struct obstack
*obstack
)
46 struct using_direct
*current
;
47 struct using_direct
*newobj
;
50 /* Has it already been added? */
52 for (current
= *using_directives
; current
!= NULL
; current
= current
->next
)
57 if (strcmp (current
->import_src
, src
) != 0)
59 if (strcmp (current
->import_dest
, dest
) != 0)
61 if ((alias
== NULL
&& current
->alias
!= NULL
)
62 || (alias
!= NULL
&& current
->alias
== NULL
)
63 || (alias
!= NULL
&& current
->alias
!= NULL
64 && strcmp (alias
, current
->alias
) != 0))
66 if ((declaration
== NULL
&& current
->declaration
!= NULL
)
67 || (declaration
!= NULL
&& current
->declaration
== NULL
)
68 || (declaration
!= NULL
&& current
->declaration
!= NULL
69 && strcmp (declaration
, current
->declaration
) != 0))
72 /* Compare the contents of EXCLUDES. */
73 for (ix
= 0; VEC_iterate (const_char_ptr
, excludes
, ix
, param
); ix
++)
74 if (current
->excludes
[ix
] == NULL
75 || strcmp (param
, current
->excludes
[ix
]) != 0)
77 if (ix
< VEC_length (const_char_ptr
, excludes
)
78 || current
->excludes
[ix
] != NULL
)
81 /* Parameters exactly match CURRENT. */
85 alloc_len
= (sizeof(*newobj
)
86 + (VEC_length (const_char_ptr
, excludes
)
87 * sizeof(*newobj
->excludes
)));
88 newobj
= (struct using_direct
*) obstack_alloc (obstack
, alloc_len
);
89 memset (newobj
, 0, sizeof (*newobj
));
94 = (const char *) obstack_copy0 (obstack
, src
, strlen (src
));
96 = (const char *) obstack_copy0 (obstack
, dest
, strlen (dest
));
100 newobj
->import_src
= src
;
101 newobj
->import_dest
= dest
;
104 if (alias
!= NULL
&& copy_names
)
106 = (const char *) obstack_copy0 (obstack
, alias
, strlen (alias
));
108 newobj
->alias
= alias
;
110 if (declaration
!= NULL
&& copy_names
)
112 = (const char *) obstack_copy0 (obstack
, declaration
,
113 strlen (declaration
));
115 newobj
->declaration
= declaration
;
117 memcpy (newobj
->excludes
, VEC_address (const_char_ptr
, excludes
),
118 VEC_length (const_char_ptr
, excludes
) * sizeof (*newobj
->excludes
));
119 newobj
->excludes
[VEC_length (const_char_ptr
, excludes
)] = NULL
;
121 newobj
->next
= *using_directives
;
122 *using_directives
= newobj
;
This page took 0.032411 seconds and 4 git commands to generate.