From e6c99ae4e2e8c37359d1de4f139c2ca31af27641 Mon Sep 17 00:00:00 2001 From: rzvxa Date: Mon, 24 Jun 2024 20:12:56 +0330 Subject: [PATCH] feat(ast_codegen): generate `ast_kind.rs`. --- crates/oxc_ast/src/generated/ast_kind.rs | 461 +++++++++++++++++++ crates/oxc_ast/src/lib.rs | 4 +- crates/oxc_ast/src/visit/visit.rs | 2 +- crates/oxc_ast/src/visit/visit_mut.rs | 2 +- tasks/ast_codegen/src/generators/ast_kind.rs | 27 +- tasks/ast_codegen/src/generators/mod.rs | 2 +- tasks/ast_codegen/src/main.rs | 17 +- 7 files changed, 503 insertions(+), 12 deletions(-) create mode 100644 crates/oxc_ast/src/generated/ast_kind.rs diff --git a/crates/oxc_ast/src/generated/ast_kind.rs b/crates/oxc_ast/src/generated/ast_kind.rs new file mode 100644 index 00000000000000..93b72c74316f8c --- /dev/null +++ b/crates/oxc_ast/src/generated/ast_kind.rs @@ -0,0 +1,461 @@ +// Auto-generated code, DO NOT EDIT DIRECTLY! +// To edit this generated file you have to edit `tasks/ast_codegen/src/generators/ast_kind.rs` + +use crate::ast::*; +#[derive(Debug, Clone, Copy)] +pub enum AstType { + BooleanLiteral, + NullLiteral, + NumericLiteral, + BigIntLiteral, + RegExpLiteral, + StringLiteral, + Program, + Expression, + IdentifierName, + IdentifierReference, + BindingIdentifier, + LabelIdentifier, + ThisExpression, + ArrayExpression, + ArrayExpressionElement, + Elision, + ObjectExpression, + ObjectPropertyKind, + ObjectProperty, + PropertyKey, + TemplateLiteral, + TaggedTemplateExpression, + TemplateElement, + MemberExpression, + ComputedMemberExpression, + StaticMemberExpression, + PrivateFieldExpression, + CallExpression, + NewExpression, + MetaProperty, + SpreadElement, + Argument, + UpdateExpression, + UnaryExpression, + BinaryExpression, + PrivateInExpression, + LogicalExpression, + ConditionalExpression, + AssignmentExpression, + AssignmentTarget, + SimpleAssignmentTarget, + AssignmentTargetPattern, + ArrayAssignmentTarget, + ObjectAssignmentTarget, + AssignmentTargetRest, + AssignmentTargetMaybeDefault, + AssignmentTargetWithDefault, + AssignmentTargetProperty, + AssignmentTargetPropertyIdentifier, + AssignmentTargetPropertyProperty, + SequenceExpression, + Super, + AwaitExpression, + ChainExpression, + ChainElement, + ParenthesizedExpression, + Statement, + Directive, + Hashbang, + BlockStatement, + Declaration, + VariableDeclaration, + VariableDeclarator, + UsingDeclaration, + EmptyStatement, + ExpressionStatement, + IfStatement, + DoWhileStatement, + WhileStatement, + ForStatement, + ForStatementInit, + ForInStatement, + ForStatementLeft, + ForOfStatement, + ContinueStatement, + BreakStatement, + ReturnStatement, + WithStatement, + SwitchStatement, + SwitchCase, + LabeledStatement, + ThrowStatement, + TryStatement, + CatchClause, + CatchParameter, + DebuggerStatement, + BindingPattern, + BindingPatternKind, + AssignmentPattern, + ObjectPattern, + BindingProperty, + ArrayPattern, + BindingRestElement, + Function, + FormalParameters, + FormalParameter, + FunctionBody, + ArrowFunctionExpression, + YieldExpression, + Class, + ClassBody, + ClassElement, + MethodDefinition, + PropertyDefinition, + PrivateIdentifier, + StaticBlock, + ModuleDeclaration, + AccessorProperty, + ImportExpression, + ImportDeclaration, + ImportDeclarationSpecifier, + ImportSpecifier, + ImportDefaultSpecifier, + ImportNamespaceSpecifier, + WithClause, + ImportAttribute, + ImportAttributeKey, + ExportNamedDeclaration, + ExportDefaultDeclaration, + ExportAllDeclaration, + ExportSpecifier, + ExportDefaultDeclarationKind, + ModuleExportName, + TSThisParameter, + TSEnumDeclaration, + TSEnumMember, + TSEnumMemberName, + TSTypeAnnotation, + TSLiteralType, + TSLiteral, + TSType, + TSConditionalType, + TSUnionType, + TSIntersectionType, + TSTypeOperator, + TSArrayType, + TSIndexedAccessType, + TSTupleType, + TSNamedTupleMember, + TSOptionalType, + TSRestType, + TSTupleElement, + TSAnyKeyword, + TSStringKeyword, + TSBooleanKeyword, + TSNumberKeyword, + TSNeverKeyword, + TSIntrinsicKeyword, + TSUnknownKeyword, + TSNullKeyword, + TSUndefinedKeyword, + TSVoidKeyword, + TSSymbolKeyword, + TSThisType, + TSObjectKeyword, + TSBigIntKeyword, + TSTypeReference, + TSTypeName, + TSQualifiedName, + TSTypeParameterInstantiation, + TSTypeParameter, + TSTypeParameterDeclaration, + TSTypeAliasDeclaration, + TSClassImplements, + TSInterfaceDeclaration, + TSInterfaceBody, + TSPropertySignature, + TSSignature, + TSIndexSignature, + TSCallSignatureDeclaration, + TSMethodSignature, + TSConstructSignatureDeclaration, + TSIndexSignatureName, + TSInterfaceHeritage, + TSTypePredicate, + TSTypePredicateName, + TSModuleDeclaration, + TSModuleDeclarationName, + TSModuleDeclarationBody, + TSModuleBlock, + TSTypeLiteral, + TSInferType, + TSTypeQuery, + TSTypeQueryExprName, + TSImportType, + TSImportAttributes, + TSImportAttribute, + TSImportAttributeName, + TSFunctionType, + TSConstructorType, + TSMappedType, + TSTemplateLiteralType, + TSAsExpression, + TSSatisfiesExpression, + TSTypeAssertion, + TSImportEqualsDeclaration, + TSModuleReference, + TSExternalModuleReference, + TSNonNullExpression, + Decorator, + TSExportAssignment, + TSNamespaceExportDeclaration, + TSInstantiationExpression, + JSDocNullableType, + JSDocUnknownType, + JSXElement, + JSXOpeningElement, + JSXClosingElement, + JSXFragment, + JSXElementName, + JSXNamespacedName, + JSXMemberExpression, + JSXMemberExpressionObject, + JSXExpressionContainer, + JSXExpression, + JSXEmptyExpression, + JSXAttributeItem, + JSXAttribute, + JSXSpreadAttribute, + JSXAttributeName, + JSXAttributeValue, + JSXIdentifier, + JSXChild, + JSXSpreadChild, + JSXText, +} +/// Untyped AST Node Kind +#[derive(Debug, Clone, Copy)] +pub enum AstKind<'a> { + BooleanLiteral(&'a BooleanLiteral), + NullLiteral(&'a NullLiteral), + NumericLiteral(&'a NumericLiteral<'a>), + BigIntLiteral(&'a BigIntLiteral<'a>), + RegExpLiteral(&'a RegExpLiteral<'a>), + StringLiteral(&'a StringLiteral<'a>), + Program(&'a Program<'a>), + Expression(&'a Expression<'a>), + IdentifierName(&'a IdentifierName<'a>), + IdentifierReference(&'a IdentifierReference<'a>), + BindingIdentifier(&'a BindingIdentifier<'a>), + LabelIdentifier(&'a LabelIdentifier<'a>), + ThisExpression(&'a ThisExpression), + ArrayExpression(&'a ArrayExpression<'a>), + ArrayExpressionElement(&'a ArrayExpressionElement<'a>), + Elision(&'a Elision), + ObjectExpression(&'a ObjectExpression<'a>), + ObjectPropertyKind(&'a ObjectPropertyKind<'a>), + ObjectProperty(&'a ObjectProperty<'a>), + PropertyKey(&'a PropertyKey<'a>), + TemplateLiteral(&'a TemplateLiteral<'a>), + TaggedTemplateExpression(&'a TaggedTemplateExpression<'a>), + TemplateElement(&'a TemplateElement<'a>), + MemberExpression(&'a MemberExpression<'a>), + ComputedMemberExpression(&'a ComputedMemberExpression<'a>), + StaticMemberExpression(&'a StaticMemberExpression<'a>), + PrivateFieldExpression(&'a PrivateFieldExpression<'a>), + CallExpression(&'a CallExpression<'a>), + NewExpression(&'a NewExpression<'a>), + MetaProperty(&'a MetaProperty<'a>), + SpreadElement(&'a SpreadElement<'a>), + Argument(&'a Argument<'a>), + UpdateExpression(&'a UpdateExpression<'a>), + UnaryExpression(&'a UnaryExpression<'a>), + BinaryExpression(&'a BinaryExpression<'a>), + PrivateInExpression(&'a PrivateInExpression<'a>), + LogicalExpression(&'a LogicalExpression<'a>), + ConditionalExpression(&'a ConditionalExpression<'a>), + AssignmentExpression(&'a AssignmentExpression<'a>), + AssignmentTarget(&'a AssignmentTarget<'a>), + SimpleAssignmentTarget(&'a SimpleAssignmentTarget<'a>), + AssignmentTargetPattern(&'a AssignmentTargetPattern<'a>), + ArrayAssignmentTarget(&'a ArrayAssignmentTarget<'a>), + ObjectAssignmentTarget(&'a ObjectAssignmentTarget<'a>), + AssignmentTargetRest(&'a AssignmentTargetRest<'a>), + AssignmentTargetMaybeDefault(&'a AssignmentTargetMaybeDefault<'a>), + AssignmentTargetWithDefault(&'a AssignmentTargetWithDefault<'a>), + AssignmentTargetProperty(&'a AssignmentTargetProperty<'a>), + AssignmentTargetPropertyIdentifier(&'a AssignmentTargetPropertyIdentifier<'a>), + AssignmentTargetPropertyProperty(&'a AssignmentTargetPropertyProperty<'a>), + SequenceExpression(&'a SequenceExpression<'a>), + Super(&'a Super), + AwaitExpression(&'a AwaitExpression<'a>), + ChainExpression(&'a ChainExpression<'a>), + ChainElement(&'a ChainElement<'a>), + ParenthesizedExpression(&'a ParenthesizedExpression<'a>), + Statement(&'a Statement<'a>), + Directive(&'a Directive<'a>), + Hashbang(&'a Hashbang<'a>), + BlockStatement(&'a BlockStatement<'a>), + Declaration(&'a Declaration<'a>), + VariableDeclaration(&'a VariableDeclaration<'a>), + VariableDeclarator(&'a VariableDeclarator<'a>), + UsingDeclaration(&'a UsingDeclaration<'a>), + EmptyStatement(&'a EmptyStatement), + ExpressionStatement(&'a ExpressionStatement<'a>), + IfStatement(&'a IfStatement<'a>), + DoWhileStatement(&'a DoWhileStatement<'a>), + WhileStatement(&'a WhileStatement<'a>), + ForStatement(&'a ForStatement<'a>), + ForStatementInit(&'a ForStatementInit<'a>), + ForInStatement(&'a ForInStatement<'a>), + ForStatementLeft(&'a ForStatementLeft<'a>), + ForOfStatement(&'a ForOfStatement<'a>), + ContinueStatement(&'a ContinueStatement<'a>), + BreakStatement(&'a BreakStatement<'a>), + ReturnStatement(&'a ReturnStatement<'a>), + WithStatement(&'a WithStatement<'a>), + SwitchStatement(&'a SwitchStatement<'a>), + SwitchCase(&'a SwitchCase<'a>), + LabeledStatement(&'a LabeledStatement<'a>), + ThrowStatement(&'a ThrowStatement<'a>), + TryStatement(&'a TryStatement<'a>), + CatchClause(&'a CatchClause<'a>), + CatchParameter(&'a CatchParameter<'a>), + DebuggerStatement(&'a DebuggerStatement), + BindingPattern(&'a BindingPattern<'a>), + BindingPatternKind(&'a BindingPatternKind<'a>), + AssignmentPattern(&'a AssignmentPattern<'a>), + ObjectPattern(&'a ObjectPattern<'a>), + BindingProperty(&'a BindingProperty<'a>), + ArrayPattern(&'a ArrayPattern<'a>), + BindingRestElement(&'a BindingRestElement<'a>), + Function(&'a Function<'a>), + FormalParameters(&'a FormalParameters<'a>), + FormalParameter(&'a FormalParameter<'a>), + FunctionBody(&'a FunctionBody<'a>), + ArrowFunctionExpression(&'a ArrowFunctionExpression<'a>), + YieldExpression(&'a YieldExpression<'a>), + Class(&'a Class<'a>), + ClassBody(&'a ClassBody<'a>), + ClassElement(&'a ClassElement<'a>), + MethodDefinition(&'a MethodDefinition<'a>), + PropertyDefinition(&'a PropertyDefinition<'a>), + PrivateIdentifier(&'a PrivateIdentifier<'a>), + StaticBlock(&'a StaticBlock<'a>), + ModuleDeclaration(&'a ModuleDeclaration<'a>), + AccessorProperty(&'a AccessorProperty<'a>), + ImportExpression(&'a ImportExpression<'a>), + ImportDeclaration(&'a ImportDeclaration<'a>), + ImportDeclarationSpecifier(&'a ImportDeclarationSpecifier<'a>), + ImportSpecifier(&'a ImportSpecifier<'a>), + ImportDefaultSpecifier(&'a ImportDefaultSpecifier<'a>), + ImportNamespaceSpecifier(&'a ImportNamespaceSpecifier<'a>), + WithClause(&'a WithClause<'a>), + ImportAttribute(&'a ImportAttribute<'a>), + ImportAttributeKey(&'a ImportAttributeKey<'a>), + ExportNamedDeclaration(&'a ExportNamedDeclaration<'a>), + ExportDefaultDeclaration(&'a ExportDefaultDeclaration<'a>), + ExportAllDeclaration(&'a ExportAllDeclaration<'a>), + ExportSpecifier(&'a ExportSpecifier<'a>), + ExportDefaultDeclarationKind(&'a ExportDefaultDeclarationKind<'a>), + ModuleExportName(&'a ModuleExportName<'a>), + TSThisParameter(&'a TSThisParameter<'a>), + TSEnumDeclaration(&'a TSEnumDeclaration<'a>), + TSEnumMember(&'a TSEnumMember<'a>), + TSEnumMemberName(&'a TSEnumMemberName<'a>), + TSTypeAnnotation(&'a TSTypeAnnotation<'a>), + TSLiteralType(&'a TSLiteralType<'a>), + TSLiteral(&'a TSLiteral<'a>), + TSType(&'a TSType<'a>), + TSConditionalType(&'a TSConditionalType<'a>), + TSUnionType(&'a TSUnionType<'a>), + TSIntersectionType(&'a TSIntersectionType<'a>), + TSTypeOperator(&'a TSTypeOperator<'a>), + TSArrayType(&'a TSArrayType<'a>), + TSIndexedAccessType(&'a TSIndexedAccessType<'a>), + TSTupleType(&'a TSTupleType<'a>), + TSNamedTupleMember(&'a TSNamedTupleMember<'a>), + TSOptionalType(&'a TSOptionalType<'a>), + TSRestType(&'a TSRestType<'a>), + TSTupleElement(&'a TSTupleElement<'a>), + TSAnyKeyword(&'a TSAnyKeyword), + TSStringKeyword(&'a TSStringKeyword), + TSBooleanKeyword(&'a TSBooleanKeyword), + TSNumberKeyword(&'a TSNumberKeyword), + TSNeverKeyword(&'a TSNeverKeyword), + TSIntrinsicKeyword(&'a TSIntrinsicKeyword), + TSUnknownKeyword(&'a TSUnknownKeyword), + TSNullKeyword(&'a TSNullKeyword), + TSUndefinedKeyword(&'a TSUndefinedKeyword), + TSVoidKeyword(&'a TSVoidKeyword), + TSSymbolKeyword(&'a TSSymbolKeyword), + TSThisType(&'a TSThisType), + TSObjectKeyword(&'a TSObjectKeyword), + TSBigIntKeyword(&'a TSBigIntKeyword), + TSTypeReference(&'a TSTypeReference<'a>), + TSTypeName(&'a TSTypeName<'a>), + TSQualifiedName(&'a TSQualifiedName<'a>), + TSTypeParameterInstantiation(&'a TSTypeParameterInstantiation<'a>), + TSTypeParameter(&'a TSTypeParameter<'a>), + TSTypeParameterDeclaration(&'a TSTypeParameterDeclaration<'a>), + TSTypeAliasDeclaration(&'a TSTypeAliasDeclaration<'a>), + TSClassImplements(&'a TSClassImplements<'a>), + TSInterfaceDeclaration(&'a TSInterfaceDeclaration<'a>), + TSInterfaceBody(&'a TSInterfaceBody<'a>), + TSPropertySignature(&'a TSPropertySignature<'a>), + TSSignature(&'a TSSignature<'a>), + TSIndexSignature(&'a TSIndexSignature<'a>), + TSCallSignatureDeclaration(&'a TSCallSignatureDeclaration<'a>), + TSMethodSignature(&'a TSMethodSignature<'a>), + TSConstructSignatureDeclaration(&'a TSConstructSignatureDeclaration<'a>), + TSIndexSignatureName(&'a TSIndexSignatureName<'a>), + TSInterfaceHeritage(&'a TSInterfaceHeritage<'a>), + TSTypePredicate(&'a TSTypePredicate<'a>), + TSTypePredicateName(&'a TSTypePredicateName<'a>), + TSModuleDeclaration(&'a TSModuleDeclaration<'a>), + TSModuleDeclarationName(&'a TSModuleDeclarationName<'a>), + TSModuleDeclarationBody(&'a TSModuleDeclarationBody<'a>), + TSModuleBlock(&'a TSModuleBlock<'a>), + TSTypeLiteral(&'a TSTypeLiteral<'a>), + TSInferType(&'a TSInferType<'a>), + TSTypeQuery(&'a TSTypeQuery<'a>), + TSTypeQueryExprName(&'a TSTypeQueryExprName<'a>), + TSImportType(&'a TSImportType<'a>), + TSImportAttributes(&'a TSImportAttributes<'a>), + TSImportAttribute(&'a TSImportAttribute<'a>), + TSImportAttributeName(&'a TSImportAttributeName<'a>), + TSFunctionType(&'a TSFunctionType<'a>), + TSConstructorType(&'a TSConstructorType<'a>), + TSMappedType(&'a TSMappedType<'a>), + TSTemplateLiteralType(&'a TSTemplateLiteralType<'a>), + TSAsExpression(&'a TSAsExpression<'a>), + TSSatisfiesExpression(&'a TSSatisfiesExpression<'a>), + TSTypeAssertion(&'a TSTypeAssertion<'a>), + TSImportEqualsDeclaration(&'a TSImportEqualsDeclaration<'a>), + TSModuleReference(&'a TSModuleReference<'a>), + TSExternalModuleReference(&'a TSExternalModuleReference<'a>), + TSNonNullExpression(&'a TSNonNullExpression<'a>), + Decorator(&'a Decorator<'a>), + TSExportAssignment(&'a TSExportAssignment<'a>), + TSNamespaceExportDeclaration(&'a TSNamespaceExportDeclaration<'a>), + TSInstantiationExpression(&'a TSInstantiationExpression<'a>), + JSDocNullableType(&'a JSDocNullableType<'a>), + JSDocUnknownType(&'a JSDocUnknownType), + JSXElement(&'a JSXElement<'a>), + JSXOpeningElement(&'a JSXOpeningElement<'a>), + JSXClosingElement(&'a JSXClosingElement<'a>), + JSXFragment(&'a JSXFragment<'a>), + JSXElementName(&'a JSXElementName<'a>), + JSXNamespacedName(&'a JSXNamespacedName<'a>), + JSXMemberExpression(&'a JSXMemberExpression<'a>), + JSXMemberExpressionObject(&'a JSXMemberExpressionObject<'a>), + JSXExpressionContainer(&'a JSXExpressionContainer<'a>), + JSXExpression(&'a JSXExpression<'a>), + JSXEmptyExpression(&'a JSXEmptyExpression), + JSXAttributeItem(&'a JSXAttributeItem<'a>), + JSXAttribute(&'a JSXAttribute<'a>), + JSXSpreadAttribute(&'a JSXSpreadAttribute<'a>), + JSXAttributeName(&'a JSXAttributeName<'a>), + JSXAttributeValue(&'a JSXAttributeValue<'a>), + JSXIdentifier(&'a JSXIdentifier<'a>), + JSXChild(&'a JSXChild<'a>), + JSXSpreadChild(&'a JSXSpreadChild<'a>), + JSXText(&'a JSXText<'a>), +} diff --git a/crates/oxc_ast/src/lib.rs b/crates/oxc_ast/src/lib.rs index ca9db3b327afd0..c5ccdfb83c6311 100644 --- a/crates/oxc_ast/src/lib.rs +++ b/crates/oxc_ast/src/lib.rs @@ -15,16 +15,18 @@ mod serialize; pub mod ast; mod ast_builder; mod ast_impl; -mod ast_kind; pub mod precedence; pub mod syntax_directed_operations; mod trivia; pub mod visit; mod generated { + pub mod ast_kind; pub mod span; } +pub use generated::ast_kind; + pub use num_bigint::BigUint; pub use crate::{ diff --git a/crates/oxc_ast/src/visit/visit.rs b/crates/oxc_ast/src/visit/visit.rs index 022a7a887000e9..6cce44f9ff84c1 100644 --- a/crates/oxc_ast/src/visit/visit.rs +++ b/crates/oxc_ast/src/visit/visit.rs @@ -2316,7 +2316,7 @@ pub mod walk { } pub fn walk_bigint_literal<'a, V: Visit<'a>>(visitor: &mut V, lit: &BigIntLiteral<'a>) { - let kind = AstKind::BigintLiteral(visitor.alloc(lit)); + let kind = AstKind::BigIntLiteral(visitor.alloc(lit)); visitor.enter_node(kind); visitor.leave_node(kind); } diff --git a/crates/oxc_ast/src/visit/visit_mut.rs b/crates/oxc_ast/src/visit/visit_mut.rs index e39c0aa5e6b3c9..d58e3a9d6d4c49 100644 --- a/crates/oxc_ast/src/visit/visit_mut.rs +++ b/crates/oxc_ast/src/visit/visit_mut.rs @@ -2402,7 +2402,7 @@ pub mod walk_mut { visitor: &mut V, _lit: &mut BigIntLiteral<'a>, ) { - let kind = AstType::BigintLiteral; + let kind = AstType::BigIntLiteral; visitor.enter_node(kind); visitor.leave_node(kind); } diff --git a/tasks/ast_codegen/src/generators/ast_kind.rs b/tasks/ast_codegen/src/generators/ast_kind.rs index 228500f80e9a39..79b539120518ff 100644 --- a/tasks/ast_codegen/src/generators/ast_kind.rs +++ b/tasks/ast_codegen/src/generators/ast_kind.rs @@ -3,6 +3,8 @@ use syn::{parse_quote, Variant}; use crate::{schema::RType, CodegenCtx, Generator, GeneratorOutput}; +use super::generated_header; + pub struct AstKindGenerator; impl Generator for AstKindGenerator { @@ -11,20 +13,37 @@ impl Generator for AstKindGenerator { } fn generate(&mut self, ctx: &CodegenCtx) -> GeneratorOutput { - let kinds: Vec = ctx + let (types, kinds): (Vec, Vec) = ctx .ty_table .iter() .filter_map(|maybe_kind| match &*maybe_kind.borrow() { - kind @ (RType::Enum(_) | RType::Struct(_)) => { + kind @ (RType::Enum(_) | RType::Struct(_)) if kind.visitable() => { let ident = kind.ident(); let typ = kind.as_type(); - Some(parse_quote!(#ident(#typ))) + Some((parse_quote!(#ident), parse_quote!(#ident(&'a #typ)))) } _ => None, }) - .collect_vec(); + .fold((Vec::new(), Vec::new()), |mut acc, it| { + acc.0.push(it.0); + acc.1.push(it.1); + acc + }); + + let header = generated_header!(); GeneratorOutput::One(parse_quote! { + #header + + use crate::ast::*; + + #[derive(Debug, Clone, Copy)] + pub enum AstType { + #(#types),* + } + + /// Untyped AST Node Kind + #[derive(Debug, Clone, Copy)] pub enum AstKind<'a> { #(#kinds),* } diff --git a/tasks/ast_codegen/src/generators/mod.rs b/tasks/ast_codegen/src/generators/mod.rs index a10ee0e605afee..1c9981b8edc9db 100644 --- a/tasks/ast_codegen/src/generators/mod.rs +++ b/tasks/ast_codegen/src/generators/mod.rs @@ -28,7 +28,7 @@ macro_rules! generated_header { "// To edit this generated file you have to edit `{file}`" )); // TODO add generation date, AST source hash, etc here. - quote! { + quote::quote! { insert!("// Auto-generated code, DO NOT EDIT DIRECTLY!"); #edit_comment endl!(); diff --git a/tasks/ast_codegen/src/main.rs b/tasks/ast_codegen/src/main.rs index 7529f1a9e03bb8..fbb40a4e40dffd 100644 --- a/tasks/ast_codegen/src/main.rs +++ b/tasks/ast_codegen/src/main.rs @@ -197,13 +197,22 @@ fn main() -> std::result::Result<(), Box> { let output_dir = output_dir()?; let outputs: HashMap<_, _> = outputs.into_iter().collect(); - { - let span_path = format!("{output_dir}/span.rs"); - let mut span_file = fs::File::create(span_path)?; + { // write `span.rs` file + let path = format!("{output_dir}/span.rs"); + let mut file = fs::File::create(path)?; let output = outputs[ImplGetSpanGenerator.name()].as_one(); let span_content = pprint(output); - span_file.write_all(span_content.as_bytes())?; + file.write_all(span_content.as_bytes())?; + } + + { // write `ast_kind.rs` file + let path = format!("{output_dir}/ast_kind.rs"); + let mut file = fs::File::create(path)?; + let output = outputs[AstKindGenerator.name()].as_one(); + let span_content = pprint(output); + + file.write_all(span_content.as_bytes())?; } // println!("{}", outputs[CountUnvisited.name()].clone().as_info());