MCPcopy Create free account
hub / github.com/apache/fory / collect_includes

Method collect_includes

compiler/fory_compiler/generators/cpp.py:1884–1984  ·  view source on GitHub ↗

Collect required includes for a field type.

(
        self,
        field_type: FieldType,
        nullable: bool,
        ref: bool,
        includes: Set[str],
        element_optional: bool = False,
        element_ref: bool = False,
        weak_ref: bool = False,
        element_weak_ref: bool = False,
    )

Source from the content-addressed store, hash-verified

1882 return type_name
1883
1884 def collect_includes(
1885 self,
1886 field_type: FieldType,
1887 nullable: bool,
1888 ref: bool,
1889 includes: Set[str],
1890 element_optional: bool = False,
1891 element_ref: bool = False,
1892 weak_ref: bool = False,
1893 element_weak_ref: bool = False,
1894 ):
1895 """Collect required includes for a field type."""
1896 if nullable:
1897 includes.add("<optional>")
1898 if ref:
1899 includes.add("<memory>")
1900 if weak_ref:
1901 includes.add('"fory/serialization/weak_ptr_serializer.h"')
1902
1903 if isinstance(field_type, PrimitiveType):
1904 if field_type.kind == PrimitiveKind.STRING:
1905 includes.add("<string>")
1906 elif field_type.kind == PrimitiveKind.BYTES:
1907 includes.add("<vector>")
1908 elif field_type.kind == PrimitiveKind.DECIMAL:
1909 includes.add('"fory/serialization/decimal_serializers.h"')
1910 elif field_type.kind in (
1911 PrimitiveKind.DATE,
1912 PrimitiveKind.TIMESTAMP,
1913 PrimitiveKind.DURATION,
1914 ):
1915 includes.add('"fory/serialization/temporal_serializers.h"')
1916 elif field_type.kind == PrimitiveKind.ANY:
1917 includes.add("<any>")
1918 elif field_type.kind == PrimitiveKind.FLOAT16:
1919 includes.add('"fory/util/float16.h"')
1920 elif field_type.kind == PrimitiveKind.BFLOAT16:
1921 includes.add('"fory/util/bfloat16.h"')
1922
1923 elif isinstance(field_type, ListType):
1924 includes.add("<vector>")
1925 effective_element_optional = element_optional or field_type.element_optional
1926 effective_element_ref = element_ref or field_type.element_ref
1927 effective_element_weak_ref = element_weak_ref
1928 if field_type.element_ref:
1929 effective_element_weak_ref = self.is_weak_ref(
1930 field_type.element_ref_options
1931 )
1932 self.collect_includes(
1933 field_type.element_type,
1934 effective_element_optional,
1935 effective_element_ref,
1936 includes,
1937 False,
1938 False,
1939 effective_element_weak_ref,
1940 False,
1941 )

Callers 2

Calls 5

is_weak_refMethod · 0.95
is_imported_typeMethod · 0.95
_header_for_typeMethod · 0.95
addMethod · 0.65
get_typeMethod · 0.45

Tested by

no test coverage detected