* valops.c (find_oload_champ): Add comment.
(find_oload_champ_namespace_loop): Fix memory management.
(find_oload_champ_namespace): Add comment.
(find_overload_match): Free oload_syms, oload_champ_bv.
* gdbtypes.c (rank_function): Add comment.
* valops.c (find_oload_champ_namespace_loop): Allow num_fns to be
zero.
* symtab.c (lookup_partial_symbol): Use strcmp_iw_ordered.
(lookup_block_symbol): Delete comment.
* symfile.c (compare_psymbols): Use strcmp_iw_ordered.
* defs.h: Declare strcmp_iw_ordered.
* utils.c (strcmp_iw_ordered): New function.
+2003-02-11 David Carlton <carlton@math.stanford.edu>
+
+ * valops.c (find_oload_champ): Add comment.
+ (find_oload_champ_namespace_loop): Fix memory management.
+ (find_oload_champ_namespace): Add comment.
+ (find_overload_match): Free oload_syms, oload_champ_bv.
+ * gdbtypes.c (rank_function): Add comment.
+ * valops.c (find_oload_champ_namespace_loop): Allow num_fns to be
+ zero.
+ * symtab.c (lookup_partial_symbol): Use strcmp_iw_ordered.
+ (lookup_block_symbol): Delete comment.
+ * symfile.c (compare_psymbols): Use strcmp_iw_ordered.
+ * defs.h: Declare strcmp_iw_ordered.
+ * utils.c (strcmp_iw_ordered): New function.
+
+2003-02-10 David Carlton <carlton@math.stanford.edu>
+
+ * symtab.c (read_in_psymtabs): Only read in symtabs where we find
+ a matching symbol.
+
2003-02-07 David Carlton <carlton@math.stanford.edu>
- * gdb_mbuild.sh (keep): Delete extra shift after -f.
+ * gdb_mbuild.sh: Delete extra shift after -f.
* Merge with mainline; tag is carlton_dictionary-20030207-merge.
extern int strcmp_iw (const char *, const char *);
+extern int strcmp_iw_ordered (const char *, const char *);
+
extern int streq (const char *, const char *);
extern int subset_compare (char *, char *);
}
}
-/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
- * to the types of an argument list (ARGS, length NARGS).
- * Return a pointer to a badness vector. This has NARGS + 1 entries. */
+/* Rank a function by comparing its parameter types (PARMS, length
+ NPARMS), to the types of an argument list (ARGS, length NARGS).
+ Return a pointer to a badness vector. This has NARGS + 1
+ entries.
+
+ It is the caller's responsibility to free the return value. */
struct badness_vector *
rank_function (struct type **parms, int nparms, struct type **args, int nargs)
return (strcmp (SYMBOL_BEST_NAME (*s1), SYMBOL_BEST_NAME (*s2)));
}
-/*
-
- LOCAL FUNCTION
-
- compare_psymbols -- compare two partial symbols by name
-
- DESCRIPTION
-
- Given pointers to pointers to two partial symbol table entries,
- compare them by name and return -N, 0, or +N (ala strcmp).
- Typically used by sorting routines like qsort().
-
- NOTES
-
- Does direct compare of first two characters before punting
- and passing to strcmp for longer compares. Note that the
- original version had a bug whereby two null strings or two
- identically named one character strings would return the
- comparison of memory following the null byte.
-
- */
+/* This compares two partial symbols by names, using strcmp_iw_ordered
+ for the comparison. */
static int
compare_psymbols (const void *s1p, const void *s2p)
{
- register struct partial_symbol **s1, **s2;
- register const char *st1, *st2;
-
- s1 = (struct partial_symbol **) s1p;
- s2 = (struct partial_symbol **) s2p;
- st1 = SYMBOL_BEST_NAME (*s1);
- st2 = SYMBOL_BEST_NAME (*s2);
+ struct partial_symbol *const *s1 = s1p;
+ struct partial_symbol *const *s2 = s2p;
-
- if ((st1[0] - st2[0]) || !st1[0])
- {
- return (st1[0] - st2[0]);
- }
- else if ((st1[1] - st2[1]) || !st1[1])
- {
- return (st1[1] - st2[1]);
- }
- else
- {
- return (strcmp (st1, st2));
- }
+ return strcmp_iw_ordered (SYMBOL_BEST_NAME (*s1),
+ SYMBOL_BEST_NAME (*s2));
}
void
do_linear_search = 0;
/* Binary search. This search is guaranteed to end with center
- pointing at the earliest partial symbol with the correct
- name. At that point *all* partial symbols with that name
+ pointing at the earliest partial symbol whose name might be
+ correct. At that point *all* partial symbols with that name
will be checked against the correct namespace. */
bottom = start;
{
do_linear_search = 1;
}
- if (strcmp (SYMBOL_BEST_NAME (*center), name) >= 0)
+ if (strcmp_iw_ordered (SYMBOL_BEST_NAME (*center), name) >= 0)
{
top = center;
}
this particular linkage name.
*/
-/* FIXME: carlton/2002-09-26: I've slightly changed the semantics: I
- replaced a call to SYMBOL_MATCHES_NAME (sym, name) with a call to
- strcmp_iw (SYMBOL_BEST_NAME (sym), name) (inside the dict_iter_name
- functions). I think this is okay: the only situations where the
- new behavior should differ from the old behavior are where NAME is
- mangled (which shouldn't happen, right??? lookup_symbol always
- tries to demangle appropriately) or where the symbol we find
- doesn't have a demangled name and where the symbol's name is such
- that strcmp and strcmp_iw don't match on it (which seems unlikely
- to me). */
-
-/* NOTE: carlton/2003-01-14: No, there are situations where this is
- more generous: it ignores whitespace on demangled names, too. This
- is good: e.g. it makes recognizing templated types more generous.
- See PR gdb/33. */
-
struct symbol *
lookup_block_symbol (register const struct block *block, const char *name,
const char *linkage_name, const namespace_enum namespace)
/* Look through the partial symtabs for all symbols which begin
by matching FUNC_NAME. Make sure we read that symbol table in. */
-/* FIXME: carlton/2003-01-30. Lies, all lies. The function does
- nothing of the kind: it just reads in every single partial symtab.
- (It used to do it in a particularly amusing way, but I've fixed
- that.) */
-
static void
read_in_psymtabs (const char *func_name)
{
ALL_PSYMTABS (objfile, ps)
{
- if (!ps->readin)
+ if (ps->readin)
+ continue;
+
+ if ((lookup_partial_symbol (ps, func_name, 1, VAR_NAMESPACE) != NULL)
+ || (lookup_partial_symbol (ps, func_name, 0, VAR_NAMESPACE) != NULL))
psymtab_to_symtab (ps);
}
}
return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
}
+/* This is like strcmp except that it ignores whitespace and treats
+ '(' as the first non-NULL character in terms of ordering. Like
+ strcmp (and unlike strcmp_iw), it returns negative if STRING1 <
+ STRING2, 0 if STRING2 = STRING2, and positive if STRING1 > STRING2
+ according to that ordering.
+
+ If a list is sorted according to this function and if you want to
+ find names in the list that match some fixed NAME according to
+ strcmp_iw(LIST_ELT, NAME), then the place to start looking is right
+ where this function would put NAME. */
+
+int
+strcmp_iw_ordered (const char *string1, const char *string2)
+{
+ while ((*string1 != '\0') && (*string2 != '\0'))
+ {
+ while (isspace (*string1))
+ {
+ string1++;
+ }
+ while (isspace (*string2))
+ {
+ string2++;
+ }
+ if (*string1 != *string2)
+ {
+ break;
+ }
+ if (*string1 != '\0')
+ {
+ string1++;
+ string2++;
+ }
+ }
+
+ switch (*string1)
+ {
+ /* Characters are non-equal unless they're both '\0'; we want to
+ make sure we get the comparison right according to our
+ comparison in the cases where one of them is '\0' or '('. */
+ case '\0':
+ if (*string2 == '\0')
+ return 0;
+ else
+ return -1;
+ case '(':
+ if (*string2 == '\0')
+ return 1;
+ else
+ return -1;
+ default:
+ if (*string2 == '(')
+ return 1;
+ else
+ return *string1 - *string2;
+ }
+}
+
/* A simple comparison function with opposite semantics to strcmp. */
int
}
old_cleanups = make_cleanup (xfree, func_name);
+ make_cleanup (xfree, oload_syms);
+ make_cleanup (xfree, oload_champ_bv);
oload_champ = find_oload_champ_namespace (arg_types, nargs,
current_block,
contained in QUALIFIED_NAME until it either finds a good match or
runs out of namespaces. It stores the overloaded functions in
*OLOAD_SYMS, and the badness vector in *OLOAD_CHAMP_BV. The
- calling function is responsible for freeing *OLOAD_SYMS. */
+ calling function is responsible for freeing *OLOAD_SYMS and
+ *OLOAD_CHAMP_BV. */
static int
find_oload_champ_namespace (struct type **arg_types, int nargs,
/* Helper function for find_oload_champ_namespace; NAMESPACE_LEN is
how deep we've looked for namespaces, and the champ is stored in
OLOAD_CHAMP. The return value is 1 if the champ is a good one, 0
- if it isn't. */
+ if it isn't.
+
+ It is the caller's responsibility to free *OLOAD_SYMS and
+ *OLOAD_CHAMP_BV. */
/* FIXME: carlton/2003-01-30: This isn't the cleanest function I've
ever written, to put it mildly. All this overloading stuff could
= (cp_find_first_component (qualified_name + modified_namespace_len)
- qualified_name);
+ /* Initialize these to values that can safely be xfree'd. */
+ *oload_syms = NULL;
+ *oload_champ_bv = NULL;
+
/* First, see if we have a deeper namespace we can search in. If we
get a good match there, use it. */
function symbol to start off with.) */
old_cleanups = make_cleanup (xfree, *oload_syms);
+ old_cleanups = make_cleanup (xfree, *oload_champ_bv);
new_oload_syms = make_symbol_overload_list (func_name,
qualified_name,
namespace_len,
current_block);
- old_cleanups = make_cleanup (xfree, new_oload_syms);
while (new_oload_syms[num_fns])
++num_fns;
- if (!num_fns)
- error ("Couldn't find function %s", func_name);
new_oload_champ = find_oload_champ (arg_types, nargs, 0, num_fns,
- NULL, new_oload_syms,
+ NULL, new_oload_syms,
&new_oload_champ_bv);
/* Case 1: We found a good match. Free earlier matches (if any),
if (new_oload_champ != -1
&& classify_oload_match (new_oload_champ_bv, nargs, 0) == STANDARD)
{
- if (searched_deeper)
- xfree (*oload_syms);
*oload_syms = new_oload_syms;
*oload_champ = new_oload_champ;
*oload_champ_bv = new_oload_champ_bv;
- discard_cleanups (old_cleanups);
+ do_cleanups (old_cleanups);
return 1;
}
else if (searched_deeper)
{
xfree (new_oload_syms);
+ xfree (new_oload_champ_bv);
discard_cleanups (old_cleanups);
return 0;
}
(depending on METHOD) given by FNS_PTR or OLOAD_SYMS, respectively.
The number of methods/functions in the list is given by NUM_FNS.
Return the index of the best match; store an indication of the
- quality of the match in OLOAD_CHAMP_BV. */
+ quality of the match in OLOAD_CHAMP_BV.
+
+ It is the caller's responsibility to free *OLOAD_CHAMP_BV. */
static int
find_oload_champ (struct type **arg_types, int nargs, int method,