summaryrefslogtreecommitdiff
path: root/type.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-09-04 18:21:25 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2025-10-06 11:37:39 -0400
commitdc1094fb4a1f416a5e56bef4941a35bca3506865 (patch)
treeadc016e6b4988e20cbfc42ecfb016bd8e4265977 /type.cpp
parent4833f8ba6f567a84217443a75eb835da70932ea4 (diff)
Add type attribute APIs
Diffstat (limited to 'type.cpp')
-rw-r--r--type.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/type.cpp b/type.cpp
index 9dccede1..6ee0e1cb 100644
--- a/type.cpp
+++ b/type.cpp
@@ -753,6 +753,29 @@ std::vector<InstructionTextToken> Type::GetPointerSuffixTokens(uint8_t baseConfi
}
+std::vector<TypeAttribute> Type::GetAttributes() const
+{
+ size_t count = 0;
+ BNTypeAttribute* attributes = BNGetTypeAttributes(m_object, &count);
+ std::vector<TypeAttribute> result;
+ for (size_t i = 0; i < count; i++)
+ result.emplace_back(attributes[i].name, attributes[i].value);
+ BNFreeTypeAttributeList(attributes, count);
+ return result;
+}
+
+
+std::optional<std::string> Type::GetAttribute(const std::string& name) const
+{
+ char* result = BNGetTypeAttributeByName(m_object, name.c_str());
+ if (!result)
+ return std::nullopt;
+ std::string resultStr(result);
+ BNFreeString(result);
+ return resultStr;
+}
+
+
string Type::GetString(Platform* platform, BNTokenEscapingType escaping) const
{
char* str = BNGetTypeString(m_object, platform ? platform->GetObject() : nullptr, escaping);
@@ -2189,6 +2212,55 @@ TypeBuilder& TypeBuilder::SetPointerSuffix(const std::set<BNPointerSuffix>& suff
}
+void TypeBuilder::SetAttribute(const std::string& name, const std::string& value)
+{
+ BNSetTypeBuilderAttribute(m_object, name.c_str(), value.c_str());
+}
+
+
+void TypeBuilder::SetAttributes(const std::map<std::string, std::string>& values)
+{
+ BNTypeAttribute* attrs = new BNTypeAttribute[values.size()];
+ size_t i = 0;
+ for (auto& [name, value] : values)
+ {
+ attrs[i].name = (char*)name.c_str();
+ attrs[i].value = (char*)value.c_str();
+ i++;
+ }
+ BNSetTypeBuilderAttributeList(m_object, attrs, values.size());
+}
+
+
+void TypeBuilder::RemoveAttribute(const std::string& name)
+{
+ BNRemoveTypeBuilderAttribute(m_object, name.c_str());
+}
+
+
+std::vector<TypeAttribute> TypeBuilder::GetAttributes() const
+{
+ size_t count;
+ BNTypeAttribute* attributes = BNGetTypeBuilderAttributes(m_object, &count);
+ std::vector<TypeAttribute> result;
+ for (size_t i = 0; i < count; i++)
+ result.emplace_back(attributes[i].name, attributes[i].value);
+ BNFreeTypeAttributeList(attributes, count);
+ return result;
+}
+
+
+std::optional<std::string> TypeBuilder::GetAttribute(const std::string& name) const
+{
+ char* result = BNGetTypeBuilderAttributeByName(m_object, name.c_str());
+ if (!result)
+ return std::nullopt;
+ std::string resultStr(result);
+ BNFreeString(result);
+ return resultStr;
+}
+
+
QualifiedName TypeBuilder::GetTypeName() const
{
BNQualifiedName name = BNTypeBuilderGetTypeName(m_object);