Skip to content

Commit

Permalink
-Use std::optional for symbol encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-gomez-windhover committed Oct 16, 2024
1 parent 8ad0f46 commit 718ab5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/SQLiteDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf)
*/
std::string writeSymbolQuery{};

if (!symbol->hasEncoding())
if (!symbol->getEncoding())
{
writeSymbolQuery +=
"INSERT INTO symbols(elf, name, byte_size, artifact, long_description, short_description) "
Expand Down Expand Up @@ -1242,8 +1242,7 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf)
writeSymbolQuery += ",";

writeSymbolQuery += "\"";
writeSymbolQuery += std::to_string(symbol->getElf().getDWARFEncoding(symbol->getEncoding()).getId());
// writeSymbolQuery += "-47";
writeSymbolQuery += std::to_string(symbol->getElf().getDWARFEncoding(symbol->getEncoding().value()).getId());
writeSymbolQuery += "\",";

writeSymbolQuery += std::to_string(symbol->getArtifact().getId());
Expand Down
14 changes: 7 additions & 7 deletions src/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,31 @@ bool Symbol::hasBitFields(void)
return hasBitField;
}

Artifact& Symbol::getArtifact() { return artifact; }
Artifact& Symbol::getArtifact() { return artifact; }

/**
* @brief Symbol::setTargetSymbol
* @note Might make sense to use std:optional for targetSymbol, however need to upgrade to C++17 first.
* @param newTargetSymbol
*/
void Symbol::setTargetSymbol(Symbol* newTargetSymbol) { targetSymbol = newTargetSymbol; }
void Symbol::setTargetSymbol(Symbol* newTargetSymbol) { targetSymbol = newTargetSymbol; }

/**
* @brief Symbol::hasTargetSymbol
* If this function returns false, then
* that means this is the concrete symbol not a typdef'd(aliased) symbol.
*/
bool Symbol::hasTargetSymbol() { return targetSymbol != nullptr; }
bool Symbol::hasTargetSymbol() { return targetSymbol != nullptr; }

Symbol* Symbol::getTargetSymbol() { return targetSymbol; }
Symbol* Symbol::getTargetSymbol() { return targetSymbol; }

/**
* @brief Symbol::setEncoding
* @param newEncoding an integer which is one of the values specified in
* in dwarf.h or in DWARF5 specification document section 5.1.1 titled "Base Type Encodings"
*/
void Symbol::setEncoding(int newEncoding) { encoding = newEncoding; }
void Symbol::setEncoding(int newEncoding) { encoding = newEncoding; }

bool Symbol::hasEncoding() { return encoding != -1; }
bool Symbol::hasEncoding() { return encoding != -1; }

int Symbol::getEncoding() { return encoding; }
std::optional<int> Symbol::getEncoding() { return encoding; }
4 changes: 2 additions & 2 deletions src/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Symbol

bool hasEncoding();

int getEncoding();
std::optional<int> getEncoding();

private:
ElfFile &elf;
Expand All @@ -87,7 +87,7 @@ class Symbol
std::string short_description;
std::string long_description;

int encoding{-1};
std::optional<int> encoding{std::nullopt};
};

#endif /* SYMBOL_H_ */

0 comments on commit 718ab5c

Please sign in to comment.