Fixed vtable duplication for binary annotator (#7809)

This commit is contained in:
Derek Bailey
2023-02-02 12:39:39 -06:00
committed by GitHub
parent f838017860
commit 0fb5519585
28 changed files with 6807 additions and 6788 deletions

View File

@@ -17,6 +17,7 @@
#ifndef FLATBUFFERS_BINARY_ANNOTATOR_H_
#define FLATBUFFERS_BINARY_ANNOTATOR_H_
#include <list>
#include <map>
#include <string>
#include <vector>
@@ -52,8 +53,8 @@ enum class BinaryRegionType {
template<typename T>
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
std::stringstream stream;
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(static_cast<int>(width))
<< i;
stream << std::hex << std::uppercase << std::setfill('0')
<< std::setw(static_cast<int>(width)) << i;
return stream.str();
}
@@ -257,6 +258,8 @@ class BinaryAnnotator {
uint16_t offset_from_table = 0;
};
const reflection::Object *referring_table;
// Field ID -> {field def, offset from table}
std::map<uint16_t, Entry> fields;
@@ -266,8 +269,12 @@ class BinaryAnnotator {
uint64_t BuildHeader(uint64_t offset);
void BuildVTable(uint64_t offset, const reflection::Object *table,
uint64_t offset_of_referring_table);
// VTables can be shared across instances or even across objects. This
// attempts to get an existing vtable given the offset and table type,
// otherwise it will built the vtable, memorize it, and return the built
// VTable. Returns nullptr if building the VTable fails.
VTable *GetOrBuildVTable(uint64_t offset, const reflection::Object *table,
uint64_t offset_of_referring_table);
void BuildTable(uint64_t offset, const BinarySectionType type,
const reflection::Object *table);
@@ -281,7 +288,7 @@ class BinaryAnnotator {
void BuildVector(uint64_t offset, const reflection::Object *table,
const reflection::Field *field, uint64_t parent_table_offset,
const VTable &vtable);
const std::map<uint16_t, VTable::Entry> vtable_fields);
std::string BuildUnion(uint64_t offset, uint8_t realized_type,
const reflection::Field *field);
@@ -382,7 +389,7 @@ class BinaryAnnotator {
const uint64_t binary_length_;
// Map of binary offset to vtables, to dedupe vtables.
std::map<uint64_t, VTable> vtables_;
std::map<uint64_t, std::list<VTable>> vtables_;
// The annotated binary sections, index by their absolute offset.
std::map<uint64_t, BinarySection> sections_;