mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8935 from ethereum/moveScopesIntoResolver
Move scopes into resolver.
This commit is contained in:
commit
1b86f27002
@ -37,16 +37,13 @@ namespace solidity::frontend
|
|||||||
NameAndTypeResolver::NameAndTypeResolver(
|
NameAndTypeResolver::NameAndTypeResolver(
|
||||||
GlobalContext& _globalContext,
|
GlobalContext& _globalContext,
|
||||||
langutil::EVMVersion _evmVersion,
|
langutil::EVMVersion _evmVersion,
|
||||||
map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes,
|
|
||||||
ErrorReporter& _errorReporter
|
ErrorReporter& _errorReporter
|
||||||
):
|
):
|
||||||
m_scopes(_scopes),
|
|
||||||
m_evmVersion(_evmVersion),
|
m_evmVersion(_evmVersion),
|
||||||
m_errorReporter(_errorReporter),
|
m_errorReporter(_errorReporter),
|
||||||
m_globalContext(_globalContext)
|
m_globalContext(_globalContext)
|
||||||
{
|
{
|
||||||
if (!m_scopes[nullptr])
|
m_scopes[nullptr] = make_shared<DeclarationContainer>();
|
||||||
m_scopes[nullptr] = make_shared<DeclarationContainer>();
|
|
||||||
for (Declaration const* declaration: _globalContext.declarations())
|
for (Declaration const* declaration: _globalContext.declarations())
|
||||||
{
|
{
|
||||||
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration.");
|
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration.");
|
||||||
|
@ -56,7 +56,6 @@ public:
|
|||||||
NameAndTypeResolver(
|
NameAndTypeResolver(
|
||||||
GlobalContext& _globalContext,
|
GlobalContext& _globalContext,
|
||||||
langutil::EVMVersion _evmVersion,
|
langutil::EVMVersion _evmVersion,
|
||||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes,
|
|
||||||
langutil::ErrorReporter& _errorReporter
|
langutil::ErrorReporter& _errorReporter
|
||||||
);
|
);
|
||||||
/// Registers all declarations found in the AST node, usually a source unit.
|
/// Registers all declarations found in the AST node, usually a source unit.
|
||||||
@ -123,7 +122,7 @@ private:
|
|||||||
/// where nullptr denotes the global scope. Note that structs are not scope since they do
|
/// where nullptr denotes the global scope. Note that structs are not scope since they do
|
||||||
/// not contain code.
|
/// not contain code.
|
||||||
/// Aliases (for example `import "x" as y;`) create multiple pointers to the same scope.
|
/// 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;
|
||||||
|
|
||||||
langutil::EVMVersion m_evmVersion;
|
langutil::EVMVersion m_evmVersion;
|
||||||
DeclarationContainer* m_currentScope = nullptr;
|
DeclarationContainer* m_currentScope = nullptr;
|
||||||
|
@ -214,7 +214,6 @@ void CompilerStack::reset(bool _keepSettings)
|
|||||||
m_metadataHash = MetadataHash::IPFS;
|
m_metadataHash = MetadataHash::IPFS;
|
||||||
}
|
}
|
||||||
m_globalContext.reset();
|
m_globalContext.reset();
|
||||||
m_scopes.clear();
|
|
||||||
m_sourceOrder.clear();
|
m_sourceOrder.clear();
|
||||||
m_contracts.clear();
|
m_contracts.clear();
|
||||||
m_errorReporter.clear();
|
m_errorReporter.clear();
|
||||||
@ -314,7 +313,8 @@ bool CompilerStack::analyze()
|
|||||||
noErrors = false;
|
noErrors = false;
|
||||||
|
|
||||||
m_globalContext = make_shared<GlobalContext>();
|
m_globalContext = make_shared<GlobalContext>();
|
||||||
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_scopes, m_errorReporter);
|
// We need to keep the same resolver during the whole process.
|
||||||
|
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (source->ast && !resolver.registerDeclarations(*source->ast))
|
if (source->ast && !resolver.registerDeclarations(*source->ast))
|
||||||
return false;
|
return false;
|
||||||
|
@ -447,8 +447,6 @@ private:
|
|||||||
std::map<util::h256, std::string> m_smtlib2Responses;
|
std::map<util::h256, std::string> m_smtlib2Responses;
|
||||||
std::shared_ptr<GlobalContext> m_globalContext;
|
std::shared_ptr<GlobalContext> m_globalContext;
|
||||||
std::vector<Source const*> m_sourceOrder;
|
std::vector<Source const*> m_sourceOrder;
|
||||||
/// This is updated during compilation.
|
|
||||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
|
|
||||||
std::map<std::string const, Contract> m_contracts;
|
std::map<std::string const, Contract> m_contracts;
|
||||||
langutil::ErrorList m_errorList;
|
langutil::ErrorList m_errorList;
|
||||||
langutil::ErrorReporter m_errorReporter;
|
langutil::ErrorReporter m_errorReporter;
|
||||||
|
@ -58,9 +58,8 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
|||||||
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(_sourceCode)));
|
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(_sourceCode)));
|
||||||
BOOST_CHECK(!!sourceUnit);
|
BOOST_CHECK(!!sourceUnit);
|
||||||
|
|
||||||
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
|
|
||||||
GlobalContext globalContext;
|
GlobalContext globalContext;
|
||||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), scopes, errorReporter);
|
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||||
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
||||||
solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
|
solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
|
@ -116,8 +116,7 @@ bytes compileFirstExpression(
|
|||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
GlobalContext globalContext;
|
GlobalContext globalContext;
|
||||||
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
|
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), scopes, errorReporter);
|
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
|
Loading…
Reference in New Issue
Block a user