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

Commit 16104887 authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "PDL: Support up to 64 bit values on enums"

parents f47f72d4 68b67486
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

EnumDef::EnumDef(std::string name, int size) : TypeDef(name, size) {}

void EnumDef::AddEntry(std::string name, uint32_t value) {
void EnumDef::AddEntry(std::string name, uint64_t value) {
  if (!util::IsEnumCase(name)) {
    ERROR() << __func__ << ": Enum " << name << "(" << value << ") should be all uppercase with underscores";
  }
+2 −2
Original line number Diff line number Diff line
@@ -30,14 +30,14 @@ class EnumDef : public TypeDef {

  virtual PacketField* GetNewField(const std::string& name, ParseLocation loc) const;

  void AddEntry(std::string name, uint32_t value);
  void AddEntry(std::string name, uint64_t value);

  bool HasEntry(std::string name) const;

  virtual Type GetDefinitionType() const override;

  // data
  std::map<uint32_t, std::string> constants_;
  std::map<uint64_t, std::string> constants_;
  std::set<std::string> entries_;

  EnumDef* try_from_enum_ = nullptr;
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ void EnumGen::GenLogging(std::ostream& stream) {

void EnumGen::GenRustDef(std::ostream& stream) {
  stream << "#[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]\n";
  stream << "#[repr(u64)]\n";
  stream << "pub enum " << e_.name_ << " {";
  for (const auto& pair : e_.constants_) {
    stream << util::ConstantCaseToCamelCase(pair.second) << " = 0x" << std::hex << pair.first << std::dec << ",";
+2 −2
Original line number Diff line number Diff line
@@ -101,12 +101,12 @@ string_literal \".*\"
                        }

{intvalue}              {
                          yylval->integer = std::stoi(std::string(yytext), nullptr, 10);
                          yylval->integer = std::stoull(std::string(yytext), nullptr, 10);
                          return token::INTEGER;
                        }

{hexvalue}              {
                          yylval->integer = std::stoi(std::string(yytext), nullptr, 16);
                          yylval->integer = std::stoull(std::string(yytext), nullptr, 16);
                          return token::INTEGER;
                        }

+5 −5
Original line number Diff line number Diff line
@@ -34,12 +34,12 @@
%verbose

%union {
  int integer;
  uint64_t integer;
  std::string* string;

  EnumDef* enum_definition;
  std::map<int, std::string>* enumeration_values;
  std::pair<int, std::string>* enumeration_value;
  std::map<uint64_t, std::string>* enumeration_values;
  std::pair<uint64_t, std::string>* enumeration_value;

  PacketDef* packet_definition_value;
  FieldList* packet_field_definitions;
@@ -173,7 +173,7 @@ enumeration_list
  : enumeration
    {
      DEBUG() << "Enumerator with comma\n";
      $$ = new std::map<int, std::string>();
      $$ = new std::map<uint64_t, std::string>();
      $$->insert(std::move(*$1));
      delete $1;
    }
@@ -589,7 +589,7 @@ constraint
    {
      DEBUG() << "Group with a fixed integer value=" << $1 << " value=" << $3 << "\n";

      $$ = new std::pair(*$1, std::variant<int64_t,std::string>($3));
      $$ = new std::pair(*$1, std::variant<int64_t,std::string>((int64_t)$3));
      delete $1;
    }
  | IDENTIFIER '=' IDENTIFIER
Loading