-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME
1801 lines (1454 loc) · 85.4 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
+-----------------------------------------------------------------------------+
| Index |
+-----------------------------------------------------------------------------+
1. DDL Specification
1.1. Selects
1.1.1. Example
1.2. Bitfields
1.2.1. Example
1.3. Structures
1.3.1. Examples
2. Expressions
3. Comments
4. DDL API
4.1. Common methods
4.1.1. const char* GetName() const
4.1.2. const char* GetAuthor() const
4.1.3. const char* GetDescription() const
4.1.4. const char* GetLabel() const
4.1.5. const char* GetDisplayLabel() const
4.1.6. uint32_t GetNameHash() const
4.1.7. DDLParser::Tag* GetTags() const
4.1.8. DDLParser::Tag* GetTag( uint32_t type ) const
5. DDLParser::Compile
5.1. Parameters
5.2. Return value
6. DDLParser::StringCrc32
7. DDLParser::Definition
7.1. uint32_t DDLParser::Definition::GetNumAggregates() const
7.2. uint32_t DDLParser::Definition::GetTotalSize() const
7.3. static DDLParser::Definition* DDLParser::Definition::FromBinRep( void* bin_rep )
7.4. DDLParser::Aggregate* DDLParser::Definition::GetAggregate( unsigned int index )
7.5. DDLParser::Aggregate* DDLParser::Definition::FindAggregate( const char* name )
7.6. DDLParser::Aggregate* DDLParser::Definition::FindAggregate( uint32_t hash )
8. DDLParser::Aggregate
8.1. uint32_t DDLParser::Aggregate::GetType() const
8.2. DDLParser::Select* DDLParser::Aggregate::ToSelect() const
8.3. DDLParser::Bitfield* DDLParser::Aggregate::ToBitfield() const
8.4. DDLParser::Struct* DDLParser::Aggregate::ToStruct() const
9. DDLParser::Select
9.1. uint32_t DDLParser::Select::GetNumItems() const
9.2. int32_t DDLParser::Select::GetDefaultItem() const
9.3. DDLParser::SelectItem* DDLParser::Select::FindItem( const char* name )
9.4. DDLParser::SelectItem* DDLParser::Select::FindItem( uint32_t hash )
10. DDLParser::SelectItem
11. DDLParser::Bitfield
11.1. uint32_t DDLParser::Bitfield::GetNumFlags() const
11.2. int32_t DDLParser::Bitfield::GetDefaultFlag() const
11.3. DDLParser::BitfieldFlag* DDLParser::Bitfield::FindFlag( const char* name )
11.4. DDLParser::BitfieldFlag* DDLParser::Bitfield::FindFlag( uint32_t hash )
12. DDLParser::BitfieldFlag
12.1. DDLParser::BitfieldFlagValue* DDLParser::BitfieldFlag::GetValue() const
12.2. uint32_t DDLParser::BitfieldFlag::GetBit() const
13. DDLParser::BitfieldFlagValue
13.1. uint32_t DDLParser::BitfieldFlagValue::GetCount() const
13.2. uint32_t DDLParser::BitfieldFlagValue::GetFlagIndex( uint32_t index ) const
13.3. Bitfield example
14. DDLParser::Struct
14.1. uint32_t DDLParser::Struct::GetNumFields() const
14.2. DDLParser::Struct* DDLParser::Struct::GetParent() const
14.3. DDLParser::Definition* DDLParser::Struct::GetDefinition() const
14.4. DDLParser::StructField* DDLParser::Struct::FindField( const char* name )
14.5. DDLParser::StructField* DDLParser::Struct::FindField( uint32_t hash )
14.6. bool DDLParser::Struct::IsInherited( DDLParser::StructField* field )
14.7. uint32_t DDLParser::Struct::GetSchemaCrc() const
15. DDLParser::StructField
15.1. DDLParser::StructValueInfo* DDLParser::StructField::GetValueInfo()
16. DDLParser::StructValueInfo
16.1. uint32_t DDLParser::StructValueInfo::GetNameHash() const
16.2. Type DDLParser::StructValueInfo::GetType() const
16.3. uint32_t DDLParser::StructValueInfo::GetTypeNameHash() const
16.4. const char* DDLParser::StructValueInfo::GetTypeName() const
16.5. ArrayType DDLParser::StructValueInfo::GetArrayType() const
16.6. DDLParser::StructFieldValue* DDLParser::StructValueInfo::GetValue() const
16.7. uint32_t DDLParser::StructValueInfo::GetCount() const
16.8. uint32_t DDLParser::StructValueInfo::GetKeyType() const
16.9. int DDLParser::StructValueInfo::GetKeyBitSize() const
16.10. bool DDLParser::StructValueInfo::AllowSubStruct() const
16.11. uint32_t DDLParser::StructValueInfo::GetSchemaCrc() const
16.12. DDLParser::Aggregate* DDLParser::StructValueInfo::GetAggregate( Definition* ddl ) const'
17. DDLParser::StructFieldValue
18. DDLParser::StructBitfieldValue
18.1. uint32_t DDLParser::StructBitfieldValue::GetCount() const
18.2. uint32_t DDLParser::StructBitfieldValue::GetHash( uint32_t index ) const
19. DDLParser::StructStructValue
19.1. uint32_t DDLParser::StructStructValue::GetCount() const
19.2. DDLParser::StructValueInfo* DDLParser::StructStructValue::GetValueInfo( uint32_t index ) const
19.3. Example
20. DDLParser::Tag
20.1. uint32_t DDLParser::Tag::GetType() const
20.2. DDLParser::Tag* DDLParser::Tag::GetNext() const
21. DDLParser::GenericTag
21.1. const char* DDLParser::GenericTag::GetName() const
21.2. uint32_t DDLParser::GenericTag::GetNameHash() const
21.3. uint32_t DDLParser::GenericTag::GetNumValues() const
21.4. DDLParser::GenericTagValue* DDLParser::GenericTag::operator[]( unsigned int index ) const
22. DDLParser::GenericTagValue
22.1. Validating Generic Tags
23. DDLParser::Str
24. DDLParser::TagSet
25. DDL Grammar
26. License
+-----------------------------------------------------------------------------+
| 1. DDL Specification |
+-----------------------------------------------------------------------------+
DDL files can contain three constructs: selects, bitfields and structures. All
constructs must have a name, and they can have an author, a description and a
label assigned to them. These fields can be used by tools when rendering the
constructs as UI elements.
There is a annotated DDL grammar at the end of this document for further
reference.
+-----------------------------------------------------------------------------+
| 1.1. Selects |
+-----------------------------------------------------------------------------+
A select is just a list of options much like an C enum. They represent
exclusive values, like a drop-down where just one value can be selected. But
unlike C enums, numeric values cannot be assigned to select fields; their
values are just the hash of their names. This way new fields can be added
without constraints while maintaining compatibility with cold that uses the
select.
Each select item can have an author, a description and a label.
+-----------------------------------------------------------------------------+
| 1.1.1. Example |
+-----------------------------------------------------------------------------+
select Weapon, author( "Andre de Leiradella" ), description( "Weapons available to the player" ), label( "Weapon" )
{
kFist, description( "Bare hands" ), label( "Fist" );
kChainsaw, description( "A la Chainsaw Massacre" ), label( "Chainsaw" );
kPistol, description( "Simple pistol" ), label( "Pistol" ), default;
kShotgun, description( "A single-barrel shotgun" ), label( "Shotgun" );
kChaingun, description( "A machine gun" ), label( "Chaingun" );
kRocketLauncher, description( "Portable rocket launcher" ), label( "Rocket launcher" );
kPlasmaGun, description( "Plasma gun" ), label( "Plasma gun" );
kBFG9000, description( "*The* BFG 9000" ), label( "BFG 9000" );
}
An item can be marked as default (see item kPistol) and it will be the item
used in fields declared with the select type that don't have an explicit value
to override the default.
+-----------------------------------------------------------------------------+
| 1.2. Bitfields |
+-----------------------------------------------------------------------------+
Bitfields represent a set of related flags. Their flags can be or'ed to form
the value of another flag. Bitfields should be used where more than one value
can be selected, like a checkbox group.
As with select items, each bitfield flag can have an author, a description and
a label.
+-----------------------------------------------------------------------------+
| 1.2.1. Example |
+-----------------------------------------------------------------------------+
bitfield Powerup, author( "Andre de Leiradella" ), description( "Powerup pickups" ), label( "Powerup" )
{
kNone, description( "Help me!" ), empty;
kRadiationSuit, description( "Makes the player immune to radiation for a limited time" ), label( "Radiation suit" );
kPartialInvisibility, description( "Makes the player almost invisible to enemies for a limited time" ), label( "Partial invisibility" );
kInvulnerability, description( "Makes the player invulnerable for a limited time" ), label( "Invulnerability" );
kComputerMap, description( "Gives the complete map of the level to the player" ), label( "Computer map" );
kLightVisor, description( "Allows the player to see in the dark for a limited time" ), label( "Light visor" );
kBerserk, description( "Gives the player the ability to quickly kill enemies with his fists" ), label( "Berserk" );
kAll, value( kRadiationSuit | kPartialInvisibility | kInvulnerability | kComputerMap | kLightVisor | kBerserk );
}
Flags without a value will get an unique bit index that can be queried at
runtime. Flags can be marked as default. If there isn't a default flag in the
bitfield the empty flag will be used, or the first declared flag will be used
if there isn't an empty flag. To get a zeroed flag, tag it with empty like the
kNone flag above.
+-----------------------------------------------------------------------------+
| 1.3. Structures |
+-----------------------------------------------------------------------------+
While selects and bitfields only define custom types and take no memory,
structures are aggregates of fields which actually take up memory to hold their
fields' values.
Structure fields can be of the following types:
* u8 (or uint8_t)
* u16 (or uint16_t)
* u32 (or uint32_t)
* u64 (or uint64_t)
* i8 (or int8_t)
* i16 (or int16_t)
* i32 (or int32_t)
* i64 (or int64_t)
* f32 (or float)
* f64 (or double)
* boolean
* string
* file
* tuid
* json
* Any previously declared select, bitfield or structure
Fields can also be arrays of any of these types by just adding [] right after
the type name. These arrays cannot take default values, and can grow as needed
at runtime. Adding a [ x ], where x is an integer expression, makes the array
fixed and up to x default values can be specified for the field. Just like
select items and bitfield flags, structure fields can have an author, a
description and a label.
To inform the default value of a field, use the value keyword and write any
expression inside the parenthesis. The expression must evaluate to a value
which fits in the data type of the field.
+-----------------------------------------------------------------------------+
| 1.3.1. Examples |
+-----------------------------------------------------------------------------+
struct Position
{
f32 m_X, value( 0 );
f32 m_Y, value( 0 );
f32 m_Angle, value( 0 ), description("The direction the player is looking at (degrees)");
}
struct Mariner, author( "Andre de Leiradella" ), description( "The player character" ), label( "Player" )
{
u32 m_Health, value( 100 ), description( "The player's health" );
Weapon m_Weapon, value( kPistol ), description( "The player's current weapon" );
Powerup m_Powerup, value( kBerserk ), description( "The player's powerups" );
i32[ 8 ] m_Ammunition, value( { 0, 0, 20, -1, -1, -1, -1, -1 } ), description( "The ammunition of each weapon, -1 means the player doesn't have it" );
string m_Name, value( "Mariner" ), description( "The player's name for multiplayer sessions" );
Position m_Position, value( { m_X = 100, m_Y = 120 } ), description( "The player's position" );
Position[] m_Deaths, description( "Places the player has died in" );
}
Array values must be written inside braces with commas separating each
expression. Values of structured fields, like m_Position above, must also
appear inside braces. It's not mandatory that all fields are present in the
value.
+-----------------------------------------------------------------------------+
| 2. Expressions |
+-----------------------------------------------------------------------------+
DDL expressions are very similar to C expressions, and care has been taken to
implement the same operators with the same precedence order. The operators, in
decreasing order of precedence, are:
* ? (ternary operator)
* || (logic or)
* && (logic and)
* | (arithmetic or)
* ^ (arithmetic xor)
* & (arithmetic and)
* == and != (equality)
* <, <=, > and >= (comparison)
* << and >> (shift)
* + and - (add and subtract)
* *, / and % (multiply, divide and modulus)
* +, -, ~ and ! (unary positive, negative, complement and logic not)
Terminals can be binary, octal, decimal and hexadecimal integer constants,
floating point constants, string literals, the true and false constants, pi,
the natural number e, and expressions between parenthesis.
Binary constants are written similarly to hexadecimal constants but using the
0b prefix instead of 0x. String literals are specified inside single or double
quotes, and any occurrence of %xx in the string is substituted by the character
with hexadecimal value xx.
The constants true and false evaluates to the integers 1 and 0 respectively.
+-----------------------------------------------------------------------------+
| 3. Comments |
+-----------------------------------------------------------------------------+
DDL files can have C and C++ style comments:
* /* this is a comment */
* // this is a comment that ends at the end of the line
+-----------------------------------------------------------------------------+
| 4. DDL API |
+-----------------------------------------------------------------------------+
The DDL API are a collection of functions and structures that allows for DDL
source code compilation and subsequent querying of the components found in the
source file for i.e. code generation.
+-----------------------------------------------------------------------------+
| 4.1. Common methods |
+-----------------------------------------------------------------------------+
Many structures present a set of common methods that are explained here.
+-----------------------------------------------------------------------------+
| 4.1.1. const char* GetName() const |
+-----------------------------------------------------------------------------+
Returns the name of the component, i.e. a select's name or a structure's
field's name.
+-----------------------------------------------------------------------------+
| 4.1.2. const char* GetAuthor() const |
+-----------------------------------------------------------------------------+
If the component has been tagged with the author tag, GetAuthor returns the
contents of the tag, otherwise it returns NULL. This tag can be used to
document the person who authored the component.
+-----------------------------------------------------------------------------+
| 4.1.3. const char* GetDescription() const |
+-----------------------------------------------------------------------------+
If the component has been tagged with the description tag, GetDescription
returns the contents of the tag, otherwise it returns NULL. This tag can be
used to give the component a verbose description.
+-----------------------------------------------------------------------------+
| 4.1.4. const char* GetLabel() const |
+-----------------------------------------------------------------------------+
If the component has been tagged with the label tag, GetLabel returns the
contents of the tag, otherwise it returns NULL. This tag can be used to give
the component a label to be used in the user interface, for example.
+-----------------------------------------------------------------------------+
| 4.1.5. const char* GetDisplayLabel() const |
+-----------------------------------------------------------------------------+
Returns the contents of the label tag if it has been defined and is not the
empty string. Otherwise it returns the name of the component.
+-----------------------------------------------------------------------------+
| 4.1.6. uint32_t GetNameHash() const |
+-----------------------------------------------------------------------------+
Returns the hash of the components's name. The hash is created with
DDLParser::StringCrc32.
+-----------------------------------------------------------------------------+
| 4.1.7. DDLParser::Tag* GetTags() const |
+-----------------------------------------------------------------------------+
Returns the first tag defined for the component, or NULL if the component has
no tags defined.
+-----------------------------------------------------------------------------+
| 4.1.8. DDLParser::Tag* GetTag( uint32_t type ) const |
+-----------------------------------------------------------------------------+
Finds and returns a tag by its type. Alternatively, type can be the hash of the
generic tag to be searched for. Either way, if the tag isn't found NULL is
returned.
+-----------------------------------------------------------------------------+
| 5. DDLParser::Compile |
+-----------------------------------------------------------------------------+
DDLParser::Definition* DDLParser::Compile( DDLParser::LinearAllocator* definition, DDLParser::LinearAllocator* scratch, const void* source, size_t source_size, char* error, size_t error_size, bool two_us_reserved, int bitfield_limit )
The DDLParser::Compile function compiles a DDL source file into a
DDLParser::Definition ready to be used to generate code.
+-----------------------------------------------------------------------------+
| 5.1. Parameters |
+-----------------------------------------------------------------------------+
* definition: A DDLParser::LinearAllocator where the definition is assembled.
When DDLParser::Compile returns, this allocator will have the complete
definition.
* scratch: A DDLParser::LinearAllocator used for temporary work. Can be
discarded after DDLParser::Compile returns.
* source: A pointer to the DDL source code. This buffer doesn't have to be
null-terminated and cannot be NULL.
* source_size: The size of the source buffer.
* error: A pointer to a buffer where the error message, if there's one, will be
written to. Cannot be NULL.
* error_size: The size of the error buffer.
* two_us_reserved: If true, identifiers starting with two underlines are
reserved and disallowed in the source code.
* bitfield_limit: The maximum number of flags allowed in a bitfield. If this
value is zero, there is no limit on the number of flags per bitfield.
+-----------------------------------------------------------------------------+
| 5.2. Return value |
+-----------------------------------------------------------------------------+
If the parse succeeds it returns the definition assembled in definition casted
to a DDLParser::Definition pointer. If there was an error, DDLParser::Compile
returns NULL and error is filled with the error message.
+-----------------------------------------------------------------------------+
| 6. DDLParser::StringCrc32 |
+-----------------------------------------------------------------------------+
uint32_t DDLParser::StringCrc32( const char* data )
Returns the CRC32 of the string.
+-----------------------------------------------------------------------------+
| 7. DDLParser::Definition |
+-----------------------------------------------------------------------------+
After a successful parsing, DDLParser::Compile returns a DDLParser::Definition,
which is used as the starting point to query all selects, bitfields, and
structures, defined in the source code.
DDLParser::Definition has the following methods:
+-----------------------------------------------------------------------------+
| 7.1. uint32_t DDLParser::Definition::GetNumAggregates() const |
+-----------------------------------------------------------------------------+
Returns the number of aggregates (selects, bitfields and structures) in the
definition.
+-----------------------------------------------------------------------------+
| 7.2. uint32_t DDLParser::Definition::GetTotalSize() const |
+-----------------------------------------------------------------------------+
Returns the total size in bytes of the definition. This can be used if you want
to write it into a file for example.
+-----------------------------------------------------------------------------+
| 7.3. static DDLParser::Definition* DDLParser::Definition::FromBinRep( void* bin_rep ) |
+-----------------------------------------------------------------------------+
Just returns the bin_rep pointer casted to a DDLParser::Definition.
+-----------------------------------------------------------------------------+
| 7.4. DDLParser::Aggregate* DDLParser::Definition::GetAggregate( unsigned int index ) |
+-----------------------------------------------------------------------------+
Returns an aggregate given its index. Aggregates are saved into the definition
in the order they appear in the source code. No bounds check is done with
index.
+-----------------------------------------------------------------------------+
| 7.5. DDLParser::Aggregate* DDLParser::Definition::FindAggregate( const char* name ) |
+-----------------------------------------------------------------------------+
Finds and returns an aggregate by name. If the aggregate does not exist, NULL
is returned.
+-----------------------------------------------------------------------------+
| 7.6. DDLParser::Aggregate* DDLParser::Definition::FindAggregate( uint32_t hash ) |
+-----------------------------------------------------------------------------+
Finds and returns an aggregate by the hash of its name. If the aggregate does
not exist, NULL is returned. The hash must be created with
DDLParser::StringCrc32.
+-----------------------------------------------------------------------------+
| 8. DDLParser::Aggregate |
+-----------------------------------------------------------------------------+
An aggregate holds information common to selects, bitfields, and structures. It
has the following common methods: GetName, GetAuthor, GetDescription, GetLabel,
GetDisplayLabel, and GetNameHash.
+-----------------------------------------------------------------------------+
| 8.1. uint32_t DDLParser::Aggregate::GetType() const |
+-----------------------------------------------------------------------------+
Returns the type of the aggregate, DDLParser::kSelect, DDLParser::kBitfield, or
DDLParser::kStruct.
+-----------------------------------------------------------------------------+
| 8.2. DDLParser::Select* DDLParser::Aggregate::ToSelect() const |
+-----------------------------------------------------------------------------+
Returns the aggregate casted to DDLParser::Select without checking for the
actual aggregate type.
+-----------------------------------------------------------------------------+
| 8.3. DDLParser::Bitfield* DDLParser::Aggregate::ToBitfield() const |
+-----------------------------------------------------------------------------+
Returns the aggregate casted to DDLParser::Bitfield without checking for the
actual aggregate type.
+-----------------------------------------------------------------------------+
| 8.4. DDLParser::Struct* DDLParser::Aggregate::ToStruct() const |
+-----------------------------------------------------------------------------+
Returns the aggregate casted to DDLParser::Struct without checking for the
actual aggregate type.
+-----------------------------------------------------------------------------+
| 9. DDLParser::Select |
+-----------------------------------------------------------------------------+
A select is like a C enum, but you can't define the value of the items. Their
value is always the hash code of their identifiers. A select holds information
about its items.
In addition to the methods listed here, selects have the following common
methods: GetName, GetAuthor, GetDescription, GetLabel, GetDisplayLabel,
GetNameHash, GetTags, and GetTag.
+-----------------------------------------------------------------------------+
| 9.1. uint32_t DDLParser::Select::GetNumItems() const |
+-----------------------------------------------------------------------------+
Returns the number of items contained in the select.
+-----------------------------------------------------------------------------+
| 9.2. int32_t DDLParser::Select::GetDefaultItem() const |
+-----------------------------------------------------------------------------+
Returns the index of the item defined as the default item for the select. If no
item was defined as the default, the default item is the first defined. This
can be used to initialize variables to a default value if none is given for
example.
+-----------------------------------------------------------------------------+
| 9.3. DDLParser::SelectItem* DDLParser::Select::FindItem( const char* name ) |
+-----------------------------------------------------------------------------+
Finds and returns an item by name. If the item does not exist, NULL is
returned.
+-----------------------------------------------------------------------------+
| 9.4. DDLParser::SelectItem* DDLParser::Select::FindItem( uint32_t hash ) |
+-----------------------------------------------------------------------------+
Finds and returns an item by the hash of its name. If the item does not exist,
NULL is returned. The hash must be created with DDLParser::StringCrc32.
+-----------------------------------------------------------------------------+
| 10. DDLParser::SelectItem |
+-----------------------------------------------------------------------------+
A select item represents an item declared in a select and has the following
common methods: GetName, GetAuthor, GetDescription, GetLabel, GetDisplayLabel,
GetNameHash, GetTags, and GetTag.
Select items doesn't have any particular method besides the common ones listed
above.
+-----------------------------------------------------------------------------+
| 11. DDLParser::Bitfield |
+-----------------------------------------------------------------------------+
A bitfield is a set, and bitfield flags are the set's items. Unlike select
items, a bitfield flag has a value associated to it. This value can be an
explicit zero, an unique, automatically assigned value or a set which is the
union of other flags. If the value is automatically assigned, it starts with
one and is incremented for each assignment.
In addition to the methods listed here, bitfields have the following common
methods: GetName, GetAuthor, GetDescription, GetLabel, GetDisplayLabel,
GetNameHash, GetTags, and GetTag.
+-----------------------------------------------------------------------------+
| 11.1. uint32_t DDLParser::Bitfield::GetNumFlags() const |
+-----------------------------------------------------------------------------+
Returns the number of flags contained in the bitfield.
+-----------------------------------------------------------------------------+
| 11.2. int32_t DDLParser::Bitfield::GetDefaultFlag() const |
+-----------------------------------------------------------------------------+
Returns the index of the flag defined as the default flag for the bitfield. If
no flag was defined as the default, the default item is the empty flag. If an
empty flag wasn't declared, The first flag is elected the default. This can be
used to initialize variables to a default value if none is given for example.
+-----------------------------------------------------------------------------+
| 11.3. DDLParser::BitfieldFlag* DDLParser::Bitfield::FindFlag( const char* name ) |
+-----------------------------------------------------------------------------+
Finds and returns a flag by name. If the flag does not exist, NULL is returned.
+-----------------------------------------------------------------------------+
| 11.4. DDLParser::BitfieldFlag* DDLParser::Bitfield::FindFlag( uint32_t hash ) |
+-----------------------------------------------------------------------------+
Finds and returns a flag by the hash of its name. If the flag does not exist,
NULL is returned. The hash must be created with DDLParser::StringCrc32.
+-----------------------------------------------------------------------------+
| 12. DDLParser::BitfieldFlag |
+-----------------------------------------------------------------------------+
A flag is a unique element in a set, or a set of other flags. A flag has the
following common methods: GetName, GetAuthor, GetDescription, GetLabel,
GetDisplayLabel, GetNameHash, GetTags, and GetTag.
Flags also have the following unique methods:
+-----------------------------------------------------------------------------+
| 12.1. DDLParser::BitfieldFlagValue* DDLParser::BitfieldFlag::GetValue() const |
+-----------------------------------------------------------------------------+
Returns the value of the flag in case it's the empty flag or a set. If neither
is true, this function returns NULL.
+-----------------------------------------------------------------------------+
| 12.2. uint32_t DDLParser::BitfieldFlag::GetBit() const |
+-----------------------------------------------------------------------------+
If the flag is the empty flag, or if it's a set, this functions returns zero.
Otherwise, it returns an automatically assigned value for the flag which is
unique in the bitfield. This values starts at one and is incremented for each
flag that uses it. It can be used to generate code for flags as bits in an
integer, i.e. 1 << ( flag->GetBit() - 1 ).
+-----------------------------------------------------------------------------+
| 13. DDLParser::BitfieldFlagValue |
+-----------------------------------------------------------------------------+
Defines the value of a flag when it's either the empty flag or a set.
+-----------------------------------------------------------------------------+
| 13.1. uint32_t DDLParser::BitfieldFlagValue::GetCount() const |
+-----------------------------------------------------------------------------+
If the flag is the empty flag, this function returns zero. Otherwise, it
returns the number of flags contained in the flag.
+-----------------------------------------------------------------------------+
| 13.2. uint32_t DDLParser::BitfieldFlagValue::GetFlagIndex( uint32_t index ) const |
+-----------------------------------------------------------------------------+
Returns the index of the flag which is part of this set.
+-----------------------------------------------------------------------------+
| 13.3. Bitfield example |
+-----------------------------------------------------------------------------+
As an example, this code generates C++ code that outputs a bitfield's flags as
bits in an unsigned integer:
static void GenerateBitfield( DDLParser::Bitfield* bitfield )
{
printf( "namespace %s\n", bitfield->GetName() );
printf( "{\n" );
for ( uint32_t i = 0; i < bitfield->GetNumFlags(); i++ )
{
DDLParser::BitfieldFlag* flag = bitfield->GetFlag( i );
DDLParser::BitfieldFlagValue* value = flag->GetValue();
printf( " static const uint32_t %-20s = ", flag->GetName() );
if ( value == NULL )
{
// The flag has an automatically assigned value.
printf( "0x%08x;\n", 1 << ( flag->GetBit() - 1 ) );
}
else
{
if ( value->GetCount() == 0 )
{
// The flag is the empty flag.
printf( "0x%08x;\n", 0 );
}
else
{
// The flag is a set containing other flags.
DDLParser::BitfieldFlag* other = bitfield->GetFlag( 0 );
printf( "%s", other->GetName() );
for ( uint32_t j = 1; j < value->GetCount(); j++ )
{
other = bitfield->GetFlag( value->GetFlagIndex( j ) );
printf( " | %s", other->GetName() );
}
printf( ";\n" );
}
}
}
printf( "}\n" );
}
+-----------------------------------------------------------------------------+
| 14. DDLParser::Struct |
+-----------------------------------------------------------------------------+
Structures are collections of fields. Each field has its own type, which can be
a native type, a select, a bitfield, another structure, a fixed or dynamic
array of the previous types, or a hashmap mapping an integer, a string, a file,
or a tuid to any other type.
In addition to the methods listed here, structures have the following common
methods: GetName, GetAuthor, GetDescription, GetLabel, GetDisplayLabel,
GetNameHash, GetTags, and GetTag.
+-----------------------------------------------------------------------------+
| 14.1. uint32_t DDLParser::Struct::GetNumFields() const |
+-----------------------------------------------------------------------------+
Returns the number of fields contained in the structure.
+-----------------------------------------------------------------------------+
| 14.2. DDLParser::Struct* DDLParser::Struct::GetParent() const |
+-----------------------------------------------------------------------------+
Returns the parent structure of this structure. If the structure doesn't
inherit from another structure, it returns NULL.
+-----------------------------------------------------------------------------+
| 14.3. DDLParser::Definition* DDLParser::Struct::GetDefinition() const |
+-----------------------------------------------------------------------------+
Returns the definition where the structure was defined.
+-----------------------------------------------------------------------------+
| 14.4. DDLParser::StructField* DDLParser::Struct::FindField( const char* name ) |
+-----------------------------------------------------------------------------+
Finds and returns a field by name. If the field does not exist, NULL is
returned.
+-----------------------------------------------------------------------------+
| 14.5. DDLParser::StructField* DDLParser::Struct::FindField( uint32_t hash ) |
+-----------------------------------------------------------------------------+
Finds and returns a field by the hash of its name. If the field does not exist,
NULL is returned. The hash must be created with DDLParser::StringCrc32.
+-----------------------------------------------------------------------------+
| 14.6. bool DDLParser::Struct::IsInherited( DDLParser::StructField* field ) |
+-----------------------------------------------------------------------------+
Returns true if the field is from a parent structure.
+-----------------------------------------------------------------------------+
| 14.7. uint32_t DDLParser::Struct::GetSchemaCrc() const |
+-----------------------------------------------------------------------------+
The schema crc reflects the type, count, name, and order of each field. If any
of those change, then the crc changes. It does not reflect default values or
any tags.
+-----------------------------------------------------------------------------+
| 15. DDLParser::StructField |
+-----------------------------------------------------------------------------+
A field is an instance of a given type. A field has these common methods:
GetName, GetAuthor, GetDescription, GetLabel, GetDisplayLabel, GetNameHash,
GetTags, and GetTag.
Fields also have the following unique method.
+-----------------------------------------------------------------------------+
| 15.1. DDLParser::StructValueInfo* DDLParser::StructField::GetValueInfo() |
+-----------------------------------------------------------------------------+
Returns the value information of the field. A field always have a
DDLParser::StructField::GetValueInfo so this method never returns NULL.
+-----------------------------------------------------------------------------+
| 16. DDLParser::StructValueInfo |
+-----------------------------------------------------------------------------+
A DDLParser::StructValueInfo holds information for both a field declared in a
structure and its default values if the field has a structure for its type. It
has the the GetTags and GetTag common methods.
+-----------------------------------------------------------------------------+
| 16.1. uint32_t DDLParser::StructValueInfo::GetNameHash() const |
+-----------------------------------------------------------------------------+
Returns the hash of the field's name.
+-----------------------------------------------------------------------------+
| 16.2. Type DDLParser::StructValueInfo::GetType() const |
+-----------------------------------------------------------------------------+
Returns the type of the field which is a value from the DDLParser::Type
enumeration.
+-----------------------------------------------------------------------------+
| 16.3. uint32_t DDLParser::StructValueInfo::GetTypeNameHash() const |
+-----------------------------------------------------------------------------+
Returns the hash of the field's type name. Only usefull if the field has a
select, bitfield or structure type so it's possible to query the definition for
the actual aggregate.
+-----------------------------------------------------------------------------+
| 16.4. const char* DDLParser::StructValueInfo::GetTypeName() const |
+-----------------------------------------------------------------------------+
Deprecated.
+-----------------------------------------------------------------------------+
| 16.5. ArrayType DDLParser::StructValueInfo::GetArrayType() const |
+-----------------------------------------------------------------------------+
Returns the array type of the field. Possible values are DDLParser::kScalar
(the field is not an array), DDLParser::kFixed (the field is an array with a
fixed dimension), DDLParser::kDynamic (the field is an array without an
specified dimention) and DDLParser::kHashmap (the field is a hashmap), from the
DDLParser::ArrayType enumeration.
+-----------------------------------------------------------------------------+
| 16.6. DDLParser::StructFieldValue* DDLParser::StructValueInfo::GetValue() const |
+-----------------------------------------------------------------------------+
Returns the array of default values for the field. If the field hasn't a
default value, it returns NULL. Only scalar and fixed array types of fields can
have a default value. In the former, only the first position of the array of
values is valid. In the later, the array of values is valid from 0 to
DDLParser::StructValueInfo::GetCount.
+-----------------------------------------------------------------------------+
| 16.7. uint32_t DDLParser::StructValueInfo::GetCount() const |
+-----------------------------------------------------------------------------+
Returns the size of the array if the array is fixed. Always returns one for
scalars and zero for dynamic arrays and hashmaps.
+-----------------------------------------------------------------------------+
| 16.8. uint32_t DDLParser::StructValueInfo::GetKeyType() const |
+-----------------------------------------------------------------------------+
Returns the DDL type of a hashmap key. If the field is not a hashmap, this
method doesn't return anything meaningful.
+-----------------------------------------------------------------------------+
| 16.9. int DDLParser::StructValueInfo::GetKeyBitSize() const |
+-----------------------------------------------------------------------------+
Convenience method that returns the bit size of the hashmap key. Returns 64 for
DDLParser::kInt64, DDLParser::kUint64, DDLParser::kFloat64, and
DDLParser::kTuid, and 32 for all other types.
+-----------------------------------------------------------------------------+
| 16.10. bool DDLParser::StructValueInfo::AllowSubStruct() const |
+-----------------------------------------------------------------------------+
Convenience method that returns true if the field was tagged with the tag(
AllowSubstruct )' generic tag.
+-----------------------------------------------------------------------------+
| 16.11. uint32_t DDLParser::StructValueInfo::GetSchemaCrc() const |
+-----------------------------------------------------------------------------+
The schema crc reflects the type, count, and name of the field. If any of those
change, then the crc changes. It does not reflect default values or any tags.
+-----------------------------------------------------------------------------+
| 16.12. DDLParser::Aggregate* DDLParser::StructValueInfo::GetAggregate( Definition* ddl ) const' |
+-----------------------------------------------------------------------------+
Returns the aggregate which is the type of the field. If the field has not a
select, bitfield or structure as its type, this method returns NULL.
+-----------------------------------------------------------------------------+
| 17. DDLParser::StructFieldValue |
+-----------------------------------------------------------------------------+
DDLParser::StructFieldValue is an union which holds the values defined for
fields.
union DDLParser::StructFieldValue
{
uint8_t m_Uint8[ 0 ];
uint16_t m_Uint16[ 0 ];
uint32_t m_Uint32[ 0 ];
uint64_t m_Uint64[ 0 ];
int8_t m_Int8[ 0 ];
int16_t m_Int16[ 0 ];
int32_t m_Int32[ 0 ];
int64_t m_Int64[ 0 ];
float m_Float32[ 0 ];
double m_Float64[ 0 ];
String m_String[ 0 ];
uint32_t m_Select[ 0 ];
StructBitfieldValuePtr m_Bitfield[ 0 ];
StructStructValuePtr m_Struct[ 0 ];
StructUnknownValuePtr m_Unknown[ 0 ]; // Deprecated
uint8_t m_Boolean[ 0 ];
String m_File[ 0 ];
uint64_t m_Tuid[ 0 ];
String m_Json[ 0 ];
};
When a field's DDLParser::StructValueInfo has a pointer to a
DDLParser::StructFieldValue (via DDLParser::StructValueInfo::GetValue), it
means the field has default values. The member of the union that is to be
accessed depends on DDLParser::StructValueInfo::GetType, and how many entries
are valid depends on the field's array type. For DDLParser::kScalar fields, one
position only is valid. For DDLParser::kFixed fields, positions from zero to
DDLParser::StructValueInfo::GetCount - 1 are valid. DDLParser::kDynamic and
DDLParser::kHashmap fields don't have default values.
+-----------------------------------------------------------------------------+
| 18. DDLParser::StructBitfieldValue |
+-----------------------------------------------------------------------------+
When a field is of a bitfield type and has a default value, this value is held
in the m_Bitfield member of the DDLParser::StructFieldValue union. It has the
following methods:
+-----------------------------------------------------------------------------+
| 18.1. uint32_t DDLParser::StructBitfieldValue::GetCount() const |
+-----------------------------------------------------------------------------+
Returns the number of flags that make the default value of the field.
+-----------------------------------------------------------------------------+
| 18.2. uint32_t DDLParser::StructBitfieldValue::GetHash( uint32_t index ) const |
+-----------------------------------------------------------------------------+
Returns the hash of the flag at the given index. This hash can be used to get
the actual flag from the bitfield via DDLParser::Bitfield::FindFlag.
+-----------------------------------------------------------------------------+
| 19. DDLParser::StructStructValue |
+-----------------------------------------------------------------------------+
When a field is of a structure type and has a default value, it's default value
is held in the m_Struct member of the DDLParser::StructFieldValue union. For
each field receiving a default value, DDLParser::StructStructValue has a
DDLParser::StructValueInfo with details of which field is being initialized and
what value it's receiving.
DDLParser::StructStructValue has the following methods:
+-----------------------------------------------------------------------------+
| 19.1. uint32_t DDLParser::StructStructValue::GetCount() const |
+-----------------------------------------------------------------------------+
Returns the number of value infos in this structure value.
+-----------------------------------------------------------------------------+
| 19.2. DDLParser::StructValueInfo* DDLParser::StructStructValue::GetValueInfo( uint32_t index ) const |
+-----------------------------------------------------------------------------+
Returns the value info at the given index.
+-----------------------------------------------------------------------------+
| 19.3. Example |
+-----------------------------------------------------------------------------+
struct A
{
uint32_t a, value( 1 );
uint32_t b;
}
struct B
{
uint32_t[ 2 ] c, value( { 1, 2 } );
uint32_t[] d;
string{ uint32_t } f;
A g, value( { a = 2 } );
}
The DDLParser::StructValueInfo for the fields declared in the DDL code above
are:
-------------------------------------------------------------------------------
| A.a |
-------------------------------------------------------------------------------
| Method | Return Value | Meaning |
-------------------------------------------------------------------------------
| GetNameHash() | 0x0136c985 | DDLParser::StringCrc32 of a, the field |
| | | name. |
-------------------------------------------------------------------------------
| GetType() | 2 | DDLParser::kUint32. |
-------------------------------------------------------------------------------
| GetTypeNameHash() | 0x0d5d2ca7 | DDLParser::StringCrc32 of uint32_t, but |
| | | meaningless. |
-------------------------------------------------------------------------------
| GetArrayType() | 0 | DDLParser::kScalar. |
-------------------------------------------------------------------------------
| GetValue() | 0x009d0074 | The address of the |
| | | DDLParser::StructFieldValue, since this |
| | | field has a default value defined for |