mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 21:17:25 +00:00
Added --filename-suffix and --filename-ext to flatc (#5778)
* Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case. * Added --filename-suffix and --filename-ext to flatc * Fixed typo and added example generation of suffix and extension for C++ * Removed extra ; * Removed clang-format block from a region that didn't need it. Fixed an auto format of another clang-format block * Added docs, fixed pointer alignment, removed suffix test file
This commit is contained in:
@@ -94,15 +94,20 @@ class BaseGenerator {
|
||||
static std::string NamespaceDir(const Parser &parser, const std::string &path,
|
||||
const Namespace &ns);
|
||||
|
||||
std::string GeneratedFileName(const std::string &path,
|
||||
const std::string &file_name,
|
||||
const IDLOptions &options) const;
|
||||
|
||||
protected:
|
||||
BaseGenerator(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name, std::string qualifying_start,
|
||||
std::string qualifying_separator)
|
||||
std::string qualifying_separator, std::string default_extension)
|
||||
: parser_(parser),
|
||||
path_(path),
|
||||
file_name_(file_name),
|
||||
qualifying_start_(qualifying_start),
|
||||
qualifying_separator_(qualifying_separator) {}
|
||||
qualifying_separator_(qualifying_separator),
|
||||
default_extension_(default_extension) {}
|
||||
virtual ~BaseGenerator() {}
|
||||
|
||||
// No copy/assign.
|
||||
@@ -138,6 +143,7 @@ class BaseGenerator {
|
||||
const std::string &file_name_;
|
||||
const std::string qualifying_start_;
|
||||
const std::string qualifying_separator_;
|
||||
const std::string default_extension_;
|
||||
};
|
||||
|
||||
struct CommentConfig {
|
||||
|
||||
@@ -365,7 +365,7 @@ template<typename T> class Vector {
|
||||
// This class is a pointer. Copying will therefore create an invalid object.
|
||||
// Private and unimplemented copy constructor.
|
||||
Vector(const Vector &);
|
||||
Vector& operator=(const Vector&);
|
||||
Vector &operator=(const Vector &);
|
||||
|
||||
template<typename K> static int KeyCompare(const void *ap, const void *bp) {
|
||||
const K *key = reinterpret_cast<const K *>(ap);
|
||||
@@ -525,7 +525,7 @@ template<typename T, uint16_t length> class Array<Offset<T>, length> {
|
||||
static_assert(flatbuffers::is_same<T, void>::value, "unexpected type T");
|
||||
|
||||
public:
|
||||
typedef const void* return_type;
|
||||
typedef const void *return_type;
|
||||
|
||||
const uint8_t *Data() const { return data_; }
|
||||
|
||||
|
||||
@@ -218,16 +218,17 @@ class Object {
|
||||
class Sized : public Object {
|
||||
public:
|
||||
// Size prefix.
|
||||
Sized(const uint8_t *data, uint8_t byte_width) :
|
||||
Object(data, byte_width), size_(read_size()) {}
|
||||
Sized(const uint8_t *data, uint8_t byte_width)
|
||||
: Object(data, byte_width), size_(read_size()) {}
|
||||
// Manual size.
|
||||
Sized(const uint8_t *data, uint8_t byte_width, size_t sz) :
|
||||
Object(data, byte_width), size_(sz) {}
|
||||
Sized(const uint8_t *data, uint8_t byte_width, size_t sz)
|
||||
: Object(data, byte_width), size_(sz) {}
|
||||
size_t size() const { return size_; }
|
||||
// Access size stored in `byte_width_` bytes before data_ pointer.
|
||||
size_t read_size() const {
|
||||
return static_cast<size_t>(ReadUInt64(data_ - byte_width_, byte_width_));
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t size_;
|
||||
};
|
||||
@@ -235,11 +236,10 @@ class Sized : public Object {
|
||||
class String : public Sized {
|
||||
public:
|
||||
// Size prefix.
|
||||
String(const uint8_t *data, uint8_t byte_width)
|
||||
: Sized(data, byte_width) {}
|
||||
String(const uint8_t *data, uint8_t byte_width) : Sized(data, byte_width) {}
|
||||
// Manual size.
|
||||
String(const uint8_t *data, uint8_t byte_width, size_t sz)
|
||||
: Sized(data, byte_width, sz) {}
|
||||
: Sized(data, byte_width, sz) {}
|
||||
|
||||
size_t length() const { return size(); }
|
||||
const char *c_str() const { return reinterpret_cast<const char *>(data_); }
|
||||
@@ -296,6 +296,7 @@ class TypedVector : public Sized {
|
||||
Type ElementType() { return type_; }
|
||||
|
||||
friend Reference;
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
|
||||
@@ -614,8 +615,8 @@ class Reference {
|
||||
|
||||
TypedVector AsTypedVector() const {
|
||||
if (IsTypedVector()) {
|
||||
auto tv = TypedVector(Indirect(), byte_width_,
|
||||
ToTypedVectorElementType(type_));
|
||||
auto tv =
|
||||
TypedVector(Indirect(), byte_width_, ToTypedVectorElementType(type_));
|
||||
if (tv.type_ == FBT_STRING) {
|
||||
// These can't be accessed as strings, since we don't know the bit-width
|
||||
// of the size field, see the declaration of
|
||||
|
||||
@@ -560,6 +560,8 @@ struct IDLOptions {
|
||||
std::vector<std::string> cpp_includes;
|
||||
std::string cpp_std;
|
||||
std::string proto_namespace_suffix;
|
||||
std::string filename_suffix;
|
||||
std::string filename_extension;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
enum Language {
|
||||
@@ -643,6 +645,8 @@ struct IDLOptions {
|
||||
force_defaults(false),
|
||||
java_primitive_has_method(false),
|
||||
cs_gen_json_serializer(false),
|
||||
filename_suffix("_generated"),
|
||||
filename_extension(),
|
||||
lang(IDLOptions::kJava),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
lang_to_generate(0),
|
||||
@@ -1126,9 +1130,8 @@ bool GeneratePythonGRPC(const Parser &parser, const std::string &path,
|
||||
|
||||
// Generate GRPC Swift interfaces.
|
||||
// See idl_gen_grpc.cpp.
|
||||
extern bool GenerateSwiftGRPC(const Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
||||
@@ -636,30 +636,30 @@ inline bool EscapeString(const char *s, size_t length, std::string *_text,
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string BufferToHexText(const void *buffer, size_t buffer_size, size_t max_length,
|
||||
inline std::string BufferToHexText(const void *buffer, size_t buffer_size,
|
||||
size_t max_length,
|
||||
const std::string &wrapped_line_prefix,
|
||||
const std::string &wrapped_line_suffix) {
|
||||
std::string text = wrapped_line_prefix;
|
||||
size_t start_offset = 0;
|
||||
const char *s = reinterpret_cast<const char *>(buffer);
|
||||
for (size_t i = 0; s && i < buffer_size; i++) {
|
||||
// Last iteration or do we have more?
|
||||
bool have_more= i + 1 < buffer_size;
|
||||
text += "0x";
|
||||
text += IntToStringHex(static_cast<uint8_t>(s[i]), 2);
|
||||
if (have_more) {
|
||||
text += ',';
|
||||
}
|
||||
// If we have more to process and we reached max_length
|
||||
if (have_more && text.size() + wrapped_line_suffix.size() >= start_offset + max_length) {
|
||||
text += wrapped_line_suffix;
|
||||
text += '\n';
|
||||
start_offset = text.size();
|
||||
text += wrapped_line_prefix;
|
||||
}
|
||||
std::string text = wrapped_line_prefix;
|
||||
size_t start_offset = 0;
|
||||
const char *s = reinterpret_cast<const char *>(buffer);
|
||||
for (size_t i = 0; s && i < buffer_size; i++) {
|
||||
// Last iteration or do we have more?
|
||||
bool have_more = i + 1 < buffer_size;
|
||||
text += "0x";
|
||||
text += IntToStringHex(static_cast<uint8_t>(s[i]), 2);
|
||||
if (have_more) { text += ','; }
|
||||
// If we have more to process and we reached max_length
|
||||
if (have_more &&
|
||||
text.size() + wrapped_line_suffix.size() >= start_offset + max_length) {
|
||||
text += wrapped_line_suffix;
|
||||
text += '\n';
|
||||
start_offset = text.size();
|
||||
text += wrapped_line_prefix;
|
||||
}
|
||||
text += wrapped_line_suffix;
|
||||
return text;
|
||||
}
|
||||
text += wrapped_line_suffix;
|
||||
return text;
|
||||
}
|
||||
|
||||
// Remove paired quotes in a string: "text"|'text' -> text.
|
||||
|
||||
Reference in New Issue
Block a user