From 40ca2c9e977b98083efed96f031c298cf65d0893 Mon Sep 17 00:00:00 2001
From: Alex Sinyagin <sinyagin.alexander@gmail.com>
Date: Tue, 16 Aug 2016 14:28:28 +0000
Subject: Add ast json converter for UsingForDirective

---
 libsolidity/ast/ASTJsonConverter.cpp | 13 ++++++++++++-
 libsolidity/ast/ASTJsonConverter.h   |  2 ++
 test/libsolidity/ASTJSON.cpp         | 17 +++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 60a3fd0a..9362b86b 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -122,7 +122,13 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
 
 bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
 {
-	addJsonNode(_node, "Inheritance", { }, true);
+	addJsonNode(_node, "Inheritance", {}, true);
+	return true;
+}
+
+bool ASTJsonConverter::visit(UsingForDirective const& _node)
+{
+	addJsonNode(_node, "UsingFor", {}, true);
 	return true;
 }
 
@@ -356,6 +362,11 @@ void ASTJsonConverter::endVisit(InheritanceSpecifier const&)
 	goUp();
 }
 
+void ASTJsonConverter::endVisit(UsingForDirective const&)
+{
+	goUp();
+}
+
 void ASTJsonConverter::endVisit(StructDefinition const&)
 {
 	goUp();
diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h
index fb32352d..8e25802a 100644
--- a/libsolidity/ast/ASTJsonConverter.h
+++ b/libsolidity/ast/ASTJsonConverter.h
@@ -54,6 +54,7 @@ public:
 	bool visit(ImportDirective const& _node) override;
 	bool visit(ContractDefinition const& _node) override;
 	bool visit(InheritanceSpecifier const& _node) override;
+	bool visit(UsingForDirective const& _node) override;
 	bool visit(StructDefinition const& _node) override;
 	bool visit(ParameterList const& _node) override;
 	bool visit(FunctionDefinition const& _node) override;
@@ -89,6 +90,7 @@ public:
 	void endVisit(ImportDirective const&) override;
 	void endVisit(ContractDefinition const&) override;
 	void endVisit(InheritanceSpecifier const&) override;
+	void endVisit(UsingForDirective const&) override;
 	void endVisit(StructDefinition const&) override;
 	void endVisit(ParameterList const&) override;
 	void endVisit(FunctionDefinition const&) override;
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp
index 997e0fe8..c252b133 100644
--- a/test/libsolidity/ASTJSON.cpp
+++ b/test/libsolidity/ASTJSON.cpp
@@ -76,6 +76,23 @@ BOOST_AUTO_TEST_CASE(inheritance_specifier)
 	BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1");
 }
 
+BOOST_AUTO_TEST_CASE(using_for_directive)
+{
+	CompilerStack c;
+	c.addSource("a", "library L {} contract C { using L for uint; }");
+	c.parse();
+	map<string, unsigned> sourceIndices;
+	sourceIndices["a"] = 1;
+	Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
+	Json::Value usingFor = astJson["children"][1]["children"][0];
+	BOOST_CHECK_EQUAL(usingFor["name"], "UsingFor");
+	BOOST_CHECK_EQUAL(usingFor["src"], "26:17:1");
+	BOOST_CHECK_EQUAL(usingFor["children"][0]["name"], "UserDefinedTypeName");
+	BOOST_CHECK_EQUAL(usingFor["children"][0]["attributes"]["name"], "L");
+	BOOST_CHECK_EQUAL(usingFor["children"][1]["name"], "ElementaryTypeName");
+	BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint");    
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 }
-- 
cgit v1.2.3