diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Slice/Util.cpp | 50 |
2 files changed, 55 insertions, 1 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 6d47a0c689d..95432a9cee7 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -150,7 +150,11 @@ Slice::Preprocessor::preprocess(bool keepComments) char* err = mcpp_get_mem_buffer(Err); if(err) { - emitRaw(err); + vector<string> messages = filterMcppWarnings(err); + for(vector<string>::const_iterator i = messages.begin(); i != messages.end(); ++i) + { + emitRaw(i->c_str()); + } } if(status == 0) diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp index 6a691df8fb3..106a14d989b 100644 --- a/cpp/src/Slice/Util.cpp +++ b/cpp/src/Slice/Util.cpp @@ -251,3 +251,53 @@ Slice::emitRaw(const char* message) { *errorStream << message << flush; } + +vector<string> +Slice::filterMcppWarnings(const string& message) +{ + static const int messagesSize = 2; + static const char* messages[messagesSize] = {"Converted [CR+LF] to [LF]", "End of input with no newline, supplemented newline"}; + + static const string delimiters = "\n"; + + // Skip delimiters at beginning. + string::size_type lastPos = message.find_first_not_of(delimiters, 0); + // Find first "non-delimiter". + string::size_type pos = message.find_first_of(delimiters, lastPos); + + vector<string> tokens; + bool skiped; + while (string::npos != pos || string::npos != lastPos) + { + skiped = false; + string token = message.substr(lastPos, pos - lastPos); + static const string warningPrefix = "warning:"; + if(token.find_first_of(warningPrefix) != string::npos) + { + for(int j = 0; j < messagesSize; ++j) + { + if(token.find_first_of(messages[j]) != string::npos) + { + skiped = true; + //Skip Next token. + + // Skip delimiters. Note the "not_of" + lastPos = message.find_first_not_of(delimiters, pos); + // Find next "non-delimiter" + pos = message.find_first_of(delimiters, lastPos); + break; + } + } + } + + if(!skiped) + { + tokens.push_back(token); + } + // Skip delimiters. Note the "not_of" + lastPos = message.find_first_not_of(delimiters, pos); + // Find next "non-delimiter" + pos = message.find_first_of(delimiters, lastPos); + } + return tokens; +} |