@@ -17,7 +17,7 @@ use proc_macro2::{Ident, TokenStream};
17
17
use quote:: { quote, ToTokens } ;
18
18
19
19
pub fn make_enums ( enums : & [ domain:: Enum ] ) -> TokenStream {
20
- let definitions = enums. iter ( ) . map ( Enum :: to_declaration ) ;
20
+ let definitions = enums. iter ( ) . map ( Enum :: to_definition ) ;
21
21
22
22
quote ! {
23
23
#( #definitions ) *
@@ -26,17 +26,20 @@ pub fn make_enums(enums: &[domain::Enum]) -> TokenStream {
26
26
27
27
/// Codegen methods.
28
28
impl domain:: Enum {
29
- /// Creates a declaration of this enum.
29
+ /// Creates a definition of this enum.
30
30
///
31
31
/// This will also implement all relevant traits and generate appropriate constants for each enumerator.
32
- pub fn to_declaration ( & self ) -> TokenStream {
32
+ pub fn to_definition ( & self ) -> TokenStream {
33
33
// Things needed for the type definition
34
34
let derives = self . derives ( ) ;
35
35
let enum_doc = self . enum_doc ( ) ;
36
36
let name = & self . name ;
37
37
38
38
// Values
39
- let enumerators = self . to_const_declarations ( ) ;
39
+ let enumerators = self
40
+ . enumerators
41
+ . iter ( )
42
+ . map ( |enumerator| enumerator. to_definition ( name. clone ( ) . into_token_stream ( ) ) ) ;
40
43
41
44
// Trait implementations
42
45
let engine_trait_impl = self . to_engine_trait_impl ( ) ;
@@ -56,7 +59,7 @@ impl domain::Enum {
56
59
}
57
60
58
61
impl #name {
59
- #enumerators
62
+ #( # enumerators ) *
60
63
}
61
64
62
65
#engine_trait_impl
@@ -135,19 +138,6 @@ impl domain::Enum {
135
138
}
136
139
}
137
140
138
- /// Creates declarations for all the constants of this enum.
139
- fn to_const_declarations ( & self ) -> TokenStream {
140
- let declarations = self
141
- . enumerators
142
- . iter ( )
143
- . map ( |field| field. to_const_declaration ( ( & self . name ) . into_token_stream ( ) ) )
144
- . collect :: < Vec < _ > > ( ) ;
145
-
146
- quote ! {
147
- #( #declarations ) *
148
- }
149
- }
150
-
151
141
/// Creates implementations for any bitwise operators.
152
142
///
153
143
/// Currently this is just [`BitOr`](std::ops::BitOr) for bitfields but that could be expanded in the future.
@@ -196,13 +186,13 @@ impl domain::Enum {
196
186
197
187
/// Codegen methods.
198
188
impl domain:: Enumerator {
199
- /// Creates a `const` declaration for self of the type `enum_type`.
189
+ /// Creates a `const` definition for self of the type `enum_type`.
200
190
///
201
- /// That is, it'll be a declaration like
191
+ /// That is, it'll be a definition like
202
192
/// ```ignore
203
193
/// pub const NAME: enum_type = ..;
204
194
/// ```
205
- fn to_const_declaration ( & self , enum_type : TokenStream ) -> TokenStream {
195
+ fn to_definition ( & self , enum_type : TokenStream ) -> TokenStream {
206
196
let Self {
207
197
name,
208
198
godot_name,
0 commit comments