Skip to content

Commit

Permalink
refactor(inference): cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 13, 2024
1 parent ee8cf6a commit 2e8d2f2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions crates/fuse-inference/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::HashMap;

use fuse_ast::{
Atom, BindingPatternKind, CallExpression, Chunk, Function, Identifier, VariableDeclaration,
Atom, BinaryOperator, BinaryOperatorKind, BindingPatternKind, CallExpression, Chunk, Function,
Identifier, VariableDeclaration,
};
use fuse_common::ReferenceType;
use fuse_visitor::{
walk_call_expression_mut, walk_function_mut, walk_variable_declaration_mut, ScopeVisitor,
VisitorMut,
walk_binary_operator_mut, walk_call_expression_mut, walk_function_mut,
walk_variable_declaration_mut, ScopeVisitor, VisitorMut,
};

#[derive(Debug, PartialEq, Clone, Copy)]
Expand All @@ -30,19 +31,21 @@ impl PartialEq<ReferenceType> for ScopeId {
}
}

struct IdentifierMap(HashMap<Atom, ReferenceType>);
struct IdentifierMap {
map: HashMap<Atom, ReferenceType>,
}

impl IdentifierMap {
fn new() -> Self {
Self(HashMap::new())
Self{ map: HashMap::new() }
}

fn insert(&mut self, atom: Atom, ref_id: ReferenceType) -> Option<ReferenceType> {
self.0.insert(atom, ref_id)
self.map.insert(atom, ref_id)
}

fn get(&self, atom: &Atom) -> Option<ReferenceType> {
self.0.get(atom).map(|r| r.clone())
self.map.get(atom).map(|r| r.clone())
}
}

Expand Down Expand Up @@ -185,6 +188,14 @@ impl<'ast> VisitorMut<'ast> for Inference<'ast> {
self.declare_identifier(identifier);
walk_function_mut(self, decl)
}

fn visit_binary_operator_mut(&mut self, op: &'ast mut BinaryOperator) {
match &op.kind {
BinaryOperatorKind::Member(_) => {}
_ => {}
}
walk_binary_operator_mut(self, op)
}
}

impl<'ast> ScopeVisitor for Inference<'ast> {
Expand Down

0 comments on commit 2e8d2f2

Please sign in to comment.