mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 19:32:41 +00:00
Apply Namer to Go code gen (#7150)
* 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 * clang format Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
26
src/namer.h
26
src/namer.h
@@ -16,6 +16,18 @@ enum class SkipFile {
|
||||
inline SkipFile operator&(SkipFile a, SkipFile b) {
|
||||
return static_cast<SkipFile>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
// Options for Namer::Directories
|
||||
enum class SkipDir {
|
||||
None = 0,
|
||||
// Skip prefixing the -o $output_path.
|
||||
OutputPath = 1,
|
||||
// Skip trailing path seperator.
|
||||
TrailingPathSeperator = 2,
|
||||
OutputPathAndTrailingPathSeparator = 3,
|
||||
};
|
||||
inline SkipDir operator&(SkipDir a, SkipDir b) {
|
||||
return static_cast<SkipDir>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
// `Namer` applies style configuration to symbols in generated code. It manages
|
||||
// casing, escapes keywords, and object API naming.
|
||||
@@ -163,14 +175,22 @@ class Namer {
|
||||
(skip_suffix ? "" : config_.filename_suffix) +
|
||||
(skip_ext ? "" : config_.filename_extension);
|
||||
}
|
||||
// Formats `directories` and returns a filepath with the right seperator.
|
||||
// Formats `directories` prefixed with the output_path and joined with the
|
||||
// right seperator. Output path prefixing and the trailing separator may be
|
||||
// skiped using `skips`.
|
||||
// Callers may want to use `EnsureDirExists` with the result.
|
||||
std::string Directories(const std::vector<std::string> &directories) const {
|
||||
std::string result = config_.output_path;
|
||||
std::string Directories(const std::vector<std::string> &directories,
|
||||
SkipDir skips = SkipDir::None) const {
|
||||
const bool skip_output_path =
|
||||
(skips & SkipDir::OutputPath) != SkipDir::None;
|
||||
const bool skip_trailing_seperator =
|
||||
(skips & SkipDir::TrailingPathSeperator) != SkipDir::None;
|
||||
std::string result = skip_output_path ? "" : config_.output_path;
|
||||
for (auto d = directories.begin(); d != directories.end(); d++) {
|
||||
result += ConvertCase(*d, config_.directories, Case::kUpperCamel);
|
||||
result.push_back(kPathSeparator);
|
||||
}
|
||||
if (skip_trailing_seperator) result.pop_back();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user