mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Reset AST node IDs between compilation runs.
This commit is contained in:
parent
da178d967f
commit
7159944f0f
@ -34,11 +34,24 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
|
class IDDispenser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static size_t next() { return ++instance(); }
|
||||||
|
static void reset() { instance() = 0; }
|
||||||
|
private:
|
||||||
|
static size_t& instance()
|
||||||
|
{
|
||||||
|
static IDDispenser dispenser;
|
||||||
|
return dispenser.id;
|
||||||
|
}
|
||||||
|
size_t id = 0;
|
||||||
|
};
|
||||||
|
|
||||||
ASTNode::ASTNode(SourceLocation const& _location):
|
ASTNode::ASTNode(SourceLocation const& _location):
|
||||||
|
m_id(IDDispenser::next()),
|
||||||
m_location(_location)
|
m_location(_location)
|
||||||
{
|
{
|
||||||
static size_t id = 0;
|
|
||||||
m_id = ++id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNode::~ASTNode()
|
ASTNode::~ASTNode()
|
||||||
@ -46,6 +59,11 @@ ASTNode::~ASTNode()
|
|||||||
delete m_annotation;
|
delete m_annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASTNode::resetID()
|
||||||
|
{
|
||||||
|
IDDispenser::reset();
|
||||||
|
}
|
||||||
|
|
||||||
ASTAnnotation& ASTNode::annotation() const
|
ASTAnnotation& ASTNode::annotation() const
|
||||||
{
|
{
|
||||||
if (!m_annotation)
|
if (!m_annotation)
|
||||||
|
@ -59,6 +59,8 @@ public:
|
|||||||
|
|
||||||
/// @returns an identifier of this AST node that is unique for a single compilation run.
|
/// @returns an identifier of this AST node that is unique for a single compilation run.
|
||||||
size_t id() const { return m_id; }
|
size_t id() const { return m_id; }
|
||||||
|
/// Resets the global ID counter. This invalidates all previous IDs.
|
||||||
|
static void resetID();
|
||||||
|
|
||||||
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;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <libdevcore/UTF8.h>
|
#include <libdevcore/UTF8.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/range/adaptor/reversed.hpp>
|
#include <boost/range/adaptor/reversed.hpp>
|
||||||
#include <boost/range/adaptor/sliced.hpp>
|
#include <boost/range/adaptor/sliced.hpp>
|
||||||
#include <boost/range/adaptor/transformed.hpp>
|
#include <boost/range/adaptor/transformed.hpp>
|
||||||
@ -163,7 +164,7 @@ string identifierList(TypePointer const& _type1, TypePointer const& _type2)
|
|||||||
|
|
||||||
string parenthesizeUserIdentifier(string const& _internal)
|
string parenthesizeUserIdentifier(string const& _internal)
|
||||||
{
|
{
|
||||||
return parenthesizeIdentifier(boost::replace_all_copy(_internal, "$", "$$$"));
|
return parenthesizeIdentifier(boost::algorithm::replace_all_copy(_internal, "$", "$$$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2109,9 +2110,9 @@ string FunctionType::identifier() const
|
|||||||
id += "_constant";
|
id += "_constant";
|
||||||
id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes);
|
id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes);
|
||||||
if (m_gasSet)
|
if (m_gasSet)
|
||||||
id += "gas_set_";
|
id += "gas";
|
||||||
if (m_valueSet)
|
if (m_valueSet)
|
||||||
id += "value_set_";
|
id += "value";
|
||||||
if (bound())
|
if (bound())
|
||||||
id += "bound_to" + identifierList(selfType());
|
id += "bound_to" + identifierList(selfType());
|
||||||
return id;
|
return id;
|
||||||
|
@ -112,6 +112,7 @@ bool CompilerStack::parse()
|
|||||||
{
|
{
|
||||||
//reset
|
//reset
|
||||||
m_errors.clear();
|
m_errors.clear();
|
||||||
|
ASTNode::resetID();
|
||||||
m_parseSuccessful = false;
|
m_parseSuccessful = false;
|
||||||
|
|
||||||
if (SemVerVersion{string(VersionString)}.isPrerelease())
|
if (SemVerVersion{string(VersionString)}.isPrerelease())
|
||||||
|
@ -90,6 +90,7 @@ BOOST_AUTO_TEST_CASE(storage_layout_arrays)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_identifiers)
|
BOOST_AUTO_TEST_CASE(type_identifiers)
|
||||||
{
|
{
|
||||||
|
ASTNode::resetID();
|
||||||
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("uint128")->identifier(), "t_uint128");
|
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("uint128")->identifier(), "t_uint128");
|
||||||
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("int128")->identifier(), "t_int128");
|
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("int128")->identifier(), "t_int128");
|
||||||
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("address")->identifier(), "t_address");
|
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("address")->identifier(), "t_address");
|
||||||
|
Loading…
Reference in New Issue
Block a user