yql_warning.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "yql_warning.h"
  2. #include <util/string/cast.h>
  3. #include <util/string/join.h>
  4. namespace NYql {
  5. TWarningRule::EParseResult TWarningRule::ParseFrom(const TString& codePattern, const TString& action,
  6. TWarningRule& result, TString& errorMessage)
  7. {
  8. errorMessage.clear();
  9. result.IssueCodePattern.clear();
  10. result.Action = EWarningAction::DEFAULT;
  11. if (!TryFromString<EWarningAction>(to_upper(action), result.Action)) {
  12. errorMessage = "unknown warning action '" + action + "', expecting one of " +
  13. Join(", ", EWarningAction::DEFAULT, EWarningAction::ERROR, EWarningAction::DISABLE);
  14. return EParseResult::PARSE_ACTION_FAIL;
  15. }
  16. if (codePattern != "*") {
  17. ui32 code;
  18. if (!TryFromString(codePattern, code)) {
  19. errorMessage = "unknown warning code '" + codePattern + "', expecting integer or '*'";
  20. return EParseResult::PARSE_PATTERN_FAIL;
  21. }
  22. }
  23. result.IssueCodePattern = codePattern;
  24. return EParseResult::PARSE_OK;
  25. }
  26. void TWarningPolicy::AddRule(const TWarningRule& rule)
  27. {
  28. TString pattern = rule.GetPattern();
  29. if (pattern.empty()) {
  30. return;
  31. }
  32. Rules.push_back(rule);
  33. EWarningAction action = rule.GetAction();
  34. if (pattern == "*") {
  35. BaseAction = action;
  36. Overrides.clear();
  37. return;
  38. }
  39. TIssueCode code;
  40. Y_ENSURE(TryFromString(pattern, code));
  41. if (action == BaseAction) {
  42. Overrides.erase(Overrides.find(code));
  43. } else {
  44. Overrides[code] = action;
  45. }
  46. }
  47. EWarningAction TWarningPolicy::GetAction(TIssueCode code) const
  48. {
  49. auto it = Overrides.find(code);
  50. return (it == Overrides.end()) ? BaseAction : it->second;
  51. }
  52. void TWarningPolicy::Clear()
  53. {
  54. BaseAction = EWarningAction::DEFAULT;
  55. Overrides.clear();
  56. Rules.clear();
  57. }
  58. }