mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -25,69 +25,69 @@ class IdlNamer : public Namer {
|
||||
using Namer::Variable;
|
||||
using Namer::Variant;
|
||||
|
||||
std::string Constant(const FieldDef &d) const { return Constant(d.name); }
|
||||
std::string Constant(const FieldDef& d) const { return Constant(d.name); }
|
||||
|
||||
// Types are always structs or enums so we can only expose these two
|
||||
// overloads.
|
||||
std::string Type(const StructDef &d) const { return Type(d.name); }
|
||||
std::string Type(const EnumDef &d) const { return Type(d.name); }
|
||||
std::string Type(const StructDef& d) const { return Type(d.name); }
|
||||
std::string Type(const EnumDef& d) const { return Type(d.name); }
|
||||
|
||||
std::string Function(const Definition &s) const { return Function(s.name); }
|
||||
std::string Function(const std::string& prefix, const Definition &s) const {
|
||||
std::string Function(const Definition& s) const { return Function(s.name); }
|
||||
std::string Function(const std::string& prefix, const Definition& s) const {
|
||||
return Function(prefix + s.name);
|
||||
}
|
||||
|
||||
std::string Field(const FieldDef &s) const { return Field(s.name); }
|
||||
std::string Field(const FieldDef &d, const std::string &s) const {
|
||||
std::string Field(const FieldDef& s) const { return Field(s.name); }
|
||||
std::string Field(const FieldDef& d, const std::string& s) const {
|
||||
return Field(d.name + "_" + s);
|
||||
}
|
||||
|
||||
std::string Variable(const FieldDef &s) const { return Variable(s.name); }
|
||||
std::string Variable(const FieldDef& s) const { return Variable(s.name); }
|
||||
|
||||
std::string Variable(const StructDef &s) const { return Variable(s.name); }
|
||||
std::string Variable(const StructDef& s) const { return Variable(s.name); }
|
||||
|
||||
std::string Variant(const EnumVal &s) const { return Variant(s.name); }
|
||||
std::string Variant(const EnumVal& s) const { return Variant(s.name); }
|
||||
|
||||
std::string EnumVariant(const EnumDef &e, const EnumVal &v) const {
|
||||
std::string EnumVariant(const EnumDef& e, const EnumVal& v) const {
|
||||
return Type(e) + config_.enum_variant_seperator + Variant(v);
|
||||
}
|
||||
|
||||
std::string ObjectType(const StructDef &d) const {
|
||||
std::string ObjectType(const StructDef& d) const {
|
||||
return ObjectType(d.name);
|
||||
}
|
||||
std::string ObjectType(const EnumDef &d) const { return ObjectType(d.name); }
|
||||
std::string ObjectType(const EnumDef& d) const { return ObjectType(d.name); }
|
||||
|
||||
std::string Method(const FieldDef &d, const std::string &suffix) const {
|
||||
std::string Method(const FieldDef& d, const std::string& suffix) const {
|
||||
return Method(d.name, suffix);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const StructDef &d) const {
|
||||
std::string Method(const std::string& prefix, const StructDef& d) const {
|
||||
return Method(prefix, d.name);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const FieldDef &d) const {
|
||||
std::string Method(const std::string& prefix, const FieldDef& d) const {
|
||||
return Method(prefix, d.name);
|
||||
}
|
||||
std::string Method(const std::string &prefix, const FieldDef &d,
|
||||
const std::string &suffix) const {
|
||||
std::string Method(const std::string& prefix, const FieldDef& d,
|
||||
const std::string& suffix) const {
|
||||
return Method(prefix, d.name, suffix);
|
||||
}
|
||||
|
||||
std::string Namespace(const struct Namespace &ns) const {
|
||||
std::string Namespace(const struct Namespace& ns) const {
|
||||
return Namespace(ns.components);
|
||||
}
|
||||
|
||||
std::string NamespacedEnumVariant(const EnumDef &e, const EnumVal &v) const {
|
||||
std::string NamespacedEnumVariant(const EnumDef& e, const EnumVal& v) const {
|
||||
return NamespacedString(e.defined_namespace, EnumVariant(e, v));
|
||||
}
|
||||
|
||||
std::string NamespacedType(const Definition &def) const {
|
||||
std::string NamespacedType(const Definition& def) const {
|
||||
return NamespacedString(def.defined_namespace, Type(def.name));
|
||||
}
|
||||
|
||||
std::string NamespacedObjectType(const Definition &def) const {
|
||||
std::string NamespacedObjectType(const Definition& def) const {
|
||||
return NamespacedString(def.defined_namespace, ObjectType(def.name));
|
||||
}
|
||||
|
||||
std::string Directories(const struct Namespace &ns,
|
||||
std::string Directories(const struct Namespace& ns,
|
||||
SkipDir skips = SkipDir::None,
|
||||
Case input_case = Case::kUpperCamel) const {
|
||||
return Directories(ns.components, skips, input_case);
|
||||
@@ -96,19 +96,19 @@ class IdlNamer : public Namer {
|
||||
// Legacy fields do not really follow the usual config and should be
|
||||
// considered for deprecation.
|
||||
|
||||
std::string LegacyRustNativeVariant(const EnumVal &v) const {
|
||||
std::string LegacyRustNativeVariant(const EnumVal& v) const {
|
||||
return ConvertCase(EscapeKeyword(v.name), Case::kUpperCamel);
|
||||
}
|
||||
|
||||
std::string LegacyRustFieldOffsetName(const FieldDef &field) const {
|
||||
std::string LegacyRustFieldOffsetName(const FieldDef& field) const {
|
||||
return "VT_" + ConvertCase(EscapeKeyword(field.name), Case::kAllUpper);
|
||||
}
|
||||
std::string LegacyRustUnionTypeOffsetName(const FieldDef &field) const {
|
||||
return "VT_" + ConvertCase(EscapeKeyword(field.name + "_type"), Case::kAllUpper);
|
||||
std::string LegacyRustUnionTypeOffsetName(const FieldDef& field) const {
|
||||
return "VT_" +
|
||||
ConvertCase(EscapeKeyword(field.name + "_type"), Case::kAllUpper);
|
||||
}
|
||||
|
||||
|
||||
std::string LegacySwiftVariant(const EnumVal &ev) const {
|
||||
std::string LegacySwiftVariant(const EnumVal& ev) const {
|
||||
auto name = ev.name;
|
||||
if (isupper(name.front())) {
|
||||
std::transform(name.begin(), name.end(), name.begin(), CharToLower);
|
||||
@@ -117,24 +117,24 @@ class IdlNamer : public Namer {
|
||||
}
|
||||
|
||||
// Also used by Kotlin, lol.
|
||||
std::string LegacyJavaMethod2(const std::string &prefix, const StructDef &sd,
|
||||
const std::string &suffix) const {
|
||||
std::string LegacyJavaMethod2(const std::string& prefix, const StructDef& sd,
|
||||
const std::string& suffix) const {
|
||||
return prefix + sd.name + suffix;
|
||||
}
|
||||
|
||||
std::string LegacyKotlinVariant(EnumVal &ev) const {
|
||||
std::string LegacyKotlinVariant(EnumVal& ev) const {
|
||||
// Namer assumes the input case is snake case which is wrong...
|
||||
return ConvertCase(EscapeKeyword(ev.name), Case::kLowerCamel);
|
||||
}
|
||||
// Kotlin methods escapes keywords after case conversion but before
|
||||
// prefixing and suffixing.
|
||||
std::string LegacyKotlinMethod(const std::string &prefix, const FieldDef &d,
|
||||
const std::string &suffix) const {
|
||||
std::string LegacyKotlinMethod(const std::string& prefix, const FieldDef& d,
|
||||
const std::string& suffix) const {
|
||||
return prefix + ConvertCase(EscapeKeyword(d.name), Case::kUpperCamel) +
|
||||
suffix;
|
||||
}
|
||||
std::string LegacyKotlinMethod(const std::string &prefix, const StructDef &d,
|
||||
const std::string &suffix) const {
|
||||
std::string LegacyKotlinMethod(const std::string& prefix, const StructDef& d,
|
||||
const std::string& suffix) const {
|
||||
return prefix + ConvertCase(EscapeKeyword(d.name), Case::kUpperCamel) +
|
||||
suffix;
|
||||
}
|
||||
@@ -145,17 +145,19 @@ class IdlNamer : public Namer {
|
||||
return "mutate_" + d.name;
|
||||
}
|
||||
|
||||
std::string LegacyRustUnionTypeMethod(const FieldDef &d) {
|
||||
std::string LegacyRustUnionTypeMethod(const FieldDef& d) {
|
||||
// assert d is a union
|
||||
// d should convert case but not escape keywords due to historical reasons
|
||||
return ConvertCase(d.name, config_.fields, Case::kLowerCamel) + "_type";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string NamespacedString(const struct Namespace *ns,
|
||||
const std::string &str) const {
|
||||
std::string NamespacedString(const struct Namespace* ns,
|
||||
const std::string& str) const {
|
||||
std::string ret;
|
||||
if (ns != nullptr) { ret += Namespace(ns->components); }
|
||||
if (ns != nullptr) {
|
||||
ret += Namespace(ns->components);
|
||||
}
|
||||
if (!ret.empty()) ret += config_.namespace_seperator;
|
||||
return ret + str;
|
||||
}
|
||||
@@ -163,9 +165,9 @@ class IdlNamer : public Namer {
|
||||
|
||||
// This is a temporary helper function for code generators to call until all
|
||||
// flag-overriding logic into flatc.cpp
|
||||
inline Namer::Config WithFlagOptions(const Namer::Config &input,
|
||||
const IDLOptions &opts,
|
||||
const std::string &path) {
|
||||
inline Namer::Config WithFlagOptions(const Namer::Config& input,
|
||||
const IDLOptions& opts,
|
||||
const std::string& path) {
|
||||
Namer::Config result = input;
|
||||
result.object_prefix = opts.object_prefix;
|
||||
result.object_suffix = opts.object_suffix;
|
||||
|
||||
@@ -110,49 +110,49 @@ class Namer {
|
||||
|
||||
virtual ~Namer() {}
|
||||
|
||||
template<typename T> std::string Method(const T &s) const {
|
||||
template <typename T>
|
||||
std::string Method(const T& s) const {
|
||||
return Method(s.name);
|
||||
}
|
||||
|
||||
virtual std::string Method(const std::string &pre,
|
||||
const std::string &mid,
|
||||
const std::string &suf) const {
|
||||
return Format(pre + "_" + mid + "_" + suf, config_.methods);
|
||||
virtual std::string Method(const std::string& pre, const std::string& mid,
|
||||
const std::string& suf) const {
|
||||
return Format(pre + "_" + mid + "_" + suf, config_.methods);
|
||||
}
|
||||
virtual std::string Method(const std::string &pre,
|
||||
const std::string &suf) const {
|
||||
virtual std::string Method(const std::string& pre,
|
||||
const std::string& suf) const {
|
||||
return Format(pre + "_" + suf, config_.methods);
|
||||
}
|
||||
virtual std::string Method(const std::string &s) const {
|
||||
virtual std::string Method(const std::string& s) const {
|
||||
return Format(s, config_.methods);
|
||||
}
|
||||
|
||||
virtual std::string Constant(const std::string &s) const {
|
||||
virtual std::string Constant(const std::string& s) const {
|
||||
return Format(s, config_.constants);
|
||||
}
|
||||
|
||||
virtual std::string Function(const std::string &s) const {
|
||||
virtual std::string Function(const std::string& s) const {
|
||||
return Format(s, config_.functions);
|
||||
}
|
||||
|
||||
virtual std::string Variable(const std::string &s) const {
|
||||
virtual std::string Variable(const std::string& s) const {
|
||||
return Format(s, config_.variables);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string Variable(const std::string &p, const T &s) const {
|
||||
template <typename T>
|
||||
std::string Variable(const std::string& p, const T& s) const {
|
||||
return Format(p + "_" + s.name, config_.variables);
|
||||
}
|
||||
virtual std::string Variable(const std::string &p,
|
||||
const std::string &s) const {
|
||||
virtual std::string Variable(const std::string& p,
|
||||
const std::string& s) const {
|
||||
return Format(p + "_" + s, config_.variables);
|
||||
}
|
||||
|
||||
virtual std::string Namespace(const std::string &s) const {
|
||||
virtual std::string Namespace(const std::string& s) const {
|
||||
return Format(s, config_.namespaces);
|
||||
}
|
||||
|
||||
virtual std::string Namespace(const std::vector<std::string> &ns) const {
|
||||
virtual std::string Namespace(const std::vector<std::string>& ns) const {
|
||||
std::string result;
|
||||
for (auto it = ns.begin(); it != ns.end(); it++) {
|
||||
if (it != ns.begin()) result += config_.namespace_seperator;
|
||||
@@ -161,14 +161,14 @@ class Namer {
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual std::string NamespacedType(const std::vector<std::string> &ns,
|
||||
const std::string &s) const {
|
||||
virtual std::string NamespacedType(const std::vector<std::string>& ns,
|
||||
const std::string& s) const {
|
||||
return (ns.empty() ? "" : (Namespace(ns) + config_.namespace_seperator)) +
|
||||
Type(s);
|
||||
}
|
||||
|
||||
// Returns `filename` with the right casing, suffix, and extension.
|
||||
virtual std::string File(const std::string &filename,
|
||||
virtual std::string File(const std::string& filename,
|
||||
SkipFile skips = SkipFile::None) const {
|
||||
const bool skip_suffix = (skips & SkipFile::Suffix) != SkipFile::None;
|
||||
const bool skip_ext = (skips & SkipFile::Extension) != SkipFile::None;
|
||||
@@ -176,8 +176,8 @@ class Namer {
|
||||
(skip_suffix ? "" : config_.filename_suffix) +
|
||||
(skip_ext ? "" : config_.filename_extension);
|
||||
}
|
||||
template<typename T>
|
||||
std::string File(const T &f, SkipFile skips = SkipFile::None) const {
|
||||
template <typename T>
|
||||
std::string File(const T& f, SkipFile skips = SkipFile::None) const {
|
||||
return File(f.name, skips);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ class Namer {
|
||||
// input_case is used to tell how to modify namespace. e.g. kUpperCamel will
|
||||
// add a underscode between case changes, so MyGame turns into My_Game
|
||||
// (depending also on the output_case).
|
||||
virtual std::string Directories(const std::vector<std::string> &directories,
|
||||
virtual std::string Directories(const std::vector<std::string>& directories,
|
||||
SkipDir skips = SkipDir::None,
|
||||
Case input_case = Case::kUpperCamel) const {
|
||||
const bool skip_output_path =
|
||||
@@ -204,7 +204,7 @@ class Namer {
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual std::string EscapeKeyword(const std::string &name) const {
|
||||
virtual std::string EscapeKeyword(const std::string& name) const {
|
||||
if (keywords_.find(name) == keywords_.end()) {
|
||||
return name;
|
||||
} else {
|
||||
@@ -212,26 +212,26 @@ class Namer {
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::string Type(const std::string &s) const {
|
||||
virtual std::string Type(const std::string& s) const {
|
||||
return Format(s, config_.types);
|
||||
}
|
||||
virtual std::string Type(const std::string &t, const std::string &s) const {
|
||||
virtual std::string Type(const std::string& t, const std::string& s) const {
|
||||
return Format(t + "_" + s, config_.types);
|
||||
}
|
||||
|
||||
virtual std::string ObjectType(const std::string &s) const {
|
||||
virtual std::string ObjectType(const std::string& s) const {
|
||||
return config_.object_prefix + Type(s) + config_.object_suffix;
|
||||
}
|
||||
|
||||
virtual std::string Field(const std::string &s) const {
|
||||
virtual std::string Field(const std::string& s) const {
|
||||
return Format(s, config_.fields);
|
||||
}
|
||||
|
||||
virtual std::string Variant(const std::string &s) const {
|
||||
virtual std::string Variant(const std::string& s) const {
|
||||
return Format(s, config_.variants);
|
||||
}
|
||||
|
||||
virtual std::string Format(const std::string &s, Case casing) const {
|
||||
virtual std::string Format(const std::string& s, Case casing) const {
|
||||
if (config_.escape_keywords == Config::Escape::BeforeConvertingCase) {
|
||||
return ConvertCase(EscapeKeyword(s), casing, Case::kLowerCamel);
|
||||
} else {
|
||||
@@ -242,8 +242,8 @@ class Namer {
|
||||
// Denamespaces a string (e.g. The.Quick.Brown.Fox) by returning the last part
|
||||
// after the `delimiter` (Fox) and placing the rest in `namespace_prefix`
|
||||
// (The.Quick.Brown).
|
||||
virtual std::string Denamespace(const std::string &s,
|
||||
std::string &namespace_prefix,
|
||||
virtual std::string Denamespace(const std::string& s,
|
||||
std::string& namespace_prefix,
|
||||
const char delimiter = '.') const {
|
||||
const size_t pos = s.find_last_of(delimiter);
|
||||
if (pos == std::string::npos) {
|
||||
@@ -255,7 +255,7 @@ class Namer {
|
||||
}
|
||||
|
||||
// Same as above, but disregards the prefix.
|
||||
virtual std::string Denamespace(const std::string &s,
|
||||
virtual std::string Denamespace(const std::string& s,
|
||||
const char delimiter = '.') const {
|
||||
std::string prefix;
|
||||
return Denamespace(s, prefix, delimiter);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace python {
|
||||
Version::Version(const std::string &version) {
|
||||
Version::Version(const std::string& version) {
|
||||
std::stringstream ss(version);
|
||||
char dot;
|
||||
ss >> major >> dot >> minor >> dot >> micro;
|
||||
@@ -17,7 +17,7 @@ bool Version::IsValid() const {
|
||||
return (major == 0 || major == 2 || major == 3) && minor >= 0 && micro >= 0;
|
||||
}
|
||||
|
||||
std::set<std::string> Keywords(const Version &version) {
|
||||
std::set<std::string> Keywords(const Version& version) {
|
||||
switch (version.major) {
|
||||
case 2:
|
||||
// https://docs.python.org/2/reference/lexical_analysis.html#keywords
|
||||
@@ -44,15 +44,15 @@ std::set<std::string> Keywords(const Version &version) {
|
||||
}
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Import(const std::string &module) {
|
||||
const python::Import& python::Imports::Import(const std::string& module) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
imports.push_back(std::move(import));
|
||||
return imports.back();
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Import(const std::string &module,
|
||||
const std::string &name) {
|
||||
const python::Import& python::Imports::Import(const std::string& module,
|
||||
const std::string& name) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
import.name = name;
|
||||
@@ -60,15 +60,15 @@ const python::Import &python::Imports::Import(const std::string &module,
|
||||
return imports.back();
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Export(const std::string &module) {
|
||||
const python::Import& python::Imports::Export(const std::string& module) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
exports.push_back(std::move(import));
|
||||
return exports.back();
|
||||
}
|
||||
|
||||
const python::Import &python::Imports::Export(const std::string &module,
|
||||
const std::string &name) {
|
||||
const python::Import& python::Imports::Export(const std::string& module,
|
||||
const std::string& name) {
|
||||
python::Import import;
|
||||
import.module = module;
|
||||
import.name = name;
|
||||
|
||||
@@ -62,7 +62,7 @@ static const Namer::Config kStubConfig = {
|
||||
//
|
||||
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
|
||||
struct Version {
|
||||
explicit Version(const std::string &version);
|
||||
explicit Version(const std::string& version);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
@@ -71,7 +71,7 @@ struct Version {
|
||||
int16_t micro = 0;
|
||||
};
|
||||
|
||||
std::set<std::string> Keywords(const Version &version);
|
||||
std::set<std::string> Keywords(const Version& version);
|
||||
|
||||
struct Import {
|
||||
bool IsLocal() const { return module == "."; }
|
||||
@@ -81,13 +81,13 @@ struct Import {
|
||||
};
|
||||
|
||||
struct Imports {
|
||||
const python::Import &Import(const std::string &module);
|
||||
const python::Import &Import(const std::string &module,
|
||||
const std::string &name);
|
||||
const python::Import& Import(const std::string& module);
|
||||
const python::Import& Import(const std::string& module,
|
||||
const std::string& name);
|
||||
|
||||
const python::Import &Export(const std::string &module);
|
||||
const python::Import &Export(const std::string &module,
|
||||
const std::string &name);
|
||||
const python::Import& Export(const std::string& module);
|
||||
const python::Import& Export(const std::string& module,
|
||||
const std::string& name);
|
||||
|
||||
std::vector<python::Import> imports;
|
||||
std::vector<python::Import> exports;
|
||||
|
||||
Reference in New Issue
Block a user