diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 42 | ||||
-rw-r--r-- | cpp/src/slice2php/Main.cpp | 160 | ||||
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 178 | ||||
-rw-r--r-- | cpp/src/slice2rb/Main.cpp | 145 |
4 files changed, 336 insertions, 189 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 8759bee15be..03403498703 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -258,7 +258,7 @@ Slice::Preprocessor::preprocess(bool keepComments) bool Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<string>& includePaths, - const string& cppSourceExt) + const string& cppSourceExt, const string& pyPrefix) { if(!checkInputFile()) { @@ -529,6 +529,46 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin } break; } + case Python: + { + // + // Change .o[bj] suffix to .py suffix. + // + if(pyPrefix.size() != 0) + { + result = pyPrefix + result; + } + string::size_type pos; + while((pos = result.find(suffix)) != string::npos) + { + result.replace(pos, suffix.size() - 1, "_ice.py"); + } + break; + } + case Ruby: + { + // + // Change .o[bj] suffix to .rb suffix. + // + string::size_type pos; + while((pos = result.find(suffix)) != string::npos) + { + result.replace(pos, suffix.size() - 1, ".rb"); + } + break; + } + case PHP: + { + // + // Change .o[bj] suffix to .php suffix. + // + string::size_type pos; + while((pos = result.find(suffix)) != string::npos) + { + result.replace(pos, suffix.size() - 1, ".php"); + } + break; + } default: { abort(); diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index e943a742838..f0f09f0a7d5 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1529,6 +1529,7 @@ usage(const char* n) "-IDIR Put DIR in the include file search path.\n" "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" + "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only)\n" "--all Generate code for Slice definitions in included files.\n" @@ -1548,6 +1549,7 @@ compile(int argc, char* argv[]) opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); opts.addOpt("", "all"); @@ -1602,6 +1604,8 @@ compile(int argc, char* argv[]) string output = opts.optArg("output-dir"); + bool depend = opts.isSet("depend"); + bool debug = opts.isSet("debug"); bool ice = opts.isSet("ice"); @@ -1626,24 +1630,30 @@ compile(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { - PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); - - if(cppHandle == 0) + if(depend) { - return EXIT_FAILURE; - } + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + if(cppHandle == 0) { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } + + UnitPtr u = Unit::createUnit(false, false, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + u->destroy(); + + if(parseStatus == EXIT_FAILURE) + { + return EXIT_FAILURE; } + + if(!icecpp->printMakefileDependencies(Preprocessor::PHP, includePaths)) + { + return EXIT_FAILURE; + } + if(!icecpp->close()) { return EXIT_FAILURE; @@ -1651,76 +1661,102 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); - int parseStatus = u->parse(*i, cppHandle, debug); + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - if(!icecpp->close()) + if(cppHandle == 0) { - u->destroy(); return EXIT_FAILURE; } - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp->close()) + { + return EXIT_FAILURE; + } } else { - string base = icecpp->getBaseName(); - string::size_type pos = base.find_last_of("/\\"); - if(pos != string::npos) + UnitPtr u = Unit::createUnit(false, all, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + + if(!icecpp->close()) { - base.erase(0, pos + 1); + u->destroy(); + return EXIT_FAILURE; } - string file = base + ".php"; - if(!output.empty()) + if(parseStatus == EXIT_FAILURE) { - file = output + '/' + file; + status = EXIT_FAILURE; } - - try + else { - IceUtilInternal::Output out; - out.open(file.c_str()); - if(!out) + string base = icecpp->getBaseName(); + string::size_type pos = base.find_last_of("/\\"); + if(pos != string::npos) { - ostringstream os; - os << "cannot open`" << file << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); + base.erase(0, pos + 1); } - FileTracker::instance()->addFile(file); - out << "<?php\n"; - printHeader(out); - printGeneratedHeader(out, base + ".ice"); + string file = base + ".php"; + if(!output.empty()) + { + file = output + '/' + file; + } - // - // Generate the PHP mapping. - // - generate(u, all, checksum, ns, includePaths, out); + try + { + IceUtilInternal::Output out; + out.open(file.c_str()); + if(!out) + { + ostringstream os; + os << "cannot open`" << file << "': " << strerror(errno); + throw FileException(__FILE__, __LINE__, os.str()); + } + FileTracker::instance()->addFile(file); - out << "?>\n"; - out.close(); - } - catch(const Slice::FileException& ex) - { - // If a file could not be created, then cleanup any - // created files. - FileTracker::instance()->cleanup(); - u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - return EXIT_FAILURE; - } - catch(const string& err) - { - FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; - status = EXIT_FAILURE; + out << "<?php\n"; + printHeader(out); + printGeneratedHeader(out, base + ".ice"); + + // + // Generate the PHP mapping. + // + generate(u, all, checksum, ns, includePaths, out); + + out << "?>\n"; + out.close(); + } + catch(const Slice::FileException& ex) + { + // If a file could not be created, then cleanup any + // created files. + FileTracker::instance()->cleanup(); + u->destroy(); + getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + return EXIT_FAILURE; + } + catch(const string& err) + { + FileTracker::instance()->cleanup(); + getErrorStream() << argv[0] << ": error: " << err << endl; + status = EXIT_FAILURE; + } } - } - u->destroy(); + u->destroy(); + } } { diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 3af0f9b217b..74cc5d02916 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -396,6 +396,7 @@ usage(const char* n) "-IDIR Put DIR in the include file search path.\n" "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" + "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only)\n" "--all Generate code for Slice definitions in included files.\n" @@ -416,6 +417,7 @@ compile(int argc, char* argv[]) opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); opts.addOpt("", "all"); @@ -471,6 +473,8 @@ compile(int argc, char* argv[]) string output = opts.optArg("output-dir"); + bool depend = opts.isSet("depend"); + bool debug = opts.isSet("debug"); bool ice = opts.isSet("ice"); @@ -499,24 +503,30 @@ compile(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { - PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(keepComments); - - if(cppHandle == 0) + if(depend) { - return EXIT_FAILURE; - } + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + if(cppHandle == 0) { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } + return EXIT_FAILURE; } + + UnitPtr u = Unit::createUnit(false, false, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + u->destroy(); + + if(parseStatus == EXIT_FAILURE) + { + return EXIT_FAILURE; + } + + if(!icecpp->printMakefileDependencies(Preprocessor::Python, includePaths, "", prefix)) + { + return EXIT_FAILURE; + } + if(!icecpp->close()) { return EXIT_FAILURE; @@ -524,88 +534,114 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); - int parseStatus = u->parse(*i, cppHandle, debug); + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(keepComments); - if(!icecpp->close()) + if(cppHandle == 0) { - u->destroy(); return EXIT_FAILURE; } - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp->close()) + { + return EXIT_FAILURE; + } } else { - string base = icecpp->getBaseName(); - string::size_type pos = base.find_last_of("/\\"); - if(pos != string::npos) + UnitPtr u = Unit::createUnit(false, all, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + + if(!icecpp->close()) { - base.erase(0, pos + 1); + u->destroy(); + return EXIT_FAILURE; } - // - // Append the suffix "_ice" to the filename in order to avoid any conflicts - // with Slice module names. For example, if the file Test.ice defines a - // Slice module named "Test", then we couldn't create a Python package named - // "Test" and also call the generated file "Test.py". - // - string file = prefix + base + "_ice.py"; - if(!output.empty()) + if(parseStatus == EXIT_FAILURE) { - file = output + '/' + file; + status = EXIT_FAILURE; } - - try + else { - IceUtilInternal::Output out; - out.open(file.c_str()); - if(!out) + string base = icecpp->getBaseName(); + string::size_type pos = base.find_last_of("/\\"); + if(pos != string::npos) { - ostringstream os; - os << "cannot open`" << file << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); + base.erase(0, pos + 1); } - FileTracker::instance()->addFile(file); - printHeader(out); - printGeneratedHeader(out, base + ".ice", "#"); // - // Generate the Python mapping. + // Append the suffix "_ice" to the filename in order to avoid any conflicts + // with Slice module names. For example, if the file Test.ice defines a + // Slice module named "Test", then we couldn't create a Python package named + // "Test" and also call the generated file "Test.py". // - generate(u, all, checksum, includePaths, out); - - out.close(); + string file = prefix + base + "_ice.py"; + if(!output.empty()) + { + file = output + '/' + file; + } - // - // Create or update the Python package hierarchy. - // - if(!noPackage) + try { - PackageVisitor visitor(prefix + base + "_ice", output); - u->visit(&visitor, false); + IceUtilInternal::Output out; + out.open(file.c_str()); + if(!out) + { + ostringstream os; + os << "cannot open`" << file << "': " << strerror(errno); + throw FileException(__FILE__, __LINE__, os.str()); + } + FileTracker::instance()->addFile(file); + + printHeader(out); + printGeneratedHeader(out, base + ".ice", "#"); + // + // Generate the Python mapping. + // + generate(u, all, checksum, includePaths, out); + + out.close(); + + // + // Create or update the Python package hierarchy. + // + if(!noPackage) + { + PackageVisitor visitor(prefix + base + "_ice", output); + u->visit(&visitor, false); + } + } + catch(const Slice::FileException& ex) + { + // If a file could not be created, then cleanup any + // created files. + FileTracker::instance()->cleanup(); + u->destroy(); + getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + return EXIT_FAILURE; + } + catch(const string& err) + { + FileTracker::instance()->cleanup(); + getErrorStream() << argv[0] << ": error: " << err << endl; + status = EXIT_FAILURE; } } - catch(const Slice::FileException& ex) - { - // If a file could not be created, then cleanup any - // created files. - FileTracker::instance()->cleanup(); - u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - return EXIT_FAILURE; - } - catch(const string& err) - { - FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; - status = EXIT_FAILURE; - } - } - u->destroy(); + u->destroy(); + } } { diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 369fc9329db..68305f45072 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -84,6 +84,7 @@ usage(const char* n) "-IDIR Put DIR in the include file search path.\n" "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" + "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only)\n" "--all Generate code for Slice definitions in included files.\n" @@ -102,6 +103,7 @@ compile(int argc, char* argv[]) opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); opts.addOpt("", "all"); @@ -155,6 +157,8 @@ compile(int argc, char* argv[]) string output = opts.optArg("output-dir"); + bool depend = opts.isSet("depend"); + bool debug = opts.isSet("debug"); bool ice = opts.isSet("ice"); @@ -177,25 +181,30 @@ compile(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { + if(depend) + { + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + if(cppHandle == 0) + { + return EXIT_FAILURE; + } - if(cppHandle == 0) - { - return EXIT_FAILURE; - } + UnitPtr u = Unit::createUnit(false, false, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + u->destroy(); - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + if(parseStatus == EXIT_FAILURE) { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } + + if(!icecpp->printMakefileDependencies(Preprocessor::Ruby, includePaths)) + { + return EXIT_FAILURE; } + if(!icecpp->close()) { return EXIT_FAILURE; @@ -203,68 +212,94 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); - int parseStatus = u->parse(*i, cppHandle, debug); + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - if(!icecpp->close()) + if(cppHandle == 0) { - u->destroy(); return EXIT_FAILURE; } - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp->close()) + { + return EXIT_FAILURE; + } } else { - string base = icecpp->getBaseName(); - string::size_type pos = base.find_last_of("/\\"); - if(pos != string::npos) + UnitPtr u = Unit::createUnit(false, all, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + + if(!icecpp->close()) { - base.erase(0, pos + 1); + u->destroy(); + return EXIT_FAILURE; } - string file = base + ".rb"; - if(!output.empty()) + if(parseStatus == EXIT_FAILURE) { - file = output + '/' + file; + status = EXIT_FAILURE; } - - try + else { - IceUtilInternal::Output out; - out.open(file.c_str()); - if(!out) + string base = icecpp->getBaseName(); + string::size_type pos = base.find_last_of("/\\"); + if(pos != string::npos) { - ostringstream os; - os << "cannot open`" << file << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); + base.erase(0, pos + 1); } - FileTracker::instance()->addFile(file); - printHeader(out); - printGeneratedHeader(out, base + ".ice", "#"); - - // - // Generate the Ruby mapping. - // - generate(u, all, checksum, includePaths, out); + string file = base + ".rb"; + if(!output.empty()) + { + file = output + '/' + file; + } - out.close(); - } - catch(const Slice::FileException& ex) - { - // If a file could not be created, then cleanup - // any created files. - FileTracker::instance()->cleanup(); - u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - return EXIT_FAILURE; + try + { + IceUtilInternal::Output out; + out.open(file.c_str()); + if(!out) + { + ostringstream os; + os << "cannot open`" << file << "': " << strerror(errno); + throw FileException(__FILE__, __LINE__, os.str()); + } + FileTracker::instance()->addFile(file); + + printHeader(out); + printGeneratedHeader(out, base + ".ice", "#"); + + // + // Generate the Ruby mapping. + // + generate(u, all, checksum, includePaths, out); + + out.close(); + } + catch(const Slice::FileException& ex) + { + // If a file could not be created, then cleanup + // any created files. + FileTracker::instance()->cleanup(); + u->destroy(); + getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + return EXIT_FAILURE; + } } - } - u->destroy(); + u->destroy(); + } } { |