From 1b0ef0b785d195ca28aa756047da040b676f5fc9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 12 Jul 2017 23:15:52 +0100 Subject: Add sourceUnit() helper to Declaration --- libsolidity/ast/AST.cpp | 9 +++++++-- libsolidity/ast/AST.h | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 724a908f..1e1e4839 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -84,13 +84,18 @@ SourceUnitAnnotation& SourceUnit::annotation() const return dynamic_cast(*m_annotation); } -string Declaration::sourceUnitName() const +SourceUnit const& Declaration::sourceUnit() const { solAssert(!!m_scope, ""); ASTNode const* scope = m_scope; while (dynamic_cast(scope) && dynamic_cast(scope)->m_scope) scope = dynamic_cast(scope)->m_scope; - return dynamic_cast(*scope).annotation().path; + return dynamic_cast(*scope); +} + +string Declaration::sourceUnitName() const +{ + return sourceUnit().annotation().path; } ImportAnnotation& ImportDirective::annotation() const diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 81ddc754..41785780 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -168,6 +168,9 @@ public: ASTNode const* scope() const { return m_scope; } void setScope(ASTNode const* _scope) { m_scope = _scope; } + /// @returns the source unit this declaration is present in. + SourceUnit const& sourceUnit() const; + /// @returns the source name this declaration is present in. /// Can be combined with annotation().canonicalName to form a globally unique name. std::string sourceUnitName() const; -- cgit v1.2.3