summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2001-10-08 23:00:04 +0000
committerMarc Laukien <marc@zeroc.com>2001-10-08 23:00:04 +0000
commitb6d77023ad984fb88e01f2c4a12a30827a28c1c7 (patch)
tree31cb6ffb9787430b76262e5a73776c2eb52ba03b /cpp/src/slice2cpp
parentIce::Object now inherits virtually from IceUtil::Shared in order to allow (diff)
downloadice-b6d77023ad984fb88e01f2c4a12a30827a28c1c7.tar.bz2
ice-b6d77023ad984fb88e01f2c4a12a30827a28c1c7.tar.xz
ice-b6d77023ad984fb88e01f2c4a12a30827a28c1c7.zip
moved generic C++ stuff to Slice library
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/.depend3
-rw-r--r--cpp/src/slice2cpp/Gen.cpp99
-rw-r--r--cpp/src/slice2cpp/Gen.h3
-rw-r--r--cpp/src/slice2cpp/GenUtil.cpp373
-rw-r--r--cpp/src/slice2cpp/GenUtil.h33
-rw-r--r--cpp/src/slice2cpp/Makefile1
-rw-r--r--cpp/src/slice2cpp/slice2cpp.dsp8
7 files changed, 9 insertions, 511 deletions
diff --git a/cpp/src/slice2cpp/.depend b/cpp/src/slice2cpp/.depend
index e0fdaed0133..4b2269bc434 100644
--- a/cpp/src/slice2cpp/.depend
+++ b/cpp/src/slice2cpp/.depend
@@ -1,3 +1,2 @@
-Gen.o: Gen.cpp ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h Gen.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/Slice/OutputUtil.h GenUtil.h
-GenUtil.o: GenUtil.cpp GenUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Slice/OutputUtil.h
+Gen.o: Gen.cpp ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Slice/CPlusPlusUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/Slice/OutputUtil.h Gen.h
Main.o: Main.cpp Gen.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Slice/OutputUtil.h
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 28f0f1dbc2f..ef56592422f 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -9,28 +9,13 @@
// **********************************************************************
#include <IceUtil/Functional.h>
+#include <Slice/CPlusPlusUtil.h>
#include <Gen.h>
-#include <GenUtil.h>
#include <limits>
using namespace std;
using namespace Slice;
-struct ToIfdef
-{
- char operator()(char c)
- {
- if (!isalnum(c))
- {
- return '_';
- }
- else
- {
- return c;
- }
- }
-};
-
Slice::Gen::Gen(const string& name, const string& base, const string& include, const vector<string>& includePaths,
const string& dllExport, const string& dir) :
_base(base),
@@ -38,11 +23,6 @@ Slice::Gen::Gen(const string& name, const string& base, const string& include, c
_includePaths(includePaths),
_dllExport(dllExport)
{
- if (_dllExport.size())
- {
- _dllExport += " ";
- }
-
for (vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
{
if (p->length() && (*p)[p->length() - 1] != '/')
@@ -81,6 +61,8 @@ Slice::Gen::Gen(const string& name, const string& base, const string& include, c
printHeader(H);
printHeader(C);
+ H << "\n// Generated from file `" << changeInclude(_base, _includePaths) << ".ice'\n";
+ C << "\n// Generated from file `" << changeInclude(_base, _includePaths) << ".ice'\n";
string s = fileH;
if (_include.size())
@@ -137,35 +119,16 @@ Slice::Gen::generate(const UnitPtr& unit)
StringList includes = unit->includeFiles();
for (StringList::const_iterator q = includes.begin(); q != includes.end(); ++q)
{
- H << "\n#include <" << changeInclude(*q) << ".h>";
+ H << "\n#include <" << changeInclude(*q, _includePaths) << ".h>";
}
- H << sp;
- H << "\n#ifndef ICE_IGNORE_VERSION";
- H << "\n# if ICE_INT_VERSION != 0x" << hex << ICE_INT_VERSION;
- H << "\n# error Ice version mismatch!";
- H << "\n# endif";
- H << "\n#endif";
-
- C << sp;
- C << "\n#ifndef ICE_IGNORE_VERSION";
- C << "\n# if ICE_INT_VERSION != 0x" << hex << ICE_INT_VERSION;
- C << "\n# error Ice version mismatch!";
- C << "\n# endif";
- C << "\n#endif";
+ printVersionCheck(H);
+ printVersionCheck(C);
+ printDllExportStuff(H, _dllExport);
if (_dllExport.size())
{
- H << sp;
- H << "\n#ifdef WIN32";
- H << "\n# ifdef " << _dllExport.substr(0, _dllExport.size() - 1) << "_EXPORTS";
- H << "\n# define " << _dllExport << "__declspec(dllexport)";
- H << "\n# else";
- H << "\n# define " << _dllExport << "__declspec(dllimport)";
- H << "\n# endif";
- H << "\n#else";
- H << "\n# define " << _dllExport << "/**/";
- H << "\n#endif";
+ _dllExport += " ";
}
ProxyDeclVisitor proxyDeclVisitor(H, C, _dllExport);
@@ -199,52 +162,6 @@ Slice::Gen::generate(const UnitPtr& unit)
unit->visit(&objectVisitor);
}
-string
-Slice::Gen::changeInclude(const string& orig)
-{
- string file = orig;
- for (vector<string>::const_iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
- {
- if (orig.compare(0, p->length(), *p) == 0)
- {
- string s = orig.substr(p->length());
- if (s.size() < file.size())
- {
- file = s;
- }
- }
- }
-
- string::size_type pos = file.rfind('.');
- if (pos != string::npos)
- {
- file.erase(pos);
- }
-
- return file;
-}
-
-void
-Slice::Gen::printHeader(Output& out)
-{
- static const char* header =
-"// **********************************************************************\n"
-"//\n"
-"// Copyright (c) 2001\n"
-"// MutableRealms, Inc.\n"
-"// Huntsville, AL, USA\n"
-"//\n"
-"// All Rights Reserved\n"
-"//\n"
-"// **********************************************************************\n"
- ;
-
- out << header;
- out << "\n// Generated from file `" << changeInclude(_base) << ".ice'";
- out << "\n// Ice version " << ICE_STRING_VERSION;
- out << '\n';
-}
-
Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) :
H(h), C(c), _dllExport(dllExport)
{
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 8972d2f60f9..024f202a12e 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -35,9 +35,6 @@ public:
private:
- std::string changeInclude(const std::string&);
- void printHeader(Output&);
-
Output H;
Output C;
diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp
deleted file mode 100644
index bac1dcc146c..00000000000
--- a/cpp/src/slice2cpp/GenUtil.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2001
-// MutableRealms, Inc.
-// Huntsville, AL, USA
-//
-// All Rights Reserved
-//
-// **********************************************************************
-
-#include <GenUtil.h>
-
-using namespace std;
-using namespace Slice;
-
-string
-Slice::typeToString(const TypePtr& type)
-{
- static const char* builtinTable[] =
- {
- "::Ice::Byte",
- "bool",
- "::Ice::Short",
- "::Ice::Int",
- "::Ice::Long",
- "::Ice::Float",
- "::Ice::Double",
- "::std::string",
- "::std::wstring",
- "::Ice::ObjectPtr",
- "::Ice::ObjectPrx",
- "::Ice::LocalObjectPtr"
- };
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- return builtinTable[builtin->kind()];
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- return cl->scoped() + "Ptr";
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- if (proxy)
- {
- return proxy->_class()->scoped() + "Prx";
- }
-
- ContainedPtr contained = ContainedPtr::dynamicCast(type);
- if (contained)
- {
- return contained->scoped();
- }
-
- return "???";
-}
-
-string
-Slice::returnTypeToString(const TypePtr& type)
-{
- if (!type)
- {
- return "void";
- }
-
- return typeToString(type);
-}
-
-string
-Slice::inputTypeToString(const TypePtr& type)
-{
- static const char* inputBuiltinTable[] =
- {
- "::Ice::Byte",
- "bool",
- "::Ice::Short",
- "::Ice::Int",
- "::Ice::Long",
- "::Ice::Float",
- "::Ice::Double",
- "const ::std::string&",
- "const ::std::wstring&",
- "const ::Ice::ObjectPtr&",
- "const ::Ice::ObjectPrx&",
- "const ::Ice::LocalObjectPtr&"
- };
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- return inputBuiltinTable[builtin->kind()];
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- return "const " + cl->scoped() + "Ptr&";
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- if (proxy)
- {
- return "const " + proxy->_class()->scoped() + "Prx&";
- }
-
- EnumPtr en = EnumPtr::dynamicCast(type);
- if (en)
- {
- return en->scoped();
- }
-
- NativePtr native = NativePtr::dynamicCast(type);
- if (native)
- {
- return native->scoped();
- }
-
- ContainedPtr contained = ContainedPtr::dynamicCast(type);
- if (contained)
- {
- return "const " + contained->scoped() + "&";
- }
-
- return "???";
-}
-
-string
-Slice::outputTypeToString(const TypePtr& type)
-{
- static const char* outputBuiltinTable[] =
- {
- "::Ice::Byte&",
- "bool&",
- "::Ice::Short&",
- "::Ice::Int&",
- "::Ice::Long&",
- "::Ice::Float&",
- "::Ice::Double&",
- "::std::string&",
- "::std::wstring&",
- "::Ice::ObjectPtr&",
- "::Ice::ObjectPrx&",
- "::Ice::LocalObjectPtr&"
- };
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- return outputBuiltinTable[builtin->kind()];
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- return cl->scoped() + "Ptr&";
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- if (proxy)
- {
- return proxy->_class()->scoped() + "Prx&";
- }
-
- NativePtr native = NativePtr::dynamicCast(type);
- if (native)
- {
- return native->scoped();
- }
-
- ContainedPtr contained = ContainedPtr::dynamicCast(type);
- if (contained)
- {
- return contained->scoped() + "&";
- }
-
- return "???";
-}
-
-string
-Slice::exceptionTypeToString(const TypePtr& type)
-{
- static const char* inputBuiltinTable[] =
- {
- "::Ice::Byte",
- "bool",
- "::Ice::Short",
- "::Ice::Int",
- "::Ice::Long",
- "::Ice::Float",
- "::Ice::Double",
- "const ::std::string&",
- "const ::std::wstring&",
- "const ::Ice::ObjectPtrE&",
- "const ::Ice::ObjectPrxE&",
- "const ::Ice::LocalObjectPtrE&"
- };
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- return inputBuiltinTable[builtin->kind()];
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- return "const " + cl->scoped() + "PtrE&";
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- if (proxy)
- {
- return "const " + proxy->_class()->scoped() + "PrxE&";
- }
-
- EnumPtr en = EnumPtr::dynamicCast(type);
- if (en)
- {
- return en->scoped();
- }
-
- NativePtr native = NativePtr::dynamicCast(type);
- if (native)
- {
- return native->scoped();
- }
-
- ContainedPtr contained = ContainedPtr::dynamicCast(type);
- if (contained)
- {
- return "const " + contained->scoped() + "&";
- }
-
- return "???";
-}
-
-void
-Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& param, bool marshal)
-{
- const char* func = marshal ? "write(" : "read(";
- const char* stream = marshal ? "__os" : "__is";
-
- if (BuiltinPtr::dynamicCast(type))
- {
- out << nl << stream << "->" << func << param << ");";
- return;
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- out << sb;
- if (marshal)
- {
- out << nl << "::Ice::ObjectPtr __obj = " << param << ';';
- out << nl << stream << "->write(__obj);";
- }
- else
- {
- out << nl << "::Ice::ObjectPtr __obj;";
- out << nl << stream << "->read(__obj, " << cl->scoped() << "::__classIds[0]);";
- out << nl << "if (!__obj)";
- out << sb;
- ClassDefPtr def = cl->definition();
- if (def && !def->isAbstract())
- {
- out << nl << "__obj = new " << cl->scoped() << ";";
- out << nl << "__obj->__read(__is);";
- }
- else
- {
- out << nl << "throw ::Ice::NoServantFactoryException(__FILE__, __LINE__);";
- }
- out << eb;
- out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(__obj);";
- out << nl << "if (!" << param << ')';
- out << sb;
- out << nl << "throw ::Ice::ServantUnmarshalException(__FILE__, __LINE__);";
- out << eb;
- }
- out << eb;
-
- return;
- }
-
- StructPtr st = StructPtr::dynamicCast(type);
- if (st)
- {
- out << nl << param << ".__" << func << stream << ");";
- return;
- }
-
- SequencePtr seq = SequencePtr::dynamicCast(type);
- if (seq)
- {
- if (BuiltinPtr::dynamicCast(seq->type()))
- {
- out << nl << stream << "->" << func << param << ");";
- }
- else
- {
- out << nl << seq->scope() << "__" << func << stream << ", " << param << ", " << seq->scope()
- << "__U__" << seq->name() << "());";
- }
- return;
- }
-
- DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
- if (dict)
- {
- out << nl << dict->scope() << "__" << func << stream << ", " << param << ", " << dict->scope()
- << "__U__" << dict->name() << "());";
- return;
- }
-
- NativePtr native = NativePtr::dynamicCast(type);
- assert(!native); // TODO
-
- ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
- if (!constructed)
- {
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- assert(proxy);
- constructed = proxy->_class();
- }
-
- out << nl << constructed->scope() << "__" << func << stream << ", " << param << ");";
-}
-
-void
-Slice::writeMarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret)
-{
- for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p)
- {
- writeMarshalUnmarshalCode(out, p->first, p->second, true);
- }
- if (ret)
- {
- writeMarshalUnmarshalCode(out, ret, "__ret", true);
- }
-}
-
-void
-Slice::writeUnmarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret)
-{
- for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p)
- {
- writeMarshalUnmarshalCode(out, p->first, p->second, false);
- }
- if (ret)
- {
- writeMarshalUnmarshalCode(out, ret, "__ret", false);
- }
-}
-
-void
-Slice::writeAllocateCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret)
-{
- list<pair<TypePtr, string> > ps = params;
- if (ret)
- {
- ps.push_back(make_pair(ret, string("__ret")));
- }
-
- for (list<pair<TypePtr, string> >::const_iterator p = ps.begin(); p != ps.end(); ++p)
- {
- out << nl << typeToString(p->first) << ' ' << p->second << ';';
- }
-}
diff --git a/cpp/src/slice2cpp/GenUtil.h b/cpp/src/slice2cpp/GenUtil.h
deleted file mode 100644
index 0959c4eef80..00000000000
--- a/cpp/src/slice2cpp/GenUtil.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2001
-// MutableRealms, Inc.
-// Huntsville, AL, USA
-//
-// All Rights Reserved
-//
-// **********************************************************************
-
-#ifndef GEN_UTIL_H
-#define GEN_UTIL_H
-
-#include <Slice/Parser.h>
-#include <Slice/OutputUtil.h>
-
-namespace Slice
-{
-
-std::string typeToString(const TypePtr&);
-std::string returnTypeToString(const TypePtr&);
-std::string inputTypeToString(const TypePtr&);
-std::string outputTypeToString(const TypePtr&);
-std::string exceptionTypeToString(const TypePtr&);
-
-void writeMarshalUnmarshalCode(Output&, const TypePtr&, const std::string&, bool);
-void writeMarshalCode(Output&, const std::list<std::pair<TypePtr, std::string> >&, const TypePtr&);
-void writeUnmarshalCode(Output&, const std::list<std::pair<TypePtr, std::string> >&, const TypePtr&);
-void writeAllocateCode(Output&, const std::list<std::pair<TypePtr, std::string> >&, const TypePtr&);
-
-}
-
-#endif
diff --git a/cpp/src/slice2cpp/Makefile b/cpp/src/slice2cpp/Makefile
index b74e28f90b6..423aa9fed07 100644
--- a/cpp/src/slice2cpp/Makefile
+++ b/cpp/src/slice2cpp/Makefile
@@ -15,7 +15,6 @@ NAME = $(top_srcdir)/bin/slice2cpp
TARGETS = $(NAME)
OBJS = Gen.o \
- GenUtil.o \
Main.o
SRCS = $(OBJS:.o=.cpp)
diff --git a/cpp/src/slice2cpp/slice2cpp.dsp b/cpp/src/slice2cpp/slice2cpp.dsp
index 93dd144ebcb..23790b1ea0f 100644
--- a/cpp/src/slice2cpp/slice2cpp.dsp
+++ b/cpp/src/slice2cpp/slice2cpp.dsp
@@ -93,10 +93,6 @@ SOURCE=.\Gen.cpp
# End Source File
# Begin Source File
-SOURCE=.\GenUtil.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\Main.cpp
# End Source File
# End Group
@@ -107,10 +103,6 @@ SOURCE=.\Main.cpp
SOURCE=.\Gen.h
# End Source File
-# Begin Source File
-
-SOURCE=.\GenUtil.h
-# End Source File
# End Group
# Begin Group "Resource Files"