summaryrefslogtreecommitdiff
path: root/typeprinter.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-11-15 16:23:50 -0500
committerGlenn Smith <glenn@vector35.com>2022-11-16 13:57:49 -0500
commitacc1d309d20ac4414db230f52cd75d877084b969 (patch)
tree1eb9fc7d5fa2ed700c09f4500092b5240896a8be /typeprinter.cpp
parent1e67c64787bf84c3fbb264ade6bff128ddcc548d (diff)
Add TypePrinter::PrintAllTypes to export C headers
Diffstat (limited to 'typeprinter.cpp')
-rw-r--r--typeprinter.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/typeprinter.cpp b/typeprinter.cpp
index aed010b2..3242f323 100644
--- a/typeprinter.cpp
+++ b/typeprinter.cpp
@@ -116,6 +116,22 @@ bool TypePrinter::GetTypeLinesCallback(void* ctxt, BNType* type, BNBinaryView* d
}
+bool TypePrinter::PrintAllTypesCallback(void* ctxt, BNQualifiedName* names, BNType** types, size_t typeCount,
+ BNBinaryView* data, int lineWidth, BNTokenEscapingType escaping, char** result)
+{
+ TypePrinter* printer = (TypePrinter*)ctxt;
+ vector<pair<QualifiedName, Ref<Type>>> apiTypes;
+ for (size_t i = 0; i < typeCount; ++i)
+ {
+ apiTypes.push_back({QualifiedName::FromAPIObject(&names[i]), new Type(types[i])});
+ }
+
+ string resultStr = printer->PrintAllTypes(apiTypes, new BinaryView(data), lineWidth, escaping);
+ *result = BNAllocString(resultStr.c_str());
+ return true;
+}
+
+
void TypePrinter::FreeTokensCallback(void* ctxt, BNInstructionTextToken* tokens, size_t count)
{
InstructionTextToken::FreeInstructionTextTokenList(tokens, count);
@@ -246,6 +262,50 @@ std::string TypePrinter::GetTypeStringAfterName(
}
+std::string TypePrinter::PrintAllTypes(
+ const std::vector<std::pair<QualifiedName, Ref<Type>>>& types,
+ Ref<BinaryView> data,
+ int lineWidth,
+ BNTokenEscapingType escaping
+)
+{
+ return DefaultPrintAllTypes(types, data, lineWidth, escaping);
+}
+
+
+std::string TypePrinter::DefaultPrintAllTypes(
+ const std::vector<std::pair<QualifiedName, Ref<Type>>>& types,
+ Ref<BinaryView> data,
+ int lineWidth,
+ BNTokenEscapingType escaping
+)
+{
+ BNQualifiedName* apiNames = new BNQualifiedName[types.size()];
+ BNType** apiTypes = new BNType*[types.size()];
+
+ for (size_t i = 0; i < types.size(); i ++)
+ {
+ apiNames[i] = types[i].first.GetAPIObject();
+ apiTypes[i] = types[i].second->GetObject();
+ }
+
+ char* resultStr;
+ BNTypePrinterDefaultPrintAllTypes(m_object, apiNames, apiTypes, types.size(), data->GetObject(),
+ lineWidth, escaping, &resultStr);
+
+ for (size_t i = 0; i < types.size(); i ++)
+ {
+ QualifiedName::FreeAPIObject(&apiNames[i]);
+ }
+ delete[] apiTypes;
+ delete[] apiNames;
+
+ std::string result = resultStr;
+ BNFreeString(resultStr);
+ return result;
+}
+
+
CoreTypePrinter::CoreTypePrinter(BNTypePrinter* printer): TypePrinter(printer)
{
@@ -398,3 +458,36 @@ std::vector<TypeDefinitionLine> CoreTypePrinter::GetTypeLines(Ref<Type> type,
return cppLines;
}
+
+
+std::string CoreTypePrinter::PrintAllTypes(
+ const std::vector<std::pair<QualifiedName, Ref<Type>>>& types,
+ Ref<BinaryView> data,
+ int lineWidth,
+ BNTokenEscapingType escaping
+)
+{
+ BNQualifiedName* apiNames = new BNQualifiedName[types.size()];
+ BNType** apiTypes = new BNType*[types.size()];
+
+ for (size_t i = 0; i < types.size(); i ++)
+ {
+ apiNames[i] = types[i].first.GetAPIObject();
+ apiTypes[i] = types[i].second->GetObject();
+ }
+
+ char* resultStr;
+ BNTypePrinterPrintAllTypes(m_object, apiNames, apiTypes, types.size(), data->GetObject(),
+ lineWidth, escaping, &resultStr);
+
+ for (size_t i = 0; i < types.size(); i ++)
+ {
+ QualifiedName::FreeAPIObject(&apiNames[i]);
+ }
+ delete[] apiTypes;
+ delete[] apiNames;
+
+ std::string result = resultStr;
+ BNFreeString(resultStr);
+ return result;
+}