Merge pull request #1570 from ethereum/astidentifiers

Deterministic AST node identifiers.
This commit is contained in:
chriseth 2017-01-17 11:35:21 +01:00 committed by GitHub
commit a466f26c45
4 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,8 @@
### 0.4.9 (unreleased)
Features:
* AST: Use deterministic node identifiers.
### 0.4.8 (2017-01-13)
Features:

View File

@ -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()

View File

@ -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;

View File

@ -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()),