doxygen: add newline after \file
[blender.git] / source / blender / makesdna / intern / makesdna.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup DNA
22  *
23  * \brief Struct muncher for making SDNA.
24  *
25  * \section aboutmakesdnac About makesdna tool
26  * Originally by Ton, some mods by Frank, and some cleaning and
27  * extension by Nzc.
28  *
29  * Makesdna creates a .c file with a long string of numbers that
30  * encode the Blender file format. It is fast, because it is basically
31  * a binary dump. There are some details to mind when reconstructing
32  * the file (endianness and byte-alignment).
33  *
34  * This little program scans all structs that need to be serialized,
35  * and determined the names and types of all members. It calculates
36  * how much memory (on disk or in ram) is needed to store that struct,
37  * and the offsets for reaching a particular one.
38  *
39  * There is a facility to get verbose output from sdna. Search for
40  * \ref debugSDNA. This int can be set to 0 (no output) to some int. Higher
41  * numbers give more output.
42  */
43
44 #include <string.h>
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <assert.h>
48
49 #include "MEM_guardedalloc.h"
50
51 #include "BLI_utildefines.h"
52 #include "BLI_alloca.h"
53 #include "BLI_ghash.h"
54 #include "BLI_memarena.h"
55 #include "BLI_sys_types.h"  /* for intptr_t support */
56
57 #include "dna_utils.h"
58
59 #define SDNA_MAX_FILENAME_LENGTH 255
60
61 /* Included the path relative from /source/blender/ here, so we can move     */
62 /* headers around with more freedom.                                         */
63 static const char *includefiles[] = {
64
65         /* if you add files here, please add them at the end
66          * of makesdna.c (this file) as well */
67         "DNA_listBase.h",
68         "DNA_vec_types.h",
69         "DNA_ID.h",
70         "DNA_ipo_types.h",
71         "DNA_key_types.h",
72         "DNA_text_types.h",
73         "DNA_packedFile_types.h",
74         "DNA_gpu_types.h",
75         "DNA_camera_types.h",
76         "DNA_image_types.h",
77         "DNA_texture_types.h",
78         "DNA_lamp_types.h",
79         "DNA_material_types.h",
80         "DNA_vfont_types.h",
81         "DNA_meta_types.h",
82         "DNA_curve_types.h",
83         "DNA_mesh_types.h",
84         "DNA_meshdata_types.h",
85         "DNA_modifier_types.h",
86         "DNA_lattice_types.h",
87         "DNA_object_types.h",
88         "DNA_object_force_types.h",
89         "DNA_object_fluidsim_types.h",
90         "DNA_world_types.h",
91         "DNA_scene_types.h",
92         "DNA_view3d_types.h",
93         "DNA_view2d_types.h",
94         "DNA_space_types.h",
95         "DNA_userdef_types.h",
96         "DNA_screen_types.h",
97         "DNA_sdna_types.h",
98         "DNA_fileglobal_types.h",
99         "DNA_sequence_types.h",
100         "DNA_effect_types.h",
101         "DNA_outliner_types.h",
102         "DNA_sound_types.h",
103         "DNA_collection_types.h",
104         "DNA_armature_types.h",
105         "DNA_action_types.h",
106         "DNA_constraint_types.h",
107         "DNA_nla_types.h",
108         "DNA_node_types.h",
109         "DNA_color_types.h",
110         "DNA_brush_types.h",
111         "DNA_customdata_types.h",
112         "DNA_particle_types.h",
113         "DNA_cloth_types.h",
114         "DNA_gpencil_types.h",
115         "DNA_gpencil_modifier_types.h",
116         "DNA_shader_fx_types.h",
117         "DNA_windowmanager_types.h",
118         "DNA_anim_types.h",
119         "DNA_boid_types.h",
120         "DNA_smoke_types.h",
121         "DNA_speaker_types.h",
122         "DNA_movieclip_types.h",
123         "DNA_tracking_types.h",
124         "DNA_dynamicpaint_types.h",
125         "DNA_mask_types.h",
126         "DNA_rigidbody_types.h",
127         "DNA_freestyle_types.h",
128         "DNA_linestyle_types.h",
129         "DNA_cachefile_types.h",
130         "DNA_layer_types.h",
131         "DNA_workspace_types.h",
132         "DNA_lightprobe_types.h",
133
134         /* see comment above before editing! */
135
136         /* empty string to indicate end of includefiles */
137         "",
138 };
139
140 /* -------------------------------------------------------------------- */
141 /** \name Variables
142  * \{ */
143
144 MemArena *mem_arena = NULL;
145
146 static int maxdata = 500000, maxnr = 50000;
147 static int nr_names = 0;
148 static int nr_types = 0;
149 static int nr_structs = 0;
150 /** at address names[a] is string a */
151 static char **names;
152 /** at address types[a] is string a */
153 static char **types;
154 /** at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */
155 static short *typelens_native;
156 /** contains sizes as they are calculated on 32 bit systems */
157 static short *typelens_32;
158 /** contains sizes as they are calculated on 64 bit systems */
159 static short *typelens_64;
160 /** at sp = structs[a] is the first address of a struct definition
161  * sp[0] is type number
162  * sp[1] is amount of elements
163  * sp[2] sp[3] is typenr,  namenr (etc) */
164 static short **structs, *structdata;
165
166 /** Versioning data */
167 static struct {
168         GHash *struct_map_alias_from_static;
169         GHash *struct_map_static_from_alias;
170         GHash *elem_map_static_from_alias;
171 } g_version_data = {NULL};
172
173 /**
174  * Variable to control debug output of makesdna.
175  * debugSDNA:
176  * - 0 = no output, except errors
177  * - 1 = detail actions
178  * - 2 = full trace, tell which names and types were found
179  * - 4 = full trace, plus all gritty details
180  */
181 static int debugSDNA = 0;
182 static int additional_slen_offset;
183
184 #define DEBUG_PRINTF(debug_level, ...) \
185         { if (debugSDNA > debug_level) { printf(__VA_ARGS__); } } ((void)0)
186
187
188 /* stub for BLI_abort() */
189 #ifndef NDEBUG
190 void BLI_system_backtrace(FILE *fp)
191 {
192        (void)fp;
193 }
194 #endif
195
196 /** \} */
197
198 /* -------------------------------------------------------------------- */
199 /** \name Function Declarations
200  * \{ */
201
202 /**
203  * Ensure type \c str to is in the #types array.
204  * \param str: Struct name without any qualifiers.
205  * \param len: The struct size in bytes.
206  * \return Index in the #types array.
207  */
208 static int add_type(const char *str, int len);
209
210 /**
211  * Ensure \c str is int the #names array.
212  * \param str: Struct member name which may include pointer prefix & array size.
213  * \return Index in the #names array.
214  */
215 static int add_name(const char *str);
216
217 /**
218  * Search whether this structure type was already found, and if not,
219  * add it.
220  */
221 static short *add_struct(int namecode);
222
223 /**
224  * Remove comments from this buffer. Assumes that the buffer refers to
225  * ascii-code text.
226  */
227 static int preprocess_include(char *maindata, int len);
228
229 /**
230  * Scan this file for serializable types.
231  */
232 static int convert_include(const char *filename);
233
234 /**
235  * Determine how many bytes are needed for each struct.
236  */
237 static int calculate_structlens(int);
238
239 /**
240  * Construct the DNA.c file
241  */
242 static void dna_write(FILE *file, const void *pntr, const int size);
243
244 /**
245  * Report all structures found so far, and print their lengths.
246  */
247 void printStructLengths(void);
248
249 /** \} */
250
251 /* -------------------------------------------------------------------- */
252 /** \name Implementation
253  *
254  * Make DNA string (write to file).
255  * \{ */
256
257
258 static const char *version_struct_static_from_alias(const char *str)
259 {
260         const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_static_from_alias, str);
261         if (str_test != NULL) {
262                 return str_test;
263         }
264         return str;
265 }
266
267 static const char *version_struct_alias_from_static(const char *str)
268 {
269         const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_alias_from_static, str);
270         if (str_test != NULL) {
271                 return str_test;
272         }
273         return str;
274 }
275
276 static const char *version_elem_static_from_alias(
277         const int strct, const char *elem_alias_full)
278 {
279         const uint elem_alias_full_len = strlen(elem_alias_full);
280         char *elem_alias = alloca(elem_alias_full_len + 1);
281         const int elem_alias_len = DNA_elem_id_strip_copy(elem_alias, elem_alias_full);
282         const char *str_pair[2] = {types[strct], elem_alias};
283         const char *elem_static = BLI_ghash_lookup(g_version_data.elem_map_static_from_alias, str_pair);
284         if (elem_static != NULL) {
285                 return DNA_elem_id_rename(
286                         mem_arena,
287                         elem_alias, elem_alias_len,
288                         elem_static, strlen(elem_static),
289                         elem_alias_full, elem_alias_full_len,
290                         DNA_elem_id_offset_start(elem_alias_full));
291         }
292         return elem_alias_full;
293 }
294
295 static int add_type(const char *str, int len)
296 {
297         int nr;
298         char *cp;
299
300         /* first do validity check */
301         if (str[0] == 0) {
302                 return -1;
303         }
304         else if (strchr(str, '*')) {
305                 /* note: this is valid C syntax but we can't parse, complain!
306                  * 'struct SomeStruct* somevar;' <-- correct but we cant handle right now. */
307                 return -1;
308         }
309
310         str = version_struct_static_from_alias(str);
311
312         /* search through type array */
313         for (nr = 0; nr < nr_types; nr++) {
314                 if (strcmp(str, types[nr]) == 0) {
315                         if (len) {
316                                 typelens_native[nr] = len;
317                                 typelens_32[nr] = len;
318                                 typelens_64[nr] = len;
319                         }
320                         return nr;
321                 }
322         }
323
324         /* append new type */
325         const int str_size = strlen(str) + 1;
326         cp = BLI_memarena_alloc(mem_arena, str_size);
327         memcpy(cp, str, str_size);
328         types[nr_types] = cp;
329         typelens_native[nr_types] = len;
330         typelens_32[nr_types] = len;
331         typelens_64[nr_types] = len;
332
333         if (nr_types >= maxnr) {
334                 printf("too many types\n");
335                 return nr_types - 1;
336         }
337         nr_types++;
338
339         return nr_types - 1;
340 }
341
342
343 /**
344  *
345  * Because of the weird way of tokenizing, we have to 'cast' function
346  * pointers to ... (*f)(), whatever the original signature. In fact,
347  * we add name and type at the same time... There are two special
348  * cases, unfortunately. These are explicitly checked.
349  *
350  * */
351 static int add_name(const char *str)
352 {
353         int nr, i, j, k;
354         char *cp;
355         char buf[255]; /* stupid limit, change it :) */
356         const char *name;
357
358         additional_slen_offset = 0;
359
360         if (str[0] == 0 /*  || (str[1] == 0) */) return -1;
361
362         if (str[0] == '(' && str[1] == '*') {
363                 /* we handle function pointer and special array cases here, e.g.
364                  * void (*function)(...) and float (*array)[..]. the array case
365                  * name is still converted to (array *)() though because it is that
366                  * way in old dna too, and works correct with elementsize() */
367                 int isfuncptr = (strchr(str + 1, '(')) != NULL;
368
369                 DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
370                 /* functionpointer: transform the type (sometimes) */
371                 i = 0;
372
373                 while (str[i] != ')') {
374                         buf[i] = str[i];
375                         i++;
376                 }
377
378                 /* Another number we need is the extra slen offset. This extra
379                  * offset is the overshoot after a space. If there is no
380                  * space, no overshoot should be calculated. */
381                 j = i; /* j at first closing brace */
382
383                 DEBUG_PRINTF(3, "first brace after offset %d\n", i);
384
385                 j++; /* j beyond closing brace ? */
386                 while ((str[j] != 0) && (str[j] != ')')) {
387                         DEBUG_PRINTF(3, "seen %c (%d)\n", str[j], str[j]);
388                         j++;
389                 }
390                 DEBUG_PRINTF(3, "seen %c (%d)\n" "special after offset%d\n", str[j], str[j], j);
391
392                 if (!isfuncptr) {
393                         /* multidimensional array pointer case */
394                         if (str[j] == 0) {
395                                 DEBUG_PRINTF(3, "offsetting for multidim array pointer\n");
396                         }
397                         else
398                                 printf("Error during tokening multidim array pointer\n");
399                 }
400                 else if (str[j] == 0) {
401                         DEBUG_PRINTF(3, "offsetting for space\n");
402                         /* get additional offset */
403                         k = 0;
404                         while (str[j] != ')') {
405                                 j++;
406                                 k++;
407                         }
408                         DEBUG_PRINTF(3, "extra offset %d\n", k);
409                         additional_slen_offset = k;
410                 }
411                 else if (str[j] == ')') {
412                         DEBUG_PRINTF(3, "offsetting for brace\n");
413                         ; /* don't get extra offset */
414                 }
415                 else {
416                         printf("Error during tokening function pointer argument list\n");
417                 }
418
419                 /*
420                  * Put )(void) at the end? Maybe )(). Should check this with
421                  * old sdna. Actually, sometimes )(), sometimes )(void...)
422                  * Alas.. such is the nature of braindamage :(
423                  *
424                  * Sorted it out: always do )(), except for headdraw and
425                  * windraw, part of ScrArea. This is important, because some
426                  * linkers will treat different fp's differently when called
427                  * !!! This has to do with interference in byte-alignment and
428                  * the way args are pushed on the stack.
429                  *
430                  * */
431                 buf[i] = 0;
432                 DEBUG_PRINTF(3, "Name before chomping: %s\n", buf);
433                 if ((strncmp(buf, "(*headdraw", 10) == 0) ||
434                     (strncmp(buf, "(*windraw", 9) == 0) )
435                 {
436                         buf[i] = ')';
437                         buf[i + 1] = '(';
438                         buf[i + 2] = 'v';
439                         buf[i + 3] = 'o';
440                         buf[i + 4] = 'i';
441                         buf[i + 5] = 'd';
442                         buf[i + 6] = ')';
443                         buf[i + 7] = 0;
444                 }
445                 else {
446                         buf[i] = ')';
447                         buf[i + 1] = '(';
448                         buf[i + 2] = ')';
449                         buf[i + 3] = 0;
450                 }
451                 /* now precede with buf*/
452                 DEBUG_PRINTF(3, "\t\t\t\t\tProposing fp name %s\n", buf);
453                 name = buf;
454         }
455         else {
456                 /* normal field: old code */
457                 name = str;
458         }
459
460         /* search name array */
461         for (nr = 0; nr < nr_names; nr++) {
462                 if (strcmp(name, names[nr]) == 0) {
463                         return nr;
464                 }
465         }
466
467         /* append new type */
468         const int name_size = strlen(name) + 1;
469         cp = BLI_memarena_alloc(mem_arena, name_size);
470         memcpy(cp, name, name_size);
471         names[nr_names] = cp;
472
473         if (nr_names >= maxnr) {
474                 printf("too many names\n");
475                 return nr_names - 1;
476         }
477         nr_names++;
478
479         return nr_names - 1;
480 }
481
482 static short *add_struct(int namecode)
483 {
484         int len;
485         short *sp;
486
487         if (nr_structs == 0) {
488                 structs[0] = structdata;
489         }
490         else {
491                 sp = structs[nr_structs - 1];
492                 len = sp[1];
493                 structs[nr_structs] = sp + 2 * len + 2;
494         }
495
496         sp = structs[nr_structs];
497         sp[0] = namecode;
498
499         if (nr_structs >= maxnr) {
500                 printf("too many structs\n");
501                 return sp;
502         }
503         nr_structs++;
504
505         return sp;
506 }
507
508 static int preprocess_include(char *maindata, int len)
509 {
510         int a, newlen, comment = 0;
511         char *cp, *temp, *md;
512
513         /* note: len + 1, last character is a dummy to prevent
514          * comparisons using uninitialized memory */
515         temp = MEM_mallocN(len + 1, "preprocess_include");
516         temp[len] = ' ';
517
518         memcpy(temp, maindata, len);
519
520         /* remove all c++ comments */
521         /* replace all enters/tabs/etc with spaces */
522         cp = temp;
523         a = len;
524         comment = 0;
525         while (a--) {
526                 if (cp[0] == '/' && cp[1] == '/') {
527                         comment = 1;
528                 }
529                 else if (*cp == '\n') {
530                         comment = 0;
531                 }
532                 if (comment || *cp < 32 || *cp > 128) *cp = 32;
533                 cp++;
534         }
535
536
537         /* data from temp copy to maindata, remove comments and double spaces */
538         cp = temp;
539         md = maindata;
540         newlen = 0;
541         comment = 0;
542         a = len;
543         while (a--) {
544
545                 if (cp[0] == '/' && cp[1] == '*') {
546                         comment = 1;
547                         cp[0] = cp[1] = 32;
548                 }
549                 if (cp[0] == '*' && cp[1] == '/') {
550                         comment = 0;
551                         cp[0] = cp[1] = 32;
552                 }
553
554                 /* do not copy when: */
555                 if (comment) {
556                         /* pass */
557                 }
558                 else if (cp[0] == ' ' && cp[1] == ' ') {
559                         /* pass */
560                 }
561                 else if (cp[-1] == '*' && cp[0] == ' ') {
562                         /* pointers with a space */
563                 }       /* skip special keywords */
564                 else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) {
565                         /* single values are skipped already, so decrement 1 less */
566                         a -= 13;
567                         cp += 13;
568                 }
569                 else if (strncmp("DNA_PRIVATE_WORKSPACE", cp, 21) == 0) {
570                         /* Check for DNA_PRIVATE_WORKSPACE_READ_WRITE */
571                         if (strncmp("_READ_WRITE", cp + 21, 11) == 0) {
572                                 a -= 31;
573                                 cp += 31;
574                         }
575                         else {
576                                 a -= 20;
577                                 cp += 20;
578                         }
579                 }
580                 else {
581                         md[0] = cp[0];
582                         md++;
583                         newlen++;
584                 }
585                 cp++;
586         }
587
588         MEM_freeN(temp);
589         return newlen;
590 }
591
592 static void *read_file_data(const char *filename, int *r_len)
593 {
594 #ifdef WIN32
595         FILE *fp = fopen(filename, "rb");
596 #else
597         FILE *fp = fopen(filename, "r");
598 #endif
599         void *data;
600
601         if (!fp) {
602                 *r_len = -1;
603                 return NULL;
604         }
605
606         fseek(fp, 0L, SEEK_END);
607         *r_len = ftell(fp);
608         fseek(fp, 0L, SEEK_SET);
609
610         if (*r_len == -1) {
611                 fclose(fp);
612                 return NULL;
613         }
614
615         data = MEM_mallocN(*r_len, "read_file_data");
616         if (!data) {
617                 *r_len = -1;
618                 fclose(fp);
619                 return NULL;
620         }
621
622         if (fread(data, *r_len, 1, fp) != 1) {
623                 *r_len = -1;
624                 MEM_freeN(data);
625                 fclose(fp);
626                 return NULL;
627         }
628
629         fclose(fp);
630         return data;
631 }
632
633 static int convert_include(const char *filename)
634 {
635         /* read include file, skip structs with a '#' before it.
636          * store all data in temporal arrays.
637          */
638         int filelen, count, slen, type, name, strct;
639         short *structpoin, *sp;
640         char *maindata, *mainend, *md, *md1;
641         bool skip_struct;
642
643         md = maindata = read_file_data(filename, &filelen);
644         if (filelen == -1) {
645                 fprintf(stderr, "Can't read file %s\n", filename);
646                 return 1;
647         }
648
649         filelen = preprocess_include(maindata, filelen);
650         mainend = maindata + filelen - 1;
651
652         /* we look for '{' and then back to 'struct' */
653         count = 0;
654         skip_struct = false;
655         while (count < filelen) {
656
657                 /* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
658                 if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
659                         skip_struct = true;
660                 }
661
662                 if (md[0] == '{') {
663                         md[0] = 0;
664                         if (skip_struct) {
665                                 skip_struct = false;
666                         }
667                         else {
668                                 if (md[-1] == ' ') md[-1] = 0;
669                                 md1 = md - 2;
670                                 while (*md1 != 32) md1--;       /* to beginning of word */
671                                 md1++;
672
673                                 /* we've got a struct name when... */
674                                 if (strncmp(md1 - 7, "struct", 6) == 0) {
675
676                                         strct = add_type(md1, 0);
677                                         if (strct == -1) {
678                                                 fprintf(stderr, "File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
679                                                 return 1;
680                                         }
681
682                                         structpoin = add_struct(strct);
683                                         sp = structpoin + 2;
684
685                                         DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[strct]);
686
687                                         /* first lets make it all nice strings */
688                                         md1 = md + 1;
689                                         while (*md1 != '}') {
690                                                 if (md1 > mainend) break;
691
692                                                 if (*md1 == ',' || *md1 == ' ') *md1 = 0;
693                                                 md1++;
694                                         }
695
696                                         /* read types and names until first character that is not '}' */
697                                         md1 = md + 1;
698                                         while (*md1 != '}') {
699                                                 if (md1 > mainend) break;
700
701                                                 /* skip when it says 'struct' or 'unsigned' or 'const' */
702                                                 if (*md1) {
703                                                         if (strncmp(md1, "struct", 6) == 0) md1 += 7;
704                                                         if (strncmp(md1, "unsigned", 8) == 0) md1 += 9;
705                                                         if (strncmp(md1, "const", 5) == 0) md1 += 6;
706
707                                                         /* we've got a type! */
708                                                         type = add_type(md1, 0);
709                                                         if (type == -1) {
710                                                                 fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
711                                                                 return 1;
712                                                         }
713
714                                                         DEBUG_PRINTF(1, "\t|\t|\tfound type %s (", md1);
715
716                                                         md1 += strlen(md1);
717
718
719                                                         /* read until ';' */
720                                                         while (*md1 != ';') {
721                                                                 if (md1 > mainend) break;
722
723                                                                 if (*md1) {
724                                                                         /* We've got a name. slen needs
725                                                                          * correction for function
726                                                                          * pointers! */
727                                                                         slen = (int) strlen(md1);
728                                                                         if (md1[slen - 1] == ';') {
729                                                                                 md1[slen - 1] = 0;
730
731                                                                                 name = add_name(version_elem_static_from_alias(strct, md1));
732                                                                                 slen += additional_slen_offset;
733                                                                                 sp[0] = type;
734                                                                                 sp[1] = name;
735
736                                                                                 if (names[name] != NULL) {
737                                                                                         DEBUG_PRINTF(1, "%s |", names[name]);
738                                                                                 }
739
740                                                                                 structpoin[1]++;
741                                                                                 sp += 2;
742
743                                                                                 md1 += slen;
744                                                                                 break;
745                                                                         }
746
747                                                                         name = add_name(version_elem_static_from_alias(strct, md1));
748                                                                         slen += additional_slen_offset;
749
750                                                                         sp[0] = type;
751                                                                         sp[1] = name;
752                                                                         if (names[name] != NULL) {
753                                                                                 DEBUG_PRINTF(1, "%s ||", names[name]);
754                                                                         }
755
756                                                                         structpoin[1]++;
757                                                                         sp += 2;
758
759                                                                         md1 += slen;
760                                                                 }
761                                                                 md1++;
762                                                         }
763
764                                                         DEBUG_PRINTF(1, ")\n");
765
766                                                 }
767                                                 md1++;
768                                         }
769                                 }
770                         }
771                 }
772                 count++;
773                 md++;
774         }
775
776         MEM_freeN(maindata);
777
778         return 0;
779 }
780
781 static bool check_field_alignment(int firststruct, int structtype, int type, int len,
782                                   const char *name, const char *detail)
783 {
784         bool result = true;
785         if (type < firststruct && typelens_native[type] > 4 && (len % 8)) {
786                 fprintf(stderr, "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
787                         detail, types[structtype], name, len % 8);
788                 result = false;
789         }
790         if (typelens_native[type] > 3 && (len % 4) ) {
791                 fprintf(stderr, "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
792                         detail, types[structtype], name, len % 4);
793                 result = false;
794         }
795         if (typelens_native[type] == 2 && (len % 2) ) {
796                 fprintf(stderr, "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
797                         detail, types[structtype], name, len % 2);
798                 result = false;
799         }
800         return result;
801 }
802
803 static int calculate_structlens(int firststruct)
804 {
805         int unknown = nr_structs, lastunknown;
806         bool dna_error = false;
807
808         while (unknown) {
809                 lastunknown = unknown;
810                 unknown = 0;
811
812                 /* check all structs... */
813                 for (int a = 0; a < nr_structs; a++) {
814                         const short *structpoin = structs[a];
815                         const int    structtype = structpoin[0];
816
817                         /* when length is not known... */
818                         if (typelens_native[structtype] == 0) {
819
820                                 const short *sp = structpoin + 2;
821                                 int len_native = 0;
822                                 int len_32 = 0;
823                                 int len_64 = 0;
824                                 bool has_pointer = false;
825
826                                 /* check all elements in struct */
827                                 for (int b = 0; b < structpoin[1]; b++, sp += 2) {
828                                         int type = sp[0];
829                                         const char *cp = names[sp[1]];
830
831                                         int namelen = (int)strlen(cp);
832                                         /* is it a pointer or function pointer? */
833                                         if (cp[0] == '*' || cp[1] == '*') {
834                                                 has_pointer = 1;
835                                                 /* has the name an extra length? (array) */
836                                                 int mul = 1;
837                                                 if (cp[namelen - 1] == ']') {
838                                                         mul = DNA_elem_array_size(cp);
839                                                 }
840
841                                                 if (mul == 0) {
842                                                         fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
843                                                                 types[structtype], namelen + 1, cp);
844                                                         dna_error = 1;
845                                                 }
846
847                                                 /* 4-8 aligned/ */
848                                                 if (sizeof(void *) == 4) {
849                                                         if (len_native % 4) {
850                                                                 fprintf(stderr, "Align pointer error in struct (len_native 4): %s %s\n",
851                                                                         types[structtype], cp);
852                                                                 dna_error = 1;
853                                                         }
854                                                 }
855                                                 else {
856                                                         if (len_native % 8) {
857                                                                 fprintf(stderr, "Align pointer error in struct (len_native 8): %s %s\n",
858                                                                         types[structtype], cp);
859                                                                 dna_error = 1;
860                                                         }
861                                                 }
862
863                                                 if (len_64 % 8) {
864                                                         fprintf(stderr, "Align pointer error in struct (len_64 8): %s %s\n",
865                                                                 types[structtype], cp);
866                                                         dna_error = 1;
867                                                 }
868
869                                                 len_native += sizeof(void *) * mul;
870                                                 len_32 += 4 * mul;
871                                                 len_64 += 8 * mul;
872
873                                         }
874                                         else if (cp[0] == '[') {
875                                                 /* parsing can cause names "var" and "[3]"
876                                                  * to be found for "float var [3]" */
877                                                 fprintf(stderr, "Parse error in struct, invalid member name: %s %s\n",
878                                                         types[structtype], cp);
879                                                 dna_error = 1;
880                                         }
881                                         else if (typelens_native[type]) {
882                                                 /* has the name an extra length? (array) */
883                                                 int mul = 1;
884                                                 if (cp[namelen - 1] == ']') {
885                                                         mul = DNA_elem_array_size(cp);
886                                                 }
887
888                                                 if (mul == 0) {
889                                                         fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
890                                                                 types[structtype], namelen + 1, cp);
891                                                         dna_error = 1;
892                                                 }
893
894                                                 /* struct alignment */
895                                                 if (type >= firststruct) {
896                                                         if (sizeof(void *) == 8 && (len_native % 8) ) {
897                                                                 fprintf(stderr, "Align struct error: %s %s\n",
898                                                                         types[structtype], cp);
899                                                                 dna_error = 1;
900                                                         }
901                                                 }
902
903                                                 /* Check 2-4-8 aligned. */
904                                                 if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) {
905                                                         dna_error = 1;
906                                                 }
907                                                 if (!check_field_alignment(firststruct, structtype, type, len_64, cp, "64 bit")) {
908                                                         dna_error = 1;
909                                                 }
910
911                                                 len_native += mul * typelens_native[type];
912                                                 len_32 += mul * typelens_32[type];
913                                                 len_64 += mul * typelens_64[type];
914
915                                         }
916                                         else {
917                                                 len_native = 0;
918                                                 len_32 = 0;
919                                                 len_64 = 0;
920                                                 break;
921                                         }
922                                 }
923
924                                 if (len_native == 0) {
925                                         unknown++;
926                                 }
927                                 else {
928                                         typelens_native[structtype] = len_native;
929                                         typelens_32[structtype] = len_32;
930                                         typelens_64[structtype] = len_64;
931                                         /* two ways to detect if a struct contains a pointer:
932                                          * has_pointer is set or len_native  doesn't match any of 32/64bit lengths*/
933                                         if (has_pointer || len_64 != len_native || len_32 != len_native) {
934                                                 if (len_64 % 8) {
935                                                         fprintf(stderr, "Sizeerror 8 in struct: %s (add %d bytes)\n",
936                                                                 types[structtype], len_64 % 8);
937                                                         dna_error = 1;
938                                                 }
939                                         }
940
941                                         if (len_native % 4) {
942                                                 fprintf(stderr, "Sizeerror 4 in struct: %s (add %d bytes)\n",
943                                                        types[structtype], len_native % 4);
944                                                 dna_error = 1;
945                                         }
946
947                                 }
948                         }
949                 }
950
951                 if (unknown == lastunknown) break;
952         }
953
954         if (unknown) {
955                 fprintf(stderr, "ERROR: still %d structs unknown\n", unknown);
956
957                 if (debugSDNA) {
958                         fprintf(stderr, "*** Known structs :\n");
959
960                         for (int a = 0; a < nr_structs; a++) {
961                                 const short *structpoin = structs[a];
962                                 const int    structtype = structpoin[0];
963
964                                 /* length unknown */
965                                 if (typelens_native[structtype] != 0) {
966                                         fprintf(stderr, "  %s\n", types[structtype]);
967                                 }
968                         }
969                 }
970
971
972                 fprintf(stderr, "*** Unknown structs :\n");
973
974                 for (int a = 0; a < nr_structs; a++) {
975                         const short *structpoin = structs[a];
976                         const int    structtype = structpoin[0];
977
978                         /* length unknown yet */
979                         if (typelens_native[structtype] == 0) {
980                                 fprintf(stderr, "  %s\n", types[structtype]);
981                         }
982                 }
983
984                 dna_error = 1;
985         }
986
987         return dna_error;
988 }
989
990 #define MAX_DNA_LINE_LENGTH 20
991
992 static void dna_write(FILE *file, const void *pntr, const int size)
993 {
994         static int linelength = 0;
995         int i;
996         const char *data;
997
998         data = (const char *)pntr;
999
1000         for (i = 0; i < size; i++) {
1001                 fprintf(file, "%d, ", data[i]);
1002                 linelength++;
1003                 if (linelength >= MAX_DNA_LINE_LENGTH) {
1004                         fprintf(file, "\n");
1005                         linelength = 0;
1006                 }
1007         }
1008 }
1009
1010 void printStructLengths(void)
1011 {
1012         int a, unknown = nr_structs, structtype;
1013         /*int lastunknown;*/ /*UNUSED*/
1014         const short *structpoin;
1015         printf("\n\n*** All detected structs:\n");
1016
1017         while (unknown) {
1018                 /*lastunknown = unknown;*/ /*UNUSED*/
1019                 unknown = 0;
1020
1021                 /* check all structs... */
1022                 for (a = 0; a < nr_structs; a++) {
1023                         structpoin = structs[a];
1024                         structtype = structpoin[0];
1025                         printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]);
1026                 }
1027         }
1028
1029         printf("*** End of list\n");
1030
1031 }
1032
1033
1034 static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets)
1035 {
1036         int i;
1037         const short *sp;
1038         /* str contains filenames. Since we now include paths, I stretched       */
1039         /* it a bit. Hope this is enough :) -nzc-                                */
1040         char str[SDNA_MAX_FILENAME_LENGTH];
1041         int firststruct;
1042
1043         if (debugSDNA > 0) {
1044                 fflush(stdout);
1045                 printf("Running makesdna at debug level %d\n", debugSDNA);
1046         }
1047
1048         mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
1049
1050         /* the longest known struct is 50k, so we assume 100k is sufficient! */
1051         structdata = MEM_callocN(maxdata, "structdata");
1052
1053         /* a maximum of 5000 variables, must be sufficient? */
1054         names = MEM_callocN(sizeof(char *) * maxnr, "names");
1055         types = MEM_callocN(sizeof(char *) * maxnr, "types");
1056         typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native");
1057         typelens_32 = MEM_callocN(sizeof(short) * maxnr, "typelens_32");
1058         typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64");
1059         structs = MEM_callocN(sizeof(short *) * maxnr, "structs");
1060
1061         /* Build versioning data */
1062         DNA_alias_maps(
1063                 DNA_RENAME_ALIAS_FROM_STATIC,
1064                 &g_version_data.struct_map_alias_from_static,
1065                 NULL);
1066         DNA_alias_maps(
1067                 DNA_RENAME_STATIC_FROM_ALIAS,
1068                 &g_version_data.struct_map_static_from_alias,
1069                 &g_version_data.elem_map_static_from_alias);
1070
1071         /**
1072          * Insertion of all known types.
1073          *
1074          * \warning Order of function calls here must be aligned with #eSDNA_Type.
1075          * \warning uint is not allowed! use in structs an unsigned int.
1076          * \warning sizes must match #DNA_elem_type_size().
1077          */
1078         add_type("char", 1);     /* SDNA_TYPE_CHAR */
1079         add_type("uchar", 1);    /* SDNA_TYPE_UCHAR */
1080         add_type("short", 2);    /* SDNA_TYPE_SHORT */
1081         add_type("ushort", 2);   /* SDNA_TYPE_USHORT */
1082         add_type("int", 4);      /* SDNA_TYPE_INT */
1083
1084         /* note, long isn't supported,
1085          * these are place-holders to maintain alignment with eSDNA_Type*/
1086         add_type("long", 4);     /* SDNA_TYPE_LONG */
1087         add_type("ulong", 4);    /* SDNA_TYPE_ULONG */
1088
1089         add_type("float", 4);    /* SDNA_TYPE_FLOAT */
1090         add_type("double", 8);   /* SDNA_TYPE_DOUBLE */
1091         add_type("int64_t", 8);  /* SDNA_TYPE_INT64 */
1092         add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
1093         add_type("void", 0);     /* SDNA_TYPE_VOID */
1094
1095         /* the defines above shouldn't be output in the padding file... */
1096         firststruct = nr_types;
1097
1098         /* add all include files defined in the global array                     */
1099         /* Since the internal file+path name buffer has limited length, I do a   */
1100         /* little test first...                                                  */
1101         /* Mind the breaking condition here!                                     */
1102         DEBUG_PRINTF(0, "\tStart of header scan:\n");
1103         for (i = 0; *(includefiles[i]) != '\0'; i++) {
1104                 sprintf(str, "%s%s", baseDirectory, includefiles[i]);
1105                 DEBUG_PRINTF(0, "\t|-- Converting %s\n", str);
1106                 if (convert_include(str)) {
1107                         return 1;
1108                 }
1109         }
1110         DEBUG_PRINTF(0, "\tFinished scanning %d headers.\n", i);
1111
1112         if (calculate_structlens(firststruct)) {
1113                 /* error */
1114                 return 1;
1115         }
1116
1117         /* FOR DEBUG */
1118         if (debugSDNA > 1) {
1119                 int a, b;
1120                 /* short *elem; */
1121                 short num_types;
1122
1123                 printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs);
1124                 for (a = 0; a < nr_names; a++) {
1125                         printf(" %s\n", names[a]);
1126                 }
1127                 printf("\n");
1128
1129                 sp = typelens_native;
1130                 for (a = 0; a < nr_types; a++, sp++) {
1131                         printf(" %s %d\n", types[a], *sp);
1132                 }
1133                 printf("\n");
1134
1135                 for (a = 0; a < nr_structs; a++) {
1136                         sp = structs[a];
1137                         printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]);
1138                         num_types  = sp[1];
1139                         sp += 2;
1140                         /* ? num_types was elem? */
1141                         for (b = 0; b < num_types; b++, sp += 2) {
1142                                 printf("   %s %s\n", types[sp[0]], names[sp[1]]);
1143                         }
1144                 }
1145         }
1146
1147         /* file writing */
1148
1149         DEBUG_PRINTF(0, "Writing file ... ");
1150
1151         if (nr_names == 0 || nr_structs == 0) {
1152                 /* pass */
1153         }
1154         else {
1155                 const char nil_bytes[4] = {0};
1156                 int len, len_align;
1157
1158                 dna_write(file, "SDNA", 4);
1159
1160                 /* write names */
1161                 dna_write(file, "NAME", 4);
1162                 len = nr_names;
1163                 dna_write(file, &len, 4);
1164                 /* write array */
1165                 len = 0;
1166                 for (int nr = 0; nr < nr_names; nr++) {
1167                         int name_size = strlen(names[nr]) + 1;
1168                         dna_write(file, names[nr], name_size);
1169                         len += name_size;
1170                 }
1171                 len_align = (len + 3) & ~3;
1172                 if (len != len_align) {
1173                         dna_write(file, nil_bytes, len_align - len);
1174                 }
1175
1176                 /* write TYPES */
1177                 dna_write(file, "TYPE", 4);
1178                 len = nr_types;
1179                 dna_write(file, &len, 4);
1180                 /* write array */
1181                 len = 0;
1182                 for (int nr = 0; nr < nr_types; nr++) {
1183                         int type_size = strlen(types[nr]) + 1;
1184                         dna_write(file, types[nr], type_size);
1185                         len += type_size;
1186                 }
1187                 len_align = (len + 3) & ~3;
1188                 if (len != len_align) {
1189                         dna_write(file, nil_bytes, len_align - len);
1190                 }
1191
1192                 /* WRITE TYPELENGTHS */
1193                 dna_write(file, "TLEN", 4);
1194
1195                 len = 2 * nr_types;
1196                 if (nr_types & 1) len += 2;
1197                 dna_write(file, typelens_native, len);
1198
1199                 /* WRITE STRUCTS */
1200                 dna_write(file, "STRC", 4);
1201                 len = nr_structs;
1202                 dna_write(file, &len, 4);
1203
1204                 /* calc datablock size */
1205                 sp = structs[nr_structs - 1];
1206                 sp += 2 + 2 * (sp[1]);
1207                 len = (intptr_t) ((char *) sp - (char *) structs[0]);
1208                 len = (len + 3) & ~3;
1209
1210                 dna_write(file, structs[0], len);
1211
1212                 /* a simple dna padding test */
1213                 if (0) {
1214                         FILE *fp;
1215                         int a;
1216
1217                         fp = fopen("padding.c", "w");
1218                         if (fp == NULL) {
1219                                 /* pass */
1220                         }
1221                         else {
1222
1223                                 /* add all include files defined in the global array */
1224                                 for (i = 0; *(includefiles[i]) != '\0'; i++) {
1225                                         fprintf(fp, "#include \"%s%s\"\n", baseDirectory, includefiles[i]);
1226                                 }
1227
1228                                 fprintf(fp, "main() {\n");
1229                                 sp = typelens_native;
1230                                 sp += firststruct;
1231                                 for (a = firststruct; a < nr_types; a++, sp++) {
1232                                         if (*sp) {
1233                                                 fprintf(fp, "\tif (sizeof(struct %s) - %d) printf(\"ALIGN ERROR:", types[a], *sp);
1234                                                 fprintf(fp, "%%d %s %d ", types[a], *sp);
1235                                                 fprintf(fp, "\\n\",  sizeof(struct %s) - %d);\n", types[a], *sp);
1236                                         }
1237                                 }
1238                                 fprintf(fp, "}\n");
1239                                 fclose(fp);
1240                         }
1241                 }
1242                 /*      end end padding test */
1243         }
1244
1245         /* write a simple enum with all structs offsets,
1246          * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */
1247         {
1248                 fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1249                 fprintf(file_offsets, "enum {\n");
1250                 for (i = 0; i < nr_structs; i++) {
1251                         const short *structpoin = structs[i];
1252                         const int    structtype = structpoin[0];
1253                         fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", version_struct_alias_from_static(types[structtype]), i);
1254                 }
1255                 fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs);
1256                 fprintf(file_offsets, "};\n");
1257         }
1258
1259         /* Check versioning errors which could cause duplicate names,
1260          * do last because names are stripped. */
1261         {
1262                 GSet *names_unique = BLI_gset_str_new_ex(__func__, 512);
1263                 for (int struct_nr = 0; struct_nr < nr_structs; struct_nr++) {
1264                         sp = structs[struct_nr];
1265                         const char *struct_name = types[sp[0]];
1266                         const int len = sp[1];
1267                         sp += 2;
1268                         for (int a = 0; a < len; a++, sp += 2) {
1269                                 char *name = names[sp[1]];
1270                                 DNA_elem_id_strip(name);
1271                                 if (!BLI_gset_add(names_unique, name)) {
1272                                         fprintf(stderr, "Error: duplicate name found '%s.%s', "
1273                                                "likely cause is 'dna_rename_defs.h'\n",
1274                                                struct_name, name);
1275                                         return 1;
1276                                 }
1277                         }
1278                         BLI_gset_clear(names_unique, NULL);
1279                 }
1280                 BLI_gset_free(names_unique, NULL);
1281         }
1282
1283         MEM_freeN(structdata);
1284         MEM_freeN(names);
1285         MEM_freeN(types);
1286         MEM_freeN(typelens_native);
1287         MEM_freeN(typelens_32);
1288         MEM_freeN(typelens_64);
1289         MEM_freeN(structs);
1290
1291         BLI_memarena_free(mem_arena);
1292
1293         BLI_ghash_free(g_version_data.struct_map_alias_from_static, NULL, NULL);
1294         BLI_ghash_free(g_version_data.struct_map_static_from_alias, NULL, NULL);
1295         BLI_ghash_free(g_version_data.elem_map_static_from_alias, MEM_freeN, NULL);
1296
1297         DEBUG_PRINTF(0, "done.\n");
1298
1299         return 0;
1300 }
1301
1302 /** \} */
1303
1304 /* end make DNA. */
1305
1306 /* -------------------------------------------------------------------- */
1307 /** \name Main Function
1308  * \{ */
1309
1310 static void make_bad_file(const char *file, int line)
1311 {
1312         FILE *fp = fopen(file, "w");
1313         fprintf(fp,
1314                "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1315                __FILE__, line);
1316         fclose(fp);
1317 }
1318
1319 #ifndef BASE_HEADER
1320 #define BASE_HEADER "../"
1321 #endif
1322
1323 int main(int argc, char **argv)
1324 {
1325         int return_status = 0;
1326
1327         if (argc != 3 && argc != 4) {
1328                 printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1329                 return_status = 1;
1330         }
1331         else {
1332                 FILE *file_dna         = fopen(argv[1], "w");
1333                 FILE *file_dna_offsets = fopen(argv[2], "w");
1334                 if (!file_dna) {
1335                         printf("Unable to open file: %s\n", argv[1]);
1336                         return_status = 1;
1337                 }
1338                 else if (!file_dna_offsets) {
1339                         printf("Unable to open file: %s\n", argv[2]);
1340                         return_status = 1;
1341                 }
1342                 else {
1343                         const char *baseDirectory;
1344
1345                         if (argc == 4) {
1346                                 baseDirectory = argv[3];
1347                         }
1348                         else {
1349                                 baseDirectory = BASE_HEADER;
1350                         }
1351
1352                         fprintf(file_dna, "const unsigned char DNAstr[] = {\n");
1353                         if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) {
1354                                 /* error */
1355                                 fclose(file_dna);
1356                                 file_dna = NULL;
1357                                 make_bad_file(argv[1], __LINE__);
1358                                 return_status = 1;
1359                         }
1360                         else {
1361                                 fprintf(file_dna, "};\n");
1362                                 fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
1363                         }
1364                 }
1365
1366                 if (file_dna) {
1367                         fclose(file_dna);
1368                 }
1369                 if (file_dna_offsets) {
1370                         fclose(file_dna_offsets);
1371                 }
1372         }
1373
1374
1375         return return_status;
1376 }
1377
1378 /* handy but fails on struct bounds which makesdna doesn't care about
1379  * with quite the same strictness as GCC does */
1380 #if 0
1381 /* include files for automatic dependencies */
1382
1383 /* extra safety check that we are aligned,
1384  * warnings here are easier to fix the makesdna's */
1385 #ifdef __GNUC__
1386 #  pragma GCC diagnostic error "-Wpadded"
1387 #endif
1388
1389 #endif /* if 0 */
1390
1391 /* even though DNA supports, 'long' shouldn't be used since it can be either 32 or 64bit,
1392  * use int or int64_t instead.
1393  * Only valid use would be as a runtime variable if an API expected a long,
1394  * but so far we dont have this happening. */
1395 #ifdef __GNUC__
1396 #  pragma GCC poison long
1397 #endif
1398
1399 #include "DNA_listBase.h"
1400 #include "DNA_vec_types.h"
1401 #include "DNA_ID.h"
1402 #include "DNA_ipo_types.h"
1403 #include "DNA_key_types.h"
1404 #include "DNA_text_types.h"
1405 #include "DNA_packedFile_types.h"
1406 #include "DNA_camera_types.h"
1407 #include "DNA_image_types.h"
1408 #include "DNA_texture_types.h"
1409 #include "DNA_lamp_types.h"
1410 #include "DNA_material_types.h"
1411 #include "DNA_vfont_types.h"
1412 #include "DNA_meta_types.h"
1413 #include "DNA_curve_types.h"
1414 #include "DNA_mesh_types.h"
1415 #include "DNA_meshdata_types.h"
1416 #include "DNA_modifier_types.h"
1417 #include "DNA_lattice_types.h"
1418 #include "DNA_object_types.h"
1419 #include "DNA_object_force_types.h"
1420 #include "DNA_object_fluidsim_types.h"
1421 #include "DNA_world_types.h"
1422 #include "DNA_scene_types.h"
1423 #include "DNA_view3d_types.h"
1424 #include "DNA_view2d_types.h"
1425 #include "DNA_space_types.h"
1426 #include "DNA_userdef_types.h"
1427 #include "DNA_screen_types.h"
1428 #include "DNA_sdna_types.h"
1429 #include "DNA_fileglobal_types.h"
1430 #include "DNA_sequence_types.h"
1431 #include "DNA_effect_types.h"
1432 #include "DNA_outliner_types.h"
1433 #include "DNA_sound_types.h"
1434 #include "DNA_collection_types.h"
1435 #include "DNA_armature_types.h"
1436 #include "DNA_action_types.h"
1437 #include "DNA_constraint_types.h"
1438 #include "DNA_nla_types.h"
1439 #include "DNA_node_types.h"
1440 #include "DNA_color_types.h"
1441 #include "DNA_brush_types.h"
1442 #include "DNA_customdata_types.h"
1443 #include "DNA_particle_types.h"
1444 #include "DNA_cloth_types.h"
1445 #include "DNA_gpencil_types.h"
1446 #include "DNA_gpencil_modifier_types.h"
1447 #include "DNA_shader_fx_types.h"
1448 #include "DNA_windowmanager_types.h"
1449 #include "DNA_anim_types.h"
1450 #include "DNA_boid_types.h"
1451 #include "DNA_smoke_types.h"
1452 #include "DNA_speaker_types.h"
1453 #include "DNA_movieclip_types.h"
1454 #include "DNA_tracking_types.h"
1455 #include "DNA_dynamicpaint_types.h"
1456 #include "DNA_mask_types.h"
1457 #include "DNA_rigidbody_types.h"
1458 #include "DNA_freestyle_types.h"
1459 #include "DNA_linestyle_types.h"
1460 #include "DNA_cachefile_types.h"
1461 #include "DNA_layer_types.h"
1462 #include "DNA_workspace_types.h"
1463 #include "DNA_lightprobe_types.h"
1464
1465 /* end of list */
1466
1467 /** \} */
1468
1469
1470 /* -------------------------------------------------------------------- */
1471 /** \name DNA Renaming Sanity Check
1472  *
1473  * Without this it's possible to reference struct members that don't exist,
1474  * breaking backward & forward compatibility.
1475  *
1476  * \{ */
1477
1478 static void UNUSED_FUNCTION(dna_rename_defs_ensure)(void)
1479 {
1480 #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1481 #define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
1482 #include "dna_rename_defs.h"
1483 #undef DNA_STRUCT_RENAME
1484 #undef DNA_STRUCT_RENAME_ELEM
1485 }
1486
1487 /** \} */