|
Blender V4.3
|
Struct parser for generating SDNA. More...
#include <algorithm>#include <cctype>#include <cstdio>#include <cstdlib>#include <cstring>#include "MEM_guardedalloc.h"#include "BLI_alloca.h"#include "BLI_ghash.h"#include "BLI_memarena.h"#include "BLI_string.h"#include "BLI_sys_types.h"#include "BLI_system.h"#include "BLI_utildefines.h"#include "DNA_sdna_types.h"#include "dna_utils.h"#include "dna_includes_as_strings.h"#include "dna_includes_all.h"#include "dna_rename_defs.h"Go to the source code of this file.
Macros | |
| #define | DNA_DEPRECATED_ALLOW |
| #define | SDNA_MAX_FILENAME_LENGTH 255 |
| #define | FORCE_ALIGN_4 " " |
| #define | DNA_STRUCT_RENAME(old, new) (void)sizeof(new); |
| #define | DNA_STRUCT_RENAME_MEMBER(struct_name, old, new) (void)offsetof(struct_name, new); |
Functions | |
Function Declarations | |
| static int | add_type (const char *type_name, int size) |
| static int | add_member (const char *member_name) |
| static short * | add_struct (int type_index) |
| static int | preprocess_include (char *maindata, const int maindata_len) |
| static int | convert_include (const char *filepath) |
| static int | calculate_struct_sizes (int firststruct, FILE *file_verify, const char *base_directory) |
| static void | dna_write (FILE *file, const void *pntr, const int size) |
| void | print_struct_sizes () |
DNA Renaming Sanity Check | |
Without this it's possible to reference struct members that don't exist, breaking backward & forward compatibility. | |
| static void UNUSED_FUNCTION | dna_rename_defs_ensure () |
Variables | |
| static const char * | includefiles [] |
Variables | ||
| #define | DEBUG_PRINTF(debug_level, ...) | |
| static MemArena * | mem_arena = nullptr | |
| static int | max_data_size = 500000 | |
| static int | max_array_len = 50000 | |
| static int | members_num = 0 | |
| static int | types_num = 0 | |
| static int | structs_num = 0 | |
| static char ** | members | |
| static char ** | types | |
| static short * | types_size_native | |
| static short * | types_align_32 | |
| static short * | types_align_64 | |
| static short * | types_size_32 | |
| static short * | types_size_64 | |
| static short ** | structs | |
| static short * | structdata | |
| struct { | ||
| GHash * type_map_alias_from_static | ||
| GHash * type_map_static_from_alias | ||
| GHash * member_map_alias_from_static | ||
| GHash * member_map_static_from_alias | ||
| } | g_version_data = {nullptr} | |
| static int | debugSDNA = 0 | |
| static int | additional_slen_offset | |
| void | BLI_system_backtrace (FILE *fp) | |
Implementation | |
Make DNA string (write to file). | |
| #define | MAX_DNA_LINE_LENGTH 20 |
| static bool | match_identifier_with_len (const char *str, const char *identifier, const size_t identifier_len) |
| static bool | match_identifier (const char *str, const char *identifier) |
| static bool | match_identifier_and_advance (char **str_ptr, const char *identifier) |
| static const char * | version_struct_static_from_alias (const char *type_alias) |
| static const char * | version_struct_alias_from_static (const char *type_static) |
| static const char * | version_member_static_from_alias (const int type_index, const char *member_alias_full) |
| static bool | is_name_legal (const char *name) |
| static bool | str_startswith (const char *__restrict str, const char *__restrict start) |
| static bool | match_preproc_prefix (const char *__restrict str, const char *__restrict start) |
| static char * | match_preproc_strstr (char *__restrict str, const char *__restrict start) |
| static void * | read_file_data (const char *filepath, int *r_len) |
| static bool | check_field_alignment (int firststruct, int struct_type_index, int type, int len, const char *name, const char *detail) |
| static int | make_structDNA (const char *base_directory, FILE *file, FILE *file_offsets, FILE *file_verify) |
Main Function | |
| #define | BASE_HEADER "../" |
| static void | make_bad_file (const char *file, int line) |
| int | main (int argc, char **argv) |
Struct parser for generating SDNA.
makesdna creates a .c file with a long string of numbers that encode the Blender file format. It is fast, because it is basically a binary dump. There are some details to mind when reconstructing the file (endianness and byte-alignment).
This little program scans all structs that need to be serialized, and determined the names and types of all members. It calculates how much memory (on disk or in ram) is needed to store that struct, and the offsets for reaching a particular one.
There is a facility to get verbose output from sdna. Search for debugSDNA. This int can be set to 0 (no output) to some int. Higher numbers give more output.
Definition in file makesdna.cc.
| #define BASE_HEADER "../" |
Definition at line 1558 of file makesdna.cc.
Referenced by main().
| #define DEBUG_PRINTF | ( | debug_level, | |
| ... ) |
Definition at line 109 of file makesdna.cc.
Referenced by add_member(), convert_include(), and make_structDNA().
| #define DNA_DEPRECATED_ALLOW |
Definition at line 27 of file makesdna.cc.
| #define DNA_STRUCT_RENAME | ( | old, | |
| new ) (void)sizeof(new); |
| #define MAX_DNA_LINE_LENGTH 20 |
Definition at line 1229 of file makesdna.cc.
Referenced by dna_write().
| #define SDNA_MAX_FILENAME_LENGTH 255 |
Definition at line 48 of file makesdna.cc.
Referenced by make_structDNA().
|
static |
Ensure that member_name is in the members array.
| member_name | Full struct member name (may include pointer prefix & array size). |
Because of the weird way of tokenizing, we have to 'cast' function pointers to ... (*f)(), whatever the original signature. In fact, we add name and type at the same time... There are two special cases, unfortunately. These are explicitly checked.
Definition at line 357 of file makesdna.cc.
References additional_slen_offset, BLI_memarena_alloc(), DEBUG_PRINTF, is_name_legal(), max_array_len, mem_arena, members, members_num, printf, and STREQ.
Referenced by convert_include().
|
static |
Add a new structure definition, of type matching the given type_index.
NOTE: there is no lookup performed here, a new struct definition is always added.
Definition at line 496 of file makesdna.cc.
References len, max_array_len, printf, structdata, structs, and structs_num.
Referenced by convert_include(), and make_structDNA().
Ensure that type type_name is in the types array.
| type_name | Struct name without any qualifiers. |
| size | The struct size in bytes. |
Definition at line 304 of file makesdna.cc.
References BLI_memarena_alloc(), max_array_len, mem_arena, printf, size(), STREQ, types_align_32, types_align_64, types_num, types_size_32, types_size_64, types_size_native, and version_struct_static_from_alias().
Referenced by convert_include(), and make_structDNA().
| void BLI_system_backtrace | ( | FILE * | fp | ) |
Write a backtrace into a file for systems which support it.
Definition at line 119 of file makesdna.cc.
|
static |
Determine how many bytes are needed for each struct.
Definition at line 941 of file makesdna.cc.
References b, BLI_assert, BLI_ghash_lookup(), BLI_STATIC_ASSERT, check_field_alignment(), debugSDNA, DNA_member_array_num(), DNA_member_id_strip_copy(), ELEM, g_version_data, includefiles, int, members, mul(), SDNA_RAW_DATA_STRUCT_INDEX, structs, structs_num, types_align_32, types_align_64, types_size_32, types_size_64, types_size_native, and version_struct_alias_from_static().
Referenced by make_structDNA().
|
static |
Definition at line 903 of file makesdna.cc.
References len, result, and types_size_native.
Referenced by calculate_struct_sizes().
|
static |
Scan this file for serializable types.
Definition at line 706 of file makesdna.cc.
References add_member(), add_struct(), add_type(), additional_slen_offset, count, DEBUG_PRINTF, ELEM, int, match_identifier(), match_identifier_and_advance(), MEM_freeN(), members, preprocess_include(), read_file_data(), STR_ELEM, UNLIKELY, and version_member_static_from_alias().
Referenced by make_structDNA().
|
static |
Definition at line 1664 of file makesdna.cc.
|
static |
Construct the DNA.c file
Definition at line 1231 of file makesdna.cc.
References MAX_DNA_LINE_LENGTH, and size().
Referenced by make_structDNA().
|
static |
Enforce '_pad123' naming convention, disallow 'pad123' or 'pad_123', special exception for [a-z] after since there is a 'pad_rot_angle' preference.
Definition at line 265 of file makesdna.cc.
References DNA_member_id_strip_copy().
Referenced by add_member().
Definition at line 1561 of file makesdna.cc.
References BASE_HEADER, ELEM, FORCE_ALIGN_4, make_bad_file(), make_structDNA(), and printf.
|
static |
Definition at line 1547 of file makesdna.cc.
Referenced by main().
|
static |
Insertion of all known types.
Definition at line 1265 of file makesdna.cc.
References add_struct(), add_type(), b, BLI_assert, BLI_ghash_free(), BLI_gset_add(), BLI_gset_clear(), BLI_gset_free(), BLI_gset_str_new_ex(), BLI_memarena_free(), BLI_memarena_new(), BLI_MEMARENA_STD_BUFSIZE, BLI_STATIC_ASSERT, calculate_struct_sizes(), convert_include(), DEBUG_PRINTF, debugSDNA, DNA_alias_maps(), DNA_member_id_strip(), DNA_RENAME_ALIAS_FROM_STATIC, DNA_RENAME_STATIC_FROM_ALIAS, dna_write(), g_version_data, includefiles, len, max_array_len, max_data_size, mem_arena, MEM_callocN, MEM_freeN(), members, members_num, printf, SDNA_MAX_FILENAME_LENGTH, SDNA_RAW_DATA_STRUCT_INDEX, SNPRINTF, str, structdata, structs, structs_num, types_align_32, types_align_64, types_num, types_size_32, types_size_64, types_size_native, and version_struct_alias_from_static().
Referenced by main().
|
static |
Definition at line 203 of file makesdna.cc.
References match_identifier_with_len(), and str.
Referenced by convert_include(), and preprocess_include().
|
static |
Definition at line 209 of file makesdna.cc.
References match_identifier_with_len().
Referenced by convert_include().
|
static |
Definition at line 187 of file makesdna.cc.
References str.
Referenced by match_identifier(), and match_identifier_and_advance().
|
static |
Check if str is a preprocessor string that starts with start. The start doesn't need the # prefix. ifdef VALUE will match #ifdef VALUE as well as # ifdef VALUE.
Definition at line 537 of file makesdna.cc.
References str, and str_startswith().
Referenced by preprocess_include().
|
static |
str that starts with start or nullptr when not found. Definition at line 552 of file makesdna.cc.
References str, and str_startswith().
Referenced by preprocess_include().
Remove comments from this buffer. Assumes that the buffer refers to ascii-code text.
Definition at line 566 of file makesdna.cc.
References match_identifier(), match_preproc_prefix(), match_preproc_strstr(), MEM_freeN(), and MEM_mallocN.
Referenced by convert_include().
| void print_struct_sizes | ( | ) |
Report all structures found so far, and print their lengths.
Definition at line 1246 of file makesdna.cc.
References printf, structs, structs_num, and types_size_native.
|
static |
Definition at line 665 of file makesdna.cc.
References data, L, MEM_freeN(), and MEM_mallocN.
Referenced by convert_include().
|
static |
Definition at line 521 of file makesdna.cc.
References str.
Referenced by match_preproc_prefix(), and match_preproc_strstr().
|
static |
Definition at line 239 of file makesdna.cc.
References BLI_ghash_lookup(), DNA_member_id_offset_start(), DNA_member_id_rename(), DNA_member_id_strip_copy(), g_version_data, and mem_arena.
Referenced by convert_include().
|
static |
Definition at line 229 of file makesdna.cc.
References BLI_ghash_lookup(), and g_version_data.
Referenced by calculate_struct_sizes(), and make_structDNA().
|
static |
Definition at line 219 of file makesdna.cc.
References BLI_ghash_lookup(), and g_version_data.
Referenced by add_type().
|
static |
Definition at line 107 of file makesdna.cc.
Referenced by add_member(), and convert_include().
|
static |
Variable to control debug output of makesdna. debugSDNA:
Definition at line 106 of file makesdna.cc.
Referenced by calculate_struct_sizes(), and make_structDNA().
| struct { ... } g_version_data |
Versioning data
Referenced by calculate_struct_sizes(), make_structDNA(), version_member_static_from_alias(), version_struct_alias_from_static(), and version_struct_static_from_alias().
|
static |
Definition at line 52 of file makesdna.cc.
Referenced by calculate_struct_sizes(), and make_structDNA().
|
static |
Definition at line 64 of file makesdna.cc.
Referenced by add_member(), add_struct(), add_type(), and make_structDNA().
|
static |
Definition at line 64 of file makesdna.cc.
Referenced by make_structDNA().
|
static |
Definition at line 62 of file makesdna.cc.
Referenced by add_member(), add_new_bound_vert(), add_type(), adj_vmesh(), BM_face_split_edgenet_connect_islands(), build_boundary(), build_boundary_terminal_edge(), DNA_member_id_rename(), edbm_face_split_by_edges_exec(), ghash_insert_face_edge_link(), ghash_insert_link(), make_cube_corner_adj_vmesh(), make_cube_corner_square(), make_cube_corner_square_in(), make_structDNA(), new_adj_vmesh(), and version_member_static_from_alias().
| GHash* member_map_alias_from_static |
Definition at line 94 of file makesdna.cc.
Referenced by DNA_sdna_alias_data_ensure().
| GHash* member_map_static_from_alias |
Definition at line 95 of file makesdna.cc.
|
static |
At address members[a] is string a.
Definition at line 69 of file makesdna.cc.
Referenced by add_member(), bpy_context_members(), calculate_struct_sizes(), convert_include(), CTX_data_scene_set(), CTX_wm_area_set(), CTX_wm_region_set(), CTX_wm_screen_set(), CTX_wm_window_set(), and make_structDNA().
|
static |
Definition at line 65 of file makesdna.cc.
Referenced by add_member(), and make_structDNA().
|
static |
Definition at line 88 of file makesdna.cc.
Referenced by add_struct(), and make_structDNA().
|
static |
At sp = structs[a] is the first address of a struct definition:
sp[0] is type index.sp[1] is the length of the member array (next).sp[2] sp[3] is [(type_index, member_index), ..] (number of pairs is defined by sp[1]), Definition at line 88 of file makesdna.cc.
Referenced by add_struct(), calculate_struct_sizes(), dna_struct_find_index_ex_impl(), make_structDNA(), and print_struct_sizes().
|
static |
Definition at line 67 of file makesdna.cc.
Referenced by add_struct(), calculate_struct_sizes(), dna_struct_find_index_ex_impl(), make_structDNA(), and print_struct_sizes().
| GHash* type_map_alias_from_static |
Definition at line 92 of file makesdna.cc.
Referenced by DNA_sdna_alias_data_ensure().
| GHash* type_map_static_from_alias |
Definition at line 93 of file makesdna.cc.
|
static |
At address types[a] is string a.
Definition at line 71 of file makesdna.cc.
Referenced by Device::available_types(), blender::draw::curve_render_data_create(), blender::bke::CurvesGeometry::evaluated_normals(), blender::bke::GeometrySet::gather_component_types(), AnimationImporter::get_animation_type(), blender::draw::lattice_render_data_create(), blender::nodes::node_geo_attribute_capture_cc::node_geo_exec(), blender::nodes::node_geo_instance_on_points_cc::node_geo_exec(), AnimationImporter::setAnimType(), and blender::tests::TEST().
|
static |
Contains align requirements for a struct on 32 bit systems.
Definition at line 75 of file makesdna.cc.
Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().
|
static |
Contains align requirements for a struct on 64 bit systems.
Definition at line 77 of file makesdna.cc.
Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().
|
static |
Definition at line 66 of file makesdna.cc.
Referenced by add_type(), dna_struct_find_index_ex_impl(), and make_structDNA().
|
static |
Contains sizes as they are calculated on 32 bit systems.
Definition at line 79 of file makesdna.cc.
Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().
|
static |
Contains sizes as they are calculated on 64 bit systems.
Definition at line 81 of file makesdna.cc.
Referenced by add_type(), calculate_struct_sizes(), and make_structDNA().
|
static |
At types_size[a] is the size of type a on this systems bitness (32 or 64).
Definition at line 73 of file makesdna.cc.
Referenced by add_type(), calculate_struct_sizes(), check_field_alignment(), make_structDNA(), and print_struct_sizes().