Review: oslc -E (issue201057)


larry...@...
 

Reviewers: ,

Description:
Like gcc, allow a "-E" option to oslc that just outputs the result of
preprocessing.


Please review this at http://codereview.appspot.com/201057/show

Affected files:
src/liboslcomp/oslcomp.cpp
src/oslc/oslcmain.cpp


Index: src/liboslcomp/oslcomp.cpp
===================================================================
--- src/liboslcomp/oslcomp.cpp (revision 565)
+++ src/liboslcomp/oslcomp.cpp (working copy)
@@ -167,6 +167,7 @@
}

m_output_filename.clear ();
+ bool preprocess_only = false;
for (size_t i = 0; i < options.size(); ++i) {
if (options[i] == "-v") {
// verbose mode
@@ -174,6 +175,8 @@
} else if (options[i] == "-d") {
// debug mode
m_debug = true;
+ } else if (options[i] == "-E") {
+ preprocess_only = true;
} else if (options[i] == "-o" && i < options.size()-1) {
++i;
m_output_filename = options[i];
@@ -204,7 +207,19 @@
std::filebuf fb (cpppipe);
#endif

- if (fb.is_open()) {
+ if (! cpppipe || ! fb.is_open()) {
+ // File didn't open
+ std::cerr << "Could not run '" << cppcommand.c_str() << "'\n";
+
+ } else if (preprocess_only) {
+ char buf[1024*32];
+ while (! feof (cpppipe)) {
+ if (! fgets (buf, sizeof(buf)-1, cpppipe))
+ break;
+ std::cout << buf;
+ }
+
+ } else {
std::istream in (&fb);
oslcompiler = this;

@@ -248,6 +263,9 @@
oslcompiler = NULL;
}

+ if (cpppipe)
+ fclose (cpppipe);
+
return ! error_encountered();
}

Index: src/oslc/oslcmain.cpp
===================================================================
--- src/oslc/oslcmain.cpp (revision 565)
+++ src/oslc/oslcmain.cpp (working copy)
@@ -54,6 +54,7 @@
"\t-Usym Undefine preprocessor symbol\n"
"\t-O0, -O1, -O2 Set optimization level (default=1)\n"
"\t-d Debug mode\n"
+ "\t-E Only preprocess the input and output to stdout\n"
;
}

@@ -76,6 +77,7 @@
}
else if (! strcmp (argv[a], "-v") ||
! strcmp (argv[a], "-d") ||
+ ! strcmp (argv[a], "-E") ||
! strcmp (argv[a], "-O") || ! strcmp (argv[a], "-O0") ||
! strcmp (argv[a], "-O1") || ! strcmp (argv[a], "-O2")) {
// Valid command-line argument

Join osl-dev@lists.aswf.io to automatically receive all group messages.