diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-09-15 18:01:02 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-09-15 18:01:02 +0000 |
commit | b37dac91b2f47bd401941daf9a031add77c1ba70 (patch) | |
tree | deeffa19e980d8ad4883486749a908b04dd3ca88 /cpp/src | |
parent | code reorgnization; adding prefixes to generated files (diff) | |
download | ice-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')
-rw-r--r-- | cpp/src/Slice/PythonUtil.cpp | 76 | ||||
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 53 |
2 files changed, 109 insertions, 20 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. } diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index b0a899835de..86ca964e965 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -281,6 +281,9 @@ usage(const char* n) "--ice Permit `Ice' prefix (for building Ice source code only)\n" "--all Generate code for Slice definitions in included files.\n" "--no-package Do not create Python packages.\n" + "--no-package Do not create Python packages.\n" + "--checksum Generate checksums for Slice definitions.\n" + "--prefix PREFIX Prepend filenames of Python modules with PREFIX.\n" ; // Note: --case-sensitive is intentionally not shown here! } @@ -289,12 +292,15 @@ int main(int argc, char* argv[]) { string cppArgs; + vector<string> includePaths; string output; bool debug = false; bool ice = false; bool caseSensitive = false; bool all = false; bool noPackage = false; + bool checksum = false; + string prefix; int idx = 1; while(idx < argc) @@ -304,6 +310,12 @@ main(int argc, char* argv[]) cppArgs += ' '; cppArgs += 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]; @@ -331,6 +343,22 @@ main(int argc, char* argv[]) cout << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } + 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(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) { debug = true; @@ -376,7 +404,16 @@ main(int argc, char* argv[]) } --argc; } - else if(strcmp(argv[idx], "--output-dir") == 0) + else if(strcmp(argv[idx], "--checksum") == 0) + { + checksum = true; + for(int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else if(strcmp(argv[idx], "--prefix") == 0) { if(idx + 1 >= argc) { @@ -384,8 +421,8 @@ main(int argc, char* argv[]) usage(argv[0]); return EXIT_FAILURE; } - - output = argv[idx + 1]; + + prefix = argv[idx + 1]; for(int i = idx ; i + 2 < argc ; ++i) { argv[i] = argv[i + 2]; @@ -422,10 +459,10 @@ main(int argc, char* argv[]) { return EXIT_FAILURE; } - + UnitPtr u = Unit::createUnit(false, all, ice, caseSensitive); int parseStatus = u->parse(cppHandle, debug); - + if(!icecpp.close()) { u->destroy(); @@ -451,7 +488,7 @@ main(int argc, char* argv[]) // Slice module named "Test", then we couldn't create a Python package named // "Test" and also call the generated file "Test.py". // - string file = base + "_ice.py"; + string file = prefix + base + "_ice.py"; if(!output.empty()) { file = output + '/' + file; @@ -473,14 +510,14 @@ main(int argc, char* argv[]) // // Generate the Python mapping. // - generate(u, all, out); + generate(u, all, checksum, includePaths, out); // // Create or update the Python package hierarchy. // if(!noPackage) { - PackageVisitor visitor(argv[0], base + "_ice", output); + PackageVisitor visitor(argv[0], prefix + base + "_ice", output); u->visit(&visitor, false); } } |