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

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

Merge "PDL: Enforce ENUM_STYLE"

parents 16dcaacd 164ef58f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1867,7 +1867,7 @@ packet ReadLocalVersionInformation : CommandPacket (op_code = READ_LOCAL_VERSION
}

enum HciVersion : 8 {
  V_1_0b = 0x00,
  V_1_0B = 0x00,
  V_1_1 = 0x01,
  V_1_2 = 0x02,
  V_2_0 = 0x03, //  + EDR
@@ -1881,7 +1881,7 @@ enum HciVersion : 8 {
}

enum LmpVersion : 8 {
  V_1_0b = 0x00, // withdrawn
  V_1_0B = 0x00, // withdrawn
  V_1_1 = 0x01, // withdrawn
  V_1_2 = 0x02, // withdrawn
  V_2_0 = 0x03, //  + EDR
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@
EnumDef::EnumDef(std::string name, int size) : TypeDef(name, size) {}

void EnumDef::AddEntry(std::string name, uint32_t value) {
  if (!util::IsEnumCase(name)) {
    ERROR() << __func__ << ": Enum " << name << "(" << value << ") should be all uppercase with underscores";
  }
  if (value > util::GetMaxValueForBits(size_)) {
    ERROR() << __func__ << ": Value of " << name << "(" << value << ") is greater than the max possible value for enum "
            << name_ << "(" << util::GetMaxValueForBits(size_) << ")\n";
+8 −8
Original line number Diff line number Diff line
@@ -1483,7 +1483,7 @@ TEST(GeneratedPacketTest, testOneFourByteStruct) {
  PacketView<kLittleEndian> packet_bytes_view(packet_bytes);
  auto view = OneFourByteStructView::Create(packet_bytes_view);
  ASSERT_TRUE(view.IsValid());
  ASSERT_EQ(StructType::FourByte, view.GetOneStruct().struct_type_);
  ASSERT_EQ(StructType::FOUR_BYTE, view.GetOneStruct().struct_type_);
  ASSERT_EQ(four_byte_struct.four_bytes_, view.GetOneStruct().four_bytes_);
}

@@ -1552,7 +1552,7 @@ TEST(GeneratedPacketTest, testOneGenericStructFour) {
  ASSERT_TRUE(view.IsValid());
  auto base_struct = view.GetBaseStruct();
  ASSERT_NE(nullptr, base_struct);
  ASSERT_EQ(StructType::FourByte, base_struct->struct_type_);
  ASSERT_EQ(StructType::FOUR_BYTE, base_struct->struct_type_);
  ASSERT_EQ(four_byte_struct.four_bytes_, ((FourByteStruct*)base_struct.get())->four_bytes_);
}

@@ -1586,10 +1586,10 @@ TEST(GeneratedPacketTest, testOneGenericStructArray) {

  std::vector<std::unique_ptr<UnusedParentStruct>> vector_copy;
  for (auto& s : parent_vector) {
    if (s->struct_type_ == StructType::TwoByte) {
    if (s->struct_type_ == StructType::TWO_BYTE) {
      vector_copy.push_back(std::make_unique<TwoByteStruct>(*(TwoByteStruct*)s.get()));
    }
    if (s->struct_type_ == StructType::FourByte) {
    if (s->struct_type_ == StructType::FOUR_BYTE) {
      vector_copy.push_back(std::make_unique<FourByteStruct>(*(FourByteStruct*)s.get()));
    }
  }
@@ -1614,7 +1614,7 @@ TEST(GeneratedPacketTest, testOneGenericStructArray) {
  for (size_t i = 0; i < vector_copy.size(); i++) {
    ASSERT_NE(nullptr, an_array[i]);
    ASSERT_EQ(vector_copy[i]->struct_type_, an_array[i]->struct_type_);
    if (vector_copy[i]->struct_type_ == StructType::FourByte) {
    if (vector_copy[i]->struct_type_ == StructType::FOUR_BYTE) {
      ASSERT_EQ(FourByteStruct::Specialize(vector_copy[i].get())->four_bytes_,
                FourByteStruct::Specialize(an_array[i].get())->four_bytes_);
    } else {
@@ -1644,10 +1644,10 @@ TEST(GeneratedPacketTest, testOneGenericStructFourArray) {
  std::array<std::unique_ptr<UnusedParentStruct>, 4> vector_copy;
  size_t i = 0;
  for (auto& s : parent_vector) {
    if (s->struct_type_ == StructType::TwoByte) {
    if (s->struct_type_ == StructType::TWO_BYTE) {
      vector_copy[i] = std::make_unique<TwoByteStruct>(*(TwoByteStruct*)s.get());
    }
    if (s->struct_type_ == StructType::FourByte) {
    if (s->struct_type_ == StructType::FOUR_BYTE) {
      vector_copy[i] = std::make_unique<FourByteStruct>(*(FourByteStruct*)s.get());
    }
    i++;
@@ -1673,7 +1673,7 @@ TEST(GeneratedPacketTest, testOneGenericStructFourArray) {
  for (size_t i = 0; i < vector_copy.size(); i++) {
    ASSERT_NE(nullptr, an_array[i]);
    ASSERT_EQ(vector_copy[i]->struct_type_, an_array[i]->struct_type_);
    if (vector_copy[i]->struct_type_ == StructType::FourByte) {
    if (vector_copy[i]->struct_type_ == StructType::FOUR_BYTE) {
      ASSERT_EQ(FourByteStruct::Specialize(vector_copy[i].get())->four_bytes_,
                FourByteStruct::Specialize(an_array[i].get())->four_bytes_);
    } else {
+11 −10
Original line number Diff line number Diff line
@@ -278,10 +278,11 @@ packet OneVersionTwoStructPacket : OneVersionedStructPacket(version = 0x02) {
}

enum StructType : 8 {
  ZeroByte = 0x00,
  TwoByte = 0x02,
  FourByte = 0x04,
  AtLeastFourByte = 0x05,
  ZERO_BYTE = 0x00,
  TWO_BYTE = 0x02,
  FOUR_BYTE = 0x04,
  AT_LEAST_FOUR_BYTE = 0x05,
  VARIABLE = 0x06,
}

struct UnusedParentStruct {
@@ -289,28 +290,28 @@ struct UnusedParentStruct {
  _body_,
}

struct TwoByteStruct : UnusedParentStruct (struct_type = TwoByte) {
struct TwoByteStruct : UnusedParentStruct (struct_type = TWO_BYTE) {
  two_bytes : 16,
}

struct FourByteStruct : UnusedParentStruct (struct_type = FourByte) {
struct FourByteStruct : UnusedParentStruct (struct_type = FOUR_BYTE) {
  four_bytes : 32,
}

struct AtLeastFourByteStruct : UnusedParentStruct (struct_type = AtLeastFourByte) {
struct AtLeastFourByteStruct : UnusedParentStruct (struct_type = AT_LEAST_FOUR_BYTE) {
  four_bytes : 32,
  struct_type : StructType,
  _body_,
}

struct OnlyFourByteStruct : AtLeastFourByteStruct (struct_type = ZeroByte) {
struct OnlyFourByteStruct : AtLeastFourByteStruct (struct_type = ZERO_BYTE) {
}

struct SixByteStruct : AtLeastFourByteStruct (struct_type = TwoByte) {
struct SixByteStruct : AtLeastFourByteStruct (struct_type = TWO_BYTE) {
  two_bytes : 16,
}

struct EightByteStruct : AtLeastFourByteStruct (struct_type = FourByte) {
struct EightByteStruct : AtLeastFourByteStruct (struct_type = FOUR_BYTE) {
  four_bytes : 32,
}

+11 −0
Original line number Diff line number Diff line
@@ -103,4 +103,15 @@ inline std::string UnderscoreToCamelCase(std::string value) {
  return camel_case.str();
}

inline bool IsEnumCase(std::string value) {
  if (value[0] < 'A' || value[0] > 'Z') {
    return false;
  }

  // Use static to avoid compiling the regex more than once.
  static const std::regex enum_regex("[A-Z][A-Z0-9_]*");

  return std::regex_match(value, enum_regex);
}

}  // namespace util