michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* diagnostic reporting for CSS style sheet parser */ michael@0: michael@0: #ifndef mozilla_css_ErrorReporter_h_ michael@0: #define mozilla_css_ErrorReporter_h_ michael@0: michael@0: // XXX turn this off for minimo builds michael@0: #define CSS_REPORT_PARSE_ERRORS michael@0: michael@0: #include "nsString.h" michael@0: michael@0: struct nsCSSToken; michael@0: class nsCSSStyleSheet; michael@0: class nsCSSScanner; michael@0: class nsIURI; michael@0: michael@0: namespace mozilla { michael@0: namespace css { michael@0: michael@0: class Loader; michael@0: michael@0: // If CSS_REPORT_PARSE_ERRORS is not defined, all of this class's michael@0: // methods become inline stubs. michael@0: class MOZ_STACK_CLASS ErrorReporter { michael@0: public: michael@0: ErrorReporter(const nsCSSScanner &aScanner, michael@0: const nsCSSStyleSheet *aSheet, michael@0: const Loader *aLoader, michael@0: nsIURI *aURI); michael@0: ~ErrorReporter(); michael@0: michael@0: static void ReleaseGlobals(); michael@0: michael@0: void OutputError(); michael@0: void OutputError(uint32_t aLineNumber, uint32_t aLineOffset); michael@0: void ClearError(); michael@0: michael@0: // In all overloads of ReportUnexpected, aMessage is a stringbundle michael@0: // name, which will be processed as a format string with the michael@0: // indicated number of parameters. michael@0: michael@0: // no parameters michael@0: void ReportUnexpected(const char *aMessage); michael@0: // one parameter, a string michael@0: void ReportUnexpected(const char *aMessage, const nsString& aParam); michael@0: // one parameter, a token michael@0: void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken); michael@0: // two parameters, a token and a character, in that order michael@0: void ReportUnexpected(const char *aMessage, const nsCSSToken& aToken, michael@0: char16_t aChar); michael@0: michael@0: // for ReportUnexpectedEOF, aExpected can be either a stringbundle michael@0: // name or a single character. In the former case there may not be michael@0: // any format parameters. michael@0: void ReportUnexpectedEOF(const char *aExpected); michael@0: void ReportUnexpectedEOF(char16_t aExpected); michael@0: michael@0: private: michael@0: void AddToError(const nsString &aErrorText); michael@0: michael@0: #ifdef CSS_REPORT_PARSE_ERRORS michael@0: nsAutoString mError; michael@0: nsString mErrorLine; michael@0: nsString mFileName; michael@0: const nsCSSScanner *mScanner; michael@0: const nsCSSStyleSheet *mSheet; michael@0: const Loader *mLoader; michael@0: nsIURI *mURI; michael@0: uint64_t mInnerWindowID; michael@0: uint32_t mErrorLineNumber; michael@0: uint32_t mPrevErrorLineNumber; michael@0: uint32_t mErrorColNumber; michael@0: #endif michael@0: }; michael@0: michael@0: #ifndef CSS_REPORT_PARSE_ERRORS michael@0: inline ErrorReporter::ErrorReporter(const nsCSSScanner&, michael@0: const nsCSSStyleSheet*, michael@0: const Loader*, michael@0: nsIURI*) {} michael@0: inline ErrorReporter::~ErrorReporter() {} michael@0: michael@0: inline void ErrorReporter::ReleaseGlobals() {} michael@0: michael@0: inline void ErrorReporter::OutputError() {} michael@0: inline void ErrorReporter::ClearError() {} michael@0: michael@0: inline void ErrorReporter::ReportUnexpected(const char *) {} michael@0: inline void ErrorReporter::ReportUnexpected(const char *, const nsString &) {} michael@0: inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &) {} michael@0: inline void ErrorReporter::ReportUnexpected(const char *, const nsCSSToken &, michael@0: char16_t) {} michael@0: michael@0: inline void ErrorReporter::ReportUnexpectedEOF(const char *) {} michael@0: inline void ErrorReporter::ReportUnexpectedEOF(char16_t) {} michael@0: michael@0: inline void ErrorReporter::AddToError(const nsString &) {} michael@0: #endif michael@0: michael@0: } // namespace css michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_css_ErrorReporter_h_