mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Style fixes and refactoring in ASTJsonConverter
This commit is contained in:
parent
9c8ce49969
commit
839f7778b5
@ -56,7 +56,7 @@ void ASTJsonConverter::addJsonNode(string const& _nodeName,
|
||||
node["attributes"] = attrs;
|
||||
}
|
||||
|
||||
(*m_jsonNodePtrs.top()).append(node);
|
||||
m_jsonNodePtrs.top()->append(node);
|
||||
|
||||
if (_hasChildren)
|
||||
{
|
||||
@ -82,7 +82,6 @@ void ASTJsonConverter::print(ostream& _stream)
|
||||
_stream << m_astJson;
|
||||
}
|
||||
|
||||
|
||||
bool ASTJsonConverter::visit(ImportDirective const& _node)
|
||||
{
|
||||
addJsonNode("Import", { make_pair("file", _node.getIdentifier())});
|
||||
@ -217,8 +216,7 @@ bool ASTJsonConverter::visit(ExpressionStatement const&)
|
||||
bool ASTJsonConverter::visit(Expression const& _node)
|
||||
{
|
||||
addJsonNode("Expression",
|
||||
{
|
||||
make_pair("type", getType(_node)),
|
||||
{ make_pair("type", getType(_node)),
|
||||
make_pair("lvalue", boost::lexical_cast<std::string>(_node.isLValue())),
|
||||
make_pair("local_lvalue", boost::lexical_cast<std::string>(_node.isLocalLValue())) },
|
||||
true);
|
||||
@ -314,7 +312,6 @@ bool ASTJsonConverter::visit(Literal const& _node)
|
||||
|
||||
void ASTJsonConverter::endVisit(ImportDirective const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(ContractDefinition const&)
|
||||
@ -343,22 +340,18 @@ void ASTJsonConverter::endVisit(VariableDeclaration const&)
|
||||
|
||||
void ASTJsonConverter::endVisit(TypeName const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(ElementaryTypeName const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(UserDefinedTypeName const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Mapping const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Statement const&)
|
||||
@ -378,7 +371,6 @@ void ASTJsonConverter::endVisit(IfStatement const&)
|
||||
|
||||
void ASTJsonConverter::endVisit(BreakableStatement const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(WhileStatement const&)
|
||||
@ -393,12 +385,10 @@ void ASTJsonConverter::endVisit(ForStatement const&)
|
||||
|
||||
void ASTJsonConverter::endVisit(Continue const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Break const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Return const&)
|
||||
@ -458,29 +448,24 @@ void ASTJsonConverter::endVisit(IndexAccess const&)
|
||||
|
||||
void ASTJsonConverter::endVisit(PrimaryExpression const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Identifier const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(ElementaryTypeNameExpression const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ASTJsonConverter::endVisit(Literal const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string const ASTJsonConverter::getType(Expression const& _expression)
|
||||
string ASTJsonConverter::getType(Expression const& _expression)
|
||||
{
|
||||
return (_expression.getType()) ? _expression.getType()->toString() : "Unknown";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <stack>
|
||||
#include <libsolidity/ASTVisitor.h>
|
||||
#include <libsolidity/Exceptions.h>
|
||||
#include <libsolidity/Utils.h>
|
||||
#include <jsoncpp/json/json.h>
|
||||
|
||||
namespace dev
|
||||
@ -39,8 +40,7 @@ namespace solidity
|
||||
class ASTJsonConverter: public ASTConstVisitor
|
||||
{
|
||||
public:
|
||||
/// Create a converter for the given abstract syntax tree. If the source is specified,
|
||||
/// the corresponding parts of the source are printed with each node.
|
||||
/// Create a converter to JSON for the given abstract syntax tree.
|
||||
ASTJsonConverter(ASTNode const& _ast);
|
||||
/// Output the json representation of the AST to _stream.
|
||||
void print(std::ostream& _stream);
|
||||
@ -118,11 +118,10 @@ private:
|
||||
void addJsonNode(std::string const& _nodeName,
|
||||
std::initializer_list<std::pair<std::string const, std::string const>> _list,
|
||||
bool _hasChildren);
|
||||
std::string const getType(Expression const& _expression);
|
||||
std::string getType(Expression const& _expression);
|
||||
inline void goUp()
|
||||
{
|
||||
if (m_jsonNodePtrs.empty())
|
||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal error"));
|
||||
solAssert(!m_jsonNodePtrs.empty(), "Uneven json nodes stack. Internal error.");
|
||||
m_jsonNodePtrs.pop();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user