Skip to content

Commit 5d8fc44

Browse files
author
Cameron McHenry
committed
feat(ast): compute max value that can be mapped to AstType
1 parent c7889c3 commit 5d8fc44

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ pub enum AstType {
203203
JSDocUnknownType = 186,
204204
}
205205

206+
/// The largest `usize` value that can be mapped to an `AstType`.
207+
pub const AST_TYPE_MAX: usize = 186usize;
208+
206209
/// Untyped AST Node Kind
207210
#[derive(Debug, Clone, Copy)]
208211
#[repr(C, u8)]

tasks/ast_tools/src/generators/ast_kind.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl Generator for AstKindGenerator {
8787
let mut span_match_arms = quote!();
8888
let mut address_match_arms = quote!();
8989
let mut as_methods = quote!();
90+
let mut ast_type_max_usize: usize = 0;
9091

9192
let mut next_index = 0u16;
9293
for type_def in &schema.types {
@@ -104,6 +105,7 @@ impl Generator for AstKindGenerator {
104105

105106
assert!(u8::try_from(next_index).is_ok());
106107
let index = number_lit(next_index);
108+
ast_type_max_usize = next_index as usize;
107109
type_variants.extend(quote!( #type_ident = #index, ));
108110
kind_variants.extend(quote!( #type_ident(&'a #type_ty) = AstType::#type_ident as u8, ));
109111

@@ -152,6 +154,10 @@ impl Generator for AstKindGenerator {
152154
#type_variants
153155
}
154156

157+
///@@line_break
158+
/// The largest `usize` value that can be mapped to an `AstType`.
159+
pub const AST_TYPE_MAX: usize = #ast_type_max_usize;
160+
155161
///@@line_break
156162
/// Untyped AST Node Kind
157163
#[derive(Debug, Clone, Copy)]

0 commit comments

Comments
 (0)