Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83c3ce5c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PDL: Save the Size of a Struct in its definition"

parents c1c799ff 657c20f4
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -20,17 +20,17 @@
#include "util.h"

StructDef::StructDef(std::string name, FieldList fields) : StructDef(name, fields, nullptr) {}
StructDef::StructDef(std::string name, FieldList fields, StructDef* parent) : ParentDef(name, fields, parent) {}
StructDef::StructDef(std::string name, FieldList fields, StructDef* parent)
    : ParentDef(name, fields, parent), total_size_(GetSize(true)) {}

PacketField* StructDef::GetNewField(const std::string& name, ParseLocation loc) const {
  Size total_size = GetSize(false);
  if (fields_.HasBody()) {
  if (fields_.HasBody() || total_size_.has_dynamic()) {
    ERROR(new StructField(name, name_, -1, loc)) << "Variable size structs are not supported";
    fprintf(stderr, "total_size of %s(%s) = %s\n", name_.c_str(), name.c_str(), total_size.ToString().c_str());
    fprintf(stderr, "total_size_ of %s(%s) = %s\n", name_.c_str(), name.c_str(), total_size_.ToString().c_str());
    abort();
    return new StructField(name, name_, -1, loc);
  } else {
    return new StructField(name, name_, total_size.bits(), loc);
    return new StructField(name, name_, total_size_.bits(), loc);
  }
}

+3 −0
Original line number Diff line number Diff line
@@ -39,4 +39,7 @@ class StructDef : public ParentDef {
  void GenDefinition(std::ostream& s) const;

  void GenConstructor(std::ostream& s) const;

 private:
  Size total_size_;
};