diff options
Diffstat (limited to 'cpp/src/Slice/Preprocessor.cpp')
-rwxr-xr-x | cpp/src/Slice/Preprocessor.cpp | 102 |
1 files changed, 63 insertions, 39 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 089f0938713..fb7bef59d16 100755 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -156,34 +156,39 @@ Slice::Preprocessor::preprocess(bool keepComments) // Call mcpp using memory buffer. // mcpp_use_mem_buffers(1); - mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv)); + int status = mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv)); delete[] argv; // - // Write output to temporary file. Print errors to stderr. + // Print errors to stderr. // - string result; - char* buf = mcpp_get_mem_buffer(Out); - - _cppFile = ".preprocess." + IceUtil::generateUUID(); - SignalHandler::addFile(_cppFile); -#ifdef _WIN32 - _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); -#else - _cppHandle = ::fopen(_cppFile.c_str(), "w+"); -#endif - if(buf) - { - ::fwrite(buf, strlen(buf), 1, _cppHandle); - } - ::rewind(_cppHandle); - char* err = mcpp_get_mem_buffer(Err); if(err) { ::fputs(err, stderr); } + if(status == 0) + { + // + // Write output to temporary file. + // + char* buf = mcpp_get_mem_buffer(Out); + + _cppFile = ".preprocess." + IceUtil::generateUUID(); + SignalHandler::addFile(_cppFile); +#ifdef _WIN32 + _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); +#else + _cppHandle = ::fopen(_cppFile.c_str(), "w+"); +#endif + if(buf) + { + ::fwrite(buf, strlen(buf), 1, _cppHandle); + } + ::rewind(_cppHandle); + } + // // Calling this again causes the memory buffers to be freed. // @@ -217,11 +222,29 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin // Call mcpp using memory buffer. // mcpp_use_mem_buffers(1); - mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv)); + int status = mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv)); delete[] argv; // - // Get mcpp output/errors. + // Print errors to stderr. + // + char* err = mcpp_get_mem_buffer(Err); + if(err) + { + ::fputs(err, stderr); + } + + if(status != 0) + { + // + // Calling this again causes the memory buffers to be freed. + // + mcpp_use_mem_buffers(1); + return; + } + + // + // Get mcpp output. // string unprocessed; char* buf = mcpp_get_mem_buffer(Out); @@ -230,19 +253,13 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin unprocessed = string(buf); } - char* err = mcpp_get_mem_buffer(Err); - if(err) - { - ::fputs(err, stderr); - } - // // Calling this again causes the memory buffers to be freed. // mcpp_use_mem_buffers(1); // - // We now need to massage then result to get desire output. + // We now need to massage the result to get the desired output. // First make it a single line. // string::size_type pos; @@ -268,6 +285,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin { fullIncludePaths.push_back(fullPath(*p)); } + string absoluteFileName = fullPath(_fileName); // // Process each dependency. @@ -277,26 +295,32 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin { end += 4; string file = IceUtilInternal::trim(unprocessed.substr(pos, end - pos)); - if(isAbsolute(file)) { - // - // Transform back full paths generated by mcpp to paths relative to the specificed - // include paths. - // - string newFile = file; - for(vector<string>::const_iterator p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) + if(file == absoluteFileName) + { + file = _fileName; + } + else { - if(file.compare(0, p->length(), *p) == 0) + // + // Transform back full paths generated by mcpp to paths relative to the specified + // include paths. + // + string newFile = file; + for(vector<string>::const_iterator p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) { - string s = includePaths[p - fullIncludePaths.begin()] + file.substr(p->length()); - if(isAbsolute(newFile) || s.size() < newFile.size()) + if(file.compare(0, p->length(), *p) == 0) { - newFile = s; + string s = includePaths[p - fullIncludePaths.begin()] + file.substr(p->length()); + if(isAbsolute(newFile) || s.size() < newFile.size()) + { + newFile = s; + } } } + file = newFile; } - file = newFile; } // |