MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / ParseField

Method ParseField

native/thirdpart/flatbuffers/idl_parser.cpp:739–1037  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737}
738
739CheckedError Parser::ParseField(StructDef &struct_def) {
740 std::string name = attribute_;
741
742 if (LookupCreateStruct(name, false, false))
743 return Error("field name can not be the same as table/struct name");
744
745 if (!IsLowerSnakeCase(name)) {
746 Warning("field names should be lowercase snake_case, got: " + name);
747 }
748
749 std::vector<std::string> dc = doc_comment_;
750 EXPECT(kTokenIdentifier);
751 EXPECT(':');
752 Type type;
753 ECHECK(ParseType(type));
754
755 if (struct_def.fixed) {
756 auto valid = IsScalar(type.base_type) || IsStruct(type);
757 if (!valid && IsArray(type)) {
758 const auto &elem_type = type.VectorType();
759 valid |= IsScalar(elem_type.base_type) || IsStruct(elem_type);
760 }
761 if (!valid)
762 return Error("structs may contain only scalar or struct fields");
763 }
764
765 if (!struct_def.fixed && IsArray(type))
766 return Error("fixed-length array in table must be wrapped in struct");
767
768 if (IsArray(type)) {
769 advanced_features_ |= reflection::AdvancedArrayFeatures;
770 if (!SupportsAdvancedArrayFeatures()) {
771 return Error(
772 "Arrays are not yet supported in all "
773 "the specified programming languages.");
774 }
775 }
776
777 FieldDef *typefield = nullptr;
778 if (type.base_type == BASE_TYPE_UNION) {
779 // For union fields, add a second auto-generated field to hold the type,
780 // with a special suffix.
781 ECHECK(AddField(struct_def, name + UnionTypeFieldSuffix(),
782 type.enum_def->underlying_type, &typefield));
783 } else if (IsVector(type) && type.element == BASE_TYPE_UNION) {
784 advanced_features_ |= reflection::AdvancedUnionFeatures;
785 // Only cpp, js and ts supports the union vector feature so far.
786 if (!SupportsAdvancedUnionFeatures()) {
787 return Error(
788 "Vectors of unions are not yet supported in at least one of "
789 "the specified programming languages.");
790 }
791 // For vector of union fields, add a second auto-generated vector field to
792 // hold the types, with a special suffix.
793 Type union_vector(BASE_TYPE_VECTOR, nullptr, type.enum_def);
794 union_vector.element = BASE_TYPE_UTYPE;
795 ECHECK(AddField(struct_def, name + UnionTypeFieldSuffix(), union_vector,
796 &typefield));

Callers

nothing calls this directly

Calls 15

ErrorFunction · 0.85
IsLowerSnakeCaseFunction · 0.85
IsStructFunction · 0.85
IsArrayFunction · 0.85
UnionTypeFieldSuffixFunction · 0.85
IsVectorFunction · 0.85
IsStringFunction · 0.85
IsIdentifierStartFunction · 0.85
FindHashFunction16Function · 0.85
FindHashFunction32Function · 0.85
FindHashFunction64Function · 0.85
atotFunction · 0.85

Tested by

no test coverage detected