summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-09-15 18:01:02 +0000
committerMark Spruiell <mes@zeroc.com>2004-09-15 18:01:02 +0000
commitb37dac91b2f47bd401941daf9a031add77c1ba70 (patch)
treedeeffa19e980d8ad4883486749a908b04dd3ca88 /cpp/src/Slice/PythonUtil.cpp
parentcode reorgnization; adding prefixes to generated files (diff)
downloadice-b37dac91b2f47bd401941daf9a031add77c1ba70.tar.bz2
ice-b37dac91b2f47bd401941daf9a031add77c1ba70.tar.xz
ice-b37dac91b2f47bd401941daf9a031add77c1ba70.zip
adding support for prefixes on generated filenames; convert included
filenames into prefixed module names
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp76
1 files changed, 64 insertions, 12 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 4fc7cae2336..ba073b8ada5 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <Slice/PythonUtil.h>
+#include <Slice/Checksum.h>
#include <IceUtil/Functional.h>
using namespace std;
@@ -1361,27 +1362,57 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, list<
}
}
+static string
+changeInclude(const string& orig, const vector<string>& includePaths)
+{
+ string file = orig;
+ replace(file.begin(), file.end(), '\\', '/');
+
+ for(vector<string>::const_iterator p = includePaths.begin(); p != includePaths.end(); ++p)
+ {
+ string includePath = *p;
+ replace(includePath.begin(), includePath.end(), '\\', '/');
+
+ if(orig.compare(0, includePath.length(), *p) == 0)
+ {
+ string s = orig.substr(includePath.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::Python::generate(const UnitPtr& unit, bool all, Output& out)
+Slice::Python::generate(const UnitPtr& unit, bool all, bool checksum, const vector<string>& includePaths, Output& out)
{
out << nl << "import Ice, IcePy";
if(!all)
{
- StringList includes = unit->includeFiles();
- for(StringList::const_iterator p = includes.begin(); p != includes.end(); ++p)
+ vector<string> paths = includePaths;
+ for(vector<string>::iterator p = paths.begin(); p != paths.end(); ++p)
{
- string file = *p;
- string::size_type pos = file.rfind('.');
- if(pos != string::npos)
- {
- file.erase(pos, file.size() - pos);
- }
- pos = file.rfind('/');
- if(pos != string::npos)
+ if(p->length() && (*p)[p->length() - 1] != '/')
{
- file.erase(0, pos + 1);
+ *p += '/';
}
+ }
+
+ StringList includes = unit->includeFiles();
+ for(StringList::const_iterator q = includes.begin(); q != includes.end(); ++q)
+ {
+ string file = changeInclude(*q, paths);
+ replace(file.begin(), file.end(), '/', '_');
out << nl << "import " << file << "_ice";
}
}
@@ -1392,6 +1423,27 @@ Slice::Python::generate(const UnitPtr& unit, bool all, Output& out)
CodeVisitor codeVisitor(out);
unit->visit(&codeVisitor, false);
+ if(checksum)
+ {
+ ChecksumMap checksums = createChecksums(unit);
+ if(!checksums.empty())
+ {
+ out << sp;
+ for(ChecksumMap::const_iterator p = checksums.begin(); p != checksums.end(); ++p)
+ {
+ out << nl << "Ice.sliceChecksums[\"" << p->first << "\"] = \"";
+ ostringstream str;
+ str.flags(ios_base::hex);
+ str.fill('0');
+ for(vector<unsigned char>::const_iterator q = p->second.begin(); q != p->second.end(); ++q)
+ {
+ str << (int)(*q);
+ }
+ out << str.str() << "\"";
+ }
+ }
+ }
+
out << nl; // Trailing newline.
}