aboutsummaryrefslogtreecommitdiffstats
path: root/ASTPrinter.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-10-10 22:37:54 +0800
committerChristian <c@ethdev.com>2014-10-10 22:47:21 +0800
commit98bdd7429974521946a1aa3bffa038fc515f745c (patch)
tree12736aca5ed657e6aebff050b7d663ed0da3df71 /ASTPrinter.h
parent924f7c62bdcb203f42514d298f15570ff53d2bac (diff)
downloaddexon-solidity-98bdd7429974521946a1aa3bffa038fc515f745c.tar.gz
dexon-solidity-98bdd7429974521946a1aa3bffa038fc515f745c.tar.zst
dexon-solidity-98bdd7429974521946a1aa3bffa038fc515f745c.zip
AST printer and command line tool, some fixes.
Diffstat (limited to 'ASTPrinter.h')
-rw-r--r--ASTPrinter.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/ASTPrinter.h b/ASTPrinter.h
new file mode 100644
index 00000000..d3cad11c
--- /dev/null
+++ b/ASTPrinter.h
@@ -0,0 +1,88 @@
+#pragma once
+
+#include <ostream>
+#include <libsolidity/ASTVisitor.h>
+
+namespace dev {
+namespace solidity {
+
+class ASTPrinter : public ASTVisitor
+{
+public:
+ /// Create a printer for the given abstract syntax tree. If the source is specified,
+ /// the corresponding parts of the source are printed with each node.
+ ASTPrinter(ptr<ASTNode> _ast, const std::string& _source = std::string());
+ /// Output the string representation of the AST to _stream.
+ void print(std::ostream& _stream);
+
+ bool visit(ContractDefinition& _node);
+ bool visit(StructDefinition& _node);
+ bool visit(ParameterList& _node);
+ bool visit(FunctionDefinition& _node);
+ bool visit(VariableDeclaration& _node);
+ bool visit(TypeName& _node);
+ bool visit(ElementaryTypeName& _node);
+ bool visit(UserDefinedTypeName& _node);
+ bool visit(Mapping& _node);
+ bool visit(Statement& _node);
+ bool visit(Block& _node);
+ bool visit(IfStatement& _node);
+ bool visit(BreakableStatement& _node);
+ bool visit(WhileStatement& _node);
+ bool visit(Continue& _node);
+ bool visit(Break& _node);
+ bool visit(Return& _node);
+ bool visit(VariableDefinition& _node);
+ bool visit(Expression& _node);
+ bool visit(Assignment& _node);
+ bool visit(UnaryOperation& _node);
+ bool visit(BinaryOperation& _node);
+ bool visit(FunctionCall& _node);
+ bool visit(MemberAccess& _node);
+ bool visit(IndexAccess& _node);
+ bool visit(PrimaryExpression& _node);
+ bool visit(ElementaryTypeNameExpression& _node);
+ bool visit(Literal& _node);
+
+ void endVisit(ASTNode & _node);
+ void endVisit(ContractDefinition&);
+ void endVisit(StructDefinition&);
+ void endVisit(ParameterList&);
+ void endVisit(FunctionDefinition&);
+ void endVisit(VariableDeclaration&);
+ void endVisit(TypeName&);
+ void endVisit(ElementaryTypeName&);
+ void endVisit(UserDefinedTypeName&);
+ void endVisit(Mapping&);
+ void endVisit(Statement&);
+ void endVisit(Block&);
+ void endVisit(IfStatement&);
+ void endVisit(BreakableStatement&);
+ void endVisit(WhileStatement&);
+ void endVisit(Continue&);
+ void endVisit(Break&);
+ void endVisit(Return&);
+ void endVisit(VariableDefinition&);
+ void endVisit(Expression&);
+ void endVisit(Assignment&);
+ void endVisit(UnaryOperation&);
+ void endVisit(BinaryOperation&);
+ void endVisit(FunctionCall&);
+ void endVisit(MemberAccess&);
+ void endVisit(IndexAccess&);
+ void endVisit(PrimaryExpression&);
+ void endVisit(ElementaryTypeNameExpression&);
+ void endVisit(Literal&);
+
+private:
+ void printSourcePart(ASTNode const& _node);
+ std::string getIndentation() const;
+ void writeLine(std::string const& _line);
+ bool goDeeper() { m_indentation++; return true; }
+ int m_indentation;
+ std::string m_source;
+ ptr<ASTNode> m_ast;
+ std::ostream* m_ostream;
+};
+
+} }