Skip to content

Commit

Permalink
Apply review pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Oct 2, 2022
1 parent 682a72b commit 7260aa4
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boa_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
clippy::needless_pass_by_value,
clippy::match_wildcard_for_single_variants,
clippy::map_unwrap_or,
clippy::missing_inline_in_public_items,
unused_qualifications,
unused_import_braces,
unused_lifetimes,
Expand All @@ -53,6 +52,7 @@
nonstandard_style,
)]
#![allow(
clippy::missing_inline_in_public_items,
clippy::module_name_repetitions,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
Expand Down
12 changes: 12 additions & 0 deletions boa_engine/src/syntax/ast/expression/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ impl PropertyAccessField {
}

impl From<Sym> for PropertyAccessField {
#[inline]
fn from(id: Sym) -> Self {
Self::Const(id)
}
}

impl From<Expression> for PropertyAccessField {
#[inline]
fn from(expr: Expression) -> Self {
Self::Expr(Box::new(expr))
}
Expand Down Expand Up @@ -66,15 +68,18 @@ pub struct PropertyAccess {
}

impl PropertyAccess {
#[inline]
pub fn target(&self) -> &Expression {
&self.target
}

#[inline]
pub fn field(&self) -> &PropertyAccessField {
&self.field
}

/// Creates a `PropertyAccess` AST Expression.
#[inline]
pub fn new<F>(target: Expression, field: F) -> Self
where
F: Into<PropertyAccessField>,
Expand All @@ -97,6 +102,7 @@ impl PropertyAccess {
}

impl ToInternedString for PropertyAccess {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
let target = self.target.to_interned_string(interner);
match self.field {
Expand All @@ -109,6 +115,7 @@ impl ToInternedString for PropertyAccess {
}

impl From<PropertyAccess> for Expression {
#[inline]
fn from(access: PropertyAccess) -> Self {
Self::PropertyAccess(access)
}
Expand Down Expand Up @@ -166,6 +173,7 @@ impl PrivatePropertyAccess {
}

impl ToInternedString for PrivatePropertyAccess {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!(
"{}.#{}",
Expand All @@ -176,6 +184,7 @@ impl ToInternedString for PrivatePropertyAccess {
}

impl From<PrivatePropertyAccess> for Expression {
#[inline]
fn from(access: PrivatePropertyAccess) -> Self {
Self::PrivatePropertyAccess(access)
}
Expand All @@ -201,6 +210,7 @@ impl SuperPropertyAccess {
}

/// Gets the name of the field to retrieve.
#[inline]
pub fn field(&self) -> &PropertyAccessField {
&self.field
}
Expand All @@ -217,6 +227,7 @@ impl SuperPropertyAccess {
}

impl ToInternedString for SuperPropertyAccess {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
match &self.field {
PropertyAccessField::Const(field) => {
Expand All @@ -230,6 +241,7 @@ impl ToInternedString for SuperPropertyAccess {
}

impl From<SuperPropertyAccess> for Expression {
#[inline]
fn from(access: SuperPropertyAccess) -> Self {
Self::SuperPropertyAccess(access)
}
Expand Down
3 changes: 3 additions & 0 deletions boa_engine/src/syntax/ast/expression/await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ impl<T> From<T> for Await
where
T: Into<Box<Expression>>,
{
#[inline]
fn from(e: T) -> Self {
Self { expr: e.into() }
}
}

impl ToInternedString for Await {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!("await {}", self.expr.to_indented_string(interner, 0))
}
}

impl From<Await> for Expression {
#[inline]
fn from(awaitexpr: Await) -> Self {
Self::Await(awaitexpr)
}
Expand Down
4 changes: 4 additions & 0 deletions boa_engine/src/syntax/ast/expression/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Call {
}

impl ToInternedString for Call {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!(
"{}({})",
Expand All @@ -68,6 +69,7 @@ impl ToInternedString for Call {
}

impl From<Call> for Expression {
#[inline]
fn from(call: Call) -> Self {
Self::Call(call)
}
Expand Down Expand Up @@ -113,12 +115,14 @@ impl SuperCall {
}

impl ToInternedString for SuperCall {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!("super({})", join_nodes(interner, &self.args))
}
}

impl From<SuperCall> for Expression {
#[inline]
fn from(call: SuperCall) -> Self {
Self::SuperCall(call)
}
Expand Down
7 changes: 7 additions & 0 deletions boa_engine/src/syntax/ast/expression/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,28 @@ pub struct Identifier {
}

impl PartialEq<Sym> for Identifier {
#[inline]
fn eq(&self, other: &Sym) -> bool {
self.ident == *other
}
}

impl PartialEq<Identifier> for Sym {
#[inline]
fn eq(&self, other: &Identifier) -> bool {
*self == other.ident
}
}

impl Identifier {
/// Creates a new identifier AST Expression.
#[inline]
pub fn new(ident: Sym) -> Self {
Self { ident }
}

/// Retrieves the identifier's string symbol in the interner.
#[inline]
pub fn sym(self) -> Sym {
self.ident
}
Expand All @@ -72,18 +76,21 @@ impl Identifier {
}

impl ToInternedString for Identifier {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
interner.resolve_expect(self.ident).to_owned()
}
}

impl From<Sym> for Identifier {
#[inline]
fn from(sym: Sym) -> Self {
Self { ident: sym }
}
}

impl From<Identifier> for Expression {
#[inline]
fn from(local: Identifier) -> Self {
Self::Identifier(local)
}
Expand Down
4 changes: 4 additions & 0 deletions boa_engine/src/syntax/ast/expression/literal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl ArrayLiteral {
}

impl AsRef<[Option<Expression>]> for ArrayLiteral {
#[inline]
fn as_ref(&self) -> &[Option<Expression>] {
&self.arr
}
Expand All @@ -68,6 +69,7 @@ impl<T> From<T> for ArrayLiteral
where
T: Into<Box<[Option<Expression>]>>,
{
#[inline]
fn from(decl: T) -> Self {
Self {
arr: decl.into(),
Expand All @@ -77,6 +79,7 @@ where
}

impl ToInternedString for ArrayLiteral {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
let mut buf = String::from("[");
let mut first = true;
Expand All @@ -96,6 +99,7 @@ impl ToInternedString for ArrayLiteral {
}

impl From<ArrayLiteral> for Expression {
#[inline]
fn from(arr: ArrayLiteral) -> Self {
Self::ArrayLiteral(arr)
}
Expand Down
8 changes: 8 additions & 0 deletions boa_engine/src/syntax/ast/expression/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,56 @@ pub enum Literal {
}

impl From<Sym> for Literal {
#[inline]
fn from(string: Sym) -> Self {
Self::String(string)
}
}

impl From<f64> for Literal {
#[inline]
fn from(num: f64) -> Self {
Self::Num(num)
}
}

impl From<i32> for Literal {
#[inline]
fn from(i: i32) -> Self {
Self::Int(i)
}
}

impl From<BigInt> for Literal {
#[inline]
fn from(i: BigInt) -> Self {
Self::BigInt(Box::new(i))
}
}

impl From<Box<BigInt>> for Literal {
#[inline]
fn from(i: Box<BigInt>) -> Self {
Self::BigInt(i)
}
}

impl From<bool> for Literal {
#[inline]
fn from(b: bool) -> Self {
Self::Bool(b)
}
}

impl From<Literal> for Expression {
#[inline]
fn from(lit: Literal) -> Self {
Expression::Literal(lit)
}
}

impl ToInternedString for Literal {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
match *self {
Self::String(st) => {
Expand Down
4 changes: 4 additions & 0 deletions boa_engine/src/syntax/ast/expression/literal/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct ObjectLiteral {
}

impl ObjectLiteral {
#[inline]
pub fn properties(&self) -> &[PropertyDefinition] {
&self.properties
}
Expand Down Expand Up @@ -133,6 +134,7 @@ impl ObjectLiteral {
}

impl ToInternedString for ObjectLiteral {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
self.to_indented_string(interner, 0)
}
Expand All @@ -142,6 +144,7 @@ impl<T> From<T> for ObjectLiteral
where
T: Into<Box<[PropertyDefinition]>>,
{
#[inline]
fn from(props: T) -> Self {
Self {
properties: props.into(),
Expand All @@ -150,6 +153,7 @@ where
}

impl From<ObjectLiteral> for Expression {
#[inline]
fn from(obj: ObjectLiteral) -> Self {
Self::ObjectLiteral(obj)
}
Expand Down
3 changes: 3 additions & 0 deletions boa_engine/src/syntax/ast/expression/literal/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct TemplateLiteral {
}

impl From<TemplateLiteral> for Expression {
#[inline]
fn from(tem: TemplateLiteral) -> Self {
Self::TemplateLiteral(tem)
}
Expand All @@ -32,6 +33,7 @@ pub enum TemplateElement {
}

impl TemplateLiteral {
#[inline]
pub fn new(elements: Box<[TemplateElement]>) -> Self {
Self { elements }
}
Expand All @@ -58,6 +60,7 @@ impl TemplateLiteral {
}

impl ToInternedString for TemplateLiteral {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
let mut buf = "`".to_owned();

Expand Down
3 changes: 3 additions & 0 deletions boa_engine/src/syntax/ast/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub enum Expression {

impl Expression {
/// Creates a string of the value of the expression with the given indentation.
#[inline]
pub fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
self.to_no_indent_string(interner, indentation)
}
Expand Down Expand Up @@ -274,12 +275,14 @@ impl Expression {
}

impl From<Expression> for Statement {
#[inline]
fn from(expr: Expression) -> Self {
Statement::Expression(expr)
}
}

impl ToInternedString for Expression {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
self.to_indented_string(interner, 0)
}
Expand Down
Loading

0 comments on commit 7260aa4

Please sign in to comment.