Look up an entity by source name. Returns the entity reference corresponding to `name`, if it exists.
(&self, name: &str)
| 71 | /// Look up an entity by source name. |
| 72 | /// Returns the entity reference corresponding to `name`, if it exists. |
| 73 | pub fn lookup_str(&self, name: &str) -> Option<AnyEntity> { |
| 74 | split_entity_name(name).and_then(|(ent, num)| match ent { |
| 75 | "v" => Value::with_number(num).and_then(|v| { |
| 76 | if !self.contains_value(v) { |
| 77 | None |
| 78 | } else { |
| 79 | Some(v.into()) |
| 80 | } |
| 81 | }), |
| 82 | "block" => Block::with_number(num).and_then(|block| { |
| 83 | if !self.contains_block(block) { |
| 84 | None |
| 85 | } else { |
| 86 | Some(block.into()) |
| 87 | } |
| 88 | }), |
| 89 | "ss" => StackSlot::with_number(num).and_then(|ss| { |
| 90 | if !self.contains_ss(ss) { |
| 91 | None |
| 92 | } else { |
| 93 | Some(ss.into()) |
| 94 | } |
| 95 | }), |
| 96 | "gv" => GlobalValue::with_number(num).and_then(|gv| { |
| 97 | if !self.contains_gv(gv) { |
| 98 | None |
| 99 | } else { |
| 100 | Some(gv.into()) |
| 101 | } |
| 102 | }), |
| 103 | "sig" => SigRef::with_number(num).and_then(|sig| { |
| 104 | if !self.contains_sig(sig) { |
| 105 | None |
| 106 | } else { |
| 107 | Some(sig.into()) |
| 108 | } |
| 109 | }), |
| 110 | "fn" => FuncRef::with_number(num).and_then(|fn_| { |
| 111 | if !self.contains_fn(fn_) { |
| 112 | None |
| 113 | } else { |
| 114 | Some(fn_.into()) |
| 115 | } |
| 116 | }), |
| 117 | "jt" => JumpTable::with_number(num).and_then(|jt| { |
| 118 | if !self.contains_jt(jt) { |
| 119 | None |
| 120 | } else { |
| 121 | Some(jt.into()) |
| 122 | } |
| 123 | }), |
| 124 | _ => None, |
| 125 | }) |
| 126 | } |
| 127 | |
| 128 | /// Get the source location where an entity was defined. |
| 129 | pub fn location(&self, entity: AnyEntity) -> Option<Location> { |