summaryrefslogtreecommitdiff
path: root/cpp/src/slice2freezej/Main.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2009-01-28 06:55:36 +1000
committerMichi Henning <michi@zeroc.com>2009-01-28 06:55:36 +1000
commit09b4a1830989b33d06e7a421dbf197d2aa335b91 (patch)
tree61a84913028a1d08a3dfa83f5b519ccda3fd1e9b /cpp/src/slice2freezej/Main.cpp
parenthttp://bugzilla/bugzilla/show_bug.cgi?id=3483 - Move Freeze to separate Jar file (diff)
parentSquashed commit of the following: (diff)
downloadice-09b4a1830989b33d06e7a421dbf197d2aa335b91.tar.bz2
ice-09b4a1830989b33d06e7a421dbf197d2aa335b91.tar.xz
ice-09b4a1830989b33d06e7a421dbf197d2aa335b91.zip
Merge branch 'R3_3_branch'
Diffstat (limited to 'cpp/src/slice2freezej/Main.cpp')
-rw-r--r--cpp/src/slice2freezej/Main.cpp155
1 files changed, 94 insertions, 61 deletions
diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp
index a0155a74ce8..2ab8c36f86f 100644
--- a/cpp/src/slice2freezej/Main.cpp
+++ b/cpp/src/slice2freezej/Main.cpp
@@ -12,6 +12,7 @@
#include <IceUtil/CtrlCHandler.h>
#include <IceUtil/StaticMutex.h>
#include <Slice/Preprocessor.h>
+#include <Slice/FileTracker.h>
#include <Slice/JavaUtil.h>
#ifdef __BCPLUSPLUS__
@@ -73,15 +74,15 @@ public:
FreezeGenerator(const string&, const string&);
virtual ~FreezeGenerator();
- bool generate(UnitPtr&, const Dict&);
+ void generate(UnitPtr&, const Dict&);
- bool generate(UnitPtr&, const Index&);
+ void generate(UnitPtr&, const Index&);
private:
string varToObject(const TypePtr&, const string&);
string objectToVar(const TypePtr&, const string&);
- string _prog;
+ const string _prog;
};
FreezeGenerator::FreezeGenerator(const string& prog, const string& dir)
@@ -204,7 +205,7 @@ FreezeGenerator::objectToVar(const TypePtr& type, const string& param)
return result;
}
-bool
+void
FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
{
static const char* builtinTable[] =
@@ -236,16 +237,18 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
TypeList keyTypes = u->lookupType(dict.key, false);
if(keyTypes.empty())
{
- cerr << _prog << ": `" << dict.key << "' is not a valid type" << endl;
- return false;
+ ostringstream os;
+ os << "`" << dict.key << "' is not a valid type" << endl;
+ throw os.str();
}
TypePtr keyType = keyTypes.front();
TypeList valueTypes = u->lookupType(dict.value, false);
if(valueTypes.empty())
{
- cerr << _prog << ": `" << dict.value << "' is not a valid type" << endl;
- return false;
+ ostringstream os;
+ os << "`" << dict.value << "' is not a valid type" << endl;
+ throw os.str();
}
TypePtr valueType = valueTypes.front();
@@ -263,15 +266,17 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
{
if(dict.indices.size() > 1)
{
- cerr << _prog << ": bad index for dictionary `" << dict.name << "'" << endl;
- return false;
+ ostringstream os;
+ os << "bad index for dictionary `" << dict.name << "'" << endl;
+ throw os.str();
}
bool containsSequence = false;
if(!Dictionary::legalKeyType(valueType, containsSequence))
{
- cerr << _prog << ": `" << dict.value << "' is not a valid index type" << endl;
- return false;
+ ostringstream os;
+ os << "`" << dict.value << "' is not a valid index type" << endl;
+ throw os.str();
}
if(containsSequence)
{
@@ -288,8 +293,9 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
if(builtInType == 0 || builtInType->kind() != Builtin::KindString)
{
- cerr << _prog << ": VALUE is a `" << dict.value << "', not a string " << endl;
- return false;
+ ostringstream os;
+ os << "VALUE is a `" << dict.value << "', not a string " << endl;
+ throw os.str();
}
}
indexTypes.push_back(valueType);
@@ -311,8 +317,9 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
StructPtr structDecl = StructPtr::dynamicCast(valueType);
if(structDecl == 0)
{
- cerr << _prog << ": `" << dict.value << "' is neither a class nor a struct." << endl;
- return false;
+ ostringstream os;
+ os << "`" << dict.value << "' is neither a class nor a struct." << endl;
+ throw os.str();
}
dataMembers = structDecl->dataMembers();
}
@@ -331,9 +338,10 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
if(dataMember == 0)
{
- cerr << _prog << ": The value of `" << dict.name
- << "' has no data member named `" << index.member << "'" << endl;
- return false;
+ ostringstream os;
+ os << "The value of `" << dict.name
+ << "' has no data member named `" << index.member << "'" << endl;
+ throw os.str();
}
TypePtr dataMemberType = dataMember->type();
@@ -341,8 +349,9 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
bool containsSequence = false;
if(!Dictionary::legalKeyType(dataMemberType, containsSequence))
{
- cerr << _prog << ": `" << index.member << "' cannot be used as an index" << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.member << "' cannot be used as an index" << endl;
+ throw os.str();
}
if(containsSequence)
{
@@ -357,8 +366,9 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
BuiltinPtr memberType = BuiltinPtr::dynamicCast(dataMemberType);
if(memberType == 0 || memberType->kind() != Builtin::KindString)
{
- cerr << _prog << ": `" << index.member << "' is not a string " << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.member << "' is not a string " << endl;
+ throw os.str();
}
}
indexTypes.push_back(dataMemberType);
@@ -370,12 +380,7 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
}
}
-
- if(!open(dict.name))
- {
- cerr << _prog << ": unable to open class " << dict.name << endl;
- return false;
- }
+ open(dict.name);
Output& out = output();
@@ -939,13 +944,10 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
out << eb;
-
close();
-
- return true;
}
-bool
+void
FreezeGenerator::generate(UnitPtr& u, const Index& index)
{
string name;
@@ -962,16 +964,18 @@ FreezeGenerator::generate(UnitPtr& u, const Index& index)
TypeList types = u->lookupType(index.type, false);
if(types.empty())
{
- cerr << _prog << ": `" << index.type << "' is not a valid type" << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.type << "' is not a valid type" << endl;
+ throw os.str();
}
TypePtr type = types.front();
ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type);
if(classDecl == 0)
{
- cerr << _prog << ": `" << index.type << "' is not a class" << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.type << "' is not a class" << endl;
+ throw os.str();
}
DataMemberList dataMembers = classDecl->definition()->allDataMembers();
@@ -991,8 +995,9 @@ FreezeGenerator::generate(UnitPtr& u, const Index& index)
if(dataMember == 0)
{
- cerr << _prog << ": `" << index.type << "' has no data member named `" << index.member << "'" << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.type << "' has no data member named `" << index.member << "'" << endl;
+ throw os.str();
}
if(index.caseSensitive == false)
@@ -1003,18 +1008,15 @@ FreezeGenerator::generate(UnitPtr& u, const Index& index)
BuiltinPtr memberType = BuiltinPtr::dynamicCast(dataMember->type());
if(memberType == 0 || memberType->kind() != Builtin::KindString)
{
- cerr << _prog << ": `" << index.member << "'is not a string " << endl;
- return false;
+ ostringstream os;
+ os << "`" << index.member << "'is not a string " << endl;
+ throw os.str();
}
}
string memberTypeString = typeToString(dataMember->type(), TypeModeIn);
- if(!open(index.name))
- {
- cerr << _prog << ": unable to open class " << index.name << endl;
- return false;
- }
+ open(index.name);
Output& out = output();
@@ -1096,11 +1098,8 @@ FreezeGenerator::generate(UnitPtr& u, const Index& index)
out << eb;
close();
-
- return true;
}
-
void
usage(const char* n)
{
@@ -1184,7 +1183,7 @@ main(int argc, char* argv[])
if(opts.isSet("version"))
{
- cout << ICE_STRING_VERSION << endl;
+ cerr << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
@@ -1441,7 +1440,10 @@ main(int argc, char* argv[])
if(depend)
{
Preprocessor icecpp(argv[0], args[idx], cppArgs);
- icecpp.printMakefileDependencies(Preprocessor::Java, includePaths);
+ if(!icecpp.printMakefileDependencies(Preprocessor::Java, includePaths))
+ {
+ return EXIT_FAILURE;
+ }
}
else
{
@@ -1507,14 +1509,29 @@ main(int argc, char* argv[])
{
try
{
- if(!gen.generate(u, *p))
- {
- u->destroy();
- return EXIT_FAILURE;
- }
+ gen.generate(u, *p);
+ }
+ catch(const string& ex)
+ {
+ // If a file could not be created, then cleanup any
+ // created files.
+ FileTracker::instance()->cleanup();
+ u->destroy();
+ cerr << argv[0] << ": " << ex << endl;
+ return EXIT_FAILURE;
+ }
+ catch(const Slice::FileException& ex)
+ {
+ // If a file could not be created, then cleanup any
+ // created files.
+ FileTracker::instance()->cleanup();
+ u->destroy();
+ cerr << ex.reason() << endl;
+ return EXIT_FAILURE;
}
catch(...)
{
+ FileTracker::instance()->cleanup();
cerr << argv[0] << ": unknown exception" << endl;
u->destroy();
return EXIT_FAILURE;
@@ -1525,15 +1542,30 @@ main(int argc, char* argv[])
{
try
{
- if(!gen.generate(u, *q))
- {
- u->destroy();
- return EXIT_FAILURE;
- }
+ gen.generate(u, *q);
+ }
+ catch(const string& ex)
+ {
+ // If a file could not be created, then cleanup any
+ // created files.
+ FileTracker::instance()->cleanup();
+ u->destroy();
+ cerr << argv[0] << ": " << ex << endl;
+ return EXIT_FAILURE;
+ }
+ 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;
}
catch(...)
{
cerr << argv[0] << ": unknown exception" << endl;
+ FileTracker::instance()->cleanup();
u->destroy();
return EXIT_FAILURE;
}
@@ -1548,6 +1580,7 @@ main(int argc, char* argv[])
if(_interrupted)
{
+ FileTracker::instance()->cleanup();
return EXIT_FAILURE;
}
}