mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(ast_tools): generate layout assertions in multiple crates (#9448)
Generate layout assertions in each of the crates containing types tagged `#[ast]`, instead of all the assertions being generated in `oxc_ast` crate.
This commit is contained in:
1 parent
9afbae07da
commit
dcff40c4f3
11 files changed
+548
-428
No files matched your search
@@ -25,13 +25,16 @@ src:
|
||||
- 'crates/oxc_ast_visit/src/generated/visit.rs'
|
||||
- 'crates/oxc_ast_visit/src/generated/visit_mut.rs'
|
||||
- 'crates/oxc_regular_expression/src/ast.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/assert_layouts.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_content_eq.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_estree.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_get_address.rs'
|
||||
- 'crates/oxc_span/src/generated/assert_layouts.rs'
|
||||
- 'crates/oxc_span/src/generated/derive_estree.rs'
|
||||
- 'crates/oxc_span/src/source_type/mod.rs'
|
||||
- 'crates/oxc_span/src/span.rs'
|
||||
- 'crates/oxc_syntax/src/generated/assert_layouts.rs'
|
||||
- 'crates/oxc_syntax/src/generated/derive_clone_in.rs'
|
||||
- 'crates/oxc_syntax/src/generated/derive_content_eq.rs'
|
||||
- 'crates/oxc_syntax/src/generated/derive_estree.rs'
|
||||
|
||||
Generated
-1
@@ -1586,7 +1586,6 @@ version = "0.53.0"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"cow-utils",
|
||||
"nonmax",
|
||||
"oxc_allocator",
|
||||
"oxc_ast_macros",
|
||||
"oxc_estree",
|
||||
|
||||
@@ -28,7 +28,6 @@ oxc_syntax = { workspace = true }
|
||||
|
||||
bitflags = { workspace = true }
|
||||
cow-utils = { workspace = true }
|
||||
nonmax = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/assert_layouts.rs`
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
use nonmax::NonMaxU32;
|
||||
|
||||
use oxc_regular_expression::ast::*;
|
||||
use oxc_syntax::{reference::ReferenceId, scope::ScopeId, symbol::SymbolId};
|
||||
|
||||
use crate::ast::*;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
@@ -1400,194 +1397,6 @@ const _: () = {
|
||||
assert!(offset_of!(Comment, position) == 13);
|
||||
assert!(offset_of!(Comment, preceded_by_newline) == 14);
|
||||
assert!(offset_of!(Comment, followed_by_newline) == 15);
|
||||
|
||||
assert!(size_of::<NonMaxU32>() == 4);
|
||||
assert!(align_of::<NonMaxU32>() == 4);
|
||||
|
||||
assert!(size_of::<NumberBase>() == 1);
|
||||
assert!(align_of::<NumberBase>() == 1);
|
||||
|
||||
assert!(size_of::<BigintBase>() == 1);
|
||||
assert!(align_of::<BigintBase>() == 1);
|
||||
|
||||
assert!(size_of::<AssignmentOperator>() == 1);
|
||||
assert!(align_of::<AssignmentOperator>() == 1);
|
||||
|
||||
assert!(size_of::<BinaryOperator>() == 1);
|
||||
assert!(align_of::<BinaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<LogicalOperator>() == 1);
|
||||
assert!(align_of::<LogicalOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UnaryOperator>() == 1);
|
||||
assert!(align_of::<UnaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UpdateOperator>() == 1);
|
||||
assert!(align_of::<UpdateOperator>() == 1);
|
||||
|
||||
assert!(size_of::<ScopeId>() == 4);
|
||||
assert!(align_of::<ScopeId>() == 4);
|
||||
|
||||
assert!(size_of::<SymbolId>() == 4);
|
||||
assert!(align_of::<SymbolId>() == 4);
|
||||
|
||||
assert!(size_of::<ReferenceId>() == 4);
|
||||
assert!(align_of::<ReferenceId>() == 4);
|
||||
|
||||
assert!(size_of::<Span>() == 8);
|
||||
assert!(align_of::<Span>() == 8);
|
||||
assert!(offset_of!(Span, start) == 0);
|
||||
assert!(offset_of!(Span, end) == 4);
|
||||
|
||||
assert!(size_of::<SourceType>() == 3);
|
||||
assert!(align_of::<SourceType>() == 1);
|
||||
|
||||
assert!(size_of::<Language>() == 1);
|
||||
assert!(align_of::<Language>() == 1);
|
||||
|
||||
assert!(size_of::<ModuleKind>() == 1);
|
||||
assert!(align_of::<ModuleKind>() == 1);
|
||||
|
||||
assert!(size_of::<LanguageVariant>() == 1);
|
||||
assert!(align_of::<LanguageVariant>() == 1);
|
||||
|
||||
assert!(size_of::<Pattern>() == 48);
|
||||
assert!(align_of::<Pattern>() == 8);
|
||||
assert!(offset_of!(Pattern, span) == 0);
|
||||
assert!(offset_of!(Pattern, body) == 8);
|
||||
|
||||
assert!(size_of::<Disjunction>() == 40);
|
||||
assert!(align_of::<Disjunction>() == 8);
|
||||
assert!(offset_of!(Disjunction, span) == 0);
|
||||
assert!(offset_of!(Disjunction, body) == 8);
|
||||
|
||||
assert!(size_of::<Alternative>() == 40);
|
||||
assert!(align_of::<Alternative>() == 8);
|
||||
assert!(offset_of!(Alternative, span) == 0);
|
||||
assert!(offset_of!(Alternative, body) == 8);
|
||||
|
||||
assert!(size_of::<Term>() == 16);
|
||||
assert!(align_of::<Term>() == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertion>() == 16);
|
||||
assert!(align_of::<BoundaryAssertion>() == 8);
|
||||
assert!(offset_of!(BoundaryAssertion, span) == 0);
|
||||
assert!(offset_of!(BoundaryAssertion, kind) == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertionKind>() == 1);
|
||||
assert!(align_of::<BoundaryAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<LookAroundAssertion>() == 56);
|
||||
assert!(align_of::<LookAroundAssertion>() == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, span) == 0);
|
||||
assert!(offset_of!(LookAroundAssertion, kind) == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, body) == 16);
|
||||
|
||||
assert!(size_of::<LookAroundAssertionKind>() == 1);
|
||||
assert!(align_of::<LookAroundAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<Quantifier>() == 56);
|
||||
assert!(align_of::<Quantifier>() == 8);
|
||||
assert!(offset_of!(Quantifier, span) == 0);
|
||||
assert!(offset_of!(Quantifier, min) == 8);
|
||||
assert!(offset_of!(Quantifier, max) == 16);
|
||||
assert!(offset_of!(Quantifier, greedy) == 32);
|
||||
assert!(offset_of!(Quantifier, body) == 40);
|
||||
|
||||
assert!(size_of::<Character>() == 16);
|
||||
assert!(align_of::<Character>() == 8);
|
||||
assert!(offset_of!(Character, span) == 0);
|
||||
assert!(offset_of!(Character, kind) == 8);
|
||||
assert!(offset_of!(Character, value) == 12);
|
||||
|
||||
assert!(size_of::<CharacterKind>() == 1);
|
||||
assert!(align_of::<CharacterKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassEscape>() == 16);
|
||||
assert!(align_of::<CharacterClassEscape>() == 8);
|
||||
assert!(offset_of!(CharacterClassEscape, span) == 0);
|
||||
assert!(offset_of!(CharacterClassEscape, kind) == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassEscapeKind>() == 1);
|
||||
assert!(align_of::<CharacterClassEscapeKind>() == 1);
|
||||
|
||||
assert!(size_of::<UnicodePropertyEscape>() == 48);
|
||||
assert!(align_of::<UnicodePropertyEscape>() == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
|
||||
assert!(offset_of!(UnicodePropertyEscape, negative) == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, strings) == 9);
|
||||
assert!(offset_of!(UnicodePropertyEscape, name) == 16);
|
||||
assert!(offset_of!(UnicodePropertyEscape, value) == 32);
|
||||
|
||||
assert!(size_of::<Dot>() == 8);
|
||||
assert!(align_of::<Dot>() == 8);
|
||||
assert!(offset_of!(Dot, span) == 0);
|
||||
|
||||
assert!(size_of::<CharacterClass>() == 48);
|
||||
assert!(align_of::<CharacterClass>() == 8);
|
||||
assert!(offset_of!(CharacterClass, span) == 0);
|
||||
assert!(offset_of!(CharacterClass, negative) == 8);
|
||||
assert!(offset_of!(CharacterClass, strings) == 9);
|
||||
assert!(offset_of!(CharacterClass, kind) == 10);
|
||||
assert!(offset_of!(CharacterClass, body) == 16);
|
||||
|
||||
assert!(size_of::<CharacterClassContentsKind>() == 1);
|
||||
assert!(align_of::<CharacterClassContentsKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassContents>() == 16);
|
||||
assert!(align_of::<CharacterClassContents>() == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassRange>() == 40);
|
||||
assert!(align_of::<CharacterClassRange>() == 8);
|
||||
assert!(offset_of!(CharacterClassRange, span) == 0);
|
||||
assert!(offset_of!(CharacterClassRange, min) == 8);
|
||||
assert!(offset_of!(CharacterClassRange, max) == 24);
|
||||
|
||||
assert!(size_of::<ClassStringDisjunction>() == 48);
|
||||
assert!(align_of::<ClassStringDisjunction>() == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, span) == 0);
|
||||
assert!(offset_of!(ClassStringDisjunction, strings) == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, body) == 16);
|
||||
|
||||
assert!(size_of::<ClassString>() == 48);
|
||||
assert!(align_of::<ClassString>() == 8);
|
||||
assert!(offset_of!(ClassString, span) == 0);
|
||||
assert!(offset_of!(ClassString, strings) == 8);
|
||||
assert!(offset_of!(ClassString, body) == 16);
|
||||
|
||||
assert!(size_of::<CapturingGroup>() == 64);
|
||||
assert!(align_of::<CapturingGroup>() == 8);
|
||||
assert!(offset_of!(CapturingGroup, span) == 0);
|
||||
assert!(offset_of!(CapturingGroup, name) == 8);
|
||||
assert!(offset_of!(CapturingGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<IgnoreGroup>() == 64);
|
||||
assert!(align_of::<IgnoreGroup>() == 8);
|
||||
assert!(offset_of!(IgnoreGroup, span) == 0);
|
||||
assert!(offset_of!(IgnoreGroup, modifiers) == 8);
|
||||
assert!(offset_of!(IgnoreGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<Modifiers>() == 16);
|
||||
assert!(align_of::<Modifiers>() == 8);
|
||||
assert!(offset_of!(Modifiers, span) == 0);
|
||||
assert!(offset_of!(Modifiers, enabling) == 8);
|
||||
assert!(offset_of!(Modifiers, disabling) == 11);
|
||||
|
||||
assert!(size_of::<Modifier>() == 3);
|
||||
assert!(align_of::<Modifier>() == 1);
|
||||
assert!(offset_of!(Modifier, ignore_case) == 0);
|
||||
assert!(offset_of!(Modifier, multiline) == 1);
|
||||
assert!(offset_of!(Modifier, sticky) == 2);
|
||||
|
||||
assert!(size_of::<IndexedReference>() == 16);
|
||||
assert!(align_of::<IndexedReference>() == 8);
|
||||
assert!(offset_of!(IndexedReference, span) == 0);
|
||||
assert!(offset_of!(IndexedReference, index) == 8);
|
||||
|
||||
assert!(size_of::<NamedReference>() == 24);
|
||||
assert!(align_of::<NamedReference>() == 8);
|
||||
assert!(offset_of!(NamedReference, span) == 0);
|
||||
assert!(offset_of!(NamedReference, name) == 8);
|
||||
};
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
@@ -2980,194 +2789,6 @@ const _: () = {
|
||||
assert!(offset_of!(Comment, position) == 13);
|
||||
assert!(offset_of!(Comment, preceded_by_newline) == 14);
|
||||
assert!(offset_of!(Comment, followed_by_newline) == 15);
|
||||
|
||||
assert!(size_of::<NonMaxU32>() == 4);
|
||||
assert!(align_of::<NonMaxU32>() == 4);
|
||||
|
||||
assert!(size_of::<NumberBase>() == 1);
|
||||
assert!(align_of::<NumberBase>() == 1);
|
||||
|
||||
assert!(size_of::<BigintBase>() == 1);
|
||||
assert!(align_of::<BigintBase>() == 1);
|
||||
|
||||
assert!(size_of::<AssignmentOperator>() == 1);
|
||||
assert!(align_of::<AssignmentOperator>() == 1);
|
||||
|
||||
assert!(size_of::<BinaryOperator>() == 1);
|
||||
assert!(align_of::<BinaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<LogicalOperator>() == 1);
|
||||
assert!(align_of::<LogicalOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UnaryOperator>() == 1);
|
||||
assert!(align_of::<UnaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UpdateOperator>() == 1);
|
||||
assert!(align_of::<UpdateOperator>() == 1);
|
||||
|
||||
assert!(size_of::<ScopeId>() == 4);
|
||||
assert!(align_of::<ScopeId>() == 4);
|
||||
|
||||
assert!(size_of::<SymbolId>() == 4);
|
||||
assert!(align_of::<SymbolId>() == 4);
|
||||
|
||||
assert!(size_of::<ReferenceId>() == 4);
|
||||
assert!(align_of::<ReferenceId>() == 4);
|
||||
|
||||
assert!(size_of::<Span>() == 8);
|
||||
assert!(align_of::<Span>() == 4);
|
||||
assert!(offset_of!(Span, start) == 0);
|
||||
assert!(offset_of!(Span, end) == 4);
|
||||
|
||||
assert!(size_of::<SourceType>() == 3);
|
||||
assert!(align_of::<SourceType>() == 1);
|
||||
|
||||
assert!(size_of::<Language>() == 1);
|
||||
assert!(align_of::<Language>() == 1);
|
||||
|
||||
assert!(size_of::<ModuleKind>() == 1);
|
||||
assert!(align_of::<ModuleKind>() == 1);
|
||||
|
||||
assert!(size_of::<LanguageVariant>() == 1);
|
||||
assert!(align_of::<LanguageVariant>() == 1);
|
||||
|
||||
assert!(size_of::<Pattern>() == 32);
|
||||
assert!(align_of::<Pattern>() == 4);
|
||||
assert!(offset_of!(Pattern, span) == 0);
|
||||
assert!(offset_of!(Pattern, body) == 8);
|
||||
|
||||
assert!(size_of::<Disjunction>() == 24);
|
||||
assert!(align_of::<Disjunction>() == 4);
|
||||
assert!(offset_of!(Disjunction, span) == 0);
|
||||
assert!(offset_of!(Disjunction, body) == 8);
|
||||
|
||||
assert!(size_of::<Alternative>() == 24);
|
||||
assert!(align_of::<Alternative>() == 4);
|
||||
assert!(offset_of!(Alternative, span) == 0);
|
||||
assert!(offset_of!(Alternative, body) == 8);
|
||||
|
||||
assert!(size_of::<Term>() == 12);
|
||||
assert!(align_of::<Term>() == 4);
|
||||
|
||||
assert!(size_of::<BoundaryAssertion>() == 12);
|
||||
assert!(align_of::<BoundaryAssertion>() == 4);
|
||||
assert!(offset_of!(BoundaryAssertion, span) == 0);
|
||||
assert!(offset_of!(BoundaryAssertion, kind) == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertionKind>() == 1);
|
||||
assert!(align_of::<BoundaryAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<LookAroundAssertion>() == 36);
|
||||
assert!(align_of::<LookAroundAssertion>() == 4);
|
||||
assert!(offset_of!(LookAroundAssertion, span) == 0);
|
||||
assert!(offset_of!(LookAroundAssertion, kind) == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, body) == 12);
|
||||
|
||||
assert!(size_of::<LookAroundAssertionKind>() == 1);
|
||||
assert!(align_of::<LookAroundAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<Quantifier>() == 48);
|
||||
assert!(align_of::<Quantifier>() == 8);
|
||||
assert!(offset_of!(Quantifier, span) == 0);
|
||||
assert!(offset_of!(Quantifier, min) == 8);
|
||||
assert!(offset_of!(Quantifier, max) == 16);
|
||||
assert!(offset_of!(Quantifier, greedy) == 32);
|
||||
assert!(offset_of!(Quantifier, body) == 36);
|
||||
|
||||
assert!(size_of::<Character>() == 16);
|
||||
assert!(align_of::<Character>() == 4);
|
||||
assert!(offset_of!(Character, span) == 0);
|
||||
assert!(offset_of!(Character, kind) == 8);
|
||||
assert!(offset_of!(Character, value) == 12);
|
||||
|
||||
assert!(size_of::<CharacterKind>() == 1);
|
||||
assert!(align_of::<CharacterKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassEscape>() == 12);
|
||||
assert!(align_of::<CharacterClassEscape>() == 4);
|
||||
assert!(offset_of!(CharacterClassEscape, span) == 0);
|
||||
assert!(offset_of!(CharacterClassEscape, kind) == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassEscapeKind>() == 1);
|
||||
assert!(align_of::<CharacterClassEscapeKind>() == 1);
|
||||
|
||||
assert!(size_of::<UnicodePropertyEscape>() == 28);
|
||||
assert!(align_of::<UnicodePropertyEscape>() == 4);
|
||||
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
|
||||
assert!(offset_of!(UnicodePropertyEscape, negative) == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, strings) == 9);
|
||||
assert!(offset_of!(UnicodePropertyEscape, name) == 12);
|
||||
assert!(offset_of!(UnicodePropertyEscape, value) == 20);
|
||||
|
||||
assert!(size_of::<Dot>() == 8);
|
||||
assert!(align_of::<Dot>() == 4);
|
||||
assert!(offset_of!(Dot, span) == 0);
|
||||
|
||||
assert!(size_of::<CharacterClass>() == 28);
|
||||
assert!(align_of::<CharacterClass>() == 4);
|
||||
assert!(offset_of!(CharacterClass, span) == 0);
|
||||
assert!(offset_of!(CharacterClass, negative) == 8);
|
||||
assert!(offset_of!(CharacterClass, strings) == 9);
|
||||
assert!(offset_of!(CharacterClass, kind) == 10);
|
||||
assert!(offset_of!(CharacterClass, body) == 12);
|
||||
|
||||
assert!(size_of::<CharacterClassContentsKind>() == 1);
|
||||
assert!(align_of::<CharacterClassContentsKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassContents>() == 8);
|
||||
assert!(align_of::<CharacterClassContents>() == 4);
|
||||
|
||||
assert!(size_of::<CharacterClassRange>() == 40);
|
||||
assert!(align_of::<CharacterClassRange>() == 4);
|
||||
assert!(offset_of!(CharacterClassRange, span) == 0);
|
||||
assert!(offset_of!(CharacterClassRange, min) == 8);
|
||||
assert!(offset_of!(CharacterClassRange, max) == 24);
|
||||
|
||||
assert!(size_of::<ClassStringDisjunction>() == 28);
|
||||
assert!(align_of::<ClassStringDisjunction>() == 4);
|
||||
assert!(offset_of!(ClassStringDisjunction, span) == 0);
|
||||
assert!(offset_of!(ClassStringDisjunction, strings) == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, body) == 12);
|
||||
|
||||
assert!(size_of::<ClassString>() == 28);
|
||||
assert!(align_of::<ClassString>() == 4);
|
||||
assert!(offset_of!(ClassString, span) == 0);
|
||||
assert!(offset_of!(ClassString, strings) == 8);
|
||||
assert!(offset_of!(ClassString, body) == 12);
|
||||
|
||||
assert!(size_of::<CapturingGroup>() == 40);
|
||||
assert!(align_of::<CapturingGroup>() == 4);
|
||||
assert!(offset_of!(CapturingGroup, span) == 0);
|
||||
assert!(offset_of!(CapturingGroup, name) == 8);
|
||||
assert!(offset_of!(CapturingGroup, body) == 16);
|
||||
|
||||
assert!(size_of::<IgnoreGroup>() == 48);
|
||||
assert!(align_of::<IgnoreGroup>() == 4);
|
||||
assert!(offset_of!(IgnoreGroup, span) == 0);
|
||||
assert!(offset_of!(IgnoreGroup, modifiers) == 8);
|
||||
assert!(offset_of!(IgnoreGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<Modifiers>() == 16);
|
||||
assert!(align_of::<Modifiers>() == 4);
|
||||
assert!(offset_of!(Modifiers, span) == 0);
|
||||
assert!(offset_of!(Modifiers, enabling) == 8);
|
||||
assert!(offset_of!(Modifiers, disabling) == 11);
|
||||
|
||||
assert!(size_of::<Modifier>() == 3);
|
||||
assert!(align_of::<Modifier>() == 1);
|
||||
assert!(offset_of!(Modifier, ignore_case) == 0);
|
||||
assert!(offset_of!(Modifier, multiline) == 1);
|
||||
assert!(offset_of!(Modifier, sticky) == 2);
|
||||
|
||||
assert!(size_of::<IndexedReference>() == 12);
|
||||
assert!(align_of::<IndexedReference>() == 4);
|
||||
assert!(offset_of!(IndexedReference, span) == 0);
|
||||
assert!(offset_of!(IndexedReference, index) == 8);
|
||||
|
||||
assert!(size_of::<NamedReference>() == 16);
|
||||
assert!(align_of::<NamedReference>() == 4);
|
||||
assert!(offset_of!(NamedReference, span) == 0);
|
||||
assert!(offset_of!(NamedReference, name) == 8);
|
||||
};
|
||||
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/assert_layouts.rs`
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
use crate::ast::*;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const _: () = {
|
||||
assert!(size_of::<Pattern>() == 48);
|
||||
assert!(align_of::<Pattern>() == 8);
|
||||
assert!(offset_of!(Pattern, span) == 0);
|
||||
assert!(offset_of!(Pattern, body) == 8);
|
||||
|
||||
assert!(size_of::<Disjunction>() == 40);
|
||||
assert!(align_of::<Disjunction>() == 8);
|
||||
assert!(offset_of!(Disjunction, span) == 0);
|
||||
assert!(offset_of!(Disjunction, body) == 8);
|
||||
|
||||
assert!(size_of::<Alternative>() == 40);
|
||||
assert!(align_of::<Alternative>() == 8);
|
||||
assert!(offset_of!(Alternative, span) == 0);
|
||||
assert!(offset_of!(Alternative, body) == 8);
|
||||
|
||||
assert!(size_of::<Term>() == 16);
|
||||
assert!(align_of::<Term>() == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertion>() == 16);
|
||||
assert!(align_of::<BoundaryAssertion>() == 8);
|
||||
assert!(offset_of!(BoundaryAssertion, span) == 0);
|
||||
assert!(offset_of!(BoundaryAssertion, kind) == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertionKind>() == 1);
|
||||
assert!(align_of::<BoundaryAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<LookAroundAssertion>() == 56);
|
||||
assert!(align_of::<LookAroundAssertion>() == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, span) == 0);
|
||||
assert!(offset_of!(LookAroundAssertion, kind) == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, body) == 16);
|
||||
|
||||
assert!(size_of::<LookAroundAssertionKind>() == 1);
|
||||
assert!(align_of::<LookAroundAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<Quantifier>() == 56);
|
||||
assert!(align_of::<Quantifier>() == 8);
|
||||
assert!(offset_of!(Quantifier, span) == 0);
|
||||
assert!(offset_of!(Quantifier, min) == 8);
|
||||
assert!(offset_of!(Quantifier, max) == 16);
|
||||
assert!(offset_of!(Quantifier, greedy) == 32);
|
||||
assert!(offset_of!(Quantifier, body) == 40);
|
||||
|
||||
assert!(size_of::<Character>() == 16);
|
||||
assert!(align_of::<Character>() == 8);
|
||||
assert!(offset_of!(Character, span) == 0);
|
||||
assert!(offset_of!(Character, kind) == 8);
|
||||
assert!(offset_of!(Character, value) == 12);
|
||||
|
||||
assert!(size_of::<CharacterKind>() == 1);
|
||||
assert!(align_of::<CharacterKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassEscape>() == 16);
|
||||
assert!(align_of::<CharacterClassEscape>() == 8);
|
||||
assert!(offset_of!(CharacterClassEscape, span) == 0);
|
||||
assert!(offset_of!(CharacterClassEscape, kind) == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassEscapeKind>() == 1);
|
||||
assert!(align_of::<CharacterClassEscapeKind>() == 1);
|
||||
|
||||
assert!(size_of::<UnicodePropertyEscape>() == 48);
|
||||
assert!(align_of::<UnicodePropertyEscape>() == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
|
||||
assert!(offset_of!(UnicodePropertyEscape, negative) == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, strings) == 9);
|
||||
assert!(offset_of!(UnicodePropertyEscape, name) == 16);
|
||||
assert!(offset_of!(UnicodePropertyEscape, value) == 32);
|
||||
|
||||
assert!(size_of::<Dot>() == 8);
|
||||
assert!(align_of::<Dot>() == 8);
|
||||
assert!(offset_of!(Dot, span) == 0);
|
||||
|
||||
assert!(size_of::<CharacterClass>() == 48);
|
||||
assert!(align_of::<CharacterClass>() == 8);
|
||||
assert!(offset_of!(CharacterClass, span) == 0);
|
||||
assert!(offset_of!(CharacterClass, negative) == 8);
|
||||
assert!(offset_of!(CharacterClass, strings) == 9);
|
||||
assert!(offset_of!(CharacterClass, kind) == 10);
|
||||
assert!(offset_of!(CharacterClass, body) == 16);
|
||||
|
||||
assert!(size_of::<CharacterClassContentsKind>() == 1);
|
||||
assert!(align_of::<CharacterClassContentsKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassContents>() == 16);
|
||||
assert!(align_of::<CharacterClassContents>() == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassRange>() == 40);
|
||||
assert!(align_of::<CharacterClassRange>() == 8);
|
||||
assert!(offset_of!(CharacterClassRange, span) == 0);
|
||||
assert!(offset_of!(CharacterClassRange, min) == 8);
|
||||
assert!(offset_of!(CharacterClassRange, max) == 24);
|
||||
|
||||
assert!(size_of::<ClassStringDisjunction>() == 48);
|
||||
assert!(align_of::<ClassStringDisjunction>() == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, span) == 0);
|
||||
assert!(offset_of!(ClassStringDisjunction, strings) == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, body) == 16);
|
||||
|
||||
assert!(size_of::<ClassString>() == 48);
|
||||
assert!(align_of::<ClassString>() == 8);
|
||||
assert!(offset_of!(ClassString, span) == 0);
|
||||
assert!(offset_of!(ClassString, strings) == 8);
|
||||
assert!(offset_of!(ClassString, body) == 16);
|
||||
|
||||
assert!(size_of::<CapturingGroup>() == 64);
|
||||
assert!(align_of::<CapturingGroup>() == 8);
|
||||
assert!(offset_of!(CapturingGroup, span) == 0);
|
||||
assert!(offset_of!(CapturingGroup, name) == 8);
|
||||
assert!(offset_of!(CapturingGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<IgnoreGroup>() == 64);
|
||||
assert!(align_of::<IgnoreGroup>() == 8);
|
||||
assert!(offset_of!(IgnoreGroup, span) == 0);
|
||||
assert!(offset_of!(IgnoreGroup, modifiers) == 8);
|
||||
assert!(offset_of!(IgnoreGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<Modifiers>() == 16);
|
||||
assert!(align_of::<Modifiers>() == 8);
|
||||
assert!(offset_of!(Modifiers, span) == 0);
|
||||
assert!(offset_of!(Modifiers, enabling) == 8);
|
||||
assert!(offset_of!(Modifiers, disabling) == 11);
|
||||
|
||||
assert!(size_of::<Modifier>() == 3);
|
||||
assert!(align_of::<Modifier>() == 1);
|
||||
assert!(offset_of!(Modifier, ignore_case) == 0);
|
||||
assert!(offset_of!(Modifier, multiline) == 1);
|
||||
assert!(offset_of!(Modifier, sticky) == 2);
|
||||
|
||||
assert!(size_of::<IndexedReference>() == 16);
|
||||
assert!(align_of::<IndexedReference>() == 8);
|
||||
assert!(offset_of!(IndexedReference, span) == 0);
|
||||
assert!(offset_of!(IndexedReference, index) == 8);
|
||||
|
||||
assert!(size_of::<NamedReference>() == 24);
|
||||
assert!(align_of::<NamedReference>() == 8);
|
||||
assert!(offset_of!(NamedReference, span) == 0);
|
||||
assert!(offset_of!(NamedReference, name) == 8);
|
||||
};
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const _: () = {
|
||||
assert!(size_of::<Pattern>() == 32);
|
||||
assert!(align_of::<Pattern>() == 4);
|
||||
assert!(offset_of!(Pattern, span) == 0);
|
||||
assert!(offset_of!(Pattern, body) == 8);
|
||||
|
||||
assert!(size_of::<Disjunction>() == 24);
|
||||
assert!(align_of::<Disjunction>() == 4);
|
||||
assert!(offset_of!(Disjunction, span) == 0);
|
||||
assert!(offset_of!(Disjunction, body) == 8);
|
||||
|
||||
assert!(size_of::<Alternative>() == 24);
|
||||
assert!(align_of::<Alternative>() == 4);
|
||||
assert!(offset_of!(Alternative, span) == 0);
|
||||
assert!(offset_of!(Alternative, body) == 8);
|
||||
|
||||
assert!(size_of::<Term>() == 12);
|
||||
assert!(align_of::<Term>() == 4);
|
||||
|
||||
assert!(size_of::<BoundaryAssertion>() == 12);
|
||||
assert!(align_of::<BoundaryAssertion>() == 4);
|
||||
assert!(offset_of!(BoundaryAssertion, span) == 0);
|
||||
assert!(offset_of!(BoundaryAssertion, kind) == 8);
|
||||
|
||||
assert!(size_of::<BoundaryAssertionKind>() == 1);
|
||||
assert!(align_of::<BoundaryAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<LookAroundAssertion>() == 36);
|
||||
assert!(align_of::<LookAroundAssertion>() == 4);
|
||||
assert!(offset_of!(LookAroundAssertion, span) == 0);
|
||||
assert!(offset_of!(LookAroundAssertion, kind) == 8);
|
||||
assert!(offset_of!(LookAroundAssertion, body) == 12);
|
||||
|
||||
assert!(size_of::<LookAroundAssertionKind>() == 1);
|
||||
assert!(align_of::<LookAroundAssertionKind>() == 1);
|
||||
|
||||
assert!(size_of::<Quantifier>() == 48);
|
||||
assert!(align_of::<Quantifier>() == 8);
|
||||
assert!(offset_of!(Quantifier, span) == 0);
|
||||
assert!(offset_of!(Quantifier, min) == 8);
|
||||
assert!(offset_of!(Quantifier, max) == 16);
|
||||
assert!(offset_of!(Quantifier, greedy) == 32);
|
||||
assert!(offset_of!(Quantifier, body) == 36);
|
||||
|
||||
assert!(size_of::<Character>() == 16);
|
||||
assert!(align_of::<Character>() == 4);
|
||||
assert!(offset_of!(Character, span) == 0);
|
||||
assert!(offset_of!(Character, kind) == 8);
|
||||
assert!(offset_of!(Character, value) == 12);
|
||||
|
||||
assert!(size_of::<CharacterKind>() == 1);
|
||||
assert!(align_of::<CharacterKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassEscape>() == 12);
|
||||
assert!(align_of::<CharacterClassEscape>() == 4);
|
||||
assert!(offset_of!(CharacterClassEscape, span) == 0);
|
||||
assert!(offset_of!(CharacterClassEscape, kind) == 8);
|
||||
|
||||
assert!(size_of::<CharacterClassEscapeKind>() == 1);
|
||||
assert!(align_of::<CharacterClassEscapeKind>() == 1);
|
||||
|
||||
assert!(size_of::<UnicodePropertyEscape>() == 28);
|
||||
assert!(align_of::<UnicodePropertyEscape>() == 4);
|
||||
assert!(offset_of!(UnicodePropertyEscape, span) == 0);
|
||||
assert!(offset_of!(UnicodePropertyEscape, negative) == 8);
|
||||
assert!(offset_of!(UnicodePropertyEscape, strings) == 9);
|
||||
assert!(offset_of!(UnicodePropertyEscape, name) == 12);
|
||||
assert!(offset_of!(UnicodePropertyEscape, value) == 20);
|
||||
|
||||
assert!(size_of::<Dot>() == 8);
|
||||
assert!(align_of::<Dot>() == 4);
|
||||
assert!(offset_of!(Dot, span) == 0);
|
||||
|
||||
assert!(size_of::<CharacterClass>() == 28);
|
||||
assert!(align_of::<CharacterClass>() == 4);
|
||||
assert!(offset_of!(CharacterClass, span) == 0);
|
||||
assert!(offset_of!(CharacterClass, negative) == 8);
|
||||
assert!(offset_of!(CharacterClass, strings) == 9);
|
||||
assert!(offset_of!(CharacterClass, kind) == 10);
|
||||
assert!(offset_of!(CharacterClass, body) == 12);
|
||||
|
||||
assert!(size_of::<CharacterClassContentsKind>() == 1);
|
||||
assert!(align_of::<CharacterClassContentsKind>() == 1);
|
||||
|
||||
assert!(size_of::<CharacterClassContents>() == 8);
|
||||
assert!(align_of::<CharacterClassContents>() == 4);
|
||||
|
||||
assert!(size_of::<CharacterClassRange>() == 40);
|
||||
assert!(align_of::<CharacterClassRange>() == 4);
|
||||
assert!(offset_of!(CharacterClassRange, span) == 0);
|
||||
assert!(offset_of!(CharacterClassRange, min) == 8);
|
||||
assert!(offset_of!(CharacterClassRange, max) == 24);
|
||||
|
||||
assert!(size_of::<ClassStringDisjunction>() == 28);
|
||||
assert!(align_of::<ClassStringDisjunction>() == 4);
|
||||
assert!(offset_of!(ClassStringDisjunction, span) == 0);
|
||||
assert!(offset_of!(ClassStringDisjunction, strings) == 8);
|
||||
assert!(offset_of!(ClassStringDisjunction, body) == 12);
|
||||
|
||||
assert!(size_of::<ClassString>() == 28);
|
||||
assert!(align_of::<ClassString>() == 4);
|
||||
assert!(offset_of!(ClassString, span) == 0);
|
||||
assert!(offset_of!(ClassString, strings) == 8);
|
||||
assert!(offset_of!(ClassString, body) == 12);
|
||||
|
||||
assert!(size_of::<CapturingGroup>() == 40);
|
||||
assert!(align_of::<CapturingGroup>() == 4);
|
||||
assert!(offset_of!(CapturingGroup, span) == 0);
|
||||
assert!(offset_of!(CapturingGroup, name) == 8);
|
||||
assert!(offset_of!(CapturingGroup, body) == 16);
|
||||
|
||||
assert!(size_of::<IgnoreGroup>() == 48);
|
||||
assert!(align_of::<IgnoreGroup>() == 4);
|
||||
assert!(offset_of!(IgnoreGroup, span) == 0);
|
||||
assert!(offset_of!(IgnoreGroup, modifiers) == 8);
|
||||
assert!(offset_of!(IgnoreGroup, body) == 24);
|
||||
|
||||
assert!(size_of::<Modifiers>() == 16);
|
||||
assert!(align_of::<Modifiers>() == 4);
|
||||
assert!(offset_of!(Modifiers, span) == 0);
|
||||
assert!(offset_of!(Modifiers, enabling) == 8);
|
||||
assert!(offset_of!(Modifiers, disabling) == 11);
|
||||
|
||||
assert!(size_of::<Modifier>() == 3);
|
||||
assert!(align_of::<Modifier>() == 1);
|
||||
assert!(offset_of!(Modifier, ignore_case) == 0);
|
||||
assert!(offset_of!(Modifier, multiline) == 1);
|
||||
assert!(offset_of!(Modifier, sticky) == 2);
|
||||
|
||||
assert!(size_of::<IndexedReference>() == 12);
|
||||
assert!(align_of::<IndexedReference>() == 4);
|
||||
assert!(offset_of!(IndexedReference, span) == 0);
|
||||
assert!(offset_of!(IndexedReference, index) == 8);
|
||||
|
||||
assert!(size_of::<NamedReference>() == 16);
|
||||
assert!(align_of::<NamedReference>() == 4);
|
||||
assert!(offset_of!(NamedReference, span) == 0);
|
||||
assert!(offset_of!(NamedReference, name) == 8);
|
||||
};
|
||||
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
|
||||
@@ -7,6 +7,8 @@ mod parser;
|
||||
mod surrogate_pair;
|
||||
|
||||
mod generated {
|
||||
#[cfg(debug_assertions)]
|
||||
pub mod assert_layouts;
|
||||
mod derive_clone_in;
|
||||
mod derive_content_eq;
|
||||
#[cfg(feature = "serialize")]
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/assert_layouts.rs`
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const _: () = {
|
||||
assert!(size_of::<Span>() == 8);
|
||||
assert!(align_of::<Span>() == 8);
|
||||
assert!(offset_of!(Span, start) == 0);
|
||||
assert!(offset_of!(Span, end) == 4);
|
||||
|
||||
assert!(size_of::<SourceType>() == 3);
|
||||
assert!(align_of::<SourceType>() == 1);
|
||||
|
||||
assert!(size_of::<Language>() == 1);
|
||||
assert!(align_of::<Language>() == 1);
|
||||
|
||||
assert!(size_of::<ModuleKind>() == 1);
|
||||
assert!(align_of::<ModuleKind>() == 1);
|
||||
|
||||
assert!(size_of::<LanguageVariant>() == 1);
|
||||
assert!(align_of::<LanguageVariant>() == 1);
|
||||
};
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const _: () = {
|
||||
assert!(size_of::<Span>() == 8);
|
||||
assert!(align_of::<Span>() == 4);
|
||||
assert!(offset_of!(Span, start) == 0);
|
||||
assert!(offset_of!(Span, end) == 4);
|
||||
|
||||
assert!(size_of::<SourceType>() == 3);
|
||||
assert!(align_of::<SourceType>() == 1);
|
||||
|
||||
assert!(size_of::<Language>() == 1);
|
||||
assert!(align_of::<Language>() == 1);
|
||||
|
||||
assert!(size_of::<ModuleKind>() == 1);
|
||||
assert!(align_of::<ModuleKind>() == 1);
|
||||
|
||||
assert!(size_of::<LanguageVariant>() == 1);
|
||||
assert!(align_of::<LanguageVariant>() == 1);
|
||||
};
|
||||
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
|
||||
@@ -21,6 +21,8 @@ pub use crate::{
|
||||
};
|
||||
|
||||
mod generated {
|
||||
#[cfg(debug_assertions)]
|
||||
pub mod assert_layouts;
|
||||
#[cfg(feature = "serialize")]
|
||||
pub mod derive_estree;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/assert_layouts.rs`
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
use nonmax::NonMaxU32;
|
||||
|
||||
use crate::{number::*, operator::*, reference::*, scope::*, symbol::*};
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const _: () = {
|
||||
assert!(size_of::<NonMaxU32>() == 4);
|
||||
assert!(align_of::<NonMaxU32>() == 4);
|
||||
|
||||
assert!(size_of::<NumberBase>() == 1);
|
||||
assert!(align_of::<NumberBase>() == 1);
|
||||
|
||||
assert!(size_of::<BigintBase>() == 1);
|
||||
assert!(align_of::<BigintBase>() == 1);
|
||||
|
||||
assert!(size_of::<AssignmentOperator>() == 1);
|
||||
assert!(align_of::<AssignmentOperator>() == 1);
|
||||
|
||||
assert!(size_of::<BinaryOperator>() == 1);
|
||||
assert!(align_of::<BinaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<LogicalOperator>() == 1);
|
||||
assert!(align_of::<LogicalOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UnaryOperator>() == 1);
|
||||
assert!(align_of::<UnaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UpdateOperator>() == 1);
|
||||
assert!(align_of::<UpdateOperator>() == 1);
|
||||
|
||||
assert!(size_of::<ScopeId>() == 4);
|
||||
assert!(align_of::<ScopeId>() == 4);
|
||||
|
||||
assert!(size_of::<SymbolId>() == 4);
|
||||
assert!(align_of::<SymbolId>() == 4);
|
||||
|
||||
assert!(size_of::<ReferenceId>() == 4);
|
||||
assert!(align_of::<ReferenceId>() == 4);
|
||||
};
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const _: () = {
|
||||
assert!(size_of::<NonMaxU32>() == 4);
|
||||
assert!(align_of::<NonMaxU32>() == 4);
|
||||
|
||||
assert!(size_of::<NumberBase>() == 1);
|
||||
assert!(align_of::<NumberBase>() == 1);
|
||||
|
||||
assert!(size_of::<BigintBase>() == 1);
|
||||
assert!(align_of::<BigintBase>() == 1);
|
||||
|
||||
assert!(size_of::<AssignmentOperator>() == 1);
|
||||
assert!(align_of::<AssignmentOperator>() == 1);
|
||||
|
||||
assert!(size_of::<BinaryOperator>() == 1);
|
||||
assert!(align_of::<BinaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<LogicalOperator>() == 1);
|
||||
assert!(align_of::<LogicalOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UnaryOperator>() == 1);
|
||||
assert!(align_of::<UnaryOperator>() == 1);
|
||||
|
||||
assert!(size_of::<UpdateOperator>() == 1);
|
||||
assert!(align_of::<UpdateOperator>() == 1);
|
||||
|
||||
assert!(size_of::<ScopeId>() == 4);
|
||||
assert!(align_of::<ScopeId>() == 4);
|
||||
|
||||
assert!(size_of::<SymbolId>() == 4);
|
||||
assert!(align_of::<SymbolId>() == 4);
|
||||
|
||||
assert!(size_of::<ReferenceId>() == 4);
|
||||
assert!(align_of::<ReferenceId>() == 4);
|
||||
};
|
||||
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
|
||||
@@ -18,7 +18,10 @@ pub mod reference;
|
||||
pub mod scope;
|
||||
pub mod symbol;
|
||||
pub mod xml_entities;
|
||||
|
||||
mod generated {
|
||||
#[cfg(debug_assertions)]
|
||||
pub mod assert_layouts;
|
||||
mod derive_clone_in;
|
||||
mod derive_content_eq;
|
||||
#[cfg(feature = "serialize")]
|
||||
|
||||
@@ -5,16 +5,18 @@
|
||||
//! Calculate each separately, and generate assertions for each.
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
cmp::{max, min},
|
||||
num,
|
||||
};
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use rustc_hash::FxHashMap;
|
||||
use syn::Ident;
|
||||
|
||||
use crate::{
|
||||
AST_CRATE_PATH, Codegen, Generator,
|
||||
Codegen, Generator,
|
||||
output::{Output, output_path},
|
||||
schema::{
|
||||
Def, Discriminant, EnumDef, PrimitiveDef, Schema, StructDef, TypeDef, TypeId, Visibility,
|
||||
@@ -39,37 +41,8 @@ impl Generator for AssertLayouts {
|
||||
}
|
||||
|
||||
/// Generate assertions that calculated layouts are correct.
|
||||
fn generate(&self, schema: &Schema, _codegen: &Codegen) -> Output {
|
||||
let (assertions_64, assertions_32): (TokenStream, TokenStream) =
|
||||
schema.types.iter().map(generate_layout_assertions).unzip();
|
||||
|
||||
let output = quote! {
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
///@@line_break
|
||||
use nonmax::NonMaxU32;
|
||||
|
||||
///@@line_break
|
||||
use oxc_regular_expression::ast::*;
|
||||
use oxc_syntax::{reference::ReferenceId, scope::ScopeId, symbol::SymbolId};
|
||||
|
||||
///@@line_break
|
||||
use crate::ast::*;
|
||||
|
||||
///@@line_break
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const _: () = { #assertions_64 };
|
||||
|
||||
///@@line_break
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const _: () = { #assertions_32 };
|
||||
|
||||
///@@line_break
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
|
||||
};
|
||||
|
||||
Output::Rust { path: output_path(AST_CRATE_PATH, "assert_layouts.rs"), tokens: output }
|
||||
fn generate_many(&self, schema: &Schema, _codegen: &Codegen) -> Vec<Output> {
|
||||
generate_assertions(schema)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,20 +390,53 @@ fn calculate_layout_for_primitive(primitive_def: &PrimitiveDef) -> Layout {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate layout assertions for a type
|
||||
fn generate_layout_assertions(
|
||||
/// Generate layout assertions for all types.
|
||||
fn generate_assertions(schema: &Schema) -> Vec<Output> {
|
||||
let mut assertions = FxHashMap::default();
|
||||
|
||||
for type_def in &schema.types {
|
||||
generate_layout_assertions(type_def, &mut assertions, schema);
|
||||
}
|
||||
|
||||
assertions
|
||||
.into_iter()
|
||||
.map(|(krate, (assertions_64, assertions_32))| {
|
||||
let output = template(krate, &assertions_64, &assertions_32);
|
||||
|
||||
let crate_path = if krate.starts_with("napi/") {
|
||||
Cow::Borrowed(krate)
|
||||
} else {
|
||||
Cow::Owned(format!("crates/{krate}"))
|
||||
};
|
||||
Output::Rust { path: output_path(&crate_path, "assert_layouts.rs"), tokens: output }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Generate layout assertions for a type.
|
||||
fn generate_layout_assertions<'s>(
|
||||
type_def: &TypeDef,
|
||||
) -> (/* 64 bit */ TokenStream, /* 32 bit */ TokenStream) {
|
||||
assertions: &mut FxHashMap<&'s str, (/* 64 bit */ TokenStream, /* 32 bit */ TokenStream)>,
|
||||
schema: &'s Schema,
|
||||
) {
|
||||
match type_def {
|
||||
TypeDef::Struct(struct_def) => generate_layout_assertions_for_struct(struct_def),
|
||||
TypeDef::Enum(enum_def) => generate_layout_assertions_for_enum(enum_def),
|
||||
_ => (quote!(), quote!()),
|
||||
TypeDef::Struct(struct_def) => {
|
||||
generate_layout_assertions_for_struct(struct_def, assertions, schema);
|
||||
}
|
||||
TypeDef::Enum(enum_def) => {
|
||||
generate_layout_assertions_for_enum(enum_def, assertions, schema);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate layout assertions for a struct.
|
||||
/// This includes size and alignment assertions, plus assertions about offset of fields.
|
||||
fn generate_layout_assertions_for_struct(struct_def: &StructDef) -> (TokenStream, TokenStream) {
|
||||
fn generate_layout_assertions_for_struct<'s>(
|
||||
struct_def: &StructDef,
|
||||
assertions: &mut FxHashMap<&'s str, (/* 64 bit */ TokenStream, /* 32 bit */ TokenStream)>,
|
||||
schema: &'s Schema,
|
||||
) {
|
||||
fn r#gen(struct_def: &StructDef, is_64: bool, struct_ident: &Ident) -> TokenStream {
|
||||
let layout =
|
||||
if is_64 { &struct_def.layout.layout_64 } else { &struct_def.layout.layout_32 };
|
||||
@@ -458,18 +464,27 @@ fn generate_layout_assertions_for_struct(struct_def: &StructDef) -> (TokenStream
|
||||
}
|
||||
}
|
||||
|
||||
let (assertions_64, assertions_32) =
|
||||
assertions.entry(struct_def.file(schema).krate()).or_default();
|
||||
|
||||
let ident = struct_def.ident();
|
||||
(r#gen(struct_def, true, &ident), r#gen(struct_def, false, &ident))
|
||||
assertions_64.extend(r#gen(struct_def, true, &ident));
|
||||
assertions_32.extend(r#gen(struct_def, false, &ident));
|
||||
}
|
||||
|
||||
/// Generate layout assertions for an enum.
|
||||
/// This is just size and alignment assertions.
|
||||
fn generate_layout_assertions_for_enum(enum_def: &EnumDef) -> (TokenStream, TokenStream) {
|
||||
fn generate_layout_assertions_for_enum<'s>(
|
||||
enum_def: &EnumDef,
|
||||
assertions: &mut FxHashMap<&'s str, (/* 64 bit */ TokenStream, /* 32 bit */ TokenStream)>,
|
||||
schema: &'s Schema,
|
||||
) {
|
||||
let (assertions_64, assertions_32) =
|
||||
assertions.entry(enum_def.file(schema).krate()).or_default();
|
||||
|
||||
let ident = enum_def.ident();
|
||||
(
|
||||
generate_size_align_assertions(&enum_def.layout.layout_64, &ident),
|
||||
generate_size_align_assertions(&enum_def.layout.layout_32, &ident),
|
||||
)
|
||||
assertions_64.extend(generate_size_align_assertions(&enum_def.layout.layout_64, &ident));
|
||||
assertions_32.extend(generate_size_align_assertions(&enum_def.layout.layout_32, &ident));
|
||||
}
|
||||
|
||||
/// Generate size and alignment assertions for a type.
|
||||
@@ -482,3 +497,50 @@ fn generate_size_align_assertions(layout: &PlatformLayout, ident: &Ident) -> Tok
|
||||
assert!(align_of::<#ident>() == #align);
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate output for a crate.
|
||||
fn template(krate: &str, assertions_64: &TokenStream, assertions_32: &TokenStream) -> TokenStream {
|
||||
#[expect(clippy::match_same_arms)]
|
||||
let imports = match krate {
|
||||
"oxc_ast" => quote! {
|
||||
use crate::ast::*;
|
||||
},
|
||||
"oxc_regular_expression" => quote! {
|
||||
use crate::ast::*;
|
||||
},
|
||||
"oxc_span" => quote! {
|
||||
use crate::*;
|
||||
},
|
||||
"oxc_syntax" => quote! {
|
||||
use nonmax::NonMaxU32;
|
||||
|
||||
///@@line_break
|
||||
use crate::{number::*, operator::*, reference::*, scope::*, symbol::*};
|
||||
},
|
||||
_ => quote! {
|
||||
use crate::*;
|
||||
},
|
||||
};
|
||||
|
||||
quote! {
|
||||
#![allow(unused_imports)]
|
||||
|
||||
///@@line_break
|
||||
use std::mem::{align_of, offset_of, size_of};
|
||||
|
||||
///@@line_break
|
||||
#imports
|
||||
|
||||
///@@line_break
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const _: () = { #assertions_64 };
|
||||
|
||||
///@@line_break
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const _: () = { #assertions_32 };
|
||||
|
||||
///@@line_break
|
||||
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
|
||||
const _: () = panic!("Platforms with pointer width other than 64 or 32 bit are not supported");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user