mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adding inheritable members to a contract
This commit is contained in:
parent
a5b4f18dd7
commit
5e4665b84d
27
AST.cpp
27
AST.cpp
@ -209,6 +209,33 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
|
||||
return *m_interfaceFunctionList;
|
||||
}
|
||||
|
||||
vector<ASTPointer<Declaration>> const& ContractDefinition::getInheritableMembers() const
|
||||
{
|
||||
if (!m_inheritableMembers)
|
||||
{
|
||||
set<string> memberSeen;
|
||||
m_inheritableMembers.reset(new vector<ASTPointer<Declaration>>());
|
||||
for (ContractDefinition const* contract: getLinearizedBaseContracts())
|
||||
{
|
||||
for (ASTPointer<FunctionDefinition> const& f: contract->getDefinedFunctions())
|
||||
if (f->isPublic() && !f->isConstructor() && !f->getName().empty()
|
||||
&& memberSeen.count(f->getName()) == 0 && f->isVisibleInDerivedContracts())
|
||||
{
|
||||
memberSeen.insert(f->getName());
|
||||
m_inheritableMembers->push_back(f);
|
||||
}
|
||||
|
||||
for (ASTPointer<VariableDeclaration> const& v: contract->getStateVariables())
|
||||
if (v->isPublic() && memberSeen.count(v->getName()) == 0)
|
||||
{
|
||||
memberSeen.insert(v->getName());
|
||||
m_inheritableMembers->push_back(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
return *m_inheritableMembers;
|
||||
}
|
||||
|
||||
TypePointer EnumValue::getType(ContractDefinition const*) const
|
||||
{
|
||||
EnumDefinition const* parentDef = dynamic_cast<EnumDefinition const*>(getScope());
|
||||
|
4
AST.h
4
AST.h
@ -247,6 +247,9 @@ public:
|
||||
/// as intended for use by the ABI.
|
||||
std::map<FixedHash<4>, FunctionTypePointer> getInterfaceFunctions() const;
|
||||
|
||||
/// @returns a list of the inheritable members of this contract
|
||||
std::vector<ASTPointer<Declaration>> const& getInheritableMembers() const;
|
||||
|
||||
/// List of all (direct and indirect) base contracts in order from derived to base, including
|
||||
/// the contract itself. Available after name resolution
|
||||
std::vector<ContractDefinition const*> const& getLinearizedBaseContracts() const { return m_linearizedBaseContracts; }
|
||||
@ -273,6 +276,7 @@ private:
|
||||
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
||||
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
|
||||
mutable std::unique_ptr<std::vector<ASTPointer<EventDefinition>>> m_interfaceEvents;
|
||||
mutable std::unique_ptr<std::vector<ASTPointer<Declaration>>> m_inheritableMembers;
|
||||
};
|
||||
|
||||
class InheritanceSpecifier: public ASTNode
|
||||
|
@ -1025,9 +1025,8 @@ MemberList const& TypeType::getMembers() const
|
||||
if (find(currentBases.begin(), currentBases.end(), &contract) != currentBases.end())
|
||||
// We are accessing the type of a base contract, so add all public and protected
|
||||
// functions. Note that this does not add inherited functions on purpose.
|
||||
for (ASTPointer<FunctionDefinition> const& f: contract.getDefinedFunctions())
|
||||
if (!f->isConstructor() && !f->getName().empty() && f->isVisibleInDerivedContracts())
|
||||
members.push_back(make_pair(f->getName(), make_shared<FunctionType>(*f)));
|
||||
for (ASTPointer<Declaration> const& decl: contract.getInheritableMembers())
|
||||
members.push_back(make_pair(decl->getName(), decl->getType()));
|
||||
}
|
||||
else if (m_actualType->getCategory() == Category::Enum)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user