mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1570 from ethereum/astidentifiers
Deterministic AST node identifiers.
This commit is contained in:
commit
a466f26c45
@ -1,5 +1,8 @@
|
|||||||
### 0.4.9 (unreleased)
|
### 0.4.9 (unreleased)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
* AST: Use deterministic node identifiers.
|
||||||
|
|
||||||
### 0.4.8 (2017-01-13)
|
### 0.4.8 (2017-01-13)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
@ -37,6 +37,8 @@ using namespace dev::solidity;
|
|||||||
ASTNode::ASTNode(SourceLocation const& _location):
|
ASTNode::ASTNode(SourceLocation const& _location):
|
||||||
m_location(_location)
|
m_location(_location)
|
||||||
{
|
{
|
||||||
|
static size_t id = 0;
|
||||||
|
m_id = ++id;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNode::~ASTNode()
|
ASTNode::~ASTNode()
|
||||||
|
@ -57,6 +57,9 @@ public:
|
|||||||
explicit ASTNode(SourceLocation const& _location);
|
explicit ASTNode(SourceLocation const& _location);
|
||||||
virtual ~ASTNode();
|
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(ASTVisitor& _visitor) = 0;
|
||||||
virtual void accept(ASTConstVisitor& _visitor) const = 0;
|
virtual void accept(ASTConstVisitor& _visitor) const = 0;
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -94,6 +97,7 @@ public:
|
|||||||
///@}
|
///@}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
size_t m_id = 0;
|
||||||
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
|
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
|
||||||
mutable ASTAnnotation* m_annotation = nullptr;
|
mutable ASTAnnotation* m_annotation = nullptr;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void ASTJsonConverter::addJsonNode(
|
|||||||
{
|
{
|
||||||
Json::Value node;
|
Json::Value node;
|
||||||
|
|
||||||
node["id"] = reinterpret_cast<Json::UInt64>(&_node);
|
node["id"] = _node.id();
|
||||||
node["src"] = sourceLocationToString(_node.location());
|
node["src"] = sourceLocationToString(_node.location());
|
||||||
node["name"] = _nodeName;
|
node["name"] = _nodeName;
|
||||||
if (_attributes.size() != 0)
|
if (_attributes.size() != 0)
|
||||||
@ -124,7 +124,7 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
|
|||||||
{
|
{
|
||||||
Json::Value linearizedBaseContracts(Json::arrayValue);
|
Json::Value linearizedBaseContracts(Json::arrayValue);
|
||||||
for (auto const& baseContract: _node.annotation().linearizedBaseContracts)
|
for (auto const& baseContract: _node.annotation().linearizedBaseContracts)
|
||||||
linearizedBaseContracts.append(reinterpret_cast<Json::UInt64>(baseContract));
|
linearizedBaseContracts.append(baseContract->id());
|
||||||
addJsonNode(_node, "ContractDefinition", {
|
addJsonNode(_node, "ContractDefinition", {
|
||||||
make_pair("name", _node.name()),
|
make_pair("name", _node.name()),
|
||||||
make_pair("isLibrary", _node.isLibrary()),
|
make_pair("isLibrary", _node.isLibrary()),
|
||||||
|
Loading…
Reference in New Issue
Block a user