aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface
diff options
context:
space:
mode:
authordjuju <julfaber@gmail.com>2017-04-26 23:03:36 +0800
committerdjuju <julfaber@gmail.com>2017-04-27 18:38:24 +0800
commit99a7aefb752f6b97475fb48da9c1c01d87af3056 (patch)
tree38cb1023e6a0cd01a93a009abd59d1e4194eefed /libsolidity/interface
parent3cbdf6d490c6871d58f12f877cdc84111a7325c1 (diff)
downloaddexon-solidity-99a7aefb752f6b97475fb48da9c1c01d87af3056.tar.gz
dexon-solidity-99a7aefb752f6b97475fb48da9c1c01d87af3056.tar.zst
dexon-solidity-99a7aefb752f6b97475fb48da9c1c01d87af3056.zip
refactoring parse() into two separate functions
Diffstat (limited to 'libsolidity/interface')
-rw-r--r--libsolidity/interface/CompilerStack.cpp31
-rw-r--r--libsolidity/interface/CompilerStack.h10
2 files changed, 34 insertions, 7 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 6ea9ea78..6276c3c4 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -128,14 +128,12 @@ bool CompilerStack::parse()
vector<string> sourcesToParse;
for (auto const& s: m_sources)
sourcesToParse.push_back(s.first);
- map<string, SourceUnit const*> sourceUnitsByName;
for (size_t i = 0; i < sourcesToParse.size(); ++i)
{
string const& path = sourcesToParse[i];
Source& source = m_sources[path];
source.scanner->reset();
source.ast = Parser(m_errors).parse(source.scanner);
- sourceUnitsByName[path] = source.ast.get();
if (!source.ast)
solAssert(!Error::containsOnlyWarnings(m_errors), "Parser returned null but did not report error.");
else
@@ -150,9 +148,14 @@ bool CompilerStack::parse()
}
}
}
- if (!Error::containsOnlyWarnings(m_errors))
- // errors while parsing. should stop before type checking
- return false;
+ m_parseSuccessful = Error::containsOnlyWarnings(m_errors);
+ return m_parseSuccessful;
+}
+
+bool CompilerStack::analyze()
+{
+ if (m_sources.empty())
+ BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("There are no sources to be analyzed."));
resolveImports();
@@ -173,6 +176,9 @@ bool CompilerStack::parse()
if (!resolver.registerDeclarations(*source->ast))
return false;
+ map<string, SourceUnit const*> sourceUnitsByName;
+ for (auto& source : m_sources)
+ sourceUnitsByName[source.first] = source.second.ast.get();
for (Source const* source: m_sourceOrder)
if (!resolver.performImports(*source->ast, sourceUnitsByName))
return false;
@@ -245,6 +251,17 @@ bool CompilerStack::parse(string const& _sourceCode)
return parse();
}
+bool CompilerStack::parseAndAnalyze()
+{
+ return parse() && analyze();
+}
+
+bool CompilerStack::parseAndAnalyze(std::string const& _sourceCode)
+{
+ setSource(_sourceCode);
+ return parseAndAnalyze();
+}
+
vector<string> CompilerStack::contractNames() const
{
if (!m_parseSuccessful)
@@ -259,7 +276,7 @@ vector<string> CompilerStack::contractNames() const
bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> const& _libraries)
{
if (!m_parseSuccessful)
- if (!parse())
+ if (!parseAndAnalyze())
return false;
m_optimize = _optimize;
@@ -277,7 +294,7 @@ bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> co
bool CompilerStack::compile(string const& _sourceCode, bool _optimize, unsigned _runs)
{
- return parse(_sourceCode) && compile(_optimize, _runs);
+ return parseAndAnalyze(_sourceCode) && compile(_optimize, _runs);
}
void CompilerStack::link()
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index d46c99be..4c7b0018 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -103,6 +103,16 @@ public:
/// Sets the given source code as the only source unit apart from standard sources and parses it.
/// @returns false on error.
bool parse(std::string const& _sourceCode);
+ /// performs the analyisis steps (imports, scopesetting, syntaxCheck, referenceResolving,
+ /// typechecking, staticAnalysis) on the set sources
+ /// @returns false on error.
+ bool analyze();
+ /// Parses and analyzes all source units that were added
+ /// @returns false on error.
+ bool parseAndAnalyze();
+ /// Sets the given source code as the only source unit apart from standard sources and parses and analyzes it.
+ /// @returns false on error.
+ bool parseAndAnalyze(std::string const& _sourceCode);
/// @returns a list of the contract names in the sources.
std::vector<std::string> contractNames() const;
std::string defaultContractName() const;