mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor name and type resolution.
This commit is contained in:
@@ -123,11 +123,13 @@ bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map<string, So
|
||||
return !error;
|
||||
}
|
||||
|
||||
bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsideCode)
|
||||
bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source)
|
||||
{
|
||||
try
|
||||
{
|
||||
return resolveNamesAndTypesInternal(_node, _resolveInsideCode);
|
||||
for (shared_ptr<ASTNode> const& node: _source.nodes())
|
||||
if (!resolveNamesAndTypesInternal(*node, true))
|
||||
return false;
|
||||
}
|
||||
catch (langutil::FatalError const&)
|
||||
{
|
||||
@@ -135,6 +137,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsi
|
||||
throw; // Something is weird here, rather throw again.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
|
||||
@@ -227,13 +230,14 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
|
||||
bool success = true;
|
||||
setScope(contract->scope());
|
||||
solAssert(!!m_currentScope, "");
|
||||
solAssert(_resolveInsideCode, "");
|
||||
|
||||
m_globalContext.setCurrentContract(*contract);
|
||||
updateDeclaration(*m_globalContext.currentSuper());
|
||||
updateDeclaration(*m_globalContext.currentThis());
|
||||
|
||||
for (ASTPointer<InheritanceSpecifier> const& baseContract: contract->baseContracts())
|
||||
if (!resolveNamesAndTypes(*baseContract, true))
|
||||
if (!resolveNamesAndTypesInternal(*baseContract, true))
|
||||
success = false;
|
||||
|
||||
setScope(contract);
|
||||
@@ -254,23 +258,20 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
|
||||
for (ASTPointer<ASTNode> const& node: contract->subNodes())
|
||||
{
|
||||
setScope(contract);
|
||||
if (!resolveNamesAndTypes(*node, false))
|
||||
if (!resolveNamesAndTypesInternal(*node, false))
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
return false;
|
||||
|
||||
if (!_resolveInsideCode)
|
||||
return success;
|
||||
|
||||
setScope(contract);
|
||||
|
||||
// now resolve references inside the code
|
||||
for (ASTPointer<ASTNode> const& node: contract->subNodes())
|
||||
{
|
||||
setScope(contract);
|
||||
if (!resolveNamesAndTypes(*node, true))
|
||||
if (!resolveNamesAndTypesInternal(*node, true))
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
|
||||
@@ -65,12 +65,9 @@ public:
|
||||
bool registerDeclarations(SourceUnit& _sourceUnit, ASTNode const* _currentScope = nullptr);
|
||||
/// Applies the effect of import directives.
|
||||
bool performImports(SourceUnit& _sourceUnit, std::map<std::string, SourceUnit const*> const& _sourceUnits);
|
||||
/// Resolves all names and types referenced from the given AST Node.
|
||||
/// This is usually only called at the contract level, but with a bit of care, it can also
|
||||
/// be called at deeper levels.
|
||||
/// @param _resolveInsideCode if false, does not descend into nodes that contain code.
|
||||
/// Resolves all names and types referenced from the given Source Node.
|
||||
/// @returns false in case of error.
|
||||
bool resolveNamesAndTypes(ASTNode& _node, bool _resolveInsideCode = true);
|
||||
bool resolveNamesAndTypes(SourceUnit& _source);
|
||||
/// Updates the given global declaration (used for "this"). Not to be used with declarations
|
||||
/// that create their own scope.
|
||||
/// @returns false in case of error.
|
||||
|
||||
@@ -62,9 +62,9 @@ bool TypeChecker::typeSupportedByOldABIEncoder(Type const& _type, bool _isLibrar
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TypeChecker::checkTypeRequirements(ASTNode const& _contract)
|
||||
bool TypeChecker::checkTypeRequirements(SourceUnit const& _source)
|
||||
{
|
||||
_contract.accept(*this);
|
||||
_source.accept(*this);
|
||||
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,9 @@ public:
|
||||
m_errorReporter(_errorReporter)
|
||||
{}
|
||||
|
||||
/// Performs type checking on the given contract and all of its sub-nodes.
|
||||
/// Performs type checking on the given source and all of its sub-nodes.
|
||||
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings
|
||||
bool checkTypeRequirements(ASTNode const& _contract);
|
||||
bool checkTypeRequirements(SourceUnit const& _source);
|
||||
|
||||
/// @returns the type of an expression and asserts that it is present.
|
||||
TypePointer const& type(Expression const& _expression) const;
|
||||
|
||||
Reference in New Issue
Block a user