mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Provide fallback for linking.
This commit is contained in:
@@ -37,13 +37,10 @@ void LinkerObject::link(map<string, h160> const& _libraryAddresses)
|
||||
{
|
||||
std::map<size_t, std::string> remainingRefs;
|
||||
for (auto const& linkRef: linkReferences)
|
||||
{
|
||||
auto it = _libraryAddresses.find(linkRef.second);
|
||||
if (it == _libraryAddresses.end())
|
||||
remainingRefs.insert(linkRef);
|
||||
if (h160 const* address = matchLibrary(linkRef.second, _libraryAddresses))
|
||||
address->ref().copyTo(ref(bytecode).cropped(linkRef.first, 20));
|
||||
else
|
||||
it->second.ref().copyTo(ref(bytecode).cropped(linkRef.first, 20));
|
||||
}
|
||||
remainingRefs.insert(linkRef);
|
||||
linkReferences.swap(remainingRefs);
|
||||
}
|
||||
|
||||
@@ -60,3 +57,23 @@ string LinkerObject::toHex() const
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
h160 const*
|
||||
LinkerObject::matchLibrary(
|
||||
string const& _linkRefName,
|
||||
map<string, h160> const& _libraryAddresses
|
||||
)
|
||||
{
|
||||
auto it = _libraryAddresses.find(_linkRefName);
|
||||
if (it != _libraryAddresses.end())
|
||||
return &it->second;
|
||||
// If the user did not supply a fully qualified library name,
|
||||
// try to match only the simple libary name
|
||||
size_t colon = _linkRefName.find(':');
|
||||
if (colon == string::npos)
|
||||
return nullptr;
|
||||
it = _libraryAddresses.find(_linkRefName.substr(colon + 1));
|
||||
if (it != _libraryAddresses.end())
|
||||
return &it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ struct LinkerObject
|
||||
/// @returns a hex representation of the bytecode of the given object, replacing unlinked
|
||||
/// addresses by placeholders.
|
||||
std::string toHex() const;
|
||||
|
||||
private:
|
||||
static h160 const* matchLibrary(
|
||||
std::string const& _linkRefName,
|
||||
std::map<std::string, h160> const& _libraryAddresses
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user