common.cpp 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "common.h"
  2. namespace NProtoAST {
  3. IErrorCollector::IErrorCollector(size_t maxErrors)
  4. : MaxErrors(maxErrors)
  5. , NumErrors(0)
  6. {
  7. }
  8. IErrorCollector::~IErrorCollector()
  9. {
  10. }
  11. void IErrorCollector::Error(ui32 line, ui32 col, const TString& message) {
  12. if (NumErrors + 1 == MaxErrors) {
  13. AddError(0, 0, "Too many errors");
  14. ++NumErrors;
  15. }
  16. if (NumErrors >= MaxErrors) {
  17. ythrow TTooManyErrors() << "Too many errors";
  18. }
  19. AddError(line, col, message);
  20. ++NumErrors;
  21. }
  22. TErrorOutput::TErrorOutput(IOutputStream& err, const TString& name, size_t maxErrors)
  23. : IErrorCollector(maxErrors)
  24. , Err(err)
  25. , Name(name)
  26. {
  27. }
  28. TErrorOutput::~TErrorOutput()
  29. {
  30. }
  31. void TErrorOutput::AddError(ui32 line, ui32 col, const TString& message) {
  32. if (!Name.empty()) {
  33. Err << "Query " << Name << ": ";
  34. }
  35. Err << "Line " << line << " column " << col << " error: " << message;
  36. }
  37. }