aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-02 19:59:12 +0800
committerchriseth <c@ethdev.com>2015-03-02 19:59:12 +0800
commit32e210eccad6ea951feaa3441a6aefb9938f8a90 (patch)
tree372ced6ce92be6a7a9d52bfc8ba2dfb371fbac23
parent346d87cc6347b8f6bd309b8f0dfc4a446adc7973 (diff)
parent4f13859f8c010410b7497ed860c409a8b899538c (diff)
downloaddexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar.gz
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar.bz2
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar.lz
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar.xz
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.tar.zst
dexon-solidity-32e210eccad6ea951feaa3441a6aefb9938f8a90.zip
Merge pull request #1146 from LefterisJP/sol_fixBaseClassAccessors
Sol fix accessing public variable of base class
-rw-r--r--AST.cpp27
-rw-r--r--AST.h11
-rw-r--r--Types.cpp10
3 files changed, 41 insertions, 7 deletions
diff --git a/AST.cpp b/AST.cpp
index c37e8c37..4c6db6a2 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -209,6 +209,33 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
return *m_interfaceFunctionList;
}
+vector<Declaration const*> const& ContractDefinition::getInheritableMembers() const
+{
+ if (!m_inheritableMembers)
+ {
+ set<string> memberSeen;
+ m_inheritableMembers.reset(new vector<Declaration const*>());
+ auto addInheritableMember = [&](Declaration const* _decl)
+ {
+ if (memberSeen.count(_decl->getName()) == 0 && _decl->isVisibleInDerivedContracts())
+ {
+ memberSeen.insert(_decl->getName());
+ m_inheritableMembers->push_back(_decl);
+ }
+ };
+
+ for (ASTPointer<FunctionDefinition> const& f: getDefinedFunctions())
+ addInheritableMember(f.get());
+
+ for (ASTPointer<VariableDeclaration> const& v: getStateVariables())
+ addInheritableMember(v.get());
+
+ for (ASTPointer<StructDefinition> const& s: getDefinedStructs())
+ addInheritableMember(s.get());
+ }
+ return *m_inheritableMembers;
+}
+
TypePointer EnumValue::getType(ContractDefinition const*) const
{
EnumDefinition const* parentDef = dynamic_cast<EnumDefinition const*>(getScope());
diff --git a/AST.h b/AST.h
index dea0fba6..d028e8a7 100644
--- a/AST.h
+++ b/AST.h
@@ -144,7 +144,7 @@ public:
Visibility getVisibility() const { return m_visibility == Visibility::Default ? getDefaultVisibility() : m_visibility; }
bool isPublic() const { return getVisibility() >= Visibility::Public; }
bool isVisibleInContract() const { return getVisibility() != Visibility::External; }
- bool isVisibleInDerivedContracts() const { return isVisibleInContract() && getVisibility() >= Visibility::Internal; }
+ virtual bool isVisibleInDerivedContracts() const { return isVisibleInContract() && getVisibility() >= Visibility::Internal; }
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
/// Available only after name and type resolution step.
@@ -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<Declaration const*> 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<Declaration const*>> m_inheritableMembers;
};
class InheritanceSpecifier: public ASTNode
@@ -405,6 +409,11 @@ public:
ASTPointer<ParameterList> const& getReturnParameterList() const { return m_returnParameters; }
Block const& getBody() const { return *m_body; }
+ virtual bool isVisibleInDerivedContracts() const override
+ {
+ return !isConstructor() && !getName().empty() && isVisibleInContract() &&
+ getVisibility() >= Visibility::Internal;
+ }
virtual TypePointer getType(ContractDefinition const*) const override;
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
diff --git a/Types.cpp b/Types.cpp
index 8cc1f258..22d612cd 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -643,8 +643,7 @@ MemberList const& ContractType::getMembers() const
{
for (ContractDefinition const* base: m_contract.getLinearizedBaseContracts())
for (ASTPointer<FunctionDefinition> const& function: base->getDefinedFunctions())
- if (!function->isConstructor() && !function->getName().empty()&&
- function->isVisibleInDerivedContracts())
+ if (function->isVisibleInDerivedContracts())
members.push_back(make_pair(function->getName(), make_shared<FunctionType>(*function, true)));
}
else
@@ -1039,10 +1038,9 @@ MemberList const& TypeType::getMembers() const
vector<ContractDefinition const*> currentBases = m_currentContract->getLinearizedBaseContracts();
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)));
+ // members. Note that this does not add inherited functions on purpose.
+ for (Declaration const* decl: contract.getInheritableMembers())
+ members.push_back(make_pair(decl->getName(), decl->getType()));
}
else if (m_actualType->getCategory() == Category::Enum)
{