From 6b9dda06f3d85344a70efb2f868760a0dde9dc45 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 14 Feb 2018 01:48:40 +0100 Subject: Enable C99-scoping with the 0.5.0-experimental pragma. --- libsolidity/ast/AST.cpp | 30 +++++++++++++++--------------- libsolidity/ast/AST.h | 13 +++++++------ 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'libsolidity/ast') diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 60a15aeb..27220b1f 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -96,21 +96,6 @@ set SourceUnit::referencedSourceUnits(bool _recurse, set(s) && dynamic_cast(s)->scope()) - s = dynamic_cast(s)->scope(); - return dynamic_cast(*s); -} - -string Declaration::sourceUnitName() const -{ - return sourceUnit().annotation().path; -} - ImportAnnotation& ImportDirective::annotation() const { if (!m_annotation) @@ -409,6 +394,21 @@ UserDefinedTypeNameAnnotation& UserDefinedTypeName::annotation() const return dynamic_cast(*m_annotation); } +SourceUnit const& Scopable::sourceUnit() const +{ + ASTNode const* s = scope(); + solAssert(s, ""); + // will not always be a declaratoion + while (dynamic_cast(s) && dynamic_cast(s)->scope()) + s = dynamic_cast(s)->scope(); + return dynamic_cast(*s); +} + +string Scopable::sourceUnitName() const +{ + return sourceUnit().annotation().path; +} + bool VariableDeclaration::isLValue() const { // External function parameters and constant declared variables are Read-Only diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 1e4c6591..863ad2fe 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -151,6 +151,13 @@ public: ASTNode const* scope() const { return m_scope; } void setScope(ASTNode const* _scope) { m_scope = _scope; } + /// @returns the source unit this scopable is present in. + SourceUnit const& sourceUnit() const; + + /// @returns the source name this scopable is present in. + /// Can be combined with annotation().canonicalName (if present) to form a globally unique name. + std::string sourceUnitName() const; + protected: ASTNode const* m_scope = nullptr; }; @@ -197,12 +204,6 @@ public: virtual bool isVisibleInContract() const { return visibility() != Visibility::External; } bool isVisibleInDerivedContracts() const { return isVisibleInContract() && visibility() >= Visibility::Internal; } - /// @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; std::string fullyQualifiedName() const { return sourceUnitName() + ":" + name(); } virtual bool isLValue() const { return false; } -- cgit