Skip to content

Commit

Permalink
refactor(ast): move impl GetAddress for Statement (#6742)
Browse files Browse the repository at this point in the history
Follow-on after #6738. Since `GetAddress` is now defined in `oxc_allocator` crate, `impl GetAddress for Statement` doesn't need its own file.
  • Loading branch information
overlookmotel committed Oct 21, 2024
1 parent 1248557 commit b66ae2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
44 changes: 0 additions & 44 deletions crates/oxc_ast/src/address.rs

This file was deleted.

43 changes: 42 additions & 1 deletion crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(missing_docs)]
use std::{borrow::Cow, cell::Cell, fmt};

use oxc_allocator::{Box, FromIn, Vec};
use oxc_allocator::{Address, Box, FromIn, GetAddress, Vec};
use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::{
operator::UnaryOperator,
Expand Down Expand Up @@ -768,6 +768,47 @@ impl<'a> FromIn<'a, Expression<'a>> for Statement<'a> {
}
}

impl<'a> GetAddress for Statement<'a> {
// `#[inline]` because compiler should boil this down to a single assembly instruction
#[inline]
fn address(&self) -> Address {
match self {
Statement::BlockStatement(s) => s.address(),
Statement::BreakStatement(s) => s.address(),
Statement::ContinueStatement(s) => s.address(),
Statement::DebuggerStatement(s) => s.address(),
Statement::DoWhileStatement(s) => s.address(),
Statement::EmptyStatement(s) => s.address(),
Statement::ExpressionStatement(s) => s.address(),
Statement::ForInStatement(s) => s.address(),
Statement::ForOfStatement(s) => s.address(),
Statement::ForStatement(s) => s.address(),
Statement::IfStatement(s) => s.address(),
Statement::LabeledStatement(s) => s.address(),
Statement::ReturnStatement(s) => s.address(),
Statement::SwitchStatement(s) => s.address(),
Statement::ThrowStatement(s) => s.address(),
Statement::TryStatement(s) => s.address(),
Statement::WhileStatement(s) => s.address(),
Statement::WithStatement(s) => s.address(),
Statement::VariableDeclaration(s) => s.address(),
Statement::FunctionDeclaration(s) => s.address(),
Statement::ClassDeclaration(s) => s.address(),
Statement::TSTypeAliasDeclaration(s) => s.address(),
Statement::TSInterfaceDeclaration(s) => s.address(),
Statement::TSEnumDeclaration(s) => s.address(),
Statement::TSModuleDeclaration(s) => s.address(),
Statement::TSImportEqualsDeclaration(s) => s.address(),
Statement::ImportDeclaration(s) => s.address(),
Statement::ExportAllDeclaration(s) => s.address(),
Statement::ExportDefaultDeclaration(s) => s.address(),
Statement::ExportNamedDeclaration(s) => s.address(),
Statement::TSExportAssignment(s) => s.address(),
Statement::TSNamespaceExportDeclaration(s) => s.address(),
}
}
}

impl<'a> Directive<'a> {
/// A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either of the exact code point sequences "use strict" or 'use strict'.
/// A Use Strict Directive may not contain an EscapeSequence or LineContinuation.
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#[cfg(feature = "serialize")]
mod serialize;

pub mod address;
pub mod ast;
mod ast_builder_impl;
mod ast_impl;
Expand Down

0 comments on commit b66ae2e

Please sign in to comment.