mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename read file callback.
This commit is contained in:
parent
ab5e3a8f6d
commit
9ac2ac14c1
@ -34,7 +34,7 @@ class ErrorReporter;
|
|||||||
class SMTChecker: private ASTConstVisitor
|
class SMTChecker: private ASTConstVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SMTChecker(ErrorReporter& _errorReporter, ReadFile::Callback const& _readCallback);
|
SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readCallback);
|
||||||
|
|
||||||
void analyze(SourceUnit const& _sources);
|
void analyze(SourceUnit const& _sources);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <libsolidity/formal/SMTLib2Interface.h>
|
#include <libsolidity/formal/SMTLib2Interface.h>
|
||||||
|
|
||||||
#include <libsolidity/interface/Exceptions.h>
|
#include <libsolidity/interface/Exceptions.h>
|
||||||
|
#include <libsolidity/interface/ReadFile.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
@ -33,10 +34,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dev;
|
using namespace dev;
|
||||||
|
using namespace dev::solidity;
|
||||||
using namespace dev::solidity::smt;
|
using namespace dev::solidity::smt;
|
||||||
|
|
||||||
SMTLib2Interface::SMTLib2Interface(ReadFile::Callback const& _readFileCallback):
|
SMTLib2Interface::SMTLib2Interface(ReadCallback::Callback const& _queryCallback):
|
||||||
m_communicator(_readFileCallback)
|
m_queryCallback(_queryCallback)
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace smt
|
|||||||
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
|
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SMTLib2Interface(ReadFile::Callback const& _readFileCallback);
|
SMTLib2Interface(ReadCallback::Callback const& _queryCallback);
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ bool CompilerStack::analyze()
|
|||||||
|
|
||||||
if (noErrors)
|
if (noErrors)
|
||||||
{
|
{
|
||||||
SMTChecker smtChecker(m_errorReporter, m_readFile);
|
SMTChecker smtChecker(m_errorReporter, m_smtQuery);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
smtChecker.analyze(*source->ast);
|
smtChecker.analyze(*source->ast);
|
||||||
}
|
}
|
||||||
@ -535,17 +535,17 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string
|
|||||||
if (m_sources.count(importPath) || newSources.count(importPath))
|
if (m_sources.count(importPath) || newSources.count(importPath))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ReadFile::Result result{false, string("File not supplied initially.")};
|
ReadCallback::Result result{false, string("File not supplied initially.")};
|
||||||
if (m_readFile)
|
if (m_readFile)
|
||||||
result = m_readFile(importPath);
|
result = m_readFile(importPath);
|
||||||
|
|
||||||
if (result.success)
|
if (result.success)
|
||||||
newSources[importPath] = result.contentsOrErrorMessage;
|
newSources[importPath] = result.responseOrErrorMessage;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_errorReporter.parserError(
|
m_errorReporter.parserError(
|
||||||
import->location(),
|
import->location(),
|
||||||
string("Source \"" + importPath + "\" not found: " + result.contentsOrErrorMessage)
|
string("Source \"" + importPath + "\" not found: " + result.responseOrErrorMessage)
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
/// Creates a new compiler stack.
|
/// Creates a new compiler stack.
|
||||||
/// @param _readFile callback to used to read files for import statements. Must return
|
/// @param _readFile callback to used to read files for import statements. Must return
|
||||||
/// and must not emit exceptions.
|
/// and must not emit exceptions.
|
||||||
explicit CompilerStack(ReadFile::Callback const& _readFile = ReadFile::Callback()):
|
explicit CompilerStack(ReadCallback::Callback const& _readFile = ReadCallback::Callback()):
|
||||||
m_readFile(_readFile),
|
m_readFile(_readFile),
|
||||||
m_errorList(),
|
m_errorList(),
|
||||||
m_errorReporter(m_errorList) {}
|
m_errorReporter(m_errorList) {}
|
||||||
@ -287,7 +287,8 @@ private:
|
|||||||
std::string target;
|
std::string target;
|
||||||
};
|
};
|
||||||
|
|
||||||
ReadFile::Callback m_readFile;
|
ReadCallback::Callback m_readFile;
|
||||||
|
ReadCallback::Callback m_smtQuery;
|
||||||
bool m_optimize = false;
|
bool m_optimize = false;
|
||||||
unsigned m_optimizeRuns = 200;
|
unsigned m_optimizeRuns = 200;
|
||||||
std::map<std::string, h160> m_libraries;
|
std::map<std::string, h160> m_libraries;
|
||||||
|
@ -27,17 +27,17 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
class ReadFile: boost::noncopyable
|
class ReadCallback: boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// File reading result.
|
/// File reading or generic query result.
|
||||||
struct Result
|
struct Result
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
std::string contentsOrErrorMessage;
|
std::string responseOrErrorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// File reading callback.
|
/// File reading or generic query callback.
|
||||||
using Callback = std::function<Result(std::string const&)>;
|
using Callback = std::function<Result(std::string const&)>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -203,10 +203,10 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
|||||||
|
|
||||||
for (auto const& url: sources[sourceName]["urls"])
|
for (auto const& url: sources[sourceName]["urls"])
|
||||||
{
|
{
|
||||||
ReadFile::Result result = m_readFile(url.asString());
|
ReadCallback::Result result = m_readFile(url.asString());
|
||||||
if (result.success)
|
if (result.success)
|
||||||
{
|
{
|
||||||
if (!hash.empty() && !hashMatchesContent(hash, result.contentsOrErrorMessage))
|
if (!hash.empty() && !hashMatchesContent(hash, result.responseOrErrorMessage))
|
||||||
errors.append(formatError(
|
errors.append(formatError(
|
||||||
false,
|
false,
|
||||||
"IOError",
|
"IOError",
|
||||||
@ -215,13 +215,13 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
|||||||
));
|
));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_compilerStack.addSource(sourceName, result.contentsOrErrorMessage);
|
m_compilerStack.addSource(sourceName, result.responseOrErrorMessage);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
failures.push_back("Cannot import url (\"" + url.asString() + "\"): " + result.contentsOrErrorMessage);
|
failures.push_back("Cannot import url (\"" + url.asString() + "\"): " + result.responseOrErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& failure: failures)
|
for (auto const& failure: failures)
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
/// Creates a new StandardCompiler.
|
/// Creates a new StandardCompiler.
|
||||||
/// @param _readFile callback to used to read files for import statements. Must return
|
/// @param _readFile callback to used to read files for import statements. Must return
|
||||||
/// and must not emit exceptions.
|
/// and must not emit exceptions.
|
||||||
explicit StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback())
|
explicit StandardCompiler(ReadCallback::Callback const& _readFile = ReadCallback::Callback())
|
||||||
: m_compilerStack(_readFile), m_readFile(_readFile)
|
: m_compilerStack(_readFile), m_readFile(_readFile)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ private:
|
|||||||
Json::Value compileInternal(Json::Value const& _input);
|
Json::Value compileInternal(Json::Value const& _input);
|
||||||
|
|
||||||
CompilerStack m_compilerStack;
|
CompilerStack m_compilerStack;
|
||||||
ReadFile::Callback m_readFile;
|
ReadCallback::Callback m_readFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ Allowed options)",
|
|||||||
|
|
||||||
bool CommandLineInterface::processInput()
|
bool CommandLineInterface::processInput()
|
||||||
{
|
{
|
||||||
ReadFile::Callback fileReader = [this](string const& _path)
|
ReadCallback::Callback fileReader = [this](string const& _path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -683,25 +683,25 @@ bool CommandLineInterface::processInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isAllowed)
|
if (!isAllowed)
|
||||||
return ReadFile::Result{false, "File outside of allowed directories."};
|
return ReadCallback::Result{false, "File outside of allowed directories."};
|
||||||
else if (!boost::filesystem::exists(path))
|
else if (!boost::filesystem::exists(path))
|
||||||
return ReadFile::Result{false, "File not found."};
|
return ReadCallback::Result{false, "File not found."};
|
||||||
else if (!boost::filesystem::is_regular_file(canonicalPath))
|
else if (!boost::filesystem::is_regular_file(canonicalPath))
|
||||||
return ReadFile::Result{false, "Not a valid file."};
|
return ReadCallback::Result{false, "Not a valid file."};
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto contents = dev::contentsString(canonicalPath.string());
|
auto contents = dev::contentsString(canonicalPath.string());
|
||||||
m_sourceCodes[path.string()] = contents;
|
m_sourceCodes[path.string()] = contents;
|
||||||
return ReadFile::Result{true, contents};
|
return ReadCallback::Result{true, contents};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception const& _exception)
|
catch (Exception const& _exception)
|
||||||
{
|
{
|
||||||
return ReadFile::Result{false, "Exception in read callback: " + boost::diagnostic_information(_exception)};
|
return ReadCallback::Result{false, "Exception in read callback: " + boost::diagnostic_information(_exception)};
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
return ReadFile::Result{false, "Unknown exception in read callback."};
|
return ReadCallback::Result{false, "Unknown exception in read callback."};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, cha
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
ReadFile::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = nullptr)
|
ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = nullptr)
|
||||||
{
|
{
|
||||||
ReadFile::Callback readCallback;
|
ReadCallback::Callback readCallback;
|
||||||
if (_readCallback)
|
if (_readCallback)
|
||||||
{
|
{
|
||||||
readCallback = [=](string const& _path)
|
readCallback = [=](string const& _path)
|
||||||
@ -51,23 +51,23 @@ ReadFile::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = nullp
|
|||||||
char* contents_c = nullptr;
|
char* contents_c = nullptr;
|
||||||
char* error_c = nullptr;
|
char* error_c = nullptr;
|
||||||
_readCallback(_path.c_str(), &contents_c, &error_c);
|
_readCallback(_path.c_str(), &contents_c, &error_c);
|
||||||
ReadFile::Result result;
|
ReadCallback::Result result;
|
||||||
result.success = true;
|
result.success = true;
|
||||||
if (!contents_c && !error_c)
|
if (!contents_c && !error_c)
|
||||||
{
|
{
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.contentsOrErrorMessage = "File not found.";
|
result.responseOrErrorMessage = "File not found.";
|
||||||
}
|
}
|
||||||
if (contents_c)
|
if (contents_c)
|
||||||
{
|
{
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.contentsOrErrorMessage = string(contents_c);
|
result.responseOrErrorMessage = string(contents_c);
|
||||||
free(contents_c);
|
free(contents_c);
|
||||||
}
|
}
|
||||||
if (error_c)
|
if (error_c)
|
||||||
{
|
{
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.contentsOrErrorMessage = string(error_c);
|
result.responseOrErrorMessage = string(error_c);
|
||||||
free(error_c);
|
free(error_c);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user