diff --git a/bindgen/ir/IR.cpp b/bindgen/ir/IR.cpp index 481f39b..f030923 100644 --- a/bindgen/ir/IR.cpp +++ b/bindgen/ir/IR.cpp @@ -32,7 +32,7 @@ void IR::addEnum(std::string name, const std::string &type, } } -void IR::addStruct(std::string name, std::vector fields, +void IR::addStruct(std::string name, std::vector> fields, uint64_t typeSize, std::shared_ptr location) { std::shared_ptr s = std::make_shared( name, std::move(fields), typeSize, std::move(location)); @@ -46,7 +46,7 @@ void IR::addStruct(std::string name, std::vector fields, } } -void IR::addUnion(std::string name, std::vector fields, +void IR::addUnion(std::string name, std::vector> fields, uint64_t maxSize, std::shared_ptr location) { std::shared_ptr u = std::make_shared( name, std::move(fields), maxSize, std::move(location)); diff --git a/bindgen/ir/IR.h b/bindgen/ir/IR.h index 8df9859..23340ac 100644 --- a/bindgen/ir/IR.h +++ b/bindgen/ir/IR.h @@ -34,10 +34,10 @@ class IR { std::vector enumerators, std::shared_ptr location); - void addStruct(std::string name, std::vector fields, + void addStruct(std::string name, std::vector> fields, uint64_t typeSize, std::shared_ptr location); - void addUnion(std::string name, std::vector fields, + void addUnion(std::string name, std::vector> fields, uint64_t maxSize, std::shared_ptr location); void addLiteralDefine(std::string name, std::string literal, diff --git a/bindgen/ir/Struct.cpp b/bindgen/ir/Struct.cpp index 3a5a3c3..0c03556 100644 --- a/bindgen/ir/Struct.cpp +++ b/bindgen/ir/Struct.cpp @@ -38,19 +38,14 @@ std::string Field::generateGetter(int fieldIndex) { return s.str(); } -StructOrUnion::StructOrUnion(std::string name, std::vector fields, +StructOrUnion::StructOrUnion(std::string name, + std::vector> fields, std::shared_ptr location) : name(std::move(name)), fields(std::move(fields)), location(std::move(location)) {} std::string StructOrUnion::getName() const { return name; } -StructOrUnion::~StructOrUnion() { - for (const auto &field : fields) { - delete field; - } -} - bool StructOrUnion::equals(const StructOrUnion &other) const { if (this == &other) { return true; @@ -77,8 +72,8 @@ std::shared_ptr StructOrUnion::getLocation() const { return location; } -Struct::Struct(std::string name, std::vector fields, uint64_t typeSize, - std::shared_ptr location) +Struct::Struct(std::string name, std::vector> fields, + uint64_t typeSize, std::shared_ptr location) : StructOrUnion(std::move(name), std::move(fields), std::move(location)), typeSize(typeSize) {} @@ -163,8 +158,8 @@ bool Struct::operator==(const Type &other) const { return false; } -Union::Union(std::string name, std::vector fields, uint64_t maxSize, - std::shared_ptr location) +Union::Union(std::string name, std::vector> fields, + uint64_t maxSize, std::shared_ptr location) : StructOrUnion(std::move(name), std::move(fields), std::move(location)), ArrayType(std::make_shared("Byte"), maxSize) {} diff --git a/bindgen/ir/Struct.h b/bindgen/ir/Struct.h index 5669946..0bc704c 100644 --- a/bindgen/ir/Struct.h +++ b/bindgen/ir/Struct.h @@ -20,11 +20,9 @@ class Field : public TypeAndName { class StructOrUnion { public: - StructOrUnion(std::string name, std::vector fields, + StructOrUnion(std::string name, std::vector> fields, std::shared_ptr location); - ~StructOrUnion(); - virtual std::shared_ptr generateTypeDef() = 0; virtual std::string generateHelperClass() const = 0; @@ -39,7 +37,7 @@ class StructOrUnion { protected: std::string name; - std::vector fields; + std::vector> fields; std::shared_ptr location; }; @@ -47,8 +45,8 @@ class Struct : public StructOrUnion, public Type, public std::enable_shared_from_this { public: - Struct(std::string name, std::vector fields, uint64_t typeSize, - std::shared_ptr location); + Struct(std::string name, std::vector> fields, + uint64_t typeSize, std::shared_ptr location); std::shared_ptr generateTypeDef() override; @@ -77,8 +75,8 @@ class Union : public StructOrUnion, public ArrayType, public std::enable_shared_from_this { public: - Union(std::string name, std::vector fields, uint64_t maxSize, - std::shared_ptr location); + Union(std::string name, std::vector> fields, + uint64_t maxSize, std::shared_ptr location); std::shared_ptr generateTypeDef() override; diff --git a/bindgen/visitor/TreeVisitor.cpp b/bindgen/visitor/TreeVisitor.cpp index 06807c6..ff2a5c8 100644 --- a/bindgen/visitor/TreeVisitor.cpp +++ b/bindgen/visitor/TreeVisitor.cpp @@ -101,7 +101,7 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record) { void TreeVisitor::handleUnion(clang::RecordDecl *record, std::string name) { uint64_t maxSize = 0; - std::vector fields; + std::vector> fields; for (const clang::FieldDecl *field : record->fields()) { uint64_t sizeInBits = astContext->getTypeSize(field->getType()); @@ -111,7 +111,7 @@ void TreeVisitor::handleUnion(clang::RecordDecl *record, std::string name) { std::shared_ptr ftype = typeTranslator.translate(field->getType(), &name); - fields.push_back(new Field(fname, ftype)); + fields.push_back(std::make_shared(fname, ftype)); } ir.addUnion(name, std::move(fields), maxSize, getLocation(record)); @@ -128,12 +128,13 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) { } int fieldCnt = 0; - std::vector fields; + std::vector> fields; for (const clang::FieldDecl *field : record->fields()) { std::shared_ptr ftype = typeTranslator.translate(field->getType(), &name); - fields.push_back(new Field(field->getNameAsString(), ftype)); + fields.push_back( + std::make_shared(field->getNameAsString(), ftype)); cycleDetection.AddDependency(newName, field->getType());