pub fn replace_value(&mut self, found: Match<S::ValueRef>, replace: String) -> S::ValueRef {
        let bindings = found.bindings.iter().cloned().collect::<HashMap<_, _>>();
        // Vec of (parent, lhs/rhs (0/1), parse_expression)
        let mut worklist = Vec::new();
        // Remove operands to the root node and prepare for replace.
        let root = found.root;
        let mut address = self
            .ssa
            .address(root)
            .expect("No address information found");
        let block = self
            .ssa
            .block_for(root)
            .expect("Value node doesn't belong to any block");

        // Now we have a root node with no args, but retaining its uses.
        // Replace this node with the root node in the replace expression.
        for arg in &self.ssa.operands_of(root) {
            self.ssa.op_unuse(root, *arg);
        }

        let r = if let Some(tk) = self.seen.get(&replace).cloned() {
            tk
        } else {
            let t_ = self.parse_expression(&replace);
            self.seen.insert(replace, t_.clone());
            t_
        };

        let replace_root = if r.current().as_ref().map_or(false, |x| x.starts_with('%')) {
            *bindings
                .get(r.current().as_ref().unwrap())
                .unwrap_or_else(|| {
                    radeco_err!("Unknown Binding");
                    &found.root
                })
        } else if r.current().as_ref().is_some() {
            self.map_token_to_node(r.current().as_ref().unwrap(), &block, &mut address)
        } else {
            radeco_err!("r.current().as_ref() == None");
            found.root
        };

        self.ssa.replace_value(root, replace_root);
        for i in 0..r.len() {
            let p = r.op(i + 1).unwrap_or_else(|| {
                radeco_err!("parse error");
                String::new()
            });
            worklist.push((replace_root, i as u8, p));
        }

        while let Some((parent, edge_idx, subexpr)) = worklist.pop() {
            let pt = if let Some(tk) = self.seen.get(&subexpr).cloned() {
                tk
            } else {
                let t_ = self.parse_expression(&subexpr);
                self.seen.insert(subexpr, t_.clone());
                t_
            };
            let current = pt.current().unwrap_or_else(|| {
                radeco_err!("parse error");
                String::new()
            });
            let inner_node = if current.starts_with('%') {
                *bindings.get(&current).unwrap_or_else(|| {
                    radeco_err!("Unknown Binding");
                    //TODO
                    None.unwrap()
                })
            } else {
                self.map_token_to_node(&current, &block, &mut address)
            };
            self.ssa.op_use(parent, edge_idx, inner_node);
            for i in 0..pt.len() {
                let _p = r.op(i + 1).unwrap_or_else(|| {
                    radeco_err!("parse error");
                    String::new()
                });
                worklist.push((inner_node, i as u8, pt.op(i + 1).unwrap()));
            }
        }

        address.offset += 1;
        self.ssa.set_address(replace_root, address);
        replace_root
    }
/// Replaces the subtree rooted at `S::ValueRef` by the `replace` expression.
/// Returns the root of the replaced expression.
Replaces the subtree rooted at `S::ValueRef` by the `replace` expression.
Returns the root of the replaced expression.
Replaces the subtree rooted at ` S :: ValueRef ` by the ` replace ` expression . Returns the root of the replaced expression .
pub fn replace_value(&mut self, found: Match<S::ValueRef>, replace: String) -> S::ValueRef {
        let bindings = found.bindings.iter().cloned().collect::<HashMap<_, _>>();
        // Vec of (parent, lhs/rhs (0/1), parse_expression)
        let mut worklist = Vec::new();
        // Remove operands to the root node and prepare for replace.
        let root = found.root;
        let mut address = self
            .ssa
            .address(root)
            .expect("No address information found");
        let block = self
            .ssa
            .block_for(root)
            .expect("Value node doesn't belong to any block");
        // Now we have a root node with no args, but retaining its uses.
        // Replace this node with the root node in the replace expression.
        for arg in &self.ssa.operands_of(root) {
            self.ssa.op_unuse(root, *arg);
        }
        let r = if let Some(tk) = self.seen.get(&replace).cloned() {
            tk
        } else {
            let t_ = self.parse_expression(&replace);
            self.seen.insert(replace, t_.clone());
            t_
        };
        let replace_root = if r.current().as_ref().map_or(false, |x| x.starts_with('%')) {
            *bindings
                .get(r.current().as_ref().unwrap())
                .unwrap_or_else(|| {
                    radeco_err!("Unknown Binding");
                    &found.root
                })
        } else if r.current().as_ref().is_some() {
            self.map_token_to_node(r.current().as_ref().unwrap(), &block, &mut address)
        } else {
            radeco_err!("r.current().as_ref() == None");
            found.root
        };
        self.ssa.replace_value(root, replace_root);
        for i in 0..r.len() {
            let p = r.op(i + 1).unwrap_or_else(|| {
                radeco_err!("parse error");
                String::new()
            });
            worklist.push((replace_root, i as u8, p));
        }
        while let Some((parent, edge_idx, subexpr)) = worklist.pop() {
            let pt = if let Some(tk) = self.seen.get(&subexpr).cloned() {
                tk
            } else {
                let t_ = self.parse_expression(&subexpr);
                self.seen.insert(subexpr, t_.clone());
                t_
            };
            let current = pt.current().unwrap_or_else(|| {
                radeco_err!("parse error");
                String::new()
            });
            let inner_node = if current.starts_with('%') {
                *bindings.get(&current).unwrap_or_else(|| {
                    radeco_err!("Unknown Binding");
                    //TODO
                    None.unwrap()
                })
            } else {
                self.map_token_to_node(&current, &block, &mut address)
            };
            self.ssa.op_use(parent, edge_idx, inner_node);
            for i in 0..pt.len() {
                let _p = r.op(i + 1).unwrap_or_else(|| {
                    radeco_err!("parse error");
                    String::new()
                });
                worklist.push((inner_node, i as u8, pt.op(i + 1).unwrap()));
            }
        }
        address.offset += 1;
        self.ssa.set_address(replace_root, address);
        replace_root
    }
pub fn replace_value ( & mut self , found : Match < S :: ValueRef > , replace : String ) -> S :: ValueRef { let bindings = found . bindings . iter ( ) . cloned ( ) . collect :: < HashMap < _ , _ > > ( ) ; // Vec of (parent, lhs/rhs (0/1), parse_expression) let mut worklist = Vec :: new ( ) ; // Remove operands to the root node and prepare for replace. let root = found . root ; let mut address = self . ssa . address ( root ) . expect ( " " ) ; let block = self . ssa . block_for ( root ) . expect ( " " ) ; // Now we have a root node with no args, but retaining its uses. // Replace this node with the root node in the replace expression. for arg in & self . ssa . operands_of ( root ) { self . ssa . op_unuse ( root , * arg ) ; } let r = if let Some ( tk ) = self . seen . get ( & replace ) . cloned ( ) { tk } else { let t_ = self . parse_expression ( & replace ) ; self . seen . insert ( replace , t_ . clone ( ) ) ; t_ } ; let replace_root = if r . current ( ) . as_ref ( ) . map_or ( false , | x | x . starts_with ( '%' ) ) { * bindings . get ( r . current ( ) . as_ref ( ) . unwrap ( ) ) . unwrap_or_else ( | | { radeco_err ! ( " " ) ; & found . root } ) } else if r . current ( ) . as_ref ( ) . is_some ( ) { self . map_token_to_node ( r . current ( ) . as_ref ( ) . unwrap ( ) , & block , & mut address ) } else { radeco_err ! ( " " ) ; found . root } ; self . ssa . replace_value ( root , replace_root ) ; for i in 0 .. r . len ( ) { let p = r . op ( i + 1 ) . unwrap_or_else ( | | { radeco_err ! ( " " ) ; String :: new ( ) } ) ; worklist . push ( ( replace_root , i as u8 , p ) ) ; } while let Some ( ( parent , edge_idx , subexpr ) ) = worklist . pop ( ) { let pt = if let Some ( tk ) = self . seen . get ( & subexpr ) . cloned ( ) { tk } else { let t_ = self . parse_expression ( & subexpr ) ; self . seen . insert ( subexpr , t_ . clone ( ) ) ; t_ } ; let current = pt . current ( ) . unwrap_or_else ( | | { radeco_err ! ( " " ) ; String :: new ( ) } ) ; let inner_node = if current . starts_with ( '%' ) { * bindings . get ( & current ) . unwrap_or_else ( | | { radeco_err ! ( " " ) ; //TODO None . unwrap ( ) } ) } else { self . map_token_to_node ( & current , & block , & mut address ) } ; self . ssa . op_use ( parent , edge_idx , inner_node ) ; for i in 0 .. pt . len ( ) { let _p = r . op ( i + 1 ) . unwrap_or_else ( | | { radeco_err ! ( " " ) ; String :: new ( ) } ) ; worklist . push ( ( inner_node , i as u8 , pt . op ( i + 1 ) . unwrap ( ) ) ) ; } } address . offset += 1 ; self . ssa . set_address ( replace_root , address ) ; replace_root }
Replaces the subtree rooted at `S::ValueRef` by the `replace` expression.
Replaces the subtree rooted at ` S :: ValueRef ` by the ` replace ` expression .
&mut self
found
Match<S::ValueRef>
replace
String
&mut self
found
Match<S::ValueRef>
replace
String