From b37dac91b2f47bd401941daf9a031add77c1ba70 Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Wed, 15 Sep 2004 18:01:02 +0000 Subject: adding support for prefixes on generated filenames; convert included filenames into prefixed module names --- cpp/src/Slice/PythonUtil.cpp | 76 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 12 deletions(-) (limited to 'cpp/src/Slice/PythonUtil.cpp') 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 +#include #include using namespace std; @@ -1361,27 +1362,57 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, list< } } +static string +changeInclude(const string& orig, const vector& includePaths) +{ + string file = orig; + replace(file.begin(), file.end(), '\\', '/'); + + for(vector::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& 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 paths = includePaths; + for(vector::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::const_iterator q = p->second.begin(); q != p->second.end(); ++q) + { + str << (int)(*q); + } + out << str.str() << "\""; + } + } + } + out << nl; // Trailing newline. } -- cgit v1.2.3