aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-02-01 05:59:56 +0800
committerchriseth <c@ethdev.com>2017-02-14 20:23:44 +0800
commite67faa9839ebd0dadef2adf3ed1ef69fac6f65e1 (patch)
treed25d2cd8ecf784824406397130559a407dc2f0db
parentc87bafd2ede044361ff7ca849a14298e97bd8318 (diff)
downloaddexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.tar.gz
dexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.tar.zst
dexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.zip
Extract scopes into compiler stack.
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp2
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.h8
-rw-r--r--libsolidity/interface/CompilerStack.cpp3
-rw-r--r--libsolidity/interface/CompilerStack.h3
-rw-r--r--test/libsolidity/Assembly.cpp3
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp3
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp3
7 files changed, 19 insertions, 6 deletions
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index 5fea91d6..ed1bd1d3 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -34,8 +34,10 @@ namespace solidity
NameAndTypeResolver::NameAndTypeResolver(
vector<Declaration const*> const& _globals,
+ map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes,
ErrorList& _errors
) :
+ m_scopes(_scopes),
m_errors(_errors)
{
if (!m_scopes[nullptr])
diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h
index 67a6c0e4..1c7af0c9 100644
--- a/libsolidity/analysis/NameAndTypeResolver.h
+++ b/libsolidity/analysis/NameAndTypeResolver.h
@@ -42,7 +42,11 @@ namespace solidity
class NameAndTypeResolver: private boost::noncopyable
{
public:
- NameAndTypeResolver(std::vector<Declaration const*> const& _globals, ErrorList& _errors);
+ NameAndTypeResolver(
+ std::vector<Declaration const*> const& _globals,
+ std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes,
+ ErrorList& _errors
+ );
/// Registers all declarations found in the AST node, usually a source unit.
/// @returns false in case of error.
bool registerDeclarations(ASTNode& _sourceUnit);
@@ -113,7 +117,7 @@ private:
/// where nullptr denotes the global scope. Note that structs are not scope since they do
/// not contain code.
/// Aliases (for example `import "x" as y;`) create multiple pointers to the same scope.
- std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
+ std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
DeclarationContainer* m_currentScope = nullptr;
ErrorList& m_errors;
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 3335c40e..9d8d872f 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -88,6 +88,7 @@ void CompilerStack::reset(bool _keepSources)
m_optimize = false;
m_optimizeRuns = 200;
m_globalContext.reset();
+ m_scopes.clear();
m_sourceOrder.clear();
m_contracts.clear();
m_errors.clear();
@@ -165,7 +166,7 @@ bool CompilerStack::parse()
noErrors = false;
m_globalContext = make_shared<GlobalContext>();
- NameAndTypeResolver resolver(m_globalContext->declarations(), m_errors);
+ NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errors);
for (Source const* source: m_sourceOrder)
if (!resolver.registerDeclarations(*source->ast))
return false;
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index 9ee70215..eddfea68 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -52,6 +52,7 @@ namespace solidity
// forward declarations
class Scanner;
+class ASTNode;
class ContractDefinition;
class FunctionDefinition;
class SourceUnit;
@@ -59,6 +60,7 @@ class Compiler;
class GlobalContext;
class InterfaceHandler;
class Error;
+class DeclarationContainer;
enum class DocumentationType: uint8_t
{
@@ -271,6 +273,7 @@ private:
bool m_parseSuccessful;
std::map<std::string const, Source> m_sources;
std::shared_ptr<GlobalContext> m_globalContext;
+ std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
std::vector<Source const*> m_sourceOrder;
std::map<std::string const, Contract> m_contracts;
std::string m_formalTranslation;
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index 497bfc77..c4ec0d20 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -53,7 +53,8 @@ eth::AssemblyItems compileContract(const string& _sourceCode)
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
BOOST_CHECK(!!sourceUnit);
- NameAndTypeResolver resolver({}, errors);
+ map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
+ NameAndTypeResolver resolver({}, scopes, errors);
solAssert(Error::containsOnlyWarnings(errors), "");
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index a769776e..3116aea8 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -114,7 +114,8 @@ bytes compileFirstExpression(
declarations.push_back(variable.get());
ErrorList errors;
- NameAndTypeResolver resolver(declarations, errors);
+ map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
+ NameAndTypeResolver resolver(declarations, scopes, errors);
resolver.registerDeclarations(*sourceUnit);
vector<ContractDefinition const*> inheritanceHierarchy;
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 29856d31..1a4f3cdc 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -66,7 +66,8 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false,
return make_pair(sourceUnit, errors.at(0));
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
- NameAndTypeResolver resolver(globalContext->declarations(), errors);
+ map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
+ NameAndTypeResolver resolver(globalContext->declarations(), scopes, errors);
solAssert(Error::containsOnlyWarnings(errors), "");
resolver.registerDeclarations(*sourceUnit);