yql_issue_manager.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include "yql_issue.h"
  3. #include "yql_warning.h"
  4. #include <util/generic/maybe.h>
  5. #include <util/generic/stack.h>
  6. #include <util/generic/hash_set.h>
  7. #include <array>
  8. namespace NYql {
  9. class TIssueManager: private TNonCopyable {
  10. public:
  11. void AddScope(std::function<TIssuePtr()> fn);
  12. void LeaveScope();
  13. void RaiseIssue(const TIssue& issue);
  14. void RaiseIssues(const TIssues& issues);
  15. bool RaiseWarning(TIssue issue);
  16. void AddIssues(const TIssues& errors);
  17. void AddIssues(const TPosition& pos, const TIssues& issues);
  18. TIssues GetIssues();
  19. TIssues GetCompletedIssues() const;
  20. void Reset(const TIssues& issues);
  21. void Reset();
  22. void AddWarningRule(const TWarningRule &rule);
  23. void SetWarningToErrorTreatMessage(const TString& msg);
  24. void SetIssueCountLimit(size_t limit) {
  25. IssueLimit_ = limit;
  26. }
  27. void RaiseIssueForEmptyScope();
  28. private:
  29. TIssuePtr CheckUniqAndLimit(const TIssue& issue);
  30. TIssuePtr CheckUniqAndLimit(TIssuePtr issue);
  31. void LeaveAllScopes();
  32. bool HasOpenScopes() const;
  33. struct TIssueHash {
  34. ui64 operator()(const TIssuePtr& p) {
  35. return p->Hash();
  36. }
  37. };
  38. struct TIssueEqual {
  39. bool operator()(const TIssuePtr& l, const TIssuePtr& r) {
  40. return *l == *r;
  41. }
  42. };
  43. TStack<std::pair<TMaybe<TIssuePtr>, std::function<TIssuePtr()>>> RawIssues_;
  44. TIssues CompletedIssues_;
  45. TMaybe<TString> WarningToErrorTreatMessage_;
  46. TWarningPolicy WarningPolicy_;
  47. std::array<TIssuePtr, NYql::TSeverityIds::ESeverityId_ARRAYSIZE> OverflowIssues_;
  48. std::array<THashSet<TIssuePtr, TIssueHash, TIssueEqual>, NYql::TSeverityIds::ESeverityId_ARRAYSIZE> UniqueIssues_;
  49. size_t IssueLimit_ = 0;
  50. };
  51. class TIssueScopeGuard: private TNonCopyable {
  52. TIssueManager& Manager_;
  53. public:
  54. TIssueScopeGuard(TIssueManager& manager, std::function<TIssuePtr()> fn)
  55. : Manager_(manager)
  56. {
  57. Manager_.AddScope(fn);
  58. }
  59. void RaiseIssueForEmptyScope() {
  60. Manager_.RaiseIssueForEmptyScope();
  61. }
  62. ~TIssueScopeGuard()
  63. {
  64. Manager_.LeaveScope();
  65. }
  66. };
  67. }