MCPcopy Create free account
hub / github.com/argotorg/solidity / abiEncodingFunction

Method abiEncodingFunction

libsolidity/codegen/ABIFunctions.cpp:276–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276std::string ABIFunctions::abiEncodingFunction(
277 Type const& _from,
278 Type const& _to,
279 EncodingOptions const& _options
280)
281{
282 Type const* toInterface = _to.fullEncodingType(_options.encodeAsLibraryTypes, true, false);
283 solUnimplementedAssert(toInterface, "Encoding type \"" + _to.toString() + "\" not yet implemented.");
284 Type const& to = *toInterface;
285
286 if (_from.category() == Type::Category::StringLiteral)
287 return abiEncodingFunctionStringLiteral(_from, to, _options);
288 else if (auto toArray = dynamic_cast<ArrayType const*>(&to))
289 {
290 ArrayType const* fromArray = nullptr;
291 switch (_from.category())
292 {
293 case Type::Category::Array:
294 fromArray = dynamic_cast<ArrayType const*>(&_from);
295 break;
296 case Type::Category::ArraySlice:
297 fromArray = &dynamic_cast<ArraySliceType const*>(&_from)->arrayType();
298 solAssert(
299 fromArray->dataStoredIn(DataLocation::CallData) &&
300 fromArray->isDynamicallySized() &&
301 !fromArray->baseType()->isDynamicallyEncoded(),
302 ""
303 );
304 break;
305 default:
306 solAssert(false, "");
307 break;
308 }
309
310 switch (fromArray->location())
311 {
312 case DataLocation::CallData:
313 if (
314 fromArray->isByteArrayOrString() ||
315 *fromArray->baseType() == *TypeProvider::uint256() ||
316 *fromArray->baseType() == FixedBytesType(32)
317 )
318 return abiEncodingFunctionCalldataArrayWithoutCleanup(*fromArray, *toArray, _options);
319 else
320 return abiEncodingFunctionSimpleArray(*fromArray, *toArray, _options);
321 case DataLocation::Memory:
322 if (fromArray->isByteArrayOrString())
323 return abiEncodingFunctionMemoryByteArray(*fromArray, *toArray, _options);
324 else
325 return abiEncodingFunctionSimpleArray(*fromArray, *toArray, _options);
326 case DataLocation::Storage:
327 if (fromArray->baseType()->storageBytes() <= 16)
328 return abiEncodingFunctionCompactStorageArray(*fromArray, *toArray, _options);
329 else
330 return abiEncodingFunctionSimpleArray(*fromArray, *toArray, _options);
331 default:
332 solAssert(false, "");
333 }

Callers

nothing calls this directly

Calls 15

FixedBytesTypeClass · 0.85
createFunctionFunction · 0.85
fullEncodingTypeMethod · 0.80
isByteArrayOrStringMethod · 0.80
identifierMethod · 0.80
toFunctionNameSuffixMethod · 0.80
cleanupFunctionMethod · 0.80
conversionFunctionMethod · 0.80
leftAlignFunctionMethod · 0.80
renderMethod · 0.80
toStringMethod · 0.45
categoryMethod · 0.45

Tested by

no test coverage detected