aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <g@ethdev.com>2015-01-07 23:32:13 +0800
committerGav Wood <g@ethdev.com>2015-01-07 23:32:13 +0800
commit53e38b3ac96cb9b420d24008dadeb95e44eee980 (patch)
tree2f35e1586fad362814444352299ad2e654b42f3c
parent95514d1d1b0ab9afdd39e1b35837ecf330362f9f (diff)
parentdf0dce584d2d1aacf3d33658b0540f243b3adb81 (diff)
downloaddexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar.gz
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar.bz2
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar.lz
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar.xz
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.tar.zst
dexon-solidity-53e38b3ac96cb9b420d24008dadeb95e44eee980.zip
Merge pull request #738 from LefterisJP/sol_abiFunctionHash
Canonical Function signature creation in solidity
-rw-r--r--AST.cpp5
-rw-r--r--AST.h5
-rw-r--r--Types.cpp10
-rw-r--r--Types.h1
4 files changed, 21 insertions, 0 deletions
diff --git a/AST.cpp b/AST.cpp
index c7d617b4..04771106 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -110,6 +110,11 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements();
}
+string FunctionDefinition::getCanonicalSignature() const
+{
+ return getName() + FunctionType(*this).getCanonicalSignature();
+}
+
void Block::checkTypeRequirements()
{
for (shared_ptr<Statement> const& statement: m_statements)
diff --git a/AST.h b/AST.h
index b7c3dc6c..8493d432 100644
--- a/AST.h
+++ b/AST.h
@@ -277,6 +277,11 @@ public:
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
void checkTypeRequirements();
+ /// @returns the canonical signature of the function
+ /// That consists of the name of the function followed by the types of the
+ /// arguments separated by commas all enclosed in parentheses without any spaces.
+ std::string getCanonicalSignature() const;
+
private:
bool m_isPublic;
ASTPointer<ParameterList> m_parameters;
diff --git a/Types.cpp b/Types.cpp
index c87ce2e6..7a81b65f 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -484,6 +484,16 @@ unsigned FunctionType::getSizeOnStack() const
}
}
+string FunctionType::getCanonicalSignature() const
+{
+ string ret = "(";
+
+ for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it)
+ ret += (*it)->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ",");
+
+ return ret + ")";
+}
+
bool MappingType::operator==(Type const& _other) const
{
if (_other.getCategory() != getCategory())
diff --git a/Types.h b/Types.h
index 0afa0ccd..ff8a4887 100644
--- a/Types.h
+++ b/Types.h
@@ -338,6 +338,7 @@ public:
virtual unsigned getSizeOnStack() const override;
Location const& getLocation() const { return m_location; }
+ std::string getCanonicalSignature() const;
private:
TypePointers m_parameterTypes;