69 :
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109#define FLATBUFFERS_GEN_TYPES(TD) \
110 FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
111 FLATBUFFERS_GEN_TYPES_POINTER(TD) \
112 FLATBUFFERS_GEN_TYPE_ARRAY(TD)
113
114
115#ifdef __GNUC__
116__extension__
117#endif
119 #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
120 CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE) \
121 BASE_TYPE_ ## ENUM = ENUM_VALUE,
123 #undef FLATBUFFERS_TD
124};
125
126#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
127 static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
128 "define largest_scalar_t as " #CTYPE);
130#undef FLATBUFFERS_TD
131
132inline bool IsScalar (BaseType t) {
return t >= BASE_TYPE_UTYPE &&
133 t <= BASE_TYPE_DOUBLE; }
134inline bool IsInteger(BaseType t) {
return t >= BASE_TYPE_UTYPE &&
135 t <= BASE_TYPE_ULONG; }
136inline bool IsFloat (BaseType t) {
return t == BASE_TYPE_FLOAT ||
137 t == BASE_TYPE_DOUBLE; }
138inline bool IsLong (BaseType t) {
return t == BASE_TYPE_LONG ||
139 t == BASE_TYPE_ULONG; }
140inline bool IsBool (BaseType t) {
return t == BASE_TYPE_BOOL; }
141inline bool IsOneByte(BaseType t) {
return t >= BASE_TYPE_UTYPE &&
142 t <= BASE_TYPE_UCHAR; }
143inline bool IsVector (BaseType t) {
return t == BASE_TYPE_VECTOR ||
144 t == BASE_TYPE_VECTOR64; }
145
147 return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) ||
148 (t == BASE_TYPE_USHORT) || (t == BASE_TYPE_UINT) ||
149 (t == BASE_TYPE_ULONG);
150}
151
152inline size_t SizeOf(
const BaseType t) {
153 switch (t) {
154 #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
155 case BASE_TYPE_##ENUM: return sizeof(CTYPE);
157 #undef FLATBUFFERS_TD
159 }
160 return 0;
161}
162
163inline const char*
TypeName(
const BaseType t) {
164 switch (t) {
165 #define FLATBUFFERS_TD(ENUM, IDLTYPE, ...) \
166 case BASE_TYPE_##ENUM: return IDLTYPE;
168 #undef FLATBUFFERS_TD
170 }
171 return nullptr;
172}
173
174inline const char*
StringOf(
const BaseType t) {
175 switch (t) {
176 #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
177 case BASE_TYPE_##ENUM: return #CTYPE;
179 #undef FLATBUFFERS_TD
181 }
182 return "";
183}
184
185
186
187struct StructDef;
188struct EnumDef;
189class Parser;
190
191
192
194 explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd =
nullptr,
195 EnumDef *_ed = nullptr, uint16_t _fixed_length = 0)
196 : base_type(_base_type),
197 element(BASE_TYPE_NONE),
198 struct_def(_sd),
199 enum_def(_ed),
200 fixed_length(_fixed_length) {}
201
203 return base_type == o.base_type && element == o.element &&
204 struct_def == o.struct_def && enum_def == o.enum_def;
205 }
206
207 Type VectorType()
const {
208 return Type(element, struct_def, enum_def, fixed_length);
209 }
210
212
213 bool Deserialize(
const Parser &parser,
const reflection::Type *
type);
214
217
218 StructDef *struct_def;
219 EnumDef *enum_def;
220
221 uint16_t fixed_length;
222};
223
224
225struct Value {
226 Value()
228 offset(static_cast<voffset_t>(~(static_cast<voffset_t>(0U)))) {}
232};
233
234
235
236template<typename T> class SymbolTable {
237 public:
238 ~SymbolTable() {
239 for (auto it = vec.begin(); it != vec.end(); ++it) { delete *it; }
240 }
241
242 bool Add(
const std::string &name, T *e) {
243 vec.emplace_back(e);
244 auto it = dict.find(name);
245 if (it != dict.end()) return true;
247 return false;
248 }
249
250 void Move(const std::string &oldname, const std::string &newname) {
251 auto it = dict.find(oldname);
252 if (it != dict.end()) {
253 auto obj = it->second;
254 dict.erase(it);
256 } else {
258 }
259 }
260
261 T *Lookup(const std::string &name) const {
262 auto it = dict.find(name);
263 return it == dict.end() ? nullptr : it->second;
264 }
265
266 public:
267 std::map<std::string, T *> dict;
268 std::vector<T *> vec;
269};
270
271
272struct Namespace {
273 Namespace() : from_table(0) {}
274
275
276
277
278
279 std::string GetFullyQualifiedName(const std::string &name,
280 size_t max_components = 1000) const;
281
282 std::vector<std::string> components;
283 size_t from_table;
284};
285
286inline bool operator<(
const Namespace &a,
const Namespace &b) {
287 size_t min_size = std::min(a.components.size(),
b.components.size());
288 for (size_t i = 0; i < min_size; ++i) {
289 if (a.components[i] !=
b.components[i])
290 return a.components[i] <
b.components[i];
291 }
292 return a.components.size() <
b.components.size();
293}
294
295
296struct Definition {
297 Definition()
298 : generated(false),
299 defined_namespace(nullptr),
300 serialized_location(0),
302 refcount(1),
303 declaration_file(nullptr) {}
304
305 flatbuffers::Offset<
308
309 bool DeserializeAttributes(Parser &parser,
310 const Vector<Offset<reflection::KeyValue>> *attrs);
311
314 std::vector<std::string> doc_comment;
315 SymbolTable<Value> attributes;
316 bool generated;
317 Namespace *defined_namespace;
318
319
320 uoffset_t serialized_location;
322 int refcount;
323 const std::string *declaration_file;
324};
325
326struct FieldDef : public Definition {
327 FieldDef()
328 : deprecated(false),
329 key(false),
330 shared(false),
331 native_inline(false),
332 flexbuffer(false),
333 offset64(false),
335 nested_flatbuffer(nullptr),
336 padding(0),
337 sibling_union_field(nullptr) {}
338
340 const Parser &parser) const;
341
342 bool Deserialize(Parser &parser, const reflection::Field *field);
343
344 bool IsScalarOptional() const {
345 return IsScalar(value.type.base_type) && IsOptional();
346 }
347 bool IsOptional() const { return presence == kOptional; }
348 bool IsRequired() const { return presence == kRequired; }
349 bool IsDefault()
const {
return presence ==
kDefault; }
350
351 Value value;
352 bool deprecated;
353
354 bool key;
355 bool shared;
356
357 bool native_inline;
358
359 bool flexbuffer;
360 bool offset64;
361
362 enum Presence {
363
364 kRequired,
365
366 kOptional,
367
368
370 };
371 Presence static MakeFieldPresence(bool optional, bool required) {
373
374 return required ? FieldDef::kRequired
376 : FieldDef::kDefault;
377
378 }
379 Presence presence;
380
381 StructDef *nested_flatbuffer;
382 size_t padding;
383
384
385
386
387
388 FieldDef *sibling_union_field;
389};
390
391struct StructDef : public Definition {
392 StructDef()
393 : fixed(false),
394 predecl(true),
395 sortbysize(true),
396 has_key(false),
397 minalign(1),
398 bytesize(0) {}
399
400 void PadLastField(size_t min_align) {
401 auto padding = PaddingBytes(bytesize, min_align);
402 bytesize += padding;
403 if (fields.vec.size()) fields.vec.back()->padding = padding;
404 }
405
407 const Parser &parser) const;
408
409 bool Deserialize(Parser &parser, const reflection::Object *object);
410
411 SymbolTable<FieldDef> fields;
412
413 bool fixed;
414 bool predecl;
415 bool sortbysize;
416 bool has_key;
417 size_t minalign;
418 size_t bytesize;
419
421 std::vector<voffset_t> reserved_ids;
422};
423
424struct EnumDef;
425struct EnumValBuilder;
426
427struct EnumVal {
429 const Parser &parser) const;
430
431 bool Deserialize(Parser &parser, const reflection::EnumVal *val);
432
433 flatbuffers::Offset<
436
437 bool DeserializeAttributes(Parser &parser,
438 const Vector<Offset<reflection::KeyValue>> *attrs);
439
440 uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
441 int64_t GetAsInt64() const { return value; }
442 bool IsZero() const { return 0 == value; }
443 bool IsNonZero() const { return !IsZero(); }
444
446 std::vector<std::string> doc_comment;
448 SymbolTable<Value> attributes;
449
450 private:
451 friend EnumDef;
452 friend EnumValBuilder;
453 friend bool operator==(
const EnumVal &lhs,
const EnumVal &rhs);
454
455 EnumVal(
const std::string &_name, int64_t _val) :
name(_name), value(_val) {}
456 EnumVal() : value(0) {}
457
458 int64_t value;
459};
460
461struct EnumDef : public Definition {
462 EnumDef() : is_union(false), uses_multiple_type_instances(false) {}
463
465 const Parser &parser) const;
466
467 bool Deserialize(Parser &parser, const reflection::Enum *values);
468
469 template<typename T> void ChangeEnumValue(EnumVal *ev, T new_val);
470 void SortByValue();
471 void RemoveDuplicates();
472
473 std::string AllFlags() const;
474 const EnumVal *MinValue() const;
475 const EnumVal *MaxValue() const;
476
477 uint64_t Distance(const EnumVal *v1, const EnumVal *v2) const;
478
479 uint64_t Distance() const { return Distance(MinValue(), MaxValue()); }
480
481 EnumVal *ReverseLookup(int64_t enum_idx,
482 bool skip_union_default = false) const;
483 EnumVal *FindByValue(
const std::string &
constant)
const;
484
485 std::string ToString(const EnumVal &ev) const {
488 }
489
490 size_t size()
const {
return vals.vec.size(); }
491
492 const std::vector<EnumVal *> &Vals() const { return vals.vec; }
493
494 const EnumVal *Lookup(const std::string &enum_name) const {
495 return vals.Lookup(enum_name);
496 }
497
498 bool is_union;
499
500
501 bool uses_multiple_type_instances;
502 Type underlying_type;
503
504 private:
505 bool IsUInt64() const {
506 return (BASE_TYPE_ULONG == underlying_type.base_type);
507 }
508
509 friend EnumValBuilder;
510 SymbolTable<EnumVal> vals;
511};
512
514 return type.base_type == BASE_TYPE_STRING;
515}
516
518 return type.base_type == BASE_TYPE_STRUCT &&
type.struct_def->fixed;
519}
520
522 return type.base_type == BASE_TYPE_STRUCT &&
type.struct_def->predecl;
523}
524
526 return type.base_type == BASE_TYPE_STRUCT && !
type.struct_def->fixed;
527}
528
530 return type.enum_def !=
nullptr &&
type.enum_def->is_union;
531}
532
535}
536
538
541}
542
545}
546
548 return type.base_type == BASE_TYPE_ARRAY;
549}
550
553}
554
557}
558
561 ?
type.struct_def->bytesize
565}
566
569 return type.struct_def->minalign;
573 } else {
575 }
576}
577inline bool operator==(
const EnumVal &lhs,
const EnumVal &rhs) {
578 return lhs.value == rhs.value;
579}
580inline bool operator!=(
const EnumVal &lhs,
const EnumVal &rhs) {
581 return !(lhs == rhs);
582}
583
584inline bool EqualByName(
const Type &a,
const Type &b) {
585 return a.base_type ==
b.base_type && a.element ==
b.element &&
586 (a.struct_def ==
b.struct_def ||
587 (a.struct_def !=
nullptr &&
b.struct_def !=
nullptr &&
588 a.struct_def->name ==
b.struct_def->name)) &&
589 (a.enum_def ==
b.enum_def ||
590 (a.enum_def !=
nullptr &&
b.enum_def !=
nullptr &&
591 a.enum_def->name ==
b.enum_def->name));
592}
593
594struct RPCCall : public Definition {
596 const Parser &parser) const;
597
598 bool Deserialize(Parser &parser, const reflection::RPCCall *call);
599
600 StructDef *request, *response;
601};
602
603struct ServiceDef : public Definition {
605 const Parser &parser) const;
606 bool Deserialize(Parser &parser, const reflection::Service *service);
607
608 SymbolTable<RPCCall> calls;
609};
610
611struct IncludedFile {
612
613
614
615 std::string schema_name;
616
617
618
619
620
621 std::string filename;
622};
623
624
625inline bool operator<(
const IncludedFile &a,
const IncludedFile &b) {
626 return a.filename <
b.filename;
627}
628
629
630struct IDLOptions {
631
632 enum CaseStyle { CaseStyle_Unchanged = 0, CaseStyle_Upper, CaseStyle_Lower };
633 enum class ProtoIdGapAction { NO_OP, WARNING,
ERROR };
634 bool gen_jvmstatic;
635
636 bool use_flexbuffers;
637 bool strict_json;
638 bool output_default_scalars_in_json;
639 int indent_step;
640 bool cpp_minify_enums;
641 bool output_enum_identifiers;
642 bool prefixed_enums;
643 bool scoped_enums;
644 bool emit_min_max_enum_values;
645 bool swift_implementation_only;
646 bool include_dependence_headers;
647 bool mutable_buffer;
648 bool one_file;
649 bool proto_mode;
650 bool proto_oneof_union;
651 bool generate_all;
652 bool skip_unexpected_fields_in_json;
653 bool generate_name_strings;
654 bool generate_object_based_api;
655 bool gen_compare;
656 std::string cpp_object_api_pointer_type;
657 std::string cpp_object_api_string_type;
658 bool cpp_object_api_string_flexible_constructor;
659 CaseStyle cpp_object_api_field_case_style;
660 bool cpp_direct_copy;
661 bool gen_nullable;
662 std::string java_package_prefix;
663 bool java_checkerframework;
664 bool gen_generated;
665 bool gen_json_coders;
666 std::string object_prefix;
667 std::string object_suffix;
668 bool union_value_namespacing;
669 bool allow_non_utf8;
670 bool natural_utf8;
671 std::string include_prefix;
672 bool keep_prefix;
673 bool binary_schema_comments;
674 bool binary_schema_builtins;
675 bool binary_schema_gen_embed;
676 std::string go_import;
677 std::string go_namespace;
678 std::string go_module_name;
679 bool protobuf_ascii_alike;
680 bool size_prefixed;
681 std::string root_type;
682 bool force_defaults;
683 bool java_primitive_has_method;
684 bool cs_gen_json_serializer;
685 std::vector<std::string> cpp_includes;
686 std::string cpp_std;
687 bool cpp_static_reflection;
688 std::string proto_namespace_suffix;
689 std::string filename_suffix;
690 std::string filename_extension;
691 bool no_warnings;
692 bool warnings_as_errors;
693 std::string project_root;
694 bool cs_global_alias;
695 bool json_nested_flatbuffers;
696 bool json_nested_flexbuffers;
697 bool json_nested_legacy_flatbuffers;
698 bool ts_flat_files;
699 bool ts_entry_points;
700 bool ts_no_import_ext;
701 bool no_leak_private_annotations;
702 bool require_json_eof;
703 bool keep_proto_id;
704 bool python_no_type_prefix_suffix;
705 bool python_typing;
706 ProtoIdGapAction proto_id_gap_action;
707
708
709 enum Language {
710 kJava = 1 << 0,
711 kCSharp = 1 << 1,
712 kGo = 1 << 2,
713 kCpp = 1 << 3,
714 kPython = 1 << 5,
715 kPhp = 1 << 6,
716 kJson = 1 << 7,
717 kBinary = 1 << 8,
718 kTs = 1 << 9,
719 kJsonSchema = 1 << 10,
720 kDart = 1 << 11,
721 kLua = 1 << 12,
722 kLobster = 1 << 13,
723 kRust = 1 << 14,
724 kKotlin = 1 << 15,
725 kSwift = 1 << 16,
726 kNim = 1 << 17,
727 kProto = 1 << 18,
728 kMAX
729 };
730
731 enum MiniReflect {
kNone, kTypes, kTypesAndNames };
732
733 MiniReflect mini_reflect;
734
735
736 bool require_explicit_ids;
737
738
739 bool rust_serialize;
740
741
742 bool rust_module_root_file;
743
744
745
746 unsigned long lang_to_generate;
747
748
749
750 bool set_empty_strings_to_null;
751
752
753
754 bool set_empty_vectors_to_null;
755
756 IDLOptions()
757 : gen_jvmstatic(false),
758 use_flexbuffers(false),
759 strict_json(false),
760 output_default_scalars_in_json(false),
761 indent_step(2),
762 cpp_minify_enums(false),
763 output_enum_identifiers(true),
764 prefixed_enums(true),
765 scoped_enums(false),
766 emit_min_max_enum_values(true),
767 swift_implementation_only(false),
768 include_dependence_headers(true),
769 mutable_buffer(false),
770 one_file(false),
771 proto_mode(false),
772 proto_oneof_union(false),
773 generate_all(false),
774 skip_unexpected_fields_in_json(false),
775 generate_name_strings(false),
776 generate_object_based_api(false),
777 gen_compare(false),
778 cpp_object_api_pointer_type("std::unique_ptr"),
779 cpp_object_api_string_flexible_constructor(false),
780 cpp_object_api_field_case_style(CaseStyle_Unchanged),
781 cpp_direct_copy(true),
782 gen_nullable(false),
783 java_checkerframework(false),
784 gen_generated(false),
785 gen_json_coders(false),
786 object_suffix("T"),
787 union_value_namespacing(true),
788 allow_non_utf8(false),
789 natural_utf8(false),
790 keep_prefix(false),
791 binary_schema_comments(false),
792 binary_schema_builtins(false),
793 binary_schema_gen_embed(false),
794 protobuf_ascii_alike(false),
795 size_prefixed(false),
796 force_defaults(false),
797 java_primitive_has_method(false),
798 cs_gen_json_serializer(false),
799 cpp_static_reflection(false),
800 filename_suffix("_generated"),
801 filename_extension(),
802 no_warnings(false),
803 warnings_as_errors(false),
804 project_root(""),
805 cs_global_alias(false),
806 json_nested_flatbuffers(true),
807 json_nested_flexbuffers(true),
808 json_nested_legacy_flatbuffers(false),
809 ts_flat_files(false),
810 ts_entry_points(false),
811 ts_no_import_ext(false),
812 no_leak_private_annotations(false),
813 require_json_eof(true),
814 keep_proto_id(false),
815 python_no_type_prefix_suffix(false),
816 python_typing(false),
817 proto_id_gap_action(ProtoIdGapAction::WARNING),
818 mini_reflect(IDLOptions::
kNone),
819 require_explicit_ids(false),
820 rust_serialize(false),
821 rust_module_root_file(false),
822 lang_to_generate(0),
823 set_empty_strings_to_null(true),
824 set_empty_vectors_to_null(true) {}
825};
826
827
828struct ParserState {
829 ParserState()
830 : prev_cursor_(nullptr),
831 cursor_(nullptr),
832 line_start_(nullptr),
833 line_(0),
834 token_(-1),
835 attr_is_trivial_ascii_string_(true) {}
836
837 protected:
838 void ResetState(const char *source) {
839 prev_cursor_ = source;
840 cursor_ = source;
841 line_ = 0;
842 MarkNewLine();
843 }
844
845 void MarkNewLine() {
846 line_start_ = cursor_;
847 line_ += 1;
848 }
849
850 int64_t CursorPosition() const {
852 return static_cast<int64_t>(cursor_ - line_start_);
853 }
854
855 const char *prev_cursor_;
856 const char *cursor_;
857 const char *line_start_;
858 int line_;
859 int token_;
860
861
862
863
864 bool attr_is_trivial_ascii_string_;
865 std::string attribute_;
866 std::vector<std::string> doc_comment_;
867};
868
869
870
871
872
873
874
875
876class CheckedError {
877 public:
878 explicit CheckedError(bool error)
879 : is_error_(
error), has_been_checked_(false) {}
880
881 CheckedError &operator=(const CheckedError &other) {
882 is_error_ = other.is_error_;
883 has_been_checked_ = false;
884 other.has_been_checked_ = true;
885 return *this;
886 }
887
888 CheckedError(const CheckedError &other) {
889 *this = other;
890 }
891
893
894 bool Check() {
895 has_been_checked_ = true;
896 return is_error_;
897 }
898
899 private:
900 bool is_error_;
901 mutable bool has_been_checked_;
902};
903
904
905
906
907#ifdef __GNUC__
908#define FLATBUFFERS_CHECKED_ERROR CheckedError \
909 __attribute__((warn_unused_result))
910#else
911#define FLATBUFFERS_CHECKED_ERROR CheckedError
912#endif
913
914
915class Parser : public ParserState {
916 public:
917 explicit Parser(const IDLOptions &options = IDLOptions())
918 : current_namespace_(nullptr),
919 empty_namespace_(nullptr),
921 root_struct_def_(nullptr),
923 uses_flexbuffers_(false),
924 has_warning_(false),
925 advanced_features_(0),
926 source_(nullptr),
927 anonymous_counter_(0),
928 parse_depth_counter_(0) {
929 if (opts.force_defaults) { builder_.ForceDefaults(true); }
930
931 empty_namespace_ = new Namespace();
932 namespaces_.push_back(empty_namespace_);
933 current_namespace_ = empty_namespace_;
934 known_attributes_["deprecated"] = true;
935 known_attributes_["required"] = true;
936 known_attributes_["key"] = true;
937 known_attributes_["shared"] = true;
938 known_attributes_["hash"] = true;
939 known_attributes_["id"] = true;
940 known_attributes_["force_align"] = true;
941 known_attributes_["bit_flags"] = true;
942 known_attributes_["original_order"] = true;
943 known_attributes_["nested_flatbuffer"] = true;
944 known_attributes_["csharp_partial"] = true;
945 known_attributes_["streaming"] = true;
946 known_attributes_["idempotent"] = true;
947 known_attributes_["cpp_type"] = true;
948 known_attributes_["cpp_ptr_type"] = true;
949 known_attributes_["cpp_ptr_type_get"] = true;
950 known_attributes_["cpp_str_type"] = true;
951 known_attributes_["cpp_str_flex_ctor"] = true;
952 known_attributes_["native_inline"] = true;
953 known_attributes_["native_custom_alloc"] = true;
954 known_attributes_["native_type"] = true;
955 known_attributes_["native_type_pack_name"] = true;
956 known_attributes_["native_default"] = true;
957 known_attributes_["flexbuffer"] = true;
958 known_attributes_["private"] = true;
959
960
961 known_attributes_["offset64"] = true;
962
963
964
965 known_attributes_["vector64"] = true;
966 }
967
968
969 Parser(const Parser &) = delete;
970 Parser &operator=(const Parser &) = delete;
971
972 Parser(Parser &&) = default;
973 Parser &operator=(Parser &&) = default;
974
975 ~Parser() {
976 for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
977 delete *it;
978 }
979 }
980
981
982
983
984
985
986
987
988
989
990
991
992 bool Parse(const char *_source, const char **include_paths = nullptr,
993 const char *source_filename = nullptr);
994
995 bool ParseJson(const char *json, const char *json_filename = nullptr);
996
997
998 std::ptrdiff_t BytesConsumed() const;
999
1000
1001 bool SetRootType(const char *name);
1002
1003
1004 void MarkGenerated();
1005
1006
1007
1008 std::set<std::string> GetIncludedFilesRecursive(
1009 const std::string &file_name) const;
1010
1011
1012
1013 void Serialize();
1014
1015
1016 bool Deserialize(
const uint8_t *buf,
const size_t size);
1017
1018
1019
1020 bool Deserialize(const reflection::Schema *schema);
1021
1022 Type *DeserializeType(
const reflection::Type *
type);
1023
1024
1025
1026 std::string ConformTo(const Parser &base);
1027
1028
1029
1030 bool ParseFlexBuffer(const char *source, const char *source_filename,
1031 flexbuffers::Builder *builder);
1032
1033 StructDef *LookupStruct(const std::string &id) const;
1034 StructDef *LookupStructThruParentNamespaces(const std::string &id) const;
1035
1036 std::string UnqualifiedName(const std::string &fullQualifiedName);
1037
1039
1040
1041
1042
1044
1045
1046
1047
1048 std::vector<IncludedFile> GetIncludedFiles() const;
1049
1050 private:
1051 class ParseDepthGuard;
1052
1053 void Message(const std::string &msg);
1054 void Warning(const std::string &msg);
1058 bool Is(int t) const;
1059 bool IsIdent(const char *id) const;
1061 std::string TokenToStringId(int t) const;
1064 std::string *last);
1068 const std::string &name,
const Type &
type,
1069 FieldDef **dest);
1074 size_t parent_fieldn,
1075 const StructDef *parent_struct_def,
1076 size_t count,
1077 bool inside_vector = false);
1078 template<typename F>
1080 const StructDef *struct_def,
1081 F body);
1083 std::string *value, uoffset_t *ovalue);
1084 void SerializeStruct(const StructDef &struct_def, const Value &val);
1086 const Value &val);
1087 template<typename F>
1090 FieldDef *field, size_t fieldn);
1093 Value &val, FieldDef *field, size_t fieldn,
1094 const StructDef *parent_struct_def);
1097 bool check, Value &e, BaseType req,
1098 bool *destmatch);
1102 bool check_now);
1105 std::string *result);
1106 StructDef *LookupCreateStruct(const std::string &name,
1107 bool create_if_new = true,
1108 bool definition = false);
1110 const char *filename);
1113 StructDef **dest);
1115 EnumDef **dest);
1119 bool isextend, bool inside_oneof);
1128 flexbuffers::Builder *builder);
1131 const char *source_filename);
1133 const char **include_paths,
1134 const char *source_filename);
1137 const Definition &def, const Definition &value_type);
1139 const char **include_paths,
1140 const char *source_filename,
1141 const char *include_filename);
1144 StructDef *struct_def,
1145 const char *suffix, BaseType baseType);
1147 const std::string &align_constant, size_t min_align, size_t *align);
1148
1149 bool SupportsAdvancedUnionFeatures() const;
1150 bool SupportsAdvancedArrayFeatures() const;
1151 bool SupportsOptionalScalars() const;
1152 bool SupportsDefaultVectorsAndStrings() const;
1153 bool Supports64BitOffsets() const;
1154 bool SupportsUnionUnderlyingType() const;
1155 Namespace *UniqueNamespace(Namespace *ns);
1156
1158 template<typename F> CheckedError Recurse(F f);
1159
1160 const std::string &GetPooledString(const std::string &s) const;
1161
1162 public:
1163 SymbolTable<Type> types_;
1164 SymbolTable<StructDef> structs_;
1165 SymbolTable<EnumDef> enums_;
1166 SymbolTable<ServiceDef> services_;
1167 std::vector<Namespace *> namespaces_;
1168 Namespace *current_namespace_;
1169 Namespace *empty_namespace_;
1170 std::string error_;
1171
1173 flexbuffers::Builder flex_builder_;
1175 StructDef *root_struct_def_;
1176 std::string file_identifier_;
1177 std::string file_extension_;
1178
1179 std::map<uint64_t, std::string> included_files_;
1180 std::map<std::string, std::set<IncludedFile>> files_included_per_file_;
1181 std::vector<std::string> native_included_files_;
1182
1183 std::map<std::string, bool> known_attributes_;
1184
1185 IDLOptions opts;
1186 bool uses_flexbuffers_;
1187 bool has_warning_;
1188
1189 uint64_t advanced_features_;
1190
1191 std::string file_being_parsed_;
1192
1193 private:
1194 const char *source_;
1195
1196 std::vector<std::pair<Value, FieldDef *>> field_stack_;
1197
1198
1199
1200 mutable std::set<std::string> string_cache_;
1201
1202 int anonymous_counter_;
1203 int parse_depth_counter_;
1204};
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217extern const char *
GenTextFromTable(
const Parser &parser,
const void *table,
1218 const std::string &tablename,
1219 std::string *text);
1220extern const char *
GenText(
const Parser &parser,
const void *flatbuffer,
1221 std::string *text);
1222extern const char *
GenTextFile(
const Parser &parser,
const std::string &path,
1223 const std::string &file_name);
1224
1225
1226
1228 const std::string &file_name);
1229
1230
1231
1232bool GenerateGoGRPC(
const Parser &parser,
const std::string &path,
1233 const std::string &file_name);
1234
1235
1236
1238 const std::string &file_name);
1239
1240
1241
1243 const std::string &file_name);
1244
1245
1246
1248 const std::string &file_name);
1249
1250extern bool GenerateTSGRPC(
const Parser &parser,
const std::string &path,
1251 const std::string &file_name);
1252}
1253
1254#endif
void Add(const float *input1_data, const Dims< 4 > &input1_dims, const float *input2_data, const Dims< 4 > &input2_dims, float *output_data, const Dims< 4 > &output_dims)
#define FLATBUFFERS_ASSERT
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
__global uchar * offset(const Image *img, int x, int y)
#define FLATBUFFERS_CHECKED_ERROR
#define FLATBUFFERS_GEN_TYPES(TD)
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE)
bool operator==(const small_vector< T, LCapacity > &lhs, const small_vector< T, RCapacity > &rhs)
bool operator<(const ElemID &lhs, const ElemID &rhs)
bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool operator!=(const EnumVal &lhs, const EnumVal &rhs)
bool IsInteger(BaseType t)
bool IsScalar(BaseType t)
bool GenerateTSGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsUnion(const Type &type)
bool IsSeries(const Type &type)
bool IsStruct(const Type &type)
bool GenerateJavaGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsUnsigned(BaseType t)
bool IsIncompleteStruct(const Type &type)
const char * GenText(const Parser &parser, const void *flatbuffer, std::string *text)
std::string NumToString(T t)
bool GenerateCppGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsString(const Type &type)
bool IsOneByte(BaseType t)
const char * GenTextFromTable(const Parser &parser, const void *table, const std::string &tablename, std::string *text)
int LookupEnum(const char **names, const char *name)
bool GenerateGoGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
size_t InlineAlignment(const Type &type)
bool IsVectorOfTable(const Type &type)
bool IsUnionType(const Type &type)
const char * TypeName(const BaseType t)
bool IsArray(const Type &type)
bool IsTable(const Type &type)
const char * GenTextFile(const Parser &parser, const std::string &path, const std::string &file_name)
size_t InlineSize(const Type &type)
const char * StringOf(const BaseType t)
bool GeneratePythonGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
size_t SizeOf(const BaseType t)
bool IsVectorOfStruct(const Type &type)
bool IsEnum(const Type &type)
bool EqualByName(const Type &a, const Type &b)
bool IsVector(BaseType t)
loco::GraphInputIndex index(const TFPlaceholder *node)
bool optional(bool is_optional)
convert option overview for Option constructor