From 7f55eab5f9409834c0f5f02dcb67ca6a82084a42 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Wed, 23 Dec 2015 21:50:32 -0600 Subject: [PATCH] =?UTF-8?q?Bug=201235410=20-=20Centralize=20StmtType=20enu?= =?UTF-8?q?meration=20in=20a=20higher-order=20macro,=20so=20as=20not=20to?= =?UTF-8?q?=20have=20types=20and=20string=20descriptions=20of=20them=20go?= =?UTF-8?q?=20out=20of=20sync.=20=20As=20they=20happen=20to=20be=20now.=20?= =?UTF-8?q?=20=E0=B2=A0=5F=E0=B2=A0=20=20r=3Darai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/src/frontend/BytecodeEmitter.cpp | 38 +++++++-------------- js/src/frontend/SharedContext.h | 51 ++++++++++++++--------------- 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 54493a593121..74450a8fcd25 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -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)]; } diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 68028c0711cc..37d2b8ee76d8 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -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 };