analyzer_error.h 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef ANALYZER_ERROR_H_
  6. #define ANALYZER_ERROR_H_
  7. #include <string>
  8. #include <string_view>
  9. #include <vector>
  10. #include "config.h"
  11. namespace analyzer {
  12. enum class ErrorLevel {
  13. Warning,
  14. Error,
  15. };
  16. static inline const char *
  17. GetErrorLevelName(ErrorLevel error_level)
  18. {
  19. switch (error_level) {
  20. case ErrorLevel::Warning:
  21. return "warning";
  22. case ErrorLevel::Error:
  23. return "error";
  24. }
  25. ANALYZER_UNREACHABLE;
  26. }
  27. class Error
  28. {
  29. public:
  30. Error()
  31. : error_level_(ErrorLevel::Error)
  32. {}
  33. Error(ErrorLevel error_level, std::string_view message)
  34. : error_level_(error_level)
  35. , message_(message)
  36. {}
  37. ErrorLevel error_level_;
  38. std::string message_;
  39. };
  40. using Errors = std::vector<Error>;
  41. } // namespace analyzer
  42. #endif