@@ -78,7 +78,7 @@ ProcessExecutor::ProcessExecutor(const std::list<FileWithDetails> &files, const
7878namespace {
7979 class PipeWriter : public ErrorLogger {
8080 public:
81- enum PipeSignal : std::uint8_t {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' , CHILD_END=' 5' };
81+ enum PipeSignal : std::uint8_t {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' ,REPORT_SUPPR_INLINE= ' 3 ' , CHILD_END=' 5' };
8282
8383 explicit PipeWriter (int pipe) : mWpipe(pipe) {}
8484
@@ -90,11 +90,32 @@ namespace {
9090 writeToPipe (REPORT_ERROR, msg.serialize ());
9191 }
9292
93+ void writeSuppr (const SuppressionList &supprs) const {
94+ for (const auto & suppr : supprs.getSuppressions ())
95+ {
96+ if (!suppr.isInline )
97+ continue ;
98+
99+ writeToPipe (REPORT_SUPPR_INLINE, suppressionToString (suppr));
100+ }
101+ // TODO: update suppression states?
102+ }
103+
93104 void writeEnd (const std::string& str) const {
94105 writeToPipe (CHILD_END, str);
95106 }
96107
97108 private:
109+ static std::string suppressionToString (const SuppressionList::Suppression &suppr)
110+ {
111+ std::string suppr_str = suppr.toString ();
112+ suppr_str += " ;" ;
113+ suppr_str += suppr.checked ? " 1" : " 0" ;
114+ suppr_str += " ;" ;
115+ suppr_str += suppr.matched ? " 1" : " 0" ;
116+ return suppr_str;
117+ }
118+
98119 // TODO: how to log file name in error?
99120 void writeToPipeInternal (PipeSignal type, const void * data, std::size_t to_write) const
100121 {
@@ -124,7 +145,7 @@ namespace {
124145 writeToPipeInternal (type, &len, l_size);
125146 }
126147
127- if (len > 0 )
148+ if (len > 0 ) // TODO: unexpected - write a warning?
128149 writeToPipeInternal (type, data.c_str (), len);
129150 }
130151
@@ -155,7 +176,10 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
155176 std::exit (EXIT_FAILURE);
156177 }
157178
158- if (type != PipeWriter::REPORT_OUT && type != PipeWriter::REPORT_ERROR && type != PipeWriter::CHILD_END) {
179+ if (type != PipeWriter::REPORT_OUT &&
180+ type != PipeWriter::REPORT_ERROR &&
181+ type != PipeWriter::REPORT_SUPPR_INLINE &&
182+ type != PipeWriter::CHILD_END) {
159183 std::cerr << " #### ThreadExecutor::handleRead(" << filename << " ) invalid type " << int (type) << std::endl;
160184 std::exit (EXIT_FAILURE);
161185 }
@@ -174,7 +198,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
174198 }
175199
176200 std::string buf (len, ' \0 ' );
177- if (len > 0 ) {
201+ if (len > 0 ) { // TODO: unexpected - write a warning?
178202 char *data_start = &buf[0 ];
179203 bytes_to_read = len;
180204 do {
@@ -206,6 +230,29 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
206230
207231 if (hasToLog (msg))
208232 mErrorLogger .reportErr (msg);
233+ } else if (type == PipeWriter::REPORT_SUPPR_INLINE) {
234+ if (!buf.empty ()) {
235+ // TODO: avoid string splitting
236+ auto parts = splitString (buf, ' ;' );
237+ if (parts.size () != 3 )
238+ {
239+ // TODO: make this non-fatal
240+ std::cerr << " #### ThreadExecutor::handleRead(" << filename << " ) adding of inline suppression failed - insufficient data" << std::endl;
241+ std::exit (EXIT_FAILURE);
242+ }
243+ auto suppr = SuppressionList::parseLine (parts[0 ]);
244+ suppr.isInline = true ;
245+ suppr.checked = parts[1 ] == " 1" ;
246+ suppr.matched = parts[2 ] == " 1" ;
247+ const std::string err = mSuppressions .nomsg .addSuppression (suppr);
248+ if (!err.empty ()) {
249+ // TODO: only update state if it doesn't exist - otherwise propagate error
250+ mSuppressions .nomsg .updateSuppressionState (suppr); // TODO: check result
251+ // TODO: make this non-fatal
252+ // std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") adding of inline suppression failed - " << err << std::endl;
253+ // std::exit(EXIT_FAILURE);
254+ }
255+ }
209256 } else if (type == PipeWriter::CHILD_END) {
210257 result += std::stoi (buf);
211258 res = false ;
@@ -297,6 +344,8 @@ unsigned int ProcessExecutor::check()
297344 // TODO: call analyseClangTidy()?
298345 }
299346
347+ pipewriter.writeSuppr (mSuppressions .nomsg );
348+
300349 pipewriter.writeEnd (std::to_string (resultOfCheck));
301350 std::exit (EXIT_SUCCESS);
302351 }
0 commit comments