26 #define DNA_DEPRECATED_ALLOW
44 #define SDNA_MAX_FILENAME_LENGTH 255
49 #include "dna_includes_as_strings.h"
105 #define DEBUG_PRINTF(debug_level, ...) \
107 if (debugSDNA > debug_level) { \
108 printf(__VA_ARGS__); \
183 const char *identifier,
184 const size_t identifier_len)
186 if (strncmp(
str, identifier, identifier_len) == 0) {
188 if (isdigit(
str[identifier_len]) || isalpha(
str[identifier_len]) ||
189 (
str[identifier_len] ==
'_')) {
199 const size_t identifier_len = strlen(identifier);
205 const size_t identifier_len = strlen(identifier);
207 (*str_ptr) += identifier_len;
216 if (str_test !=
NULL) {
225 if (str_test !=
NULL) {
233 const uint elem_alias_full_len = strlen(elem_alias_full);
234 char *elem_alias = alloca(elem_alias_full_len + 1);
236 const char *str_pair[2] = {
types[strct], elem_alias};
238 if (elem_static !=
NULL) {
248 return elem_alias_full;
257 const int name_size = strlen(name) + 1;
258 char *name_strip = alloca(name_size);
261 const char prefix[] = {
'p',
'a',
'd'};
263 if (name[0] ==
'_') {
264 if (strncmp(&name_strip[1], prefix,
sizeof(prefix)) != 0) {
266 stderr,
"Error: only '_pad' variables can start with an underscore, found '%s'\n", name);
270 else if (strncmp(name_strip, prefix,
sizeof(prefix)) == 0) {
271 int i =
sizeof(prefix);
272 if (name_strip[i] >=
'a' && name_strip[i] <=
'z') {
276 bool has_only_digit_or_none =
true;
277 for (; name_strip[i]; i++) {
278 const char c = name_strip[i];
279 if (!((
c >=
'0' &&
c <=
'9') ||
c ==
'_')) {
280 has_only_digit_or_none =
false;
284 if (has_only_digit_or_none) {
287 stderr,
"Error: padding variables must be formatted '_pad[number]', found '%s'\n", name);
300 if (strchr(
str,
'*')) {
309 for (
int index = 0; index <
types_len; index++) {
323 const int str_size = strlen(
str) + 1;
325 memcpy(cp,
str, str_size);
333 printf(
"too many types\n");
358 if (
str[0] ==
'(' &&
str[1] ==
'*') {
363 int isfuncptr = (strchr(
str + 1,
'(')) !=
NULL;
365 DEBUG_PRINTF(3,
"\t\t\t\t*** Function pointer or multidim array pointer found\n");
369 while (
str[i] !=
')') {
382 while ((
str[j] != 0) && (
str[j] !=
')')) {
388 "special after offset%d\n",
396 DEBUG_PRINTF(3,
"offsetting for multidim array pointer\n");
399 printf(
"Error during tokening multidim array pointer\n");
402 else if (
str[j] == 0) {
406 while (
str[j] !=
')') {
413 else if (
str[j] ==
')') {
418 printf(
"Error during tokening function pointer argument list\n");
434 if ((strncmp(buf,
"(*headdraw", 10) == 0) || (strncmp(buf,
"(*windraw", 9) == 0)) {
451 DEBUG_PRINTF(3,
"\t\t\t\t\tProposing fp name %s\n", buf);
472 const int name_size = strlen(name) + 1;
474 memcpy(cp, name, name_size);
478 printf(
"too many names\n");
493 const int len = sp[1];
501 printf(
"too many structs\n");
513 char *temp =
MEM_mallocN(maindata_len + 1,
"preprocess_include");
514 temp[maindata_len] =
' ';
516 memcpy(temp, maindata, maindata_len);
521 int a = maindata_len;
524 if (cp[0] ==
'/' && cp[1] ==
'/') {
527 else if (*cp ==
'\n') {
530 if (comment || *cp < 32 || *cp > 128) {
542 bool skip_until_closing_brace =
false;
545 if (cp[0] ==
'/' && cp[1] ==
'*') {
549 if (cp[0] ==
'*' && cp[1] ==
'/') {
558 else if (cp[0] ==
' ' && cp[1] ==
' ') {
561 else if (cp[-1] ==
'*' && cp[0] ==
' ') {
573 skip_until_closing_brace =
true;
575 else if (skip_until_closing_brace) {
577 skip_until_closing_brace =
false;
595 FILE *fp = fopen(filepath,
"rb");
597 FILE *fp = fopen(filepath,
"r");
606 fseek(fp, 0
L, SEEK_END);
608 fseek(fp, 0
L, SEEK_SET);
622 if (fread(
data, *r_len, 1, fp) != 1) {
642 if (maindata_len == -1) {
643 fprintf(stderr,
"Can't read file %s\n", filepath);
648 char *mainend = maindata + maindata_len - 1;
652 bool skip_struct =
false;
653 while (
count < maindata_len) {
656 if (md[0] ==
'#' && md[1] ==
' ' && md[2] ==
'#') {
681 fprintf(stderr,
"File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
686 short *sp = structpoin + 2;
692 while (*md1 !=
'}') {
697 if (
ELEM(*md1,
',',
' ')) {
705 while (*md1 !=
'}') {
712 const char *md1_prev = md1;
719 "File '%s' contains non white space character "
720 "\"%c\" after identifier \"%s\"\n",
734 stderr,
"File '%s' contains struct we can't parse \"%s\"\n", filepath, md1);
743 while (*md1 !=
';') {
752 int slen = (int)strlen(md1);
753 if (md1[slen - 1] ==
';') {
759 "File '%s' contains struct with name that can't be added \"%s\"\n",
782 "File '%s' contains struct with name that can't be added \"%s\"\n",
820 int firststruct,
int structtype,
int type,
int len,
const char *name,
const char *detail)
825 "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
834 "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
843 "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
855 bool dna_error =
false;
858 fprintf(file_verify,
"/* Verify struct sizes and member offsets are as expected by DNA. */\n");
859 fprintf(file_verify,
"#include \"BLI_assert.h\"\n\n");
861 fprintf(file_verify,
"#define DNA_DEPRECATED_ALLOW\n");
864 fprintf(file_verify,
"#define assert_line_ assert_line_DNA_\n");
866 fprintf(file_verify,
"#include \"%s%s\"\n", base_directory,
includefiles[i]);
868 fprintf(file_verify,
"#undef assert_line_\n");
869 fprintf(file_verify,
"\n");
874 const int lastunknown = unknown;
879 const short *structpoin =
structs[
a];
880 const int structtype = structpoin[0];
886 const short *sp = structpoin + 2;
891 int max_align_32 = 0;
892 int max_align_64 = 0;
895 for (
int b = 0;
b < structpoin[1];
b++, sp += 2) {
897 const char *cp =
names[sp[1]];
898 int namelen = (int)strlen(cp);
904 char name_static[1024];
908 const char *str_pair[2] = {
types[structtype], name_static};
912 "BLI_STATIC_ASSERT(offsetof(struct %s, %s) == %d, \"DNA member offset "
915 name_alias ? name_alias : name_static,
920 if (cp[0] ==
'*' || cp[1] ==
'*') {
923 if (cp[namelen - 1] ==
']') {
929 "Zero array size found or could not parse %s: '%.*s'\n",
937 if (
sizeof(
void *) == 4) {
938 if (size_native % 4) {
940 "Align pointer error in struct (size_native 4): %s %s\n",
947 if (size_native % 8) {
949 "Align pointer error in struct (size_native 8): %s %s\n",
958 "Align pointer error in struct (size_64 8): %s %s\n",
964 size_native +=
sizeof(
void *) *
mul;
967 max_align_32 =
MAX2(max_align_32, 4);
968 max_align_64 =
MAX2(max_align_64, 8);
970 else if (cp[0] ==
'[') {
974 "Parse error in struct, invalid member name: %s %s\n",
982 if (cp[namelen - 1] ==
']') {
988 "Zero array size found or could not parse %s: '%.*s'\n",
996 if (
type >= firststruct) {
997 if (
sizeof(
void *) == 8 && (size_native % 8)) {
998 fprintf(stderr,
"Align struct error: %s %s\n",
types[structtype], cp);
1025 if (size_native == 0) {
1044 if (size_32 % max_align_32) {
1048 if ((size_64 % max_align_64 == 0) && (size_32 % max_align_32 == 4)) {
1050 "Sizeerror in 32 bit struct: %s (add padding pointer)\n",
1055 "Sizeerror in 32 bit struct: %s (add %d bytes)\n",
1057 max_align_32 - (size_32 % max_align_32));
1062 if (size_64 % max_align_64) {
1064 "Sizeerror in 64 bit struct: %s (add %d bytes)\n",
1066 max_align_64 - (size_64 % max_align_64));
1070 if (size_native % 4 && !
ELEM(size_native, 1, 2)) {
1072 "Sizeerror 4 in struct: %s (add %d bytes)\n",
1079 fprintf(file_verify,
1080 "BLI_STATIC_ASSERT(sizeof(struct %s) == %d, \"DNA struct size verify\");\n\n",
1087 if (unknown == lastunknown) {
1093 fprintf(stderr,
"ERROR: still %d structs unknown\n", unknown);
1096 fprintf(stderr,
"*** Known structs :\n");
1099 const short *structpoin =
structs[
a];
1100 const int structtype = structpoin[0];
1104 fprintf(stderr,
" %s\n",
types[structtype]);
1109 fprintf(stderr,
"*** Unknown structs :\n");
1112 const short *structpoin =
structs[
a];
1113 const int structtype = structpoin[0];
1117 fprintf(stderr,
" %s\n",
types[structtype]);
1127 #define MAX_DNA_LINE_LENGTH 20
1131 static int linelength = 0;
1132 const char *
data = (
const char *)pntr;
1134 for (
int i = 0; i <
size; i++) {
1138 fprintf(
file,
"\n");
1147 printf(
"\n\n*** All detected structs:\n");
1154 const short *structpoin =
structs[
a];
1155 const int structtype = structpoin[0];
1160 printf(
"*** End of list\n");
1170 printf(
"Running makesdna at debug level %d\n",
debugSDNA);
1230 int header_count = 0;
1243 DEBUG_PRINTF(0,
"\tFinished scanning %d headers.\n", header_count);
1258 printf(
" %s\n",
names[
a]);
1264 printf(
" %s %d\n",
types[
a], *sp);
1274 for (
b = 0;
b < num_types;
b++, sp += 2) {
1275 printf(
" %s %s allign32:%d, allign64:%d\n",
1292 const char nil_bytes[4] = {0};
1302 for (
int nr = 0; nr <
names_len; nr++) {
1303 int name_size = strlen(
names[nr]) + 1;
1307 int len_align = (
len + 3) & ~3;
1308 if (
len != len_align) {
1318 for (
int nr = 0; nr <
types_len; nr++) {
1319 int type_size = strlen(
types[nr]) + 1;
1323 len_align = (
len + 3) & ~3;
1324 if (
len != len_align) {
1344 sp += 2 + 2 * (sp[1]);
1354 fprintf(file_offsets,
"#pragma once\n");
1355 fprintf(file_offsets,
"#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1356 fprintf(file_offsets,
"enum {\n");
1358 const short *structpoin =
structs[i];
1359 const int structtype = structpoin[0];
1360 fprintf(file_offsets,
1361 "\t_SDNA_TYPE_%s = %d,\n",
1365 fprintf(file_offsets,
"\tSDNA_TYPE_MAX = %d,\n",
structs_len);
1366 fprintf(file_offsets,
"};\n\n");
1373 for (
int struct_nr = 0; struct_nr <
structs_len; struct_nr++) {
1374 const short *sp =
structs[struct_nr];
1375 const char *struct_name =
types[sp[0]];
1376 const int len = sp[1];
1378 for (
int a = 0;
a <
len;
a++, sp += 2) {
1379 char *name =
names[sp[1]];
1383 "Error: duplicate name found '%s.%s', "
1384 "likely cause is 'dna_rename_defs.h'\n",
1427 FILE *fp = fopen(
file,
"w");
1429 "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1436 # define BASE_HEADER "../"
1441 int return_status = 0;
1443 if (!
ELEM(argc, 4, 5)) {
1444 printf(
"Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1448 FILE *file_dna = fopen(argv[1],
"w");
1449 FILE *file_dna_offsets = fopen(argv[2],
"w");
1450 FILE *file_dna_verify = fopen(argv[3],
"w");
1452 printf(
"Unable to open file: %s\n", argv[1]);
1455 else if (!file_dna_offsets) {
1456 printf(
"Unable to open file: %s\n", argv[2]);
1459 else if (!file_dna_verify) {
1460 printf(
"Unable to open file: %s\n", argv[3]);
1464 const char *base_directory;
1467 base_directory = argv[4];
1477 # define FORCE_ALIGN_4 " __attribute__((aligned(4))) "
1479 # define FORCE_ALIGN_4 " "
1481 fprintf(file_dna,
"extern const unsigned char DNAstr[];\n");
1482 fprintf(file_dna,
"const unsigned char" FORCE_ALIGN_4 "DNAstr[] = {\n");
1483 #undef FORCE_ALIGN_4
1485 if (
make_structDNA(base_directory, file_dna, file_dna_offsets, file_dna_verify)) {
1493 fprintf(file_dna,
"};\n");
1494 fprintf(file_dna,
"extern const int DNAlen;\n");
1495 fprintf(file_dna,
"const int DNAlen = sizeof(DNAstr);\n");
1502 if (file_dna_offsets) {
1503 fclose(file_dna_offsets);
1505 if (file_dna_verify) {
1506 fclose(file_dna_verify);
1510 return return_status;
1521 # pragma GCC diagnostic error "-Wpadded"
1536 # pragma GCC poison long
1541 #include "dna_includes_all.h"
1557 #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1558 #define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
1560 #undef DNA_STRUCT_RENAME
1561 #undef DNA_STRUCT_RENAME_ELEM
GSet * BLI_gset_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
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_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#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)
#define UNUSED_FUNCTION(x)
_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)
SyclQueue void void size_t num_bytes void
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 bool match_identifier(const char *str, const char *identifier)
#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 short * types_size_32
int main(int argc, char **argv)
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 bool match_identifier_and_advance(char **str_ptr, const char *identifier)
static short * add_struct(int namecode)
static void * read_file_data(const char *filepath, int *r_len)
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)
static int convert_include(const char *filepath)
GHash * elem_map_alias_from_static
GHash * struct_map_alias_from_static
static short * types_align_64
static bool match_identifier_with_len(const char *str, const char *identifier, const size_t identifier_len)
static void UNUSED_FUNCTION() dna_rename_defs_ensure(void)
static struct @1143 g_version_data
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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)