From 6327a99aeed1e95ea67e8a5ec2ee9752b8ca5470 Mon Sep 17 00:00:00 2001 From: chaoticgd <43898262+chaoticgd@users.noreply.github.com> Date: Sat, 20 Jan 2024 05:35:59 +0000 Subject: [PATCH] Add SymbolDatabase::first_symbol_from_starting_address function --- src/ccc/symbol_database.cpp | 12 ++++++++---- src/ccc/symbol_database.h | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ccc/symbol_database.cpp b/src/ccc/symbol_database.cpp index edd1409..5d0e825 100644 --- a/src/ccc/symbol_database.cpp +++ b/src/ccc/symbol_database.cpp @@ -587,15 +587,19 @@ s32 SymbolDatabase::symbol_count() const return sum; } -bool SymbolDatabase::symbol_exists_with_starting_address(Address address) const +const Symbol* SymbolDatabase::first_symbol_from_starting_address(Address address) const { #define CCC_X(SymbolType, symbol_list) \ - if(symbol_list.first_handle_from_starting_address(address).valid()) { \ - return true; \ + if constexpr(SymbolType::FLAGS & WITH_ADDRESS_MAP) { \ + const SymbolHandle handle = symbol_list.first_handle_from_starting_address(address); \ + const SymbolType* symbol = symbol_list.symbol_from_handle(handle); \ + if(symbol) { \ + return symbol; \ + } \ } CCC_FOR_EACH_SYMBOL_TYPE_DO_X #undef CCC_X - return false; + return nullptr; } Result SymbolDatabase::get_symbol_source(const std::string& name) diff --git a/src/ccc/symbol_database.h b/src/ccc/symbol_database.h index dc7fe63..459a73b 100644 --- a/src/ccc/symbol_database.h +++ b/src/ccc/symbol_database.h @@ -550,8 +550,10 @@ class SymbolDatabase { // Sum up the symbol counts for each symbol list. s32 symbol_count() const; - // Check if a symbol has already been added to the database. - bool symbol_exists_with_starting_address(Address address) const; + // Find a symbol of any type that exists at the specified address. Symbols + // of the types specified higher up in the CCC_FOR_EACH_SYMBOL_TYPE_DO_X + // macro are checked for first. + const Symbol* first_symbol_from_starting_address(Address address) const; // Finds a symbol source object with the given name or creates one if it // doesn't already exist.