Map this CodeObject to one that holds a Bag::Constant
(self, bag: Bag)
| 1196 | |
| 1197 | /// Map this CodeObject to one that holds a Bag::Constant |
| 1198 | pub fn map_bag<Bag: ConstantBag>(self, bag: Bag) -> CodeObject<Bag::Constant> { |
| 1199 | let map_names = |names: Box<[C::Name]>| { |
| 1200 | names |
| 1201 | .iter() |
| 1202 | .map(|x| bag.make_name(x.as_ref())) |
| 1203 | .collect::<Box<[_]>>() |
| 1204 | }; |
| 1205 | CodeObject { |
| 1206 | constants: self |
| 1207 | .constants |
| 1208 | .iter() |
| 1209 | .map(|x| bag.make_constant(x.borrow_constant())) |
| 1210 | .collect(), |
| 1211 | names: map_names(self.names), |
| 1212 | varnames: map_names(self.varnames), |
| 1213 | cellvars: map_names(self.cellvars), |
| 1214 | freevars: map_names(self.freevars), |
| 1215 | source_path: bag.make_name(self.source_path.as_ref()), |
| 1216 | obj_name: bag.make_name(self.obj_name.as_ref()), |
| 1217 | qualname: bag.make_name(self.qualname.as_ref()), |
| 1218 | |
| 1219 | instructions: self.instructions, |
| 1220 | locations: self.locations, |
| 1221 | flags: self.flags, |
| 1222 | posonlyarg_count: self.posonlyarg_count, |
| 1223 | arg_count: self.arg_count, |
| 1224 | kwonlyarg_count: self.kwonlyarg_count, |
| 1225 | first_line_number: self.first_line_number, |
| 1226 | max_stackdepth: self.max_stackdepth, |
| 1227 | localspluskinds: self.localspluskinds, |
| 1228 | linetable: self.linetable, |
| 1229 | exceptiontable: self.exceptiontable, |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | /// Same as `map_bag` but clones `self` |
| 1234 | pub fn map_clone_bag<Bag: ConstantBag>(&self, bag: &Bag) -> CodeObject<Bag::Constant> { |
no test coverage detected