11 changed files with 1065 additions and 55 deletions
@ -0,0 +1,53 @@ |
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <memory> |
|||
#include <vector> |
|||
|
|||
// Forward-declare all AST node types
|
|||
|
|||
namespace dev { |
|||
namespace solidity { |
|||
|
|||
class ASTNode; |
|||
class ContractDefinition; |
|||
class StructDefinition; |
|||
class ParameterList; |
|||
class FunctionDefinition; |
|||
class VariableDeclaration; |
|||
class TypeName; |
|||
class ElementaryTypeName; |
|||
class UserDefinedTypeName; |
|||
class Mapping; |
|||
class Statement; |
|||
class Block; |
|||
class IfStatement; |
|||
class BreakableStatement; |
|||
class WhileStatement; |
|||
class Continue; |
|||
class Break; |
|||
class Return; |
|||
class VariableDefinition; |
|||
class Expression; |
|||
class Assignment; |
|||
class UnaryOperation; |
|||
class BinaryOperation; |
|||
class FunctionCall; |
|||
class MemberAccess; |
|||
class IndexAccess; |
|||
class PrimaryExpression; |
|||
class ElementaryTypeNameExpression; |
|||
class Literal; |
|||
|
|||
// Used as pointers to AST nodes, to be replaced by more clever pointers, e.g. pointers which do
|
|||
// not do reference counting but point to a special memory area that is completely released
|
|||
// explicitly.
|
|||
template <class T> |
|||
using ptr = std::shared_ptr<T>; |
|||
template <class T> |
|||
using vecptr = std::vector<ptr<T>>; |
|||
|
|||
using ASTString = std::string; |
|||
|
|||
|
|||
} } |
@ -0,0 +1,388 @@ |
|||
#include <libsolidity/ASTPrinter.h> |
|||
#include <libsolidity/AST.h> |
|||
|
|||
namespace dev { |
|||
namespace solidity { |
|||
|
|||
ASTPrinter::ASTPrinter(ptr<ASTNode> _ast, const std::string& _source) |
|||
: m_indentation(0), m_source(_source), m_ast(_ast) |
|||
{ |
|||
} |
|||
|
|||
void ASTPrinter::print(std::ostream& _stream) |
|||
{ |
|||
m_ostream = &_stream; |
|||
m_ast->accept(*this); |
|||
m_ostream = nullptr; |
|||
} |
|||
|
|||
|
|||
bool ASTPrinter::visit(ContractDefinition& _node) |
|||
{ |
|||
writeLine("ContractDefinition \"" + _node.getName() + "\""); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(StructDefinition& _node) |
|||
{ |
|||
writeLine("StructDefinition \"" + _node.getName() + "\""); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(ParameterList& _node) |
|||
{ |
|||
writeLine("ParameterList"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(FunctionDefinition& _node) |
|||
{ |
|||
writeLine("FunctionDefinition \"" + _node.getName() + "\"" + |
|||
(_node.isPublic() ? " - public" : "") + |
|||
(_node.isDeclaredConst() ? " - const" : "")); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(VariableDeclaration& _node) |
|||
{ |
|||
writeLine("VariableDeclaration \"" + _node.getName() + "\""); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(TypeName& _node) |
|||
{ |
|||
writeLine("TypeName"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(ElementaryTypeName& _node) |
|||
{ |
|||
writeLine(std::string("ElementaryTypeName ") + Token::String(_node.getType())); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(UserDefinedTypeName& _node) |
|||
{ |
|||
writeLine("UserDefinedTypeName \"" + _node.getName() + "\""); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Mapping& _node) |
|||
{ |
|||
writeLine("Mapping"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Statement& _node) |
|||
{ |
|||
writeLine("Statement"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Block& _node) |
|||
{ |
|||
writeLine("Block"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(IfStatement& _node) |
|||
{ |
|||
writeLine("IfStatement"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(BreakableStatement& _node) |
|||
{ |
|||
writeLine("BreakableStatement"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(WhileStatement& _node) |
|||
{ |
|||
writeLine("WhileStatement"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Continue& _node) |
|||
{ |
|||
writeLine("Continue"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Break& _node) |
|||
{ |
|||
writeLine("Break"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Return& _node) |
|||
{ |
|||
writeLine("Return"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(VariableDefinition& _node) |
|||
{ |
|||
writeLine("VariableDefinition"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Expression& _node) |
|||
{ |
|||
writeLine("Expression"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Assignment& _node) |
|||
{ |
|||
writeLine(std::string("Assignment using operator ") + Token::String(_node.getAssignmentOperator())); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(UnaryOperation& _node) |
|||
{ |
|||
writeLine(std::string("UnaryOperation (") + (_node.isPrefixOperation() ? "prefix" : "postfix") + |
|||
") " + Token::String(_node.getOperator())); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(BinaryOperation& _node) |
|||
{ |
|||
writeLine(std::string("BinaryOperation using operator ") + Token::String(_node.getOperator())); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(FunctionCall& _node) |
|||
{ |
|||
writeLine("FunctionCall"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(MemberAccess& _node) |
|||
{ |
|||
writeLine("MemberAccess to member " + _node.getMemberName()); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(IndexAccess& _node) |
|||
{ |
|||
writeLine("IndexAccess"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(PrimaryExpression& _node) |
|||
{ |
|||
writeLine("PrimaryExpression"); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(ElementaryTypeNameExpression& _node) |
|||
{ |
|||
writeLine(std::string("ElementaryTypeNameExpression ") + Token::String(_node.getType())); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
bool ASTPrinter::visit(Literal& _node) |
|||
{ |
|||
const char* tokenString = Token::String(_node.getToken()); |
|||
if (tokenString == nullptr) |
|||
tokenString = "----"; |
|||
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue()); |
|||
printSourcePart(_node); |
|||
return goDeeper(); |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(ASTNode&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
// @todo instead of this, we could make the default implementation of endVisit call the
|
|||
// superclass' endVisit
|
|||
void ASTPrinter::endVisit(ContractDefinition&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(StructDefinition&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(ParameterList&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(FunctionDefinition&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(VariableDeclaration&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(TypeName&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(ElementaryTypeName&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(UserDefinedTypeName&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Mapping&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Statement&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Block&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(IfStatement&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(BreakableStatement&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(WhileStatement&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Continue&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Break&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Return&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(VariableDefinition&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Expression&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Assignment&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(UnaryOperation&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(BinaryOperation&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(FunctionCall&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(MemberAccess&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(IndexAccess&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(PrimaryExpression&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(ElementaryTypeNameExpression&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::endVisit(Literal&) |
|||
{ |
|||
m_indentation--; |
|||
} |
|||
|
|||
void ASTPrinter::printSourcePart(ASTNode const& _node) |
|||
{ |
|||
if (!m_source.empty()) { |
|||
Location const& location(_node.getLocation()); |
|||
*m_ostream << getIndentation() << " Source: |" |
|||
<< m_source.substr(location.start, location.end - location.start) << "|\n"; |
|||
} |
|||
} |
|||
|
|||
std::string ASTPrinter::getIndentation() const |
|||
{ |
|||
return std::string(m_indentation * 2, ' '); |
|||
} |
|||
|
|||
void ASTPrinter::writeLine(const std::string& _line) |
|||
{ |
|||
*m_ostream << getIndentation() << _line << '\n'; |
|||
} |
|||
|
|||
} } |
@ -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; |
|||
}; |
|||
|
|||
} } |
@ -0,0 +1,76 @@ |
|||
#pragma once |
|||
|
|||
#include <libsolidity/ASTForward.h> |
|||
#include <string> |
|||
|
|||
namespace dev { |
|||
namespace solidity { |
|||
|
|||
class ASTVisitor { |
|||
public: |
|||
/// These functions are called after a call to ASTNode::accept,
|
|||
/// first visit, then (if visit returns true) recursively for all
|
|||
/// child nodes in document order (exception for contracts) and then
|
|||
/// endVisit.
|
|||
virtual bool visit(ASTNode&) { return true; } |
|||
virtual bool visit(ContractDefinition&) { return true; } |
|||
virtual bool visit(StructDefinition&) { return true; } |
|||
virtual bool visit(ParameterList&) { return true; } |
|||
virtual bool visit(FunctionDefinition&) { return true; } |
|||
virtual bool visit(VariableDeclaration&) { return true; } |
|||
virtual bool visit(TypeName&) { return true; } |
|||
virtual bool visit(ElementaryTypeName&) { return true; } |
|||
virtual bool visit(UserDefinedTypeName&) { return true; } |
|||
virtual bool visit(Mapping&) { return true; } |
|||
virtual bool visit(Statement&) { return true; } |
|||
virtual bool visit(Block&) { return true; } |
|||
virtual bool visit(IfStatement&) { return true; } |
|||
virtual bool visit(BreakableStatement&) { return true; } |
|||
virtual bool visit(WhileStatement&) { return true; } |
|||
virtual bool visit(Continue&) { return true; } |
|||
virtual bool visit(Break&) { return true; } |
|||
virtual bool visit(Return&) { return true; } |
|||
virtual bool visit(VariableDefinition&) { return true; } |
|||
virtual bool visit(Expression&) { return true; } |
|||
virtual bool visit(Assignment&) { return true; } |
|||
virtual bool visit(UnaryOperation&) { return true; } |
|||
virtual bool visit(BinaryOperation&) { return true; } |
|||
virtual bool visit(FunctionCall&) { return true; } |
|||
virtual bool visit(MemberAccess&) { return true; } |
|||
virtual bool visit(IndexAccess&) { return true; } |
|||
virtual bool visit(PrimaryExpression&) { return true; } |
|||
virtual bool visit(ElementaryTypeNameExpression&) { return true; } |
|||
virtual bool visit(Literal&) { return true; } |
|||
|
|||
virtual void endVisit(ASTNode&) { } |
|||
virtual void endVisit(ContractDefinition&) { } |
|||
virtual void endVisit(StructDefinition&) { } |
|||
virtual void endVisit(ParameterList&) { } |
|||
virtual void endVisit(FunctionDefinition&) { } |
|||
virtual void endVisit(VariableDeclaration&) { } |
|||
virtual void endVisit(TypeName&) { } |
|||
virtual void endVisit(ElementaryTypeName&) { } |
|||
virtual void endVisit(UserDefinedTypeName&) { } |
|||
virtual void endVisit(Mapping&) { } |
|||
virtual void endVisit(Statement&) { } |
|||
virtual void endVisit(Block&) { } |
|||
virtual void endVisit(IfStatement&) { } |
|||
virtual void endVisit(BreakableStatement&) { } |
|||
virtual void endVisit(WhileStatement&) { } |
|||
virtual void endVisit(Continue&) { } |
|||
virtual void endVisit(Break&) { } |
|||
virtual void endVisit(Return&) { } |
|||
virtual void endVisit(VariableDefinition&) { } |
|||
virtual void endVisit(Expression&) { } |
|||
virtual void endVisit(Assignment&) { } |
|||
virtual void endVisit(UnaryOperation&) { } |
|||
virtual void endVisit(BinaryOperation&) { } |
|||
virtual void endVisit(FunctionCall&) { } |
|||
virtual void endVisit(MemberAccess&) { } |
|||
virtual void endVisit(IndexAccess&) { } |
|||
virtual void endVisit(PrimaryExpression&) { } |
|||
virtual void endVisit(ElementaryTypeNameExpression&) { } |
|||
virtual void endVisit(Literal&) { } |
|||
}; |
|||
|
|||
} } |
@ -0,0 +1,31 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(..) |
|||
|
|||
set(EXECUTABLE solc) |
|||
|
|||
add_executable(${EXECUTABLE} ${SRC_LIST}) |
|||
|
|||
target_link_libraries(${EXECUTABLE} solidity) |
|||
target_link_libraries(${EXECUTABLE} devcore) |
|||
|
|||
if ("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") |
|||
target_link_libraries(${EXECUTABLE} gcc) |
|||
target_link_libraries(${EXECUTABLE} gdi32) |
|||
target_link_libraries(${EXECUTABLE} ws2_32) |
|||
target_link_libraries(${EXECUTABLE} mswsock) |
|||
target_link_libraries(${EXECUTABLE} shlwapi) |
|||
target_link_libraries(${EXECUTABLE} iphlpapi) |
|||
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) |
|||
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) |
|||
elseif (UNIX) |
|||
else () |
|||
find_package(Threads REQUIRED) |
|||
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
endif () |
|||
|
|||
install( TARGETS ${EXECUTABLE} DESTINATION bin ) |
|||
|
@ -0,0 +1,78 @@ |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/CommonData.h> |
|||
#include <libdevcore/CommonIO.h> |
|||
#include <libsolidity/Scanner.h> |
|||
#include <libsolidity/Parser.h> |
|||
#include <libsolidity/ASTPrinter.h> |
|||
|
|||
namespace dev { |
|||
namespace solidity { |
|||
|
|||
ptr<ASTNode> parseAST(std::string const& _source) |
|||
{ |
|||
ptr<Scanner> scanner = std::make_shared<Scanner>(CharStream(_source)); |
|||
Parser parser; |
|||
return parser.parse(scanner); |
|||
} |
|||
|
|||
} } // end namespaces
|
|||
|
|||
void help() |
|||
{ |
|||
std::cout |
|||
<< "Usage solc [OPTIONS] <file>" << std::endl |
|||
<< "Options:" << std::endl |
|||
<< " -h,--help Show this help message and exit." << std::endl |
|||
<< " -V,--version Show the version and exit." << std::endl; |
|||
exit(0); |
|||
} |
|||
|
|||
void version() |
|||
{ |
|||
std::cout |
|||
<< "solc, the solidity complier commandline interface " << dev::Version << std::endl |
|||
<< " by Christian <c@ethdev.com>, (c) 2014." << std::endl |
|||
<< "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << std::endl; |
|||
exit(0); |
|||
} |
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
std::string infile; |
|||
|
|||
for (int i = 1; i < argc; ++i) |
|||
{ |
|||
std::string arg = argv[i]; |
|||
if (arg == "-h" || arg == "--help") |
|||
help(); |
|||
else if (arg == "-V" || arg == "--version") |
|||
version(); |
|||
else |
|||
infile = argv[i]; |
|||
} |
|||
|
|||
std::string src; |
|||
if (infile.empty()) |
|||
{ |
|||
std::string s; |
|||
while (!std::cin.eof()) |
|||
{ |
|||
getline(std::cin, s); |
|||
src.append(s); |
|||
} |
|||
} else { |
|||
src = dev::asString(dev::contents(infile)); |
|||
} |
|||
|
|||
std::cout << "Parsing..." << std::endl; |
|||
// @todo catch exception
|
|||
dev::solidity::ptr<dev::solidity::ASTNode> ast = dev::solidity::parseAST(src); |
|||
std::cout << "Syntax tree for the contract:" << std::endl; |
|||
dev::solidity::ASTPrinter printer(ast, src); |
|||
printer.print(std::cout); |
|||
return 0; |
|||
} |
Loading…
Reference in new issue