aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-01-17 17:31:09 +0800
committerchriseth <c@ethdev.com>2017-01-17 17:45:45 +0800
commit99eaadd2cd4ece9c3ceba16fa5559c45c2e66b08 (patch)
treeb02e8efce3ff7e63b8a285bca0c93e24fdc548ff /libsolidity/ast
parent6ecb4aa36f8c30ca91f650d17f1214c2f2bc4319 (diff)
downloaddexon-solidity-99eaadd2cd4ece9c3ceba16fa5559c45c2e66b08.tar.gz
dexon-solidity-99eaadd2cd4ece9c3ceba16fa5559c45c2e66b08.tar.zst
dexon-solidity-99eaadd2cd4ece9c3ceba16fa5559c45c2e66b08.zip
Deterministic AST node identifiers.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.cpp2
-rw-r--r--libsolidity/ast/AST.h4
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
3 files changed, 8 insertions, 2 deletions
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()),