mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow remappings with empty prefix.
This commit is contained in:
@@ -58,22 +58,31 @@ using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::solidity;
|
||||
|
||||
void CompilerStack::setRemappings(vector<string> const& _remappings)
|
||||
boost::optional<CompilerStack::Remapping> CompilerStack::parseRemapping(string const& _remapping)
|
||||
{
|
||||
auto eq = find(_remapping.begin(), _remapping.end(), '=');
|
||||
if (eq == _remapping.end())
|
||||
return {};
|
||||
|
||||
auto colon = find(_remapping.begin(), eq, ':');
|
||||
|
||||
Remapping r;
|
||||
|
||||
r.context = colon == eq ? string() : string(_remapping.begin(), colon);
|
||||
r.prefix = colon == eq ? string(_remapping.begin(), eq) : string(colon + 1, eq);
|
||||
r.target = string(eq + 1, _remapping.end());
|
||||
|
||||
if (r.prefix.empty())
|
||||
return {};
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void CompilerStack::setRemappings(vector<Remapping> const& _remappings)
|
||||
{
|
||||
vector<Remapping> remappings;
|
||||
for (auto const& remapping: _remappings)
|
||||
{
|
||||
auto eq = find(remapping.begin(), remapping.end(), '=');
|
||||
if (eq == remapping.end())
|
||||
continue; // ignore
|
||||
auto colon = find(remapping.begin(), eq, ':');
|
||||
Remapping r;
|
||||
r.context = colon == eq ? string() : string(remapping.begin(), colon);
|
||||
r.prefix = colon == eq ? string(remapping.begin(), eq) : string(colon + 1, eq);
|
||||
r.target = string(eq + 1, remapping.end());
|
||||
remappings.push_back(r);
|
||||
}
|
||||
swap(m_remappings, remappings);
|
||||
solAssert(!remapping.prefix.empty(), "");
|
||||
m_remappings = _remappings;
|
||||
}
|
||||
|
||||
void CompilerStack::setEVMVersion(EVMVersion _version)
|
||||
|
||||
@@ -84,6 +84,13 @@ public:
|
||||
CompilationSuccessful
|
||||
};
|
||||
|
||||
struct Remapping
|
||||
{
|
||||
std::string context;
|
||||
std::string prefix;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
/// Creates a new compiler stack.
|
||||
/// @param _readFile callback to used to read files for import statements. Must return
|
||||
/// and must not emit exceptions.
|
||||
@@ -103,8 +110,11 @@ public:
|
||||
/// All settings, with the exception of remappings, are reset.
|
||||
void reset(bool _keepSources = false);
|
||||
|
||||
/// Sets path remappings in the format "context:prefix=target"
|
||||
void setRemappings(std::vector<std::string> const& _remappings);
|
||||
// Parses a remapping of the format "context:prefix=target".
|
||||
static boost::optional<Remapping> parseRemapping(std::string const& _remapping);
|
||||
|
||||
/// Sets path remappings.
|
||||
void setRemappings(std::vector<Remapping> const& _remappings);
|
||||
|
||||
/// Sets library addresses. Addresses are cleared iff @a _libraries is missing.
|
||||
/// Will not take effect before running compile.
|
||||
@@ -319,13 +329,6 @@ private:
|
||||
FunctionDefinition const& _function
|
||||
) const;
|
||||
|
||||
struct Remapping
|
||||
{
|
||||
std::string context;
|
||||
std::string prefix;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
ReadCallback::Callback m_readFile;
|
||||
ReadCallback::Callback m_smtQuery;
|
||||
bool m_optimize = false;
|
||||
|
||||
@@ -326,9 +326,14 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
||||
m_compilerStack.setEVMVersion(*version);
|
||||
}
|
||||
|
||||
vector<string> remappings;
|
||||
vector<CompilerStack::Remapping> remappings;
|
||||
for (auto const& remapping: settings.get("remappings", Json::Value()))
|
||||
remappings.push_back(remapping.asString());
|
||||
{
|
||||
if (auto r = CompilerStack::parseRemapping(remapping.asString()))
|
||||
remappings.emplace_back(std::move(*r));
|
||||
else
|
||||
return formatFatalError("JSONError", "Invalid remapping: \"" + remapping.asString() + "\"");
|
||||
}
|
||||
m_compilerStack.setRemappings(remappings);
|
||||
|
||||
Json::Value optimizerSettings = settings.get("optimizer", Json::Value());
|
||||
|
||||
Reference in New Issue
Block a user