summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2002-01-25 14:48:39 +0000
committerMatthew Newhook <matthew@zeroc.com>2002-01-25 14:48:39 +0000
commit8d2ec3bcb23c04c3899a2516cb05a699b0db393a (patch)
tree133eba1ae126c1f405f9627cceadbcacf05ce59f /cpp/src
parentfixes (diff)
downloadice-8d2ec3bcb23c04c3899a2516cb05a699b0db393a.tar.bz2
ice-8d2ec3bcb23c04c3899a2516cb05a699b0db393a.tar.xz
ice-8d2ec3bcb23c04c3899a2516cb05a699b0db393a.zip
Initial version of slice2wsdl.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/slice2wsdl/.depend2
-rw-r--r--cpp/src/slice2wsdl/Gen.cpp326
-rw-r--r--cpp/src/slice2wsdl/Gen.h61
-rw-r--r--cpp/src/slice2wsdl/Main.cpp222
-rw-r--r--cpp/src/slice2wsdl/Makefile31
-rw-r--r--cpp/src/slice2xsd/Gen.cpp20
-rw-r--r--cpp/src/slice2xsd/Main.cpp6
-rw-r--r--cpp/src/slice2xsd/ice.xsd4
8 files changed, 649 insertions, 23 deletions
diff --git a/cpp/src/slice2wsdl/.depend b/cpp/src/slice2wsdl/.depend
new file mode 100644
index 00000000000..4b2269bc434
--- /dev/null
+++ b/cpp/src/slice2wsdl/.depend
@@ -0,0 +1,2 @@
+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/slice2wsdl/Gen.cpp b/cpp/src/slice2wsdl/Gen.cpp
new file mode 100644
index 00000000000..e35dbb2b1c3
--- /dev/null
+++ b/cpp/src/slice2wsdl/Gen.cpp
@@ -0,0 +1,326 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <IceUtil/Functional.h>
+
+#include <Slice/CPlusPlusUtil.h> // TODO: ???
+#include <Gen.h>
+
+using namespace std;
+using namespace Slice;
+
+static const string internalId = "_internal.";
+
+Slice::Gen::Gen(const string& name, const string& base, const string& include,
+ const vector<string>& includePaths, const string& dir,
+ const ClassDefPtr& classDef) :
+ _base(base),
+ _include(include),
+ _includePaths(includePaths),
+ _classDef(classDef)
+{
+ _orgName = "http://www.noorg.org"; // TODO: argument!
+ for (vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
+ {
+ if (p->length() && (*p)[p->length() - 1] != '/')
+ {
+ *p += '/';
+ }
+ }
+
+ string::size_type pos = _base.rfind('/');
+ if (pos != string::npos)
+ {
+ _base.erase(0, pos + 1);
+ }
+
+ string fileO = _base + ".wsdl";
+ if (!dir.empty())
+ {
+ fileO = dir + '/' + fileO;
+ }
+
+ O.open(fileO.c_str());
+ if (!O)
+ {
+ cerr << name << ": can't open `" << fileO << "' for writing: " << strerror(errno) << endl;
+ return;
+ }
+
+ printHeader();
+ O << "\n<!-- Generated from file `" << changeInclude(_base, _includePaths) << ".ice' -->\n";
+}
+
+Slice::Gen::~Gen()
+{
+}
+
+bool
+Slice::Gen::operator!() const
+{
+ return !O;
+}
+
+void
+Slice::Gen::generate(const UnitPtr& unit)
+{
+ unit->mergeModules();
+
+ string scopeId = containedToId(_classDef);
+
+ //
+ // TODO: It would be better if start() aligned the attributes
+ // correctly.
+ //
+ ostringstream os;
+ os << "wsdl:definitions name=\"" << scopeId << "\""
+ << "\n xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\""
+ << "\n xmlns:xsd1=\"" << _orgName << "/schemas\""
+ << "\n xmlns:tns=\"" << _orgName << "/definitions\""
+ << "\n targetNamespace=\"" << _orgName << "/definitions\"";
+
+ start(os.str());
+
+ // TODO: schemaLocation?
+ O << sp << nl << "<wsdl:import namespace=\"" << _orgName << "/schemas\" location=\"" << _base << ".xsd\"/>";
+
+
+ OperationList ops = _classDef->allOperations();
+ for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q)
+ {
+ emitMessage(*q);
+ }
+
+ O << sp;
+
+ os.str("");
+ os << "wsdl:portType name=\"" << scopeId << "PortType\"";
+ start(os.str());
+
+ for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q)
+ {
+ emitOperation(*q);
+ }
+
+ end(); // PortType
+
+ end(); // definitions
+
+ O << nl;
+}
+
+void
+Slice::Gen::emitMessage(const OperationPtr& p)
+{
+ O << sp;
+
+ string scopeId = containedToId(p);
+
+ ostringstream os;
+ os << "wsdl:message name=\"input." << p->name() << "\"";
+ start(os.str());
+
+ O << nl << "<wsdl:part name=\"body\" element=\"xsd1:" << scopeId << "request." << p->name() << "\"/>";
+
+ end(); // message
+
+ os.str("");
+ os << "wsdl:message name=\"output." << p->name() << "\"";
+ start(os.str());
+
+ O << nl << "<wsdl:part name=\"body\" element=\"xsd1:" << scopeId << "request." << p->name() << "\"/>";
+
+ end(); // message
+}
+
+void
+Slice::Gen::emitOperation(const OperationPtr& p)
+{
+ string scopeId = containedToId(p);
+
+ ostringstream os;
+ os << "wsdl:operation name=\"" << p->name() << "\"";
+ start(os.str());
+
+ O << nl << "<wsdl:input message=\"tns:input." << p->name() << "\">";
+ O << nl << "<wsdl:output message=\"tns:output." << p->name() << "\">";
+
+ end(); // operation
+}
+
+void
+Slice::Gen::printHeader()
+{
+ static const char* header =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<!--\n"
+"**********************************************************************\n"
+"Copyright (c) 2001\n"
+"MutableRealms, Inc.\n"
+"Huntsville, AL, USA\n"
+"\n"
+"All Rights Reserved\n"
+"\n"
+"Generated by the `slice2wsdl' converter\n"
+"**********************************************************************\n"
+"-->";
+
+ O.zeroIndent();
+ O << header;
+ O << "\n<!-- Ice version " << ICE_STRING_VERSION << " -->";
+ O.restoreIndent();
+}
+
+
+void
+Slice::Gen::start(const std::string& element)
+{
+ O << nl << '<' << element << '>';
+ O.inc();
+
+ string::size_type pos = element.find_first_of(" \t");
+ if (pos == string::npos)
+ {
+ _elementStack.push(element);
+ }
+ else
+ {
+ _elementStack.push(element.substr(0, pos));
+ }
+}
+
+void
+Slice::Gen::end()
+{
+ string element = _elementStack.top();
+ _elementStack.pop();
+
+ O.dec();
+ O << nl << "</" << element << '>';
+}
+
+string
+Slice::Gen::containedToId(const ContainedPtr& contained)
+{
+ assert(contained);
+
+ string scoped = contained->scope();
+ if (scoped[0] == ':')
+ {
+ scoped.erase(0, 2);
+ }
+
+ string id;
+
+ id.reserve(scoped.size());
+
+ for (unsigned int i = 0; i < scoped.size(); ++i)
+ {
+ if (scoped[i] == ':')
+ {
+ id += '.';
+ ++i;
+ }
+ else
+ {
+ id += scoped[i];
+ }
+ }
+
+ return id;
+}
+
+string
+Slice::Gen::toString(const SyntaxTreeBasePtr& p)
+{
+ string tag;
+ string linkend;
+ string s;
+
+ static const char* builtinTable[] =
+ {
+ "xs:byte",
+ "xs:boolean",
+ "xs;short",
+ "xs:int",
+ "xs:long",
+ "xs:float",
+ "xs:double",
+ "xs:string",
+ "ice:_internal.reference", /* Object */
+ "ice:_internal.proxyType", /* Object* */
+ "???" /* LocalObject */
+ };
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p);
+ if (builtin)
+ {
+ s = builtinTable[builtin->kind()];
+ //tag = "type";
+ }
+
+ ProxyPtr proxy = ProxyPtr::dynamicCast(p);
+ if (proxy)
+ {
+ s = "ice:_internal.proxyType";
+ }
+
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p);
+ if (cl)
+ {
+ string scopeId = containedToId(cl);
+ //s = "tns:" + internalId + scopeId + cl->name() + "Type";
+ s = "ice:_internal.reference";
+ }
+
+ ExceptionPtr ex = ExceptionPtr::dynamicCast(p);
+ if (ex)
+ {
+ string scopeId = containedToId(ex);
+ s = "tns:" + internalId + scopeId + ex->name() + "Type";
+ }
+
+ StructPtr st = StructPtr::dynamicCast(p);
+ if (st)
+ {
+ string scopeId = containedToId(st);
+ s = "tns:" + internalId + scopeId + st->name() + "Type";
+ }
+
+ EnumeratorPtr en = EnumeratorPtr::dynamicCast(p);
+ if (en)
+ {
+ string scopeId = containedToId(en);
+ s = "tns:" + internalId + scopeId + en->name() + "Type";
+ }
+
+ SequencePtr sq = SequencePtr::dynamicCast(p);
+ if (sq)
+ {
+ string scopeId = containedToId(sq);
+ s = "tns:" + internalId + scopeId + sq->name() + "Type";
+ }
+
+ DictionaryPtr di = DictionaryPtr::dynamicCast(p);
+ if (di)
+ {
+ string scopeId = containedToId(di);
+ s = "tns:" + internalId + scopeId + di->name() + "Type";
+ }
+
+ EnumPtr em = EnumPtr::dynamicCast(p);
+ if (em)
+ {
+ string scopeId = containedToId(em);
+ s = "tns:" + internalId + scopeId + em->name() + "Type";
+ }
+
+ return s;
+}
diff --git a/cpp/src/slice2wsdl/Gen.h b/cpp/src/slice2wsdl/Gen.h
new file mode 100644
index 00000000000..507f9e86ba1
--- /dev/null
+++ b/cpp/src/slice2wsdl/Gen.h
@@ -0,0 +1,61 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef GEN_H
+#define GEN_H
+
+#include <Slice/Parser.h>
+#include <Slice/OutputUtil.h>
+#include <stack>
+
+namespace Slice
+{
+
+class Gen : public ::IceUtil::noncopyable
+{
+public:
+
+ Gen(const std::string&,
+ const std::string&,
+ const std::string&,
+ const std::vector<std::string>&,
+ const std::string&,
+ const ClassDefPtr&);
+ virtual ~Gen();
+
+ bool operator!() const; // Returns true if there was a constructor error
+
+ void generate(const UnitPtr&);
+
+ void emitMessage(const OperationPtr&);
+ void emitOperation(const OperationPtr&);
+
+private:
+
+ void printHeader();
+ void start(const std::string&);
+ void end();
+
+ std::string containedToId(const ContainedPtr&);
+ std::string toString(const SyntaxTreeBasePtr&);
+
+ Output O;
+
+ std::string _base;
+ std::string _include;
+ std::string _orgName;
+ std::vector<std::string> _includePaths;
+ ClassDefPtr _classDef;
+ std::stack<std::string> _elementStack;
+};
+
+}
+
+#endif
diff --git a/cpp/src/slice2wsdl/Main.cpp b/cpp/src/slice2wsdl/Main.cpp
new file mode 100644
index 00000000000..2efe434b590
--- /dev/null
+++ b/cpp/src/slice2wsdl/Main.cpp
@@ -0,0 +1,222 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Gen.h>
+#include <fstream>
+
+using namespace std;
+using namespace Slice;
+
+void
+usage(const char* n)
+{
+ cerr << "Usage: " << n << " [options] slice-file type-id\n";
+ cerr <<
+ "Options:\n"
+ "-h, --help Show this message.\n"
+ "-v, --version Display the Ice version.\n"
+ "-DNAME Define NAME as 1.\n"
+ "-DNAME=DEF Define NAME as DEF.\n"
+ "-UNAME Remove any definition for NAME.\n"
+ "-IDIR Put DIR in the include file search path.\n"
+ "-d, --debug Print debug messages.\n"
+ ;
+}
+
+int
+main(int argc, char* argv[])
+{
+ string cpp("cpp -C");
+ bool debug = false;
+ string include;
+ string output;
+ vector<string> includePaths;
+
+ int idx = 1;
+ while (idx < argc)
+ {
+ if (strncmp(argv[idx], "-I", 2) == 0)
+ {
+ cpp += ' ';
+ cpp += argv[idx];
+
+ string path = argv[idx] + 2;
+ if (path.length())
+ {
+ includePaths.push_back(path);
+ }
+
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0)
+ {
+ cpp += ' ';
+ cpp += argv[idx];
+
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0)
+ {
+ usage(argv[0]);
+ return EXIT_SUCCESS;
+ }
+ else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0)
+ {
+ cout << ICE_STRING_VERSION << endl;
+ return EXIT_SUCCESS;
+ }
+ else if (strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0)
+ {
+ debug = true;
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strcmp(argv[idx], "--include-dir") == 0)
+ {
+ if (idx + 1 >= argc)
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ include = argv[idx + 1];
+ for (int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
+ else if (strcmp(argv[idx], "--output-dir") == 0)
+ {
+ if (idx + 1 >= argc)
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ output = argv[idx + 1];
+ for (int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
+ else if (argv[idx][0] == '-')
+ {
+ cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+ else
+ {
+ ++idx;
+ }
+ }
+
+ if (argc != 3)
+ {
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ string sourceFile = argv[1];
+ string typeId = argv[2];
+
+ int status = EXIT_SUCCESS;
+
+ string base(sourceFile);
+ string suffix;
+ string::size_type pos = base.rfind('.');
+ if (pos != string::npos)
+ {
+ suffix = base.substr(pos);
+ transform(suffix.begin(), suffix.end(), suffix.begin(), tolower);
+ }
+ if (suffix != ".ice")
+ {
+ cerr << argv[0] << ": input files must end with `.ice'" << endl;
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+ base.erase(pos);
+
+ ifstream test(sourceFile.c_str());
+ if (!test)
+ {
+ cerr << argv[0] << ": can't open `" << sourceFile << "' for reading: " << strerror(errno) << endl;
+ return EXIT_FAILURE;
+ }
+ test.close();
+
+ string cmd = cpp + " " + sourceFile;
+#ifdef WIN32
+ FILE* cppHandle = _popen(cmd.c_str(), "r");
+#else
+ FILE* cppHandle = popen(cmd.c_str(), "r");
+#endif
+ if (cppHandle == 0)
+ {
+ cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl;
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+
+ UnitPtr unit = Unit::createUnit(false, false);
+ int parseStatus = unit->parse(cppHandle, debug);
+
+#ifdef WIN32
+ _pclose(cppHandle);
+#else
+ pclose(cppHandle);
+#endif
+
+ if (parseStatus == EXIT_FAILURE)
+ {
+ status = EXIT_FAILURE;
+ }
+ else
+ {
+ ContainedList contained = unit->findContents(typeId);
+ if (contained.empty() || contained.front()->containedType() != Contained::ContainedTypeClass)
+ {
+ cerr << argv[0] << ": invalid type: " << typeId << endl;
+ status = EXIT_FAILURE;
+ }
+ else
+ {
+ ClassDefPtr p = ClassDefPtr::dynamicCast(contained.front());
+ assert(p);
+ Gen gen(argv[0], base, include, includePaths, output, p);
+ if (!gen)
+ {
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+ gen.generate(unit);
+ }
+ }
+
+ unit->destroy();
+
+ return status;
+}
diff --git a/cpp/src/slice2wsdl/Makefile b/cpp/src/slice2wsdl/Makefile
new file mode 100644
index 00000000000..7cda23c0b47
--- /dev/null
+++ b/cpp/src/slice2wsdl/Makefile
@@ -0,0 +1,31 @@
+# **********************************************************************
+#
+# Copyright (c) 2001
+# MutableRealms, Inc.
+# Huntsville, AL, USA
+#
+# All Rights Reserved
+#
+# **********************************************************************
+
+top_srcdir = ../..
+
+NAME = $(top_srcdir)/bin/slice2wsdl
+
+TARGETS = $(NAME)
+
+OBJS = Gen.o \
+ Main.o
+
+SRCS = $(OBJS:.o=.cpp) \
+ $(VOBJS:.o=.cpp)
+
+include $(top_srcdir)/config/Make.rules
+
+CPPFLAGS := -I. $(CPPFLAGS) -I$(XERCESC_HOME)/include/xercesc
+
+$(NAME): $(OBJS)
+ rm -f $@
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) -lSlice $(BASELIBS)
+
+include .depend
diff --git a/cpp/src/slice2xsd/Gen.cpp b/cpp/src/slice2xsd/Gen.cpp
index e12809989be..0f651884b71 100644
--- a/cpp/src/slice2xsd/Gen.cpp
+++ b/cpp/src/slice2xsd/Gen.cpp
@@ -72,12 +72,6 @@ Slice::Gen::generate(const UnitPtr& unit)
unit->mergeModules();
//
- // I don't want the top-level module to be sorted, therefore no
- // unit->sort() before or after the unit->sortContents().
- //
- //unit->sortContents();
-
- //
// TODO: It would be better if start() aligned the attributes
// correctly.
//
@@ -85,17 +79,13 @@ Slice::Gen::generate(const UnitPtr& unit)
os << "xs:schema"
<< " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
<< "\n elementFormDefault=\"qualified\""
- << "\n xmlns:ice=\"http://www.mutablerealms.com\""
- << "\n xmlns:tns=\""
- << _orgName
- << "\""
- << "\n targetNamespace=\""
- << _orgName
- << "\"";
+ << "\n xmlns:ice=\"http://www.mutablerealms.com/schemas\""
+ << "\n xmlns:tns=\"" << _orgName << "/schemas\""
+ << "\n targetNamespace=\"" << _orgName << "/schemas\"";
start(os.str());
// TODO: schemaLocation?
- O << nl << "<xs:import namespace=\"http://www.mutablerealms.com\" schemaLocation=\"ice.xsd\"/>";
+ O << nl << "<xs:import namespace=\"http://www.mutablerealms.com/schemas\" schemaLocation=\"ice.xsd\"/>";
StringList includes = unit->includeFiles();
for (StringList::const_iterator q = includes.begin(); q != includes.end(); ++q)
@@ -493,8 +483,6 @@ Slice::Gen::visitDictionary(const DictionaryPtr& p)
<< internalId << scopeId << p->name() << "Type\"/>";
}
-/* sequence, dictionary */
-
void
Slice::Gen::printHeader()
{
diff --git a/cpp/src/slice2xsd/Main.cpp b/cpp/src/slice2xsd/Main.cpp
index 281396c423a..43f041d7302 100644
--- a/cpp/src/slice2xsd/Main.cpp
+++ b/cpp/src/slice2xsd/Main.cpp
@@ -17,7 +17,7 @@ using namespace Slice;
void
usage(const char* n)
{
- cerr << "Usage: " << n << " [options] docbook-file slice-files...\n";
+ cerr << "Usage: " << n << " [options] slice-files...\n";
cerr <<
"Options:\n"
"-h, --help Show this message.\n"
@@ -26,10 +26,6 @@ usage(const char* n)
"-DNAME=DEF Define NAME as DEF.\n"
"-UNAME Remove any definition for NAME.\n"
"-IDIR Put DIR in the include file search path.\n"
- "-s, --stand-alone Create stand-alone docbook file.\n"
- "--no-globals Don't document the global module.\n"
- "--chapter Use \"chapter\" instead of \"section\" as\n"
- " top-level element.\n"
"-d, --debug Print debug messages.\n"
;
}
diff --git a/cpp/src/slice2xsd/ice.xsd b/cpp/src/slice2xsd/ice.xsd
index 1ab107f5e7e..ac13b7c0bd8 100644
--- a/cpp/src/slice2xsd/ice.xsd
+++ b/cpp/src/slice2xsd/ice.xsd
@@ -10,8 +10,8 @@ All Rights Reserved
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
- xmlns:tns="http://www.mutablerealms.com"
- targetNamespace="http://www.mutablerealms.com">
+ xmlns:tns="http://www.mutablerealms.com/schemas"
+ targetNamespace="http://www.mutablerealms.com/schemas">
<xs:simpleType name="_internal.proxyType">
<xs:annotation>