aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-29 23:39:30 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-30 00:11:13 +0800
commit005100c4867f133e86a2675be0dd9370fed3e191 (patch)
treed41b83ef3066a24b94a152b9e7866db5f35eff2a /Types.cpp
parent77384af827d7d941620552c4f5f740c3b7c576ef (diff)
downloaddexon-solidity-005100c4867f133e86a2675be0dd9370fed3e191.tar.gz
dexon-solidity-005100c4867f133e86a2675be0dd9370fed3e191.tar.zst
dexon-solidity-005100c4867f133e86a2675be0dd9370fed3e191.zip
Contract Interface Functions now return FunctionType
- Enchanced Function Type by declaration so that it can provide all the required information at each place interface functions are consumed - Changed all places where interface functions was used. - Simplified Mix's FunctionDefinition code
Diffstat (limited to 'Types.cpp')
-rw-r--r--Types.cpp46
1 files changed, 41 insertions, 5 deletions
diff --git a/Types.cpp b/Types.cpp
index 3d6c4e96..e7765e1b 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -499,7 +499,7 @@ MemberList const& ContractType::getMembers() const
}
else
for (auto const& it: m_contract.getInterfaceFunctions())
- members[it.second.getName()] = it.second.getFunctionTypeShared();
+ members[it.second->getDeclaration()->getName()] = it.second;
m_members.reset(new MemberList(members));
}
return *m_members;
@@ -522,7 +522,7 @@ u256 ContractType::getFunctionIdentifier(string const& _functionName) const
{
auto interfaceFunctions = m_contract.getInterfaceFunctions();
for (auto const& it: m_contract.getInterfaceFunctions())
- if (it.second.getName() == _functionName)
+ if (it.second->getDeclaration()->getName() == _functionName)
return FixedHash<4>::Arith(it.first);
return Invalid256;
@@ -589,12 +589,15 @@ u256 StructType::getStorageOffsetOfMember(string const& _name) const
}
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
- m_location(_isInternal ? Location::INTERNAL : Location::EXTERNAL)
+ m_location(_isInternal ? Location::INTERNAL : Location::EXTERNAL),
+ m_isConstant(_function.isDeclaredConst()),
+ m_declaration(&_function)
{
TypePointers params;
vector<string> paramNames;
TypePointers retParams;
vector<string> retParamNames;
+
params.reserve(_function.getParameters().size());
paramNames.reserve(_function.getParameters().size());
for (ASTPointer<VariableDeclaration> const& var: _function.getParameters())
@@ -616,7 +619,7 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal
}
FunctionType::FunctionType(VariableDeclaration const& _varDecl):
- m_location(Location::EXTERNAL)
+ m_location(Location::EXTERNAL), m_isConstant(true), m_declaration(&_varDecl)
{
TypePointers params({});
vector<string> paramNames({});
@@ -711,7 +714,13 @@ MemberList const& FunctionType::getMembers() const
string FunctionType::getCanonicalSignature(std::string const& _name) const
{
- string ret = _name + "(";
+ std::string funcName = _name;
+ if (_name == "")
+ {
+ solAssert(m_declaration != nullptr, "Function type without name needs a declaration");
+ funcName = m_declaration->getName();
+ }
+ string ret = funcName + "(";
for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it)
ret += (*it)->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ",");
@@ -734,6 +743,33 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con
m_gasSet || _setGas, m_valueSet || _setValue);
}
+vector<string> const FunctionType::getParameterTypeNames() const
+{
+ vector<string> names;
+ for (TypePointer const& t: m_parameterTypes)
+ names.push_back(t->toString());
+
+ return names;
+}
+
+vector<string> const FunctionType::getReturnParameterTypeNames() const
+{
+ vector<string> names;
+ for (TypePointer const& t: m_returnParameterTypes)
+ names.push_back(t->toString());
+
+ return names;
+}
+
+ASTPointer<ASTString> FunctionType::getDocumentation() const
+{
+ auto function = dynamic_cast<FunctionDefinition const*>(m_declaration);
+ if (function)
+ return function->getDocumentation();
+
+ return ASTPointer<ASTString>();
+}
+
bool MappingType::operator==(Type const& _other) const
{
if (_other.getCategory() != getCategory())