summaryrefslogtreecommitdiff
path: root/cpp/src/slice2js
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2js')
-rw-r--r--cpp/src/slice2js/Gen.cpp26
-rw-r--r--cpp/src/slice2js/Gen.h8
-rw-r--r--cpp/src/slice2js/Main.cpp66
3 files changed, 85 insertions, 15 deletions
diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp
index 5f13813a3de..c569568c385 100644
--- a/cpp/src/slice2js/Gen.cpp
+++ b/cpp/src/slice2js/Gen.cpp
@@ -573,7 +573,8 @@ Slice::JsVisitor::writeDocComment(const ContainedPtr& p, const string& deprecate
Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const string& dir, bool icejs) :
_includePaths(includePaths),
- _icejs(icejs)
+ _icejs(icejs),
+ _useStdout(false)
{
_fileBase = base;
string::size_type pos = base.find_last_of("/\\");
@@ -581,13 +582,14 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st
{
_fileBase = base.substr(pos + 1);
}
+
string file = _fileBase + ".js";
if(!dir.empty())
{
file = dir + '/' + file;
}
-
+
_out.open(file.c_str());
if(!_out)
{
@@ -596,14 +598,32 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st
throw FileException(__FILE__, __LINE__, os.str());
}
FileTracker::instance()->addFile(file);
+
+
printHeader();
+ printGeneratedHeader(_out, _fileBase + ".ice");
+}
+Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const string& dir, bool icejs, ostream& out) :
+ _out(out),
+ _includePaths(includePaths),
+ _icejs(icejs),
+ _useStdout(true)
+{
+ _fileBase = base;
+ string::size_type pos = base.find_last_of("/\\");
+ if(pos != string::npos)
+ {
+ _fileBase = base.substr(pos + 1);
+ }
+
+ printHeader();
printGeneratedHeader(_out, _fileBase + ".ice");
}
Slice::Gen::~Gen()
{
- if(_out.isOpen())
+ if(_out.isOpen() || _useStdout)
{
_out << '\n';
}
diff --git a/cpp/src/slice2js/Gen.h b/cpp/src/slice2js/Gen.h
index f982df5ce27..86011de4bc8 100644
--- a/cpp/src/slice2js/Gen.h
+++ b/cpp/src/slice2js/Gen.h
@@ -55,6 +55,12 @@ public:
const std::vector<std::string>&,
const std::string&,
bool);
+
+ Gen(const std::string&,
+ const std::vector<std::string>&,
+ const std::string&,
+ bool,
+ std::ostream&);
~Gen();
void generate(const UnitPtr&);
@@ -62,11 +68,13 @@ public:
private:
+ std::ofstream _stdout;
IceUtilInternal::Output _out;
std::vector<std::string> _includePaths;
std::string _fileBase;
bool _icejs;
+ bool _useStdout;
void printHeader();
diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp
index b09dccb6287..328b8997f60 100644
--- a/cpp/src/slice2js/Main.cpp
+++ b/cpp/src/slice2js/Main.cpp
@@ -66,8 +66,10 @@ usage(const char* n)
"-UNAME Remove any definition for NAME.\n"
"-IDIR Put DIR in the include file search path.\n"
"-E Print preprocessor output on stdout.\n"
+ "--stdout Print genreated code to stdout.\n"
"--output-dir DIR Create files in the directory DIR.\n"
"--depend Generate Makefile dependencies.\n"
+ "--depend-json Generate Makefile dependencies in JSON format.\n"
"-d, --debug Print debug messages.\n"
"--ice Permit `Ice' prefix (for building Ice source code only).\n"
"--underscore Permit underscores in Slice identifiers.\n"
@@ -85,8 +87,10 @@ compile(int argc, char* argv[])
opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
opts.addOpt("E");
+ opts.addOpt("", "stdout");
opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "depend");
+ opts.addOpt("", "depend-json");
opts.addOpt("d", "debug");
opts.addOpt("", "ice");
opts.addOpt("", "underscore");
@@ -137,9 +141,13 @@ compile(int argc, char* argv[])
bool preprocess = opts.isSet("E");
+ bool useStdout = opts.isSet("stdout");
+
string output = opts.optArg("output-dir");
bool depend = opts.isSet("depend");
+
+ bool dependJSON = opts.isSet("depend-json");
bool debug = opts.isSet("debug");
@@ -161,18 +169,27 @@ compile(int argc, char* argv[])
IceUtil::CtrlCHandler ctrlCHandler;
ctrlCHandler.setCallback(interruptedCallback);
+ if(dependJSON)
+ {
+ cout << "{" << endl;
+ }
+
+ //
+ // Create a copy of args without the duplicates.
+ //
+ vector<string> sources;
for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i)
{
- //
- // Ignore duplicates.
- //
- vector<string>::iterator p = find(args.begin(), args.end(), *i);
- if(p != i)
+ vector<string>::iterator p = find(sources.begin(), sources.end(), *i);
+ if(p == sources.end())
{
- continue;
+ sources.push_back(*i);
}
-
- if(depend)
+ }
+
+ for(vector<string>::const_iterator i = sources.begin(); i != sources.end();)
+ {
+ if(depend || dependJSON)
{
PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2JS__");
@@ -190,8 +207,10 @@ compile(int argc, char* argv[])
{
return EXIT_FAILURE;
}
-
- if(!icecpp->printMakefileDependencies(Preprocessor::JS, includePaths,
+
+ bool last = (++i == sources.end());
+
+ if(!icecpp->printMakefileDependencies(depend ? Preprocessor::JavaScript : Preprocessor::JavaScriptJSON, includePaths,
"-D__SLICE2JS__"))
{
return EXIT_FAILURE;
@@ -201,6 +220,15 @@ compile(int argc, char* argv[])
{
return EXIT_FAILURE;
}
+
+ if(dependJSON)
+ {
+ if(!last)
+ {
+ cout << ",";
+ }
+ cout << "\n";
+ }
}
else
{
@@ -245,8 +273,16 @@ compile(int argc, char* argv[])
{
try
{
- Gen gen(icecpp->getBaseName(), includePaths, output, icejs);
- gen.generate(p);
+ if(useStdout)
+ {
+ Gen gen(icecpp->getBaseName(), includePaths, output, icejs, cout);
+ gen.generate(p);
+ }
+ else
+ {
+ Gen gen(icecpp->getBaseName(), includePaths, output, icejs);
+ gen.generate(p);
+ }
}
catch(const Slice::FileException& ex)
{
@@ -262,6 +298,7 @@ compile(int argc, char* argv[])
p->destroy();
}
+ ++i;
}
{
@@ -274,6 +311,11 @@ compile(int argc, char* argv[])
}
}
}
+
+ if(dependJSON)
+ {
+ cout << "}" << endl;
+ }
return status;
}