Bug 1235410 - Centralize StmtType enumeration in a higher-order macro, so as not to have types and string descriptions of them go out of sync. As they happen to be now. ಠ_ಠ r=arai

This commit is contained in:
Jeff Walden 2015-12-23 21:50:32 -06:00
parent ab7db1e183
commit 46d79e9eed
2 changed files with 36 additions and 53 deletions

View File

@ -357,38 +357,22 @@ BytecodeEmitter::emitDupAt(unsigned slotFromTop)
return true;
}
/* XXX too many "... statement" L10N gaffes below -- fix via js.msg! */
const char js_with_statement_str[] = "with statement";
const char js_finally_block_str[] = "finally block";
static const char * const statementName[] = {
"label statement", /* LABEL */
"if statement", /* IF */
"else statement", /* ELSE */
"destructuring body", /* BODY */
"switch statement", /* SWITCH */
"block", /* BLOCK */
js_with_statement_str, /* WITH */
"catch block", /* CATCH */
"try block", /* TRY */
js_finally_block_str, /* FINALLY */
js_finally_block_str, /* SUBROUTINE */
"do loop", /* DO_LOOP */
"for loop", /* FOR_LOOP */
"for/in loop", /* FOR_IN_LOOP */
"for/of loop", /* FOR_OF_LOOP */
"while loop", /* WHILE_LOOP */
"spread", /* SPREAD */
};
static_assert(MOZ_ARRAY_LENGTH(statementName) == uint16_t(StmtType::LIMIT),
"statementName array and StmtType enum must be consistent");
static const char*
StatementName(StmtInfoBCE* stmt)
{
if (!stmt)
return js_script_str;
/* XXX too many "... statement" L10N gaffes -- fix via js.msg! */
static const char* const statementName[] = {
#define STATEMENT_TYPE_NAME(name, desc) desc,
FOR_EACH_STATEMENT_TYPE(STATEMENT_TYPE_NAME)
#undef STATEMENT_TYPE_NAME
};
static_assert(MOZ_ARRAY_LENGTH(statementName) == uint16_t(StmtType::LIMIT),
"statementName array and StmtType enum must be consistent");
return statementName[uint16_t(stmt->type)];
}

View File

@ -458,34 +458,33 @@ SharedContext::allLocalsAliased()
return bindingsAccessedDynamically() || (isFunctionBox() && asFunctionBox()->isGenerator());
}
// NOTE: If you add a new type of statement that is a scope, add it between
// WITH and CATCH, or you'll break StmtInfoBase::linksScope. If you add
// a non-looping statement type, add it before DO_LOOP or you'll break
// StmtInfoBase::isLoop().
#define FOR_EACH_STATEMENT_TYPE(macro) \
macro(LABEL, "label statement") \
macro(IF, "if statement") \
macro(ELSE, "else statement") \
macro(SEQ, "destructuring body") \
macro(BLOCK, "block") \
macro(SWITCH, "switch statement") \
macro(WITH, "with statement") \
macro(CATCH, "catch block") \
macro(TRY, "try block") \
macro(FINALLY, "finally block") \
macro(SUBROUTINE, "finally block") \
macro(DO_LOOP, "do loop") \
macro(FOR_LOOP, "for loop") \
macro(FOR_IN_LOOP, "for/in loop") \
macro(FOR_OF_LOOP, "for/of loop") \
macro(WHILE_LOOP, "while loop") \
macro(SPREAD, "spread")
/*
* NB: If you add a new type of statement that is a scope, add it between
* STMT_WITH and STMT_CATCH, or you will break StmtInfoBase::linksScope. If you
* add a non-looping statement type, add it before STMT_DO_LOOP or you will
* break StmtInfoBase::isLoop().
*
* Also remember to keep the statementName array in BytecodeEmitter.cpp in
* sync.
*/
enum class StmtType : uint16_t {
LABEL, /* labeled statement: L: s */
IF, /* if (then) statement */
ELSE, /* else clause of if statement */
SEQ, /* synthetic sequence of statements */
BLOCK, /* compound statement: { s1[;... sN] } */
SWITCH, /* switch statement */
WITH, /* with statement */
CATCH, /* catch block */
TRY, /* try block */
FINALLY, /* finally block */
SUBROUTINE, /* gosub-target subroutine body */
DO_LOOP, /* do/while loop statement */
FOR_LOOP, /* for loop statement */
FOR_IN_LOOP, /* for/in loop statement */
FOR_OF_LOOP, /* for/of loop statement */
WHILE_LOOP, /* while loop statement */
SPREAD, /* spread operator (pseudo for/of) */
#define DECLARE_STMTTYPE_ENUM(name, desc) name,
FOR_EACH_STATEMENT_TYPE(DECLARE_STMTTYPE_ENUM)
#undef DECLARE_STMTTYPE_ENUM
LIMIT
};