Add reference to contract in FunctionDefinition annotation

This commit is contained in:
Mathias Baumann 2019-09-16 12:37:56 +02:00
parent 20e227afb5
commit 5ff02c12e2
3 changed files with 6 additions and 0 deletions

View File

@ -570,6 +570,7 @@ bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract)
m_globalContext.setCurrentContract(_contract);
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentThis(), nullptr, false, true);
m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentSuper(), nullptr, false, true);
m_currentContract = &_contract;
registerDeclaration(_contract, true);
_contract.annotation().canonicalName = currentCanonicalName();
@ -578,6 +579,7 @@ bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract)
void DeclarationRegistrationHelper::endVisit(ContractDefinition&)
{
m_currentContract = nullptr;
closeCurrentScope();
}
@ -615,6 +617,7 @@ bool DeclarationRegistrationHelper::visit(FunctionDefinition& _function)
{
registerDeclaration(_function, true);
m_currentFunction = &_function;
_function.annotation().contract = m_currentContract;
return true;
}

View File

@ -204,6 +204,7 @@ private:
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
ASTNode const* m_currentScope = nullptr;
VariableScope* m_currentFunction = nullptr;
ContractDefinition const* m_currentContract = nullptr;
langutil::ErrorReporter& m_errorReporter;
GlobalContext& m_globalContext;
};

View File

@ -109,6 +109,8 @@ struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
/// The function this function overrides, if any. This is always the closest
/// in the linearized inheritance hierarchy.
FunctionDefinition const* superFunction = nullptr;
/// Reference to the contract this function is defined in
ContractDefinition const* contract = nullptr;
};
struct EventDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation