From 86495dfc57dde9b825ffd8c219ea809446e978f9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 19 Nov 2015 18:02:04 +0100 Subject: Make members context-sensitive. --- libsolidity/codegen/CompilerUtils.cpp | 4 ++-- libsolidity/codegen/ExpressionCompiler.cpp | 8 ++------ libsolidity/codegen/LValue.cpp | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 357013e6..b57f5b29 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -542,7 +542,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp allocateMemory(); m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2; // stack: - for (auto const& member: typeOnStack.members()) + for (auto const& member: typeOnStack.members(nullptr)) { if (!member.type->canLiveOutsideStorage()) continue; @@ -642,7 +642,7 @@ void CompilerUtils::pushZeroValue(Type const& _type) m_context << eth::Instruction::DUP1; if (auto structType = dynamic_cast(&_type)) - for (auto const& member: structType->members()) + for (auto const& member: structType->members(nullptr)) { pushZeroValue(*member.type); storeInMemoryDynamic(*member.type); diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index c94c988b..6c288ae7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -888,10 +888,6 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) case Type::Category::TypeType: { TypeType const& type = dynamic_cast(*_memberAccess.expression().annotation().type); - solAssert( - !type.members().membersByName(_memberAccess.memberName()).empty(), - "Invalid member access to " + type.toString(false) - ); if (dynamic_cast(type.actualType().get())) { @@ -1043,11 +1039,11 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier) Declaration const* declaration = _identifier.annotation().referencedDeclaration; if (MagicVariableDeclaration const* magicVar = dynamic_cast(declaration)) { - switch (magicVar->type(_identifier.annotation().contractScope)->category()) + switch (magicVar->type()->category()) { case Type::Category::Contract: // "this" or "super" - if (!dynamic_cast(*magicVar->type(_identifier.annotation().contractScope)).isSuper()) + if (!dynamic_cast(*magicVar->type()).isSuper()) m_context << eth::Instruction::ADDRESS; break; case Type::Category::Integer: diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 864f28d0..fdef6937 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -273,7 +273,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc "Struct assignment with conversion." ); solAssert(sourceType.location() != DataLocation::CallData, "Structs in calldata not supported."); - for (auto const& member: structType.members()) + for (auto const& member: structType.members(nullptr)) { // assign each member that is not a mapping TypePointer const& memberType = member.type; @@ -336,7 +336,7 @@ void StorageItem::setToZero(SourceLocation const&, bool _removeReference) const // @todo this can be improved: use StorageItem for non-value types, and just store 0 in // all slots that contain value types later. auto const& structType = dynamic_cast(*m_dataType); - for (auto const& member: structType.members()) + for (auto const& member: structType.members(nullptr)) { // zero each member that is not a mapping TypePointer const& memberType = member.type; -- cgit From b47d5932528357939ee29758a8b8027c90bdb1e5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 23 Nov 2015 23:57:17 +0100 Subject: Do not store elements of a contract by AST node type. --- libsolidity/codegen/Compiler.cpp | 2 +- libsolidity/codegen/CompilerContext.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index 055e607f..f1d95980 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -385,7 +385,7 @@ void Compiler::registerStateVariables(ContractDefinition const& _contract) void Compiler::initializeStateVariables(ContractDefinition const& _contract) { - for (ASTPointer const& variable: _contract.stateVariables()) + for (VariableDeclaration const* variable: _contract.stateVariables()) if (variable->value() && !variable->isConstant()) ExpressionCompiler(m_context, m_optimize).appendStateVariableInitialization(*variable); } diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 00b9d87c..9e2405cc 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -133,9 +133,9 @@ ModifierDefinition const& CompilerContext::functionModifier(string const& _name) { solAssert(!m_inheritanceHierarchy.empty(), "No inheritance hierarchy set."); for (ContractDefinition const* contract: m_inheritanceHierarchy) - for (ASTPointer const& modifier: contract->functionModifiers()) + for (ModifierDefinition const* modifier: contract->functionModifiers()) if (modifier->name() == _name) - return *modifier.get(); + return *modifier; BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Function modifier " + _name + " not found.")); } @@ -195,7 +195,7 @@ eth::AssemblyItem CompilerContext::virtualFunctionEntryLabel( FunctionType functionType(_function); auto it = _searchStart; for (; it != m_inheritanceHierarchy.end(); ++it) - for (ASTPointer const& function: (*it)->definedFunctions()) + for (FunctionDefinition const* function: (*it)->definedFunctions()) if ( function->name() == name && !function->isConstructor() && -- cgit