aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast/AST.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-28 00:06:10 +0800
committerGitHub <noreply@github.com>2018-02-28 00:06:10 +0800
commit908b46e9a7f56a06c76db9e702fb9b25d8b0d344 (patch)
tree47594aa2e1c58a14557263f04199f01421622106 /libsolidity/ast/AST.cpp
parent6d8dee586c592b3ed34143b0e4c6cba3b704fa84 (diff)
parentd64aa0eaad50741896020d31c0c93b64c3f03bc1 (diff)
downloaddexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.gz
dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.zst
dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.zip
Merge pull request #3476 from ethereum/scoping
C99/C++ scoping rules
Diffstat (limited to 'libsolidity/ast/AST.cpp')
-rw-r--r--libsolidity/ast/AST.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 8da6964e..27220b1f 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -96,20 +96,6 @@ set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, set<Sour
return sourceUnits;
}
-SourceUnit const& Declaration::sourceUnit() const
-{
- solAssert(!!m_scope, "");
- ASTNode const* scope = m_scope;
- while (dynamic_cast<Declaration const*>(scope) && dynamic_cast<Declaration const*>(scope)->m_scope)
- scope = dynamic_cast<Declaration const*>(scope)->m_scope;
- return dynamic_cast<SourceUnit const&>(*scope);
-}
-
-string Declaration::sourceUnitName() const
-{
- return sourceUnit().annotation().path;
-}
-
ImportAnnotation& ImportDirective::annotation() const
{
if (!m_annotation)
@@ -408,12 +394,36 @@ UserDefinedTypeNameAnnotation& UserDefinedTypeName::annotation() const
return dynamic_cast<UserDefinedTypeNameAnnotation&>(*m_annotation);
}
+SourceUnit const& Scopable::sourceUnit() const
+{
+ ASTNode const* s = scope();
+ solAssert(s, "");
+ // will not always be a declaratoion
+ while (dynamic_cast<Scopable const*>(s) && dynamic_cast<Scopable const*>(s)->scope())
+ s = dynamic_cast<Scopable const*>(s)->scope();
+ return dynamic_cast<SourceUnit const&>(*s);
+}
+
+string Scopable::sourceUnitName() const
+{
+ return sourceUnit().annotation().path;
+}
+
bool VariableDeclaration::isLValue() const
{
// External function parameters and constant declared variables are Read-Only
return !isExternalCallableParameter() && !m_isConstant;
}
+bool VariableDeclaration::isLocalVariable() const
+{
+ auto s = scope();
+ return
+ dynamic_cast<CallableDeclaration const*>(s) ||
+ dynamic_cast<Block const*>(s) ||
+ dynamic_cast<ForStatement const*>(s);
+}
+
bool VariableDeclaration::isCallableParameter() const
{
auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
@@ -459,8 +469,7 @@ bool VariableDeclaration::isExternalCallableParameter() const
bool VariableDeclaration::canHaveAutoType() const
{
- auto const* callable = dynamic_cast<CallableDeclaration const*>(scope());
- return (!!callable && !isCallableParameter());
+ return isLocalVariable() && !isCallableParameter();
}
TypePointer VariableDeclaration::type() const