[v2,12/30] Add domain_search_flags
Checks
Commit Message
This adds a new flag enum type, domain_search_flags, which is the flag
version of domain_enum. Nothing uses this yet, but the goal here is
to have all symbol searches and lookups use these flags. The new
names are chosen to exactly parallel domain_enum.
---
gdb/symtab.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/symtab.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
@@ -331,6 +331,21 @@ search_domain_name (enum search_domain e)
/* See symtab.h. */
+std::string
+domain_name (domain_search_flags flags)
+{
+ static constexpr domain_search_flags::string_mapping mapping[] = {
+#define DOMAIN(X) \
+ MAP_ENUM_FLAG (SEARCH_ ## X ## _DOMAIN),
+#include "sym-domains.def"
+#undef DOMAIN
+ };
+
+ return flags.to_string (mapping);
+}
+
+/* See symtab.h. */
+
CORE_ADDR
linetable_entry::pc (const struct objfile *objfile) const
{
@@ -2666,6 +2681,41 @@ symbol_matches_domain (enum language symbol_language,
/* See symtab.h. */
+bool
+symbol::matches (domain_search_flags flags) const
+{
+ if (language () != language_c
+ && language () != language_objc
+ && language () != language_opencl)
+ {
+ /* Only C languages distinguish tag and type namespaces. */
+ if ((flags & SEARCH_TYPE_DOMAIN) != 0)
+ flags |= SEARCH_STRUCT_DOMAIN;
+ }
+
+ if ((flags & SEARCH_FUNCTION_DOMAIN) != 0
+ && domain () == VAR_DOMAIN
+ && aclass () == LOC_BLOCK)
+ return true;
+
+ if ((flags & SEARCH_VAR_DOMAIN) != 0
+ && domain () == VAR_DOMAIN)
+ return true;
+
+ if ((flags & SEARCH_TYPE_DOMAIN) != 0
+ && domain () == VAR_DOMAIN
+ && aclass () == LOC_TYPEDEF)
+ return true;
+
+ if ((flags & SEARCH_STRUCT_DOMAIN) != 0
+ && domain () == STRUCT_DOMAIN)
+ return true;
+
+ return search_flags_matches (flags, m_domain);
+}
+
+/* See symtab.h. */
+
struct type *
lookup_transparent_type (const char *name)
{
@@ -905,6 +905,48 @@ enum domain_enum
extern const char *domain_name (domain_enum);
+/* Flags used for searching symbol tables. These can be combined to
+ let the search match multiple kinds of symbol. */
+enum domain_search_flag
+{
+#define DOMAIN(X) \
+ SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN),
+#include "sym-domains.def"
+#undef DOMAIN
+};
+DEF_ENUM_FLAGS_TYPE (enum domain_search_flag, domain_search_flags);
+
+/* A convenience constant to search for any symbol. */
+constexpr domain_search_flags SEARCH_ALL
+ = ((domain_search_flags) 0
+#define DOMAIN(X) | SEARCH_ ## X ## _DOMAIN
+#include "sym-domains.def"
+#undef DOMAIN
+ );
+
+/* A convenience define for "C-like" name lookups, matching variables,
+ types, and functions. */
+#define SEARCH_VFT \
+ (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN)
+
+/* Return a string representing the given flags. */
+extern std::string domain_name (domain_search_flags);
+
+/* Convert a symbol domain to search flags. */
+static inline domain_search_flags
+to_search_flags (domain_enum domain)
+{
+ return domain_search_flags (domain_search_flag (1 << domain));
+}
+
+/* Return true if the given domain matches the given flags, false
+ otherwise. */
+static inline bool
+search_flags_matches (domain_search_flags flags, domain_enum domain)
+{
+ return (flags & to_search_flags (domain)) != 0;
+}
+
/* Searching domains, used when searching for symbols. Element numbers are
hardcoded in GDB, check all enum uses before changing it. */
@@ -1250,6 +1292,9 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
return symbol_matches_domain (language (), domain (), d);
}
+ /* Return true if this symbol's domain matches FLAGS. */
+ bool matches (domain_search_flags flags) const;
+
domain_enum domain () const
{
return m_domain;