diff options
-rw-r--r-- | AST.cpp | 14 | ||||
-rw-r--r-- | ExpressionCompiler.cpp | 27 |
2 files changed, 27 insertions, 14 deletions
@@ -263,13 +263,15 @@ void StructDefinition::checkRecursion() const void EnumDefinition::checkValidityOfMembers() const { -#if 0 // LTODO: Make this work for the Declarations - vector<ASTPointer<ASTString>> members = getMembers(); - sort(begin(members), end(members)); - for (size_t i = 0; i < members.size(); ++i) - if (members[i] == members[i + 1]) + vector<ASTPointer<EnumDeclaration>> members(getMembers()); + auto compareDecls = [](ASTPointer<EnumDeclaration> a, ASTPointer<EnumDeclaration> b) + { + return a->getName() < b->getName(); + }; + sort(begin(members), end(members), compareDecls); + for (size_t i = 0; i < members.size() - 1; ++i) + if (members[i]->getName() == members[i + 1]->getName()) BOOST_THROW_EXCEPTION(createTypeError("Duplicate member detected in Enum")); -#endif } TypePointer EnumDefinition::getType(ContractDefinition const*) const diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index dd41b485..4e72aca5 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -494,20 +494,31 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) EnumType const& type = dynamic_cast<EnumType const&>(*_memberAccess.getExpression().getType()); EnumDefinition const& enumDef = type.getEnumDefinition(); m_context << enumDef.getMemberValue(_memberAccess.getMemberName()); + break; } case Type::Category::TypeType: { TypeType const& type = dynamic_cast<TypeType const&>(*_memberAccess.getExpression().getType()); + ContractType const* contractType; + EnumType const* enumType; if (type.getMembers().getMemberType(member)) { - ContractDefinition const& contract = dynamic_cast<ContractType const&>(*type.getActualType()) - .getContractDefinition(); - for (ASTPointer<FunctionDefinition> const& function: contract.getDefinedFunctions()) - if (function->getName() == member) - { - m_context << m_context.getFunctionEntryLabel(*function).pushTag(); - return; - } + if ((contractType = dynamic_cast<ContractType const*>(type.getActualType().get()))) + { + ContractDefinition const& contract = contractType->getContractDefinition(); + for (ASTPointer<FunctionDefinition> const& function: contract.getDefinedFunctions()) + if (function->getName() == member) + { + m_context << m_context.getFunctionEntryLabel(*function).pushTag(); + return; + } + } + else if ((enumType = dynamic_cast<EnumType const*>(type.getActualType().get()))) + { + EnumDefinition const &enumDef = enumType->getEnumDefinition(); + m_context << enumDef.getMemberValue(_memberAccess.getMemberName()); + return; + } } BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to " + type.toString())); } |