diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index ec83472f37b..479a21f5939 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4511,8 +4511,8 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT; - script = JSCompiler::compileScript(cx, obj, NULL, principals, tcflags, - chars, length, NULL, filename, lineno); + script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, + chars, length, NULL, filename, lineno); LAST_FRAME_CHECKS(cx, script); return script; } @@ -4538,11 +4538,11 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, result = JS_TRUE; exnState = JS_SaveExceptionState(cx); { - JSCompiler jsc(cx); - if (jsc.init(chars, length, NULL, NULL, 1)) { + Parser parser(cx); + if (parser.init(chars, length, NULL, NULL, 1)) { older = JS_SetErrorReporter(cx, NULL); - if (!jsc.parse(obj) && - jsc.tokenStream.isUnexpectedEOF()) { + if (!parser.parse(obj) && + parser.tokenStream.isUnexpectedEOF()) { /* * We ran into an error. If it was because we ran out of * source, we return false so our caller knows to try to @@ -4578,8 +4578,8 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename) } tcflags = JS_OPTIONS_TO_TCFLAGS(cx); - script = JSCompiler::compileScript(cx, obj, NULL, NULL, tcflags, - NULL, 0, fp, filename, 1); + script = Compiler::compileScript(cx, obj, NULL, NULL, tcflags, + NULL, 0, fp, filename, 1); if (fp != stdin) fclose(fp); LAST_FRAME_CHECKS(cx, script); @@ -4603,8 +4603,8 @@ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, CHECK_REQUEST(cx); tcflags = JS_OPTIONS_TO_TCFLAGS(cx); - script = JSCompiler::compileScript(cx, obj, NULL, principals, tcflags, - NULL, 0, file, filename, 1); + script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, + NULL, 0, file, filename, 1); LAST_FRAME_CHECKS(cx, script); return script; } @@ -4743,8 +4743,8 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj, } } - if (!JSCompiler::compileFunctionBody(cx, fun, principals, - chars, length, filename, lineno)) { + if (!Compiler::compileFunctionBody(cx, fun, principals, + chars, length, filename, lineno)) { fun = NULL; goto out; } @@ -4892,11 +4892,11 @@ JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, JSBool ok; CHECK_REQUEST(cx); - script = JSCompiler::compileScript(cx, obj, NULL, principals, - !rval - ? TCF_COMPILE_N_GO | TCF_NO_SCRIPT_RVAL - : TCF_COMPILE_N_GO, - chars, length, NULL, filename, lineno); + script = Compiler::compileScript(cx, obj, NULL, principals, + !rval + ? TCF_COMPILE_N_GO | TCF_NO_SCRIPT_RVAL + : TCF_COMPILE_N_GO, + chars, length, NULL, filename, lineno); if (!script) { LAST_FRAME_CHECKS(cx, script); return JS_FALSE; diff --git a/js/src/jsatom.cpp b/js/src/jsatom.cpp index a5bd4838400..2cfe6981506 100644 --- a/js/src/jsatom.cpp +++ b/js/src/jsatom.cpp @@ -60,6 +60,8 @@ #include "jsversion.h" #include "jsstrinlines.h" +using namespace js; + /* * ATOM_HASH assumes that JSHashNumber is 32-bit even on 64-bit systems. */ @@ -956,23 +958,23 @@ JS_STATIC_ASSERT(TEMP_SIZE_START >= sizeof(JSHashTable)); static void * js_alloc_temp_space(void *priv, size_t size) { - JSCompiler *jsc = (JSCompiler *) priv; + Parser *parser = (Parser *) priv; void *space; if (size < TEMP_SIZE_LIMIT) { int bin = JS_CeilingLog2(size) - TEMP_SIZE_START_LOG2; JS_ASSERT(unsigned(bin) < NUM_TEMP_FREELISTS); - space = jsc->tempFreeList[bin]; + space = parser->tempFreeList[bin]; if (space) { - jsc->tempFreeList[bin] = *(void **)space; + parser->tempFreeList[bin] = *(void **)space; return space; } } - JS_ARENA_ALLOCATE(space, &jsc->context->tempPool, size); + JS_ARENA_ALLOCATE(space, &parser->context->tempPool, size); if (!space) - js_ReportOutOfScriptQuota(jsc->context); + js_ReportOutOfScriptQuota(parser->context); return space; } @@ -982,29 +984,29 @@ js_free_temp_space(void *priv, void *item, size_t size) if (size >= TEMP_SIZE_LIMIT) return; - JSCompiler *jsc = (JSCompiler *) priv; + Parser *parser = (Parser *) priv; int bin = JS_CeilingLog2(size) - TEMP_SIZE_START_LOG2; JS_ASSERT(unsigned(bin) < NUM_TEMP_FREELISTS); - *(void **)item = jsc->tempFreeList[bin]; - jsc->tempFreeList[bin] = item; + *(void **)item = parser->tempFreeList[bin]; + parser->tempFreeList[bin] = item; } static JSHashEntry * js_alloc_temp_entry(void *priv, const void *key) { - JSCompiler *jsc = (JSCompiler *) priv; + Parser *parser = (Parser *) priv; JSAtomListElement *ale; - ale = jsc->aleFreeList; + ale = parser->aleFreeList; if (ale) { - jsc->aleFreeList = ALE_NEXT(ale); + parser->aleFreeList = ALE_NEXT(ale); return &ale->entry; } - JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &jsc->context->tempPool); + JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &parser->context->tempPool); if (!ale) { - js_ReportOutOfScriptQuota(jsc->context); + js_ReportOutOfScriptQuota(parser->context); return NULL; } return &ale->entry; @@ -1013,11 +1015,11 @@ js_alloc_temp_entry(void *priv, const void *key) static void js_free_temp_entry(void *priv, JSHashEntry *he, uintN flag) { - JSCompiler *jsc = (JSCompiler *) priv; + Parser *parser = (Parser *) priv; JSAtomListElement *ale = (JSAtomListElement *) he; - ALE_SET_NEXT(ale, jsc->aleFreeList); - jsc->aleFreeList = ale; + ALE_SET_NEXT(ale, parser->aleFreeList); + parser->aleFreeList = ale; } static JSHashAllocOps temp_alloc_ops = { @@ -1053,7 +1055,7 @@ JSAtomList::rawLookup(JSAtom *atom, JSHashEntry **&hep) #define ATOM_LIST_HASH_THRESHOLD 12 JSAtomListElement * -JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how) +JSAtomList::add(Parser *parser, JSAtom *atom, AddHow how) { JS_ASSERT(!set); @@ -1064,7 +1066,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how) if (!ale || how != UNIQUE) { if (count < ATOM_LIST_HASH_THRESHOLD && !table) { /* Few enough for linear search and no hash table yet needed. */ - ale = (JSAtomListElement *)js_alloc_temp_entry(jsc, atom); + ale = (JSAtomListElement *)js_alloc_temp_entry(parser, atom); if (!ale) return NULL; ALE_SET_ATOM(ale, atom); @@ -1090,7 +1092,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how) JS_ASSERT(!hep); table = JS_NewHashTable(count + 1, js_hash_atom_ptr, JS_CompareValues, JS_CompareValues, - &temp_alloc_ops, jsc); + &temp_alloc_ops, parser); if (!table) return NULL; @@ -1150,7 +1152,7 @@ JSAtomList::add(JSCompiler *jsc, JSAtom *atom, AddHow how) } void -JSAtomList::rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep) +JSAtomList::rawRemove(Parser *parser, JSAtomListElement *ale, JSHashEntry **hep) { JS_ASSERT(!set); JS_ASSERT(count != 0); @@ -1166,7 +1168,7 @@ JSAtomList::rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep hep = &(*hep)->next; } *hep = ale->entry.next; - js_free_temp_entry(jsc, &ale->entry, HT_FREE_ENTRY); + js_free_temp_entry(parser, &ale->entry, HT_FREE_ENTRY); } --count; @@ -1180,7 +1182,7 @@ JSAutoAtomList::~JSAutoAtomList() JSHashEntry *hep = list; while (hep) { JSHashEntry *next = hep->next; - js_free_temp_entry(compiler, hep, HT_FREE_ENTRY); + js_free_temp_entry(parser, hep, HT_FREE_ENTRY); hep = next; } } diff --git a/js/src/jsatom.h b/js/src/jsatom.h index 98d7e9bf276..15d52a95790 100644 --- a/js/src/jsatom.h +++ b/js/src/jsatom.h @@ -152,16 +152,16 @@ struct JSAtomList : public JSAtomSet enum AddHow { UNIQUE, SHADOW, HOIST }; - JSAtomListElement *add(JSCompiler *jsc, JSAtom *atom, AddHow how = UNIQUE); + JSAtomListElement *add(js::Parser *parser, JSAtom *atom, AddHow how = UNIQUE); - void remove(JSCompiler *jsc, JSAtom *atom) { + void remove(js::Parser *parser, JSAtom *atom) { JSHashEntry **hep; JSAtomListElement *ale = rawLookup(atom, hep); if (ale) - rawRemove(jsc, ale, hep); + rawRemove(parser, ale, hep); } - void rawRemove(JSCompiler *jsc, JSAtomListElement *ale, JSHashEntry **hep); + void rawRemove(js::Parser *parser, JSAtomListElement *ale, JSHashEntry **hep); }; /* @@ -170,10 +170,10 @@ struct JSAtomList : public JSAtomSet */ struct JSAutoAtomList: public JSAtomList { - JSAutoAtomList(JSCompiler *c): compiler(c) {} + JSAutoAtomList(js::Parser *p): parser(p) {} ~JSAutoAtomList(); private: - JSCompiler *compiler; /* For freeing list entries. */ + js::Parser *parser; /* For freeing list entries. */ }; /* diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index f852fb1882b..1b9f292aa8c 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -1649,7 +1649,7 @@ class AutoGCRooter { JSVAL = -1, /* js::AutoValueRooter */ SPROP = -2, /* js::AutoScopePropertyRooter */ WEAKROOTS = -3, /* js::AutoSaveWeakRoots */ - COMPILER = -4, /* JSCompiler */ + PARSER = -4, /* js::Parser */ SCRIPT = -5, /* js::AutoScriptRooter */ ENUMERATOR = -6, /* js::AutoEnumStateRooter */ IDARRAY = -7, /* js::AutoIdArray */ diff --git a/js/src/jscntxtinlines.h b/js/src/jscntxtinlines.h index 3141959102c..ff633e08c5b 100644 --- a/js/src/jscntxtinlines.h +++ b/js/src/jscntxtinlines.h @@ -81,8 +81,8 @@ AutoGCRooter::trace(JSTracer *trc) static_cast(this)->savedRoots.mark(trc); return; - case COMPILER: - static_cast(this)->trace(trc); + case PARSER: + static_cast(this)->trace(trc); return; case SCRIPT: diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 5de4ad9393c..7a40046e5c6 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -1344,9 +1344,9 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp, * we use a static level that will cause us not to attempt to optimize * variable references made by this frame. */ - script = JSCompiler::compileScript(cx, scobj, fp, JS_StackFramePrincipals(cx, fp), - TCF_COMPILE_N_GO, chars, length, NULL, - filename, lineno, NULL, JS_DISPLAY_SIZE); + script = Compiler::compileScript(cx, scobj, fp, JS_StackFramePrincipals(cx, fp), + TCF_COMPILE_N_GO, chars, length, NULL, + filename, lineno, NULL, JS_DISPLAY_SIZE); if (!script) return JS_FALSE; diff --git a/js/src/jsemit.cpp b/js/src/jsemit.cpp index f53c6c8a6b9..35691a00061 100644 --- a/js/src/jsemit.cpp +++ b/js/src/jsemit.cpp @@ -85,10 +85,10 @@ static JSBool NewTryNote(JSContext *cx, JSCodeGenerator *cg, JSTryNoteKind kind, uintN stackDepth, size_t start, size_t end); -JSCodeGenerator::JSCodeGenerator(JSCompiler *jsc, +JSCodeGenerator::JSCodeGenerator(Parser *parser, JSArenaPool *cpool, JSArenaPool *npool, uintN lineno) - : JSTreeContext(jsc), + : JSTreeContext(parser), codePool(cpool), notePool(npool), codeMark(JS_ARENA_MARK(cpool)), noteMark(JS_ARENA_MARK(npool)), stackDepth(0), maxStackDepth(0), @@ -114,10 +114,10 @@ JSCodeGenerator::~JSCodeGenerator() /* NB: non-null only after OOM. */ if (spanDeps) - compiler->context->free(spanDeps); + parser->context->free(spanDeps); if (upvarMap.vector) - compiler->context->free(upvarMap.vector); + parser->context->free(upvarMap.vector); } static ptrdiff_t @@ -189,7 +189,7 @@ UpdateDepth(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t target) TokenStream *ts; JS_snprintf(numBuf, sizeof numBuf, "%d", target); - ts = &cg->compiler->tokenStream; + ts = &cg->parser->tokenStream; JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, js_GetErrorMessage, NULL, JSMSG_STACK_UNDERFLOW, @@ -895,7 +895,7 @@ OptimizeSpanDeps(JSContext *cx, JSCodeGenerator *cg) if (growth) { #ifdef DEBUG_brendan - TokenStream *ts = &cg->compiler->tokenStream; + TokenStream *ts = &cg->parser->tokenStream; printf("%s:%u: %u/%u jumps extended in %d passes (%d=%d+%d)\n", ts->filename ? ts->filename : "stdin", cg->firstLine, @@ -1258,7 +1258,7 @@ JSTreeContext::ensureSharpSlots() JS_ASSERT(!(flags & TCF_HAS_SHARPS)); if (flags & TCF_IN_FUNCTION) { - JSContext *cx = compiler->context; + JSContext *cx = parser->context; JSAtom *sharpArrayAtom = js_Atomize(cx, "#array", 6, 0); JSAtom *sharpDepthAtom = js_Atomize(cx, "#depth", 6, 0); if (!sharpArrayAtom || !sharpDepthAtom) @@ -1271,7 +1271,7 @@ JSTreeContext::ensureSharpSlots() return false; } else { /* - * JSCompiler::compileScript will rebase immediate operands indexing + * Compiler::compileScript will rebase immediate operands indexing * the sharp slots to come at the end of the global script's |nfixed| * slots storage, after gvars and regexps. */ @@ -1562,7 +1562,7 @@ js_DefineCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom, return JS_FALSE; v = ATOM_KEY(valueAtom); } - ale = cg->constList.add(cg->compiler, atom); + ale = cg->constList.add(cg->parser, atom); if (!ale) return JS_FALSE; ALE_SET_VALUE(ale, v); @@ -1773,7 +1773,7 @@ EmitAtomOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg) pn->pn_atom == cx->runtime->atomState.lengthAtom) { return js_Emit1(cx, cg, JSOP_LENGTH) >= 0; } - ale = cg->atomList.add(cg->compiler, pn->pn_atom); + ale = cg->atomList.add(cg->parser, pn->pn_atom); if (!ale) return JS_FALSE; return EmitIndexOp(cx, op, ALE_INDEX(ale), cg); @@ -1826,7 +1826,7 @@ EmitSlotIndexOp(JSContext *cx, JSOp op, uintN slot, uintN index, * Adjust the slot for a block local to account for the number of variables * that share the same index space with locals. Due to the incremental code * generation for top-level script, we do the adjustment via code patching in - * JSCompiler::compileScript; see comments there. + * Compiler::compileScript; see comments there. * * The function returns -1 on failures. */ @@ -1894,15 +1894,15 @@ EmitEnterBlock(JSContext *cx, JSParseNode *pn, JSCodeGenerator *cg) * lazily, growing upvarMap.vector by powers of two. * * This function knows that it is called with pn pointing to a PN_NAME-arity - * node, and cg->compiler->callerFrame having a non-null fun member, and the + * node, and cg->parser->callerFrame having a non-null fun member, and the * static level of cg at least one greater than the eval-calling function's * static level. */ static bool MakeUpvarForEval(JSParseNode *pn, JSCodeGenerator *cg) { - JSContext *cx = cg->compiler->context; - JSFunction *fun = cg->compiler->callerFrame->fun; + JSContext *cx = cg->parser->context; + JSFunction *fun = cg->parser->callerFrame->fun; uintN upvarLevel = fun->u.i.script->staticLevel; JSFunctionBox *funbox = cg->funbox; @@ -1947,7 +1947,7 @@ MakeUpvarForEval(JSParseNode *pn, JSCodeGenerator *cg) return false; } - ale = cg->upvarList.add(cg->compiler, atom); + ale = cg->upvarList.add(cg->parser, atom); if (!ale) return false; JS_ASSERT(ALE_INDEX(ale) == cg->upvarList.count - 1); @@ -2050,7 +2050,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) * Turn JSOP_DELNAME into JSOP_FALSE if dn is known, as all declared * bindings visible to the compiler are permanent in JS unless the * declaration originates in eval code. We detect eval code by testing - * cg->compiler->callerFrame, which is set only by eval or a debugger + * cg->parser->callerFrame, which is set only by eval or a debugger * equivalent. * * Note that this callerFrame non-null test must be qualified by testing @@ -2063,7 +2063,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) break; case JSOP_DELNAME: if (dn_kind != JSDefinition::UNKNOWN) { - if (cg->compiler->callerFrame && !cg->funbox) + if (cg->parser->callerFrame && !cg->funbox) JS_ASSERT(cg->flags & TCF_COMPILE_N_GO); else pn->pn_op = JSOP_FALSE; @@ -2077,7 +2077,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) } if (cookie == FREE_UPVAR_COOKIE) { - JSStackFrame *caller = cg->compiler->callerFrame; + JSStackFrame *caller = cg->parser->callerFrame; if (caller) { JS_ASSERT(cg->flags & TCF_COMPILE_N_GO); @@ -2096,12 +2096,12 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) * Make sure the variable object used by the compiler to initialize * parent links matches the caller's varobj. Compile-n-go compiler- * created function objects have the top-level cg's scopeChain set - * as their parent by JSCompiler::newFunction. + * as their parent by Parser::newFunction. */ JSObject *scopeobj = (cg->flags & TCF_IN_FUNCTION) ? FUN_OBJECT(cg->fun)->getParent() : cg->scopeChain; - if (scopeobj != cg->compiler->callerVarObj) + if (scopeobj != cg->parser->callerVarObj) return JS_TRUE; /* @@ -2118,7 +2118,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) * defeats the display optimization to static link searching used * by JSOP_{GET,CALL}UPVAR. */ - JSFunction *fun = cg->compiler->callerFrame->fun; + JSFunction *fun = cg->parser->callerFrame->fun; JS_ASSERT(cg->staticLevel >= fun->u.i.script->staticLevel); unsigned skip = cg->staticLevel - fun->u.i.script->staticLevel; if (cg->skipSpansGenerator(skip)) @@ -2184,7 +2184,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) return JS_TRUE; #ifdef DEBUG - JSStackFrame *caller = cg->compiler->callerFrame; + JSStackFrame *caller = cg->parser->callerFrame; #endif JS_ASSERT(caller); JS_ASSERT(caller->script); @@ -2196,7 +2196,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) JSCodeGenerator *evalcg = (JSCodeGenerator *) tc; JS_ASSERT(evalcg->flags & TCF_COMPILE_N_GO); - JS_ASSERT(caller->fun && cg->compiler->callerVarObj == evalcg->scopeChain); + JS_ASSERT(caller->fun && cg->parser->callerVarObj == evalcg->scopeChain); /* * Don't generate upvars on the left side of a for loop. See @@ -2241,7 +2241,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) /* * The function we're compiling may not be heavyweight, but if it * escapes as a funarg, we can't use JSOP_GETUPVAR/JSOP_CALLUPVAR. - * JSCompiler::analyzeFunctions has arranged for this function's + * Parser::analyzeFunctions has arranged for this function's * enclosing functions to be heavyweight, so we can safely stick * with JSOP_NAME/JSOP_CALLNAME. */ @@ -2266,7 +2266,7 @@ BindNameToSlot(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) if (!js_AddLocal(cx, cg->fun, atom, JSLOCAL_UPVAR)) return JS_FALSE; - ale = cg->upvarList.add(cg->compiler, atom); + ale = cg->upvarList.add(cg->parser, atom); if (!ale) return JS_FALSE; index = ALE_INDEX(ale); @@ -2691,7 +2691,7 @@ EmitSpecialPropOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg) * array instances by going up to Array.prototype before looking up the * property name. */ - JSAtomListElement *ale = cg->atomList.add(cg->compiler, pn->pn_atom); + JSAtomListElement *ale = cg->atomList.add(cg->parser, pn->pn_atom); if (!ale) return JS_FALSE; if (!EmitIndexOp(cx, JSOP_QNAMEPART, ALE_INDEX(ale), cg)) @@ -2755,7 +2755,7 @@ EmitPropOp(JSContext *cx, JSParseNode *pn, JSOp op, JSCodeGenerator *cg, JSAtomListElement *ale; jsatomid atomIndex; - ale = cg->atomList.add(cg->compiler, pn->pn_atom); + ale = cg->atomList.add(cg->parser, pn->pn_atom); if (!ale) return JS_FALSE; atomIndex = ALE_INDEX(ale); @@ -2994,7 +2994,7 @@ EmitNumberOp(JSContext *cx, jsdouble dval, JSCodeGenerator *cg) if (!atom) return JS_FALSE; - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) return JS_FALSE; return EmitIndexOp(cx, JSOP_DOUBLE, ALE_INDEX(ale), cg); @@ -3433,7 +3433,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn, pn4->pn_type == TOK_NAME) { /* Note a propagated constant with the const's name. */ JS_ASSERT(!pn4->maybeExpr()); - ale = cg->atomList.add(cg->compiler, pn4->pn_atom); + ale = cg->atomList.add(cg->parser, pn4->pn_atom); if (!ale) goto bad; CG_NEXT(cg) = pc; @@ -3450,7 +3450,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn, if (pn4 && pn4->pn_type == TOK_NAME) { /* Note a propagated constant with the const's name. */ JS_ASSERT(!pn4->maybeExpr()); - ale = cg->atomList.add(cg->compiler, pn4->pn_atom); + ale = cg->atomList.add(cg->parser, pn4->pn_atom); if (!ale) goto bad; CG_NEXT(cg) = pc; @@ -3531,7 +3531,7 @@ EmitSwitch(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn, continue; if (!js_AtomizePrimitiveValue(cx, pn3->pn_val, &atom)) goto bad; - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) goto bad; SET_INDEX(pc, ALE_INDEX(ale)); @@ -3640,7 +3640,7 @@ MaybeEmitVarDecl(JSContext *cx, JSCodeGenerator *cg, JSOp prologOp, if (pn->pn_cookie != FREE_UPVAR_COOKIE) { atomIndex = (jsatomid) UPVAR_FRAME_SLOT(pn->pn_cookie); } else { - ale = cg->atomList.add(cg->compiler, pn->pn_atom); + ale = cg->atomList.add(cg->parser, pn->pn_atom); if (!ale) return JS_FALSE; atomIndex = ALE_INDEX(ale); @@ -4393,7 +4393,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) return JS_FALSE; } JSCodeGenerator *cg2 = - new (cg2space) JSCodeGenerator(cg->compiler, + new (cg2space) JSCodeGenerator(cg->parser, cg->codePool, cg->notePool, pn->pn_pos.begin.lineno); cg2->flags = pn->pn_funbox->tcflags | TCF_IN_FUNCTION; @@ -5053,7 +5053,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) stmt = cg->topStmt; atom = pn->pn_atom; if (atom) { - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) return JS_FALSE; while (stmt->type != STMT_LABEL || stmt->label != atom) @@ -5076,7 +5076,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) if (atom) { /* Find the loop statement enclosed by the matching label. */ JSStmtInfo *loop = NULL; - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) return JS_FALSE; while (stmt->type != STMT_LABEL || stmt->label != atom) { @@ -5667,7 +5667,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) case TOK_COLON: /* Emit an annotated nop so we know to decompile a label. */ atom = pn->pn_atom; - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) return JS_FALSE; pn2 = pn->expr(); @@ -5741,7 +5741,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) if (pn2->pn_cookie != FREE_UPVAR_COOKIE) { atomIndex = (jsatomid) pn2->pn_cookie; } else { - ale = cg->atomList.add(cg->compiler, pn2->pn_atom); + ale = cg->atomList.add(cg->parser, pn2->pn_atom); if (!ale) return JS_FALSE; atomIndex = ALE_INDEX(ale); @@ -5752,7 +5752,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) case TOK_DOT: if (!js_EmitTree(cx, cg, pn2->expr())) return JS_FALSE; - ale = cg->atomList.add(cg->compiler, pn2->pn_atom); + ale = cg->atomList.add(cg->parser, pn2->pn_atom); if (!ale) return JS_FALSE; atomIndex = ALE_INDEX(ale); @@ -6653,7 +6653,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) } else { JS_ASSERT(pn3->pn_type == TOK_NAME || pn3->pn_type == TOK_STRING); - ale = cg->atomList.add(cg->compiler, pn3->pn_atom); + ale = cg->atomList.add(cg->parser, pn3->pn_atom); if (!ale) return JS_FALSE; @@ -6815,7 +6815,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) if (pn->pn_count == 0) { JS_ASSERT(pn->pn_type == TOK_XMLLIST); atom = cx->runtime->atomState.emptyAtom; - ale = cg->atomList.add(cg->compiler, atom); + ale = cg->atomList.add(cg->parser, atom); if (!ale) return JS_FALSE; EMIT_INDEX_OP(JSOP_STRING, ALE_INDEX(ale)); @@ -6844,7 +6844,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) if (js_Emit1(cx, cg, JSOP_STARTXML) < 0) return JS_FALSE; - ale = cg->atomList.add(cg->compiler, + ale = cg->atomList.add(cg->parser, (pn->pn_type == TOK_XMLETAGO) ? cx->runtime->atomState.etagoAtom : cx->runtime->atomState.stagoAtom); @@ -6878,7 +6878,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) } } - ale = cg->atomList.add(cg->compiler, + ale = cg->atomList.add(cg->parser, (pn->pn_type == TOK_XMLPTAGC) ? cx->runtime->atomState.ptagcAtom : cx->runtime->atomState.tagcAtom); @@ -6915,7 +6915,7 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn) break; case TOK_XMLPI: - ale = cg->atomList.add(cg->compiler, pn->pn_atom2); + ale = cg->atomList.add(cg->parser, pn->pn_atom2); if (!ale) return JS_FALSE; if (!EmitIndexOp(cx, JSOP_QNAMEPART, ALE_INDEX(ale), cg)) diff --git a/js/src/jsemit.h b/js/src/jsemit.h index b7124cee5f3..c287ff91346 100644 --- a/js/src/jsemit.h +++ b/js/src/jsemit.h @@ -176,7 +176,7 @@ struct JSTreeContext { /* tree context for semantic checks */ JSParseNode *blockNode; /* parse node for a block with let declarations (block with its own lexical scope) */ JSAtomList decls; /* function, const, and var declarations */ - JSCompiler *compiler; /* ptr to common parsing and lexing data */ + js::Parser *parser; /* ptr to common parsing and lexing data */ union { JSFunction *fun; /* function to store argument and variable @@ -190,7 +190,7 @@ struct JSTreeContext { /* tree context for semantic checks */ JSFunctionBox *funbox; /* null or box for function we're compiling if (flags & TCF_IN_FUNCTION) and not in - JSCompiler::compileFunctionBody */ + Compiler::compileFunctionBody */ JSFunctionBox *functionList; #ifdef JS_SCOPE_DEPTH_METER @@ -198,13 +198,13 @@ struct JSTreeContext { /* tree context for semantic checks */ uint16 maxScopeDepth; /* maximum lexical scope chain depth */ #endif - JSTreeContext(JSCompiler *jsc) + JSTreeContext(js::Parser *prs) : flags(0), ngvars(0), bodyid(0), blockidGen(0), topStmt(NULL), topScopeStmt(NULL), blockChain(NULL), blockNode(NULL), - compiler(jsc), scopeChain(NULL), parent(jsc->tc), staticLevel(0), + parser(prs), scopeChain(NULL), parent(prs->tc), staticLevel(0), funbox(NULL), functionList(NULL), sharpSlotBase(-1) { - jsc->tc = this; + prs->tc = this; JS_SCOPE_DEPTH_METERING(scopeDepth = maxScopeDepth = 0); } @@ -214,9 +214,9 @@ struct JSTreeContext { /* tree context for semantic checks */ * cases, we store uint16(-1) in maxScopeDepth. */ ~JSTreeContext() { - compiler->tc = this->parent; + parser->tc = this->parent; JS_SCOPE_DEPTH_METERING_IF((maxScopeDepth != uint16(-1)), - JS_BASIC_STATS_ACCUM(&compiler + JS_BASIC_STATS_ACCUM(&parser ->context ->runtime ->lexicalScopeDepthStats, @@ -260,7 +260,7 @@ struct JSTreeContext { /* tree context for semantic checks */ own name */ #define TCF_HAS_FUNCTION_STMT 0x800 /* block contains a function statement */ #define TCF_GENEXP_LAMBDA 0x1000 /* flag lambda from generator expression */ -#define TCF_COMPILE_N_GO 0x2000 /* compiler-and-go mode of script, can +#define TCF_COMPILE_N_GO 0x2000 /* compile-and-go mode of script, can optimize name references based on scope chain */ #define TCF_NO_SCRIPT_RVAL 0x4000 /* API caller does not want result value @@ -281,7 +281,7 @@ struct JSTreeContext { /* tree context for semantic checks */ #define TCF_DECL_DESTRUCTURING 0x10000 /* - * A request flag passed to JSCompiler::compileScript and then down via + * A request flag passed to Compiler::compileScript and then down via * JSCodeGenerator to js_NewScriptFromCG, from script_compile_sub and any * kindred functions that need to make mutable scripts (even empty ones; * i.e., they can't share the const JSScript::emptyScript() singleton). @@ -335,7 +335,7 @@ struct JSTreeContext { /* tree context for semantic checks */ * JSOPTION_STRICT warnings or strict mode errors. */ inline bool JSTreeContext::needStrictChecks() { - return JS_HAS_STRICT_OPTION(compiler->context) || + return JS_HAS_STRICT_OPTION(parser->context) || (flags & TCF_STRICT_MODE_CODE); } @@ -467,14 +467,14 @@ struct JSCodeGenerator : public JSTreeContext /* * Initialize cg to allocate bytecode space from codePool, source note * space from notePool, and all other arena-allocated temporaries from - * jsc->context->tempPool. + * parser->context->tempPool. */ - JSCodeGenerator(JSCompiler *jsc, + JSCodeGenerator(js::Parser *parser, JSArenaPool *codePool, JSArenaPool *notePool, uintN lineno); /* - * Release cg->codePool, cg->notePool, and compiler->context->tempPool to + * Release cg->codePool, cg->notePool, and parser->context->tempPool to * marks set by JSCodeGenerator's ctor. Note that cgs are magic: they own * the arena pool "tops-of-stack" space above their codeMark, noteMark, and * tempMark points. This means you cannot alloc from tempPool and save the @@ -493,7 +493,7 @@ struct JSCodeGenerator : public JSTreeContext } }; -#define CG_TS(cg) TS((cg)->compiler) +#define CG_TS(cg) TS((cg)->parser) #define CG_BASE(cg) ((cg)->current->base) #define CG_LIMIT(cg) ((cg)->current->limit) diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 5100c562326..15828726b8e 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -2426,9 +2426,9 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) str = cx->runtime->emptyString; } - return JSCompiler::compileFunctionBody(cx, fun, principals, - str->chars(), str->length(), - filename, lineno); + return Compiler::compileFunctionBody(cx, fun, principals, + str->chars(), str->length(), + filename, lineno); } JSObject * diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 1f4597db03f..53ae9df7f7f 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -1353,14 +1353,14 @@ obj_eval(JSContext *cx, uintN argc, jsval *vp) script->principals->subsume(script->principals, principals)))) { /* * Get the prior (cache-filling) eval's saved caller function. - * See JSCompiler::compileScript in jsparse.cpp. + * See Compiler::compileScript in jsparse.cpp. */ JSFunction *fun = script->getFunction(0); if (fun == caller->fun) { /* * Get the source string passed for safekeeping in the - * atom map by the prior eval to JSCompiler::compileScript. + * atom map by the prior eval to Compiler::compileScript. */ JSString *src = ATOM_TO_STRING(script->atomMap.vector[0]); @@ -1412,11 +1412,11 @@ obj_eval(JSContext *cx, uintN argc, jsval *vp) */ JSStackFrame *callerFrame = (staticLevel != 0) ? caller : NULL; if (!script) { - script = JSCompiler::compileScript(cx, scopeobj, callerFrame, - principals, - TCF_COMPILE_N_GO | TCF_NEED_MUTABLE_SCRIPT, - str->chars(), str->length(), - NULL, file, line, str, staticLevel); + script = Compiler::compileScript(cx, scopeobj, callerFrame, + principals, + TCF_COMPILE_N_GO | TCF_NEED_MUTABLE_SCRIPT, + str->chars(), str->length(), + NULL, file, line, str, staticLevel); if (!script) return JS_FALSE; } diff --git a/js/src/jsopcode.h b/js/src/jsopcode.h index c28a6f84ba4..ce4db34e171 100644 --- a/js/src/jsopcode.h +++ b/js/src/jsopcode.h @@ -122,7 +122,7 @@ typedef enum JSOp { #define JOF_SHARPSLOT (1U<<24) /* first immediate is uint16 stack slot no. that needs fixup when in global code (see - JSCompiler::compileScript) */ + Compiler::compileScript) */ /* Shorthands for type from format and type from opcode. */ #define JOF_TYPE(fmt) ((fmt) & JOF_TYPEMASK) diff --git a/js/src/jsparse.cpp b/js/src/jsparse.cpp index a882bd98f61..fc4e3607b14 100644 --- a/js/src/jsparse.cpp +++ b/js/src/jsparse.cpp @@ -160,8 +160,8 @@ JSParseNode::clear() } bool -JSCompiler::init(const jschar *base, size_t length, - FILE *fp, const char *filename, uintN lineno) +Parser::init(const jschar *base, size_t length, + FILE *fp, const char *filename, uintN lineno) { JSContext *cx = context; @@ -173,7 +173,7 @@ JSCompiler::init(const jschar *base, size_t length, return true; } -JSCompiler::~JSCompiler() +Parser::~Parser() { JSContext *cx = context; @@ -184,7 +184,7 @@ JSCompiler::~JSCompiler() } void -JSCompiler::setPrincipals(JSPrincipals *prin) +Parser::setPrincipals(JSPrincipals *prin) { JS_ASSERT(!principals); if (prin) @@ -193,13 +193,13 @@ JSCompiler::setPrincipals(JSPrincipals *prin) } JSObjectBox * -JSCompiler::newObjectBox(JSObject *obj) +Parser::newObjectBox(JSObject *obj) { JS_ASSERT(obj); /* * We use JSContext.tempPool to allocate parsed objects and place them on - * a list in this JSCompiler to ensure GC safety. Thus the tempPool arenas + * a list in this Parser to ensure GC safety. Thus the tempPool arenas * containing the entries must be alive until we are done with scanning, * parsing and code generation for the whole script or top-level function. */ @@ -217,14 +217,14 @@ JSCompiler::newObjectBox(JSObject *obj) } JSFunctionBox * -JSCompiler::newFunctionBox(JSObject *obj, JSParseNode *fn, JSTreeContext *tc) +Parser::newFunctionBox(JSObject *obj, JSParseNode *fn, JSTreeContext *tc) { JS_ASSERT(obj); JS_ASSERT(obj->isFunction()); /* * We use JSContext.tempPool to allocate parsed objects and place them on - * a list in this JSCompiler to ensure GC safety. Thus the tempPool arenas + * a list in this Parser to ensure GC safety. Thus the tempPool arenas * containing the entries must be alive until we are done with scanning, * parsing and code generation for the whole script or top-level function. */ @@ -241,7 +241,7 @@ JSCompiler::newFunctionBox(JSObject *obj, JSParseNode *fn, JSTreeContext *tc) funbox->node = fn; funbox->siblings = tc->functionList; tc->functionList = funbox; - ++tc->compiler->functionCount; + ++tc->parser->functionCount; funbox->kids = NULL; funbox->parent = tc->funbox; funbox->methods = NULL; @@ -280,7 +280,7 @@ JSFunctionBox::shouldUnbrand(uintN methods, uintN slowMethods) const } void -JSCompiler::trace(JSTracer *trc) +Parser::trace(JSTracer *trc) { JSObjectBox *objbox = traceListHead; while (objbox) { @@ -389,7 +389,7 @@ RecycleTree(JSParseNode *pn, JSTreeContext *tc) return NULL; /* Catch back-to-back dup recycles. */ - JS_ASSERT(pn != tc->compiler->nodeList); + JS_ASSERT(pn != tc->parser->nodeList); next = pn->pn_next; if (pn->pn_used || pn->pn_defn) { /* @@ -404,7 +404,7 @@ RecycleTree(JSParseNode *pn, JSTreeContext *tc) RecycleFuncNameKids(pn, tc); } else { UnlinkFunctionBoxes(pn, tc); - head = &tc->compiler->nodeList; + head = &tc->parser->nodeList; pn->pn_next = *head; *head = pn; #ifdef METER_PARSENODES @@ -449,15 +449,15 @@ NewOrRecycledNode(JSTreeContext *tc) { JSParseNode *pn, *pn2; - pn = tc->compiler->nodeList; + pn = tc->parser->nodeList; if (!pn) { - JSContext *cx = tc->compiler->context; + JSContext *cx = tc->parser->context; JS_ARENA_ALLOCATE_TYPE(pn, JSParseNode, &cx->tempPool); if (!pn) js_ReportOutOfScriptQuota(cx); } else { - tc->compiler->nodeList = pn->pn_next; + tc->parser->nodeList = pn->pn_next; /* Recycle immediate descendents only, to save work and working set. */ switch (pn->pn_arity) { @@ -475,8 +475,8 @@ NewOrRecycledNode(JSTreeContext *tc) pn2 = RecycleTree(pn2, tc); } while (pn2); } else { - *pn->pn_tail = tc->compiler->nodeList; - tc->compiler->nodeList = pn->pn_head; + *pn->pn_tail = tc->parser->nodeList; + tc->parser->nodeList = pn->pn_head; #ifdef METER_PARSENODES recyclednodes += pn->pn_count; #endif @@ -526,7 +526,7 @@ JSParseNode::create(JSParseNodeArity arity, JSTreeContext *tc) JSParseNode *pn = NewOrRecycledNode(tc); if (!pn) return NULL; - const Token &tok = tc->compiler->tokenStream.currentToken(); + const Token &tok = tc->parser->tokenStream.currentToken(); pn->init(tok.type, JSOP_NOP, arity); pn->pn_pos = tok.pos; return pn; @@ -635,7 +635,7 @@ static bool GenerateBlockId(JSTreeContext *tc, uint32& blockid) { if (tc->blockidGen == JS_BIT(20)) { - JS_ReportErrorNumber(tc->compiler->context, js_GetErrorMessage, NULL, + JS_ReportErrorNumber(tc->parser->context, js_GetErrorMessage, NULL, JSMSG_NEED_DIET, "program"); return false; } @@ -659,7 +659,7 @@ GenerateBlockIdForStmtNode(JSParseNode *pn, JSTreeContext *tc) * Parse a top-level JS script. */ JSParseNode * -JSCompiler::parse(JSObject *chain) +Parser::parse(JSObject *chain) { /* * Protect atoms from being collected by a GC activation, which might @@ -703,7 +703,7 @@ SetStaticLevel(JSTreeContext *tc, uintN staticLevel) * for slot, but only based on evidence. */ if (staticLevel >= FREE_STATIC_LEVEL) { - JS_ReportErrorNumber(tc->compiler->context, js_GetErrorMessage, NULL, + JS_ReportErrorNumber(tc->parser->context, js_GetErrorMessage, NULL, JSMSG_TOO_DEEP, js_function_str); return false; } @@ -715,14 +715,14 @@ SetStaticLevel(JSTreeContext *tc, uintN staticLevel) * Compile a top-level script. */ JSScript * -JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame, - JSPrincipals *principals, uint32 tcflags, - const jschar *chars, size_t length, - FILE *file, const char *filename, uintN lineno, - JSString *source /* = NULL */, - unsigned staticLevel /* = 0 */) +Compiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame, + JSPrincipals *principals, uint32 tcflags, + const jschar *chars, size_t length, + FILE *file, const char *filename, uintN lineno, + JSString *source /* = NULL */, + unsigned staticLevel /* = 0 */) { - JSCompiler jsc(cx, principals, callerFrame); + Compiler compiler(cx, principals, callerFrame); JSArenaPool codePool, notePool; TokenKind tt; JSParseNode *pn; @@ -742,7 +742,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal JS_ASSERT_IF(callerFrame, tcflags & TCF_COMPILE_N_GO); JS_ASSERT_IF(staticLevel != 0, callerFrame); - if (!jsc.init(chars, length, file, filename, lineno)) + if (!compiler.init(chars, length, file, filename, lineno)) return NULL; JS_InitArenaPool(&codePool, "code", 1024, sizeof(jsbytecode), @@ -750,7 +750,10 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal JS_InitArenaPool(¬ePool, "note", 1024, sizeof(jssrcnote), &cx->scriptStackQuota); - JSCodeGenerator cg(&jsc, &codePool, ¬ePool, jsc.tokenStream.getLineno()); + Parser &parser = compiler.parser; + TokenStream &tokenStream = parser.tokenStream; + + JSCodeGenerator cg(&parser, &codePool, ¬ePool, tokenStream.getLineno()); MUST_FLOW_THROUGH("out"); @@ -767,7 +770,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal callerFrame->script && callerFrame->script->strictModeCode) { cg.flags |= TCF_STRICT_MODE_CODE; - jsc.tokenStream.setStrictMode(); + tokenStream.setStrictMode(); } /* @@ -784,7 +787,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal * eval cache (see obj_eval in jsobj.cpp). */ JSAtom *atom = js_AtomizeString(cx, source, 0); - if (!atom || !cg.atomList.add(&jsc, atom)) + if (!atom || !cg.atomList.add(&parser, atom)) goto out; } @@ -794,7 +797,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal * function captured in case it refers to an upvar, and someone * wishes to decompile it while it's running. */ - funbox = jsc.newObjectBox(FUN_OBJECT(callerFrame->fun)); + funbox = parser.newObjectBox(FUN_OBJECT(callerFrame->fun)); if (!funbox) goto out; funbox->emitLink = cg.objectList.lastbox; @@ -825,7 +828,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal inDirectivePrologue = true; for (;;) { - tt = jsc.tokenStream.peekToken(TSF_OPERAND); + tt = tokenStream.peekToken(TSF_OPERAND); if (tt <= TOK_EOF) { if (tt == TOK_EOF) break; @@ -833,19 +836,19 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal goto out; } - pn = jsc.statement(); + pn = parser.statement(); if (!pn) goto out; JS_ASSERT(!cg.blockNode); if (inDirectivePrologue) - inDirectivePrologue = jsc.recognizeDirectivePrologue(pn); + inDirectivePrologue = parser.recognizeDirectivePrologue(pn); if (!js_FoldConstants(cx, pn, &cg)) goto out; if (cg.functionList) { - if (!jsc.analyzeFunctions(cg.functionList, cg.flags)) + if (!parser.analyzeFunctions(cg.functionList, cg.flags)) goto out; cg.functionList = NULL; } @@ -870,7 +873,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal * https://bugzilla.mozilla.org/show_bug.cgi?id=336551 */ if (pn && onlyXML && (tcflags & TCF_NO_SCRIPT_RVAL)) { - ReportCompileErrorNumber(cx, &jsc.tokenStream, NULL, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, &tokenStream, NULL, JSREPORT_ERROR, JSMSG_XML_WHOLE_PROGRAM); goto out; } @@ -961,7 +964,7 @@ JSCompiler::compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *cal return script; too_many_slots: - ReportCompileErrorNumber(cx, &jsc.tokenStream, NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_LOCALS); + ReportCompileErrorNumber(cx, &tokenStream, NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_LOCALS); script = NULL; goto out; } @@ -1106,7 +1109,7 @@ ReportBadReturn(JSContext *cx, JSTreeContext *tc, uintN flags, uintN errnum, errnum = anonerrnum; name = NULL; } - return ReportCompileErrorNumber(cx, TS(tc->compiler), NULL, flags, errnum, name); + return ReportCompileErrorNumber(cx, TS(tc->parser), NULL, flags, errnum, name); } static JSBool @@ -1132,7 +1135,7 @@ CheckStrictAssignment(JSContext *cx, JSTreeContext *tc, JSParseNode *lhs) if (atom == atomState->evalAtom || atom == atomState->argumentsAtom) { const char *name = js_AtomToPrintableString(cx, atom); if (!name || - !ReportStrictModeError(cx, TS(tc->compiler), tc, lhs, JSMSG_DEPRECATED_ASSIGN, + !ReportStrictModeError(cx, TS(tc->parser), tc, lhs, JSMSG_DEPRECATED_ASSIGN, name)) { return false; } @@ -1157,7 +1160,7 @@ CheckStrictBinding(JSContext *cx, JSTreeContext *tc, JSAtom *atom, JSParseNode * if (atom == atomState->evalAtom || atom == atomState->argumentsAtom) { const char *name = js_AtomToPrintableString(cx, atom); if (name) - ReportStrictModeError(cx, TS(tc->compiler), tc, pn, JSMSG_BAD_BINDING, name); + ReportStrictModeError(cx, TS(tc->parser), tc, pn, JSMSG_BAD_BINDING, name); return false; } return true; @@ -1197,7 +1200,7 @@ CheckStrictFormals(JSContext *cx, JSTreeContext *tc, JSFunction *fun, pn = dn; const char *name = js_AtomToPrintableString(cx, atom); if (!name || - !ReportStrictModeError(cx, TS(tc->compiler), tc, pn, JSMSG_DUPLICATE_FORMAL, name)) { + !ReportStrictModeError(cx, TS(tc->parser), tc, pn, JSMSG_DUPLICATE_FORMAL, name)) { return false; } } @@ -1211,7 +1214,7 @@ CheckStrictFormals(JSContext *cx, JSTreeContext *tc, JSFunction *fun, JS_ASSERT(dn->pn_atom == atom); const char *name = js_AtomToPrintableString(cx, atom); if (!name || - !ReportStrictModeError(cx, TS(tc->compiler), tc, dn, JSMSG_BAD_BINDING, name)) { + !ReportStrictModeError(cx, TS(tc->parser), tc, dn, JSMSG_BAD_BINDING, name)) { return false; } } @@ -1220,7 +1223,7 @@ CheckStrictFormals(JSContext *cx, JSTreeContext *tc, JSFunction *fun, } JSParseNode * -JSCompiler::functionBody() +Parser::functionBody() { JSStmtInfo stmtInfo; uintN oldflags, firstLine; @@ -1285,7 +1288,7 @@ JSCompiler::functionBody() static JSAtomListElement * MakePlaceholder(JSParseNode *pn, JSTreeContext *tc) { - JSAtomListElement *ale = tc->lexdeps.add(tc->compiler, pn->pn_atom); + JSAtomListElement *ale = tc->lexdeps.add(tc->parser, pn->pn_atom); if (!ale) return NULL; @@ -1334,12 +1337,12 @@ Define(JSParseNode *pn, JSAtom *atom, JSTreeContext *tc, bool let = false) dn->dn_uses = pnu; if ((!pnu || pnu->pn_blockid < tc->bodyid) && list != &tc->decls) - list->rawRemove(tc->compiler, ale, hep); + list->rawRemove(tc->parser, ale, hep); } } } - ale = tc->decls.add(tc->compiler, atom, let ? JSAtomList::SHADOW : JSAtomList::UNIQUE); + ale = tc->decls.add(tc->parser, atom, let ? JSAtomList::SHADOW : JSAtomList::UNIQUE); if (!ale) return false; ALE_SET_DEFN(ale, pn); @@ -1461,9 +1464,9 @@ DefineArg(JSParseNode *pn, JSAtom *atom, uintN i, JSTreeContext *tc) JSParseNode *argpn, *argsbody; /* Flag tc so we don't have to lookup arguments on every use. */ - if (atom == tc->compiler->context->runtime->atomState.argumentsAtom) + if (atom == tc->parser->context->runtime->atomState.argumentsAtom) tc->flags |= TCF_FUN_PARAM_ARGUMENTS; - if (atom == tc->compiler->context->runtime->atomState.evalAtom) + if (atom == tc->parser->context->runtime->atomState.evalAtom) tc->flags |= TCF_FUN_PARAM_EVAL; /* @@ -1504,13 +1507,13 @@ DefineArg(JSParseNode *pn, JSAtom *atom, uintN i, JSTreeContext *tc) * handler attribute in an HTML tag. */ bool -JSCompiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals, - const jschar *chars, size_t length, - const char *filename, uintN lineno) +Compiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals, + const jschar *chars, size_t length, + const char *filename, uintN lineno) { - JSCompiler jsc(cx, principals); + Compiler compiler(cx, principals); - if (!jsc.init(chars, length, NULL, filename, lineno)) + if (!compiler.init(chars, length, NULL, filename, lineno)) return false; /* No early return from after here until the js_FinishArenaPool calls. */ @@ -1520,14 +1523,17 @@ JSCompiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *pr JS_InitArenaPool(¬ePool, "note", 1024, sizeof(jssrcnote), &cx->scriptStackQuota); - JSCodeGenerator funcg(&jsc, &codePool, ¬ePool, jsc.tokenStream.getLineno()); + Parser &parser = compiler.parser; + TokenStream &tokenStream = parser.tokenStream; + + JSCodeGenerator funcg(&parser, &codePool, ¬ePool, tokenStream.getLineno()); funcg.flags |= TCF_IN_FUNCTION; funcg.fun = fun; if (!GenerateBlockId(&funcg, funcg.bodyid)) return NULL; /* FIXME: make Function format the source for a function definition. */ - jsc.tokenStream.mungeCurrentToken(TOK_NAME); + tokenStream.mungeCurrentToken(TOK_NAME); JSParseNode *fn = FunctionNode::create(&funcg); if (fn) { fn->pn_body = NULL; @@ -1556,20 +1562,20 @@ JSCompiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *pr * done parsing, we must fold constants, analyze any nested functions, and * generate code for this function, including a stop opcode at the end. */ - jsc.tokenStream.mungeCurrentToken(TOK_LC); - JSParseNode *pn = fn ? jsc.functionBody() : NULL; + tokenStream.mungeCurrentToken(TOK_LC); + JSParseNode *pn = fn ? parser.functionBody() : NULL; if (pn) { if (!CheckStrictFormals(cx, &funcg, fun, pn)) { pn = NULL; - } else if (!jsc.tokenStream.matchToken(TOK_EOF)) { - ReportCompileErrorNumber(cx, &jsc.tokenStream, NULL, JSREPORT_ERROR, + } else if (!tokenStream.matchToken(TOK_EOF)) { + ReportCompileErrorNumber(cx, &tokenStream, NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR); pn = NULL; } else if (!js_FoldConstants(cx, pn, &funcg)) { /* js_FoldConstants reported the error already. */ pn = NULL; } else if (funcg.functionList && - !jsc.analyzeFunctions(funcg.functionList, funcg.flags)) { + !parser.analyzeFunctions(funcg.functionList, funcg.flags)) { pn = NULL; } else { if (fn->pn_body) { @@ -1644,16 +1650,16 @@ BindDestructuringArg(JSContext *cx, BindData *data, JSAtom *atom, JSParseNode *pn; /* Flag tc so we don't have to lookup arguments on every use. */ - if (atom == tc->compiler->context->runtime->atomState.argumentsAtom) + if (atom == tc->parser->context->runtime->atomState.argumentsAtom) tc->flags |= TCF_FUN_PARAM_ARGUMENTS; - if (atom == tc->compiler->context->runtime->atomState.evalAtom) + if (atom == tc->parser->context->runtime->atomState.evalAtom) tc->flags |= TCF_FUN_PARAM_EVAL; JS_ASSERT(tc->flags & TCF_IN_FUNCTION); JSLocalKind localKind = js_LookupLocal(cx, tc->fun, atom, NULL); if (localKind != JSLOCAL_NONE) { - ReportCompileErrorNumber(cx, TS(tc->compiler), NULL, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, TS(tc->parser), NULL, JSREPORT_ERROR, JSMSG_DESTRUCT_DUP_ARG); return JS_FALSE; } @@ -1674,7 +1680,7 @@ BindDestructuringArg(JSContext *cx, BindData *data, JSAtom *atom, #endif /* JS_HAS_DESTRUCTURING */ JSFunction * -JSCompiler::newFunction(JSTreeContext *tc, JSAtom *atom, uintN lambda) +Parser::newFunction(JSTreeContext *tc, JSAtom *atom, uintN lambda) { JSObject *parent; JSFunction *fun; @@ -1716,7 +1722,7 @@ MatchOrInsertSemicolon(JSContext *cx, TokenStream *ts) } bool -JSCompiler::analyzeFunctions(JSFunctionBox *funbox, uint32& tcflags) +Parser::analyzeFunctions(JSFunctionBox *funbox, uint32& tcflags) { if (!markFunArgs(funbox, tcflags)) return false; @@ -1852,7 +1858,7 @@ FindFunArgs(JSFunctionBox *funbox, int level, JSFunctionBoxQueue *queue) } bool -JSCompiler::markFunArgs(JSFunctionBox *funbox, uintN tcflags) +Parser::markFunArgs(JSFunctionBox *funbox, uintN tcflags) { JSFunctionBoxQueue queue; if (!queue.init(functionCount)) @@ -2035,7 +2041,7 @@ CanFlattenUpvar(JSDefinition *dn, JSFunctionBox *funbox, uint32 tcflags) * definition or expression, afunbox->parent will be null. The body * source might use |arguments| outside of any nested functions it may * contain, so we have to check the tcflags parameter that was passed - * in from JSCompiler::compileFunctionBody. + * in from Compiler::compileFunctionBody. */ if (dnKind == JSDefinition::ARG && ((afunbox->parent ? afunbox->parent->tcflags : tcflags) & TCF_FUN_USES_ARGUMENTS)) { @@ -2115,7 +2121,7 @@ DeoptimizeUsesWithin(JSDefinition *dn, JSFunctionBox *funbox, uint32& tcflags) } void -JSCompiler::setFunctionKinds(JSFunctionBox *funbox, uint32& tcflags) +Parser::setFunctionKinds(JSFunctionBox *funbox, uint32& tcflags) { #ifdef JS_FUNCTION_METERING # define FUN_METER(x) JS_RUNTIME_METER(context->runtime, functionMeter.x) @@ -2358,12 +2364,12 @@ EnterFunction(JSParseNode *fn, JSTreeContext *funtc, JSAtom *funAtom = NULL, uintN lambda = JSFUN_LAMBDA) { JSTreeContext *tc = funtc->parent; - JSFunction *fun = tc->compiler->newFunction(tc, funAtom, lambda); + JSFunction *fun = tc->parser->newFunction(tc, funAtom, lambda); if (!fun) return NULL; /* Create box for fun->object early to protect against last-ditch GC. */ - JSFunctionBox *funbox = tc->compiler->newFunctionBox(FUN_OBJECT(fun), fn, tc); + JSFunctionBox *funbox = tc->parser->newFunctionBox(FUN_OBJECT(fun), fn, tc); if (!funbox) return NULL; @@ -2487,7 +2493,7 @@ LeaveFunction(JSParseNode *fn, JSTreeContext *funtc, JSAtom *funAtom = NULL, } } else { /* Add an outer lexical dependency for ale's definition. */ - outer_ale = tc->lexdeps.add(tc->compiler, atom); + outer_ale = tc->lexdeps.add(tc->parser, atom); if (!outer_ale) return false; ALE_SET_DEFN(outer_ale, ALE_DEFN(ale)); @@ -2504,7 +2510,7 @@ LeaveFunction(JSParseNode *fn, JSTreeContext *funtc, JSAtom *funAtom = NULL, fn->pn_body->pn_type = TOK_UPVARS; fn->pn_body->pn_pos = body->pn_pos; if (foundCallee) - funtc->lexdeps.remove(tc->compiler, funAtom); + funtc->lexdeps.remove(tc->parser, funAtom); fn->pn_body->pn_names = funtc->lexdeps; fn->pn_body->pn_tree = body; } @@ -2516,7 +2522,7 @@ LeaveFunction(JSParseNode *fn, JSTreeContext *funtc, JSAtom *funAtom = NULL, } JSParseNode * -JSCompiler::functionDef(uintN lambda, bool namePermitted) +Parser::functionDef(uintN lambda, bool namePermitted) { JSParseNode *pn, *body, *result; TokenKind tt; @@ -2621,7 +2627,7 @@ JSCompiler::functionDef(uintN lambda, bool namePermitted) fn->pn_body = NULL; fn->pn_cookie = FREE_UPVAR_COOKIE; - tc->lexdeps.rawRemove(tc->compiler, ale, hep); + tc->lexdeps.rawRemove(tc->parser, ale, hep); RecycleTree(pn, tc); pn = fn; } @@ -2675,7 +2681,7 @@ JSCompiler::functionDef(uintN lambda, bool namePermitted) JSTreeContext *outertc = tc; /* Initialize early for possible flags mutation via destructuringExpr. */ - JSTreeContext funtc(tc->compiler); + JSTreeContext funtc(tc->parser); JSFunctionBox *funbox = EnterFunction(pn, &funtc, funAtom, lambda); if (!funbox) @@ -2945,13 +2951,13 @@ JSCompiler::functionDef(uintN lambda, bool namePermitted) } JSParseNode * -JSCompiler::functionStmt() +Parser::functionStmt() { return functionDef(0, true); } JSParseNode * -JSCompiler::functionExpr() +Parser::functionExpr() { return functionDef(JSFUN_LAMBDA, true); } @@ -2975,7 +2981,7 @@ JSCompiler::functionExpr() * if it can't possibly be a directive, now or in the future. */ bool -JSCompiler::recognizeDirectivePrologue(JSParseNode *pn) +Parser::recognizeDirectivePrologue(JSParseNode *pn) { if (!pn->isDirectivePrologueMember()) return false; @@ -2995,7 +3001,7 @@ JSCompiler::recognizeDirectivePrologue(JSParseNode *pn) * match { before and } after. */ JSParseNode * -JSCompiler::statements() +Parser::statements() { JSParseNode *pn, *pn2, *saveBlock; TokenKind tt; @@ -3064,7 +3070,7 @@ JSCompiler::statements() } JSParseNode * -JSCompiler::condition() +Parser::condition() { JSParseNode *pn; @@ -3127,7 +3133,7 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) if (ale && ALE_DEFN(ale)->pn_blockid == tc->blockid()) { const char *name = js_AtomToPrintableString(cx, atom); if (name) { - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_REDECLARED_VAR, (ale && ALE_DEFN(ale)->isConst()) ? js_const_str @@ -3139,7 +3145,7 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) n = OBJ_BLOCK_COUNT(cx, blockObj); if (n == JS_BIT(16)) { - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, data->let.overflow); return JS_FALSE; } @@ -3155,7 +3161,7 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) * Assign block-local index to pn->pn_cookie right away, encoding it as an * upvar cookie whose skip tells the current static level. The emitter will * adjust the node's slot based on its stack depth model -- and, for global - * and eval code, JSCompiler::compileScript will adjust the slot again to + * and eval code, Compiler::compileScript will adjust the slot again to * include script->nfixed. */ pn->pn_op = JSOP_GETLOCAL; @@ -3199,9 +3205,9 @@ PopStatement(JSTreeContext *tc) JSAtom *atom = JSID_TO_ATOM(sprop->id); /* Beware the empty destructuring dummy. */ - if (atom == tc->compiler->context->runtime->atomState.emptyAtom) + if (atom == tc->parser->context->runtime->atomState.emptyAtom) continue; - tc->decls.remove(tc->compiler, atom); + tc->decls.remove(tc->parser, atom); } } js_PopStatement(tc); @@ -3250,12 +3256,12 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) return JS_FALSE; if (op == JSOP_DEFCONST) { - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_REDECLARED_PARAM, name); return JS_FALSE; } - if (!ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + if (!ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_WARNING | JSREPORT_STRICT, JSMSG_VAR_HIDES_ARG, name)) { return JS_FALSE; @@ -3271,7 +3277,7 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) : error) { name = js_AtomToPrintableString(cx, atom); if (!name || - !ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + !ReportCompileErrorNumber(cx, TS(tc->parser), pn, !error ? JSREPORT_WARNING | JSREPORT_STRICT : JSREPORT_ERROR, @@ -3343,7 +3349,7 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) ale = tc->lexdeps.rawLookup(atom, hep); if (ale) { pn = ALE_DEFN(ale); - tc->lexdeps.rawRemove(tc->compiler, ale, hep); + tc->lexdeps.rawRemove(tc->parser, ale, hep); } else { JSParseNode *pn2 = NameNode::create(atom, tc); if (!pn2) @@ -3357,7 +3363,7 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) pn->pn_op = JSOP_NAME; } - ale = tc->decls.add(tc->compiler, atom, JSAtomList::HOIST); + ale = tc->decls.add(tc->parser, atom, JSAtomList::HOIST); if (!ale) return JS_FALSE; ALE_SET_DEFN(ale, pn); @@ -3383,11 +3389,11 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, JSTreeContext *tc) * upvars early and possibly simplify jsemit.cpp:BindNameToSlot? */ pn->pn_op = JSOP_NAME; - if ((tc->flags & TCF_COMPILING) && !tc->compiler->callerFrame) { + if ((tc->flags & TCF_COMPILING) && !tc->parser->callerFrame) { JSCodeGenerator *cg = (JSCodeGenerator *) tc; /* Index atom so we can map fast global number to name. */ - ale = cg->atomList.add(tc->compiler, atom); + ale = cg->atomList.add(tc->parser, atom); if (!ale) return JS_FALSE; @@ -3453,7 +3459,7 @@ MakeSetCall(JSContext *cx, JSParseNode *pn, JSTreeContext *tc, uintN msg) JS_ASSERT(pn->pn_op == JSOP_CALL || pn->pn_op == JSOP_EVAL || pn->pn_op == JSOP_APPLY); pn2 = pn->pn_head; if (pn2->pn_type == TOK_FUNCTION && (pn2->pn_funbox->tcflags & TCF_GENEXP_LAMBDA)) { - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, JSREPORT_ERROR, msg); + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, msg); return JS_FALSE; } pn->pn_op = JSOP_SETCALL; @@ -3590,7 +3596,7 @@ BindDestructuringLHS(JSContext *cx, JSParseNode *pn, JSTreeContext *tc) #endif default: - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_BAD_LEFTSIDE_OF_ASS); return JS_FALSE; } @@ -3788,14 +3794,14 @@ CheckDestructuring(JSContext *cx, BindData *data, JSParseNode *lhs, *rhs, *pn, *pn2; if (left->pn_type == TOK_ARRAYCOMP) { - ReportCompileErrorNumber(cx, TS(tc->compiler), left, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, TS(tc->parser), left, JSREPORT_ERROR, JSMSG_ARRAY_COMP_LEFTSIDE); return JS_FALSE; } #if JS_HAS_DESTRUCTURING_SHORTHAND if (right && right->pn_arity == PN_LIST && (right->pn_xflags & PNX_DESTRUCT)) { - ReportCompileErrorNumber(cx, TS(tc->compiler), right, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, TS(tc->parser), right, JSREPORT_ERROR, JSMSG_BAD_OBJECT_INIT); return JS_FALSE; } @@ -3903,7 +3909,7 @@ CheckDestructuring(JSContext *cx, BindData *data, return ok; no_var_name: - ReportCompileErrorNumber(cx, TS(tc->compiler), pn, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_NO_VARIABLE_NAME); ok = JS_FALSE; goto out; @@ -3918,8 +3924,8 @@ CheckDestructuring(JSContext *cx, BindData *data, * to cover its corresponding initializer, so that the initialized binding does * not appear to dominate any closures in its initializer. See bug 496134. * - * The quick-and-dirty dominance computation in JSCompiler::setFunctionKinds is - * not very precise. With one-pass SSA construction from structured source code + * The quick-and-dirty dominance computation in Parser::setFunctionKinds is not + * very precise. With one-pass SSA construction from structured source code * (see "Single-Pass Generation of Static Single Assignment Form for Structured * Languages", Brandis and Mössenböck), we could do much better. * @@ -3937,7 +3943,7 @@ UndominateInitializers(JSParseNode *left, JSParseNode *right, JSTreeContext *tc) #if JS_HAS_DESTRUCTURING_SHORTHAND if (right->pn_arity == PN_LIST && (right->pn_xflags & PNX_DESTRUCT)) { - ReportCompileErrorNumber(tc->compiler->context, TS(tc->compiler), right, JSREPORT_ERROR, + ReportCompileErrorNumber(tc->parser->context, TS(tc->parser), right, JSREPORT_ERROR, JSMSG_BAD_OBJECT_INIT); return JS_FALSE; } @@ -3990,7 +3996,7 @@ UndominateInitializers(JSParseNode *left, JSParseNode *right, JSTreeContext *tc) } JSParseNode * -JSCompiler::destructuringExpr(BindData *data, TokenKind tt) +Parser::destructuringExpr(BindData *data, TokenKind tt) { JSParseNode *pn; @@ -4030,7 +4036,7 @@ CloneParseTree(JSParseNode *opn, JSTreeContext *tc) case PN_FUNC: NULLCHECK(pn->pn_funbox = - tc->compiler->newFunctionBox(opn->pn_funbox->object, pn, tc)); + tc->parser->newFunctionBox(opn->pn_funbox->object, pn, tc)); NULLCHECK(pn->pn_body = CloneParseTree(opn->pn_body, tc)); pn->pn_cookie = opn->pn_cookie; pn->pn_dflags = opn->pn_dflags; @@ -4163,7 +4169,7 @@ ContainsStmt(JSParseNode *pn, TokenKind tt) } JSParseNode * -JSCompiler::returnOrYield(bool useAssignExpr) +Parser::returnOrYield(bool useAssignExpr) { TokenKind tt, tt2; JSParseNode *pn, *pn2; @@ -4247,7 +4253,7 @@ PushLexicalScope(JSContext *cx, TokenStream *ts, JSTreeContext *tc, if (!obj) return NULL; - blockbox = tc->compiler->newObjectBox(obj); + blockbox = tc->parser->newObjectBox(obj); if (!blockbox) return NULL; @@ -4266,7 +4272,7 @@ PushLexicalScope(JSContext *cx, TokenStream *ts, JSTreeContext *tc, #if JS_HAS_BLOCK_SCOPE JSParseNode * -JSCompiler::letBlock(JSBool statement) +Parser::letBlock(JSBool statement) { JSParseNode *pn, *pnblock, *pnlet; JSStmtInfo stmtInfo; @@ -4372,7 +4378,7 @@ NewBindingNode(JSAtom *atom, JSTreeContext *tc, bool let = false) if (let) pn->pn_blockid = tc->blockid(); - tc->lexdeps.remove(tc->compiler, atom); + tc->lexdeps.remove(tc->parser, atom); return pn; } } @@ -4460,7 +4466,7 @@ RebindLets(JSParseNode *pn, JSTreeContext *tc) #endif /* JS_HAS_BLOCK_SCOPE */ JSParseNode * -JSCompiler::statement() +Parser::statement() { TokenKind tt; JSParseNode *pn, *pn1, *pn2, *pn3, *pn4; @@ -5401,11 +5407,11 @@ JSCompiler::statement() JS_ASSERT(!stmt->downScope); /* Convert the block statement into a scope statement. */ - JSObject *obj = js_NewBlockObject(tc->compiler->context); + JSObject *obj = js_NewBlockObject(tc->parser->context); if (!obj) return NULL; - blockbox = tc->compiler->newObjectBox(obj); + blockbox = tc->parser->newObjectBox(obj); if (!blockbox) return NULL; @@ -5604,7 +5610,7 @@ JSCompiler::statement() /* * Keep track of all apparent methods created by assignments such * as this.foo = function (...) {...} in a function that could end - * up a constructor function. See JSCompiler::setFunctionKinds. + * up a constructor function. See Parser::setFunctionKinds. */ if (tc->funbox && PN_OP(pn2) == JSOP_NOP && @@ -5636,7 +5642,7 @@ NoteArgumentsUse(JSTreeContext *tc) } JSParseNode * -JSCompiler::variables(bool inLetHead) +Parser::variables(bool inLetHead) { TokenKind tt; bool let; @@ -5818,7 +5824,7 @@ bad_var_init: } JSParseNode * -JSCompiler::expr() +Parser::expr() { JSParseNode *pn, *pn2; @@ -5851,7 +5857,7 @@ JSCompiler::expr() } JSParseNode * -JSCompiler::assignExpr() +Parser::assignExpr() { JSParseNode *pn, *rhs; TokenKind tt; @@ -5940,7 +5946,7 @@ JSCompiler::assignExpr() } JSParseNode * -JSCompiler::condExpr() +Parser::condExpr() { JSParseNode *pn, *pn1, *pn2, *pn3; uintN oldflags; @@ -5978,7 +5984,7 @@ JSCompiler::condExpr() } JSParseNode * -JSCompiler::orExpr() +Parser::orExpr() { JSParseNode *pn; @@ -5989,7 +5995,7 @@ JSCompiler::orExpr() } JSParseNode * -JSCompiler::andExpr() +Parser::andExpr() { JSParseNode *pn; @@ -6000,7 +6006,7 @@ JSCompiler::andExpr() } JSParseNode * -JSCompiler::bitOrExpr() +Parser::bitOrExpr() { JSParseNode *pn; @@ -6012,7 +6018,7 @@ JSCompiler::bitOrExpr() } JSParseNode * -JSCompiler::bitXorExpr() +Parser::bitXorExpr() { JSParseNode *pn; @@ -6024,7 +6030,7 @@ JSCompiler::bitXorExpr() } JSParseNode * -JSCompiler::bitAndExpr() +Parser::bitAndExpr() { JSParseNode *pn; @@ -6035,7 +6041,7 @@ JSCompiler::bitAndExpr() } JSParseNode * -JSCompiler::eqExpr() +Parser::eqExpr() { JSParseNode *pn; JSOp op; @@ -6049,7 +6055,7 @@ JSCompiler::eqExpr() } JSParseNode * -JSCompiler::relExpr() +Parser::relExpr() { JSParseNode *pn; TokenKind tt; @@ -6082,7 +6088,7 @@ JSCompiler::relExpr() } JSParseNode * -JSCompiler::shiftExpr() +Parser::shiftExpr() { JSParseNode *pn; JSOp op; @@ -6096,7 +6102,7 @@ JSCompiler::shiftExpr() } JSParseNode * -JSCompiler::addExpr() +Parser::addExpr() { JSParseNode *pn; TokenKind tt; @@ -6114,7 +6120,7 @@ JSCompiler::addExpr() } JSParseNode * -JSCompiler::mulExpr() +Parser::mulExpr() { JSParseNode *pn; TokenKind tt; @@ -6203,7 +6209,7 @@ SetIncOpKid(JSContext *cx, TokenStream *ts, JSTreeContext *tc, } JSParseNode * -JSCompiler::unaryExpr() +Parser::unaryExpr() { JSParseNode *pn, *pn2; @@ -6353,7 +6359,7 @@ BumpStaticLevel(JSParseNode *pn, JSTreeContext *tc) JS_ASSERT(level >= tc->staticLevel); if (level >= FREE_STATIC_LEVEL) { - JS_ReportErrorNumber(tc->compiler->context, js_GetErrorMessage, NULL, + JS_ReportErrorNumber(tc->parser->context, js_GetErrorMessage, NULL, JSMSG_TOO_DEEP, js_function_str); return false; } @@ -6474,12 +6480,12 @@ CompExprTransplanter::transplant(JSParseNode *pn) JS_ASSERT(!tc->decls.lookup(atom)); if (dn->pn_pos < root->pn_pos || dn->isPlaceholder()) { - JSAtomListElement *ale = tc->lexdeps.add(tc->compiler, dn->pn_atom); + JSAtomListElement *ale = tc->lexdeps.add(tc->parser, dn->pn_atom); if (!ale) return false; if (dn->pn_pos >= root->pn_pos) { - tc->parent->lexdeps.remove(tc->compiler, atom); + tc->parent->lexdeps.remove(tc->parser, atom); } else { JSDefinition *dn2 = (JSDefinition *)NameNode::create(dn->pn_atom, tc); if (!dn2) @@ -6530,8 +6536,8 @@ CompExprTransplanter::transplant(JSParseNode *pn) * (possibly nested) for-loop, initialized by |type, op, kid|. */ JSParseNode * -JSCompiler::comprehensionTail(JSParseNode *kid, uintN blockid, - TokenKind type, JSOp op) +Parser::comprehensionTail(JSParseNode *kid, uintN blockid, + TokenKind type, JSOp op) { uintN adjust; JSParseNode *pn, *pn2, *pn3, **pnp; @@ -6733,7 +6739,7 @@ JSCompiler::comprehensionTail(JSParseNode *kid, uintN blockid, * is merely sugar for a generator function expression and its application. */ JSParseNode * -JSCompiler::generatorExpr(JSParseNode *pn, JSParseNode *kid) +Parser::generatorExpr(JSParseNode *pn, JSParseNode *kid) { /* Initialize pn, connecting it to kid. */ JS_ASSERT(pn->pn_arity == PN_UNARY); @@ -6755,7 +6761,7 @@ JSCompiler::generatorExpr(JSParseNode *pn, JSParseNode *kid) { JSTreeContext *outertc = tc; - JSTreeContext gentc(tc->compiler); + JSTreeContext gentc(tc->parser); JSFunctionBox *funbox = EnterFunction(genfn, &gentc); if (!funbox) @@ -6819,7 +6825,7 @@ static const char js_generator_str[] = "generator"; #endif /* JS_HAS_GENERATORS */ JSBool -JSCompiler::argumentList(JSParseNode *listNode) +Parser::argumentList(JSParseNode *listNode) { if (tokenStream.matchToken(TOK_RP, TSF_OPERAND)) return JS_TRUE; @@ -6882,7 +6888,7 @@ CheckForImmediatelyAppliedLambda(JSParseNode *pn) } JSParseNode * -JSCompiler::memberExpr(JSBool allowCallSyntax) +Parser::memberExpr(JSBool allowCallSyntax) { JSParseNode *pn, *pn2, *pn3; @@ -7084,7 +7090,7 @@ JSCompiler::memberExpr(JSBool allowCallSyntax) } JSParseNode * -JSCompiler::bracketedExpr() +Parser::bracketedExpr() { uintN oldflags; JSParseNode *pn; @@ -7104,7 +7110,7 @@ JSCompiler::bracketedExpr() #if JS_HAS_XML_SUPPORT JSParseNode * -JSCompiler::endBracketedExpr() +Parser::endBracketedExpr() { JSParseNode *pn; @@ -7168,7 +7174,7 @@ JSCompiler::endBracketedExpr() * PropertySelector vs. Identifier pn_arity, pn_op, and other members. */ JSParseNode * -JSCompiler::propertySelector() +Parser::propertySelector() { JSParseNode *pn; @@ -7190,7 +7196,7 @@ JSCompiler::propertySelector() } JSParseNode * -JSCompiler::qualifiedSuffix(JSParseNode *pn) +Parser::qualifiedSuffix(JSParseNode *pn) { JSParseNode *pn2, *pn3; TokenKind tt; @@ -7236,7 +7242,7 @@ JSCompiler::qualifiedSuffix(JSParseNode *pn) } JSParseNode * -JSCompiler::qualifiedIdentifier() +Parser::qualifiedIdentifier() { JSParseNode *pn; @@ -7252,7 +7258,7 @@ JSCompiler::qualifiedIdentifier() } JSParseNode * -JSCompiler::attributeIdentifier() +Parser::attributeIdentifier() { JSParseNode *pn, *pn2; TokenKind tt; @@ -7282,7 +7288,7 @@ JSCompiler::attributeIdentifier() * Make a TOK_LC unary node whose pn_kid is an expression. */ JSParseNode * -JSCompiler::xmlExpr(JSBool inTag) +Parser::xmlExpr(JSBool inTag) { JSParseNode *pn, *pn2; @@ -7317,7 +7323,7 @@ JSCompiler::xmlExpr(JSBool inTag) * child of a container tag. */ JSParseNode * -JSCompiler::xmlAtomNode() +Parser::xmlAtomNode() { JSParseNode *pn = NullaryNode::create(tc); if (!pn) @@ -7343,7 +7349,7 @@ JSCompiler::xmlAtomNode() * will be TOK_LC. */ JSParseNode * -JSCompiler::xmlNameExpr() +Parser::xmlNameExpr() { JSParseNode *pn, *pn2, *list; TokenKind tt; @@ -7410,7 +7416,7 @@ JSCompiler::xmlNameExpr() * we parsed exactly one expression. */ JSParseNode * -JSCompiler::xmlTagContent(TokenKind tagtype, JSAtom **namep) +Parser::xmlTagContent(TokenKind tagtype, JSAtom **namep) { JSParseNode *pn, *pn2, *list; TokenKind tt; @@ -7484,7 +7490,7 @@ JSCompiler::xmlTagContent(TokenKind tagtype, JSAtom **namep) * that opens the end tag for the container. */ JSBool -JSCompiler::xmlElementContent(JSParseNode *pn) +Parser::xmlElementContent(JSParseNode *pn) { tokenStream.setXMLTagMode(false); for (;;) { @@ -7537,7 +7543,7 @@ JSCompiler::xmlElementContent(JSParseNode *pn) * Return a PN_LIST node containing an XML or XMLList Initialiser. */ JSParseNode * -JSCompiler::xmlElementOrList(JSBool allowList) +Parser::xmlElementOrList(JSBool allowList) { JSParseNode *pn, *pn2, *list; TokenKind tt; @@ -7680,7 +7686,7 @@ JSCompiler::xmlElementOrList(JSBool allowList) } JSParseNode * -JSCompiler::xmlElementOrListRoot(JSBool allowList) +Parser::xmlElementOrListRoot(JSBool allowList) { uint32 oldopts; JSParseNode *pn; @@ -7698,7 +7704,7 @@ JSCompiler::xmlElementOrListRoot(JSBool allowList) } JSParseNode * -JSCompiler::parseXMLText(JSObject *chain, bool allowList) +Parser::parseXMLText(JSObject *chain, bool allowList) { /* * Push a compiler frame if we have no frames, or if the top frame is a @@ -7762,7 +7768,7 @@ BlockIdInScope(uintN blockid, JSTreeContext *tc) #endif JSParseNode * -JSCompiler::primaryExpr(TokenKind tt, JSBool afterDot) +Parser::primaryExpr(TokenKind tt, JSBool afterDot) { JSParseNode *pn, *pn2, *pn3; JSOp op; @@ -7925,7 +7931,7 @@ JSCompiler::primaryExpr(TokenKind tt, JSBool afterDot) * if we've seen as getter, and both of those if we've just * seen an ordinary value. */ - JSAutoAtomList seen(tc->compiler); + JSAutoAtomList seen(tc->parser); pn = ListNode::create(tc); if (!pn) @@ -8084,7 +8090,7 @@ JSCompiler::primaryExpr(TokenKind tt, JSBool afterDot) } ALE_SET_INDEX(ale, attributesMask | ALE_INDEX(ale)); } else { - ale = seen.add(tc->compiler, atom); + ale = seen.add(tc->parser, atom); if (!ale) return NULL; ALE_SET_INDEX(ale, attributesMask); @@ -8358,7 +8364,7 @@ JSCompiler::primaryExpr(TokenKind tt, JSBool afterDot) obj->clearProto(); } - pn->pn_objbox = tc->compiler->newObjectBox(obj); + pn->pn_objbox = tc->parser->newObjectBox(obj); if (!pn->pn_objbox) return NULL; @@ -8394,7 +8400,7 @@ JSCompiler::primaryExpr(TokenKind tt, JSBool afterDot) } JSParseNode * -JSCompiler::parenExpr(JSParseNode *pn1, JSBool *genexp) +Parser::parenExpr(JSParseNode *pn1, JSBool *genexp) { TokenPtr begin; JSParseNode *pn; @@ -9223,7 +9229,7 @@ js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc, bool inCond) return JS_FALSE; JS_ASSERT(!JSVAL_IS_PRIMITIVE(v)); - xmlbox = tc->compiler->newObjectBox(JSVAL_TO_OBJECT(v)); + xmlbox = tc->parser->newObjectBox(JSVAL_TO_OBJECT(v)); if (!xmlbox) return JS_FALSE; diff --git a/js/src/jsparse.h b/js/src/jsparse.h index 1217546a519..9216f56066f 100644 --- a/js/src/jsparse.h +++ b/js/src/jsparse.h @@ -749,7 +749,7 @@ struct JSDefinition : public JSParseNode * We store definition pointers in PN_NAMESET JSAtomLists in the AST, but * due to redefinition these nodes may become uses of other definitions. * This is unusual, so we simply chase the pn_lexdef link to find the final - * definition node. See methods called from JSCompiler::analyzeFunctions. + * definition node. See methods called from Parser::analyzeFunctions. * * FIXME: MakeAssignment mutates for want of a parent link... */ @@ -910,7 +910,10 @@ struct JSFunctionBoxQueue { typedef struct BindData BindData; -struct JSCompiler : private js::AutoGCRooter { +namespace js { + +struct Parser : private js::AutoGCRooter +{ JSContext * const context; /* FIXME Bug 551291: use AutoGCRooter::context? */ JSAtomListElement *aleFreeList; void *tempFreeList[NUM_TEMP_FREELISTS]; @@ -927,8 +930,8 @@ struct JSCompiler : private js::AutoGCRooter { /* Root atoms and objects allocated for the parsed tree. */ js::AutoKeepAtoms keepAtoms; - JSCompiler(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL) - : js::AutoGCRooter(cx, COMPILER), context(cx), + Parser(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL) + : js::AutoGCRooter(cx, PARSER), context(cx), aleFreeList(NULL), tokenStream(cx), principals(NULL), callerFrame(cfp), callerVarObj(cfp ? cfp->varobj(cx->containingCallStack(cfp)) : NULL), nodeList(NULL), functionCount(0), traceListHead(NULL), tc(NULL), @@ -939,16 +942,17 @@ struct JSCompiler : private js::AutoGCRooter { JS_ASSERT_IF(cfp, cfp->script); } - ~JSCompiler(); + ~Parser(); friend void js::AutoGCRooter::trace(JSTracer *trc); friend struct JSTreeContext; + friend struct Compiler; /* - * Initialize a compiler. Parameters are passed on to init tokenStream. + * Initialize a parser. Parameters are passed on to init tokenStream. * The compiler owns the arena pool "tops-of-stack" space above the current * JSContext.tempPool mark. This means you cannot allocate from tempPool - * and save the pointer beyond the next JSCompiler destructor invocation. + * and save the pointer beyond the next Parser destructor invocation. */ bool init(const jschar *base, size_t length, FILE *fp, const char *filename, uintN lineno); @@ -1051,8 +1055,27 @@ private: JSParseNode *xmlElementOrList(JSBool allowList); JSParseNode *xmlElementOrListRoot(JSBool allowList); #endif /* JS_HAS_XML_SUPPORT */ +}; + +struct Compiler +{ + Parser parser; + + Compiler(JSContext *cx, JSPrincipals *prin = NULL, JSStackFrame *cfp = NULL) + : parser(cx, prin, cfp) + { + } + + /* + * Initialize a compiler. Parameters are passed on to init parser. + */ + inline bool + init(const jschar *base, size_t length, + FILE *fp, const char *filename, uintN lineno) + { + return parser.init(base, length, fp, filename, lineno); + } -public: static bool compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals, const jschar *chars, size_t length, @@ -1067,10 +1090,12 @@ public: unsigned staticLevel = 0); }; +} /* namespace js */ + /* - * Convenience macro to access JSCompiler.tokenStream as a pointer. + * Convenience macro to access Parser.tokenStream as a pointer. */ -#define TS(jsc) (&(jsc)->tokenStream) +#define TS(p) (&(p)->tokenStream) extern JSBool js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc, diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h index f6355713d07..3e6832579ed 100644 --- a/js/src/jsprvtd.h +++ b/js/src/jsprvtd.h @@ -88,13 +88,18 @@ typedef uint8 jsbytecode; typedef uint8 jssrcnote; typedef uint32 jsatomid; +/* Class and struct forward declarations in namespace js. */ +namespace js { +struct Parser; +struct Compiler; +} + /* Struct typedefs. */ typedef struct JSArgumentFormatMap JSArgumentFormatMap; typedef struct JSCodeGenerator JSCodeGenerator; typedef struct JSGCThing JSGCThing; typedef struct JSGenerator JSGenerator; typedef struct JSNativeEnumerator JSNativeEnumerator; -typedef struct JSCompiler JSCompiler; typedef struct JSFunctionBox JSFunctionBox; typedef struct JSObjectBox JSObjectBox; typedef struct JSParseNode JSParseNode; diff --git a/js/src/jsscan.cpp b/js/src/jsscan.cpp index 25a077dcc0a..9304500e312 100644 --- a/js/src/jsscan.cpp +++ b/js/src/jsscan.cpp @@ -1396,7 +1396,7 @@ TokenStream::getTokenInternal() * * https://bugzilla.mozilla.org/show_bug.cgi?id=336551 * - * The check for this is in jsparse.cpp, JSCompiler::compileScript. + * The check for this is in jsparse.cpp, Compiler::compileScript. */ if ((flags & TSF_OPERAND) && (JS_HAS_XML_OPTION(cx) || peekChar() != '!')) { diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 73edd15ca73..e776b3422ac 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1004,7 +1004,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg) script->nfixed = (uint16) nfixed; js_InitAtomMap(cx, &script->atomMap, &cg->atomList); - filename = cg->compiler->tokenStream.getFilename(); + filename = cg->parser->tokenStream.getFilename(); if (filename) { script->filename = js_SaveScriptFilename(cx, filename); if (!script->filename) @@ -1017,7 +1017,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg) } script->nslots = script->nfixed + cg->maxStackDepth; script->staticLevel = uint16(cg->staticLevel); - script->principals = cg->compiler->principals; + script->principals = cg->parser->principals; if (script->principals) JSPRINCIPALS_HOLD(cx, script->principals); diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index f5ecd831541..5cca4f3d311 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -1216,10 +1216,10 @@ static const char xml_namespace_str[] = "http://www.w3.org/XML/1998/namespace"; static const char xmlns_namespace_str[] = "http://www.w3.org/2000/xmlns/"; static JSObject * -ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn, +ParseNodeToQName(Parser *parser, JSParseNode *pn, JSXMLArray *inScopeNSes, JSBool isAttributeName) { - JSContext *cx = jsc->context; + JSContext *cx = parser->context; JSString *str, *uri, *prefix, *localName; size_t length, offset; const jschar *start, *limit, *colon; @@ -1269,14 +1269,14 @@ ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn, } if (!uri) { - ReportCompileErrorNumber(jsc->context, &jsc->tokenStream, pn, + ReportCompileErrorNumber(parser->context, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_NAMESPACE, - js_ValueToPrintableString(jsc->context, + js_ValueToPrintableString(parser->context, STRING_TO_JSVAL(prefix))); return NULL; } - localName = js_NewStringCopyN(jsc->context, colon + 1, length - (offset + 1)); + localName = js_NewStringCopyN(parser->context, colon + 1, length - (offset + 1)); if (!localName) return NULL; } else { @@ -1301,12 +1301,12 @@ ParseNodeToQName(JSCompiler *jsc, JSParseNode *pn, break; } } - prefix = uri->empty() ? jsc->context->runtime->emptyString : NULL; + prefix = uri->empty() ? parser->context->runtime->emptyString : NULL; } localName = str; } - return NewXMLQName(jsc->context, uri, prefix, localName); + return NewXMLQName(parser->context, uri, prefix, localName); } static JSString * @@ -1336,10 +1336,10 @@ ChompXMLWhitespace(JSContext *cx, JSString *str) } static JSXML * -ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, +ParseNodeToXML(Parser *parser, JSParseNode *pn, JSXMLArray *inScopeNSes, uintN flags) { - JSContext *cx = jsc->context; + JSContext *cx = parser->context; JSXML *xml, *kid, *attr, *attrj; JSString *str; uint32 length, n, i, j; @@ -1350,7 +1350,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, int stackDummy; if (!JS_CHECK_STACK_SIZE(cx, stackDummy)) { - ReportCompileErrorNumber(cx, &jsc->tokenStream, pn, JSREPORT_ERROR, + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_OVER_RECURSED); return NULL; } @@ -1369,7 +1369,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, case TOK_XMLELEM: length = inScopeNSes->length; pn2 = pn->pn_head; - xml = ParseNodeToXML(jsc, pn2, inScopeNSes, flags); + xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags); if (!xml) goto fail; @@ -1394,7 +1394,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, continue; } - kid = ParseNodeToXML(jsc, pn2, inScopeNSes, flags); + kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags); if (kid == PN2X_SKIP_CHILD) { --n; continue; @@ -1445,7 +1445,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, continue; } - kid = ParseNodeToXML(jsc, pn2, inScopeNSes, flags); + kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags); if (kid == PN2X_SKIP_CHILD) { --n; continue; @@ -1489,7 +1489,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, /* Enforce "Well-formedness constraint: Unique Att Spec". */ for (pn3 = head; pn3 != pn2; pn3 = pn3->pn_next->pn_next) { if (pn3->pn_atom == pn2->pn_atom) { - ReportCompileErrorNumber(cx, &jsc->tokenStream, pn2, + ReportCompileErrorNumber(cx, &parser->tokenStream, pn2, JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR, js_ValueToPrintableString(cx, ATOM_KEY(pn2->pn_atom))); @@ -1573,7 +1573,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, /* Second pass: process tag name and attributes, using namespaces. */ pn2 = pn->pn_head; - qn = ParseNodeToQName(jsc, pn2, inScopeNSes, JS_FALSE); + qn = ParseNodeToQName(parser, pn2, inScopeNSes, JS_FALSE); if (!qn) goto fail; xml->name = qn; @@ -1584,7 +1584,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, goto fail; for (i = 0; (pn2 = pn2->pn_next) != NULL; i++) { - qn = ParseNodeToQName(jsc, pn2, inScopeNSes, JS_TRUE); + qn = ParseNodeToQName(parser, pn2, inScopeNSes, JS_TRUE); if (!qn) { xml->xml_attrs.length = i; goto fail; @@ -1599,7 +1599,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, attrjqn = attrj->name; if (js_EqualStrings(GetURI(attrjqn), GetURI(qn)) && js_EqualStrings(GetLocalName(attrjqn), GetLocalName(qn))) { - ReportCompileErrorNumber(cx, &jsc->tokenStream, pn2, + ReportCompileErrorNumber(cx, &parser->tokenStream, pn2, JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR, js_ValueToPrintableString(cx, ATOM_KEY(pn2->pn_atom))); @@ -1639,7 +1639,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, xml_class = JSXML_CLASS_COMMENT; } else if (pn->pn_type == TOK_XMLPI) { if (IS_XML(str)) { - ReportCompileErrorNumber(cx, &jsc->tokenStream, pn, + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_RESERVED_ID, js_ValueToPrintableString(cx, STRING_TO_JSVAL(str))); @@ -1649,7 +1649,7 @@ ParseNodeToXML(JSCompiler *jsc, JSParseNode *pn, if (flags & XSF_IGNORE_PROCESSING_INSTRUCTIONS) goto skip_child; - qn = ParseNodeToQName(jsc, pn, inScopeNSes, JS_FALSE); + qn = ParseNodeToQName(parser, pn, inScopeNSes, JS_FALSE); if (!qn) goto fail; @@ -1687,7 +1687,7 @@ skip_child: #undef PN2X_SKIP_CHILD syntax: - ReportCompileErrorNumber(cx, &jsc->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP); + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP); fail: js_LeaveLocalRootScope(cx); return NULL; @@ -1843,12 +1843,12 @@ ParseXMLSource(JSContext *cx, JSString *src) } { - JSCompiler jsc(cx); - if (jsc.init(chars, length, NULL, filename, lineno)) { - pn = jsc.parseXMLText(js_GetTopStackFrame(cx)->scopeChain, false); + Parser parser(cx); + if (parser.init(chars, length, NULL, filename, lineno)) { + pn = parser.parseXMLText(js_GetTopStackFrame(cx)->scopeChain, false); if (pn && XMLArrayInit(cx, &nsarray, 1)) { if (GetXMLSettingFlags(cx, &flags)) - xml = ParseNodeToXML(&jsc, pn, &nsarray, flags); + xml = ParseNodeToXML(&parser, pn, &nsarray, flags); XMLArrayFinish(cx, &nsarray); }