summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/.depend4
-rw-r--r--cpp/src/slice2cpp/Gen.cpp97
-rw-r--r--cpp/src/slice2cpp/Gen.h5
-rw-r--r--cpp/src/slice2cpp/Main.cpp54
-rw-r--r--cpp/src/slice2cpp/Makefile2
-rw-r--r--cpp/src/slice2cpp/Makefile.mak2
-rw-r--r--cpp/src/slice2cpp/Slice2Cpp.rc10
7 files changed, 91 insertions, 83 deletions
diff --git a/cpp/src/slice2cpp/.depend b/cpp/src/slice2cpp/.depend
index e17f5043684..3e72263da59 100644
--- a/cpp/src/slice2cpp/.depend
+++ b/cpp/src/slice2cpp/.depend
@@ -1,2 +1,2 @@
-Gen$(OBJEXT): Gen.cpp ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/OutputUtil.h $(includedir)/Slice/CPlusPlusUtil.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Iterator.h $(includedir)/Slice/Checksum.h $(includedir)/Slice/SignalHandler.h
-Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h $(includedir)/Slice/Preprocessor.h $(includedir)/Slice/SignalHandler.h ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/OutputUtil.h
+Gen$(OBJEXT): Gen.cpp ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/OutputUtil.h $(includedir)/Slice/Util.h $(includedir)/Slice/CPlusPlusUtil.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Iterator.h $(includedir)/Slice/Checksum.h
+Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/CtrlCHandler.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Slice/Preprocessor.h ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/OutputUtil.h
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 77e6d834465..d442b2a7586 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1,41 +1,31 @@
// **********************************************************************
//
-// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
+#include <IceUtil/DisableWarnings.h>
#include <Gen.h>
#include <Slice/Util.h>
#include <Slice/CPlusPlusUtil.h>
#include <IceUtil/Functional.h>
#include <IceUtil/Iterator.h>
#include <Slice/Checksum.h>
-#include <Slice/SignalHandler.h>
+#include <Slice/FileTracker.h>
#include <limits>
+
#include <sys/stat.h>
+#include <string.h>
using namespace std;
using namespace Slice;
using namespace IceUtil;
using namespace IceUtilInternal;
-//
-// Callback for Crtl-C signal handling
-//
-static Gen* _gen = 0;
-
-static void closeCallback()
-{
- if(_gen != 0)
- {
- _gen->closeOutput();
- }
-}
-
static string
getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
{
@@ -48,8 +38,8 @@ getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
return deprecateSymbol;
}
-Slice::Gen::Gen(const string& name, const string& base, const string& headerExtension,
- const string& sourceExtension, const vector<string>& extraHeaders, const string& include,
+Slice::Gen::Gen(const string& base, const string& headerExtension, const string& sourceExtension,
+ const vector<string>& extraHeaders, const string& include,
const vector<string>& includePaths, const string& dllExport, const string& dir,
bool imp, bool checksum, bool stream, bool ice) :
_base(base),
@@ -64,9 +54,6 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
_stream(stream),
_ice(ice)
{
- _gen = this;
- SignalHandler::setCallback(closeCallback);
-
for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
{
*p = fullPath(*p);
@@ -87,34 +74,38 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
fileImplH = dir + '/' + fileImplH;
fileImplC = dir + '/' + fileImplC;
}
- SignalHandler::addFile(fileImplH);
- SignalHandler::addFile(fileImplC);
struct stat st;
if(stat(fileImplH.c_str(), &st) == 0)
{
- cerr << name << ": `" << fileImplH << "' already exists - will not overwrite" << endl;
- return;
+ ostringstream os;
+ os << fileImplH << "' already exists - will not overwrite";
+ throw FileException(__FILE__, __LINE__, os.str());
}
if(stat(fileImplC.c_str(), &st) == 0)
{
- cerr << name << ": `" << fileImplC << "' already exists - will not overwrite" << endl;
- return;
+ ostringstream os;
+ os << fileImplC << "' already exists - will not overwrite";
+ throw FileException(__FILE__, __LINE__, os.str());
}
implH.open(fileImplH.c_str());
if(!implH)
{
- cerr << name << ": can't open `" << fileImplH << "' for writing" << endl;
- return;
+ ostringstream os;
+ os << "cannot open `" << fileImplH << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
+ FileTracker::instance()->addFile(fileImplH);
implC.open(fileImplC.c_str());
if(!implC)
{
- cerr << name << ": can't open `" << fileImplC << "' for writing" << endl;
- return;
+ ostringstream os;
+ os << "cannot open `" << fileImplC << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
+ FileTracker::instance()->addFile(fileImplC);
string s = fileImplH;
if(_include.size())
@@ -134,22 +125,24 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
fileH = dir + '/' + fileH;
fileC = dir + '/' + fileC;
}
- SignalHandler::addFile(fileH);
- SignalHandler::addFile(fileC);
H.open(fileH.c_str());
if(!H)
{
- cerr << name << ": can't open `" << fileH << "' for writing" << endl;
- return;
+ ostringstream os;
+ os << "cannot open `" << fileH << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
+ FileTracker::instance()->addFile(fileH);
C.open(fileC.c_str());
if(!C)
{
- cerr << name << ": can't open `" << fileC << "' for writing" << endl;
- return;
+ ostringstream os;
+ os << "cannot open `" << fileC << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
+ FileTracker::instance()->addFile(fileC);
printHeader(H);
printHeader(C);
@@ -177,22 +170,6 @@ Slice::Gen::~Gen()
implH << "\n\n#endif\n";
implC << '\n';
}
-
- SignalHandler::setCallback(0);
-}
-
-bool
-Slice::Gen::operator!() const
-{
- if(!H || !C)
- {
- return true;
- }
- if(_impl && (!implH || !implC))
- {
- return true;
- }
- return false;
}
void
@@ -2647,6 +2624,7 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
}
C << nl << "bool __ok = __og.invoke();";
+ writeAllocateCode(C, ParamDeclList(), ret, p->getMetaData(), _useWstring);
if(!p->returnsData())
{
C << nl << "if(!__og.is()->b.empty())";
@@ -2710,7 +2688,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
C << eb;
C << eb;
- writeAllocateCode(C, ParamDeclList(), ret, p->getMetaData(), _useWstring);
for(ParamDeclList::const_iterator opi = outParams.begin(); opi != outParams.end(); ++opi)
{
StructPtr st = StructPtr::dynamicCast((*opi)->type());
@@ -2720,7 +2697,7 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
}
}
- if(p->returnsData())
+ if(ret || !outParams.empty())
{
C << nl << "::IceInternal::BasicStream* __is = __og.is();";
C << nl << "__is->startReadEncaps();";
@@ -5301,7 +5278,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
C << sb;
if(p->returnsData())
{
- C << nl << "__prx->__checkTwowayOnly(\"" << p->name() << "\");";
+ C << nl << "__prx->__checkTwowayOnly(" << flatName << ");";
}
C << nl << "__prepare(__prx, " << flatName << ", " << operationModeToString(p->sendMode()) << ", __ctx);";
writeMarshalCode(C, inParams, 0, StringList(), true);
@@ -5357,7 +5334,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
C << nl << "return;";
C << eb;
- if(p->returnsData())
+ if(ret || !outParams.empty())
{
C << nl << "__is->startReadEncaps();";
writeUnmarshalCode(C, outParams, 0, StringList(), true);
@@ -5676,7 +5653,7 @@ Slice::Gen::MetaDataVisitor::visitModuleStart(const ModulePtr& p)
{
continue;
}
- cout << file << ": warning: ignoring invalid global metadata `" << s << "'" << endl;
+ cerr << file << ": warning: ignoring invalid global metadata `" << s << "'" << endl;
}
_history.insert(s);
}
@@ -5747,7 +5724,7 @@ Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
if(!cl->isLocal())
{
- cout << p->definitionContext()->filename() << ":" << p->line()
+ cerr << p->definitionContext()->filename() << ":" << p->line()
<< ": warning: metadata directive `UserException' applies only to local operations "
<< "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
<< "' is not local" << endl;
@@ -5766,7 +5743,7 @@ Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
if(q->find("cpp:type:", 0) == 0 || q->find("cpp:array", 0) == 0 || q->find("cpp:range", 0) == 0)
{
- cout << p->definitionContext()->filename() << ":" << p->line()
+ cerr << p->definitionContext()->filename() << ":" << p->line()
<< ": warning: invalid metadata for operation" << endl;
break;
}
@@ -5859,7 +5836,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin
continue;
}
- cout << file << ":" << line << ": warning: ignoring invalid metadata `" << s << "'" << endl;
+ cerr << file << ":" << line << ": warning: ignoring invalid metadata `" << s << "'" << endl;
}
_history.insert(s);
}
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index d30e43cc844..e3c1c9afc01 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -1,6 +1,6 @@
// **********************************************************************
//
-// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
@@ -23,7 +23,6 @@ public:
Gen(const std::string&,
const std::string&,
const std::string&,
- const std::string&,
const std::vector<std::string>&,
const std::string&,
const std::vector<std::string>&,
@@ -35,8 +34,6 @@ public:
bool);
~Gen();
- bool operator!() const; // Returns true if there was a constructor error
-
void generate(const UnitPtr&);
void closeOutput();
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index 0fef7634add..7e2ff8b58b1 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -1,6 +1,6 @@
// **********************************************************************
//
-// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
@@ -8,13 +8,26 @@
// **********************************************************************
#include <IceUtil/Options.h>
+#include <IceUtil/CtrlCHandler.h>
+#include <IceUtil/StaticMutex.h>
#include <Slice/Preprocessor.h>
-#include <Slice/SignalHandler.h>
+#include <Slice/FileTracker.h>
#include <Gen.h>
using namespace std;
using namespace Slice;
+static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER;
+static bool _interrupted = false;
+
+void
+interruptedCallback(int signal)
+{
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ _interrupted = true;
+}
+
void
usage(const char* n)
{
@@ -88,7 +101,7 @@ main(int argc, char* argv[])
if(opts.isSet("version"))
{
- cout << ICE_STRING_VERSION << endl;
+ cerr << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
@@ -149,14 +162,18 @@ main(int argc, char* argv[])
int status = EXIT_SUCCESS;
+ IceUtil::CtrlCHandler ctrlCHandler;
+ ctrlCHandler.setCallback(interruptedCallback);
+
for(i = args.begin(); i != args.end(); ++i)
{
- SignalHandler sigHandler;
-
if(depend)
{
Preprocessor icecpp(argv[0], *i, cppArgs);
- icecpp.printMakefileDependencies(Preprocessor::CPlusPlus, includePaths);
+ if(!icecpp.printMakefileDependencies(Preprocessor::CPlusPlus, includePaths))
+ {
+ return EXIT_FAILURE;
+ }
}
else
{
@@ -200,19 +217,36 @@ main(int argc, char* argv[])
}
else
{
- Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, extraHeaders, include,
- includePaths, dllExport, output, impl, checksum, stream, ice);
- if(!gen)
+ try
+ {
+ Gen gen(icecpp.getBaseName(), headerExtension, sourceExtension, extraHeaders, include,
+ includePaths, dllExport, output, impl, checksum, stream, ice);
+ gen.generate(u);
+ }
+ catch(const Slice::FileException& ex)
{
+ // If a file could not be created, then
+ // cleanup any created files.
+ FileTracker::instance()->cleanup();
u->destroy();
+ cerr << argv[0] << ": " << ex.reason() << endl;
return EXIT_FAILURE;
}
- gen.generate(u);
}
u->destroy();
}
}
+
+ {
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ if(_interrupted)
+ {
+ FileTracker::instance()->cleanup();
+ return EXIT_FAILURE;
+ }
+ }
}
return status;
diff --git a/cpp/src/slice2cpp/Makefile b/cpp/src/slice2cpp/Makefile
index a23b12c84d2..084d2e85b00 100644
--- a/cpp/src/slice2cpp/Makefile
+++ b/cpp/src/slice2cpp/Makefile
@@ -1,6 +1,6 @@
# **********************************************************************
#
-# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
diff --git a/cpp/src/slice2cpp/Makefile.mak b/cpp/src/slice2cpp/Makefile.mak
index fb9a69e62c0..847211d4f52 100644
--- a/cpp/src/slice2cpp/Makefile.mak
+++ b/cpp/src/slice2cpp/Makefile.mak
@@ -1,6 +1,6 @@
# **********************************************************************
#
-# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
diff --git a/cpp/src/slice2cpp/Slice2Cpp.rc b/cpp/src/slice2cpp/Slice2Cpp.rc
index e2259027702..f7fe1cd95b6 100644
--- a/cpp/src/slice2cpp/Slice2Cpp.rc
+++ b/cpp/src/slice2cpp/Slice2Cpp.rc
@@ -1,8 +1,8 @@
#include "winver.h"
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 3,3,0,0
- PRODUCTVERSION 3,3,0,0
+ FILEVERSION 3,3,1,0
+ PRODUCTVERSION 3,3,1,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
@@ -19,12 +19,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "ZeroC, Inc.\0"
VALUE "FileDescription", "Slice To C++ Translator\0"
- VALUE "FileVersion", "3.3.0\0"
+ VALUE "FileVersion", "3.3.1\0"
VALUE "InternalName", "slice2cpp\0"
- VALUE "LegalCopyright", "Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.\0"
+ VALUE "LegalCopyright", "Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.\0"
VALUE "OriginalFilename", "slice2cpp.exe\0"
VALUE "ProductName", "Ice\0"
- VALUE "ProductVersion", "3.3.0\0"
+ VALUE "ProductVersion", "3.3.1\0"
END
END
BLOCK "VarFileInfo"