Backed out changeset 097c455f81fa (bug 1066827)

This commit is contained in:
Carsten "Tomcat" Book 2014-10-28 12:22:57 +01:00
parent cc25a0302d
commit 70d338266b
3 changed files with 17 additions and 11 deletions

View File

@ -196,6 +196,7 @@ namespace frontend {
// Values of this type are used to index into arrays such as isExprEnding[],
// so the first value must be zero.
enum TokenKind {
TOK_ERROR = 0,
#define EMIT_ENUM(name, desc) TOK_##name,
#define EMIT_ENUM_RANGE(name, value) TOK_##name = TOK_##value,
FOR_EACH_TOKEN_KIND_WITH_RANGE(EMIT_ENUM, EMIT_ENUM_RANGE)

View File

@ -516,14 +516,13 @@ TokenStream::TokenBuf::findEOLMax(const char16_t *p, size_t max)
void
TokenStream::advance(size_t position)
{
MOZ_ASSERT(position <= mozilla::PointerRangeSize(userbuf.base(), userbuf.limit()));
const char16_t *end = userbuf.base() + position;
while (userbuf.addressOfNextRawChar() < end)
getChar();
Token *cur = &tokens[cursor];
cur->pos.begin = userbuf.addressOfNextRawChar() - userbuf.base();
MOZ_MAKE_MEM_UNDEFINED(&cur->type, sizeof(cur->type));
cur->type = TOK_ERROR;
lookahead = 0;
}
@ -944,7 +943,7 @@ IsTokenSane(Token *tp)
{
// Nb: TOK_EOL should never be used in an actual Token; it should only be
// returned as a TokenKind from peekTokenSameLine().
if (tp->type < 0 || tp->type >= TOK_LIMIT || tp->type == TOK_EOL)
if (tp->type < TOK_ERROR || tp->type >= TOK_LIMIT || tp->type == TOK_EOL)
return false;
if (tp->pos.end < tp->pos.begin)
@ -1632,16 +1631,19 @@ TokenStream::getTokenInternal(TokenKind *ttp, Modifier modifier)
error:
flags.isDirtyLine = true;
tp->pos.end = userbuf.addressOfNextRawChar() - userbuf.base();
MOZ_MAKE_MEM_UNDEFINED(&tp->type, sizeof(tp->type));
tp->type = TOK_ERROR;
flags.hadError = true;
#ifdef DEBUG
// Poisoning userbuf on error establishes an invariant: once an erroneous
// token has been seen, userbuf will not be consulted again. This is true
// because the parser will deal with the illegal token by aborting parsing
// immediately.
// because the parser will either (a) deal with the TOK_ERROR token by
// aborting parsing immediately; or (b) if the TOK_ERROR token doesn't
// match what it expected, it will unget the token, and the next getToken()
// call will immediately return the just-gotten TOK_ERROR token again
// without consulting userbuf, thanks to the lookahead buffer.
userbuf.poison();
#endif
MOZ_MAKE_MEM_UNDEFINED(ttp, sizeof(*ttp));
*ttp = TOK_ERROR;
return false;
}
@ -1807,6 +1809,9 @@ frontend::TokenKindToDesc(TokenKind tt)
#define EMIT_CASE(name, desc) case TOK_##name: return desc;
FOR_EACH_TOKEN_KIND(EMIT_CASE)
#undef EMIT_CASE
case TOK_ERROR:
MOZ_ASSERT_UNREACHABLE("TOK_ERROR should not be passed.");
break;
case TOK_LIMIT:
MOZ_ASSERT_UNREACHABLE("TOK_LIMIT should not be passed.");
break;
@ -1823,6 +1828,7 @@ TokenKindToString(TokenKind tt)
#define EMIT_CASE(name, desc) case TOK_##name: return "TOK_" #name;
FOR_EACH_TOKEN_KIND(EMIT_CASE)
#undef EMIT_CASE
case TOK_ERROR: return "TOK_ERROR";
case TOK_LIMIT: break;
}

View File

@ -105,9 +105,9 @@ struct Token
// pointer, and it's only initialized a very few places, so having a
// user-defined constructor won't hurt perf.) See also bug 920318.
Token()
: pos(0, 0)
: type(TOK_ERROR),
pos(0, 0)
{
MOZ_MAKE_MEM_UNDEFINED(&type, sizeof(type));
}
// Mutators
@ -347,8 +347,7 @@ class MOZ_STACK_CLASS TokenStream
bool isEOF:1; // Hit end of file.
bool isDirtyLine:1; // Non-whitespace since start of line.
bool sawOctalEscape:1; // Saw an octal character escape.
bool hadError:1; // Hit a syntax error, at start or during a
// token.
bool hadError:1; // Returned TOK_ERROR from getToken.
Flags()
: isEOF(), isDirtyLine(), sawOctalEscape(), hadError()