aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/CompilerStack.h
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-01-19 20:14:25 +0800
committerchriseth <c@ethdev.com>2016-01-19 20:14:25 +0800
commitd21c4276b33ced75055e2fc6a37ac8019e95f032 (patch)
tree9ac7fdc0116d51040673b8ef2f45d152495f2d8e /libsolidity/interface/CompilerStack.h
parent02340e84647171872e267a0a1635926a3243da16 (diff)
parent8f7c4e0cc227cba209e6e7981e20a677f05b69d6 (diff)
downloaddexon-solidity-d21c4276b33ced75055e2fc6a37ac8019e95f032.tar.gz
dexon-solidity-d21c4276b33ced75055e2fc6a37ac8019e95f032.tar.zst
dexon-solidity-d21c4276b33ced75055e2fc6a37ac8019e95f032.zip
Merge pull request #351 from chriseth/autoload
Automatically load imported files in solc.
Diffstat (limited to 'libsolidity/interface/CompilerStack.h')
-rw-r--r--libsolidity/interface/CompilerStack.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index 6cf19db4..517d0055 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -27,6 +27,7 @@
#include <string>
#include <memory>
#include <vector>
+#include <functional>
#include <boost/noncopyable.hpp>
#include <json/json.h>
#include <libdevcore/Common.h>
@@ -74,8 +75,14 @@ enum class DocumentationType: uint8_t
class CompilerStack: boost::noncopyable
{
public:
- /// Creates a new compiler stack. Adds standard sources if @a _addStandardSources.
- explicit CompilerStack(bool _addStandardSources = true);
+ /// File reading callback, should return a pair of content and error message (exactly one nonempty)
+ /// for a given path.
+ using ReadFileCallback = std::function<std::pair<std::string, std::string>(std::string const&)>;
+
+ /// Creates a new compiler stack.
+ /// @param _readFile callback to used to read files for import statements. Should return
+ /// @param _addStandardSources Adds standard sources if @a _addStandardSources.
+ explicit CompilerStack(bool _addStandardSources = true, ReadFileCallback const& _readFile = ReadFileCallback());
/// Resets the compiler to a state where the sources are not parsed or even removed.
void reset(bool _keepSources = false, bool _addStandardSources = true);
@@ -198,6 +205,10 @@ private:
mutable std::unique_ptr<std::string const> devDocumentation;
};
+ /// Loads the missing sources from @a _ast (named @a _path) using the callback
+ /// @a m_readFile and stores the absolute paths of all imports in the AST annotations.
+ /// @returns the newly loaded sources.
+ StringMap loadMissingSources(SourceUnit const& _ast, std::string const& _path);
void resolveImports();
/// Checks whether there are libraries with the same name, reports that as an error and
/// @returns false in this case.
@@ -215,6 +226,7 @@ private:
Contract const& contract(std::string const& _contractName = "") const;
Source const& source(std::string const& _sourceName = "") const;
+ ReadFileCallback m_readFile;
bool m_parseSuccessful;
std::map<std::string const, Source> m_sources;
std::shared_ptr<GlobalContext> m_globalContext;