forked from BigfootDev/flatbuffers
Apply Namer to Python code gen (#7146)
* Refactor out a class from Rust Codegen * Convert GenerateRustModuleRootFile * git-clang-format * unused variable * parenthesis * update BUILD file * buildifier * Delete bfbs_gen_rust.h * Delete bfbs_gen_rust.cpp * Addressed some comments * Namer::EnumVariant * Remove do not submit; Add Namespace vector overload * Unshadow variable * removed redundant variables * Apply Namer to Python * Use more variables a bit * Apply const a bunch * More variables * Fix ObjectTypes * git clang format * small thing * Simplified code around nested flatbuffers * Make more methods const. * Python files are kKeep case * Address DO NOT SUBMIT in SaveType * ensure dir exists before saving files * fix space Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,7 @@ Namer::Config RustDefaultConfig() {
|
||||
/*methods=*/Case::kSnake,
|
||||
/*functions=*/Case::kSnake,
|
||||
/*fields=*/Case::kKeep,
|
||||
/*variables=*/Case::kUnknown, // Unused.
|
||||
/*variants=*/Case::kKeep,
|
||||
/*enum_variant_seperator=*/"::",
|
||||
/*namespaces=*/Case::kSnake,
|
||||
|
||||
14
src/namer.h
14
src/namer.h
@@ -13,7 +13,7 @@ enum class SkipFile {
|
||||
Extension = 2,
|
||||
SuffixAndExtension = 3,
|
||||
};
|
||||
SkipFile operator&(SkipFile a, SkipFile b) {
|
||||
inline SkipFile operator&(SkipFile a, SkipFile b) {
|
||||
return static_cast<SkipFile>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ class Namer {
|
||||
// Case style for flatbuffers-defined fields.
|
||||
// e.g. `struct Struct { int my_field; }`
|
||||
Case fields;
|
||||
// Case style for flatbuffers-defined variables.
|
||||
// e.g. `int my_variable = 2`
|
||||
Case variables;
|
||||
// Case style for flatbuffers-defined variants.
|
||||
// e.g. `enum class Enum { MyVariant, }`
|
||||
Case variants;
|
||||
@@ -117,6 +120,10 @@ class Namer {
|
||||
return Format(s, config_.fields);
|
||||
}
|
||||
|
||||
std::string Variable(const std::string &s) const {
|
||||
return Format(s, config_.variables);
|
||||
}
|
||||
|
||||
std::string Variant(const std::string &s) const {
|
||||
return Format(s, config_.variants);
|
||||
}
|
||||
@@ -142,6 +149,11 @@ class Namer {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string NamespacedType(const std::vector<std::string> &ns,
|
||||
const std::string &s) const {
|
||||
return Namespace(ns) + config_.namespace_seperator + Type(s);
|
||||
}
|
||||
|
||||
// Returns `filename` with the right casing, suffix, and extension.
|
||||
std::string File(const std::string &filename,
|
||||
SkipFile skips = SkipFile::None) const {
|
||||
|
||||
Reference in New Issue
Block a user