createMapDelete deletes a key from a map by calling the appropriate runtime function. It is the implementation of the Go delete() builtin.
(keyType types.Type, m, key llvm.Value, pos token.Pos)
| 150 | // createMapDelete deletes a key from a map by calling the appropriate runtime |
| 151 | // function. It is the implementation of the Go delete() builtin. |
| 152 | func (b *builder) createMapDelete(keyType types.Type, m, key llvm.Value, pos token.Pos) error { |
| 153 | origKeyType := keyType |
| 154 | keyType = keyType.Underlying() |
| 155 | if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 { |
| 156 | // key is a string |
| 157 | params := []llvm.Value{m, key} |
| 158 | b.createRuntimeCall("hashmapStringDelete", params, "") |
| 159 | return nil |
| 160 | } else if hashmapIsBinaryKey(keyType) { |
| 161 | keyAlloca, keySize := b.createTemporaryAlloca(key.Type(), "hashmap.key") |
| 162 | b.CreateStore(key, keyAlloca) |
| 163 | b.zeroUndefBytes(b.getLLVMType(keyType), keyAlloca) |
| 164 | params := []llvm.Value{m, keyAlloca} |
| 165 | b.createRuntimeCall("hashmapBinaryDelete", params, "") |
| 166 | b.emitLifetimeEnd(keyAlloca, keySize) |
| 167 | return nil |
| 168 | } else { |
| 169 | // Key is not trivially comparable, so compare it as an interface |
| 170 | // instead. |
| 171 | itfKey := key |
| 172 | if _, ok := keyType.(*types.Interface); !ok { |
| 173 | // Not already an interface, so convert it to an interface first. |
| 174 | itfKey = b.createMakeInterface(key, origKeyType, pos) |
| 175 | } |
| 176 | params := []llvm.Value{m, itfKey} |
| 177 | b.createRuntimeCall("hashmapInterfaceDelete", params, "") |
| 178 | return nil |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Clear the given map. |
| 183 | func (b *builder) createMapClear(m llvm.Value) { |
no test coverage detected