aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
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 /libsolidity
parentc87bafd2ede044361ff7ca849a14298e97bd8318 (diff)
downloaddexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.tar.gz
dexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.tar.zst
dexon-solidity-e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1.zip
Extract scopes into compiler stack.
Diffstat (limited to 'libsolidity')
-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
4 files changed, 13 insertions, 3 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;