Disable RTTI and rework use in idl_gen_ts.cpp (#7474)

This commit is contained in:
Derek Bailey
2022-08-24 10:36:11 -07:00
committed by GitHub
parent 8d01c5859c
commit b7eb441470
2 changed files with 12 additions and 3 deletions

View File

@@ -369,6 +369,8 @@ else()
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
-Werror # Treat all compiler warnings as errors
-fno-rtti # Disable runtime type information
$<$<CXX_COMPILER_ID:GNU>:
# False positive string overflow
# https://github.com/google/flatbuffers/issues/7366

View File

@@ -38,6 +38,12 @@ struct ImportDefinition {
};
enum AnnotationType { kParam = 0, kType = 1, kReturns = 2 };
template<typename T> bool SupportsObjectAPI() { return false; }
// Structs can have Object API support.
template<> bool SupportsObjectAPI<StructDef>() { return true; }
} // namespace
namespace ts {
@@ -712,9 +718,9 @@ class TsGenerator : public BaseGenerator {
return symbols_expression;
}
template<typename DefintionT>
template<typename DefinitionT>
ImportDefinition AddImport(import_set &imports, const Definition &dependent,
const DefintionT &dependency) {
const DefinitionT &dependency) {
// The unique name of the dependency, fully qualified in its namespace.
const std::string unique_name = GetTypeName(
dependency, /*object_api = */ false, /*force_ns_wrap=*/true);
@@ -748,8 +754,9 @@ class TsGenerator : public BaseGenerator {
// Strip the leading //
.substr(2);
flat_file_import_declarations_[file][import_name] = name;
if (parser_.opts.generate_object_based_api &&
typeid(dependency) == typeid(StructDef)) {
SupportsObjectAPI<DefinitionT>()) {
flat_file_import_declarations_[file][import_name + "T"] = object_name;
}
}