mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Bugfix concerning pointers to moved data.
This commit is contained in:
parent
15a1468c3f
commit
e510e7e792
@ -38,8 +38,9 @@ NameAndTypeResolver::NameAndTypeResolver(
|
|||||||
) :
|
) :
|
||||||
m_errors(_errors)
|
m_errors(_errors)
|
||||||
{
|
{
|
||||||
|
m_scopes[nullptr].reset(new DeclarationContainer());
|
||||||
for (Declaration const* declaration: _globals)
|
for (Declaration const* declaration: _globals)
|
||||||
m_scopes[nullptr].registerDeclaration(*declaration);
|
m_scopes[nullptr]->registerDeclaration(*declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit)
|
bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit)
|
||||||
@ -62,7 +63,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_currentScope = &m_scopes[nullptr];
|
m_currentScope = m_scopes[nullptr].get();
|
||||||
|
|
||||||
ReferencesResolver resolver(m_errors, *this, nullptr);
|
ReferencesResolver resolver(m_errors, *this, nullptr);
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@ -70,7 +71,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
|
|||||||
if (!resolver.resolve(*baseContract))
|
if (!resolver.resolve(*baseContract))
|
||||||
success = false;
|
success = false;
|
||||||
|
|
||||||
m_currentScope = &m_scopes[&_contract];
|
m_currentScope = m_scopes[&_contract].get();
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@ -87,7 +88,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
|
|||||||
// these can contain code, only resolve parameters for now
|
// these can contain code, only resolve parameters for now
|
||||||
for (ASTPointer<ASTNode> const& node: _contract.subNodes())
|
for (ASTPointer<ASTNode> const& node: _contract.subNodes())
|
||||||
{
|
{
|
||||||
m_currentScope = &m_scopes[m_scopes.count(node.get()) ? node.get() : &_contract];
|
m_currentScope = m_scopes[m_scopes.count(node.get()) ? node.get() : &_contract].get();
|
||||||
if (!resolver.resolve(*node))
|
if (!resolver.resolve(*node))
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
@ -95,12 +96,12 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
|
|||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_currentScope = &m_scopes[&_contract];
|
m_currentScope = m_scopes[&_contract].get();
|
||||||
|
|
||||||
// now resolve references inside the code
|
// now resolve references inside the code
|
||||||
for (ModifierDefinition const* modifier: _contract.functionModifiers())
|
for (ModifierDefinition const* modifier: _contract.functionModifiers())
|
||||||
{
|
{
|
||||||
m_currentScope = &m_scopes[modifier];
|
m_currentScope = m_scopes[modifier].get();
|
||||||
ReferencesResolver resolver(m_errors, *this, nullptr, true);
|
ReferencesResolver resolver(m_errors, *this, nullptr, true);
|
||||||
if (!resolver.resolve(*modifier))
|
if (!resolver.resolve(*modifier))
|
||||||
success = false;
|
success = false;
|
||||||
@ -108,7 +109,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
|
|||||||
|
|
||||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
for (FunctionDefinition const* function: _contract.definedFunctions())
|
||||||
{
|
{
|
||||||
m_currentScope = &m_scopes[function];
|
m_currentScope = m_scopes[function].get();
|
||||||
if (!ReferencesResolver(
|
if (!ReferencesResolver(
|
||||||
m_errors,
|
m_errors,
|
||||||
*this,
|
*this,
|
||||||
@ -133,7 +134,7 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_scopes[nullptr].registerDeclaration(_declaration, false, true);
|
m_scopes[nullptr]->registerDeclaration(_declaration, false, true);
|
||||||
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
|
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
|
||||||
}
|
}
|
||||||
catch (FatalError const&)
|
catch (FatalError const&)
|
||||||
@ -150,7 +151,7 @@ vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _na
|
|||||||
auto iterator = m_scopes.find(_scope);
|
auto iterator = m_scopes.find(_scope);
|
||||||
if (iterator == end(m_scopes))
|
if (iterator == end(m_scopes))
|
||||||
return vector<Declaration const*>({});
|
return vector<Declaration const*>({});
|
||||||
return iterator->second.resolveName(_name, false);
|
return iterator->second->resolveName(_name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _recursive) const
|
vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString const& _name, bool _recursive) const
|
||||||
@ -166,7 +167,7 @@ Declaration const* NameAndTypeResolver::pathFromCurrentScope(vector<ASTString> c
|
|||||||
{
|
{
|
||||||
if (!m_scopes.count(candidates.front()))
|
if (!m_scopes.count(candidates.front()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
candidates = m_scopes.at(candidates.front()).resolveName(_path[i], false);
|
candidates = m_scopes.at(candidates.front())->resolveName(_path[i], false);
|
||||||
}
|
}
|
||||||
if (candidates.size() == 1)
|
if (candidates.size() == 1)
|
||||||
return candidates.front();
|
return candidates.front();
|
||||||
@ -210,7 +211,7 @@ void NameAndTypeResolver::importInheritedScope(ContractDefinition const& _base)
|
|||||||
{
|
{
|
||||||
auto iterator = m_scopes.find(&_base);
|
auto iterator = m_scopes.find(&_base);
|
||||||
solAssert(iterator != end(m_scopes), "");
|
solAssert(iterator != end(m_scopes), "");
|
||||||
for (auto const& nameAndDeclaration: iterator->second.declarations())
|
for (auto const& nameAndDeclaration: iterator->second->declarations())
|
||||||
for (auto const& declaration: nameAndDeclaration.second)
|
for (auto const& declaration: nameAndDeclaration.second)
|
||||||
// Import if it was declared in the base, is not the constructor and is visible in derived classes
|
// Import if it was declared in the base, is not the constructor and is visible in derived classes
|
||||||
if (declaration->scope() == &_base && declaration->isVisibleInDerivedContracts())
|
if (declaration->scope() == &_base && declaration->isVisibleInDerivedContracts())
|
||||||
@ -342,7 +343,7 @@ void NameAndTypeResolver::reportFatalTypeError(Error const& _e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeclarationRegistrationHelper::DeclarationRegistrationHelper(
|
DeclarationRegistrationHelper::DeclarationRegistrationHelper(
|
||||||
map<ASTNode const*, DeclarationContainer>& _scopes,
|
map<ASTNode const*, std::unique_ptr<DeclarationContainer>>& _scopes,
|
||||||
ASTNode& _astRoot,
|
ASTNode& _astRoot,
|
||||||
ErrorList& _errors
|
ErrorList& _errors
|
||||||
):
|
):
|
||||||
@ -450,9 +451,10 @@ void DeclarationRegistrationHelper::endVisit(EventDefinition&)
|
|||||||
|
|
||||||
void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declaration)
|
void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declaration)
|
||||||
{
|
{
|
||||||
map<ASTNode const*, DeclarationContainer>::iterator iter;
|
map<ASTNode const*, std::unique_ptr<DeclarationContainer>>::iterator iter;
|
||||||
bool newlyAdded;
|
bool newlyAdded;
|
||||||
tie(iter, newlyAdded) = m_scopes.emplace(&_declaration, DeclarationContainer(m_currentScope, &m_scopes[m_currentScope]));
|
std::unique_ptr<DeclarationContainer> container(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get()));
|
||||||
|
tie(iter, newlyAdded) = m_scopes.emplace(&_declaration, move(container));
|
||||||
solAssert(newlyAdded, "Unable to add new scope.");
|
solAssert(newlyAdded, "Unable to add new scope.");
|
||||||
m_currentScope = &_declaration;
|
m_currentScope = &_declaration;
|
||||||
}
|
}
|
||||||
@ -460,16 +462,16 @@ void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declara
|
|||||||
void DeclarationRegistrationHelper::closeCurrentScope()
|
void DeclarationRegistrationHelper::closeCurrentScope()
|
||||||
{
|
{
|
||||||
solAssert(m_currentScope, "Closed non-existing scope.");
|
solAssert(m_currentScope, "Closed non-existing scope.");
|
||||||
m_currentScope = m_scopes[m_currentScope].enclosingDeclaration();
|
m_currentScope = m_scopes[m_currentScope]->enclosingDeclaration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
|
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
|
||||||
{
|
{
|
||||||
if (!m_scopes[m_currentScope].registerDeclaration(_declaration, !_declaration.isVisibleInContract()))
|
if (!m_scopes[m_currentScope]->registerDeclaration(_declaration, !_declaration.isVisibleInContract()))
|
||||||
{
|
{
|
||||||
SourceLocation firstDeclarationLocation;
|
SourceLocation firstDeclarationLocation;
|
||||||
SourceLocation secondDeclarationLocation;
|
SourceLocation secondDeclarationLocation;
|
||||||
Declaration const* conflictingDeclaration = m_scopes[m_currentScope].conflictingDeclaration(_declaration);
|
Declaration const* conflictingDeclaration = m_scopes[m_currentScope]->conflictingDeclaration(_declaration);
|
||||||
solAssert(conflictingDeclaration, "");
|
solAssert(conflictingDeclaration, "");
|
||||||
|
|
||||||
if (_declaration.location().start < conflictingDeclaration->location().start)
|
if (_declaration.location().start < conflictingDeclaration->location().start)
|
||||||
@ -502,7 +504,7 @@ string DeclarationRegistrationHelper::currentCanonicalName() const
|
|||||||
for (
|
for (
|
||||||
Declaration const* scope = m_currentScope;
|
Declaration const* scope = m_currentScope;
|
||||||
scope != nullptr;
|
scope != nullptr;
|
||||||
scope = m_scopes[scope].enclosingDeclaration()
|
scope = m_scopes[scope]->enclosingDeclaration()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!ret.empty())
|
if (!ret.empty())
|
||||||
|
@ -91,7 +91,7 @@ private:
|
|||||||
/// Maps nodes declaring a scope to scopes, i.e. ContractDefinition and FunctionDeclaration,
|
/// Maps nodes declaring a scope to scopes, i.e. ContractDefinition and FunctionDeclaration,
|
||||||
/// 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.
|
||||||
std::map<ASTNode const*, DeclarationContainer> m_scopes;
|
std::map<ASTNode const*, std::unique_ptr<DeclarationContainer>> m_scopes;
|
||||||
|
|
||||||
// creates the Declaration error and adds it in the errors list
|
// creates the Declaration error and adds it in the errors list
|
||||||
void reportDeclarationError(
|
void reportDeclarationError(
|
||||||
@ -121,7 +121,11 @@ private:
|
|||||||
class DeclarationRegistrationHelper: private ASTVisitor
|
class DeclarationRegistrationHelper: private ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeclarationRegistrationHelper(std::map<ASTNode const*, DeclarationContainer>& _scopes, ASTNode& _astRoot, ErrorList& _errors);
|
DeclarationRegistrationHelper(
|
||||||
|
std::map<ASTNode const*, std::unique_ptr<DeclarationContainer>>& _scopes,
|
||||||
|
ASTNode& _astRoot,
|
||||||
|
ErrorList& _errors
|
||||||
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool visit(ContractDefinition& _contract) override;
|
bool visit(ContractDefinition& _contract) override;
|
||||||
@ -159,7 +163,7 @@ private:
|
|||||||
// creates the Declaration error and adds it in the errors list and throws FatalError
|
// creates the Declaration error and adds it in the errors list and throws FatalError
|
||||||
void fatalDeclarationError(SourceLocation _sourceLocation, std::string const& _description);
|
void fatalDeclarationError(SourceLocation _sourceLocation, std::string const& _description);
|
||||||
|
|
||||||
std::map<ASTNode const*, DeclarationContainer>& m_scopes;
|
std::map<ASTNode const*, std::unique_ptr<DeclarationContainer>>& m_scopes;
|
||||||
Declaration const* m_currentScope = nullptr;
|
Declaration const* m_currentScope = nullptr;
|
||||||
VariableScope* m_currentFunction = nullptr;
|
VariableScope* m_currentFunction = nullptr;
|
||||||
ErrorList& m_errors;
|
ErrorList& m_errors;
|
||||||
|
Loading…
Reference in New Issue
Block a user