aboutsummaryrefslogtreecommitdiffstats
path: root/CommandLineInterface.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-05 22:46:40 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-15 23:56:40 +0800
commitd0f02c28c69b1ce7696670a09835cc7cc173bd03 (patch)
treeadaf17bbb0345abe47448ef10635fc8f5eac5861 /CommandLineInterface.cpp
parent245fba5055776885501ad46827ad680651248823 (diff)
downloaddexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar.gz
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar.bz2
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar.lz
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar.xz
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.tar.zst
dexon-solidity-d0f02c28c69b1ce7696670a09835cc7cc173bd03.zip
Preparing the ground for AST outputing to JSON
Diffstat (limited to 'CommandLineInterface.cpp')
-rw-r--r--CommandLineInterface.cpp62
1 files changed, 53 insertions, 9 deletions
diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp
index 8c5192ab..7be27297 100644
--- a/CommandLineInterface.cpp
+++ b/CommandLineInterface.cpp
@@ -36,6 +36,7 @@
#include <libsolidity/Scanner.h>
#include <libsolidity/Parser.h>
#include <libsolidity/ASTPrinter.h>
+#include <libsolidity/ASTJsonConverter.h>
#include <libsolidity/NameAndTypeResolver.h>
#include <libsolidity/Exceptions.h>
#include <libsolidity/CompilerStack.h>
@@ -55,6 +56,7 @@ static string const g_argAbiStr = "json-abi";
static string const g_argSolAbiStr = "sol-abi";
static string const g_argAsmStr = "asm";
static string const g_argAstStr = "ast";
+static string const g_argAstJson = "ast-json";
static string const g_argBinaryStr = "binary";
static string const g_argOpcodesStr = "opcodes";
static string const g_argNatspecDevStr = "natspec-dev";
@@ -75,9 +77,10 @@ static inline bool argToStdout(po::variables_map const& _args, string const& _na
static bool needStdout(po::variables_map const& _args)
{
+
return
argToStdout(_args, g_argAbiStr) || argToStdout(_args, g_argSolAbiStr) ||
- argToStdout(_args, g_argNatspecUserStr) ||
+ argToStdout(_args, g_argNatspecUserStr) || argToStdout(_args, g_argAstJson) ||
argToStdout(_args, g_argNatspecDevStr) || argToStdout(_args, g_argAsmStr) ||
argToStdout(_args, g_argOpcodesStr) || argToStdout(_args, g_argBinaryStr);
}
@@ -215,6 +218,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
("input-file", po::value<vector<string>>(), "input file")
(g_argAstStr.c_str(), po::value<OutputType>(),
"Request to output the AST of the contract. " OUTPUT_TYPE_STR)
+ (g_argAstJson.c_str(), po::value<OutputType>(),
+ "Request to output the AST of the contract in JSON format. " OUTPUT_TYPE_STR)
(g_argAsmStr.c_str(), po::value<OutputType>(),
"Request to output the EVM assembly of the contract. " OUTPUT_TYPE_STR)
(g_argOpcodesStr.c_str(), po::value<OutputType>(),
@@ -339,20 +344,44 @@ bool CommandLineInterface::processInput()
return true;
}
-void CommandLineInterface::actOnInput()
+void CommandLineInterface::handleAst(std::string const& _argStr)
{
+ std::string title;
+ std::string suffix;
+
+ if (_argStr == g_argAstStr)
+ {
+ title = "Syntax trees:";
+ suffix = ".ast";
+ }
+ else if (_argStr == g_argAstJson)
+ {
+ title = "JSON AST:";
+ suffix = ".json";
+ }
+ else
+ BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal argStr for AST"));
+
// do we need AST output?
- if (m_args.count(g_argAstStr))
+ if (m_args.count(_argStr))
{
- auto choice = m_args[g_argAstStr].as<OutputType>();
+ auto choice = m_args[_argStr].as<OutputType>();
if (outputToStdout(choice))
{
- cout << "Syntax trees:" << endl << endl;
+ cout << title << endl << endl;
for (auto const& sourceCode: m_sourceCodes)
{
cout << endl << "======= " << sourceCode.first << " =======" << endl;
- ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
- printer.print(cout);
+ if (_argStr == g_argAstStr)
+ {
+ ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
+ printer.print(cout);
+ }
+ else
+ {
+ ASTJsonConverter converter(m_compiler.getAST(sourceCode.first));
+ converter.print(cout);
+ }
}
}
@@ -362,12 +391,27 @@ void CommandLineInterface::actOnInput()
{
boost::filesystem::path p(sourceCode.first);
ofstream outFile(p.stem().string() + ".ast");
- ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
- printer.print(outFile);
+ if (_argStr == g_argAstStr)
+ {
+ ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
+ printer.print(outFile);
+ }
+ else
+ {
+ ASTJsonConverter converter(m_compiler.getAST(sourceCode.first));
+ converter.print(outFile);
+ }
outFile.close();
}
}
}
+}
+
+void CommandLineInterface::actOnInput()
+{
+ // do we need AST output?
+ handleAst(g_argAstStr);
+ handleAst(g_argAstJson);
vector<string> contracts = m_compiler.getContractNames();
for (string const& contract: contracts)