Skip to content

Commit 4457170

Browse files
committed
Merge pull request #96 from chriseth/moreASTOutput
Provide types for VariableDeclaration.
2 parents 1736fe8 + e81f4ba commit 4457170

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

libsolidity/ASTJsonConverter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
124124

125125
bool ASTJsonConverter::visit(VariableDeclaration const& _node)
126126
{
127-
addJsonNode("VariableDeclaration", { make_pair("name", _node.name()) }, true);
127+
addJsonNode("VariableDeclaration", {
128+
make_pair("name", _node.name()),
129+
make_pair("name", _node.name()),
130+
}, true);
128131
return true;
129132
}
130133

@@ -444,5 +447,10 @@ string ASTJsonConverter::type(Expression const& _expression)
444447
return _expression.annotation().type ? _expression.annotation().type->toString() : "Unknown";
445448
}
446449

450+
string ASTJsonConverter::type(VariableDeclaration const& _varDecl)
451+
{
452+
return _varDecl.annotation().type ? _varDecl.annotation().type->toString() : "Unknown";
453+
}
454+
447455
}
448456
}

libsolidity/ASTJsonConverter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ASTJsonConverter: public ASTConstVisitor
116116
std::initializer_list<std::pair<std::string const, std::string const>> _list,
117117
bool _hasChildren);
118118
std::string type(Expression const& _expression);
119+
std::string type(VariableDeclaration const& _varDecl);
119120
inline void goUp()
120121
{
121122
solAssert(!m_jsonNodePtrs.empty(), "Uneven json nodes stack. Internal error.");

libsolidity/ASTPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ bool ASTPrinter::visit(FunctionDefinition const& _node)
105105
bool ASTPrinter::visit(VariableDeclaration const& _node)
106106
{
107107
writeLine("VariableDeclaration \"" + _node.name() + "\"");
108+
*m_ostream << indentation() << (
109+
_node.annotation().type ?
110+
string(" Type: ") + _node.annotation().type->toString() :
111+
string(" Type unknown.")
112+
) << "\n";
108113
printSourcePart(_node);
109114
return goDeeper();
110115
}

0 commit comments

Comments
 (0)