1326454 - Introduce TokenStream::warning that warns at the current offset.

This commit is contained in:
Gaming4JC 2019-06-08 15:40:56 -04:00 • committed by Roy Tam
commit cd2bccf4c0
2 changed files with 14 additions and 10 deletions

View file

@ -777,7 +777,7 @@ TokenStream::reportErrorNoOffset(unsigned errorNumber, ...)
} }
bool bool
TokenStream::reportWarning(unsigned errorNumber, ...) TokenStream::warning(unsigned errorNumber, ...)
{ {
va_list args; va_list args;
va_start(args, errorNumber); va_start(args, errorNumber);
@ -958,9 +958,10 @@ TokenStream::getDirective(bool isMultiline, bool shouldWarnDeprecated,
int32_t c; int32_t c;
if (peekChars(directiveLength, peeked) && CharsMatch(peeked, directive)) { if (peekChars(directiveLength, peeked) && CharsMatch(peeked, directive)) {
if (shouldWarnDeprecated && if (shouldWarnDeprecated) {
!reportWarning(JSMSG_DEPRECATED_PRAGMA, errorMsgPragma)) if (!warning(JSMSG_DEPRECATED_PRAGMA, errorMsgPragma))
return false; return false;
}
skipChars(directiveLength); skipChars(directiveLength);
tokenbuf.clear(); tokenbuf.clear();
@ -1555,10 +1556,11 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
// grammar. We might not always be so permissive, so we warn // grammar. We might not always be so permissive, so we warn
// about it. // about it.
if (c >= '8') { if (c >= '8') {
if (!reportWarning(JSMSG_BAD_OCTAL, c == '8' ? "08" : "09")) { if (!warning(JSMSG_BAD_OCTAL, c == '8' ? "08" : "09"))
goto error; goto error;
}
goto decimal; // use the decimal scanner for the rest of the number // Use the decimal scanner for the rest of the number.
goto decimal;
} }
c = getCharIgnoreEOL(); c = getCharIgnoreEOL();
} }

View file

@ -364,16 +364,18 @@ class MOZ_STACK_CLASS TokenStream
// TokenStream-specific error reporters. // TokenStream-specific error reporters.
bool reportError(unsigned errorNumber, ...); bool reportError(unsigned errorNumber, ...);
bool reportErrorNoOffset(unsigned errorNumber, ...); bool reportErrorNoOffset(unsigned errorNumber, ...);
bool reportWarning(unsigned errorNumber, ...);
// Report the given error at the current offset. // Report the given error at the current offset.
void error(unsigned errorNumber, ...); void error(unsigned errorNumber, ...);
// Warn at the current offset.
MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
static const uint32_t NoOffset = UINT32_MAX; static const uint32_t NoOffset = UINT32_MAX;
// General-purpose error reporters. You should avoid calling these // General-purpose error reporters. You should avoid calling these
// directly, and instead use the more succinct alternatives (e.g. // directly, and instead use the more succinct alternatives (error(),
// reportError()) in TokenStream, Parser, and BytecodeEmitter. // warning(), &c.) in TokenStream, Parser, and BytecodeEmitter.
bool reportCompileErrorNumberVA(uint32_t offset, unsigned flags, unsigned errorNumber, bool reportCompileErrorNumberVA(uint32_t offset, unsigned flags, unsigned errorNumber,
va_list args); va_list args);
bool reportStrictModeErrorNumberVA(uint32_t offset, bool strictMode, unsigned errorNumber, bool reportStrictModeErrorNumberVA(uint32_t offset, bool strictMode, unsigned errorNumber,