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

Commit 25d92a90 authored by Erwin Jansen's avatar Erwin Jansen
Browse files

Change dynamic_cast to static_cast

dynamic_cast requires type information at run time to throw exceptions.
This is not available in the emulator build system, where execeptions
are explicitly disabled.

Instead we use static_cast to downcast.

Change-Id: I75ef0b5c694320fc1e9fe648e8087e4def8cdf94
Test: Build succeeds.
parent 61ec2022
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ using ::bluetooth::packet::parser::ChecksumTypeChecker;

  for (const auto& e : decls.type_defs_queue_) {
    if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) {
      const auto* enum_def = dynamic_cast<const EnumDef*>(e.second);
      const auto* enum_def = static_cast<const EnumDef*>(e.second);
      EnumGen gen(*enum_def);
      gen.GenDefinition(out_file);
      out_file << "\n\n";
@@ -155,7 +155,7 @@ using ::bluetooth::packet::parser::ChecksumTypeChecker;
  }
  for (const auto& e : decls.type_defs_queue_) {
    if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) {
      const auto* enum_def = dynamic_cast<const EnumDef*>(e.second);
      const auto* enum_def = static_cast<const EnumDef*>(e.second);
      EnumGen gen(*enum_def);
      gen.GenLogging(out_file);
      out_file << "\n\n";
@@ -163,7 +163,7 @@ using ::bluetooth::packet::parser::ChecksumTypeChecker;
  }
  for (const auto& ch : decls.type_defs_queue_) {
    if (ch.second->GetDefinitionType() == TypeDef::Type::CHECKSUM) {
      const auto* checksum_def = dynamic_cast<const ChecksumDef*>(ch.second);
      const auto* checksum_def = static_cast<const ChecksumDef*>(ch.second);
      checksum_def->GenChecksumCheck(out_file);
    }
  }
@@ -172,10 +172,10 @@ using ::bluetooth::packet::parser::ChecksumTypeChecker;
  for (const auto& c : decls.type_defs_queue_) {
    if (c.second->GetDefinitionType() == TypeDef::Type::CUSTOM) {
      if (c.second->size_ == -1 /* Variable Size */) {
        const auto* custom_field_def = dynamic_cast<const CustomFieldDef*>(c.second);
        const auto* custom_field_def = static_cast<const CustomFieldDef*>(c.second);
        custom_field_def->GenCustomFieldCheck(out_file, decls.is_little_endian);
      } else {  // fixed size
        const auto* custom_field_def = dynamic_cast<const CustomFieldDef*>(c.second);
        const auto* custom_field_def = static_cast<const CustomFieldDef*>(c.second);
        custom_field_def->GenFixedSizeCustomFieldCheck(out_file);
      }
    }
@@ -184,7 +184,7 @@ using ::bluetooth::packet::parser::ChecksumTypeChecker;

  for (auto& s : decls.type_defs_queue_) {
    if (s.second->GetDefinitionType() == TypeDef::Type::STRUCT) {
      const auto* struct_def = dynamic_cast<const StructDef*>(s.second);
      const auto* struct_def = static_cast<const StructDef*>(s.second);
      struct_def->GenDefinition(out_file);
      out_file << "\n";
    }
@@ -293,7 +293,7 @@ bool generate_pybind11_sources_one_file(

    for (const auto& c : decls.type_defs_queue_) {
      if (c.second->GetDefinitionType() == TypeDef::Type::CUSTOM) {
        const auto* custom_def = dynamic_cast<const CustomFieldDef*>(c.second);
        const auto* custom_def = static_cast<const CustomFieldDef*>(c.second);
        custom_def->GenPyBind11Include(out_file);
      }
    }
@@ -306,7 +306,7 @@ bool generate_pybind11_sources_one_file(
    for (const auto& c : decls.type_defs_queue_) {
      if (c.second->GetDefinitionType() == TypeDef::Type::CUSTOM ||
          c.second->GetDefinitionType() == TypeDef::Type::CHECKSUM) {
        const auto* custom_def = dynamic_cast<const CustomFieldDef*>(c.second);
        const auto* custom_def = static_cast<const CustomFieldDef*>(c.second);
        custom_def->GenUsing(out_file);
      }
    }
@@ -344,7 +344,7 @@ bool generate_pybind11_sources_one_file(

  for (const auto& e : decls.type_defs_queue_) {
    if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) {
      const auto* enum_def = dynamic_cast<const EnumDef*>(e.second);
      const auto* enum_def = static_cast<const EnumDef*>(e.second);
      EnumGen gen(*enum_def);
      auto& out_file = get_out_file(symbol_count, symbol_total, &out_file_shards);
      gen.GenDefinitionPybind11(out_file);
@@ -355,7 +355,7 @@ bool generate_pybind11_sources_one_file(

  for (const auto& s : decls.type_defs_queue_) {
    if (s.second->GetDefinitionType() == TypeDef::Type::STRUCT) {
      const auto* struct_def = dynamic_cast<const StructDef*>(s.second);
      const auto* struct_def = static_cast<const StructDef*>(s.second);
      auto& out_file = get_out_file(symbol_count, symbol_total, &out_file_shards);
      struct_def->GenDefinitionPybind11(out_file);
      out_file << "\n";
+3 −3
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ bool generate_rust_source_one_file(
    EnumDef* opcode_index = nullptr;
    for (const auto& e : decls.type_defs_queue_) {
      if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) {
        auto* enum_def = dynamic_cast<EnumDef*>(e.second);
        auto* enum_def = static_cast<EnumDef*>(e.second);
        if (enum_def->name_ == "OpCode") {
          opcode = enum_def;
        } else if (enum_def->name_ == "OpCodeIndex") {
@@ -143,7 +143,7 @@ bool generate_rust_source_one_file(

  for (const auto& e : decls.type_defs_queue_) {
    if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) {
      const auto* enum_def = dynamic_cast<const EnumDef*>(e.second);
      const auto* enum_def = static_cast<const EnumDef*>(e.second);
      EnumGen gen(*enum_def);
      gen.GenRustDef(out_file);
      out_file << "\n\n";
@@ -152,7 +152,7 @@ bool generate_rust_source_one_file(

  for (auto& s : decls.type_defs_queue_) {
    if (s.second->GetDefinitionType() == TypeDef::Type::STRUCT) {
      const auto* struct_def = dynamic_cast<const StructDef*>(s.second);
      const auto* struct_def = static_cast<const StructDef*>(s.second);
      struct_def->GenRustDef(out_file);
      out_file << "\n\n";
    }
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ bool parse_declarations_one_file(const std::filesystem::path& input_file, Declar
  // Set endianess before returning
  for (auto& s : declarations->type_defs_queue_) {
    if (s.second->GetDefinitionType() == TypeDef::Type::STRUCT) {
      auto* struct_def = dynamic_cast<StructDef*>(s.second);
      auto* struct_def = static_cast<StructDef*>(s.second);
      struct_def->SetEndianness(declarations->is_little_endian);
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ StructParserGenerator::StructParserGenerator(const Declarations& decls) {
  is_little_endian = decls.is_little_endian;
  for (const auto& s : decls.type_defs_queue_) {
    if (s.second->GetDefinitionType() == TypeDef::Type::STRUCT) {
      const auto* struct_def = dynamic_cast<const StructDef*>(s.second);
      const auto* struct_def = static_cast<const StructDef*>(s.second);
      variable_struct_fields_.emplace_back(struct_def);
    }
  }