()
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | fn constant_pool_error(context: &str, error: impl std::fmt::Display) -> io::Error { |
| 97 | io::Error::new(io::ErrorKind::InvalidData, format!("{context}: {error}")) |
| 98 | } |
| 99 | |
| 100 | fn import_constant( |
| 101 | source_index: u16, |
| 102 | source: &ConstantPool<'static>, |
| 103 | target: &mut ConstantPool<'static>, |
| 104 | target_constants: &mut HashMap<ConstantKey, u16>, |
| 105 | indexes: &mut HashMap<u16, u16>, |
| 106 | bootstrap_method_offset: u16, |
| 107 | ) -> io::Result<u16> { |
| 108 | if let Some(index) = indexes.get(&source_index) { |
| 109 | return Ok(*index); |
| 110 | } |
| 111 | |
| 112 | let constant = source |
| 113 | .try_get(source_index) |
| 114 | .map_err(|error| constant_pool_error("invalid incoming constant-pool reference", error))? |
| 115 | .clone() |
| 116 | .into_owned(); |
| 117 | let imported = match constant { |
| 118 | Constant::Class(index) => Constant::Class(import_constant( |
| 119 | index, |
| 120 | source, |
| 121 | target, |
| 122 | target_constants, |
| 123 | indexes, |
| 124 | bootstrap_method_offset, |
| 125 | )?), |
| 126 | Constant::String(index) => Constant::String(import_constant( |
| 127 | index, |
| 128 | source, |
| 129 | target, |
| 130 | target_constants, |
| 131 | indexes, |
| 132 | bootstrap_method_offset, |
| 133 | )?), |
| 134 | Constant::MethodType(index) => Constant::MethodType(import_constant( |
| 135 | index, |
| 136 | source, |
| 137 | target, |
| 138 | target_constants, |
| 139 | indexes, |
| 140 | bootstrap_method_offset, |
| 141 | )?), |
| 142 | Constant::Module(index) => Constant::Module(import_constant( |
| 143 | index, |
| 144 | source, |
| 145 | target, |
| 146 | target_constants, |
| 147 | indexes, |
| 148 | bootstrap_method_offset, |
| 149 | )?), |
| 150 | Constant::Package(index) => Constant::Package(import_constant( |
| 151 | index, |
nothing calls this directly
no test coverage detected