nvfuser-cu121-torch25 0.2.25.dev20250201__cp310-cp310-manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- nvfuser/_C.cpython-310-x86_64-linux-gnu.so +0 -0
- nvfuser/__init__.py +618 -0
- nvfuser/__init__.pyi +4 -0
- nvfuser/contrib/__init__.py +9 -0
- nvfuser/contrib/nn/__init__.py +13 -0
- nvfuser/contrib/nn/normalization.py +725 -0
- nvfuser/include/nvfuser/alias_analysis.h +116 -0
- nvfuser/include/nvfuser/bfs.h +929 -0
- nvfuser/include/nvfuser/codegen.h +26 -0
- nvfuser/include/nvfuser/compute_at.h +28 -0
- nvfuser/include/nvfuser/compute_at_map.h +394 -0
- nvfuser/include/nvfuser/contiguity.h +351 -0
- nvfuser/include/nvfuser/cuda_utils.h +50 -0
- nvfuser/include/nvfuser/debug.h +50 -0
- nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
- nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
- nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
- nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
- nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
- nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
- nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
- nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
- nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
- nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
- nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
- nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
- nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
- nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
- nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
- nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
- nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
- nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
- nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
- nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
- nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
- nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
- nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
- nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
- nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
- nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
- nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
- nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
- nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
- nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
- nvfuser/include/nvfuser/device_lower/utils.h +382 -0
- nvfuser/include/nvfuser/device_lower/validation.h +74 -0
- nvfuser/include/nvfuser/disjoint_set.h +556 -0
- nvfuser/include/nvfuser/dispatch.h +334 -0
- nvfuser/include/nvfuser/driver_api.h +49 -0
- nvfuser/include/nvfuser/dynamic_transform.h +316 -0
- nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
- nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
- nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
- nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
- nvfuser/include/nvfuser/evaluator_common.h +295 -0
- nvfuser/include/nvfuser/exceptions.h +283 -0
- nvfuser/include/nvfuser/expr_evaluator.h +125 -0
- nvfuser/include/nvfuser/expr_simplifier.h +218 -0
- nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
- nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
- nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
- nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
- nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
- nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
- nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
- nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
- nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
- nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
- nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
- nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
- nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
- nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
- nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
- nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
- nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
- nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
- nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
- nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
- nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
- nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
- nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
- nvfuser/include/nvfuser/fusion.h +511 -0
- nvfuser/include/nvfuser/fusion_guard.h +37 -0
- nvfuser/include/nvfuser/fusion_profiler.h +311 -0
- nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
- nvfuser/include/nvfuser/global_allocator.h +27 -0
- nvfuser/include/nvfuser/grouped_reduction.h +47 -0
- nvfuser/include/nvfuser/host_ir/container.h +60 -0
- nvfuser/include/nvfuser/host_ir/executor.h +152 -0
- nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
- nvfuser/include/nvfuser/host_ir/lower.h +35 -0
- nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
- nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
- nvfuser/include/nvfuser/id_model/id_model.h +359 -0
- nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
- nvfuser/include/nvfuser/id_model/indexing.h +208 -0
- nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
- nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
- nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
- nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
- nvfuser/include/nvfuser/id_model/schedule.h +54 -0
- nvfuser/include/nvfuser/id_model/to_string.h +87 -0
- nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
- nvfuser/include/nvfuser/id_model/utils.h +176 -0
- nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
- nvfuser/include/nvfuser/index_compute.h +651 -0
- nvfuser/include/nvfuser/instrumentation.h +107 -0
- nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
- nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
- nvfuser/include/nvfuser/ir/builder.h +215 -0
- nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
- nvfuser/include/nvfuser/ir/cloner.h +185 -0
- nvfuser/include/nvfuser/ir/container.h +226 -0
- nvfuser/include/nvfuser/ir/graphviz.h +119 -0
- nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
- nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
- nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
- nvfuser/include/nvfuser/ir/iostream.h +98 -0
- nvfuser/include/nvfuser/ir/printer.h +57 -0
- nvfuser/include/nvfuser/ir/utils.h +801 -0
- nvfuser/include/nvfuser/iter_visitor.h +661 -0
- nvfuser/include/nvfuser/kernel.h +299 -0
- nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
- nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
- nvfuser/include/nvfuser/kernel_ir.h +1457 -0
- nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
- nvfuser/include/nvfuser/linked_hash_map.h +97 -0
- nvfuser/include/nvfuser/logical_domain_map.h +577 -0
- nvfuser/include/nvfuser/macros.h +23 -0
- nvfuser/include/nvfuser/mma_type.h +257 -0
- nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
- nvfuser/include/nvfuser/multidevice/communication.h +232 -0
- nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
- nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
- nvfuser/include/nvfuser/multidevice/executor.h +107 -0
- nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
- nvfuser/include/nvfuser/multidevice/utils.h +187 -0
- nvfuser/include/nvfuser/non_divisible_split.h +86 -0
- nvfuser/include/nvfuser/opaque_type.h +129 -0
- nvfuser/include/nvfuser/ops/alias.h +192 -0
- nvfuser/include/nvfuser/ops/all_ops.h +13 -0
- nvfuser/include/nvfuser/ops/arith.h +712 -0
- nvfuser/include/nvfuser/ops/composite.h +130 -0
- nvfuser/include/nvfuser/ops/indexing.h +55 -0
- nvfuser/include/nvfuser/ops/normalization.h +263 -0
- nvfuser/include/nvfuser/ops/utils.h +127 -0
- nvfuser/include/nvfuser/options.h +313 -0
- nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
- nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
- nvfuser/include/nvfuser/polymorphic_value.h +432 -0
- nvfuser/include/nvfuser/predicate_compute.h +213 -0
- nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
- nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
- nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
- nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
- nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
- nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
- nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
- nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
- nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
- nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
- nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
- nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
- nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
- nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
- nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
- nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
- nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
- nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
- nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
- nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
- nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
- nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
- nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
- nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
- nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
- nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
- nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
- nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
- nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
- nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
- nvfuser/include/nvfuser/scheduler/registry.h +97 -0
- nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
- nvfuser/include/nvfuser/scheduler/resize.h +41 -0
- nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
- nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
- nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
- nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
- nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
- nvfuser/include/nvfuser/scheduler/utils.h +771 -0
- nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
- nvfuser/include/nvfuser/serde/factory.h +55 -0
- nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
- nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
- nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
- nvfuser/include/nvfuser/serde/utils.h +34 -0
- nvfuser/include/nvfuser/struct.inl +127 -0
- nvfuser/include/nvfuser/swizzle.h +54 -0
- nvfuser/include/nvfuser/sys_utils.h +40 -0
- nvfuser/include/nvfuser/tensor_metadata.h +118 -0
- nvfuser/include/nvfuser/tma.h +124 -0
- nvfuser/include/nvfuser/transform_iter.h +522 -0
- nvfuser/include/nvfuser/transform_replay.h +297 -0
- nvfuser/include/nvfuser/transform_rfactor.h +33 -0
- nvfuser/include/nvfuser/transform_view.h +136 -0
- nvfuser/include/nvfuser/type.h +1125 -0
- nvfuser/include/nvfuser/type_promotion.h +61 -0
- nvfuser/include/nvfuser/utils.h +619 -0
- nvfuser/include/nvfuser/val_graph.h +446 -0
- nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
- nvfuser/include/nvfuser/validator_utils.h +92 -0
- nvfuser/include/nvfuser/vectorization_info.h +31 -0
- nvfuser/include/nvfuser/visibility.h +21 -0
- nvfuser/lib/libnvfuser_codegen.so +0 -0
- nvfuser/nvfuser_version.py +69 -0
- nvfuser/pytorch_utils.py +184 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
- nvfuser/utils.py +18 -0
- nvfuser/version.py +1 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +20 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
- nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,1359 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2014 Google Inc. All rights reserved.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef FLATBUFFERS_IDL_H_
|
18
|
+
#define FLATBUFFERS_IDL_H_
|
19
|
+
|
20
|
+
#include <algorithm>
|
21
|
+
#include <functional>
|
22
|
+
#include <map>
|
23
|
+
#include <memory>
|
24
|
+
#include <stack>
|
25
|
+
|
26
|
+
#include "flatbuffers/base.h"
|
27
|
+
#include "flatbuffers/flatbuffers.h"
|
28
|
+
#include "flatbuffers/flexbuffers.h"
|
29
|
+
#include "flatbuffers/hash.h"
|
30
|
+
#include "flatbuffers/reflection.h"
|
31
|
+
|
32
|
+
// This file defines the data types representing a parsed IDL (Interface
|
33
|
+
// Definition Language) / schema file.
|
34
|
+
|
35
|
+
// Limits maximum depth of nested objects.
|
36
|
+
// Prevents stack overflow while parse scheme, or json, or flexbuffer.
|
37
|
+
#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
|
38
|
+
# define FLATBUFFERS_MAX_PARSING_DEPTH 64
|
39
|
+
#endif
|
40
|
+
|
41
|
+
namespace flatbuffers {
|
42
|
+
|
43
|
+
// The order of these matters for Is*() functions below.
|
44
|
+
// Additionally, Parser::ParseType assumes bool..string is a contiguous range
|
45
|
+
// of type tokens.
|
46
|
+
// clang-format off
|
47
|
+
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
|
48
|
+
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 0) \
|
49
|
+
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 1) /* begin scalar/int */ \
|
50
|
+
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool, 2) \
|
51
|
+
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8, 3) \
|
52
|
+
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 4) \
|
53
|
+
TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16, 5) \
|
54
|
+
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16, 6) \
|
55
|
+
TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32, 7) \
|
56
|
+
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32, 8) \
|
57
|
+
TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64, 9) \
|
58
|
+
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64, 10) /* end int */ \
|
59
|
+
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32, 11) /* begin float */ \
|
60
|
+
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double, 12) /* end float/scalar */
|
61
|
+
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
|
62
|
+
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>, 13) \
|
63
|
+
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 14) \
|
64
|
+
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 15) \
|
65
|
+
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 16)
|
66
|
+
#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
|
67
|
+
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>, 17)
|
68
|
+
// The fields are:
|
69
|
+
// - enum
|
70
|
+
// - FlatBuffers schema type.
|
71
|
+
// - C++ type.
|
72
|
+
// - Java type.
|
73
|
+
// - Go type.
|
74
|
+
// - C# / .Net type.
|
75
|
+
// - Python type.
|
76
|
+
// - Kotlin type.
|
77
|
+
// - Rust type.
|
78
|
+
// - Swift type.
|
79
|
+
// - enum value (matches the reflected values)
|
80
|
+
|
81
|
+
// using these macros, we can now write code dealing with types just once, e.g.
|
82
|
+
|
83
|
+
/*
|
84
|
+
switch (type) {
|
85
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \
|
86
|
+
RTYPE, KTYPE, STYPE, ...) \
|
87
|
+
case BASE_TYPE_ ## ENUM: \
|
88
|
+
// do something specific to CTYPE here
|
89
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
90
|
+
#undef FLATBUFFERS_TD
|
91
|
+
}
|
92
|
+
*/
|
93
|
+
|
94
|
+
// If not all FLATBUFFERS_GEN_() arguments are necessary for implementation
|
95
|
+
// of FLATBUFFERS_TD, you can use a variadic macro (with __VA_ARGS__ if needed).
|
96
|
+
// In the above example, only CTYPE is used to generate the code, it can be rewritten:
|
97
|
+
|
98
|
+
/*
|
99
|
+
switch (type) {
|
100
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
101
|
+
case BASE_TYPE_ ## ENUM: \
|
102
|
+
// do something specific to CTYPE here
|
103
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
104
|
+
#undef FLATBUFFERS_TD
|
105
|
+
}
|
106
|
+
*/
|
107
|
+
|
108
|
+
#define FLATBUFFERS_GEN_TYPES(TD) \
|
109
|
+
FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
|
110
|
+
FLATBUFFERS_GEN_TYPES_POINTER(TD) \
|
111
|
+
FLATBUFFERS_GEN_TYPE_ARRAY(TD)
|
112
|
+
|
113
|
+
// Create an enum for all the types above.
|
114
|
+
#ifdef __GNUC__
|
115
|
+
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
|
116
|
+
#endif
|
117
|
+
enum BaseType {
|
118
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, \
|
119
|
+
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE) \
|
120
|
+
BASE_TYPE_ ## ENUM = ENUM_VALUE,
|
121
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
122
|
+
#undef FLATBUFFERS_TD
|
123
|
+
};
|
124
|
+
|
125
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
126
|
+
static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
|
127
|
+
"define largest_scalar_t as " #CTYPE);
|
128
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
129
|
+
#undef FLATBUFFERS_TD
|
130
|
+
|
131
|
+
inline bool IsScalar (BaseType t) { return t >= BASE_TYPE_UTYPE &&
|
132
|
+
t <= BASE_TYPE_DOUBLE; }
|
133
|
+
inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE &&
|
134
|
+
t <= BASE_TYPE_ULONG; }
|
135
|
+
inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT ||
|
136
|
+
t == BASE_TYPE_DOUBLE; }
|
137
|
+
inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG ||
|
138
|
+
t == BASE_TYPE_ULONG; }
|
139
|
+
inline bool IsBool (BaseType t) { return t == BASE_TYPE_BOOL; }
|
140
|
+
inline bool IsOneByte(BaseType t) { return t >= BASE_TYPE_UTYPE &&
|
141
|
+
t <= BASE_TYPE_UCHAR; }
|
142
|
+
|
143
|
+
inline bool IsUnsigned(BaseType t) {
|
144
|
+
return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) ||
|
145
|
+
(t == BASE_TYPE_USHORT) || (t == BASE_TYPE_UINT) ||
|
146
|
+
(t == BASE_TYPE_ULONG);
|
147
|
+
}
|
148
|
+
|
149
|
+
inline size_t SizeOf(const BaseType t) {
|
150
|
+
switch (t) {
|
151
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
152
|
+
case BASE_TYPE_##ENUM: return sizeof(CTYPE);
|
153
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
154
|
+
#undef FLATBUFFERS_TD
|
155
|
+
default: FLATBUFFERS_ASSERT(0);
|
156
|
+
}
|
157
|
+
return 0;
|
158
|
+
}
|
159
|
+
|
160
|
+
inline const char* TypeName(const BaseType t) {
|
161
|
+
switch (t) {
|
162
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ...) \
|
163
|
+
case BASE_TYPE_##ENUM: return IDLTYPE;
|
164
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
165
|
+
#undef FLATBUFFERS_TD
|
166
|
+
default: FLATBUFFERS_ASSERT(0);
|
167
|
+
}
|
168
|
+
return nullptr;
|
169
|
+
}
|
170
|
+
|
171
|
+
inline const char* StringOf(const BaseType t) {
|
172
|
+
switch (t) {
|
173
|
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
174
|
+
case BASE_TYPE_##ENUM: return #CTYPE;
|
175
|
+
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
176
|
+
#undef FLATBUFFERS_TD
|
177
|
+
default: FLATBUFFERS_ASSERT(0);
|
178
|
+
}
|
179
|
+
return "";
|
180
|
+
}
|
181
|
+
|
182
|
+
// clang-format on
|
183
|
+
|
184
|
+
struct StructDef;
|
185
|
+
struct EnumDef;
|
186
|
+
class Parser;
|
187
|
+
|
188
|
+
// Represents any type in the IDL, which is a combination of the BaseType
|
189
|
+
// and additional information for vectors/structs_.
|
190
|
+
struct Type {
|
191
|
+
explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr,
|
192
|
+
EnumDef *_ed = nullptr, uint16_t _fixed_length = 0)
|
193
|
+
: base_type(_base_type),
|
194
|
+
element(BASE_TYPE_NONE),
|
195
|
+
struct_def(_sd),
|
196
|
+
enum_def(_ed),
|
197
|
+
fixed_length(_fixed_length) {}
|
198
|
+
|
199
|
+
bool operator==(const Type &o) const {
|
200
|
+
return base_type == o.base_type && element == o.element &&
|
201
|
+
struct_def == o.struct_def && enum_def == o.enum_def;
|
202
|
+
}
|
203
|
+
|
204
|
+
Type VectorType() const {
|
205
|
+
return Type(element, struct_def, enum_def, fixed_length);
|
206
|
+
}
|
207
|
+
|
208
|
+
Offset<reflection::Type> Serialize(FlatBufferBuilder *builder) const;
|
209
|
+
|
210
|
+
bool Deserialize(const Parser &parser, const reflection::Type *type);
|
211
|
+
|
212
|
+
BaseType base_type;
|
213
|
+
BaseType element; // only set if t == BASE_TYPE_VECTOR
|
214
|
+
StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
|
215
|
+
EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
|
216
|
+
// or for an integral type derived from an enum.
|
217
|
+
uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
|
218
|
+
};
|
219
|
+
|
220
|
+
// Represents a parsed scalar value, it's type, and field offset.
|
221
|
+
struct Value {
|
222
|
+
Value()
|
223
|
+
: constant("0"),
|
224
|
+
offset(static_cast<voffset_t>(~(static_cast<voffset_t>(0U)))) {}
|
225
|
+
Type type;
|
226
|
+
std::string constant;
|
227
|
+
voffset_t offset;
|
228
|
+
};
|
229
|
+
|
230
|
+
// Helper class that retains the original order of a set of identifiers and
|
231
|
+
// also provides quick lookup.
|
232
|
+
template<typename T> class SymbolTable {
|
233
|
+
public:
|
234
|
+
~SymbolTable() {
|
235
|
+
for (auto it = vec.begin(); it != vec.end(); ++it) { delete *it; }
|
236
|
+
}
|
237
|
+
|
238
|
+
bool Add(const std::string &name, T *e) {
|
239
|
+
vec.emplace_back(e);
|
240
|
+
auto it = dict.find(name);
|
241
|
+
if (it != dict.end()) return true;
|
242
|
+
dict[name] = e;
|
243
|
+
return false;
|
244
|
+
}
|
245
|
+
|
246
|
+
void Move(const std::string &oldname, const std::string &newname) {
|
247
|
+
auto it = dict.find(oldname);
|
248
|
+
if (it != dict.end()) {
|
249
|
+
auto obj = it->second;
|
250
|
+
dict.erase(it);
|
251
|
+
dict[newname] = obj;
|
252
|
+
} else {
|
253
|
+
FLATBUFFERS_ASSERT(false);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
T *Lookup(const std::string &name) const {
|
258
|
+
auto it = dict.find(name);
|
259
|
+
return it == dict.end() ? nullptr : it->second;
|
260
|
+
}
|
261
|
+
|
262
|
+
public:
|
263
|
+
std::map<std::string, T *> dict; // quick lookup
|
264
|
+
std::vector<T *> vec; // Used to iterate in order of insertion
|
265
|
+
};
|
266
|
+
|
267
|
+
// A name space, as set in the schema.
|
268
|
+
struct Namespace {
|
269
|
+
Namespace() : from_table(0) {}
|
270
|
+
|
271
|
+
// Given a (potentially unqualified) name, return the "fully qualified" name
|
272
|
+
// which has a full namespaced descriptor.
|
273
|
+
// With max_components you can request less than the number of components
|
274
|
+
// the current namespace has.
|
275
|
+
std::string GetFullyQualifiedName(const std::string &name,
|
276
|
+
size_t max_components = 1000) const;
|
277
|
+
|
278
|
+
std::vector<std::string> components;
|
279
|
+
size_t from_table; // Part of the namespace corresponds to a message/table.
|
280
|
+
};
|
281
|
+
|
282
|
+
inline bool operator<(const Namespace &a, const Namespace &b) {
|
283
|
+
size_t min_size = std::min(a.components.size(), b.components.size());
|
284
|
+
for (size_t i = 0; i < min_size; ++i) {
|
285
|
+
if (a.components[i] != b.components[i])
|
286
|
+
return a.components[i] < b.components[i];
|
287
|
+
}
|
288
|
+
return a.components.size() < b.components.size();
|
289
|
+
}
|
290
|
+
|
291
|
+
// Base class for all definition types (fields, structs_, enums_).
|
292
|
+
struct Definition {
|
293
|
+
Definition()
|
294
|
+
: generated(false),
|
295
|
+
defined_namespace(nullptr),
|
296
|
+
serialized_location(0),
|
297
|
+
index(-1),
|
298
|
+
refcount(1),
|
299
|
+
declaration_file(nullptr) {}
|
300
|
+
|
301
|
+
flatbuffers::Offset<
|
302
|
+
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
303
|
+
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
|
304
|
+
|
305
|
+
bool DeserializeAttributes(Parser &parser,
|
306
|
+
const Vector<Offset<reflection::KeyValue>> *attrs);
|
307
|
+
|
308
|
+
std::string name;
|
309
|
+
std::string file;
|
310
|
+
std::vector<std::string> doc_comment;
|
311
|
+
SymbolTable<Value> attributes;
|
312
|
+
bool generated; // did we already output code for this definition?
|
313
|
+
Namespace *defined_namespace; // Where it was defined.
|
314
|
+
|
315
|
+
// For use with Serialize()
|
316
|
+
uoffset_t serialized_location;
|
317
|
+
int index; // Inside the vector it is stored.
|
318
|
+
int refcount;
|
319
|
+
const std::string *declaration_file;
|
320
|
+
};
|
321
|
+
|
322
|
+
struct FieldDef : public Definition {
|
323
|
+
FieldDef()
|
324
|
+
: deprecated(false),
|
325
|
+
key(false),
|
326
|
+
shared(false),
|
327
|
+
native_inline(false),
|
328
|
+
flexbuffer(false),
|
329
|
+
presence(kDefault),
|
330
|
+
nested_flatbuffer(nullptr),
|
331
|
+
padding(0),
|
332
|
+
sibling_union_field(nullptr) {}
|
333
|
+
|
334
|
+
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
335
|
+
const Parser &parser) const;
|
336
|
+
|
337
|
+
bool Deserialize(Parser &parser, const reflection::Field *field);
|
338
|
+
|
339
|
+
bool IsScalarOptional() const {
|
340
|
+
return IsScalar(value.type.base_type) && IsOptional();
|
341
|
+
}
|
342
|
+
bool IsOptional() const { return presence == kOptional; }
|
343
|
+
bool IsRequired() const { return presence == kRequired; }
|
344
|
+
bool IsDefault() const { return presence == kDefault; }
|
345
|
+
|
346
|
+
Value value;
|
347
|
+
bool deprecated; // Field is allowed to be present in old data, but can't be.
|
348
|
+
// written in new data nor accessed in new code.
|
349
|
+
bool key; // Field functions as a key for creating sorted vectors.
|
350
|
+
bool shared; // Field will be using string pooling (i.e. CreateSharedString)
|
351
|
+
// as default serialization behavior if field is a string.
|
352
|
+
bool native_inline; // Field will be defined inline (instead of as a pointer)
|
353
|
+
// for native tables if field is a struct.
|
354
|
+
bool flexbuffer; // This field contains FlexBuffer data.
|
355
|
+
|
356
|
+
enum Presence {
|
357
|
+
// Field must always be present.
|
358
|
+
kRequired,
|
359
|
+
// Non-presence should be signalled to and controlled by users.
|
360
|
+
kOptional,
|
361
|
+
// Non-presence is hidden from users.
|
362
|
+
// Implementations may omit writing default values.
|
363
|
+
kDefault,
|
364
|
+
};
|
365
|
+
Presence static MakeFieldPresence(bool optional, bool required) {
|
366
|
+
FLATBUFFERS_ASSERT(!(required && optional));
|
367
|
+
// clang-format off
|
368
|
+
return required ? FieldDef::kRequired
|
369
|
+
: optional ? FieldDef::kOptional
|
370
|
+
: FieldDef::kDefault;
|
371
|
+
// clang-format on
|
372
|
+
}
|
373
|
+
Presence presence;
|
374
|
+
|
375
|
+
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
376
|
+
size_t padding; // Bytes to always pad after this field.
|
377
|
+
|
378
|
+
// sibling_union_field is always set to nullptr. The only exception is
|
379
|
+
// when FieldDef is a union field or an union type field. Therefore,
|
380
|
+
// sibling_union_field on a union field points to the union type field
|
381
|
+
// and vice-versa.
|
382
|
+
FieldDef *sibling_union_field;
|
383
|
+
};
|
384
|
+
|
385
|
+
struct StructDef : public Definition {
|
386
|
+
StructDef()
|
387
|
+
: fixed(false),
|
388
|
+
predecl(true),
|
389
|
+
sortbysize(true),
|
390
|
+
has_key(false),
|
391
|
+
minalign(1),
|
392
|
+
bytesize(0) {}
|
393
|
+
|
394
|
+
void PadLastField(size_t min_align) {
|
395
|
+
auto padding = PaddingBytes(bytesize, min_align);
|
396
|
+
bytesize += padding;
|
397
|
+
if (fields.vec.size()) fields.vec.back()->padding = padding;
|
398
|
+
}
|
399
|
+
|
400
|
+
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
|
401
|
+
const Parser &parser) const;
|
402
|
+
|
403
|
+
bool Deserialize(Parser &parser, const reflection::Object *object);
|
404
|
+
|
405
|
+
SymbolTable<FieldDef> fields;
|
406
|
+
|
407
|
+
bool fixed; // If it's struct, not a table.
|
408
|
+
bool predecl; // If it's used before it was defined.
|
409
|
+
bool sortbysize; // Whether fields come in the declaration or size order.
|
410
|
+
bool has_key; // It has a key field.
|
411
|
+
size_t minalign; // What the whole object needs to be aligned to.
|
412
|
+
size_t bytesize; // Size if fixed.
|
413
|
+
|
414
|
+
flatbuffers::unique_ptr<std::string> original_location;
|
415
|
+
std::vector<voffset_t> reserved_ids;
|
416
|
+
};
|
417
|
+
|
418
|
+
struct EnumDef;
|
419
|
+
struct EnumValBuilder;
|
420
|
+
|
421
|
+
struct EnumVal {
|
422
|
+
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder,
|
423
|
+
const Parser &parser) const;
|
424
|
+
|
425
|
+
bool Deserialize(Parser &parser, const reflection::EnumVal *val);
|
426
|
+
|
427
|
+
flatbuffers::Offset<
|
428
|
+
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
429
|
+
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
|
430
|
+
|
431
|
+
bool DeserializeAttributes(Parser &parser,
|
432
|
+
const Vector<Offset<reflection::KeyValue>> *attrs);
|
433
|
+
|
434
|
+
uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
|
435
|
+
int64_t GetAsInt64() const { return value; }
|
436
|
+
bool IsZero() const { return 0 == value; }
|
437
|
+
bool IsNonZero() const { return !IsZero(); }
|
438
|
+
|
439
|
+
std::string name;
|
440
|
+
std::vector<std::string> doc_comment;
|
441
|
+
Type union_type;
|
442
|
+
SymbolTable<Value> attributes;
|
443
|
+
|
444
|
+
private:
|
445
|
+
friend EnumDef;
|
446
|
+
friend EnumValBuilder;
|
447
|
+
friend bool operator==(const EnumVal &lhs, const EnumVal &rhs);
|
448
|
+
|
449
|
+
EnumVal(const std::string &_name, int64_t _val) : name(_name), value(_val) {}
|
450
|
+
EnumVal() : value(0) {}
|
451
|
+
|
452
|
+
int64_t value;
|
453
|
+
};
|
454
|
+
|
455
|
+
struct EnumDef : public Definition {
|
456
|
+
EnumDef() : is_union(false), uses_multiple_type_instances(false) {}
|
457
|
+
|
458
|
+
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder,
|
459
|
+
const Parser &parser) const;
|
460
|
+
|
461
|
+
bool Deserialize(Parser &parser, const reflection::Enum *values);
|
462
|
+
|
463
|
+
template<typename T> void ChangeEnumValue(EnumVal *ev, T new_val);
|
464
|
+
void SortByValue();
|
465
|
+
void RemoveDuplicates();
|
466
|
+
|
467
|
+
std::string AllFlags() const;
|
468
|
+
const EnumVal *MinValue() const;
|
469
|
+
const EnumVal *MaxValue() const;
|
470
|
+
// Returns the number of integer steps from v1 to v2.
|
471
|
+
uint64_t Distance(const EnumVal *v1, const EnumVal *v2) const;
|
472
|
+
// Returns the number of integer steps from Min to Max.
|
473
|
+
uint64_t Distance() const { return Distance(MinValue(), MaxValue()); }
|
474
|
+
|
475
|
+
EnumVal *ReverseLookup(int64_t enum_idx,
|
476
|
+
bool skip_union_default = false) const;
|
477
|
+
EnumVal *FindByValue(const std::string &constant) const;
|
478
|
+
|
479
|
+
std::string ToString(const EnumVal &ev) const {
|
480
|
+
return IsUInt64() ? NumToString(ev.GetAsUInt64())
|
481
|
+
: NumToString(ev.GetAsInt64());
|
482
|
+
}
|
483
|
+
|
484
|
+
size_t size() const { return vals.vec.size(); }
|
485
|
+
|
486
|
+
const std::vector<EnumVal *> &Vals() const { return vals.vec; }
|
487
|
+
|
488
|
+
const EnumVal *Lookup(const std::string &enum_name) const {
|
489
|
+
return vals.Lookup(enum_name);
|
490
|
+
}
|
491
|
+
|
492
|
+
bool is_union;
|
493
|
+
// Type is a union which uses type aliases where at least one type is
|
494
|
+
// available under two different names.
|
495
|
+
bool uses_multiple_type_instances;
|
496
|
+
Type underlying_type;
|
497
|
+
|
498
|
+
private:
|
499
|
+
bool IsUInt64() const {
|
500
|
+
return (BASE_TYPE_ULONG == underlying_type.base_type);
|
501
|
+
}
|
502
|
+
|
503
|
+
friend EnumValBuilder;
|
504
|
+
SymbolTable<EnumVal> vals;
|
505
|
+
};
|
506
|
+
|
507
|
+
inline bool IsString(const Type &type) {
|
508
|
+
return type.base_type == BASE_TYPE_STRING;
|
509
|
+
}
|
510
|
+
|
511
|
+
inline bool IsStruct(const Type &type) {
|
512
|
+
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
513
|
+
}
|
514
|
+
|
515
|
+
inline bool IsIncompleteStruct(const Type &type) {
|
516
|
+
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->predecl;
|
517
|
+
}
|
518
|
+
|
519
|
+
inline bool IsTable(const Type &type) {
|
520
|
+
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
521
|
+
}
|
522
|
+
|
523
|
+
inline bool IsUnion(const Type &type) {
|
524
|
+
return type.enum_def != nullptr && type.enum_def->is_union;
|
525
|
+
}
|
526
|
+
|
527
|
+
inline bool IsUnionType(const Type &type) {
|
528
|
+
return IsUnion(type) && IsInteger(type.base_type);
|
529
|
+
}
|
530
|
+
|
531
|
+
inline bool IsVector(const Type &type) {
|
532
|
+
return type.base_type == BASE_TYPE_VECTOR;
|
533
|
+
}
|
534
|
+
|
535
|
+
inline bool IsVectorOfStruct(const Type &type) {
|
536
|
+
return IsVector(type) && IsStruct(type.VectorType());
|
537
|
+
}
|
538
|
+
|
539
|
+
inline bool IsVectorOfTable(const Type &type) {
|
540
|
+
return IsVector(type) && IsTable(type.VectorType());
|
541
|
+
}
|
542
|
+
|
543
|
+
inline bool IsArray(const Type &type) {
|
544
|
+
return type.base_type == BASE_TYPE_ARRAY;
|
545
|
+
}
|
546
|
+
|
547
|
+
inline bool IsSeries(const Type &type) {
|
548
|
+
return IsVector(type) || IsArray(type);
|
549
|
+
}
|
550
|
+
|
551
|
+
inline bool IsEnum(const Type &type) {
|
552
|
+
return type.enum_def != nullptr && IsInteger(type.base_type);
|
553
|
+
}
|
554
|
+
|
555
|
+
inline size_t InlineSize(const Type &type) {
|
556
|
+
return IsStruct(type)
|
557
|
+
? type.struct_def->bytesize
|
558
|
+
: (IsArray(type)
|
559
|
+
? InlineSize(type.VectorType()) * type.fixed_length
|
560
|
+
: SizeOf(type.base_type));
|
561
|
+
}
|
562
|
+
|
563
|
+
inline size_t InlineAlignment(const Type &type) {
|
564
|
+
if (IsStruct(type)) {
|
565
|
+
return type.struct_def->minalign;
|
566
|
+
} else if (IsArray(type)) {
|
567
|
+
return IsStruct(type.VectorType()) ? type.struct_def->minalign
|
568
|
+
: SizeOf(type.element);
|
569
|
+
} else {
|
570
|
+
return SizeOf(type.base_type);
|
571
|
+
}
|
572
|
+
}
|
573
|
+
inline bool operator==(const EnumVal &lhs, const EnumVal &rhs) {
|
574
|
+
return lhs.value == rhs.value;
|
575
|
+
}
|
576
|
+
inline bool operator!=(const EnumVal &lhs, const EnumVal &rhs) {
|
577
|
+
return !(lhs == rhs);
|
578
|
+
}
|
579
|
+
|
580
|
+
inline bool EqualByName(const Type &a, const Type &b) {
|
581
|
+
return a.base_type == b.base_type && a.element == b.element &&
|
582
|
+
(a.struct_def == b.struct_def ||
|
583
|
+
(a.struct_def != nullptr && b.struct_def != nullptr &&
|
584
|
+
a.struct_def->name == b.struct_def->name)) &&
|
585
|
+
(a.enum_def == b.enum_def ||
|
586
|
+
(a.enum_def != nullptr && b.enum_def != nullptr &&
|
587
|
+
a.enum_def->name == b.enum_def->name));
|
588
|
+
}
|
589
|
+
|
590
|
+
struct RPCCall : public Definition {
|
591
|
+
Offset<reflection::RPCCall> Serialize(FlatBufferBuilder *builder,
|
592
|
+
const Parser &parser) const;
|
593
|
+
|
594
|
+
bool Deserialize(Parser &parser, const reflection::RPCCall *call);
|
595
|
+
|
596
|
+
StructDef *request, *response;
|
597
|
+
};
|
598
|
+
|
599
|
+
struct ServiceDef : public Definition {
|
600
|
+
Offset<reflection::Service> Serialize(FlatBufferBuilder *builder,
|
601
|
+
const Parser &parser) const;
|
602
|
+
bool Deserialize(Parser &parser, const reflection::Service *service);
|
603
|
+
|
604
|
+
SymbolTable<RPCCall> calls;
|
605
|
+
};
|
606
|
+
|
607
|
+
struct IncludedFile {
|
608
|
+
// The name of the schema file being included, as defined in the .fbs file.
|
609
|
+
// This includes the prefix (e.g., include "foo/bar/baz.fbs" would mean this
|
610
|
+
// value is "foo/bar/baz.fbs").
|
611
|
+
std::string schema_name;
|
612
|
+
|
613
|
+
// The filename of where the included file was found, after searching the
|
614
|
+
// relative paths plus any other paths included with `flatc -I ...`. Note,
|
615
|
+
// while this is sometimes the same as schema_name, it is not always, since it
|
616
|
+
// can be defined relative to where flatc was invoked.
|
617
|
+
std::string filename;
|
618
|
+
};
|
619
|
+
|
620
|
+
// Since IncludedFile is contained within a std::set, need to provide ordering.
|
621
|
+
inline bool operator<(const IncludedFile &a, const IncludedFile &b) {
|
622
|
+
return a.filename < b.filename;
|
623
|
+
}
|
624
|
+
|
625
|
+
// Container of options that may apply to any of the source/text generators.
|
626
|
+
struct IDLOptions {
|
627
|
+
// field case style options for C++
|
628
|
+
enum CaseStyle { CaseStyle_Unchanged = 0, CaseStyle_Upper, CaseStyle_Lower };
|
629
|
+
enum class ProtoIdGapAction { NO_OP, WARNING, ERROR };
|
630
|
+
bool gen_jvmstatic;
|
631
|
+
// Use flexbuffers instead for binary and text generation
|
632
|
+
bool use_flexbuffers;
|
633
|
+
bool strict_json;
|
634
|
+
bool output_default_scalars_in_json;
|
635
|
+
int indent_step;
|
636
|
+
bool cpp_minify_enums;
|
637
|
+
bool output_enum_identifiers;
|
638
|
+
bool prefixed_enums;
|
639
|
+
bool scoped_enums;
|
640
|
+
bool emit_min_max_enum_values;
|
641
|
+
bool swift_implementation_only;
|
642
|
+
bool include_dependence_headers;
|
643
|
+
bool mutable_buffer;
|
644
|
+
bool one_file;
|
645
|
+
bool proto_mode;
|
646
|
+
bool proto_oneof_union;
|
647
|
+
bool generate_all;
|
648
|
+
bool skip_unexpected_fields_in_json;
|
649
|
+
bool generate_name_strings;
|
650
|
+
bool generate_object_based_api;
|
651
|
+
bool gen_compare;
|
652
|
+
std::string cpp_object_api_pointer_type;
|
653
|
+
std::string cpp_object_api_string_type;
|
654
|
+
bool cpp_object_api_string_flexible_constructor;
|
655
|
+
CaseStyle cpp_object_api_field_case_style;
|
656
|
+
bool cpp_direct_copy;
|
657
|
+
bool gen_nullable;
|
658
|
+
std::string java_package_prefix;
|
659
|
+
bool java_checkerframework;
|
660
|
+
bool gen_generated;
|
661
|
+
bool gen_json_coders;
|
662
|
+
std::string object_prefix;
|
663
|
+
std::string object_suffix;
|
664
|
+
bool union_value_namespacing;
|
665
|
+
bool allow_non_utf8;
|
666
|
+
bool natural_utf8;
|
667
|
+
std::string include_prefix;
|
668
|
+
bool keep_prefix;
|
669
|
+
bool binary_schema_comments;
|
670
|
+
bool binary_schema_builtins;
|
671
|
+
bool binary_schema_gen_embed;
|
672
|
+
std::string go_import;
|
673
|
+
std::string go_namespace;
|
674
|
+
std::string go_module_name;
|
675
|
+
bool protobuf_ascii_alike;
|
676
|
+
bool size_prefixed;
|
677
|
+
std::string root_type;
|
678
|
+
bool force_defaults;
|
679
|
+
bool java_primitive_has_method;
|
680
|
+
bool cs_gen_json_serializer;
|
681
|
+
std::vector<std::string> cpp_includes;
|
682
|
+
std::string cpp_std;
|
683
|
+
bool cpp_static_reflection;
|
684
|
+
std::string proto_namespace_suffix;
|
685
|
+
std::string filename_suffix;
|
686
|
+
std::string filename_extension;
|
687
|
+
bool no_warnings;
|
688
|
+
bool warnings_as_errors;
|
689
|
+
std::string project_root;
|
690
|
+
bool cs_global_alias;
|
691
|
+
bool json_nested_flatbuffers;
|
692
|
+
bool json_nested_flexbuffers;
|
693
|
+
bool json_nested_legacy_flatbuffers;
|
694
|
+
bool ts_flat_files;
|
695
|
+
bool ts_entry_points;
|
696
|
+
bool ts_no_import_ext;
|
697
|
+
bool no_leak_private_annotations;
|
698
|
+
bool require_json_eof;
|
699
|
+
bool keep_proto_id;
|
700
|
+
ProtoIdGapAction proto_id_gap_action;
|
701
|
+
|
702
|
+
// Possible options for the more general generator below.
|
703
|
+
enum Language {
|
704
|
+
kJava = 1 << 0,
|
705
|
+
kCSharp = 1 << 1,
|
706
|
+
kGo = 1 << 2,
|
707
|
+
kCpp = 1 << 3,
|
708
|
+
kPython = 1 << 5,
|
709
|
+
kPhp = 1 << 6,
|
710
|
+
kJson = 1 << 7,
|
711
|
+
kBinary = 1 << 8,
|
712
|
+
kTs = 1 << 9,
|
713
|
+
kJsonSchema = 1 << 10,
|
714
|
+
kDart = 1 << 11,
|
715
|
+
kLua = 1 << 12,
|
716
|
+
kLobster = 1 << 13,
|
717
|
+
kRust = 1 << 14,
|
718
|
+
kKotlin = 1 << 15,
|
719
|
+
kSwift = 1 << 16,
|
720
|
+
kNim = 1 << 17,
|
721
|
+
kProto = 1 << 18,
|
722
|
+
kMAX
|
723
|
+
};
|
724
|
+
|
725
|
+
enum MiniReflect { kNone, kTypes, kTypesAndNames };
|
726
|
+
|
727
|
+
MiniReflect mini_reflect;
|
728
|
+
|
729
|
+
// If set, require all fields in a table to be explicitly numbered.
|
730
|
+
bool require_explicit_ids;
|
731
|
+
|
732
|
+
// If set, implement serde::Serialize for generated Rust types
|
733
|
+
bool rust_serialize;
|
734
|
+
|
735
|
+
// If set, generate rust types in individual files with a root module file.
|
736
|
+
bool rust_module_root_file;
|
737
|
+
|
738
|
+
// The corresponding language bit will be set if a language is included
|
739
|
+
// for code generation.
|
740
|
+
unsigned long lang_to_generate;
|
741
|
+
|
742
|
+
// If set (default behavior), empty string fields will be set to nullptr to
|
743
|
+
// make the flatbuffer more compact.
|
744
|
+
bool set_empty_strings_to_null;
|
745
|
+
|
746
|
+
// If set (default behavior), empty vector fields will be set to nullptr to
|
747
|
+
// make the flatbuffer more compact.
|
748
|
+
bool set_empty_vectors_to_null;
|
749
|
+
|
750
|
+
IDLOptions()
|
751
|
+
: gen_jvmstatic(false),
|
752
|
+
use_flexbuffers(false),
|
753
|
+
strict_json(false),
|
754
|
+
output_default_scalars_in_json(false),
|
755
|
+
indent_step(2),
|
756
|
+
cpp_minify_enums(false),
|
757
|
+
output_enum_identifiers(true),
|
758
|
+
prefixed_enums(true),
|
759
|
+
scoped_enums(false),
|
760
|
+
emit_min_max_enum_values(true),
|
761
|
+
swift_implementation_only(false),
|
762
|
+
include_dependence_headers(true),
|
763
|
+
mutable_buffer(false),
|
764
|
+
one_file(false),
|
765
|
+
proto_mode(false),
|
766
|
+
proto_oneof_union(false),
|
767
|
+
generate_all(false),
|
768
|
+
skip_unexpected_fields_in_json(false),
|
769
|
+
generate_name_strings(false),
|
770
|
+
generate_object_based_api(false),
|
771
|
+
gen_compare(false),
|
772
|
+
cpp_object_api_pointer_type("std::unique_ptr"),
|
773
|
+
cpp_object_api_string_flexible_constructor(false),
|
774
|
+
cpp_object_api_field_case_style(CaseStyle_Unchanged),
|
775
|
+
cpp_direct_copy(true),
|
776
|
+
gen_nullable(false),
|
777
|
+
java_checkerframework(false),
|
778
|
+
gen_generated(false),
|
779
|
+
gen_json_coders(false),
|
780
|
+
object_suffix("T"),
|
781
|
+
union_value_namespacing(true),
|
782
|
+
allow_non_utf8(false),
|
783
|
+
natural_utf8(false),
|
784
|
+
keep_prefix(false),
|
785
|
+
binary_schema_comments(false),
|
786
|
+
binary_schema_builtins(false),
|
787
|
+
binary_schema_gen_embed(false),
|
788
|
+
protobuf_ascii_alike(false),
|
789
|
+
size_prefixed(false),
|
790
|
+
force_defaults(false),
|
791
|
+
java_primitive_has_method(false),
|
792
|
+
cs_gen_json_serializer(false),
|
793
|
+
cpp_static_reflection(false),
|
794
|
+
filename_suffix("_generated"),
|
795
|
+
filename_extension(),
|
796
|
+
no_warnings(false),
|
797
|
+
warnings_as_errors(false),
|
798
|
+
project_root(""),
|
799
|
+
cs_global_alias(false),
|
800
|
+
json_nested_flatbuffers(true),
|
801
|
+
json_nested_flexbuffers(true),
|
802
|
+
json_nested_legacy_flatbuffers(false),
|
803
|
+
ts_flat_files(false),
|
804
|
+
ts_entry_points(false),
|
805
|
+
ts_no_import_ext(false),
|
806
|
+
no_leak_private_annotations(false),
|
807
|
+
require_json_eof(true),
|
808
|
+
keep_proto_id(false),
|
809
|
+
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
810
|
+
mini_reflect(IDLOptions::kNone),
|
811
|
+
require_explicit_ids(false),
|
812
|
+
rust_serialize(false),
|
813
|
+
rust_module_root_file(false),
|
814
|
+
lang_to_generate(0),
|
815
|
+
set_empty_strings_to_null(true),
|
816
|
+
set_empty_vectors_to_null(true) {}
|
817
|
+
};
|
818
|
+
|
819
|
+
// This encapsulates where the parser is in the current source file.
|
820
|
+
struct ParserState {
|
821
|
+
ParserState()
|
822
|
+
: prev_cursor_(nullptr),
|
823
|
+
cursor_(nullptr),
|
824
|
+
line_start_(nullptr),
|
825
|
+
line_(0),
|
826
|
+
token_(-1),
|
827
|
+
attr_is_trivial_ascii_string_(true) {}
|
828
|
+
|
829
|
+
protected:
|
830
|
+
void ResetState(const char *source) {
|
831
|
+
prev_cursor_ = source;
|
832
|
+
cursor_ = source;
|
833
|
+
line_ = 0;
|
834
|
+
MarkNewLine();
|
835
|
+
}
|
836
|
+
|
837
|
+
void MarkNewLine() {
|
838
|
+
line_start_ = cursor_;
|
839
|
+
line_ += 1;
|
840
|
+
}
|
841
|
+
|
842
|
+
int64_t CursorPosition() const {
|
843
|
+
FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_);
|
844
|
+
return static_cast<int64_t>(cursor_ - line_start_);
|
845
|
+
}
|
846
|
+
|
847
|
+
const char *prev_cursor_;
|
848
|
+
const char *cursor_;
|
849
|
+
const char *line_start_;
|
850
|
+
int line_; // the current line being parsed
|
851
|
+
int token_;
|
852
|
+
|
853
|
+
// Flag: text in attribute_ is true ASCII string without escape
|
854
|
+
// sequences. Only printable ASCII (without [\t\r\n]).
|
855
|
+
// Used for number-in-string (and base64 string in future).
|
856
|
+
bool attr_is_trivial_ascii_string_;
|
857
|
+
std::string attribute_;
|
858
|
+
std::vector<std::string> doc_comment_;
|
859
|
+
};
|
860
|
+
|
861
|
+
// A way to make error propagation less error prone by requiring values to be
|
862
|
+
// checked.
|
863
|
+
// Once you create a value of this type you must either:
|
864
|
+
// - Call Check() on it.
|
865
|
+
// - Copy or assign it to another value.
|
866
|
+
// Failure to do so leads to an assert.
|
867
|
+
// This guarantees that this as return value cannot be ignored.
|
868
|
+
class CheckedError {
|
869
|
+
public:
|
870
|
+
explicit CheckedError(bool error)
|
871
|
+
: is_error_(error), has_been_checked_(false) {}
|
872
|
+
|
873
|
+
CheckedError &operator=(const CheckedError &other) {
|
874
|
+
is_error_ = other.is_error_;
|
875
|
+
has_been_checked_ = false;
|
876
|
+
other.has_been_checked_ = true;
|
877
|
+
return *this;
|
878
|
+
}
|
879
|
+
|
880
|
+
CheckedError(const CheckedError &other) {
|
881
|
+
*this = other; // Use assignment operator.
|
882
|
+
}
|
883
|
+
|
884
|
+
~CheckedError() { FLATBUFFERS_ASSERT(has_been_checked_); }
|
885
|
+
|
886
|
+
bool Check() {
|
887
|
+
has_been_checked_ = true;
|
888
|
+
return is_error_;
|
889
|
+
}
|
890
|
+
|
891
|
+
private:
|
892
|
+
bool is_error_;
|
893
|
+
mutable bool has_been_checked_;
|
894
|
+
};
|
895
|
+
|
896
|
+
// Additionally, in GCC we can get these errors statically, for additional
|
897
|
+
// assurance:
|
898
|
+
// clang-format off
|
899
|
+
#ifdef __GNUC__
|
900
|
+
#define FLATBUFFERS_CHECKED_ERROR CheckedError \
|
901
|
+
__attribute__((warn_unused_result))
|
902
|
+
#else
|
903
|
+
#define FLATBUFFERS_CHECKED_ERROR CheckedError
|
904
|
+
#endif
|
905
|
+
// clang-format on
|
906
|
+
|
907
|
+
class Parser : public ParserState {
|
908
|
+
public:
|
909
|
+
explicit Parser(const IDLOptions &options = IDLOptions())
|
910
|
+
: current_namespace_(nullptr),
|
911
|
+
empty_namespace_(nullptr),
|
912
|
+
flex_builder_(256, flexbuffers::BUILDER_FLAG_SHARE_ALL),
|
913
|
+
root_struct_def_(nullptr),
|
914
|
+
opts(options),
|
915
|
+
uses_flexbuffers_(false),
|
916
|
+
has_warning_(false),
|
917
|
+
advanced_features_(0),
|
918
|
+
source_(nullptr),
|
919
|
+
anonymous_counter_(0),
|
920
|
+
parse_depth_counter_(0) {
|
921
|
+
if (opts.force_defaults) { builder_.ForceDefaults(true); }
|
922
|
+
// Start out with the empty namespace being current.
|
923
|
+
empty_namespace_ = new Namespace();
|
924
|
+
namespaces_.push_back(empty_namespace_);
|
925
|
+
current_namespace_ = empty_namespace_;
|
926
|
+
known_attributes_["deprecated"] = true;
|
927
|
+
known_attributes_["required"] = true;
|
928
|
+
known_attributes_["key"] = true;
|
929
|
+
known_attributes_["shared"] = true;
|
930
|
+
known_attributes_["hash"] = true;
|
931
|
+
known_attributes_["id"] = true;
|
932
|
+
known_attributes_["force_align"] = true;
|
933
|
+
known_attributes_["bit_flags"] = true;
|
934
|
+
known_attributes_["original_order"] = true;
|
935
|
+
known_attributes_["nested_flatbuffer"] = true;
|
936
|
+
known_attributes_["csharp_partial"] = true;
|
937
|
+
known_attributes_["streaming"] = true;
|
938
|
+
known_attributes_["idempotent"] = true;
|
939
|
+
known_attributes_["cpp_type"] = true;
|
940
|
+
known_attributes_["cpp_ptr_type"] = true;
|
941
|
+
known_attributes_["cpp_ptr_type_get"] = true;
|
942
|
+
known_attributes_["cpp_str_type"] = true;
|
943
|
+
known_attributes_["cpp_str_flex_ctor"] = true;
|
944
|
+
known_attributes_["native_inline"] = true;
|
945
|
+
known_attributes_["native_custom_alloc"] = true;
|
946
|
+
known_attributes_["native_type"] = true;
|
947
|
+
known_attributes_["native_type_pack_name"] = true;
|
948
|
+
known_attributes_["native_default"] = true;
|
949
|
+
known_attributes_["flexbuffer"] = true;
|
950
|
+
known_attributes_["private"] = true;
|
951
|
+
}
|
952
|
+
|
953
|
+
// Copying is not allowed
|
954
|
+
Parser(const Parser &) = delete;
|
955
|
+
Parser &operator=(const Parser &) = delete;
|
956
|
+
|
957
|
+
Parser(Parser &&) = default;
|
958
|
+
Parser &operator=(Parser &&) = default;
|
959
|
+
|
960
|
+
~Parser() {
|
961
|
+
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
962
|
+
delete *it;
|
963
|
+
}
|
964
|
+
}
|
965
|
+
|
966
|
+
// Parse the string containing either schema or JSON data, which will
|
967
|
+
// populate the SymbolTable's or the FlatBufferBuilder above.
|
968
|
+
// include_paths is used to resolve any include statements, and typically
|
969
|
+
// should at least include the project path (where you loaded source_ from).
|
970
|
+
// include_paths must be nullptr terminated if specified.
|
971
|
+
// If include_paths is nullptr, it will attempt to load from the current
|
972
|
+
// directory.
|
973
|
+
// If the source was loaded from a file and isn't an include file,
|
974
|
+
// supply its name in source_filename.
|
975
|
+
// All paths specified in this call must be in posix format, if you accept
|
976
|
+
// paths from user input, please call PosixPath on them first.
|
977
|
+
bool Parse(const char *_source, const char **include_paths = nullptr,
|
978
|
+
const char *source_filename = nullptr);
|
979
|
+
|
980
|
+
bool ParseJson(const char *json, const char *json_filename = nullptr);
|
981
|
+
|
982
|
+
// Returns the number of characters were consumed when parsing a JSON string.
|
983
|
+
std::ptrdiff_t BytesConsumed() const;
|
984
|
+
|
985
|
+
// Set the root type. May override the one set in the schema.
|
986
|
+
bool SetRootType(const char *name);
|
987
|
+
|
988
|
+
// Mark all definitions as already having code generated.
|
989
|
+
void MarkGenerated();
|
990
|
+
|
991
|
+
// Get the files recursively included by the given file. The returned
|
992
|
+
// container will have at least the given file.
|
993
|
+
std::set<std::string> GetIncludedFilesRecursive(
|
994
|
+
const std::string &file_name) const;
|
995
|
+
|
996
|
+
// Fills builder_ with a binary version of the schema parsed.
|
997
|
+
// See reflection/reflection.fbs
|
998
|
+
void Serialize();
|
999
|
+
|
1000
|
+
// Deserialize a schema buffer
|
1001
|
+
bool Deserialize(const uint8_t *buf, const size_t size);
|
1002
|
+
|
1003
|
+
// Fills internal structure as if the schema passed had been loaded by parsing
|
1004
|
+
// with Parse except that included filenames will not be populated.
|
1005
|
+
bool Deserialize(const reflection::Schema *schema);
|
1006
|
+
|
1007
|
+
Type *DeserializeType(const reflection::Type *type);
|
1008
|
+
|
1009
|
+
// Checks that the schema represented by this parser is a safe evolution
|
1010
|
+
// of the schema provided. Returns non-empty error on any problems.
|
1011
|
+
std::string ConformTo(const Parser &base);
|
1012
|
+
|
1013
|
+
// Similar to Parse(), but now only accepts JSON to be parsed into a
|
1014
|
+
// FlexBuffer.
|
1015
|
+
bool ParseFlexBuffer(const char *source, const char *source_filename,
|
1016
|
+
flexbuffers::Builder *builder);
|
1017
|
+
|
1018
|
+
StructDef *LookupStruct(const std::string &id) const;
|
1019
|
+
StructDef *LookupStructThruParentNamespaces(const std::string &id) const;
|
1020
|
+
|
1021
|
+
std::string UnqualifiedName(const std::string &fullQualifiedName);
|
1022
|
+
|
1023
|
+
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
1024
|
+
|
1025
|
+
// @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars
|
1026
|
+
// in a schema.
|
1027
|
+
// @param opts Options used to parce a schema and generate code.
|
1028
|
+
static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts);
|
1029
|
+
|
1030
|
+
// Get the set of included files that are directly referenced by the file
|
1031
|
+
// being parsed. This does not include files that are transitively included by
|
1032
|
+
// others includes.
|
1033
|
+
std::vector<IncludedFile> GetIncludedFiles() const;
|
1034
|
+
|
1035
|
+
private:
|
1036
|
+
class ParseDepthGuard;
|
1037
|
+
|
1038
|
+
void Message(const std::string &msg);
|
1039
|
+
void Warning(const std::string &msg);
|
1040
|
+
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val);
|
1041
|
+
FLATBUFFERS_CHECKED_ERROR Next();
|
1042
|
+
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
|
1043
|
+
bool Is(int t) const;
|
1044
|
+
bool IsIdent(const char *id) const;
|
1045
|
+
FLATBUFFERS_CHECKED_ERROR Expect(int t);
|
1046
|
+
std::string TokenToStringId(int t) const;
|
1047
|
+
EnumDef *LookupEnum(const std::string &id);
|
1048
|
+
FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id,
|
1049
|
+
std::string *last);
|
1050
|
+
FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type);
|
1051
|
+
FLATBUFFERS_CHECKED_ERROR ParseType(Type &type);
|
1052
|
+
FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def,
|
1053
|
+
const std::string &name, const Type &type,
|
1054
|
+
FieldDef **dest);
|
1055
|
+
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
|
1056
|
+
FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling);
|
1057
|
+
FLATBUFFERS_CHECKED_ERROR ParseComma();
|
1058
|
+
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
|
1059
|
+
size_t parent_fieldn,
|
1060
|
+
const StructDef *parent_struct_def,
|
1061
|
+
uoffset_t count,
|
1062
|
+
bool inside_vector = false);
|
1063
|
+
template<typename F>
|
1064
|
+
FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn,
|
1065
|
+
const StructDef *struct_def,
|
1066
|
+
F body);
|
1067
|
+
FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
|
1068
|
+
std::string *value, uoffset_t *ovalue);
|
1069
|
+
void SerializeStruct(const StructDef &struct_def, const Value &val);
|
1070
|
+
void SerializeStruct(FlatBufferBuilder &builder, const StructDef &struct_def,
|
1071
|
+
const Value &val);
|
1072
|
+
template<typename F>
|
1073
|
+
FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(uoffset_t &count, F body);
|
1074
|
+
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue,
|
1075
|
+
FieldDef *field, size_t fieldn);
|
1076
|
+
FLATBUFFERS_CHECKED_ERROR ParseArray(Value &array);
|
1077
|
+
FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer(
|
1078
|
+
Value &val, FieldDef *field, size_t fieldn,
|
1079
|
+
const StructDef *parent_struct_def);
|
1080
|
+
FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable<Value> *attributes);
|
1081
|
+
FLATBUFFERS_CHECKED_ERROR TryTypedValue(const std::string *name, int dtoken,
|
1082
|
+
bool check, Value &e, BaseType req,
|
1083
|
+
bool *destmatch);
|
1084
|
+
FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef *field);
|
1085
|
+
FLATBUFFERS_CHECKED_ERROR TokenError();
|
1086
|
+
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e,
|
1087
|
+
bool check_now);
|
1088
|
+
FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e);
|
1089
|
+
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type,
|
1090
|
+
std::string *result);
|
1091
|
+
StructDef *LookupCreateStruct(const std::string &name,
|
1092
|
+
bool create_if_new = true,
|
1093
|
+
bool definition = false);
|
1094
|
+
FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest,
|
1095
|
+
const char *filename);
|
1096
|
+
FLATBUFFERS_CHECKED_ERROR ParseNamespace();
|
1097
|
+
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
|
1098
|
+
StructDef **dest);
|
1099
|
+
FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, bool is_union,
|
1100
|
+
EnumDef **dest);
|
1101
|
+
FLATBUFFERS_CHECKED_ERROR ParseDecl(const char *filename);
|
1102
|
+
FLATBUFFERS_CHECKED_ERROR ParseService(const char *filename);
|
1103
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
1104
|
+
bool isextend, bool inside_oneof);
|
1105
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoMapField(StructDef *struct_def);
|
1106
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
1107
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
|
1108
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
|
1109
|
+
FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent();
|
1110
|
+
FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type);
|
1111
|
+
FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue();
|
1112
|
+
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant(
|
1113
|
+
flexbuffers::Builder *builder);
|
1114
|
+
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder);
|
1115
|
+
FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source,
|
1116
|
+
const char *source_filename);
|
1117
|
+
FLATBUFFERS_CHECKED_ERROR ParseRoot(const char *_source,
|
1118
|
+
const char **include_paths,
|
1119
|
+
const char *source_filename);
|
1120
|
+
FLATBUFFERS_CHECKED_ERROR CheckPrivateLeak();
|
1121
|
+
FLATBUFFERS_CHECKED_ERROR CheckPrivatelyLeakedFields(
|
1122
|
+
const Definition &def, const Definition &value_type);
|
1123
|
+
FLATBUFFERS_CHECKED_ERROR DoParse(const char *_source,
|
1124
|
+
const char **include_paths,
|
1125
|
+
const char *source_filename,
|
1126
|
+
const char *include_filename);
|
1127
|
+
FLATBUFFERS_CHECKED_ERROR DoParseJson();
|
1128
|
+
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef *> &fields,
|
1129
|
+
StructDef *struct_def,
|
1130
|
+
const char *suffix, BaseType baseType);
|
1131
|
+
FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute(
|
1132
|
+
const std::string &align_constant, size_t min_align, size_t *align);
|
1133
|
+
|
1134
|
+
bool SupportsAdvancedUnionFeatures() const;
|
1135
|
+
bool SupportsAdvancedArrayFeatures() const;
|
1136
|
+
bool SupportsOptionalScalars() const;
|
1137
|
+
bool SupportsDefaultVectorsAndStrings() const;
|
1138
|
+
Namespace *UniqueNamespace(Namespace *ns);
|
1139
|
+
|
1140
|
+
FLATBUFFERS_CHECKED_ERROR RecurseError();
|
1141
|
+
template<typename F> CheckedError Recurse(F f);
|
1142
|
+
|
1143
|
+
const std::string &GetPooledString(const std::string &s) const;
|
1144
|
+
|
1145
|
+
public:
|
1146
|
+
SymbolTable<Type> types_;
|
1147
|
+
SymbolTable<StructDef> structs_;
|
1148
|
+
SymbolTable<EnumDef> enums_;
|
1149
|
+
SymbolTable<ServiceDef> services_;
|
1150
|
+
std::vector<Namespace *> namespaces_;
|
1151
|
+
Namespace *current_namespace_;
|
1152
|
+
Namespace *empty_namespace_;
|
1153
|
+
std::string error_; // User readable error_ if Parse() == false
|
1154
|
+
|
1155
|
+
FlatBufferBuilder builder_; // any data contained in the file
|
1156
|
+
flexbuffers::Builder flex_builder_;
|
1157
|
+
flexbuffers::Reference flex_root_;
|
1158
|
+
StructDef *root_struct_def_;
|
1159
|
+
std::string file_identifier_;
|
1160
|
+
std::string file_extension_;
|
1161
|
+
|
1162
|
+
std::map<uint64_t, std::string> included_files_;
|
1163
|
+
std::map<std::string, std::set<IncludedFile>> files_included_per_file_;
|
1164
|
+
std::vector<std::string> native_included_files_;
|
1165
|
+
|
1166
|
+
std::map<std::string, bool> known_attributes_;
|
1167
|
+
|
1168
|
+
IDLOptions opts;
|
1169
|
+
bool uses_flexbuffers_;
|
1170
|
+
bool has_warning_;
|
1171
|
+
|
1172
|
+
uint64_t advanced_features_;
|
1173
|
+
|
1174
|
+
std::string file_being_parsed_;
|
1175
|
+
|
1176
|
+
private:
|
1177
|
+
const char *source_;
|
1178
|
+
|
1179
|
+
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
1180
|
+
|
1181
|
+
// TODO(cneo): Refactor parser to use string_cache more often to save
|
1182
|
+
// on memory usage.
|
1183
|
+
mutable std::set<std::string> string_cache_;
|
1184
|
+
|
1185
|
+
int anonymous_counter_;
|
1186
|
+
int parse_depth_counter_; // stack-overflow guard
|
1187
|
+
};
|
1188
|
+
|
1189
|
+
// Utility functions for multiple generators:
|
1190
|
+
|
1191
|
+
// Generate text (JSON) from a given FlatBuffer, and a given Parser
|
1192
|
+
// object that has been populated with the corresponding schema.
|
1193
|
+
// If ident_step is 0, no indentation will be generated. Additionally,
|
1194
|
+
// if it is less than 0, no linefeeds will be generated either.
|
1195
|
+
// See idl_gen_text.cpp.
|
1196
|
+
// strict_json adds "quotes" around field names if true.
|
1197
|
+
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
|
1198
|
+
// byte arrays in String values), returns false.
|
1199
|
+
extern bool GenerateTextFromTable(const Parser &parser, const void *table,
|
1200
|
+
const std::string &tablename,
|
1201
|
+
std::string *text);
|
1202
|
+
extern bool GenerateText(const Parser &parser, const void *flatbuffer,
|
1203
|
+
std::string *text);
|
1204
|
+
extern bool GenerateTextFile(const Parser &parser, const std::string &path,
|
1205
|
+
const std::string &file_name);
|
1206
|
+
|
1207
|
+
// Generate Json schema to string
|
1208
|
+
// See idl_gen_json_schema.cpp.
|
1209
|
+
extern bool GenerateJsonSchema(const Parser &parser, std::string *json);
|
1210
|
+
|
1211
|
+
// Generate binary files from a given FlatBuffer, and a given Parser
|
1212
|
+
// object that has been populated with the corresponding schema.
|
1213
|
+
// See code_generators.cpp.
|
1214
|
+
extern bool GenerateBinary(const Parser &parser, const std::string &path,
|
1215
|
+
const std::string &file_name);
|
1216
|
+
|
1217
|
+
// Generate a C++ header from the definitions in the Parser object.
|
1218
|
+
// See idl_gen_cpp.
|
1219
|
+
extern bool GenerateCPP(const Parser &parser, const std::string &path,
|
1220
|
+
const std::string &file_name);
|
1221
|
+
|
1222
|
+
// Generate C# files from the definitions in the Parser object.
|
1223
|
+
// See idl_gen_csharp.cpp.
|
1224
|
+
extern bool GenerateCSharp(const Parser &parser, const std::string &path,
|
1225
|
+
const std::string &file_name);
|
1226
|
+
|
1227
|
+
extern bool GenerateDart(const Parser &parser, const std::string &path,
|
1228
|
+
const std::string &file_name);
|
1229
|
+
|
1230
|
+
// Generate Java files from the definitions in the Parser object.
|
1231
|
+
// See idl_gen_java.cpp.
|
1232
|
+
extern bool GenerateJava(const Parser &parser, const std::string &path,
|
1233
|
+
const std::string &file_name);
|
1234
|
+
|
1235
|
+
// Generate JavaScript or TypeScript code from the definitions in the Parser
|
1236
|
+
// object. See idl_gen_js.
|
1237
|
+
extern bool GenerateTS(const Parser &parser, const std::string &path,
|
1238
|
+
const std::string &file_name);
|
1239
|
+
|
1240
|
+
// Generate Go files from the definitions in the Parser object.
|
1241
|
+
// See idl_gen_go.cpp.
|
1242
|
+
extern bool GenerateGo(const Parser &parser, const std::string &path,
|
1243
|
+
const std::string &file_name);
|
1244
|
+
|
1245
|
+
// Generate Php code from the definitions in the Parser object.
|
1246
|
+
// See idl_gen_php.
|
1247
|
+
extern bool GeneratePhp(const Parser &parser, const std::string &path,
|
1248
|
+
const std::string &file_name);
|
1249
|
+
|
1250
|
+
// Generate Python files from the definitions in the Parser object.
|
1251
|
+
// See idl_gen_python.cpp.
|
1252
|
+
extern bool GeneratePython(const Parser &parser, const std::string &path,
|
1253
|
+
const std::string &file_name);
|
1254
|
+
|
1255
|
+
// Generate Lobster files from the definitions in the Parser object.
|
1256
|
+
// See idl_gen_lobster.cpp.
|
1257
|
+
extern bool GenerateLobster(const Parser &parser, const std::string &path,
|
1258
|
+
const std::string &file_name);
|
1259
|
+
|
1260
|
+
// Generate Lua files from the definitions in the Parser object.
|
1261
|
+
// See idl_gen_lua.cpp.
|
1262
|
+
extern bool GenerateLua(const Parser &parser, const std::string &path,
|
1263
|
+
const std::string &file_name);
|
1264
|
+
|
1265
|
+
// Generate Rust files from the definitions in the Parser object.
|
1266
|
+
// See idl_gen_rust.cpp.
|
1267
|
+
extern bool GenerateRust(const Parser &parser, const std::string &path,
|
1268
|
+
const std::string &file_name);
|
1269
|
+
|
1270
|
+
// Generate Json schema file
|
1271
|
+
// See idl_gen_json_schema.cpp.
|
1272
|
+
extern bool GenerateJsonSchema(const Parser &parser, const std::string &path,
|
1273
|
+
const std::string &file_name);
|
1274
|
+
|
1275
|
+
extern bool GenerateKotlin(const Parser &parser, const std::string &path,
|
1276
|
+
const std::string &file_name);
|
1277
|
+
|
1278
|
+
// Generate Swift classes.
|
1279
|
+
// See idl_gen_swift.cpp
|
1280
|
+
extern bool GenerateSwift(const Parser &parser, const std::string &path,
|
1281
|
+
const std::string &file_name);
|
1282
|
+
|
1283
|
+
// Generate a schema file from the internal representation, useful after
|
1284
|
+
// parsing a .proto schema.
|
1285
|
+
extern std::string GenerateFBS(const Parser &parser,
|
1286
|
+
const std::string &file_name);
|
1287
|
+
extern bool GenerateFBS(const Parser &parser, const std::string &path,
|
1288
|
+
const std::string &file_name);
|
1289
|
+
|
1290
|
+
// Generate a make rule for the generated TypeScript code.
|
1291
|
+
// See idl_gen_ts.cpp.
|
1292
|
+
extern std::string TSMakeRule(const Parser &parser, const std::string &path,
|
1293
|
+
const std::string &file_name);
|
1294
|
+
|
1295
|
+
// Generate a make rule for the generated C++ header.
|
1296
|
+
// See idl_gen_cpp.cpp.
|
1297
|
+
extern std::string CPPMakeRule(const Parser &parser, const std::string &path,
|
1298
|
+
const std::string &file_name);
|
1299
|
+
|
1300
|
+
// Generate a make rule for the generated Dart code
|
1301
|
+
// see idl_gen_dart.cpp
|
1302
|
+
extern std::string DartMakeRule(const Parser &parser, const std::string &path,
|
1303
|
+
const std::string &file_name);
|
1304
|
+
|
1305
|
+
// Generate a make rule for the generated Rust code.
|
1306
|
+
// See idl_gen_rust.cpp.
|
1307
|
+
extern std::string RustMakeRule(const Parser &parser, const std::string &path,
|
1308
|
+
const std::string &file_name);
|
1309
|
+
|
1310
|
+
// Generate a make rule for generated Java or C# files.
|
1311
|
+
// See code_generators.cpp.
|
1312
|
+
extern std::string CSharpMakeRule(const Parser &parser, const std::string &path,
|
1313
|
+
const std::string &file_name);
|
1314
|
+
extern std::string JavaMakeRule(const Parser &parser, const std::string &path,
|
1315
|
+
const std::string &file_name);
|
1316
|
+
|
1317
|
+
// Generate a make rule for the generated text (JSON) files.
|
1318
|
+
// See idl_gen_text.cpp.
|
1319
|
+
extern std::string TextMakeRule(const Parser &parser, const std::string &path,
|
1320
|
+
const std::string &file_names);
|
1321
|
+
|
1322
|
+
// Generate a make rule for the generated binary files.
|
1323
|
+
// See code_generators.cpp.
|
1324
|
+
extern std::string BinaryMakeRule(const Parser &parser, const std::string &path,
|
1325
|
+
const std::string &file_name);
|
1326
|
+
|
1327
|
+
// Generate GRPC Cpp interfaces.
|
1328
|
+
// See idl_gen_grpc.cpp.
|
1329
|
+
bool GenerateCppGRPC(const Parser &parser, const std::string &path,
|
1330
|
+
const std::string &file_name);
|
1331
|
+
|
1332
|
+
// Generate GRPC Go interfaces.
|
1333
|
+
// See idl_gen_grpc.cpp.
|
1334
|
+
bool GenerateGoGRPC(const Parser &parser, const std::string &path,
|
1335
|
+
const std::string &file_name);
|
1336
|
+
|
1337
|
+
// Generate GRPC Java classes.
|
1338
|
+
// See idl_gen_grpc.cpp
|
1339
|
+
bool GenerateJavaGRPC(const Parser &parser, const std::string &path,
|
1340
|
+
const std::string &file_name);
|
1341
|
+
|
1342
|
+
// Generate GRPC Python interfaces.
|
1343
|
+
// See idl_gen_grpc.cpp.
|
1344
|
+
bool GeneratePythonGRPC(const Parser &parser, const std::string &path,
|
1345
|
+
const std::string &file_name);
|
1346
|
+
|
1347
|
+
// Generate GRPC Swift interfaces.
|
1348
|
+
// See idl_gen_grpc.cpp.
|
1349
|
+
extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path,
|
1350
|
+
const std::string &file_name);
|
1351
|
+
|
1352
|
+
extern bool GenerateTSGRPC(const Parser &parser, const std::string &path,
|
1353
|
+
const std::string &file_name);
|
1354
|
+
|
1355
|
+
extern bool GenerateRustModuleRootFile(const Parser &parser,
|
1356
|
+
const std::string &path);
|
1357
|
+
} // namespace flatbuffers
|
1358
|
+
|
1359
|
+
#endif // FLATBUFFERS_IDL_H_
|