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

Commit ad8210f5 authored by Myles Watson's avatar Myles Watson Committed by Jakub Pawlowski
Browse files

PDL: Util fixup

Test: add a type with a large enum value
enum BadType : 4 {
  ZERO = 0,
  ONE = 1,
  TWO = 2,
  THREE = 0xffffff,
}
ERROR: AddEntry: Value of THREE(16777215) is greater than the max possible value for enum BadType(15)
Change-Id: Ieb9920818723a56c9f05342b895c172ee772a2b0
parent a4f58798
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ EnumDef::EnumDef(std::string name, int size) : TypeDef(name, size){};

void EnumDef::AddEntry(std::string name, uint32_t value) {
  if (value > util::GetMaxValueForBits(size_)) {
    std::cerr << __func__ << ": Value provided is greater than max possible value for enum. " << name_ << "\n";
    abort();
    ERROR() << __func__ << ": Value of " << name << "(" << value << ") is greater than the max possible value for enum "
            << name_ << "(" << util::GetMaxValueForBits(size_) << ")\n";
  }

  constants_.insert(std::pair(value, name));
+2 −7
Original line number Diff line number Diff line
@@ -56,13 +56,8 @@ inline uint64_t GetMaxValueForBits(int bits) {
    ERROR() << __func__ << ": Cannot use a type larger than 64 bits. (" << bits << ")\n";
  }

  uint64_t max = 0;
  for (int i = 0; i < bits; i++) {
    max <<= 1;
    max |= 1;
  }

  return max;
  // Set all the bits to 1, then shift off extras.
  return ~(static_cast<uint64_t>(0)) >> (64 - bits);
}

inline std::string CamelCaseToUnderScore(std::string value) {