|
28 | 28 | #include "writer-json.hh" |
29 | 29 |
|
30 | 30 | #include <cstdlib> |
31 | | -#include <fstream> |
32 | 31 | #include <iomanip> |
33 | 32 | #include <map> |
34 | 33 |
|
@@ -336,158 +335,6 @@ class SrcAnnotPredicate: public IPredicate { |
336 | 335 | } |
337 | 336 | }; |
338 | 337 |
|
339 | | -class PathStripper: public GenericAbstractFilter { |
340 | | - public: |
341 | | - PathStripper(AbstractWriter *agent, const std::string &prefix): |
342 | | - GenericAbstractFilter(agent), |
343 | | - prefStr_(prefix), |
344 | | - prefSize_(prefix.size()) |
345 | | - { |
346 | | - } |
347 | | - |
348 | | - void handleDef(const Defect &defOrig) override { |
349 | | - Defect def(defOrig); |
350 | | - |
351 | | - // iterate through all events |
352 | | - for (DefEvent &evt : def.events) { |
353 | | - std::string &path = evt.fileName; |
354 | | - if (path.size() < prefSize_) |
355 | | - continue; |
356 | | - |
357 | | - const std::string str(path, /* pos */ 0U, prefSize_); |
358 | | - if (str != prefStr_) |
359 | | - continue; |
360 | | - |
361 | | - // strip path prefix in this event |
362 | | - path.erase(/* pos */ 0U, prefSize_); |
363 | | - } |
364 | | - |
365 | | - agent_->handleDef(def); |
366 | | - } |
367 | | - |
368 | | - private: |
369 | | - const std::string prefStr_; |
370 | | - const size_t prefSize_; |
371 | | -}; |
372 | | - |
373 | | -class PathPrepender: public GenericAbstractFilter { |
374 | | - public: |
375 | | - PathPrepender(AbstractWriter *agent, const std::string &prefix): |
376 | | - GenericAbstractFilter(agent), |
377 | | - prefix_(prefix) |
378 | | - { |
379 | | - } |
380 | | - |
381 | | - void handleDef(const Defect &defOrig) override { |
382 | | - Defect def(defOrig); |
383 | | - |
384 | | - // iterate through all events |
385 | | - for (DefEvent &evt : def.events) { |
386 | | - std::string &path = evt.fileName; |
387 | | - if (path.empty() || path[0] == '/') |
388 | | - // not a relative path |
389 | | - continue; |
390 | | - |
391 | | - path.insert(0U, prefix_); |
392 | | - } |
393 | | - |
394 | | - agent_->handleDef(def); |
395 | | - } |
396 | | - |
397 | | - private: |
398 | | - const std::string prefix_; |
399 | | -}; |
400 | | - |
401 | | -class DropScanProps: public GenericAbstractFilter { |
402 | | - public: |
403 | | - DropScanProps(AbstractWriter *agent): |
404 | | - GenericAbstractFilter(agent) |
405 | | - { |
406 | | - } |
407 | | - |
408 | | - /// ignore any given scan properties |
409 | | - void setScanProps(const TScanProps &) override { } |
410 | | - |
411 | | - /// always return empty scan properties |
412 | | - const TScanProps& getScanProps() const override { |
413 | | - return emp_; |
414 | | - } |
415 | | - |
416 | | - private: |
417 | | - const TScanProps emp_; |
418 | | -}; |
419 | | - |
420 | | -class ScanPropSetter: public GenericAbstractFilter { |
421 | | - public: |
422 | | - ScanPropSetter(AbstractWriter *agent, const TStringList &propList); |
423 | | - |
424 | | - /// override specified scan properties |
425 | | - void setScanProps(const TScanProps &origProps) override; |
426 | | - |
427 | | - private: |
428 | | - // key/val pairs are stored in a vector |
429 | | - using TItem = std::pair<std::string, std::string>; |
430 | | - using TList = std::vector<TItem>; |
431 | | - TList itemList_; |
432 | | -}; |
433 | | - |
434 | | -ScanPropSetter::ScanPropSetter( |
435 | | - AbstractWriter *agent, |
436 | | - const TStringList &propList): |
437 | | - GenericAbstractFilter(agent) |
438 | | -{ |
439 | | - // iterate over the given NAME:VALUE strings |
440 | | - for (const std::string &str : propList) { |
441 | | - // split the string by the first occurrence of ':' |
442 | | - size_t ddAt = str.find(':'); |
443 | | - if (std::string::npos == ddAt) { |
444 | | - const auto msg = "missing ':' in " + str; |
445 | | - throw std::runtime_error(msg); |
446 | | - } |
447 | | - |
448 | | - // store the key/val pair into the vector |
449 | | - itemList_.emplace_back( |
450 | | - /* key */ str.substr(0, ddAt), |
451 | | - /* val */ str.substr(ddAt + 1)); |
452 | | - } |
453 | | -} |
454 | | - |
455 | | -void ScanPropSetter::setScanProps(const TScanProps &origProps) |
456 | | -{ |
457 | | - // we need to copy the given map |
458 | | - TScanProps props = origProps; |
459 | | - |
460 | | - // apply specified changes |
461 | | - for (const auto &item : itemList_) |
462 | | - props[item./* key */first] = item./* val */second; |
463 | | - |
464 | | - // forward the result |
465 | | - agent_->setScanProps(props); |
466 | | -} |
467 | | - |
468 | | -class DuplicateFilter: public AbstractFilter { |
469 | | - public: |
470 | | - DuplicateFilter(AbstractWriter *agent): |
471 | | - AbstractFilter(agent) |
472 | | - { |
473 | | - } |
474 | | - |
475 | | - protected: |
476 | | - bool matchDef(const Defect &def) override { |
477 | | - DefEvent evt = def.events[def.keyEventIdx]; |
478 | | - |
479 | | - // abstract out differences we do not deem important |
480 | | - evt.fileName = MsgFilter::inst().filterPath(evt.fileName); |
481 | | - evt.msg = MsgFilter::inst().filterMsg(evt.msg, def.checker); |
482 | | - |
483 | | - return lookup_.insert(evt)./* inserted */second; |
484 | | - } |
485 | | - |
486 | | - private: |
487 | | - typedef std::set<DefEvent> TLookup; |
488 | | - TLookup lookup_; |
489 | | -}; |
490 | | - |
491 | 338 | class WriterFactory { |
492 | 339 | private: |
493 | 340 | typedef std::map<std::string, AbstractWriter* (*)(void)> TTable; |
|
0 commit comments