2014-10-13 15:13:48 +00:00
|
|
|
/*
|
2019-02-13 15:56:46 +00:00
|
|
|
This file is part of solidity.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-10-13 15:13:48 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2014-10-13 15:13:48 +00:00
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Parser part that determines the declarations corresponding to names and the types of expressions.
|
|
|
|
*/
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
2017-02-16 11:36:43 +00:00
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/analysis/TypeChecker.h>
|
2018-12-17 11:30:08 +00:00
|
|
|
#include <libsolidity/ast/AST.h>
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/ErrorReporter.h>
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/StringUtils.h>
|
2017-06-09 13:35:27 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2020-10-07 22:41:04 +00:00
|
|
|
#include <unordered_set>
|
2017-06-09 13:35:27 +00:00
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
using namespace std;
|
2019-12-11 16:31:36 +00:00
|
|
|
using namespace solidity::langutil;
|
2014-10-24 17:06:30 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2014-10-16 12:08:54 +00:00
|
|
|
{
|
2014-10-13 13:07:21 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
NameAndTypeResolver::NameAndTypeResolver(
|
2019-04-29 16:29:40 +00:00
|
|
|
GlobalContext& _globalContext,
|
2019-11-14 11:44:33 +00:00
|
|
|
langutil::EVMVersion _evmVersion,
|
2017-05-11 13:26:35 +00:00
|
|
|
ErrorReporter& _errorReporter
|
2019-11-14 11:44:33 +00:00
|
|
|
):
|
|
|
|
m_evmVersion(_evmVersion),
|
2019-04-29 16:29:40 +00:00
|
|
|
m_errorReporter(_errorReporter),
|
|
|
|
m_globalContext(_globalContext)
|
2014-11-20 17:33:23 +00:00
|
|
|
{
|
2020-05-14 09:56:10 +00:00
|
|
|
m_scopes[nullptr] = make_shared<DeclarationContainer>();
|
2019-04-29 16:29:40 +00:00
|
|
|
for (Declaration const* declaration: _globalContext.declarations())
|
2017-12-30 12:47:15 +00:00
|
|
|
{
|
2020-10-07 22:41:04 +00:00
|
|
|
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration, false, false), "Unable to register global declaration.");
|
2017-12-30 12:47:15 +00:00
|
|
|
}
|
2014-11-20 17:33:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode const* _currentScope)
|
2014-12-03 16:45:12 +00:00
|
|
|
{
|
2014-12-05 14:35:05 +00:00
|
|
|
// The helper registers all declarations in m_scopes as a side-effect of its construction.
|
2015-10-14 18:37:41 +00:00
|
|
|
try
|
|
|
|
{
|
2019-04-29 16:29:40 +00:00
|
|
|
DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, m_globalContext, _currentScope);
|
2015-10-14 18:37:41 +00:00
|
|
|
}
|
2018-11-14 16:11:55 +00:00
|
|
|
catch (langutil::FatalError const&)
|
2015-10-14 18:37:41 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
if (m_errorReporter.errors().empty())
|
2015-10-16 12:52:01 +00:00
|
|
|
throw; // Something is weird here, rather throw again.
|
2015-10-14 18:37:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-12-03 16:45:12 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 02:09:47 +00:00
|
|
|
bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map<string, SourceUnit const*> const& _sourceUnits)
|
|
|
|
{
|
|
|
|
DeclarationContainer& target = *m_scopes.at(&_sourceUnit);
|
|
|
|
bool error = false;
|
|
|
|
for (auto const& node: _sourceUnit.nodes())
|
|
|
|
if (auto imp = dynamic_cast<ImportDirective const*>(node.get()))
|
|
|
|
{
|
2020-09-10 10:01:23 +00:00
|
|
|
string const& path = *imp->annotation().absolutePath;
|
2021-02-16 12:30:12 +00:00
|
|
|
// The import resolution in CompilerStack enforces this.
|
|
|
|
solAssert(_sourceUnits.count(path), "");
|
2016-01-11 12:55:58 +00:00
|
|
|
auto scope = m_scopes.find(_sourceUnits.at(path));
|
|
|
|
solAssert(scope != end(m_scopes), "");
|
|
|
|
if (!imp->symbolAliases().empty())
|
|
|
|
for (auto const& alias: imp->symbolAliases())
|
|
|
|
{
|
2022-07-14 14:24:10 +00:00
|
|
|
auto declarations = scope->second->resolveName(alias.symbol->name());
|
2016-01-11 12:55:58 +00:00
|
|
|
if (declarations.empty())
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
2020-05-05 22:38:28 +00:00
|
|
|
2904_error,
|
2016-01-11 12:55:58 +00:00
|
|
|
imp->location(),
|
|
|
|
"Declaration \"" +
|
2019-09-25 12:14:44 +00:00
|
|
|
alias.symbol->name() +
|
2016-01-11 12:55:58 +00:00
|
|
|
"\" not found in \"" +
|
|
|
|
path +
|
|
|
|
"\" (referenced as \"" +
|
|
|
|
imp->path() +
|
|
|
|
"\")."
|
|
|
|
);
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (Declaration const* declaration: declarations)
|
2017-02-02 11:39:12 +00:00
|
|
|
if (!DeclarationRegistrationHelper::registerDeclaration(
|
2021-09-01 16:29:19 +00:00
|
|
|
target,
|
|
|
|
*declaration,
|
|
|
|
alias.alias ? alias.alias.get() : &alias.symbol->name(),
|
|
|
|
&alias.location,
|
|
|
|
false,
|
|
|
|
m_errorReporter
|
2017-02-02 11:39:12 +00:00
|
|
|
))
|
2016-01-11 12:55:58 +00:00
|
|
|
error = true;
|
|
|
|
}
|
2015-12-15 14:46:03 +00:00
|
|
|
else if (imp->name().empty())
|
2015-12-05 02:09:47 +00:00
|
|
|
for (auto const& nameAndDeclaration: scope->second->declarations())
|
|
|
|
for (auto const& declaration: nameAndDeclaration.second)
|
2017-02-02 11:39:12 +00:00
|
|
|
if (!DeclarationRegistrationHelper::registerDeclaration(
|
2020-09-26 22:00:56 +00:00
|
|
|
target, *declaration, &nameAndDeclaration.first, &imp->location(), false, m_errorReporter
|
2017-02-02 11:39:12 +00:00
|
|
|
))
|
|
|
|
error = true;
|
2015-12-05 02:09:47 +00:00
|
|
|
}
|
2020-09-21 13:36:00 +00:00
|
|
|
_sourceUnit.annotation().exportedSymbols = m_scopes[&_sourceUnit]->declarations();
|
2015-12-05 02:09:47 +00:00
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
2020-06-11 15:17:07 +00:00
|
|
|
bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2015-10-14 18:37:41 +00:00
|
|
|
try
|
|
|
|
{
|
2020-06-11 15:17:07 +00:00
|
|
|
for (shared_ptr<ASTNode> const& node: _source.nodes())
|
2020-09-30 17:38:01 +00:00
|
|
|
{
|
|
|
|
setScope(&_source);
|
2020-06-11 15:17:07 +00:00
|
|
|
if (!resolveNamesAndTypesInternal(*node, true))
|
|
|
|
return false;
|
2020-09-30 17:38:01 +00:00
|
|
|
}
|
2015-04-15 15:40:50 +00:00
|
|
|
}
|
2018-11-14 16:11:55 +00:00
|
|
|
catch (langutil::FatalError const&)
|
2015-04-15 15:40:50 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
if (m_errorReporter.errors().empty())
|
2015-11-04 13:49:54 +00:00
|
|
|
throw; // Something is weird here, rather throw again.
|
2015-10-14 18:37:41 +00:00
|
|
|
return false;
|
2015-04-15 15:40:50 +00:00
|
|
|
}
|
2020-06-11 15:17:07 +00:00
|
|
|
return true;
|
2014-10-13 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 18:37:41 +00:00
|
|
|
bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
|
2014-12-03 16:45:12 +00:00
|
|
|
{
|
2015-10-14 18:37:41 +00:00
|
|
|
try
|
|
|
|
{
|
2020-10-07 22:41:04 +00:00
|
|
|
m_scopes[nullptr]->registerDeclaration(_declaration, false, true);
|
2015-10-14 18:37:41 +00:00
|
|
|
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
|
|
|
|
}
|
2018-11-14 16:11:55 +00:00
|
|
|
catch (langutil::FatalError const&)
|
2015-10-14 18:37:41 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
if (m_errorReporter.errors().empty())
|
2015-10-16 12:52:01 +00:00
|
|
|
throw; // Something is weird here, rather throw again.
|
2015-10-14 18:37:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-12-03 16:45:12 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
void NameAndTypeResolver::activateVariable(string const& _name)
|
|
|
|
{
|
|
|
|
solAssert(m_currentScope, "");
|
2018-07-10 16:54:43 +00:00
|
|
|
// Scoped local variables are invisible before activation.
|
|
|
|
// When a local variable is activated, its name is removed
|
|
|
|
// from a scope's invisible variables.
|
|
|
|
// This is used to avoid activation of variables of same name
|
|
|
|
// in the same scope (an error is returned).
|
2018-07-06 09:04:30 +00:00
|
|
|
if (m_currentScope->isInvisible(_name))
|
|
|
|
m_currentScope->activateVariable(_name);
|
2018-02-15 10:30:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 02:09:47 +00:00
|
|
|
vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2014-10-30 00:20:32 +00:00
|
|
|
auto iterator = m_scopes.find(_scope);
|
|
|
|
if (iterator == end(m_scopes))
|
2015-05-07 08:12:27 +00:00
|
|
|
return vector<Declaration const*>({});
|
2022-07-14 14:24:10 +00:00
|
|
|
return iterator->second->resolveName(_name);
|
2014-10-13 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _includeInvisibles) const
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2022-07-14 14:24:10 +00:00
|
|
|
ResolvingSettings settings;
|
|
|
|
settings.recursive = true;
|
|
|
|
settings.alsoInvisible = _includeInvisibles;
|
2022-08-23 17:28:45 +00:00
|
|
|
return m_currentScope->resolveName(_name, std::move(settings));
|
2014-10-13 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 14:09:22 +00:00
|
|
|
Declaration const* NameAndTypeResolver::pathFromCurrentScope(vector<ASTString> const& _path) const
|
2022-06-08 16:12:27 +00:00
|
|
|
{
|
|
|
|
if (auto declarations = pathFromCurrentScopeWithAllDeclarations(_path); !declarations.empty())
|
|
|
|
return declarations.back();
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Declaration const*> NameAndTypeResolver::pathFromCurrentScopeWithAllDeclarations(std::vector<ASTString> const& _path) const
|
2015-10-06 10:35:10 +00:00
|
|
|
{
|
|
|
|
solAssert(!_path.empty(), "");
|
2022-06-08 16:12:27 +00:00
|
|
|
vector<Declaration const*> pathDeclarations;
|
|
|
|
|
2022-07-14 14:24:10 +00:00
|
|
|
ResolvingSettings settings;
|
|
|
|
settings.recursive = true;
|
|
|
|
settings.alsoInvisible = false;
|
|
|
|
settings.onlyVisibleAsUnqualifiedNames = true;
|
2022-08-23 17:28:45 +00:00
|
|
|
vector<Declaration const*> candidates = m_currentScope->resolveName(_path.front(), std::move(settings));
|
2021-02-08 04:50:58 +00:00
|
|
|
|
2015-10-06 10:35:10 +00:00
|
|
|
for (size_t i = 1; i < _path.size() && candidates.size() == 1; i++)
|
|
|
|
{
|
|
|
|
if (!m_scopes.count(candidates.front()))
|
2022-06-08 16:12:27 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
pathDeclarations.push_back(candidates.front());
|
|
|
|
|
2022-07-14 14:24:10 +00:00
|
|
|
candidates = m_scopes.at(candidates.front())->resolveName(_path[i]);
|
2015-10-06 10:35:10 +00:00
|
|
|
}
|
|
|
|
if (candidates.size() == 1)
|
2022-06-08 16:12:27 +00:00
|
|
|
{
|
|
|
|
pathDeclarations.push_back(candidates.front());
|
|
|
|
return pathDeclarations;
|
|
|
|
}
|
2015-10-06 10:35:10 +00:00
|
|
|
else
|
2022-06-08 16:12:27 +00:00
|
|
|
return {};
|
2015-10-06 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 22:41:04 +00:00
|
|
|
void NameAndTypeResolver::warnHomonymDeclarations() const
|
|
|
|
{
|
|
|
|
DeclarationContainer::Homonyms homonyms;
|
|
|
|
m_scopes.at(nullptr)->populateHomonyms(back_inserter(homonyms));
|
|
|
|
|
2020-10-08 01:59:06 +00:00
|
|
|
for (auto [innerLocation, outerDeclarations]: homonyms)
|
2020-10-07 22:41:04 +00:00
|
|
|
{
|
2020-10-08 01:59:06 +00:00
|
|
|
solAssert(innerLocation && !outerDeclarations.empty(), "");
|
2020-10-07 22:41:04 +00:00
|
|
|
|
2020-10-08 01:59:06 +00:00
|
|
|
bool magicShadowed = false;
|
|
|
|
SecondarySourceLocation homonymousLocations;
|
|
|
|
SecondarySourceLocation shadowedLocations;
|
|
|
|
for (Declaration const* outerDeclaration: outerDeclarations)
|
2020-10-07 22:41:04 +00:00
|
|
|
{
|
2020-10-08 01:59:06 +00:00
|
|
|
solAssert(outerDeclaration, "");
|
|
|
|
if (dynamic_cast<MagicVariableDeclaration const*>(outerDeclaration))
|
|
|
|
magicShadowed = true;
|
|
|
|
else if (!outerDeclaration->isVisibleInContract())
|
|
|
|
homonymousLocations.append("The other declaration is here:", outerDeclaration->location());
|
2020-10-07 22:41:04 +00:00
|
|
|
else
|
2020-10-08 01:59:06 +00:00
|
|
|
shadowedLocations.append("The shadowed declaration is here:", outerDeclaration->location());
|
2020-10-07 22:41:04 +00:00
|
|
|
}
|
2020-10-08 01:59:06 +00:00
|
|
|
|
|
|
|
if (magicShadowed)
|
|
|
|
m_errorReporter.warning(
|
|
|
|
2319_error,
|
|
|
|
*innerLocation,
|
|
|
|
"This declaration shadows a builtin symbol."
|
|
|
|
);
|
|
|
|
if (!homonymousLocations.infos.empty())
|
|
|
|
m_errorReporter.warning(
|
|
|
|
8760_error,
|
|
|
|
*innerLocation,
|
|
|
|
"This declaration has the same name as another declaration.",
|
|
|
|
homonymousLocations
|
|
|
|
);
|
|
|
|
if (!shadowedLocations.infos.empty())
|
|
|
|
m_errorReporter.warning(
|
|
|
|
2519_error,
|
|
|
|
*innerLocation,
|
|
|
|
"This declaration shadows an existing declaration.",
|
|
|
|
shadowedLocations
|
|
|
|
);
|
2020-10-07 22:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
void NameAndTypeResolver::setScope(ASTNode const* _node)
|
|
|
|
{
|
|
|
|
m_currentScope = m_scopes[_node].get();
|
|
|
|
}
|
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode)
|
|
|
|
{
|
|
|
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(&_node))
|
|
|
|
{
|
|
|
|
bool success = true;
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(contract->scope());
|
2017-02-16 11:36:43 +00:00
|
|
|
solAssert(!!m_currentScope, "");
|
2020-06-11 15:17:07 +00:00
|
|
|
solAssert(_resolveInsideCode, "");
|
2017-02-16 11:36:43 +00:00
|
|
|
|
2019-04-29 16:29:40 +00:00
|
|
|
m_globalContext.setCurrentContract(*contract);
|
2020-12-07 11:10:35 +00:00
|
|
|
if (!contract->isLibrary())
|
|
|
|
updateDeclaration(*m_globalContext.currentSuper());
|
2019-04-29 16:29:40 +00:00
|
|
|
updateDeclaration(*m_globalContext.currentThis());
|
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
for (ASTPointer<InheritanceSpecifier> const& baseContract: contract->baseContracts())
|
2020-06-11 15:17:07 +00:00
|
|
|
if (!resolveNamesAndTypesInternal(*baseContract, true))
|
2017-02-16 11:36:43 +00:00
|
|
|
success = false;
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(contract);
|
2017-02-16 11:36:43 +00:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
linearizeBaseContracts(*contract);
|
|
|
|
vector<ContractDefinition const*> properBases(
|
|
|
|
++contract->annotation().linearizedBaseContracts.begin(),
|
|
|
|
contract->annotation().linearizedBaseContracts.end()
|
|
|
|
);
|
|
|
|
|
|
|
|
for (ContractDefinition const* base: properBases)
|
|
|
|
importInheritedScope(*base);
|
|
|
|
}
|
|
|
|
|
|
|
|
// these can contain code, only resolve parameters for now
|
|
|
|
for (ASTPointer<ASTNode> const& node: contract->subNodes())
|
|
|
|
{
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(contract);
|
2020-06-11 15:17:07 +00:00
|
|
|
if (!resolveNamesAndTypesInternal(*node, false))
|
2017-02-16 11:36:43 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return false;
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(contract);
|
2017-02-16 11:36:43 +00:00
|
|
|
|
|
|
|
// now resolve references inside the code
|
|
|
|
for (ASTPointer<ASTNode> const& node: contract->subNodes())
|
|
|
|
{
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(contract);
|
2020-06-11 15:17:07 +00:00
|
|
|
if (!resolveNamesAndTypesInternal(*node, true))
|
2017-02-16 11:36:43 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2020-05-04 16:38:00 +00:00
|
|
|
|
|
|
|
// make "this" and "super" invisible.
|
2020-10-07 22:41:04 +00:00
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentThis(), true, true);
|
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentSuper(), true, true);
|
2020-05-04 16:38:00 +00:00
|
|
|
m_globalContext.resetCurrentContract();
|
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_scopes.count(&_node))
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(&_node);
|
2019-11-14 11:44:33 +00:00
|
|
|
return ReferencesResolver(m_errorReporter, *this, m_evmVersion, _resolveInsideCode).resolve(_node);
|
2017-02-16 11:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:12:27 +00:00
|
|
|
void NameAndTypeResolver::importInheritedScope(ContractDefinition const& _base)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
auto iterator = m_scopes.find(&_base);
|
|
|
|
solAssert(iterator != end(m_scopes), "");
|
2015-12-05 01:26:54 +00:00
|
|
|
for (auto const& nameAndDeclaration: iterator->second->declarations())
|
2015-03-01 03:34:39 +00:00
|
|
|
for (auto const& declaration: nameAndDeclaration.second)
|
|
|
|
// Import if it was declared in the base, is not the constructor and is visible in derived classes
|
2015-08-31 16:44:29 +00:00
|
|
|
if (declaration->scope() == &_base && declaration->isVisibleInDerivedContracts())
|
2020-10-07 22:41:04 +00:00
|
|
|
if (!m_currentScope->registerDeclaration(*declaration, false, false))
|
2016-11-01 16:18:00 +00:00
|
|
|
{
|
|
|
|
SourceLocation firstDeclarationLocation;
|
|
|
|
SourceLocation secondDeclarationLocation;
|
|
|
|
Declaration const* conflictingDeclaration = m_currentScope->conflictingDeclaration(*declaration);
|
|
|
|
solAssert(conflictingDeclaration, "");
|
|
|
|
|
2016-12-02 15:06:01 +00:00
|
|
|
// Usual shadowing is not an error
|
2019-11-28 15:53:13 +00:00
|
|
|
if (
|
|
|
|
dynamic_cast<ModifierDefinition const*>(declaration) &&
|
|
|
|
dynamic_cast<ModifierDefinition const*>(conflictingDeclaration)
|
|
|
|
)
|
2016-12-02 15:06:01 +00:00
|
|
|
continue;
|
|
|
|
|
2019-11-28 15:53:13 +00:00
|
|
|
// Public state variable can override functions
|
|
|
|
if (auto varDecl = dynamic_cast<VariableDeclaration const*>(conflictingDeclaration))
|
|
|
|
if (
|
|
|
|
dynamic_cast<FunctionDefinition const*>(declaration) &&
|
|
|
|
varDecl->isStateVariable() &&
|
|
|
|
varDecl->isPublic()
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
|
2016-11-01 16:18:00 +00:00
|
|
|
if (declaration->location().start < conflictingDeclaration->location().start)
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = declaration->location();
|
|
|
|
secondDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
secondDeclarationLocation = declaration->location();
|
|
|
|
}
|
|
|
|
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
2020-05-05 22:38:28 +00:00
|
|
|
9097_error,
|
2016-11-01 16:18:00 +00:00
|
|
|
secondDeclarationLocation,
|
2017-05-11 13:26:35 +00:00
|
|
|
SecondarySourceLocation().append("The previous declaration is here:", firstDeclarationLocation),
|
|
|
|
"Identifier already declared."
|
2016-11-01 16:18:00 +00:00
|
|
|
);
|
|
|
|
}
|
2015-01-15 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 18:37:41 +00:00
|
|
|
void NameAndTypeResolver::linearizeBaseContracts(ContractDefinition& _contract)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
// order in the lists is from derived to base
|
|
|
|
// list of lists to linearize, the last element is the list of direct bases
|
2016-05-17 05:27:39 +00:00
|
|
|
list<list<ContractDefinition const*>> input(1, list<ContractDefinition const*>{});
|
2015-08-31 16:44:29 +00:00
|
|
|
for (ASTPointer<InheritanceSpecifier> const& baseSpecifier: _contract.baseContracts())
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
2020-08-11 09:18:22 +00:00
|
|
|
IdentifierPath const& baseName = baseSpecifier->name();
|
2015-09-16 14:56:30 +00:00
|
|
|
auto base = dynamic_cast<ContractDefinition const*>(baseName.annotation().referencedDeclaration);
|
2015-01-15 19:04:06 +00:00
|
|
|
if (!base)
|
2020-05-05 22:38:28 +00:00
|
|
|
m_errorReporter.fatalTypeError(8758_error, baseName.location(), "Contract expected.");
|
2015-01-26 09:20:46 +00:00
|
|
|
// "push_front" has the effect that bases mentioned later can overwrite members of bases
|
|
|
|
// mentioned earlier
|
|
|
|
input.back().push_front(base);
|
2015-09-16 14:56:30 +00:00
|
|
|
vector<ContractDefinition const*> const& basesBases = base->annotation().linearizedBaseContracts;
|
2015-01-15 19:04:06 +00:00
|
|
|
if (basesBases.empty())
|
2020-05-05 22:38:28 +00:00
|
|
|
m_errorReporter.fatalTypeError(2449_error, baseName.location(), "Definition of base has to precede definition of derived contract");
|
2015-01-15 19:04:06 +00:00
|
|
|
input.push_front(list<ContractDefinition const*>(basesBases.begin(), basesBases.end()));
|
|
|
|
}
|
2015-01-26 09:20:46 +00:00
|
|
|
input.back().push_front(&_contract);
|
2015-01-15 19:04:06 +00:00
|
|
|
vector<ContractDefinition const*> result = cThreeMerge(input);
|
|
|
|
if (result.empty())
|
2020-05-05 22:38:28 +00:00
|
|
|
m_errorReporter.fatalTypeError(5005_error, _contract.location(), "Linearization of inheritance graph impossible");
|
2015-09-16 14:56:30 +00:00
|
|
|
_contract.annotation().linearizedBaseContracts = result;
|
2015-01-15 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 17:44:39 +00:00
|
|
|
template <class T>
|
|
|
|
vector<T const*> NameAndTypeResolver::cThreeMerge(list<list<T const*>>& _toMerge)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
// returns true iff _candidate appears only as last element of the lists
|
2020-02-17 17:44:39 +00:00
|
|
|
auto appearsOnlyAtHead = [&](T const* _candidate) -> bool
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
2020-02-17 17:44:39 +00:00
|
|
|
for (list<T const*> const& bases: _toMerge)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
solAssert(!bases.empty(), "");
|
|
|
|
if (find(++bases.begin(), bases.end(), _candidate) != bases.end())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
// returns the next candidate to append to the linearized list or nullptr on failure
|
2020-02-17 17:44:39 +00:00
|
|
|
auto nextCandidate = [&]() -> T const*
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
2020-02-17 17:44:39 +00:00
|
|
|
for (list<T const*> const& bases: _toMerge)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
solAssert(!bases.empty(), "");
|
|
|
|
if (appearsOnlyAtHead(bases.front()))
|
|
|
|
return bases.front();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
// removes the given contract from all lists
|
2020-02-17 17:44:39 +00:00
|
|
|
auto removeCandidate = [&](T const* _candidate)
|
2015-01-15 19:04:06 +00:00
|
|
|
{
|
|
|
|
for (auto it = _toMerge.begin(); it != _toMerge.end();)
|
|
|
|
{
|
|
|
|
it->remove(_candidate);
|
|
|
|
if (it->empty())
|
|
|
|
it = _toMerge.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-17 17:44:39 +00:00
|
|
|
_toMerge.remove_if([](list<T const*> const& _bases) { return _bases.empty(); });
|
|
|
|
vector<T const*> result;
|
2015-01-15 19:04:06 +00:00
|
|
|
while (!_toMerge.empty())
|
|
|
|
{
|
2020-02-17 17:44:39 +00:00
|
|
|
T const* candidate = nextCandidate();
|
2015-01-15 19:04:06 +00:00
|
|
|
if (!candidate)
|
2020-02-17 17:44:39 +00:00
|
|
|
return vector<T const*>();
|
2015-01-15 19:04:06 +00:00
|
|
|
result.push_back(candidate);
|
|
|
|
removeCandidate(candidate);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-29 08:08:40 +00:00
|
|
|
string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const
|
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
return util::quotedAlternativesList(m_currentScope->similarNames(_name));
|
2017-10-29 08:08:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 18:37:41 +00:00
|
|
|
DeclarationRegistrationHelper::DeclarationRegistrationHelper(
|
2015-12-15 14:46:03 +00:00
|
|
|
map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes,
|
2015-10-14 18:37:41 +00:00
|
|
|
ASTNode& _astRoot,
|
2017-05-11 13:26:35 +00:00
|
|
|
ErrorReporter& _errorReporter,
|
2019-04-29 16:29:40 +00:00
|
|
|
GlobalContext& _globalContext,
|
2017-01-31 22:12:40 +00:00
|
|
|
ASTNode const* _currentScope
|
2015-10-14 18:37:41 +00:00
|
|
|
):
|
|
|
|
m_scopes(_scopes),
|
2017-01-31 22:12:40 +00:00
|
|
|
m_currentScope(_currentScope),
|
2019-04-29 16:29:40 +00:00
|
|
|
m_errorReporter(_errorReporter),
|
|
|
|
m_globalContext(_globalContext)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
|
|
|
_astRoot.accept(*this);
|
2017-01-31 22:12:40 +00:00
|
|
|
solAssert(m_currentScope == _currentScope, "Scopes not correctly closed.");
|
2017-01-27 22:29:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 11:39:12 +00:00
|
|
|
bool DeclarationRegistrationHelper::registerDeclaration(
|
|
|
|
DeclarationContainer& _container,
|
|
|
|
Declaration const& _declaration,
|
|
|
|
string const* _name,
|
|
|
|
SourceLocation const* _errorLocation,
|
2018-02-15 10:30:32 +00:00
|
|
|
bool _inactive,
|
2017-02-02 11:39:12 +00:00
|
|
|
ErrorReporter& _errorReporter
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!_errorLocation)
|
|
|
|
_errorLocation = &_declaration.location();
|
|
|
|
|
2018-02-16 10:03:56 +00:00
|
|
|
string name = _name ? *_name : _declaration.name();
|
2017-02-02 11:39:12 +00:00
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
// We use "invisible" for both inactive variables in blocks and for members invisible in contracts.
|
|
|
|
// They cannot both be true at the same time.
|
|
|
|
solAssert(!(_inactive && !_declaration.isVisibleInContract()), "");
|
2020-11-11 11:10:25 +00:00
|
|
|
|
|
|
|
static set<string> illegalNames{"_", "super", "this"};
|
|
|
|
|
|
|
|
if (illegalNames.count(name))
|
|
|
|
{
|
|
|
|
auto isPublicFunctionOrEvent = [](Declaration const* _d) -> bool
|
|
|
|
{
|
|
|
|
if (auto functionDefinition = dynamic_cast<FunctionDefinition const*>(_d))
|
|
|
|
{
|
|
|
|
if (!functionDefinition->isFree() && functionDefinition->isPublic())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<EventDefinition const*>(_d))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// We allow an exception for public functions or events.
|
|
|
|
if (!isPublicFunctionOrEvent(&_declaration))
|
|
|
|
_errorReporter.declarationError(
|
|
|
|
3726_error,
|
|
|
|
*_errorLocation,
|
|
|
|
"The name \"" + name + "\" is reserved."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-07 22:41:04 +00:00
|
|
|
if (!_container.registerDeclaration(_declaration, _name, _errorLocation, !_declaration.isVisibleInContract() || _inactive, false))
|
2017-02-02 11:39:12 +00:00
|
|
|
{
|
|
|
|
SourceLocation firstDeclarationLocation;
|
|
|
|
SourceLocation secondDeclarationLocation;
|
|
|
|
Declaration const* conflictingDeclaration = _container.conflictingDeclaration(_declaration, _name);
|
|
|
|
solAssert(conflictingDeclaration, "");
|
|
|
|
bool const comparable =
|
2021-06-29 12:38:59 +00:00
|
|
|
_errorLocation->sourceName &&
|
|
|
|
conflictingDeclaration->location().sourceName &&
|
|
|
|
*_errorLocation->sourceName == *conflictingDeclaration->location().sourceName;
|
2017-02-02 11:39:12 +00:00
|
|
|
if (comparable && _errorLocation->start < conflictingDeclaration->location().start)
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = *_errorLocation;
|
|
|
|
secondDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
secondDeclarationLocation = *_errorLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
_errorReporter.declarationError(
|
2020-05-05 22:38:28 +00:00
|
|
|
2333_error,
|
2017-02-02 11:39:12 +00:00
|
|
|
secondDeclarationLocation,
|
|
|
|
SecondarySourceLocation().append("The previous declaration is here:", firstDeclarationLocation),
|
|
|
|
"Identifier already declared."
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-30 18:37:43 +00:00
|
|
|
|
2017-02-02 11:39:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-27 22:29:03 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit)
|
|
|
|
{
|
|
|
|
if (!m_scopes[&_sourceUnit])
|
|
|
|
// By importing, it is possible that the container already exists.
|
2019-11-27 16:24:21 +00:00
|
|
|
m_scopes[&_sourceUnit] = make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get());
|
2020-08-18 09:02:35 +00:00
|
|
|
return ASTVisitor::visit(_sourceUnit);
|
2017-01-27 22:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(SourceUnit& _sourceUnit)
|
|
|
|
{
|
2020-08-18 09:02:35 +00:00
|
|
|
ASTVisitor::endVisit(_sourceUnit);
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(ImportDirective& _import)
|
|
|
|
{
|
|
|
|
SourceUnit const* importee = _import.annotation().sourceUnit;
|
|
|
|
solAssert(!!importee, "");
|
|
|
|
if (!m_scopes[importee])
|
2019-11-27 16:24:21 +00:00
|
|
|
m_scopes[importee] = make_shared<DeclarationContainer>(nullptr, m_scopes[nullptr].get());
|
2015-12-15 14:46:03 +00:00
|
|
|
m_scopes[&_import] = m_scopes[importee];
|
2022-01-10 18:30:26 +00:00
|
|
|
ASTVisitor::visit(_import);
|
|
|
|
return false; // Do not recurse into child nodes (Identifier for symbolAliases)
|
2015-12-15 14:46:03 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:54:41 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract)
|
|
|
|
{
|
2019-04-29 16:29:40 +00:00
|
|
|
m_globalContext.setCurrentContract(_contract);
|
2020-10-07 22:41:04 +00:00
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentThis(), false, true);
|
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentSuper(), false, true);
|
2019-09-16 10:37:56 +00:00
|
|
|
m_currentContract = &_contract;
|
2019-04-29 16:29:40 +00:00
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
return ASTVisitor::visit(_contract);
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisit(ContractDefinition& _contract)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
2020-05-04 16:38:00 +00:00
|
|
|
// make "this" and "super" invisible.
|
2020-10-07 22:41:04 +00:00
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentThis(), true, true);
|
|
|
|
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentSuper(), true, true);
|
2020-05-04 16:38:00 +00:00
|
|
|
m_globalContext.resetCurrentContract();
|
2019-09-16 10:37:56 +00:00
|
|
|
m_currentContract = nullptr;
|
2020-08-18 09:02:35 +00:00
|
|
|
ASTVisitor::endVisit(_contract);
|
2018-02-09 15:53:52 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:21:38 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisit(VariableDeclarationStatement& _variableDeclarationStatement)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
2014-10-30 00:20:32 +00:00
|
|
|
// Register the local variables with the function
|
|
|
|
// This does not fit here perfectly, but it saves us another AST visit.
|
2015-02-17 15:21:38 +00:00
|
|
|
solAssert(m_currentFunction, "Variable declaration without function.");
|
2015-10-08 16:01:12 +00:00
|
|
|
for (ASTPointer<VariableDeclaration> const& var: _variableDeclarationStatement.declarations())
|
|
|
|
if (var)
|
|
|
|
m_currentFunction->addLocalVariable(*var);
|
2020-08-18 09:02:35 +00:00
|
|
|
ASTVisitor::endVisit(_variableDeclarationStatement);
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
bool DeclarationRegistrationHelper::visitNode(ASTNode& _node)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2020-08-18 09:02:35 +00:00
|
|
|
if (auto const* scopable = dynamic_cast<Scopable const*>(&_node))
|
|
|
|
solAssert(scopable->annotation().scope == m_currentScope, "");
|
|
|
|
|
|
|
|
if (auto* declaration = dynamic_cast<Declaration*>(&_node))
|
|
|
|
registerDeclaration(*declaration);
|
2021-09-14 15:31:00 +00:00
|
|
|
|
|
|
|
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
|
|
|
|
{
|
|
|
|
string canonicalName = dynamic_cast<Declaration const&>(_node).name();
|
|
|
|
solAssert(!canonicalName.empty(), "");
|
|
|
|
|
|
|
|
for (
|
|
|
|
ASTNode const* scope = m_currentScope;
|
|
|
|
scope != nullptr;
|
|
|
|
scope = m_scopes[scope]->enclosingNode()
|
|
|
|
)
|
|
|
|
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
|
|
|
{
|
|
|
|
solAssert(!decl->name().empty(), "");
|
|
|
|
canonicalName = decl->name() + "." + canonicalName;
|
|
|
|
}
|
|
|
|
|
|
|
|
annotation->canonicalName = canonicalName;
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
if (dynamic_cast<ScopeOpener const*>(&_node))
|
|
|
|
enterNewSubScope(_node);
|
|
|
|
|
|
|
|
if (auto* variableScope = dynamic_cast<VariableScope*>(&_node))
|
|
|
|
m_currentFunction = variableScope;
|
2014-10-15 13:54:41 +00:00
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisitNode(ASTNode& _node)
|
2015-01-31 15:50:33 +00:00
|
|
|
{
|
2020-08-18 09:02:35 +00:00
|
|
|
if (dynamic_cast<ScopeOpener const*>(&_node))
|
|
|
|
closeCurrentScope();
|
|
|
|
if (dynamic_cast<VariableScope*>(&_node))
|
|
|
|
m_currentFunction = nullptr;
|
2015-01-31 15:50:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
2020-10-07 22:41:04 +00:00
|
|
|
if (m_scopes.count(&_subScope))
|
|
|
|
// Source units are the only AST nodes for which containers can be created from multiple places due to imports.
|
|
|
|
solAssert(dynamic_cast<SourceUnit const*>(&_subScope), "Unexpected scope type.");
|
|
|
|
else
|
|
|
|
{
|
2021-02-08 04:50:58 +00:00
|
|
|
bool newlyAdded = m_scopes.emplace(
|
|
|
|
&_subScope,
|
|
|
|
make_shared<DeclarationContainer>(m_currentScope, m_scopes[m_currentScope].get())
|
|
|
|
).second;
|
2020-10-07 22:41:04 +00:00
|
|
|
solAssert(newlyAdded, "Unable to add new scope.");
|
|
|
|
}
|
2018-02-09 15:53:25 +00:00
|
|
|
m_currentScope = &_subScope;
|
2014-10-13 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:54:41 +00:00
|
|
|
void DeclarationRegistrationHelper::closeCurrentScope()
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2017-01-27 22:29:03 +00:00
|
|
|
solAssert(m_currentScope && m_scopes.count(m_currentScope), "Closed non-existing scope.");
|
2015-12-05 02:09:47 +00:00
|
|
|
m_currentScope = m_scopes[m_currentScope]->enclosingNode();
|
2014-10-13 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 09:02:35 +00:00
|
|
|
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
2017-01-27 22:29:03 +00:00
|
|
|
solAssert(m_currentScope && m_scopes.count(m_currentScope), "No current scope.");
|
2020-09-26 22:00:56 +00:00
|
|
|
solAssert(m_currentScope == _declaration.scope(), "Unexpected current scope.");
|
2015-05-04 13:46:46 +00:00
|
|
|
|
2018-06-15 10:30:28 +00:00
|
|
|
// Register declaration as inactive if we are in block scope.
|
2018-02-15 10:30:32 +00:00
|
|
|
bool inactive =
|
|
|
|
(dynamic_cast<Block const*>(m_currentScope) || dynamic_cast<ForStatement const*>(m_currentScope));
|
|
|
|
|
2020-09-26 22:00:56 +00:00
|
|
|
registerDeclaration(*m_scopes[m_currentScope], _declaration, nullptr, nullptr, inactive, m_errorReporter);
|
2015-04-30 16:06:04 +00:00
|
|
|
|
2020-08-06 12:46:04 +00:00
|
|
|
solAssert(_declaration.annotation().scope == m_currentScope, "");
|
|
|
|
solAssert(_declaration.annotation().contract == m_currentContract, "");
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|