@@ -22,6 +22,7 @@ def __init__(
22
22
package : str ,
23
23
copyright_ : Optional [str ],
24
24
parser_info : Optional [str ],
25
+ salad_version : str ,
25
26
) -> None :
26
27
"""Initialize the D codegen."""
27
28
super ().__init__ ()
@@ -31,6 +32,7 @@ def __init__(
31
32
self .package = package
32
33
self .copyright = copyright_
33
34
self .parser_info = parser_info
35
+ self .salad_version = salad_version
34
36
self .doc_root_types : List [str ] = []
35
37
36
38
def prologue (self ) -> None :
@@ -60,11 +62,11 @@ def prologue(self) -> None:
60
62
f"""module { self .package } ;
61
63
62
64
import salad.meta.dumper : genDumper;
63
- import salad.meta.impl : genCtor , genIdentifier, genOpEq;
65
+ import salad.meta.impl : genCtor_ , genIdentifier, genOpEq;
64
66
import salad.meta.parser : import_ = importFromURI;
65
67
import salad.meta.uda : documentRoot, id, idMap, link, LinkResolver, secondaryFilesDSL, typeDSL;
66
68
import salad.primitives : SchemaBase;
67
- import salad.type : None, Either ;
69
+ import salad.type : None, Union ;
68
70
69
71
"""
70
72
)
@@ -75,10 +77,21 @@ def prologue(self) -> None:
75
77
""" # noqa: B907
76
78
)
77
79
80
+ self .target .write (
81
+ f"""
82
+ enum saladVersion = "{ self .salad_version } ";
83
+
84
+ mixin template genCtor()
85
+ {{
86
+ mixin genCtor_!saladVersion;
87
+ }}
88
+ """
89
+ )
90
+
78
91
def epilogue (self , root_loader : TypeDef ) -> None :
79
92
"""Trigger to generate the epilouge code."""
80
93
doc_root_type_str = ", " .join (self .doc_root_types )
81
- doc_root_type = f"Either !({ doc_root_type_str } )"
94
+ doc_root_type = f"Union !({ doc_root_type_str } )"
82
95
self .target .write (
83
96
f"""
84
97
///
@@ -185,7 +198,7 @@ def parse_record_field_type(
185
198
elif isinstance (type_ , list ):
186
199
t_str = [self .parse_record_field_type (t , None )[1 ] for t in type_ ]
187
200
union_types = ", " .join (t_str )
188
- type_str = f"Either !({ union_types } )"
201
+ type_str = f"Union !({ union_types } )"
189
202
elif shortname (type_ ["type" ]) == "array" :
190
203
item_type = self .parse_record_field_type (type_ ["items" ], None )[1 ]
191
204
type_str = f"{ item_type } []"
0 commit comments