1
1
use std:: collections:: HashMap ;
2
2
3
3
use fuse_ast:: {
4
- Atom , BinaryOperator , BinaryOperatorKind , BindingPatternKind , CallExpression , Chunk , Function ,
5
- Identifier , VariableDeclaration ,
4
+ Atom , BinaryOperator , BinaryOperatorKind , BindingPatternKind , CallExpression , Chunk ,
5
+ Expression , Function , Identifier , VariableDeclaration ,
6
6
} ;
7
7
use fuse_common:: ReferenceType ;
8
8
use fuse_visitor:: {
@@ -31,21 +31,19 @@ impl PartialEq<ReferenceType> for ScopeId {
31
31
}
32
32
}
33
33
34
- struct IdentifierMap {
35
- map : HashMap < Atom , ReferenceType > ,
36
- }
34
+ struct IdentifierMap ( HashMap < Atom , ReferenceType > ) ;
37
35
38
36
impl IdentifierMap {
39
37
fn new ( ) -> Self {
40
- Self { map : HashMap :: new ( ) }
38
+ Self ( HashMap :: new ( ) )
41
39
}
42
40
43
41
fn insert ( & mut self , atom : Atom , ref_id : ReferenceType ) -> Option < ReferenceType > {
44
- self . map . insert ( atom, ref_id)
42
+ self . 0 . insert ( atom, ref_id)
45
43
}
46
44
47
45
fn get ( & self , atom : & Atom ) -> Option < ReferenceType > {
48
- self . map . get ( atom) . map ( |r| r. clone ( ) )
46
+ self . 0 . get ( atom) . map ( |r| r. clone ( ) )
49
47
}
50
48
}
51
49
@@ -128,13 +126,13 @@ impl ScopeTree {
128
126
}
129
127
}
130
128
131
- pub struct Inference < ' ast > {
129
+ pub struct Resolver < ' ast > {
132
130
source : & ' ast str ,
133
131
scope : ScopeTree ,
134
132
last_reference : ReferenceType ,
135
133
}
136
134
137
- impl < ' ast > Inference < ' ast > {
135
+ impl < ' ast > Resolver < ' ast > {
138
136
pub fn new ( source : & ' ast str ) -> Self {
139
137
Self {
140
138
source,
@@ -143,9 +141,9 @@ impl<'ast> Inference<'ast> {
143
141
}
144
142
}
145
143
146
- pub fn resolve ( & mut self , chunk : & ' ast mut Chunk ) -> InferenceResult {
144
+ pub fn resolve ( & mut self , chunk : & ' ast mut Chunk ) -> ResolverResult {
147
145
self . visit_chunk_mut ( chunk) ;
148
- InferenceResult {
146
+ ResolverResult {
149
147
errors : Vec :: default ( ) ,
150
148
}
151
149
}
@@ -163,7 +161,7 @@ impl<'ast> Inference<'ast> {
163
161
}
164
162
}
165
163
166
- impl < ' ast > VisitorMut < ' ast > for Inference < ' ast > {
164
+ impl < ' ast > VisitorMut < ' ast > for Resolver < ' ast > {
167
165
fn visit_identifier_mut ( & mut self , ident : & ' ast mut Identifier ) {
168
166
if ident. reference . get_mut ( ) . is_none ( ) {
169
167
self . reference_identifier ( ident) ;
@@ -191,14 +189,22 @@ impl<'ast> VisitorMut<'ast> for Inference<'ast> {
191
189
192
190
fn visit_binary_operator_mut ( & mut self , op : & ' ast mut BinaryOperator ) {
193
191
match & op. kind {
194
- BinaryOperatorKind :: Member ( _) => { }
192
+ BinaryOperatorKind :: Member ( _) => {
193
+ println ! ( "{:?}" , op) ;
194
+ // let rhs = match &op.rhs {
195
+ // Expression::Identifier(rhs) => rhs,
196
+ // Expression::BinaryOperator(op) => match op {
197
+ // },
198
+ // _ => panic!("Right hand side of a member(.) operator should be an identifier"),
199
+ // };
200
+ }
195
201
_ => { }
196
202
}
197
203
walk_binary_operator_mut ( self , op)
198
204
}
199
205
}
200
206
201
- impl < ' ast > ScopeVisitor for Inference < ' ast > {
207
+ impl < ' ast > ScopeVisitor for Resolver < ' ast > {
202
208
fn enter_scope ( & mut self ) {
203
209
self . scope . push_stack ( ) ;
204
210
}
@@ -208,8 +214,8 @@ impl<'ast> ScopeVisitor for Inference<'ast> {
208
214
}
209
215
}
210
216
211
- pub struct InferenceResult {
212
- pub errors : Vec < InferenceError > ,
217
+ pub struct ResolverResult {
218
+ pub errors : Vec < ResolverError > ,
213
219
}
214
220
215
- pub struct InferenceError { }
221
+ pub struct ResolverError { }
0 commit comments