2014-10-13 15:13:48 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-10-16 12:08:54 +00:00
|
|
|
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
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-10-16 12:08:54 +00:00
|
|
|
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
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
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/ast/AST.h>
|
|
|
|
#include <libsolidity/analysis/TypeChecker.h>
|
2017-05-11 13:26:35 +00:00
|
|
|
#include <libsolidity/interface/ErrorReporter.h>
|
2017-11-21 16:50:35 +00:00
|
|
|
#include <libdevcore/StringUtils.h>
|
2014-10-13 13:07:21 +00:00
|
|
|
|
2017-06-09 13:35:27 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2014-10-13 13:07:21 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
NameAndTypeResolver::NameAndTypeResolver(
|
2015-10-02 12:41:40 +00:00
|
|
|
vector<Declaration const*> const& _globals,
|
2017-01-31 21:59:56 +00:00
|
|
|
map<ASTNode const*, shared_ptr<DeclarationContainer>>& _scopes,
|
2017-05-11 13:26:35 +00:00
|
|
|
ErrorReporter& _errorReporter
|
2015-10-02 12:41:40 +00:00
|
|
|
) :
|
2017-01-31 21:59:56 +00:00
|
|
|
m_scopes(_scopes),
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter(_errorReporter)
|
2014-11-20 17:33:23 +00:00
|
|
|
{
|
2015-12-05 02:09:47 +00:00
|
|
|
if (!m_scopes[nullptr])
|
|
|
|
m_scopes[nullptr].reset(new DeclarationContainer());
|
2014-12-06 01:32:51 +00:00
|
|
|
for (Declaration const* declaration: _globals)
|
2017-12-30 12:47:15 +00:00
|
|
|
{
|
|
|
|
solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration.");
|
|
|
|
}
|
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
|
|
|
{
|
2018-02-15 10:30:32 +00:00
|
|
|
bool useC99Scoping = _sourceUnit.annotation().experimentalFeatures.count(ExperimentalFeature::V050);
|
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
|
|
|
|
{
|
2018-02-15 10:30:32 +00:00
|
|
|
DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, useC99Scoping, m_errorReporter, _currentScope);
|
2015-10-14 18:37:41 +00:00
|
|
|
}
|
2015-11-26 13:47:28 +00:00
|
|
|
catch (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()))
|
|
|
|
{
|
2015-12-09 16:35:20 +00:00
|
|
|
string const& path = imp->annotation().absolutePath;
|
|
|
|
if (!_sourceUnits.count(path))
|
2015-12-05 02:09:47 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
2016-01-11 12:55:58 +00:00
|
|
|
imp->location(),
|
|
|
|
"Import \"" + path + "\" (referenced as \"" + imp->path() + "\") not found."
|
2015-12-09 16:35:20 +00:00
|
|
|
);
|
2015-12-05 02:09:47 +00:00
|
|
|
error = true;
|
2016-01-11 12:55:58 +00:00
|
|
|
continue;
|
2015-12-05 02:09:47 +00:00
|
|
|
}
|
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())
|
|
|
|
{
|
|
|
|
auto declarations = scope->second->resolveName(alias.first->name(), false);
|
|
|
|
if (declarations.empty())
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
2016-01-11 12:55:58 +00:00
|
|
|
imp->location(),
|
|
|
|
"Declaration \"" +
|
|
|
|
alias.first->name() +
|
|
|
|
"\" 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(
|
2018-02-15 10:30:32 +00:00
|
|
|
target, *declaration, alias.second.get(), &imp->location(), true, 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(
|
2018-02-15 10:30:32 +00:00
|
|
|
target, *declaration, &nameAndDeclaration.first, &imp->location(), true, false, m_errorReporter
|
2017-02-02 11:39:12 +00:00
|
|
|
))
|
|
|
|
error = true;
|
2015-12-05 02:09:47 +00:00
|
|
|
}
|
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
2017-01-27 17:27:59 +00:00
|
|
|
bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsideCode)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2015-10-14 18:37:41 +00:00
|
|
|
try
|
|
|
|
{
|
2017-02-16 11:36:43 +00:00
|
|
|
return resolveNamesAndTypesInternal(_node, _resolveInsideCode);
|
2015-04-15 15:40:50 +00:00
|
|
|
}
|
2015-11-26 13:47:28 +00:00
|
|
|
catch (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
|
|
|
}
|
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
|
|
|
|
{
|
2015-12-05 02:09:47 +00:00
|
|
|
m_scopes[nullptr]->registerDeclaration(_declaration, nullptr, false, true);
|
2015-10-14 18:37:41 +00:00
|
|
|
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
|
|
|
|
}
|
2015-11-26 13:47:28 +00:00
|
|
|
catch (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, "");
|
|
|
|
m_currentScope->activateVariable(_name);
|
|
|
|
}
|
|
|
|
|
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*>({});
|
2015-12-05 01:26:54 +00:00
|
|
|
return iterator->second->resolveName(_name, false);
|
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
|
|
|
{
|
2018-02-15 10:30:32 +00:00
|
|
|
return m_currentScope->resolveName(_name, true, _includeInvisibles);
|
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
|
2015-10-06 10:35:10 +00:00
|
|
|
{
|
|
|
|
solAssert(!_path.empty(), "");
|
2018-02-09 14:09:22 +00:00
|
|
|
vector<Declaration const*> candidates = m_currentScope->resolveName(_path.front(), true);
|
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()))
|
|
|
|
return nullptr;
|
2015-12-05 01:26:54 +00:00
|
|
|
candidates = m_scopes.at(candidates.front())->resolveName(_path[i], false);
|
2015-10-06 10:35:10 +00:00
|
|
|
}
|
|
|
|
if (candidates.size() == 1)
|
|
|
|
return candidates.front();
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-08 14:07:25 +00:00
|
|
|
vector<Declaration const*> NameAndTypeResolver::cleanedDeclarations(
|
2015-05-07 16:12:58 +00:00
|
|
|
Identifier const& _identifier,
|
|
|
|
vector<Declaration const*> const& _declarations
|
|
|
|
)
|
2015-05-07 08:12:27 +00:00
|
|
|
{
|
2015-05-08 14:07:25 +00:00
|
|
|
solAssert(_declarations.size() > 1, "");
|
2015-05-07 14:52:06 +00:00
|
|
|
vector<Declaration const*> uniqueFunctions;
|
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
for (Declaration const* declaration: _declarations)
|
2015-05-07 08:12:27 +00:00
|
|
|
{
|
2017-02-16 11:36:43 +00:00
|
|
|
solAssert(declaration, "");
|
2016-10-20 08:47:15 +00:00
|
|
|
// the declaration is functionDefinition, eventDefinition or a VariableDeclaration while declarations > 1
|
2017-02-16 11:36:43 +00:00
|
|
|
solAssert(
|
|
|
|
dynamic_cast<FunctionDefinition const*>(declaration) ||
|
|
|
|
dynamic_cast<EventDefinition const*>(declaration) ||
|
2017-12-30 12:46:53 +00:00
|
|
|
dynamic_cast<VariableDeclaration const*>(declaration) ||
|
|
|
|
dynamic_cast<MagicVariableDeclaration const*>(declaration),
|
|
|
|
"Found overloading involving something not a function, event or a (magic) variable."
|
2017-02-16 11:36:43 +00:00
|
|
|
);
|
2016-12-02 15:24:53 +00:00
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
FunctionTypePointer functionType { declaration->functionType(false) };
|
2017-01-10 15:26:13 +00:00
|
|
|
if (!functionType)
|
2017-02-16 11:36:43 +00:00
|
|
|
functionType = declaration->functionType(true);
|
|
|
|
solAssert(functionType, "Failed to determine the function type of the overloaded.");
|
2015-10-14 18:37:41 +00:00
|
|
|
|
2017-01-10 15:26:13 +00:00
|
|
|
for (auto parameter: functionType->parameterTypes() + functionType->returnParameterTypes())
|
|
|
|
if (!parameter)
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.fatalDeclarationError(_identifier.location(), "Function type can not be used in this context.");
|
2017-01-10 15:26:13 +00:00
|
|
|
|
2015-05-07 14:52:06 +00:00
|
|
|
if (uniqueFunctions.end() == find_if(
|
|
|
|
uniqueFunctions.begin(),
|
|
|
|
uniqueFunctions.end(),
|
|
|
|
[&](Declaration const* d)
|
|
|
|
{
|
2017-01-10 15:34:55 +00:00
|
|
|
shared_ptr<FunctionType const> newFunctionType { d->functionType(false) };
|
|
|
|
if (!newFunctionType)
|
|
|
|
newFunctionType = d->functionType(true);
|
|
|
|
return newFunctionType && functionType->hasEqualArgumentTypes(*newFunctionType);
|
2015-05-07 14:52:06 +00:00
|
|
|
}
|
|
|
|
))
|
2017-02-16 11:36:43 +00:00
|
|
|
uniqueFunctions.push_back(declaration);
|
2015-05-07 08:12:27 +00:00
|
|
|
}
|
2015-05-07 14:52:06 +00:00
|
|
|
return uniqueFunctions;
|
2015-05-07 08:12:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 13:35:27 +00:00
|
|
|
void NameAndTypeResolver::warnVariablesNamedLikeInstructions()
|
|
|
|
{
|
|
|
|
for (auto const& instruction: c_instructions)
|
|
|
|
{
|
|
|
|
string const instructionName{boost::algorithm::to_lower_copy(instruction.first)};
|
2018-02-15 10:30:32 +00:00
|
|
|
auto declarations = nameFromCurrentScope(instructionName, true);
|
2017-06-09 13:35:27 +00:00
|
|
|
for (Declaration const* const declaration: declarations)
|
|
|
|
{
|
|
|
|
solAssert(!!declaration, "");
|
|
|
|
if (dynamic_cast<MagicVariableDeclaration const* const>(declaration))
|
|
|
|
// Don't warn the user for what the user did not.
|
|
|
|
continue;
|
|
|
|
m_errorReporter.warning(
|
|
|
|
declaration->location(),
|
|
|
|
"Variable is shadowed in inline assembly by an instruction of the same name"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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, "");
|
|
|
|
|
|
|
|
for (ASTPointer<InheritanceSpecifier> const& baseContract: contract->baseContracts())
|
|
|
|
if (!resolveNamesAndTypes(*baseContract, true))
|
|
|
|
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);
|
2017-02-16 11:36:43 +00:00
|
|
|
if (!resolveNamesAndTypes(*node, false))
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!_resolveInsideCode)
|
|
|
|
return success;
|
|
|
|
|
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);
|
2017-02-16 11:36:43 +00:00
|
|
|
if (!resolveNamesAndTypes(*node, true))
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_scopes.count(&_node))
|
2018-02-09 15:53:25 +00:00
|
|
|
setScope(&_node);
|
2017-05-11 13:26:35 +00:00
|
|
|
return ReferencesResolver(m_errorReporter, *this, _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())
|
2016-11-01 16:18:00 +00:00
|
|
|
if (!m_currentScope->registerDeclaration(*declaration))
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if (dynamic_cast<VariableDeclaration const*>(declaration) && dynamic_cast<VariableDeclaration const*>(conflictingDeclaration))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Usual shadowing is not an error
|
|
|
|
if (dynamic_cast<ModifierDefinition const*>(declaration) && dynamic_cast<ModifierDefinition const*>(conflictingDeclaration))
|
|
|
|
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(
|
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
|
|
|
{
|
2015-12-21 17:44:21 +00:00
|
|
|
UserDefinedTypeName 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)
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.fatalTypeError(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())
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.fatalTypeError(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())
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.fatalTypeError(_contract.location(), "Linearization of inheritance graph impossible");
|
2015-09-16 14:56:30 +00:00
|
|
|
_contract.annotation().linearizedBaseContracts = result;
|
2015-10-07 13:57:17 +00:00
|
|
|
_contract.annotation().contractDependencies.insert(result.begin() + 1, result.end());
|
2015-01-15 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T>
|
|
|
|
vector<_T const*> NameAndTypeResolver::cThreeMerge(list<list<_T const*>>& _toMerge)
|
|
|
|
{
|
|
|
|
// returns true iff _candidate appears only as last element of the lists
|
|
|
|
auto appearsOnlyAtHead = [&](_T const* _candidate) -> bool
|
|
|
|
{
|
|
|
|
for (list<_T const*> const& bases: _toMerge)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
auto nextCandidate = [&]() -> _T const*
|
|
|
|
{
|
|
|
|
for (list<_T const*> const& bases: _toMerge)
|
|
|
|
{
|
|
|
|
solAssert(!bases.empty(), "");
|
|
|
|
if (appearsOnlyAtHead(bases.front()))
|
|
|
|
return bases.front();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
// removes the given contract from all lists
|
|
|
|
auto removeCandidate = [&](_T const* _candidate)
|
|
|
|
{
|
|
|
|
for (auto it = _toMerge.begin(); it != _toMerge.end();)
|
|
|
|
{
|
|
|
|
it->remove(_candidate);
|
|
|
|
if (it->empty())
|
|
|
|
it = _toMerge.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_toMerge.remove_if([](list<_T const*> const& _bases) { return _bases.empty(); });
|
|
|
|
vector<_T const*> result;
|
|
|
|
while (!_toMerge.empty())
|
|
|
|
{
|
|
|
|
_T const* candidate = nextCandidate();
|
|
|
|
if (!candidate)
|
|
|
|
return vector<_T const*>();
|
|
|
|
result.push_back(candidate);
|
|
|
|
removeCandidate(candidate);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-29 08:08:40 +00:00
|
|
|
string NameAndTypeResolver::similarNameSuggestions(ASTString const& _name) const
|
|
|
|
{
|
2017-11-21 16:50:35 +00:00
|
|
|
return 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,
|
2018-02-15 10:30:32 +00:00
|
|
|
bool _useC99Scoping,
|
2017-05-11 13:26:35 +00:00
|
|
|
ErrorReporter& _errorReporter,
|
2017-01-31 22:12:40 +00:00
|
|
|
ASTNode const* _currentScope
|
2015-10-14 18:37:41 +00:00
|
|
|
):
|
2018-02-15 10:30:32 +00:00
|
|
|
m_useC99Scoping(_useC99Scoping),
|
2015-10-14 18:37:41 +00:00
|
|
|
m_scopes(_scopes),
|
2017-01-31 22:12:40 +00:00
|
|
|
m_currentScope(_currentScope),
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter(_errorReporter)
|
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,
|
|
|
|
bool _warnOnShadow,
|
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
|
|
|
Declaration const* shadowedDeclaration = nullptr;
|
2018-02-16 10:03:56 +00:00
|
|
|
if (_warnOnShadow && !name.empty() && _container.enclosingContainer())
|
2018-02-15 10:30:32 +00:00
|
|
|
for (auto const* decl: _container.enclosingContainer()->resolveName(name, true, true))
|
2017-08-04 12:27:53 +00:00
|
|
|
shadowedDeclaration = decl;
|
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()), "");
|
|
|
|
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract() || _inactive))
|
2017-02-02 11:39:12 +00:00
|
|
|
{
|
|
|
|
SourceLocation firstDeclarationLocation;
|
|
|
|
SourceLocation secondDeclarationLocation;
|
|
|
|
Declaration const* conflictingDeclaration = _container.conflictingDeclaration(_declaration, _name);
|
|
|
|
solAssert(conflictingDeclaration, "");
|
|
|
|
bool const comparable =
|
|
|
|
_errorLocation->sourceName &&
|
|
|
|
conflictingDeclaration->location().sourceName &&
|
|
|
|
*_errorLocation->sourceName == *conflictingDeclaration->location().sourceName;
|
|
|
|
if (comparable && _errorLocation->start < conflictingDeclaration->location().start)
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = *_errorLocation;
|
|
|
|
secondDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstDeclarationLocation = conflictingDeclaration->location();
|
|
|
|
secondDeclarationLocation = *_errorLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
_errorReporter.declarationError(
|
|
|
|
secondDeclarationLocation,
|
|
|
|
SecondarySourceLocation().append("The previous declaration is here:", firstDeclarationLocation),
|
|
|
|
"Identifier already declared."
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (shadowedDeclaration)
|
|
|
|
{
|
|
|
|
if (dynamic_cast<MagicVariableDeclaration const*>(shadowedDeclaration))
|
|
|
|
_errorReporter.warning(
|
|
|
|
_declaration.location(),
|
|
|
|
"This declaration shadows a builtin symbol."
|
|
|
|
);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto shadowedLocation = shadowedDeclaration->location();
|
|
|
|
_errorReporter.warning(
|
|
|
|
_declaration.location(),
|
|
|
|
"This declaration shadows an existing declaration.",
|
|
|
|
SecondarySourceLocation().append("The shadowed declaration is here:", shadowedLocation)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
2017-01-31 22:12:40 +00:00
|
|
|
m_scopes[&_sourceUnit].reset(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get()));
|
2017-01-27 22:29:03 +00:00
|
|
|
m_currentScope = &_sourceUnit;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(SourceUnit& _sourceUnit)
|
|
|
|
{
|
|
|
|
_sourceUnit.annotation().exportedSymbols = m_scopes[&_sourceUnit]->declarations();
|
|
|
|
closeCurrentScope();
|
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])
|
|
|
|
m_scopes[importee].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get()));
|
|
|
|
m_scopes[&_import] = m_scopes[importee];
|
|
|
|
registerDeclaration(_import, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-15 13:54:41 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract)
|
|
|
|
{
|
|
|
|
registerDeclaration(_contract, true);
|
2015-10-05 15:19:23 +00:00
|
|
|
_contract.annotation().canonicalName = currentCanonicalName();
|
2014-10-15 13:54:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(ContractDefinition&)
|
|
|
|
{
|
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeclarationRegistrationHelper::visit(StructDefinition& _struct)
|
|
|
|
{
|
|
|
|
registerDeclaration(_struct, true);
|
2015-10-05 15:19:23 +00:00
|
|
|
_struct.annotation().canonicalName = currentCanonicalName();
|
2014-10-15 13:54:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(StructDefinition&)
|
|
|
|
{
|
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
2015-02-11 20:40:47 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(EnumDefinition& _enum)
|
|
|
|
{
|
|
|
|
registerDeclaration(_enum, true);
|
2015-10-05 15:19:23 +00:00
|
|
|
_enum.annotation().canonicalName = currentCanonicalName();
|
2015-02-11 20:40:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(EnumDefinition&)
|
|
|
|
{
|
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
2015-02-14 02:06:50 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(EnumValue& _value)
|
|
|
|
{
|
|
|
|
registerDeclaration(_value, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-15 13:54:41 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(FunctionDefinition& _function)
|
|
|
|
{
|
|
|
|
registerDeclaration(_function, true);
|
2014-10-30 00:20:32 +00:00
|
|
|
m_currentFunction = &_function;
|
2014-10-15 13:54:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(FunctionDefinition&)
|
|
|
|
{
|
2014-10-30 00:20:32 +00:00
|
|
|
m_currentFunction = nullptr;
|
2014-10-15 13:54:41 +00:00
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(ModifierDefinition& _modifier)
|
|
|
|
{
|
|
|
|
registerDeclaration(_modifier, true);
|
|
|
|
m_currentFunction = &_modifier;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclarationRegistrationHelper::endVisit(ModifierDefinition&)
|
|
|
|
{
|
|
|
|
m_currentFunction = nullptr;
|
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:53:52 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(Block& _block)
|
|
|
|
{
|
2018-02-14 00:48:40 +00:00
|
|
|
_block.setScope(m_currentScope);
|
2018-02-15 10:30:32 +00:00
|
|
|
if (m_useC99Scoping)
|
2018-02-14 00:48:40 +00:00
|
|
|
enterNewSubScope(_block);
|
2018-02-09 15:53:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisit(Block&)
|
2018-02-09 15:53:52 +00:00
|
|
|
{
|
2018-02-15 10:30:32 +00:00
|
|
|
if (m_useC99Scoping)
|
2018-02-14 00:48:40 +00:00
|
|
|
closeCurrentScope();
|
2018-02-09 15:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DeclarationRegistrationHelper::visit(ForStatement& _for)
|
|
|
|
{
|
2018-02-14 00:48:40 +00:00
|
|
|
_for.setScope(m_currentScope);
|
2018-02-15 10:30:32 +00:00
|
|
|
if (m_useC99Scoping)
|
2018-02-14 00:48:40 +00:00
|
|
|
enterNewSubScope(_for);
|
2018-02-09 15:53:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisit(ForStatement&)
|
2018-02-09 15:53:52 +00:00
|
|
|
{
|
2018-02-15 10:30:32 +00:00
|
|
|
if (m_useC99Scoping)
|
2018-02-14 00:48:40 +00:00
|
|
|
closeCurrentScope();
|
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);
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 00:20:32 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(VariableDeclaration& _declaration)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2014-10-30 00:20:32 +00:00
|
|
|
registerDeclaration(_declaration, false);
|
|
|
|
return true;
|
2014-10-15 13:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
bool DeclarationRegistrationHelper::visit(EventDefinition& _event)
|
|
|
|
{
|
2015-01-31 15:50:33 +00:00
|
|
|
registerDeclaration(_event, true);
|
2015-01-29 13:35:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-31 15:50:33 +00:00
|
|
|
void DeclarationRegistrationHelper::endVisit(EventDefinition&)
|
|
|
|
{
|
|
|
|
closeCurrentScope();
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope)
|
2014-10-15 13:54:41 +00:00
|
|
|
{
|
2015-12-15 14:46:03 +00:00
|
|
|
map<ASTNode const*, shared_ptr<DeclarationContainer>>::iterator iter;
|
2014-10-13 13:07:21 +00:00
|
|
|
bool newlyAdded;
|
2015-12-15 14:46:03 +00:00
|
|
|
shared_ptr<DeclarationContainer> container(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get()));
|
2018-02-09 15:53:25 +00:00
|
|
|
tie(iter, newlyAdded) = m_scopes.emplace(&_subScope, move(container));
|
2014-12-17 15:23:18 +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
|
|
|
}
|
|
|
|
|
2014-10-15 13:54:41 +00:00
|
|
|
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
|
|
|
|
{
|
2017-01-27 22:29:03 +00:00
|
|
|
solAssert(m_currentScope && m_scopes.count(m_currentScope), "No current scope.");
|
2015-05-04 12:46:52 +00:00
|
|
|
|
2017-02-02 11:39:12 +00:00
|
|
|
bool warnAboutShadowing = true;
|
|
|
|
// Do not warn about shadowing for structs and enums because their members are
|
2017-10-04 15:09:52 +00:00
|
|
|
// not accessible without prefixes. Also do not warn about event parameters
|
|
|
|
// because they don't participate in any proper scope.
|
2017-02-02 11:39:12 +00:00
|
|
|
if (
|
|
|
|
dynamic_cast<StructDefinition const*>(m_currentScope) ||
|
2017-10-04 15:09:52 +00:00
|
|
|
dynamic_cast<EnumDefinition const*>(m_currentScope) ||
|
|
|
|
dynamic_cast<EventDefinition const*>(m_currentScope)
|
2017-02-02 11:39:12 +00:00
|
|
|
)
|
|
|
|
warnAboutShadowing = false;
|
|
|
|
// Do not warn about the constructor shadowing the contract.
|
|
|
|
if (auto fun = dynamic_cast<FunctionDefinition const*>(&_declaration))
|
|
|
|
if (fun->isConstructor())
|
|
|
|
warnAboutShadowing = false;
|
2015-05-04 13:46:46 +00:00
|
|
|
|
2018-02-15 10:30:32 +00:00
|
|
|
// Register declaration as inactive if we are in block scope and C99 mode.
|
|
|
|
bool inactive =
|
|
|
|
m_useC99Scoping &&
|
|
|
|
(dynamic_cast<Block const*>(m_currentScope) || dynamic_cast<ForStatement const*>(m_currentScope));
|
|
|
|
|
|
|
|
registerDeclaration(*m_scopes[m_currentScope], _declaration, nullptr, nullptr, warnAboutShadowing, inactive, m_errorReporter);
|
2015-04-30 16:06:04 +00:00
|
|
|
|
2018-02-14 00:48:40 +00:00
|
|
|
_declaration.setScope(m_currentScope);
|
2014-10-15 13:54:41 +00:00
|
|
|
if (_opensScope)
|
|
|
|
enterNewSubScope(_declaration);
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
string DeclarationRegistrationHelper::currentCanonicalName() const
|
|
|
|
{
|
|
|
|
string ret;
|
|
|
|
for (
|
2015-12-05 02:09:47 +00:00
|
|
|
ASTNode const* scope = m_currentScope;
|
2015-10-05 15:19:23 +00:00
|
|
|
scope != nullptr;
|
2015-12-05 02:09:47 +00:00
|
|
|
scope = m_scopes[scope]->enclosingNode()
|
2015-10-05 15:19:23 +00:00
|
|
|
)
|
|
|
|
{
|
2015-12-05 02:09:47 +00:00
|
|
|
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
|
|
|
{
|
|
|
|
if (!ret.empty())
|
|
|
|
ret = "." + ret;
|
|
|
|
ret = decl->name() + ret;
|
|
|
|
}
|
2015-10-05 15:19:23 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|