aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-10-25 18:50:24 +0800
committerGitHub <noreply@github.com>2016-10-25 18:50:24 +0800
commite00a4b47c06d412cd9342b8be2163e861c591c28 (patch)
tree3c8584a2d12591f6dd5766f0c3f074bf0a6ffd97 /libsolidity
parentd190f016ad70f78f3abb06a09472235844e7c04d (diff)
parent59f6c18c2be86152261bb20732161c60fd2a6485 (diff)
downloaddexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.gz
dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.tar.zst
dexon-solidity-e00a4b47c06d412cd9342b8be2163e861c591c28.zip
Merge pull request #1264 from ethereum/988
State variable under contract's name
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp5
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp23
-rw-r--r--libsolidity/codegen/ExpressionCompiler.h2
3 files changed, 21 insertions, 9 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 10d24e5a..46f4f7f6 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1386,6 +1386,11 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
}
else if (exprType->category() == Type::Category::FixedBytes)
annotation.isLValue = false;
+ else if (TypeType const* typeType = dynamic_cast<decltype(typeType)>(exprType.get()))
+ {
+ if (ContractType const* contractType = dynamic_cast<decltype(contractType)>(typeType->actualType().get()))
+ annotation.isLValue = annotation.referencedDeclaration->isLValue();
+ }
return false;
}
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 6d54b48b..9a096e2d 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -890,6 +890,8 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
{
// no-op
}
+ else if (auto variable = dynamic_cast<VariableDeclaration const*>(_memberAccess.annotation().referencedDeclaration))
+ appendVariable(*variable, static_cast<Expression const&>(_memberAccess));
else
_memberAccess.expression().accept(*this);
}
@@ -1203,15 +1205,7 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration))
m_context << m_context.virtualFunctionEntryLabel(*functionDef).pushTag();
else if (auto variable = dynamic_cast<VariableDeclaration const*>(declaration))
- {
- if (!variable->isConstant())
- setLValueFromDeclaration(*declaration, _identifier);
- else
- {
- variable->value()->accept(*this);
- utils().convertType(*variable->value()->annotation().type, *variable->annotation().type);
- }
- }
+ appendVariable(*variable, static_cast<Expression const&>(_identifier));
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
{
if (contract->isLibrary())
@@ -1646,6 +1640,17 @@ void ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
utils().storeInMemoryDynamic(_expectedType);
}
+void ExpressionCompiler::appendVariable(VariableDeclaration const& _variable, Expression const& _expression)
+{
+ if (!_variable.isConstant())
+ setLValueFromDeclaration(_variable, _expression);
+ else
+ {
+ _variable.value()->accept(*this);
+ utils().convertType(*_variable.value()->annotation().type, *_variable.annotation().type);
+ }
+}
+
void ExpressionCompiler::setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression)
{
if (m_context.isLocalVariable(&_declaration))
diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h
index 43a92a10..f4ce1fec 100644
--- a/libsolidity/codegen/ExpressionCompiler.h
+++ b/libsolidity/codegen/ExpressionCompiler.h
@@ -103,6 +103,8 @@ private:
/// expected to be on the stack and is updated by this call.
void appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression);
+ /// Appends code for a variable that might be a constant or not
+ void appendVariable(VariableDeclaration const& _variable, Expression const& _expression);
/// Sets the current LValue to a new one (of the appropriate type) from the given declaration.
/// Also retrieves the value if it was not requested by @a _expression.
void setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression);