44 #define DNA_DEPRECATED_ALLOW
61 #define SDNA_MAX_FILENAME_LENGTH 255
74 "DNA_packedFile_types.h",
78 "DNA_texture_types.h",
80 "DNA_material_types.h",
85 "DNA_meshdata_types.h",
86 "DNA_modifier_types.h",
87 "DNA_lineart_types.h",
88 "DNA_lattice_types.h",
90 "DNA_object_force_types.h",
91 "DNA_object_fluidsim_types.h",
97 "DNA_userdef_types.h",
100 "DNA_fileglobal_types.h",
101 "DNA_sequence_types.h",
102 "DNA_session_uuid_types.h",
103 "DNA_effect_types.h",
104 "DNA_outliner_types.h",
106 "DNA_collection_types.h",
107 "DNA_armature_types.h",
108 "DNA_action_types.h",
109 "DNA_constraint_types.h",
114 "DNA_customdata_types.h",
115 "DNA_particle_types.h",
117 "DNA_gpencil_types.h",
118 "DNA_gpencil_modifier_types.h",
119 "DNA_shader_fx_types.h",
120 "DNA_windowmanager_types.h",
124 "DNA_speaker_types.h",
125 "DNA_movieclip_types.h",
126 "DNA_tracking_types.h",
127 "DNA_dynamicpaint_types.h",
129 "DNA_rigidbody_types.h",
130 "DNA_freestyle_types.h",
131 "DNA_linestyle_types.h",
132 "DNA_cachefile_types.h",
134 "DNA_workspace_types.h",
135 "DNA_lightprobe_types.h",
136 "DNA_curveprofile_types.h",
139 "DNA_pointcloud_types.h",
140 "DNA_volume_types.h",
141 "DNA_simulation_types.h",
142 "DNA_pointcache_types.h",
202 #define DEBUG_PRINTF(debug_level, ...) \
204 if (debugSDNA > debug_level) { \
205 printf(__VA_ARGS__); \
282 if (str_test !=
NULL) {
291 if (str_test !=
NULL) {
299 const uint elem_alias_full_len = strlen(elem_alias_full);
300 char *elem_alias = alloca(elem_alias_full_len + 1);
302 const char *str_pair[2] = {
types[strct], elem_alias};
304 if (elem_static !=
NULL) {
314 return elem_alias_full;
323 const int name_size = strlen(name) + 1;
324 char *name_strip = alloca(name_size);
327 const char prefix[] = {
'p',
'a',
'd'};
329 if (name[0] ==
'_') {
330 if (strncmp(&name_strip[1], prefix,
sizeof(prefix)) != 0) {
332 stderr,
"Error: only '_pad' variables can start with an underscore, found '%s'\n", name);
336 else if (strncmp(name_strip, prefix,
sizeof(prefix)) == 0) {
337 int i =
sizeof(prefix);
338 if (name_strip[i] >=
'a' && name_strip[i] <=
'z') {
342 bool has_only_digit_or_none =
true;
343 for (; name_strip[i]; i++) {
344 const char c = name_strip[i];
345 if (!((
c >=
'0' &&
c <=
'9') ||
c ==
'_')) {
346 has_only_digit_or_none =
false;
350 if (has_only_digit_or_none) {
353 stderr,
"Error: padding variables must be formatted '_pad[number]', found '%s'\n", name);
366 if (strchr(
str,
'*')) {
375 for (
int index = 0; index <
types_len; index++) {
389 const int str_size = strlen(
str) + 1;
391 memcpy(cp,
str, str_size);
399 printf(
"too many types\n");
424 if (
str[0] ==
'(' &&
str[1] ==
'*') {
429 int isfuncptr = (strchr(
str + 1,
'(')) !=
NULL;
431 DEBUG_PRINTF(3,
"\t\t\t\t*** Function pointer or multidim array pointer found\n");
435 while (
str[i] !=
')') {
448 while ((
str[j] != 0) && (
str[j] !=
')')) {
454 "special after offset%d\n",
462 DEBUG_PRINTF(3,
"offsetting for multidim array pointer\n");
465 printf(
"Error during tokening multidim array pointer\n");
468 else if (
str[j] == 0) {
472 while (
str[j] !=
')') {
479 else if (
str[j] ==
')') {
484 printf(
"Error during tokening function pointer argument list\n");
500 if ((strncmp(buf,
"(*headdraw", 10) == 0) || (strncmp(buf,
"(*windraw", 9) == 0)) {
517 DEBUG_PRINTF(3,
"\t\t\t\t\tProposing fp name %s\n", buf);
538 const int name_size = strlen(name) + 1;
540 memcpy(cp, name, name_size);
544 printf(
"too many names\n");
559 const int len = sp[1];
567 printf(
"too many structs\n");
579 char *temp =
MEM_mallocN(maindata_len + 1,
"preprocess_include");
580 temp[maindata_len] =
' ';
582 memcpy(temp, maindata, maindata_len);
587 int a = maindata_len;
590 if (cp[0] ==
'/' && cp[1] ==
'/') {
593 else if (*cp ==
'\n') {
596 if (comment || *cp < 32 || *cp > 128) {
610 if (cp[0] ==
'/' && cp[1] ==
'*') {
614 if (cp[0] ==
'*' && cp[1] ==
'/') {
623 else if (cp[0] ==
' ' && cp[1] ==
' ') {
626 else if (cp[-1] ==
'*' && cp[0] ==
' ') {
629 else if (strncmp(
"DNA_DEPRECATED", cp, 14) == 0) {
649 FILE *fp = fopen(filename,
"rb");
651 FILE *fp = fopen(filename,
"r");
660 fseek(fp, 0
L, SEEK_END);
662 fseek(fp, 0
L, SEEK_SET);
676 if (fread(
data, *r_len, 1, fp) != 1) {
696 if (maindata_len == -1) {
697 fprintf(stderr,
"Can't read file %s\n", filename);
702 char *mainend = maindata + maindata_len - 1;
706 bool skip_struct =
false;
707 while (
count < maindata_len) {
710 if (md[0] ==
'#' && md[1] ==
' ' && md[2] ==
'#') {
731 if (strncmp(md1 - 7,
"struct", 6) == 0) {
735 fprintf(stderr,
"File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
740 short *sp = structpoin + 2;
746 while (*md1 !=
'}') {
751 if (
ELEM(*md1,
',',
' ')) {
759 while (*md1 !=
'}') {
766 if (strncmp(md1,
"struct", 6) == 0) {
769 if (strncmp(md1,
"unsigned", 8) == 0) {
772 if (strncmp(md1,
"const", 5) == 0) {
780 stderr,
"File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
789 while (*md1 !=
';') {
798 int slen = (int)strlen(md1);
799 if (md1[slen - 1] ==
';') {
805 "File '%s' contains struct with name that can't be added \"%s\"\n",
828 "File '%s' contains struct with name that can't be added \"%s\"\n",
866 int firststruct,
int structtype,
int type,
int len,
const char *name,
const char *detail)
871 "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
880 "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
889 "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
901 bool dna_error =
false;
904 fprintf(file_verify,
"/* Verify struct sizes and member offsets are as expected by DNA. */\n");
905 fprintf(file_verify,
"#include \"BLI_assert.h\"\n\n");
907 fprintf(file_verify,
"#define DNA_DEPRECATED_ALLOW\n");
910 fprintf(file_verify,
"#define assert_line_ assert_line_DNA_\n");
912 fprintf(file_verify,
"#include \"%s%s\"\n", base_directory,
includefiles[i]);
914 fprintf(file_verify,
"#undef assert_line_\n");
915 fprintf(file_verify,
"\n");
920 const int lastunknown = unknown;
925 const short *structpoin =
structs[
a];
926 const int structtype = structpoin[0];
932 const short *sp = structpoin + 2;
937 int max_align_32 = 0;
938 int max_align_64 = 0;
941 for (
int b = 0; b < structpoin[1]; b++, sp += 2) {
943 const char *cp =
names[sp[1]];
944 int namelen = (int)strlen(cp);
950 char name_static[1024];
954 const char *str_pair[2] = {
types[structtype], name_static};
958 "BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset "
961 name_alias ? name_alias : name_static,
966 if (cp[0] ==
'*' || cp[1] ==
'*') {
969 if (cp[namelen - 1] ==
']') {
975 "Zero array size found or could not parse %s: '%.*s'\n",
983 if (
sizeof(
void *) == 4) {
984 if (size_native % 4) {
986 "Align pointer error in struct (size_native 4): %s %s\n",
993 if (size_native % 8) {
995 "Align pointer error in struct (size_native 8): %s %s\n",
1004 "Align pointer error in struct (size_64 8): %s %s\n",
1010 size_native +=
sizeof(
void *) *
mul;
1013 max_align_32 =
MAX2(max_align_32, 4);
1014 max_align_64 =
MAX2(max_align_64, 8);
1016 else if (cp[0] ==
'[') {
1020 "Parse error in struct, invalid member name: %s %s\n",
1028 if (cp[namelen - 1] ==
']') {
1034 "Zero array size found or could not parse %s: '%.*s'\n",
1042 if (
type >= firststruct) {
1043 if (
sizeof(
void *) == 8 && (size_native % 8)) {
1044 fprintf(stderr,
"Align struct error: %s %s\n",
types[structtype], cp);
1071 if (size_native == 0) {
1090 if (size_32 % max_align_32) {
1094 if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
1096 "Sizeerror in 32 bit struct: %s (add paddding pointer)\n",
1101 "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
1103 max_align_32 - (size_32 % max_align_32));
1108 if (size_64 % max_align_64) {
1110 "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
1112 max_align_64 - (size_64 % max_align_64));
1116 if (size_native % 4 && !
ELEM(size_native, 1, 2)) {
1118 "Sizeerror 4 in struct: %s (add %d bytes)\n",
1125 fprintf(file_verify,
1126 "BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n",
1133 if (unknown == lastunknown) {
1139 fprintf(stderr,
"ERROR: still %d structs unknown\n", unknown);
1142 fprintf(stderr,
"*** Known structs :\n");
1145 const short *structpoin =
structs[
a];
1146 const int structtype = structpoin[0];
1150 fprintf(stderr,
" %s\n",
types[structtype]);
1155 fprintf(stderr,
"*** Unknown structs :\n");
1158 const short *structpoin =
structs[
a];
1159 const int structtype = structpoin[0];
1163 fprintf(stderr,
" %s\n",
types[structtype]);
1173 #define MAX_DNA_LINE_LENGTH 20
1177 static int linelength = 0;
1178 const char *
data = (
const char *)pntr;
1180 for (
int i = 0; i <
size; i++) {
1184 fprintf(
file,
"\n");
1193 printf(
"\n\n*** All detected structs:\n");
1200 const short *structpoin =
structs[
a];
1201 const int structtype = structpoin[0];
1206 printf(
"*** End of list\n");
1216 printf(
"Running makesdna at debug level %d\n",
debugSDNA);
1276 int header_count = 0;
1289 DEBUG_PRINTF(0,
"\tFinished scanning %d headers.\n", header_count);
1304 printf(
" %s\n",
names[
a]);
1310 printf(
" %s %d\n",
types[
a], *sp);
1320 for (b = 0; b < num_types; b++, sp += 2) {
1321 printf(
" %s %s allign32:%d, allign64:%d\n",
1338 const char nil_bytes[4] = {0};
1348 for (
int nr = 0; nr <
names_len; nr++) {
1349 int name_size = strlen(
names[nr]) + 1;
1353 int len_align = (
len + 3) & ~3;
1354 if (
len != len_align) {
1364 for (
int nr = 0; nr <
types_len; nr++) {
1365 int type_size = strlen(
types[nr]) + 1;
1369 len_align = (
len + 3) & ~3;
1370 if (
len != len_align) {
1390 sp += 2 + 2 * (sp[1]);
1400 fprintf(file_offsets,
"#pragma once\n");
1401 fprintf(file_offsets,
"#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1402 fprintf(file_offsets,
"enum {\n");
1404 const short *structpoin =
structs[i];
1405 const int structtype = structpoin[0];
1406 fprintf(file_offsets,
1407 "\t_SDNA_TYPE_%s = %d,\n",
1411 fprintf(file_offsets,
"\tSDNA_TYPE_MAX = %d,\n",
structs_len);
1412 fprintf(file_offsets,
"};\n\n");
1419 for (
int struct_nr = 0; struct_nr <
structs_len; struct_nr++) {
1420 const short *sp =
structs[struct_nr];
1421 const char *struct_name =
types[sp[0]];
1422 const int len = sp[1];
1424 for (
int a = 0;
a <
len;
a++, sp += 2) {
1425 char *name =
names[sp[1]];
1429 "Error: duplicate name found '%s.%s', "
1430 "likely cause is 'dna_rename_defs.h'\n",
1473 FILE *fp = fopen(
file,
"w");
1475 "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1482 # define BASE_HEADER "../"
1487 int return_status = 0;
1489 if (!
ELEM(argc, 4, 5)) {
1490 printf(
"Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1494 FILE *file_dna = fopen(argv[1],
"w");
1495 FILE *file_dna_offsets = fopen(argv[2],
"w");
1496 FILE *file_dna_verify = fopen(argv[3],
"w");
1498 printf(
"Unable to open file: %s\n", argv[1]);
1501 else if (!file_dna_offsets) {
1502 printf(
"Unable to open file: %s\n", argv[2]);
1505 else if (!file_dna_verify) {
1506 printf(
"Unable to open file: %s\n", argv[3]);
1510 const char *base_directory;
1513 base_directory = argv[4];
1519 fprintf(file_dna,
"extern const unsigned char DNAstr[];\n");
1520 fprintf(file_dna,
"const unsigned char DNAstr[] = {\n");
1521 if (
make_structDNA(base_directory, file_dna, file_dna_offsets, file_dna_verify)) {
1529 fprintf(file_dna,
"};\n");
1530 fprintf(file_dna,
"extern const int DNAlen;\n");
1531 fprintf(file_dna,
"const int DNAlen = sizeof(DNAstr);\n");
1538 if (file_dna_offsets) {
1539 fclose(file_dna_offsets);
1541 if (file_dna_verify) {
1542 fclose(file_dna_verify);
1546 return return_status;
1557 # pragma GCC diagnostic error "-Wpadded"
1572 # pragma GCC poison long
1665 #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1666 #define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
1668 #undef DNA_STRUCT_RENAME
1669 #undef DNA_STRUCT_RENAME_ELEM
GSet * BLI_gset_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
bool BLI_gset_add(GSet *gs, void *key)
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
#define BLI_MEMARENA_STD_BUFSIZE
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
struct MemArena * BLI_memarena_new(const size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2) ATTR_MALLOC
#define UNUSED_FUNCTION(x)
ID and Library types, which are fundamental for sdna.
Object groups, one object can be in many groups at once.
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static void mul(btAlignedObjectArray< T > &items, const Q &value)
uint DNA_elem_id_strip(char *elem)
char * DNA_elem_id_rename(struct MemArena *mem_arena, const char *elem_src, const int elem_src_len, const char *elem_dst, const int elem_dst_len, const char *elem_src_full, const int elem_src_full_len, const uint elem_src_full_offset_len)
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_struct_map, GHash **r_elem_map)
uint DNA_elem_id_offset_start(const char *elem_full)
uint DNA_elem_id_strip_copy(char *elem_dst, const char *elem_src)
int DNA_elem_array_size(const char *str)
@ DNA_RENAME_ALIAS_FROM_STATIC
@ DNA_RENAME_STATIC_FROM_ALIAS
static int additional_slen_offset
static const char * version_struct_alias_from_static(const char *str)
static void * read_file_data(const char *filename, int *r_len)
#define MAX_DNA_LINE_LENGTH
static short * types_size_native
static short * types_align_32
static int preprocess_include(char *maindata, const int maindata_len)
static int convert_include(const char *filename)
static short * types_size_32
int main(int argc, char **argv)
static struct @1095 g_version_data
static const char * version_elem_static_from_alias(const int strct, const char *elem_alias_full)
static short * structdata
static int make_structDNA(const char *base_directory, FILE *file, FILE *file_offsets, FILE *file_verify)
static short * types_size_64
static short * add_struct(int namecode)
void BLI_system_backtrace(FILE *fp)
static int add_name(const char *str)
void print_struct_sizes(void)
GHash * struct_map_static_from_alias
static void dna_write(FILE *file, const void *pntr, const int size)
static int add_type(const char *str, int size)
#define DEBUG_PRINTF(debug_level,...)
GHash * elem_map_static_from_alias
static const char * version_struct_static_from_alias(const char *str)
GHash * elem_map_alias_from_static
GHash * struct_map_alias_from_static
static short * types_align_64
static void UNUSED_FUNCTION() dna_rename_defs_ensure(void)
static bool check_field_alignment(int firststruct, int structtype, int type, int len, const char *name, const char *detail)
#define SDNA_MAX_FILENAME_LENGTH
static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char *base_directory)
static const char * includefiles[]
static MemArena * mem_arena
static bool is_name_legal(const char *name)
static void make_bad_file(const char *file, int line)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)