diff options
author | Michi Henning <michi@zeroc.com> | 2005-03-24 04:30:34 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2005-03-24 04:30:34 +0000 |
commit | 00be99a369f583b1146e07c89425153cfa93a7ab (patch) | |
tree | 7aa4882d47e931a9e32e5614ccf5a61c78c4c5f1 /cpp/src | |
parent | Added slice2cppe and slice2javae to "all" target for VC++ and fixed (diff) | |
download | ice-00be99a369f583b1146e07c89425153cfa93a7ab.tar.bz2 ice-00be99a369f583b1146e07c89425153cfa93a7ab.tar.xz ice-00be99a369f583b1146e07c89425153cfa93a7ab.zip |
Added -E option to Slice compilers.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 56 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Main.cpp | 57 | ||||
-rw-r--r-- | cpp/src/slice2cs/Main.cpp | 80 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Main.cpp | 23 | ||||
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 25 | ||||
-rw-r--r-- | cpp/src/slice2freezej/Main.cpp | 26 | ||||
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 86 | ||||
-rw-r--r-- | cpp/src/slice2javae/Main.cpp | 86 | ||||
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 156 | ||||
-rw-r--r-- | cpp/src/slice2vb/Main.cpp | 78 |
10 files changed, 441 insertions, 232 deletions
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 3dd9e7ec820..8c65493e552 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -28,6 +28,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--include-dir DIR Use DIR as the header include directory in source files.\n" "--output-dir DIR Create files in the directory DIR.\n" "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" @@ -46,6 +47,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string include; string output; string dllExport; @@ -65,6 +67,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "include-dir", IceUtil::Options::NeedArg); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("", "dll-export", IceUtil::Options::NeedArg); @@ -126,6 +129,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("include-dir")) { include = opts.optArg("include-dir"); @@ -171,33 +175,51 @@ main(int argc, char* argv[]) { return EXIT_FAILURE; } - - UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = u->parse(cppHandle, debug); - - if(!icecpp.close()) - { - u->destroy(); - return EXIT_FAILURE; - } - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, include, - includePaths, dllExport, output, impl, checksum, stream); - if(!gen) + UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = u->parse(cppHandle, debug); + + if(!icecpp.close()) { u->destroy(); return EXIT_FAILURE; } - gen.generate(u); - } - u->destroy(); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + else + { + Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, include, + includePaths, dllExport, output, impl, checksum, stream); + if(!gen) + { + u->destroy(); + return EXIT_FAILURE; + } + gen.generate(u); + } + + u->destroy(); + } } } diff --git a/cpp/src/slice2cppe/Main.cpp b/cpp/src/slice2cppe/Main.cpp index 3dd9e7ec820..7bcebe1b172 100644 --- a/cpp/src/slice2cppe/Main.cpp +++ b/cpp/src/slice2cppe/Main.cpp @@ -28,6 +28,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--include-dir DIR Use DIR as the header include directory in source files.\n" "--output-dir DIR Create files in the directory DIR.\n" "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" @@ -46,6 +47,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string include; string output; string dllExport; @@ -65,6 +67,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "include-dir", IceUtil::Options::NeedArg); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("", "dll-export", IceUtil::Options::NeedArg); @@ -126,6 +129,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("include-dir")) { include = opts.optArg("include-dir"); @@ -171,33 +175,50 @@ main(int argc, char* argv[]) { return EXIT_FAILURE; } - - UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = u->parse(cppHandle, debug); - - if(!icecpp.close()) + if(preprocess) { - u->destroy(); - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, include, - includePaths, dllExport, output, impl, checksum, stream); - if(!gen) + UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = u->parse(cppHandle, debug); + + if(!icecpp.close()) { u->destroy(); return EXIT_FAILURE; } - gen.generate(u); - } - u->destroy(); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + else + { + Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, include, + includePaths, dllExport, output, impl, checksum, stream); + if(!gen) + { + u->destroy(); + return EXIT_FAILURE; + } + gen.generate(u); + } + + u->destroy(); + } } } diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index ea929a85787..898c9ece515 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -26,6 +26,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "--tie Generate TIE classes.\n" "--impl Generate sample implementations.\n" @@ -44,6 +45,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string output; bool tie; bool impl; @@ -61,6 +63,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("", "tie"); opts.addOpt("", "impl"); @@ -118,6 +121,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("output-dir")) { output = opts.optArg("output-dir"); @@ -164,47 +168,65 @@ main(int argc, char* argv[]) { return EXIT_FAILURE; } - - UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(cppHandle, debug); - - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), includePaths, output, impl, implTie, stream); - if(!gen) + UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = p->parse(cppHandle, debug); + + if(!icecpp.close()) { p->destroy(); return EXIT_FAILURE; - } - gen.generate(p); - if(tie) + } + + if(parseStatus == EXIT_FAILURE) { - gen.generateTie(p); + status = EXIT_FAILURE; } - if(impl) + else { - gen.generateImpl(p); + Gen gen(argv[0], icecpp.getBaseName(), includePaths, output, impl, implTie, stream); + if(!gen) + { + p->destroy(); + return EXIT_FAILURE; + } + gen.generate(p); + if(tie) + { + gen.generateTie(p); + } + if(impl) + { + gen.generateImpl(p); + } + if(implTie) + { + gen.generateImplTie(p); + } + if(checksum) + { + gen.generateChecksums(p); + } } - if(implTie) - { - gen.generateImplTie(p); - } - if(checksum) - { - gen.generateChecksums(p); - } - } - p->destroy(); + p->destroy(); + } } } diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 8e89a9ab85e..0c2459a7591 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -27,6 +27,7 @@ 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" + "-E Print preprocessor output on stdout.\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" @@ -42,6 +43,7 @@ int main(int argc, char* argv[]) { string cppArgs; + bool preprocess; bool standAlone; bool noGlobals; bool chapter; @@ -110,6 +112,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("-E"); standAlone = opts.isSet("s") || opts.isSet("stand-alone"); noGlobals = opts.isSet("no-globals"); chapter = opts.isSet("chapter"); @@ -160,8 +163,22 @@ main(int argc, char* argv[]) p->destroy(); return EXIT_FAILURE; } - - status = p->parse(cppHandle, debug); + if(preprocess) + { + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + p->destroy(); + return EXIT_FAILURE; + } + } + } + else + { + status = p->parse(cppHandle, debug); + } if(!icecpp.close()) { @@ -170,7 +187,7 @@ main(int argc, char* argv[]) } } - if(status == EXIT_SUCCESS) + if(status == EXIT_SUCCESS && !preprocess) { Gen gen(argv[0], docbook, standAlone, noGlobals, chapter, noIndex); if(!gen) diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 716ada2ec6d..22bce317e9f 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -58,6 +58,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--include-dir DIR Use DIR as the header include directory in source files.\n" "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" "--dict NAME,KEY,VALUE Create a Freeze dictionary with the name NAME,\n" @@ -963,6 +964,7 @@ main(int argc, char* argv[]) string headerExtension; string sourceExtension; vector<string> includePaths; + bool preprocess; string include; string dllExport; vector<Dict> dicts; @@ -980,6 +982,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "include-dir", IceUtil::Options::NeedArg); opts.addOpt("", "dll-export", IceUtil::Options::NeedArg); opts.addOpt("", "dict", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); @@ -1040,6 +1043,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess= opts.isSet("E"); if(opts.isSet("include-dir")) { include = opts.optArg("include-dir"); @@ -1302,8 +1306,23 @@ main(int argc, char* argv[]) u->destroy(); return EXIT_FAILURE; } - - status = u->parse(cppHandle, debug); + + if(preprocess) + { + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + u->destroy(); + return EXIT_FAILURE; + } + } + } + else + { + status = u->parse(cppHandle, debug); + } if(!icecpp.close()) { @@ -1312,7 +1331,7 @@ main(int argc, char* argv[]) } } - if(status == EXIT_SUCCESS) + if(status == EXIT_SUCCESS && !preprocess) { u->mergeModules(); u->sort(); diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 83fb57e0410..b08e3fbf1cd 100644 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -866,6 +866,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--include-dir DIR Use DIR as the header include directory.\n" "--dict NAME,KEY,VALUE Create a Freeze dictionary with the name NAME,\n" " using KEY as key, and VALUE as value. This\n" @@ -899,6 +900,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string include; vector<Dict> dicts; vector<Index> indices; @@ -914,6 +916,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "include-dir", IceUtil::Options::NeedArg); opts.addOpt("", "dict", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("", "index", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); @@ -970,6 +973,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("include-dir")) { include = opts.optArg("include-dir"); @@ -1211,8 +1215,23 @@ main(int argc, char* argv[]) u->destroy(); return EXIT_FAILURE; } - - status = u->parse(cppHandle, debug); + + if(preprocess) + { + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + u->destroy(); + return EXIT_FAILURE; + } + } + } + else + { + status = u->parse(cppHandle, debug); + } if(!icecpp.close()) { @@ -1224,10 +1243,11 @@ main(int argc, char* argv[]) if(depend) { + u->destroy(); return EXIT_SUCCESS; } - if(status == EXIT_SUCCESS) + if(status == EXIT_SUCCESS && !preprocess) { u->mergeModules(); u->sort(); diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 47d01d11993..32c3a19e18f 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -26,6 +26,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "--tie Generate TIE classes.\n" "--impl Generate sample implementations.\n" @@ -44,6 +45,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string output; bool tie; bool impl; @@ -61,6 +63,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("", "tie"); opts.addOpt("", "impl"); @@ -118,6 +121,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("output-dir")) { output = opts.optArg("output-dir"); @@ -170,50 +174,68 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(cppHandle, debug); - - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), includePaths, output); - if(!gen) + UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = p->parse(cppHandle, debug); + + if(!icecpp.close()) { p->destroy(); return EXIT_FAILURE; - } - gen.generate(p, stream); - if(tie) + } + + if(parseStatus == EXIT_FAILURE) { - gen.generateTie(p); + status = EXIT_FAILURE; } - if(impl) + else { - gen.generateImpl(p); + Gen gen(argv[0], icecpp.getBaseName(), includePaths, output); + if(!gen) + { + p->destroy(); + return EXIT_FAILURE; + } + gen.generate(p, stream); + if(tie) + { + gen.generateTie(p); + } + if(impl) + { + gen.generateImpl(p); + } + if(implTie) + { + gen.generateImplTie(p); + } + if(!checksumClass.empty()) + { + // + // Calculate checksums for the Slice definitions in the unit. + // + ChecksumMap m = createChecksums(p); + copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); + } } - if(implTie) - { - gen.generateImplTie(p); - } - if(!checksumClass.empty()) - { - // - // Calculate checksums for the Slice definitions in the unit. - // - ChecksumMap m = createChecksums(p); - copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); - } + p->destroy(); } - - p->destroy(); } } diff --git a/cpp/src/slice2javae/Main.cpp b/cpp/src/slice2javae/Main.cpp index 47d01d11993..36406c3912c 100644 --- a/cpp/src/slice2javae/Main.cpp +++ b/cpp/src/slice2javae/Main.cpp @@ -26,6 +26,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "--tie Generate TIE classes.\n" "--impl Generate sample implementations.\n" @@ -44,6 +45,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string output; bool tie; bool impl; @@ -61,6 +63,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("", "tie"); opts.addOpt("", "impl"); @@ -118,6 +121,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("output-dir")) { output = opts.optArg("output-dir"); @@ -170,50 +174,68 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(cppHandle, debug); - - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), includePaths, output); - if(!gen) + UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = p->parse(cppHandle, debug); + + if(!icecpp.close()) { p->destroy(); return EXIT_FAILURE; - } - gen.generate(p, stream); - if(tie) + } + + if(parseStatus == EXIT_FAILURE) { - gen.generateTie(p); + status = EXIT_FAILURE; } - if(impl) + else { - gen.generateImpl(p); + Gen gen(argv[0], icecpp.getBaseName(), includePaths, output); + if(!gen) + { + p->destroy(); + return EXIT_FAILURE; + } + gen.generate(p, stream); + if(tie) + { + gen.generateTie(p); + } + if(impl) + { + gen.generateImpl(p); + } + if(implTie) + { + gen.generateImplTie(p); + } + if(!checksumClass.empty()) + { + // + // Calculate checksums for the Slice definitions in the unit. + // + ChecksumMap m = createChecksums(p); + copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); + } } - if(implTie) - { - gen.generateImplTie(p); - } - if(!checksumClass.empty()) - { - // - // Calculate checksums for the Slice definitions in the unit. - // - ChecksumMap m = createChecksums(p); - copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); - } + p->destroy(); } - - p->destroy(); } } diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index fc9f8053ad8..43d64d0ec06 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -368,6 +368,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only)\n" @@ -384,6 +385,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string output; bool debug; bool ice; @@ -399,6 +401,7 @@ main(int argc, char* argv[]) opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); + opts.addOpt("E"); opts.addOpt("", "output-dir", IceUtil::Options::NeedArg); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); @@ -454,6 +457,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("output-dir")) { output = opts.optArg("output-dir"); @@ -488,73 +492,91 @@ 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(); - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - else - { - string base = icecpp.getBaseName(); - string::size_type pos = base.rfind('/'); - if(pos == string::npos) - { - pos = base.rfind('\\'); - } - if(pos != string::npos) - { - base.erase(0, pos + 1); - } - - // - // 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()) - { - file = output + '/' + file; - } - - IceUtil::Output out; - out.setUseTab(false); - out.open(file.c_str()); - if(!out) - { - cerr << argv[0] << ": can't open `" << file << "' for writing" << endl; - u->destroy(); - return EXIT_FAILURE; - } - - printHeader(out); - out << "\n# Generated from file `" << base << ".ice'\n"; - - // - // Generate the Python mapping. - // - generate(u, all, checksum, includePaths, out); - - // - // Create or update the Python package hierarchy. - // - if(!noPackage) - { - PackageVisitor visitor(argv[0], prefix + base + "_ice", output); - u->visit(&visitor, false); - } - } - - u->destroy(); + if(preprocess) + { + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } + } + else + { + UnitPtr u = Unit::createUnit(false, all, ice, caseSensitive); + int parseStatus = u->parse(cppHandle, debug); + + if(!icecpp.close()) + { + u->destroy(); + return EXIT_FAILURE; + } + + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + else + { + string base = icecpp.getBaseName(); + string::size_type pos = base.rfind('/'); + if(pos == string::npos) + { + pos = base.rfind('\\'); + } + if(pos != string::npos) + { + base.erase(0, pos + 1); + } + + // + // 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()) + { + file = output + '/' + file; + } + + IceUtil::Output out; + out.setUseTab(false); + out.open(file.c_str()); + if(!out) + { + cerr << argv[0] << ": can't open `" << file << "' for writing" << endl; + u->destroy(); + return EXIT_FAILURE; + } + + printHeader(out); + out << "\n# Generated from file `" << base << ".ice'\n"; + + // + // Generate the Python mapping. + // + generate(u, all, checksum, includePaths, out); + + // + // Create or update the Python package hierarchy. + // + if(!noPackage) + { + PackageVisitor visitor(argv[0], prefix + base + "_ice", output); + u->visit(&visitor, false); + } + } + + u->destroy(); + } } return status; diff --git a/cpp/src/slice2vb/Main.cpp b/cpp/src/slice2vb/Main.cpp index c17777909a4..b5714591ac9 100644 --- a/cpp/src/slice2vb/Main.cpp +++ b/cpp/src/slice2vb/Main.cpp @@ -26,6 +26,7 @@ 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" + "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "--tie Generate TIE classes.\n" "--impl Generate sample implementations.\n" @@ -44,6 +45,7 @@ main(int argc, char* argv[]) { string cppArgs; vector<string> includePaths; + bool preprocess; string output; bool tie; bool impl; @@ -118,6 +120,7 @@ main(int argc, char* argv[]) cppArgs += " -I" + *i; } } + preprocess = opts.isSet("E"); if(opts.isSet("output-dir")) { output = opts.optArg("output-dir"); @@ -165,46 +168,65 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(cppHandle, debug); - - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) + if(preprocess) { - status = EXIT_FAILURE; + char buf[4096]; + while(fgets(buf, sizeof(buf), cppHandle) != NULL) + { + if(fputs(buf, stdout) == EOF) + { + return EXIT_FAILURE; + } + } + if(!icecpp.close()) + { + return EXIT_FAILURE; + } } else { - Gen gen(argv[0], icecpp.getBaseName(), includePaths, output, impl, implTie, stream); - if(!gen) + UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); + int parseStatus = p->parse(cppHandle, debug); + + if(!icecpp.close()) { p->destroy(); return EXIT_FAILURE; - } - gen.generate(p); - if(tie) - { - gen.generateTie(p); - } - if(impl) + } + + if(parseStatus == EXIT_FAILURE) { - gen.generateImpl(p); + status = EXIT_FAILURE; } - if(implTie) + else { - gen.generateImplTie(p); + Gen gen(argv[0], icecpp.getBaseName(), includePaths, output, impl, implTie, stream); + if(!gen) + { + p->destroy(); + return EXIT_FAILURE; + } + gen.generate(p); + if(tie) + { + gen.generateTie(p); + } + if(impl) + { + gen.generateImpl(p); + } + if(implTie) + { + gen.generateImplTie(p); + } + if(checksum) + { + gen.generateChecksums(p); + } } - if(checksum) - { - gen.generateChecksums(p); - } - } - p->destroy(); + p->destroy(); + } } } |