forked from BigfootDev/flatbuffers
Use the Google Style for clang-format without exceptions (#8706)
This reduces the friction when merging from github and google repos by using the exact same clang style guide. MARKDOWN=true
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
// Limits maximum depth of nested objects.
|
||||
// Prevents stack overflow while parse scheme, or json, or flexbuffer.
|
||||
#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
|
||||
# define FLATBUFFERS_MAX_PARSING_DEPTH 64
|
||||
#define FLATBUFFERS_MAX_PARSING_DEPTH 64
|
||||
#endif
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -192,15 +192,15 @@ class Parser;
|
||||
// Represents any type in the IDL, which is a combination of the BaseType
|
||||
// and additional information for vectors/structs_.
|
||||
struct Type {
|
||||
explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr,
|
||||
EnumDef *_ed = nullptr, uint16_t _fixed_length = 0)
|
||||
explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef* _sd = nullptr,
|
||||
EnumDef* _ed = nullptr, uint16_t _fixed_length = 0)
|
||||
: base_type(_base_type),
|
||||
element(BASE_TYPE_NONE),
|
||||
struct_def(_sd),
|
||||
enum_def(_ed),
|
||||
fixed_length(_fixed_length) {}
|
||||
|
||||
bool operator==(const Type &o) const {
|
||||
bool operator==(const Type& o) const {
|
||||
return base_type == o.base_type && element == o.element &&
|
||||
struct_def == o.struct_def && enum_def == o.enum_def;
|
||||
}
|
||||
@@ -209,15 +209,15 @@ struct Type {
|
||||
return Type(element, struct_def, enum_def, fixed_length);
|
||||
}
|
||||
|
||||
Offset<reflection::Type> Serialize(FlatBufferBuilder *builder) const;
|
||||
Offset<reflection::Type> Serialize(FlatBufferBuilder* builder) const;
|
||||
|
||||
bool Deserialize(const Parser &parser, const reflection::Type *type);
|
||||
bool Deserialize(const Parser& parser, const reflection::Type* type);
|
||||
|
||||
BaseType base_type;
|
||||
BaseType element; // only set if t == BASE_TYPE_VECTOR or
|
||||
// BASE_TYPE_VECTOR64
|
||||
StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
|
||||
EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
|
||||
StructDef* struct_def; // only set if t or element == BASE_TYPE_STRUCT
|
||||
EnumDef* enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
|
||||
// or for an integral type derived from an enum.
|
||||
uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
|
||||
};
|
||||
@@ -234,13 +234,16 @@ struct Value {
|
||||
|
||||
// Helper class that retains the original order of a set of identifiers and
|
||||
// also provides quick lookup.
|
||||
template<typename T> class SymbolTable {
|
||||
template <typename T>
|
||||
class SymbolTable {
|
||||
public:
|
||||
~SymbolTable() {
|
||||
for (auto it = vec.begin(); it != vec.end(); ++it) { delete *it; }
|
||||
for (auto it = vec.begin(); it != vec.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
bool Add(const std::string &name, T *e) {
|
||||
bool Add(const std::string& name, T* e) {
|
||||
vec.emplace_back(e);
|
||||
auto it = dict.find(name);
|
||||
if (it != dict.end()) return true;
|
||||
@@ -248,7 +251,7 @@ template<typename T> class SymbolTable {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Move(const std::string &oldname, const std::string &newname) {
|
||||
void Move(const std::string& oldname, const std::string& newname) {
|
||||
auto it = dict.find(oldname);
|
||||
if (it != dict.end()) {
|
||||
auto obj = it->second;
|
||||
@@ -259,14 +262,14 @@ template<typename T> class SymbolTable {
|
||||
}
|
||||
}
|
||||
|
||||
T *Lookup(const std::string &name) const {
|
||||
T* Lookup(const std::string& name) const {
|
||||
auto it = dict.find(name);
|
||||
return it == dict.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
public:
|
||||
std::map<std::string, T *> dict; // quick lookup
|
||||
std::vector<T *> vec; // Used to iterate in order of insertion
|
||||
std::map<std::string, T*> dict; // quick lookup
|
||||
std::vector<T*> vec; // Used to iterate in order of insertion
|
||||
};
|
||||
|
||||
// A name space, as set in the schema.
|
||||
@@ -277,14 +280,14 @@ struct Namespace {
|
||||
// which has a full namespaced descriptor.
|
||||
// With max_components you can request less than the number of components
|
||||
// the current namespace has.
|
||||
std::string GetFullyQualifiedName(const std::string &name,
|
||||
std::string GetFullyQualifiedName(const std::string& name,
|
||||
size_t max_components = 1000) const;
|
||||
|
||||
std::vector<std::string> components;
|
||||
size_t from_table; // Part of the namespace corresponds to a message/table.
|
||||
};
|
||||
|
||||
inline bool operator<(const Namespace &a, const Namespace &b) {
|
||||
inline bool operator<(const Namespace& a, const Namespace& b) {
|
||||
size_t min_size = std::min(a.components.size(), b.components.size());
|
||||
for (size_t i = 0; i < min_size; ++i) {
|
||||
if (a.components[i] != b.components[i])
|
||||
@@ -305,23 +308,23 @@ struct Definition {
|
||||
|
||||
flatbuffers::Offset<
|
||||
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
|
||||
SerializeAttributes(FlatBufferBuilder* builder, const Parser& parser) const;
|
||||
|
||||
bool DeserializeAttributes(Parser &parser,
|
||||
const Vector<Offset<reflection::KeyValue>> *attrs);
|
||||
bool DeserializeAttributes(Parser& parser,
|
||||
const Vector<Offset<reflection::KeyValue>>* attrs);
|
||||
|
||||
std::string name;
|
||||
std::string file;
|
||||
std::vector<std::string> doc_comment;
|
||||
SymbolTable<Value> attributes;
|
||||
bool generated; // did we already output code for this definition?
|
||||
Namespace *defined_namespace; // Where it was defined.
|
||||
Namespace* defined_namespace; // Where it was defined.
|
||||
|
||||
// For use with Serialize()
|
||||
uoffset_t serialized_location;
|
||||
int index; // Inside the vector it is stored.
|
||||
int refcount;
|
||||
const std::string *declaration_file;
|
||||
const std::string* declaration_file;
|
||||
};
|
||||
|
||||
struct FieldDef : public Definition {
|
||||
@@ -337,17 +340,14 @@ struct FieldDef : public Definition {
|
||||
padding(0),
|
||||
sibling_union_field(nullptr) {}
|
||||
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||
const Parser &parser) const;
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder* builder, uint16_t id,
|
||||
const Parser& parser) const;
|
||||
|
||||
bool Deserialize(Parser &parser, const reflection::Field *field);
|
||||
bool Deserialize(Parser& parser, const reflection::Field* field);
|
||||
|
||||
|
||||
bool IsScalarOptional() const {
|
||||
return IsScalar() && IsOptional();
|
||||
}
|
||||
bool IsScalarOptional() const { return IsScalar() && IsOptional(); }
|
||||
bool IsScalar() const {
|
||||
return ::flatbuffers::IsScalar(value.type.base_type);
|
||||
return ::flatbuffers::IsScalar(value.type.base_type);
|
||||
}
|
||||
bool IsOptional() const { return presence == kOptional; }
|
||||
bool IsRequired() const { return presence == kRequired; }
|
||||
@@ -383,14 +383,14 @@ struct FieldDef : public Definition {
|
||||
}
|
||||
Presence presence;
|
||||
|
||||
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
||||
StructDef* nested_flatbuffer; // This field contains nested FlatBuffer data.
|
||||
size_t padding; // Bytes to always pad after this field.
|
||||
|
||||
// sibling_union_field is always set to nullptr. The only exception is
|
||||
// when FieldDef is a union field or an union type field. Therefore,
|
||||
// sibling_union_field on a union field points to the union type field
|
||||
// and vice-versa.
|
||||
FieldDef *sibling_union_field;
|
||||
FieldDef* sibling_union_field;
|
||||
};
|
||||
|
||||
struct StructDef : public Definition {
|
||||
@@ -408,10 +408,10 @@ struct StructDef : public Definition {
|
||||
if (fields.vec.size()) fields.vec.back()->padding = padding;
|
||||
}
|
||||
|
||||
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
Offset<reflection::Object> Serialize(FlatBufferBuilder* builder,
|
||||
const Parser& parser) const;
|
||||
|
||||
bool Deserialize(Parser &parser, const reflection::Object *object);
|
||||
bool Deserialize(Parser& parser, const reflection::Object* object);
|
||||
|
||||
SymbolTable<FieldDef> fields;
|
||||
|
||||
@@ -430,17 +430,17 @@ struct EnumDef;
|
||||
struct EnumValBuilder;
|
||||
|
||||
struct EnumVal {
|
||||
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder* builder,
|
||||
const Parser& parser) const;
|
||||
|
||||
bool Deserialize(Parser &parser, const reflection::EnumVal *val);
|
||||
bool Deserialize(Parser& parser, const reflection::EnumVal* val);
|
||||
|
||||
flatbuffers::Offset<
|
||||
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
|
||||
SerializeAttributes(FlatBufferBuilder* builder, const Parser& parser) const;
|
||||
|
||||
bool DeserializeAttributes(Parser &parser,
|
||||
const Vector<Offset<reflection::KeyValue>> *attrs);
|
||||
bool DeserializeAttributes(Parser& parser,
|
||||
const Vector<Offset<reflection::KeyValue>>* attrs);
|
||||
|
||||
uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
|
||||
int64_t GetAsInt64() const { return value; }
|
||||
@@ -455,9 +455,9 @@ struct EnumVal {
|
||||
private:
|
||||
friend EnumDef;
|
||||
friend EnumValBuilder;
|
||||
friend bool operator==(const EnumVal &lhs, const EnumVal &rhs);
|
||||
friend bool operator==(const EnumVal& lhs, const EnumVal& rhs);
|
||||
|
||||
EnumVal(const std::string &_name, int64_t _val) : name(_name), value(_val) {}
|
||||
EnumVal(const std::string& _name, int64_t _val) : name(_name), value(_val) {}
|
||||
EnumVal() : value(0) {}
|
||||
|
||||
int64_t value;
|
||||
@@ -466,37 +466,38 @@ struct EnumVal {
|
||||
struct EnumDef : public Definition {
|
||||
EnumDef() : is_union(false), uses_multiple_type_instances(false) {}
|
||||
|
||||
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
Offset<reflection::Enum> Serialize(FlatBufferBuilder* builder,
|
||||
const Parser& parser) const;
|
||||
|
||||
bool Deserialize(Parser &parser, const reflection::Enum *values);
|
||||
bool Deserialize(Parser& parser, const reflection::Enum* values);
|
||||
|
||||
template<typename T> void ChangeEnumValue(EnumVal *ev, T new_val);
|
||||
template <typename T>
|
||||
void ChangeEnumValue(EnumVal* ev, T new_val);
|
||||
void SortByValue();
|
||||
void RemoveDuplicates();
|
||||
|
||||
std::string AllFlags() const;
|
||||
const EnumVal *MinValue() const;
|
||||
const EnumVal *MaxValue() const;
|
||||
const EnumVal* MinValue() const;
|
||||
const EnumVal* MaxValue() const;
|
||||
// Returns the number of integer steps from v1 to v2.
|
||||
uint64_t Distance(const EnumVal *v1, const EnumVal *v2) const;
|
||||
uint64_t Distance(const EnumVal* v1, const EnumVal* v2) const;
|
||||
// Returns the number of integer steps from Min to Max.
|
||||
uint64_t Distance() const { return Distance(MinValue(), MaxValue()); }
|
||||
|
||||
EnumVal *ReverseLookup(int64_t enum_idx,
|
||||
EnumVal* ReverseLookup(int64_t enum_idx,
|
||||
bool skip_union_default = false) const;
|
||||
EnumVal *FindByValue(const std::string &constant) const;
|
||||
EnumVal* FindByValue(const std::string& constant) const;
|
||||
|
||||
std::string ToString(const EnumVal &ev) const {
|
||||
std::string ToString(const EnumVal& ev) const {
|
||||
return IsUInt64() ? NumToString(ev.GetAsUInt64())
|
||||
: NumToString(ev.GetAsInt64());
|
||||
}
|
||||
|
||||
size_t size() const { return vals.vec.size(); }
|
||||
|
||||
const std::vector<EnumVal *> &Vals() const { return vals.vec; }
|
||||
const std::vector<EnumVal*>& Vals() const { return vals.vec; }
|
||||
|
||||
const EnumVal *Lookup(const std::string &enum_name) const {
|
||||
const EnumVal* Lookup(const std::string& enum_name) const {
|
||||
return vals.Lookup(enum_name);
|
||||
}
|
||||
|
||||
@@ -515,53 +516,53 @@ struct EnumDef : public Definition {
|
||||
SymbolTable<EnumVal> vals;
|
||||
};
|
||||
|
||||
inline bool IsString(const Type &type) {
|
||||
inline bool IsString(const Type& type) {
|
||||
return type.base_type == BASE_TYPE_STRING;
|
||||
}
|
||||
|
||||
inline bool IsStruct(const Type &type) {
|
||||
inline bool IsStruct(const Type& type) {
|
||||
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
||||
}
|
||||
|
||||
inline bool IsIncompleteStruct(const Type &type) {
|
||||
inline bool IsIncompleteStruct(const Type& type) {
|
||||
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->predecl;
|
||||
}
|
||||
|
||||
inline bool IsTable(const Type &type) {
|
||||
inline bool IsTable(const Type& type) {
|
||||
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
||||
}
|
||||
|
||||
inline bool IsUnion(const Type &type) {
|
||||
inline bool IsUnion(const Type& type) {
|
||||
return type.enum_def != nullptr && type.enum_def->is_union;
|
||||
}
|
||||
|
||||
inline bool IsUnionType(const Type &type) {
|
||||
inline bool IsUnionType(const Type& type) {
|
||||
return IsUnion(type) && IsInteger(type.base_type);
|
||||
}
|
||||
|
||||
inline bool IsVector(const Type &type) { return IsVector(type.base_type); }
|
||||
inline bool IsVector(const Type& type) { return IsVector(type.base_type); }
|
||||
|
||||
inline bool IsVectorOfStruct(const Type &type) {
|
||||
inline bool IsVectorOfStruct(const Type& type) {
|
||||
return IsVector(type) && IsStruct(type.VectorType());
|
||||
}
|
||||
|
||||
inline bool IsVectorOfTable(const Type &type) {
|
||||
inline bool IsVectorOfTable(const Type& type) {
|
||||
return IsVector(type) && IsTable(type.VectorType());
|
||||
}
|
||||
|
||||
inline bool IsArray(const Type &type) {
|
||||
inline bool IsArray(const Type& type) {
|
||||
return type.base_type == BASE_TYPE_ARRAY;
|
||||
}
|
||||
|
||||
inline bool IsSeries(const Type &type) {
|
||||
inline bool IsSeries(const Type& type) {
|
||||
return IsVector(type) || IsArray(type);
|
||||
}
|
||||
|
||||
inline bool IsEnum(const Type &type) {
|
||||
inline bool IsEnum(const Type& type) {
|
||||
return type.enum_def != nullptr && IsInteger(type.base_type);
|
||||
}
|
||||
|
||||
inline size_t InlineSize(const Type &type) {
|
||||
inline size_t InlineSize(const Type& type) {
|
||||
return IsStruct(type)
|
||||
? type.struct_def->bytesize
|
||||
: (IsArray(type)
|
||||
@@ -569,7 +570,7 @@ inline size_t InlineSize(const Type &type) {
|
||||
: SizeOf(type.base_type));
|
||||
}
|
||||
|
||||
inline size_t InlineAlignment(const Type &type) {
|
||||
inline size_t InlineAlignment(const Type& type) {
|
||||
if (IsStruct(type)) {
|
||||
return type.struct_def->minalign;
|
||||
} else if (IsArray(type)) {
|
||||
@@ -579,14 +580,14 @@ inline size_t InlineAlignment(const Type &type) {
|
||||
return SizeOf(type.base_type);
|
||||
}
|
||||
}
|
||||
inline bool operator==(const EnumVal &lhs, const EnumVal &rhs) {
|
||||
inline bool operator==(const EnumVal& lhs, const EnumVal& rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
inline bool operator!=(const EnumVal &lhs, const EnumVal &rhs) {
|
||||
inline bool operator!=(const EnumVal& lhs, const EnumVal& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool EqualByName(const Type &a, const Type &b) {
|
||||
inline bool EqualByName(const Type& a, const Type& b) {
|
||||
return a.base_type == b.base_type && a.element == b.element &&
|
||||
(a.struct_def == b.struct_def ||
|
||||
(a.struct_def != nullptr && b.struct_def != nullptr &&
|
||||
@@ -597,18 +598,18 @@ inline bool EqualByName(const Type &a, const Type &b) {
|
||||
}
|
||||
|
||||
struct RPCCall : public Definition {
|
||||
Offset<reflection::RPCCall> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
Offset<reflection::RPCCall> Serialize(FlatBufferBuilder* builder,
|
||||
const Parser& parser) const;
|
||||
|
||||
bool Deserialize(Parser &parser, const reflection::RPCCall *call);
|
||||
bool Deserialize(Parser& parser, const reflection::RPCCall* call);
|
||||
|
||||
StructDef *request, *response;
|
||||
};
|
||||
|
||||
struct ServiceDef : public Definition {
|
||||
Offset<reflection::Service> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
bool Deserialize(Parser &parser, const reflection::Service *service);
|
||||
Offset<reflection::Service> Serialize(FlatBufferBuilder* builder,
|
||||
const Parser& parser) const;
|
||||
bool Deserialize(Parser& parser, const reflection::Service* service);
|
||||
|
||||
SymbolTable<RPCCall> calls;
|
||||
};
|
||||
@@ -627,7 +628,7 @@ struct IncludedFile {
|
||||
};
|
||||
|
||||
// Since IncludedFile is contained within a std::set, need to provide ordering.
|
||||
inline bool operator<(const IncludedFile &a, const IncludedFile &b) {
|
||||
inline bool operator<(const IncludedFile& a, const IncludedFile& b) {
|
||||
return a.filename < b.filename;
|
||||
}
|
||||
|
||||
@@ -711,7 +712,7 @@ struct IDLOptions {
|
||||
/********************************** Python **********************************/
|
||||
bool python_no_type_prefix_suffix;
|
||||
bool python_typing;
|
||||
bool python_decode_obj_api_strings=false;
|
||||
bool python_decode_obj_api_strings = false;
|
||||
|
||||
// The target Python version. Can be one of the following:
|
||||
// - "0"
|
||||
@@ -881,7 +882,7 @@ struct ParserState {
|
||||
attr_is_trivial_ascii_string_(true) {}
|
||||
|
||||
protected:
|
||||
void ResetState(const char *source) {
|
||||
void ResetState(const char* source) {
|
||||
prev_cursor_ = source;
|
||||
cursor_ = source;
|
||||
line_ = 0;
|
||||
@@ -898,9 +899,9 @@ struct ParserState {
|
||||
return static_cast<int64_t>(cursor_ - line_start_);
|
||||
}
|
||||
|
||||
const char *prev_cursor_;
|
||||
const char *cursor_;
|
||||
const char *line_start_;
|
||||
const char* prev_cursor_;
|
||||
const char* cursor_;
|
||||
const char* line_start_;
|
||||
int line_; // the current line being parsed
|
||||
int token_;
|
||||
|
||||
@@ -924,14 +925,14 @@ class CheckedError {
|
||||
explicit CheckedError(bool error)
|
||||
: is_error_(error), has_been_checked_(false) {}
|
||||
|
||||
CheckedError &operator=(const CheckedError &other) {
|
||||
CheckedError& operator=(const CheckedError& other) {
|
||||
is_error_ = other.is_error_;
|
||||
has_been_checked_ = false;
|
||||
other.has_been_checked_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CheckedError(const CheckedError &other) {
|
||||
CheckedError(const CheckedError& other) {
|
||||
*this = other; // Use assignment operator.
|
||||
}
|
||||
|
||||
@@ -960,7 +961,7 @@ class CheckedError {
|
||||
|
||||
class Parser : public ParserState {
|
||||
public:
|
||||
explicit Parser(const IDLOptions &options = IDLOptions())
|
||||
explicit Parser(const IDLOptions& options = IDLOptions())
|
||||
: current_namespace_(nullptr),
|
||||
empty_namespace_(nullptr),
|
||||
flex_builder_(256, flexbuffers::BUILDER_FLAG_SHARE_ALL),
|
||||
@@ -972,7 +973,9 @@ class Parser : public ParserState {
|
||||
source_(nullptr),
|
||||
anonymous_counter_(0),
|
||||
parse_depth_counter_(0) {
|
||||
if (opts.force_defaults) { builder_.ForceDefaults(true); }
|
||||
if (opts.force_defaults) {
|
||||
builder_.ForceDefaults(true);
|
||||
}
|
||||
// Start out with the empty namespace being current.
|
||||
empty_namespace_ = new Namespace();
|
||||
namespaces_.push_back(empty_namespace_);
|
||||
@@ -1012,11 +1015,11 @@ class Parser : public ParserState {
|
||||
}
|
||||
|
||||
// Copying is not allowed
|
||||
Parser(const Parser &) = delete;
|
||||
Parser &operator=(const Parser &) = delete;
|
||||
Parser(const Parser&) = delete;
|
||||
Parser& operator=(const Parser&) = delete;
|
||||
|
||||
Parser(Parser &&) = default;
|
||||
Parser &operator=(Parser &&) = default;
|
||||
Parser(Parser&&) = default;
|
||||
Parser& operator=(Parser&&) = default;
|
||||
|
||||
~Parser() {
|
||||
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
||||
@@ -1035,16 +1038,16 @@ class Parser : public ParserState {
|
||||
// supply its name in source_filename.
|
||||
// All paths specified in this call must be in posix format, if you accept
|
||||
// paths from user input, please call PosixPath on them first.
|
||||
bool Parse(const char *_source, const char **include_paths = nullptr,
|
||||
const char *source_filename = nullptr);
|
||||
bool Parse(const char* _source, const char** include_paths = nullptr,
|
||||
const char* source_filename = nullptr);
|
||||
|
||||
bool ParseJson(const char *json, const char *json_filename = nullptr);
|
||||
bool ParseJson(const char* json, const char* json_filename = nullptr);
|
||||
|
||||
// Returns the number of characters were consumed when parsing a JSON string.
|
||||
std::ptrdiff_t BytesConsumed() const;
|
||||
|
||||
// Set the root type. May override the one set in the schema.
|
||||
bool SetRootType(const char *name);
|
||||
bool SetRootType(const char* name);
|
||||
|
||||
// Mark all definitions as already having code generated.
|
||||
void MarkGenerated();
|
||||
@@ -1052,41 +1055,41 @@ class Parser : public ParserState {
|
||||
// Get the files recursively included by the given file. The returned
|
||||
// container will have at least the given file.
|
||||
std::set<std::string> GetIncludedFilesRecursive(
|
||||
const std::string &file_name) const;
|
||||
const std::string& file_name) const;
|
||||
|
||||
// Fills builder_ with a binary version of the schema parsed.
|
||||
// See reflection/reflection.fbs
|
||||
void Serialize();
|
||||
|
||||
// Deserialize a schema buffer
|
||||
bool Deserialize(const uint8_t *buf, const size_t size);
|
||||
bool Deserialize(const uint8_t* buf, const size_t size);
|
||||
|
||||
// Fills internal structure as if the schema passed had been loaded by parsing
|
||||
// with Parse except that included filenames will not be populated.
|
||||
bool Deserialize(const reflection::Schema *schema);
|
||||
bool Deserialize(const reflection::Schema* schema);
|
||||
|
||||
Type *DeserializeType(const reflection::Type *type);
|
||||
Type* DeserializeType(const reflection::Type* type);
|
||||
|
||||
// Checks that the schema represented by this parser is a safe evolution
|
||||
// of the schema provided. Returns non-empty error on any problems.
|
||||
std::string ConformTo(const Parser &base);
|
||||
std::string ConformTo(const Parser& base);
|
||||
|
||||
// Similar to Parse(), but now only accepts JSON to be parsed into a
|
||||
// FlexBuffer.
|
||||
bool ParseFlexBuffer(const char *source, const char *source_filename,
|
||||
flexbuffers::Builder *builder);
|
||||
bool ParseFlexBuffer(const char* source, const char* source_filename,
|
||||
flexbuffers::Builder* builder);
|
||||
|
||||
StructDef *LookupStruct(const std::string &id) const;
|
||||
StructDef *LookupStructThruParentNamespaces(const std::string &id) const;
|
||||
StructDef* LookupStruct(const std::string& id) const;
|
||||
StructDef* LookupStructThruParentNamespaces(const std::string& id) const;
|
||||
|
||||
std::string UnqualifiedName(const std::string &fullQualifiedName);
|
||||
std::string UnqualifiedName(const std::string& fullQualifiedName);
|
||||
|
||||
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
||||
FLATBUFFERS_CHECKED_ERROR Error(const std::string& msg);
|
||||
|
||||
// @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars
|
||||
// in a schema.
|
||||
// @param opts Options used to parce a schema and generate code.
|
||||
static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts);
|
||||
static bool SupportsOptionalScalars(const flatbuffers::IDLOptions& opts);
|
||||
|
||||
// Get the set of included files that are directly referenced by the file
|
||||
// being parsed. This does not include files that are transitively included by
|
||||
@@ -1096,101 +1099,101 @@ class Parser : public ParserState {
|
||||
private:
|
||||
class ParseDepthGuard;
|
||||
|
||||
void Message(const std::string &msg);
|
||||
void Warning(const std::string &msg);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val);
|
||||
void Message(const std::string& msg);
|
||||
void Warning(const std::string& msg);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t* val);
|
||||
FLATBUFFERS_CHECKED_ERROR Next();
|
||||
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
|
||||
bool Is(int t) const;
|
||||
bool IsIdent(const char *id) const;
|
||||
bool IsIdent(const char* id) const;
|
||||
FLATBUFFERS_CHECKED_ERROR Expect(int t);
|
||||
std::string TokenToStringId(int t) const;
|
||||
EnumDef *LookupEnum(const std::string &id);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id,
|
||||
std::string *last);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseType(Type &type);
|
||||
FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def,
|
||||
const std::string &name, const Type &type,
|
||||
FieldDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling);
|
||||
EnumDef* LookupEnum(const std::string& id);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string* id,
|
||||
std::string* last);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type& type);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseType(Type& type);
|
||||
FLATBUFFERS_CHECKED_ERROR AddField(StructDef& struct_def,
|
||||
const std::string& name, const Type& type,
|
||||
FieldDef** dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef& struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseString(Value& val, bool use_string_pooling);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseComma();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
|
||||
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value& val, FieldDef* field,
|
||||
size_t parent_fieldn,
|
||||
const StructDef *parent_struct_def,
|
||||
const StructDef* parent_struct_def,
|
||||
size_t count,
|
||||
bool inside_vector = false);
|
||||
template<typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn,
|
||||
const StructDef *struct_def,
|
||||
template <typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t& fieldn,
|
||||
const StructDef* struct_def,
|
||||
F body);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
|
||||
std::string *value, uoffset_t *ovalue);
|
||||
void SerializeStruct(const StructDef &struct_def, const Value &val);
|
||||
void SerializeStruct(FlatBufferBuilder &builder, const StructDef &struct_def,
|
||||
const Value &val);
|
||||
template<typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(size_t &count, F body);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue,
|
||||
FieldDef *field, size_t fieldn);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseArray(Value &array);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef& struct_def,
|
||||
std::string* value, uoffset_t* ovalue);
|
||||
void SerializeStruct(const StructDef& struct_def, const Value& val);
|
||||
void SerializeStruct(FlatBufferBuilder& builder, const StructDef& struct_def,
|
||||
const Value& val);
|
||||
template <typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(size_t& count, F body);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type& type, uoffset_t* ovalue,
|
||||
FieldDef* field, size_t fieldn);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseArray(Value& array);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer(
|
||||
Value &val, FieldDef *field, size_t fieldn,
|
||||
const StructDef *parent_struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable<Value> *attributes);
|
||||
FLATBUFFERS_CHECKED_ERROR TryTypedValue(const std::string *name, int dtoken,
|
||||
bool check, Value &e, BaseType req,
|
||||
bool *destmatch);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef *field);
|
||||
Value& val, FieldDef* field, size_t fieldn,
|
||||
const StructDef* parent_struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable<Value>* attributes);
|
||||
FLATBUFFERS_CHECKED_ERROR TryTypedValue(const std::string* name, int dtoken,
|
||||
bool check, Value& e, BaseType req,
|
||||
bool* destmatch);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseHash(Value& e, FieldDef* field);
|
||||
FLATBUFFERS_CHECKED_ERROR TokenError();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e,
|
||||
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string* name, Value& e,
|
||||
bool check_now);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type,
|
||||
std::string *result);
|
||||
StructDef *LookupCreateStruct(const std::string &name,
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string* name, Value& e);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type& type,
|
||||
std::string* result);
|
||||
StructDef* LookupCreateStruct(const std::string& name,
|
||||
bool create_if_new = true,
|
||||
bool definition = false);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest,
|
||||
const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef** dest,
|
||||
const char* filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseNamespace();
|
||||
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
|
||||
StructDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, bool is_union,
|
||||
EnumDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseDecl(const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseService(const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
||||
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string& name,
|
||||
StructDef** dest);
|
||||
FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string& name, bool is_union,
|
||||
EnumDef** dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseDecl(const char* filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseService(const char* filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef* struct_def,
|
||||
bool isextend, bool inside_oneof);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoMapField(StructDef *struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoMapField(StructDef* struct_def);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type* type);
|
||||
FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant(
|
||||
flexbuffers::Builder *builder);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder);
|
||||
FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source,
|
||||
const char *source_filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseRoot(const char *_source,
|
||||
const char **include_paths,
|
||||
const char *source_filename);
|
||||
flexbuffers::Builder* builder);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder* builder);
|
||||
FLATBUFFERS_CHECKED_ERROR StartParseFile(const char* source,
|
||||
const char* source_filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseRoot(const char* _source,
|
||||
const char** include_paths,
|
||||
const char* source_filename);
|
||||
FLATBUFFERS_CHECKED_ERROR CheckPrivateLeak();
|
||||
FLATBUFFERS_CHECKED_ERROR CheckPrivatelyLeakedFields(
|
||||
const Definition &def, const Definition &value_type);
|
||||
FLATBUFFERS_CHECKED_ERROR DoParse(const char *_source,
|
||||
const char **include_paths,
|
||||
const char *source_filename,
|
||||
const char *include_filename);
|
||||
const Definition& def, const Definition& value_type);
|
||||
FLATBUFFERS_CHECKED_ERROR DoParse(const char* _source,
|
||||
const char** include_paths,
|
||||
const char* source_filename,
|
||||
const char* include_filename);
|
||||
FLATBUFFERS_CHECKED_ERROR DoParseJson();
|
||||
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef *> &fields,
|
||||
StructDef *struct_def,
|
||||
const char *suffix, BaseType baseType);
|
||||
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef*>& fields,
|
||||
StructDef* struct_def,
|
||||
const char* suffix, BaseType baseType);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute(
|
||||
const std::string &align_constant, size_t min_align, size_t *align);
|
||||
const std::string& align_constant, size_t min_align, size_t* align);
|
||||
|
||||
bool SupportsAdvancedUnionFeatures() const;
|
||||
bool SupportsAdvancedArrayFeatures() const;
|
||||
@@ -1198,27 +1201,28 @@ class Parser : public ParserState {
|
||||
bool SupportsDefaultVectorsAndStrings() const;
|
||||
bool Supports64BitOffsets() const;
|
||||
bool SupportsUnionUnderlyingType() const;
|
||||
Namespace *UniqueNamespace(Namespace *ns);
|
||||
Namespace* UniqueNamespace(Namespace* ns);
|
||||
|
||||
FLATBUFFERS_CHECKED_ERROR RecurseError();
|
||||
template<typename F> CheckedError Recurse(F f);
|
||||
template <typename F>
|
||||
CheckedError Recurse(F f);
|
||||
|
||||
const std::string &GetPooledString(const std::string &s) const;
|
||||
const std::string& GetPooledString(const std::string& s) const;
|
||||
|
||||
public:
|
||||
SymbolTable<Type> types_;
|
||||
SymbolTable<StructDef> structs_;
|
||||
SymbolTable<EnumDef> enums_;
|
||||
SymbolTable<ServiceDef> services_;
|
||||
std::vector<Namespace *> namespaces_;
|
||||
Namespace *current_namespace_;
|
||||
Namespace *empty_namespace_;
|
||||
std::vector<Namespace*> namespaces_;
|
||||
Namespace* current_namespace_;
|
||||
Namespace* empty_namespace_;
|
||||
std::string error_; // User readable error_ if Parse() == false
|
||||
|
||||
FlatBufferBuilder builder_; // any data contained in the file
|
||||
flexbuffers::Builder flex_builder_;
|
||||
flexbuffers::Reference flex_root_;
|
||||
StructDef *root_struct_def_;
|
||||
StructDef* root_struct_def_;
|
||||
std::string file_identifier_;
|
||||
std::string file_extension_;
|
||||
|
||||
@@ -1237,9 +1241,9 @@ class Parser : public ParserState {
|
||||
std::string file_being_parsed_;
|
||||
|
||||
private:
|
||||
const char *source_;
|
||||
const char* source_;
|
||||
|
||||
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
||||
std::vector<std::pair<Value, FieldDef*>> field_stack_;
|
||||
|
||||
// TODO(cneo): Refactor parser to use string_cache more often to save
|
||||
// on memory usage.
|
||||
@@ -1260,51 +1264,50 @@ class Parser : public ParserState {
|
||||
// These functions return nullptr on success, or an error string,
|
||||
// which may happen if the flatbuffer cannot be encoded in JSON (e.g.,
|
||||
// it contains non-UTF-8 byte arrays in String values).
|
||||
extern bool GenerateTextFromTable(const Parser &parser,
|
||||
const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
extern const char *GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *text);
|
||||
extern const char *GenerateTextFile(const Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
extern bool GenerateTextFromTable(const Parser& parser, const void* table,
|
||||
const std::string& tablename,
|
||||
std::string* text);
|
||||
extern const char* GenerateText(const Parser& parser, const void* flatbuffer,
|
||||
std::string* text);
|
||||
extern const char* GenerateTextFile(const Parser& parser,
|
||||
const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
extern const char *GenTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
extern const char *GenText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *text);
|
||||
extern const char *GenTextFile(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
extern const char* GenTextFromTable(const Parser& parser, const void* table,
|
||||
const std::string& tablename,
|
||||
std::string* text);
|
||||
extern const char* GenText(const Parser& parser, const void* flatbuffer,
|
||||
std::string* text);
|
||||
extern const char* GenTextFile(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
// Generate GRPC Cpp interfaces.
|
||||
// See idl_gen_grpc.cpp.
|
||||
bool GenerateCppGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
bool GenerateCppGRPC(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
// Generate GRPC Go interfaces.
|
||||
// See idl_gen_grpc.cpp.
|
||||
bool GenerateGoGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
bool GenerateGoGRPC(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
// Generate GRPC Java classes.
|
||||
// See idl_gen_grpc.cpp
|
||||
bool GenerateJavaGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
bool GenerateJavaGRPC(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
// Generate GRPC Python interfaces.
|
||||
// See idl_gen_grpc.cpp.
|
||||
bool GeneratePythonGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
bool GeneratePythonGRPC(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
|
||||
// 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);
|
||||
|
||||
extern bool GenerateTSGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
extern bool GenerateTSGRPC(const Parser& parser, const std::string& path,
|
||||
const std::string& file_name);
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_IDL_H_
|
||||
|
||||
Reference in New Issue
Block a user