mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add all path locations to the IdentifierPath ASTNode
This commit is contained in:
+13
-2
@@ -587,10 +587,19 @@ private:
|
||||
class IdentifierPath: public ASTNode
|
||||
{
|
||||
public:
|
||||
IdentifierPath(int64_t _id, SourceLocation const& _location, std::vector<ASTString> _path):
|
||||
ASTNode(_id, _location), m_path(std::move(_path)) {}
|
||||
IdentifierPath(
|
||||
int64_t _id,
|
||||
SourceLocation const& _location,
|
||||
std::vector<ASTString> _path,
|
||||
std::vector<SourceLocation> _pathLocations
|
||||
):
|
||||
ASTNode(_id, _location), m_path(std::move(_path)), m_pathLocations(std::move(_pathLocations))
|
||||
{
|
||||
solAssert(m_pathLocations.size() == m_path.size());
|
||||
}
|
||||
|
||||
std::vector<ASTString> const& path() const { return m_path; }
|
||||
std::vector<SourceLocation > const& pathLocations() const { return m_pathLocations; }
|
||||
IdentifierPathAnnotation& annotation() const override
|
||||
{
|
||||
return initAnnotation<IdentifierPathAnnotation>();
|
||||
@@ -600,6 +609,8 @@ public:
|
||||
void accept(ASTConstVisitor& _visitor) const override;
|
||||
private:
|
||||
std::vector<ASTString> m_path;
|
||||
// Corresponding locations for m_path. Array has same length and indices as m_path.
|
||||
std::vector<SourceLocation> m_pathLocations;
|
||||
};
|
||||
|
||||
class InheritanceSpecifier: public ASTNode
|
||||
|
||||
@@ -294,8 +294,14 @@ bool ASTJsonExporter::visit(ContractDefinition const& _node)
|
||||
|
||||
bool ASTJsonExporter::visit(IdentifierPath const& _node)
|
||||
{
|
||||
Json::Value nameLocations = Json::arrayValue;
|
||||
|
||||
for (SourceLocation location: _node.pathLocations())
|
||||
nameLocations.append(sourceLocationToString(location));
|
||||
|
||||
setJsonNode(_node, "IdentifierPath", {
|
||||
make_pair("name", namePathToString(_node.path())),
|
||||
make_pair("nameLocations", nameLocations),
|
||||
make_pair("referencedDeclaration", idOrNull(_node.annotation().referencedDeclaration))
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -325,6 +325,7 @@ ASTPointer<IdentifierPath> ASTJsonImporter::createIdentifierPath(Json::Value con
|
||||
astAssert(_node["name"].isString(), "Expected 'name' to be a string!");
|
||||
|
||||
vector<ASTString> namePath;
|
||||
vector<SourceLocation> namePathLocations;
|
||||
vector<string> strs;
|
||||
string nameString = member(_node, "name").asString();
|
||||
boost::algorithm::split(strs, nameString, boost::is_any_of("."));
|
||||
@@ -334,7 +335,23 @@ ASTPointer<IdentifierPath> ASTJsonImporter::createIdentifierPath(Json::Value con
|
||||
astAssert(!s.empty(), "Expected non-empty string for IdentifierPath element.");
|
||||
namePath.emplace_back(s);
|
||||
}
|
||||
return createASTNode<IdentifierPath>(_node, namePath);
|
||||
|
||||
if (_node.isMember("nameLocations") && _node["nameLocations"].isArray())
|
||||
for (auto const& val: _node["nameLocations"])
|
||||
namePathLocations.emplace_back(langutil::parseSourceLocation(val.asString(), m_sourceNames));
|
||||
else
|
||||
namePathLocations.resize(namePath.size());
|
||||
|
||||
astAssert(
|
||||
namePath.size() == namePathLocations.size(),
|
||||
"SourceLocations don't match name paths."
|
||||
);
|
||||
|
||||
return createASTNode<IdentifierPath>(
|
||||
_node,
|
||||
namePath,
|
||||
namePathLocations
|
||||
);
|
||||
}
|
||||
|
||||
ASTPointer<InheritanceSpecifier> ASTJsonImporter::createInheritanceSpecifier(Json::Value const& _node)
|
||||
|
||||
Reference in New Issue
Block a user