mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Some changes to enums.
This commit is contained in:
		
							parent
							
								
									41647fd75f
								
							
						
					
					
						commit
						c944976d00
					
				
							
								
								
									
										13
									
								
								AST.cpp
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								AST.cpp
									
									
									
									
									
								
							| @ -262,19 +262,6 @@ void StructDefinition::checkRecursion() const | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void EnumDefinition::checkValidityOfMembers() const | ||||
| { | ||||
| 	vector<ASTPointer<EnumValue>> members(getMembers()); | ||||
| 	auto compareDecls = [](ASTPointer<EnumValue> a, ASTPointer<EnumValue> 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(members[i]->createTypeError("Duplicate member detected in Enum")); | ||||
| } | ||||
| 
 | ||||
| TypePointer EnumDefinition::getType(ContractDefinition const*) const | ||||
| { | ||||
| 	return make_shared<TypeType>(make_shared<EnumType>(*this)); | ||||
|  | ||||
							
								
								
									
										4
									
								
								AST.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								AST.h
									
									
									
									
									
								
							| @ -333,11 +333,7 @@ public: | ||||
| 
 | ||||
| 	virtual TypePointer getType(ContractDefinition const*) const override; | ||||
| 
 | ||||
| 	/// Checks that the members do not include any duplicate names
 | ||||
| 	void checkValidityOfMembers() const; | ||||
| 
 | ||||
| private: | ||||
| 
 | ||||
| 	std::vector<ASTPointer<EnumValue>> m_members; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -498,12 +498,10 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) | ||||
| 	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)) | ||||
| 			BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to " + type.toString()));			 | ||||
| 			BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid member access to " + type.toString())); | ||||
| 
 | ||||
| 		if ((contractType = dynamic_cast<ContractType const*>(type.getActualType().get()))) | ||||
| 		if (auto contractType = dynamic_cast<ContractType const*>(type.getActualType().get())) | ||||
| 		{ | ||||
| 			ContractDefinition const& contract = contractType->getContractDefinition(); | ||||
| 			for (ASTPointer<FunctionDefinition> const& function: contract.getDefinedFunctions()) | ||||
| @ -513,12 +511,9 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess) | ||||
| 					return; | ||||
| 				} | ||||
| 		} | ||||
| 		else if ((enumType = dynamic_cast<EnumType const*>(type.getActualType().get()))) | ||||
| 		{ | ||||
| 		else if (auto enumType = dynamic_cast<EnumType const*>(type.getActualType().get())) | ||||
| 			m_context << enumType->getMemberValue(_memberAccess.getMemberName()); | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		break; | ||||
| 	} | ||||
| 	case Type::Category::ByteArray: | ||||
| 	{ | ||||
|  | ||||
| @ -81,8 +81,6 @@ void NameAndTypeResolver::checkTypeRequirements(ContractDefinition& _contract) | ||||
| { | ||||
| 	for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs()) | ||||
| 		structDef->checkValidityOfMembers(); | ||||
| 	for (ASTPointer<EnumDefinition> const& enumDef: _contract.getDefinedEnums()) | ||||
| 		enumDef->checkValidityOfMembers(); | ||||
| 	_contract.checkTypeRequirements(); | ||||
| } | ||||
| 
 | ||||
| @ -236,6 +234,12 @@ void DeclarationRegistrationHelper::endVisit(EnumDefinition&) | ||||
| 	closeCurrentScope(); | ||||
| } | ||||
| 
 | ||||
| bool DeclarationRegistrationHelper::visit(EnumValue& _value) | ||||
| { | ||||
| 	registerDeclaration(_value, false); | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| bool DeclarationRegistrationHelper::visit(FunctionDefinition& _function) | ||||
| { | ||||
| 	registerDeclaration(_function, true); | ||||
|  | ||||
| @ -100,6 +100,7 @@ private: | ||||
| 	void endVisit(StructDefinition& _struct) override; | ||||
| 	bool visit(EnumDefinition& _enum) override; | ||||
| 	void endVisit(EnumDefinition& _enum) override; | ||||
| 	bool visit(EnumValue& _value) override; | ||||
| 	bool visit(FunctionDefinition& _function) override; | ||||
| 	void endVisit(FunctionDefinition& _function) override; | ||||
| 	bool visit(ModifierDefinition& _modifier) override; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user