Skip to content

Commit 47bf175

Browse files
committed
foo
1 parent b622954 commit 47bf175

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

godot-codegen/src/generator/central_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn make_global_enums(api: &ExtensionApi) -> Vec<TokenStream> {
265265
continue;
266266
}
267267

268-
let def = enum_.to_declaration();
268+
let def = enum_.to_definition();
269269
global_enum_defs.push(def);
270270
}
271271

godot-codegen/src/generator/enums.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use proc_macro2::{Ident, TokenStream};
1717
use quote::{quote, ToTokens};
1818

1919
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);
2121

2222
quote! {
2323
#( #definitions )*
@@ -26,17 +26,20 @@ pub fn make_enums(enums: &[domain::Enum]) -> TokenStream {
2626

2727
/// Codegen methods.
2828
impl domain::Enum {
29-
/// Creates a declaration of this enum.
29+
/// Creates a definition of this enum.
3030
///
3131
/// 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 {
3333
// Things needed for the type definition
3434
let derives = self.derives();
3535
let enum_doc = self.enum_doc();
3636
let name = &self.name;
3737

3838
// 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()));
4043

4144
// Trait implementations
4245
let engine_trait_impl = self.to_engine_trait_impl();
@@ -56,7 +59,7 @@ impl domain::Enum {
5659
}
5760

5861
impl #name {
59-
#enumerators
62+
#( #enumerators )*
6063
}
6164

6265
#engine_trait_impl
@@ -135,19 +138,6 @@ impl domain::Enum {
135138
}
136139
}
137140

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-
151141
/// Creates implementations for any bitwise operators.
152142
///
153143
/// 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 {
196186

197187
/// Codegen methods.
198188
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`.
200190
///
201-
/// That is, it'll be a declaration like
191+
/// That is, it'll be a definition like
202192
/// ```ignore
203193
/// pub const NAME: enum_type = ..;
204194
/// ```
205-
fn to_const_declaration(&self, enum_type: TokenStream) -> TokenStream {
195+
fn to_definition(&self, enum_type: TokenStream) -> TokenStream {
206196
let Self {
207197
name,
208198
godot_name,

0 commit comments

Comments
 (0)