@@ -63,17 +63,17 @@ pub struct FnIr {
6363
6464impl FnIr {
6565 /// Find the next unvisited placeholder for `param`, mark it visited,
66- /// and if it was "unknown", patch it with the given access.
67- /// Searches inside MethodCall bodies recursively.
66+ /// and apply ` patch` to it. Searches inside MethodCall bodies
67+ /// recursively.
6868 pub fn resolve_next_param (
6969 & mut self ,
7070 param : & str ,
71- access : Access ,
7271 visited : & mut HashMap < String , usize > ,
72+ patch : impl Fn ( & mut PlaceholderInner ) ,
7373 ) {
7474 let n = visited. entry ( param. to_string ( ) ) . or_insert ( 0 ) ;
7575 let nth = std:: mem:: replace ( n, * n + 1 ) ;
76- resolve_nth_unknown ( & mut self . body , param, access , nth ) ;
76+ resolve_nth_unknown ( & mut self . body , param, nth , patch ) ;
7777 }
7878
7979 pub fn has_unknowns ( & self ) -> bool {
@@ -139,6 +139,8 @@ pub enum Access {
139139pub struct PlaceholderInner {
140140 pub arg : i32 ,
141141 pub access : Access ,
142+ #[ serde( default , skip_serializing_if = "std::ops::Not::not" ) ]
143+ pub is_index_base : bool ,
142144}
143145
144146#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -157,34 +159,38 @@ impl BodyFragment {
157159 }
158160}
159161
160- /// Resolve the nth Unknown placeholder for `param` in a body fragment list.
161- fn resolve_nth_unknown ( body : & mut [ BodyFragment ] , param : & str , access : Access , nth : usize ) {
162+ /// Find the nth occurrence of `param` in a body fragment list and apply
163+ /// `patch` to it.
164+ fn resolve_nth_unknown (
165+ body : & mut [ BodyFragment ] ,
166+ param : & str ,
167+ nth : usize ,
168+ patch : impl Fn ( & mut PlaceholderInner ) ,
169+ ) {
162170 let mut count = 0 ;
163171 fn resolve (
164172 body : & mut [ BodyFragment ] ,
165173 param : & str ,
166- access : Access ,
167174 nth : usize ,
168175 count : & mut usize ,
176+ patch : & impl Fn ( & mut PlaceholderInner ) ,
169177 ) -> bool {
170178 for frag in body {
171179 match frag {
172180 BodyFragment :: Placeholder { placeholder }
173181 if placeholder. arg == param[ 1 ..] . parse ( ) . unwrap_or ( 0 ) =>
174182 {
175183 if * count == nth {
176- if placeholder. access == Access :: Unknown {
177- placeholder. access = access;
178- }
184+ patch ( placeholder) ;
179185 return true ;
180186 }
181187 * count += 1 ;
182188 }
183189 BodyFragment :: MethodCall { method_call } => {
184- if resolve ( & mut method_call. receiver , param, access , nth, count) {
190+ if resolve ( & mut method_call. receiver , param, nth, count, patch ) {
185191 return true ;
186192 }
187- if resolve ( & mut method_call. body , param, access , nth, count) {
193+ if resolve ( & mut method_call. body , param, nth, count, patch ) {
188194 return true ;
189195 }
190196 }
@@ -193,7 +199,7 @@ fn resolve_nth_unknown(body: &mut [BodyFragment], param: &str, access: Access, n
193199 }
194200 false
195201 }
196- resolve ( body, param, access , nth, & mut count) ;
202+ resolve ( body, param, nth, & mut count, & patch ) ;
197203}
198204
199205// A rule file's IR: mix of function rules (f1, f2, ...) and type rules (t1, t2, ...)
@@ -211,7 +217,6 @@ pub type FileIr = BTreeMap<String, RuleIr>;
211217/// All IR for all rule files.
212218pub struct RulesIR {
213219 pub all_ir : HashMap < String , FileIr > ,
214- pub has_unknowns : bool ,
215220 pub crate_root : PathBuf ,
216221}
217222
0 commit comments