Instead of having a source note per variable type, use a single source note with an immediate operand. bug 336378, r=brendan

git-svn-id: svn://10.0.0.236/trunk@198230 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mrbkap%gmail.com 2006-05-22 23:33:57 +00:00
parent 88941886a8
commit 5fda27c80f
3 changed files with 21 additions and 14 deletions

View File

@ -3321,12 +3321,12 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
* TOK_VAR case, conditioned on pn_extra flags set by the parser.
*
* In the 'for (var x = i in o) ...' case, the js_EmitTree(...pn3)
* called here will generate the SRC_VAR note for the assignment
* called here will generate the proper note for the assignment
* op that sets x = i, hoisting the initialized var declaration
* out of the loop: 'var x = i; for (x in o) ...'.
*
* In the 'for (var x in o) ...' case, nothing but the prolog op
* (if needed) should be generated here, we must emit the SRC_VAR
* (if needed) should be generated here, we must emit the note
* just before the JSOP_FOR* opcode in the switch on pn3->pn_type
* a bit below, so nothing is hoisted: 'for (var x in o) ...'.
*/
@ -3359,8 +3359,10 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
case TOK_VAR:
pn3 = pn3->pn_head;
JS_ASSERT(pn3->pn_type == TOK_NAME);
if (!pn3->pn_expr && js_NewSrcNote(cx, cg, SRC_VAR) < 0)
if (!pn3->pn_expr &&
js_NewSrcNote2(cx, cg, SRC_DECL, SRC_DECL_VAR) < 0) {
return JS_FALSE;
}
/* FALL THROUGH */
case TOK_NAME:
if (pn3->pn_slot >= 0) {
@ -4006,10 +4008,10 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
break;
if (pn2 == pn->pn_head &&
js_NewSrcNote(cx, cg,
(pn->pn_op == JSOP_DEFCONST)
? SRC_CONST
: SRC_VAR) < 0) {
js_NewSrcNote2(cx, cg, SRC_DECL,
(pn->pn_op == JSOP_DEFCONST)
? SRC_DECL_CONST
: SRC_DECL_VAR) < 0) {
return JS_FALSE;
}
if (op == JSOP_ARGUMENTS) {
@ -5155,7 +5157,7 @@ JS_FRIEND_DATA(JSSrcNoteSpec) js_SrcNoteSpec[] = {
{"while", 1, 0, 1},
{"for", 3, 1, 1},
{"continue", 0, 0, 0},
{"var", 0, 0, 0},
{"decl", 1, 0, 0},
{"pcdelta", 1, 0, 1},
{"assignop", 0, 0, 0},
{"cond", 1, 0, 1},
@ -5170,7 +5172,7 @@ JS_FRIEND_DATA(JSSrcNoteSpec) js_SrcNoteSpec[] = {
{"switch", 2, 0, 1},
{"funcdef", 1, 0, 0},
{"catch", 1, 11, 1},
{"const", 0, 0, 0},
{"unused21", 0, 0, 0},
{"newline", 0, 0, 0},
{"setline", 1, 0, 0},
{"xdelta", 0, 0, 0},

View File

@ -434,7 +434,7 @@ typedef enum JSSrcNoteType {
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break;
also used on JSOP_ENDINIT if extra comma
at end of array literal: [1,2,,] */
SRC_VAR = 6, /* JSOP_NAME/SETNAME/FORNAME in a var decl */
SRC_DECL = 6, /* type of a declaration (var, const, let*) */
SRC_PCDELTA = 7, /* distance from comma-operator to next POP,
or from CONDSWITCH to first CASE opcode --
or SRC_PCBASE variant for obj.function::foo
@ -454,12 +454,16 @@ typedef enum JSSrcNoteType {
2nd off to first JSOP_CASE if condswitch */
SRC_FUNCDEF = 19, /* JSOP_NOP for function f() with atomid */
SRC_CATCH = 20, /* catch block has guard */
SRC_CONST = 21, /* JSOP_SETCONST in a const decl */
SRC_UNUSED21 = 21, /* Unused source note */
SRC_NEWLINE = 22, /* bytecode follows a source newline */
SRC_SETLINE = 23, /* a file-absolute source line number note */
SRC_XDELTA = 24 /* 24-31 are for extended delta notes */
} JSSrcNoteType;
/* Constants for the SRC_DECL source note. */
#define SRC_DECL_VAR 0
#define SRC_DECL_CONST 1
#define SN_TYPE_BITS 5
#define SN_DELTA_BITS 3
#define SN_XDELTA_BITS 6

View File

@ -901,10 +901,11 @@ GetSlotAtom(JSPrinter *jp, JSPropertyOp getter, uintN slot)
static const char *
VarPrefix(jssrcnote *sn)
{
if (sn) {
if (SN_TYPE(sn) == SRC_VAR)
if (sn && SN_TYPE(sn) == SRC_DECL) {
ptrdiff_t type = js_GetSrcNoteOffset(sn, 0);
if (type == SRC_DECL_VAR)
return "var ";
if (SN_TYPE(sn) == SRC_CONST)
if (type == SRC_DECL_CONST)
return "const ";
}
return "";