mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
MemberList.Member's last argument (declaration) made mandatory to avoid accidental missing out during construction.
This commit is contained in:
parent
b0d3412fa9
commit
9ca389d6cd
@ -111,6 +111,13 @@ util::Result<TypePointers> transformParametersToExternal(TypePointers const& _pa
|
||||
|
||||
}
|
||||
|
||||
MemberList::Member::Member(Declaration const* _declaration, Type const* _type):
|
||||
name(_declaration->name()),
|
||||
type(_type),
|
||||
declaration(_declaration)
|
||||
{
|
||||
}
|
||||
|
||||
void Type::clearCache() const
|
||||
{
|
||||
m_members.clear();
|
||||
@ -365,7 +372,7 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _sc
|
||||
FunctionTypePointer fun =
|
||||
dynamic_cast<FunctionType const&>(*function->typeViaContractName()).asBoundFunction();
|
||||
if (_type.isImplicitlyConvertibleTo(*fun->selfType()))
|
||||
members.emplace_back(function->name(), fun, function);
|
||||
members.emplace_back(function, fun);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1985,9 +1992,8 @@ MemberList::MemberMap ContractType::nativeMembers(ASTNode const*) const
|
||||
if (!m_contract.isLibrary())
|
||||
for (auto const& it: m_contract.interfaceFunctions())
|
||||
members.emplace_back(
|
||||
it.second->declaration().name(),
|
||||
it.second->asExternallyCallableFunction(m_contract.isLibrary()),
|
||||
&it.second->declaration()
|
||||
&it.second->declaration(),
|
||||
it.second->asExternallyCallableFunction(m_contract.isLibrary())
|
||||
);
|
||||
|
||||
return members;
|
||||
@ -2213,9 +2219,8 @@ MemberList::MemberMap StructType::nativeMembers(ASTNode const*) const
|
||||
solAssert(type, "");
|
||||
solAssert(!(location() != DataLocation::Storage && type->containsNestedMapping()), "");
|
||||
members.emplace_back(
|
||||
variable->name(),
|
||||
copyForLocationIfReference(type),
|
||||
variable.get()
|
||||
variable.get(),
|
||||
copyForLocationIfReference(type)
|
||||
);
|
||||
}
|
||||
return members;
|
||||
@ -3687,7 +3692,7 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons
|
||||
break;
|
||||
}
|
||||
if (!functionWithEqualArgumentsFound)
|
||||
members.emplace_back(function->name(), functionType, function);
|
||||
members.emplace_back(function, functionType);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -3708,15 +3713,15 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons
|
||||
auto const* functionDefinition = dynamic_cast<FunctionDefinition const*>(declaration);
|
||||
functionDefinition && !functionDefinition->isImplemented()
|
||||
)
|
||||
members.emplace_back(declaration->name(), declaration->typeViaContractName(), declaration);
|
||||
members.emplace_back(declaration, declaration->typeViaContractName());
|
||||
else
|
||||
members.emplace_back(declaration->name(), declaration->type(), declaration);
|
||||
members.emplace_back(declaration, declaration->type());
|
||||
}
|
||||
else if (
|
||||
(contract.isLibrary() && declaration->isVisibleAsLibraryMember()) ||
|
||||
declaration->isVisibleViaContractTypeAccess()
|
||||
)
|
||||
members.emplace_back(declaration->name(), declaration->typeViaContractName(), declaration);
|
||||
members.emplace_back(declaration, declaration->typeViaContractName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3725,7 +3730,7 @@ MemberList::MemberMap TypeType::nativeMembers(ASTNode const* _currentScope) cons
|
||||
EnumDefinition const& enumDef = dynamic_cast<EnumType const&>(*m_actualType).enumDefinition();
|
||||
auto enumType = TypeProvider::enumType(enumDef);
|
||||
for (ASTPointer<EnumValue> const& enumValue: enumDef.members())
|
||||
members.emplace_back(enumValue->name(), enumType, enumValue.get());
|
||||
members.emplace_back(enumValue.get(), enumType);
|
||||
}
|
||||
return members;
|
||||
}
|
||||
@ -3801,9 +3806,12 @@ bool ModuleType::operator==(Type const& _other) const
|
||||
MemberList::MemberMap ModuleType::nativeMembers(ASTNode const*) const
|
||||
{
|
||||
MemberList::MemberMap symbols;
|
||||
for (auto const& symbolName: *m_sourceUnit.annotation().exportedSymbols)
|
||||
for (Declaration const* symbol: symbolName.second)
|
||||
symbols.emplace_back(symbolName.first, symbol->type(), symbol);
|
||||
for (auto const& [name, declarations]: *m_sourceUnit.annotation().exportedSymbols)
|
||||
for (Declaration const* symbol: declarations)
|
||||
{
|
||||
solAssert(name == symbol->name(), "");
|
||||
symbols.emplace_back(symbol, symbol->type());
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
|
@ -100,15 +100,19 @@ class MemberList
|
||||
public:
|
||||
struct Member
|
||||
{
|
||||
Member(std::string _name, Type const* _type, Declaration const* _declaration = nullptr):
|
||||
name(std::move(_name)),
|
||||
/// Manual constructor for members that are not taken from a declaration.
|
||||
Member(char const* _name, Type const* _type):
|
||||
name(_name),
|
||||
type(_type),
|
||||
declaration(_declaration)
|
||||
declaration(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructs a Member with the name extracted from @p _declaration's name.
|
||||
Member(Declaration const* _declaration, Type const* _type);
|
||||
|
||||
std::string name;
|
||||
Type const* type;
|
||||
Type const* type = nullptr;
|
||||
Declaration const* declaration = nullptr;
|
||||
};
|
||||
|
||||
|
@ -78,9 +78,9 @@ BOOST_AUTO_TEST_CASE(ufixed_types)
|
||||
BOOST_AUTO_TEST_CASE(storage_layout_simple)
|
||||
{
|
||||
MemberList members(MemberList::MemberMap({
|
||||
{string("first"), TypeProvider::fromElementaryTypeName("uint128")},
|
||||
{string("second"), TypeProvider::fromElementaryTypeName("uint120")},
|
||||
{string("wraps"), TypeProvider::fromElementaryTypeName("uint16")}
|
||||
{"first", TypeProvider::fromElementaryTypeName("uint128")},
|
||||
{"second", TypeProvider::fromElementaryTypeName("uint120")},
|
||||
{"wraps", TypeProvider::fromElementaryTypeName("uint16")}
|
||||
}));
|
||||
BOOST_REQUIRE_EQUAL(u256(2), members.storageSize());
|
||||
BOOST_REQUIRE(members.memberStorageOffset("first") != nullptr);
|
||||
@ -94,13 +94,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_simple)
|
||||
BOOST_AUTO_TEST_CASE(storage_layout_mapping)
|
||||
{
|
||||
MemberList members(MemberList::MemberMap({
|
||||
{string("first"), TypeProvider::fromElementaryTypeName("uint128")},
|
||||
{string("second"), TypeProvider::mapping(
|
||||
{"first", TypeProvider::fromElementaryTypeName("uint128")},
|
||||
{"second", TypeProvider::mapping(
|
||||
TypeProvider::fromElementaryTypeName("uint8"),
|
||||
TypeProvider::fromElementaryTypeName("uint8")
|
||||
)},
|
||||
{string("third"), TypeProvider::fromElementaryTypeName("uint16")},
|
||||
{string("final"), TypeProvider::mapping(
|
||||
{"third", TypeProvider::fromElementaryTypeName("uint16")},
|
||||
{"final", TypeProvider::mapping(
|
||||
TypeProvider::fromElementaryTypeName("uint8"),
|
||||
TypeProvider::fromElementaryTypeName("uint8")
|
||||
)},
|
||||
|
Loading…
Reference in New Issue
Block a user