ErrorReporter.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* diagnostic reporting for CSS style sheet parser */
  6. #ifndef mozilla_css_ErrorReporter_h_
  7. #define mozilla_css_ErrorReporter_h_
  8. // XXX turn this off for minimo builds
  9. #define CSS_REPORT_PARSE_ERRORS
  10. #include "nsString.h"
  11. struct nsCSSToken;
  12. class nsCSSScanner;
  13. class nsIURI;
  14. namespace mozilla {
  15. class CSSStyleSheet;
  16. namespace css {
  17. class Loader;
  18. // If CSS_REPORT_PARSE_ERRORS is not defined, all of this class's
  19. // methods become inline stubs.
  20. class MOZ_STACK_CLASS ErrorReporter {
  21. public:
  22. ErrorReporter(const nsCSSScanner &aScanner,
  23. const CSSStyleSheet *aSheet,
  24. const Loader *aLoader,
  25. nsIURI *aURI);
  26. ~ErrorReporter();
  27. static void ReleaseGlobals();
  28. void OutputError();
  29. void OutputError(uint32_t aLineNumber, uint32_t aLineOffset);
  30. void ClearError();
  31. // In all overloads of ReportUnexpected, aMessage is a stringbundle
  32. // name, which will be processed as a format string with the
  33. // indicated number of parameters.
  34. // no parameters
  35. void ReportUnexpected(const char *aMessage);
  36. // one parameter, a string
  37. void ReportUnexpected(const char *aMessage, const nsString& aParam);
  38. // one parameter, a token
  39. void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken);
  40. // two parameters, a token and a character, in that order
  41. void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken,
  42. char16_t aChar);
  43. // two parameters, a param and a value
  44. void ReportUnexpected(const char *aMessage, const nsString& aParam,
  45. const nsString& aValue);
  46. // for ReportUnexpectedEOF, aExpected can be either a stringbundle
  47. // name or a single character. In the former case there may not be
  48. // any format parameters.
  49. void ReportUnexpectedEOF(const char *aExpected);
  50. void ReportUnexpectedEOF(char16_t aExpected);
  51. private:
  52. void AddToError(const nsString &aErrorText);
  53. #ifdef CSS_REPORT_PARSE_ERRORS
  54. nsAutoString mError;
  55. nsString mErrorLine;
  56. nsString mFileName;
  57. const nsCSSScanner *mScanner;
  58. const CSSStyleSheet *mSheet;
  59. const Loader *mLoader;
  60. nsIURI *mURI;
  61. uint64_t mInnerWindowID;
  62. uint32_t mErrorLineNumber;
  63. uint32_t mPrevErrorLineNumber;
  64. uint32_t mErrorColNumber;
  65. #endif
  66. };
  67. #ifndef CSS_REPORT_PARSE_ERRORS
  68. inline ErrorReporter::ErrorReporter(const nsCSSScanner&,
  69. const CSSStyleSheet*,
  70. const Loader*,
  71. nsIURI*) {}
  72. inline ErrorReporter::~ErrorReporter() {}
  73. inline void ErrorReporter::ReleaseGlobals() {}
  74. inline void ErrorReporter::OutputError() {}
  75. inline void ErrorReporter::ClearError() {}
  76. inline void ErrorReporter::ReportUnexpected(const char *) {}
  77. inline void ErrorReporter::ReportUnexpected(const char *, const nsString &) {}
  78. inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &) {}
  79. inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &,
  80. char16_t) {}
  81. inline void ErrorReporter::ReportUnexpected(const char *, const nsString &,
  82. const nsString &) {}
  83. inline void ErrorReporter::ReportUnexpectedEOF(const char *) {}
  84. inline void ErrorReporter::ReportUnexpectedEOF(char16_t) {}
  85. inline void ErrorReporter::AddToError(const nsString &) {}
  86. #endif
  87. } // namespace css
  88. } // namespace mozilla
  89. #endif // mozilla_css_ErrorReporter_h_