+2002-10-15 David Carlton <carlton@math.stanford.edu>
+
+ * symtab.c (lookup_symbol_aux_using_loop): prefix_len should be <=
+ outer_length.
+ (lookup_symbol_aux_using_loop): Don't skip colons in rest_of_outer
+ if we've used all of outer.
+ * cp-support.h: Rename declaration of cp_add_using to
+ cp_add_using_obstack.
+ * cp-support.c (cp_add_using_obstack): Rename from cp_add_using.
+ * buildsym.h: Rename arguments in declaration of
+ add_using_directive.
+ * buildsym.c (add_using_directive): Finish definition, rename
+ arguments.
+ * cp-support.h: Add declaration for cp_add_using_xmalloc.
+ * cp-support.c (cp_add_using_xmalloc): New function.
+ * buildsym.c (copy_usings_to_obstack): New function.
+ (end_symtab): Set STATIC_BLOCK's BLOCK_USING using
+ copy_usings_to_obstack.
+
2002-10-14 David Carlton <carlton@math.stanford.edu>
* buildsym.c (add_using_directive): Rewrite to match new version
of struct using_direct.
(finish_block): Ditto.
-
* symtab.c (lookup_symbol_aux_using_loop): Add 'prefix_len'
argument; rewrite to match new version of struct using_direct.
-
* cp-support.h: Update declaration for cp_add_using.
-
* cp-support.c (cp_add_using): Rewrite to match new version of
struct using_direct.
-
* cp-support.h (struct using_direct): Rewrite struct.
-
* buildsym.h: Declaration for add_using_directive.
-
* buildsym.c: New variable 'using_list'.
(start_symtab): Initialize using_list.
(end_symtab): Initialize BLOCK_USING of STATIC_BLOCK.
static int compare_line_numbers (const void *ln1p, const void *ln2p);
static void scan_for_anonymous_namespaces (struct symbol *symbol);
+
+static struct using_direct_node *copy_usings_to_obstack (struct
+ using_direct_node
+ *usings,
+ struct obstack
+ *obstack);
\f
/* Initial sizes of data structures. These are realloc'd larger if
}
}
-/* Add a symbol to one of the lists of symbols. While we're at it,
- check to see if it references an anonymous namespace; if so, add an
- appropriate using directive. */
+/* Add a symbol to one of the lists of symbols. While we're at it, if
+ we're in the C++ case, check to see if it references an anonymous
+ namespace; if so, add an appropriate using directive. */
void
add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
/* Check to see if we might need to look for a mention of anonymous
namespaces. */
- /* TODOTODO */
-/* if (SYMBOL_LANGUAGE (symbol) == language_cplus */
-/* && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) */
-/* scan_for_anonymous_namespaces (symbol) */
+
+ if (SYMBOL_LANGUAGE (symbol) == language_cplus
+ && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
+ scan_for_anonymous_namespaces (symbol);
}
/* Check to see if a symbol is contained within an anonymous
for (beginning = name, end = cp_find_first_component (name);
*end == ':';
- /* The "+ 2" is for ':'. */
+ /* The "+ 2" is for the "::"-. */
beginning = end + 2, end = cp_find_first_component (beginning))
{
if ((end - beginning) == ANONYMOUS_NAMESPACE_LEN
/* This adds a using directive to using_list. NAME is the start of a
string that should contain the namespaces we want to add as initial
- substrings, OUTER_INDEX is the end of the outer namespace, and
- INNER_INDEX is the end of the inner namespace. If the using
+ substrings, OUTER_LENGTH is the end of the outer namespace, and
+ INNER_LENGTH is the end of the inner namespace. If the using
directive in question has already been added, don't add it
twice. */
void
-add_using_directive (const char *name, unsigned int outer_index,
- unsigned int inner_index)
+add_using_directive (const char *name, unsigned int outer_length,
+ unsigned int inner_length)
{
struct using_direct_node *current;
+ struct using_direct_node *new_node;
+ struct using_direct *new;
- gdb_assert (outer_index < inner_index);
+ gdb_assert (outer_length < inner_length);
/* Has it already been added? */
for (current = using_list; current; current = current->next)
- if (strncmp (current->current->name, name, outer_index) == 0
- && strncmp (current->current->name, name, inner_index) == 0)
+ if (current->current->outer_length == outer_length
+ && current->current->inner_length == inner_length
+ && (strncmp (current->current->name, name, inner_length) == 0))
return;
- /* TODOTODO */
+ using_list = cp_add_using_xmalloc (name, outer_length, inner_length,
+ using_list);
}
next = cp_find_first_component (next + 2))
{
BLOCK_USING (block)
- = cp_add_using (name, 0, next - name, BLOCK_USING (block),
- &objfile->symbol_obstack);
+ = cp_add_using_obstack (name, 0, next - name,
+ BLOCK_USING (block),
+ &objfile->symbol_obstack);
}
/* FIMXE: carlton/2002-10-09: Until I understand the
finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
objfile);
blockvector = make_blockvector (objfile);
- /* TODOTODO */
-/* BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK)) */
-/* = cp_copy_usings_obstack (using_list, &objfile->symbol_obstack); */
-/* cp_deep_free_usings (using_list); */
+ if (using_list != NULL)
+ {
+ BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK))
+ = copy_usings_to_obstack (using_list,
+ &objfile->symbol_obstack);
+ using_list = NULL;
+ }
}
#ifndef PROCESS_LINENUMBER_HOOK
return symtab;
}
+/* This reallocates USINGS using OBSTACK and xfree's USINGS. It
+ returns the reallocated version of USINGS. */
+
+static struct using_direct_node *
+copy_usings_to_obstack (struct using_direct_node *usings,
+ struct obstack *obstack)
+{
+ if (usings == NULL)
+ return NULL;
+ else
+ {
+ struct using_direct_node *new_node
+ = cp_add_using_obstack (usings->current->name,
+ usings->current->outer_length,
+ usings->current->inner_length,
+ copy_usings_to_obstack (usings->next,
+ obstack),
+ obstack);
+
+ xfree (usings->current);
+ xfree (usings);
+
+ return new_node;
+ }
+}
+
/* Search the block for global symbols indicating the presence of
anonymous namespaces; add using declarations for them, if
found. */
extern struct symbol *find_symbol_in_list (struct pending *list,
char *name, int length);
-extern void add_using_directive (const char *name, unsigned int outer_index,
- unsigned int inner_index);
+extern void add_using_directive (const char *name, unsigned int outer_length,
+ unsigned int inner_length);
extern void finish_block (struct symbol *symbol,
struct pending **listhead,
using_direct_node. All memory is allocated using OBSTACK. */
struct using_direct_node *
-cp_add_using (const char *name,
- unsigned short outer_length,
- unsigned short inner_length,
- struct using_direct_node *next,
- struct obstack *obstack)
+cp_add_using_obstack (const char *name,
+ unsigned short outer_length,
+ unsigned short inner_length,
+ struct using_direct_node *next,
+ struct obstack *obstack)
{
struct using_direct *current
= obstack_alloc (obstack, sizeof (struct using_direct));
return retval;
}
+/* Same as cp_add_using, except that it uses xmalloc instead of
+ obstacks. */
+
+struct using_direct_node *
+cp_add_using_xmalloc (const char *name,
+ unsigned short outer_length,
+ unsigned short inner_length,
+ struct using_direct_node *next)
+{
+ struct using_direct *current = xmalloc (sizeof (struct using_direct));
+ struct using_direct_node *retval
+ = xmalloc (sizeof (struct using_direct_node));
+
+ gdb_assert (outer_length < inner_length);
+
+ current->name = name;
+ current->outer_length = outer_length;
+ current->inner_length = inner_length;
+ retval->current = current;
+ retval->next = next;
+
+ return retval;
+}
+
/* This copies the using_direct_nodes in TOCOPY, using xmalloc, and
- sticks them onto a list ending in TAIL. */
+ sticks them onto a list ending in TAIL. (It doesn't copy the
+ using_directs, just the using_direct_nodes.) */
struct using_direct_node *
cp_copy_usings (struct using_direct_node *tocopy,
struct using_direct_node *next;
};
-extern struct using_direct_node *cp_add_using (const char *name,
- unsigned short outer_length,
- unsigned short inner_length,
- struct using_direct_node *next,
- struct obstack *obstack);
+extern struct
+using_direct_node *cp_add_using_obstack (const char *name,
+ unsigned short outer_length,
+ unsigned short inner_length,
+ struct using_direct_node *next,
+ struct obstack *obstack);
+
+extern
+struct using_direct_node *cp_add_using_xmalloc (const char *name,
+ unsigned short outer_length,
+ unsigned short inner_length,
+ struct using_direct_node
+ *next);
extern
struct using_direct_node *cp_copy_usings (struct using_direct_node *tocopy,
{
/* First, see if the prefix matches the start of this using
directive. */
- if (prefix_len >= current->current->outer_length
+ if (prefix_len <= current->current->outer_length
&& strncmp (prefix, current->current->name, prefix_len) == 0)
{
/* Great, it matches: now does the rest of the using
const char *rest_of_outer = current->current->name + prefix_len;
int rest_of_outer_len
= current->current->outer_length - prefix_len;
- /* Should we skip some colons? (Should always be true
- unless PREFIX_LEN is zero (and hence we're in the global
- namespace.) */
- if (*rest_of_outer == ':')
+ /* Should we skip some colons? Should be true unless
+ PREFIX_LEN is zero (and hence we're in the global
+ namespace) or we've finished all of outer. */
+ if (rest_of_outer_len != 0 && *rest_of_outer == ':')
{
rest_of_outer += 2;
rest_of_outer_len -= 2;
+2002-10-15 David Carlton <carlton@math.stanford.edu>
+
+ * gdb.c++/namespace.exp: Add anonymous namespace tests.
+ * gdb.c++/namespace.cc: Add anonymous namespaces.
+
2002-10-11 David Carlton <carlton@math.stanford.edu>
* gdb.c++/namespace.exp: Add tests from within C::D::marker2.
return;
}
+namespace
+{
+ int X = 9;
+
+ namespace G
+ {
+ int Xg = 10;
+
+ namespace
+ {
+ int XgX = 11;
+ }
+ }
+}
+
namespace C
{
int c = 1;
+ namespace
+ {
+ int cX = 6;
+
+ namespace F
+ {
+ int cXf = 7;
+
+ namespace
+ {
+ int cXfX = 8;
+ }
+ }
+ }
+
namespace C
{
int cc = 2;
cd;
E::cde;
//E::ce;
+ cX;
+ F::cXf;
+ F::cXfX;
+ X;
+ G::Xg;
+ G::XgX;
return;
}
}
}
-
int main ()
{
using AAA::inA;
# FIXME: carlton/2002-10-11: It would be nice to test printing
# "E::ce", but unfortunately GDB will print it out even though it
# shouldn't. Oops.
+
+gdb_test "print cX" "\\$\[0-9\].* = 6" "print cX"
+gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" "print F::cXf"
+gdb_test "print 'F::cXfX'" "\\$\[0-9\].* = 8" "print F::cXfX"
+gdb_test "print X" "\\$\[0-9\].* = 9" "print X"
+gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" "print G::Xg"
+gdb_test "print 'G::XgX'" "\\$\[0-9\].* = 11" "print G::XgX"