aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-01-17 18:35:21 +0800
committerGitHub <noreply@github.com>2017-01-17 18:35:21 +0800
commita466f26c459c8df27b0b25e53b897461fdc8fd63 (patch)
treeb02e8efce3ff7e63b8a285bca0c93e24fdc548ff
parent6ecb4aa36f8c30ca91f650d17f1214c2f2bc4319 (diff)
parent99eaadd2cd4ece9c3ceba16fa5559c45c2e66b08 (diff)
downloaddexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar.gz
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar.bz2
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar.lz
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar.xz
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.tar.zst
dexon-solidity-a466f26c459c8df27b0b25e53b897461fdc8fd63.zip
Merge pull request #1570 from ethereum/astidentifiers
Deterministic AST node identifiers.
-rw-r--r--Changelog.md3
-rw-r--r--libsolidity/ast/AST.cpp2
-rw-r--r--libsolidity/ast/AST.h4
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
4 files changed, 11 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md
index a5c4b922..1a80bac0 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,8 @@
### 0.4.9 (unreleased)
+Features:
+ * AST: Use deterministic node identifiers.
+
### 0.4.8 (2017-01-13)
Features:
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 6f7a64dc..3db4627a 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -37,6 +37,8 @@ using namespace dev::solidity;
ASTNode::ASTNode(SourceLocation const& _location):
m_location(_location)
{
+ static size_t id = 0;
+ m_id = ++id;
}
ASTNode::~ASTNode()
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 2d092408..e9df2e7d 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -57,6 +57,9 @@ public:
explicit ASTNode(SourceLocation const& _location);
virtual ~ASTNode();
+ /// @returns an identifier of this AST node that is unique for a single compilation run.
+ size_t id() const { return m_id; }
+
virtual void accept(ASTVisitor& _visitor) = 0;
virtual void accept(ASTConstVisitor& _visitor) const = 0;
template <class T>
@@ -94,6 +97,7 @@ public:
///@}
protected:
+ size_t m_id = 0;
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
mutable ASTAnnotation* m_annotation = nullptr;
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index abaad0fd..de8fde92 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -42,7 +42,7 @@ void ASTJsonConverter::addJsonNode(
{
Json::Value node;
- node["id"] = reinterpret_cast<Json::UInt64>(&_node);
+ node["id"] = _node.id();
node["src"] = sourceLocationToString(_node.location());
node["name"] = _nodeName;
if (_attributes.size() != 0)
@@ -124,7 +124,7 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
{
Json::Value linearizedBaseContracts(Json::arrayValue);
for (auto const& baseContract: _node.annotation().linearizedBaseContracts)
- linearizedBaseContracts.append(reinterpret_cast<Json::UInt64>(baseContract));
+ linearizedBaseContracts.append(baseContract->id());
addJsonNode(_node, "ContractDefinition", {
make_pair("name", _node.name()),
make_pair("isLibrary", _node.isLibrary()),