Bug 695549 - Rename almost everything in the JS front end. Part 4, rename js::Compiler to js::BytecodeCompiler and fix up old comments referring to jsparse.c etc. r=luke.

--HG--
extra : rebase_source : f1f7d634b48e3cd2cdae15c02cbb1903151e49be
This commit is contained in:
Jason Orendorff 2011-10-19 09:51:04 -05:00
parent 50e34b7d27
commit 5105838e7c
15 changed files with 94 additions and 123 deletions

View File

@ -56,12 +56,12 @@ namespace js {
/*
* Compile a top-level script.
*/
Compiler::Compiler(JSContext *cx, JSPrincipals *prin, StackFrame *cfp)
BytecodeCompiler::BytecodeCompiler(JSContext *cx, JSPrincipals *prin, StackFrame *cfp)
: parser(cx, prin, cfp), globalScope(NULL)
{}
JSScript *
Compiler::compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
BytecodeCompiler::compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerFrame,
JSPrincipals *principals, uint32 tcflags,
const jschar *chars, size_t length,
const char *filename, uintN lineno, JSVersion version,
@ -83,7 +83,7 @@ Compiler::compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
JS_ASSERT_IF(callerFrame, tcflags & TCF_COMPILE_N_GO);
JS_ASSERT_IF(staticLevel != 0, callerFrame);
Compiler compiler(cx, principals, callerFrame);
BytecodeCompiler compiler(cx, principals, callerFrame);
if (!compiler.init(chars, length, filename, lineno, version))
return NULL;
@ -285,7 +285,7 @@ Compiler::compileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
}
bool
Compiler::defineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript *script)
BytecodeCompiler::defineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript *script)
{
JSObject *globalObj = globalScope.globalObj;
@ -391,11 +391,11 @@ Compiler::defineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript *scrip
* handler attribute in an HTML <INPUT> tag.
*/
bool
Compiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals,
BytecodeCompiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals,
Bindings *bindings, const jschar *chars, size_t length,
const char *filename, uintN lineno, JSVersion version)
{
Compiler compiler(cx, principals);
BytecodeCompiler compiler(cx, principals);
if (!compiler.init(chars, length, filename, lineno, version))
return false;
@ -443,9 +443,10 @@ Compiler::compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *prin
/*
* Farble the body so that it looks like a block statement to EmitTree,
* which is called from EmitFunctionBody (see jsemit.cpp). After we're
* done parsing, we must fold constants, analyze any nested functions, and
* generate code for this function, including a stop opcode at the end.
* which is called from EmitFunctionBody (see BytecodeGenerator.cpp).
* After we're done parsing, we must fold constants, analyze any nested
* functions, and generate code for this function, including a stop opcode
* at the end.
*/
tokenStream.mungeCurrentToken(TOK_LC);
ParseNode *pn = fn ? parser.functionBody() : NULL;

View File

@ -45,12 +45,12 @@
namespace js {
struct Compiler
struct BytecodeCompiler
{
Parser parser;
GlobalScope *globalScope;
Compiler(JSContext *cx, JSPrincipals *prin = NULL, StackFrame *cfp = NULL);
BytecodeCompiler(JSContext *cx, JSPrincipals *prin = NULL, StackFrame *cfp = NULL);
JSContext *context() {
return parser.context;

View File

@ -1320,9 +1320,9 @@ TreeContext::ensureSharpSlots()
return false;
} else {
/*
* 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.
* BytecodeCompiler::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.
*/
sharpSlotBase = 0;
}
@ -1974,7 +1974,7 @@ namespace frontend {
* 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
* Compiler::compileScript; see comments there.
* BytecodeCompiler::compileScript; see comments there.
*
* The function returns -1 on failures.
*/
@ -4370,12 +4370,12 @@ EmitVariables(JSContext *cx, CodeGenerator *cg, ParseNode *pn, JSBool inLetHead,
#if JS_HAS_DESTRUCTURING
if (pn2->isKind(TOK_RB) || pn2->isKind(TOK_RC)) {
/*
* Emit variable binding ops, but not destructuring ops.
* The parser (see Variables, jsparse.c) has ensured that
* our caller will be the TOK_FOR/TOK_IN case in EmitTree,
* and that case will emit the destructuring code only after
* emitting an enumerating opcode and a branch that tests
* whether the enumeration ended.
* Emit variable binding ops, but not destructuring ops. The
* parser (see Parser::variables) has ensured that our caller
* will be the TOK_FOR/TOK_IN case in EmitTree, and that case
* will emit the destructuring code only after emitting an
* enumerating opcode and a branch that tests whether the
* enumeration ended.
*/
JS_ASSERT(forInVar);
JS_ASSERT(pn->pn_count == 1);
@ -5639,9 +5639,10 @@ EmitTree(JSContext *cx, CodeGenerator *cg, ParseNode *pn)
cg2->parent = cg;
/*
* jsparse.cpp:SetStaticLevel limited static nesting depth to fit in 16
* bits and to reserve the all-ones value, thereby reserving the magic
* FREE_UPVAR_COOKIE value. Note the cg2->staticLevel assignment below.
* js::frontend::SetStaticLevel limited static nesting depth to fit in
* 16 bits and to reserve the all-ones value, thereby reserving the
* magic FREE_UPVAR_COOKIE value. Note the cg2->staticLevel assignment
* below.
*/
JS_ASSERT(cg->staticLevel < JS_BITMASK(16) - 1);
cg2->staticLevel = cg->staticLevel + 1;
@ -7254,7 +7255,7 @@ EmitTree(JSContext *cx, CodeGenerator *cg, ParseNode *pn)
/*
* Cope with a left-over function definition that was replaced by a use
* of a later function definition of the same name. See FunctionDef and
* MakeDefIntoUse in jsparse.cpp.
* MakeDefIntoUse in Parser.cpp.
*/
if (pn->isOp(JSOP_NOP))
break;
@ -7628,9 +7629,10 @@ static void DumpSrcNoteSizeHist()
/*
* Fill in the storage at notes with prolog and main srcnotes; the space at
* notes was allocated using the CG_COUNT_FINAL_SRCNOTES macro from jsemit.h.
* SO DON'T CHANGE THIS FUNCTION WITHOUT AT LEAST CHECKING WHETHER jsemit.h's
* CG_COUNT_FINAL_SRCNOTES MACRO NEEDS CORRESPONDING CHANGES!
* notes was allocated using the CG_COUNT_FINAL_SRCNOTES macro from
* BytecodeGenerator.h. SO DON'T CHANGE THIS FUNCTION WITHOUT AT LEAST
* CHECKING WHETHER BytecodeGenerator.h's CG_COUNT_FINAL_SRCNOTES MACRO NEEDS
* CORRESPONDING CHANGES!
*/
JSBool
FinishTakingSrcNotes(JSContext *cx, CodeGenerator *cg, jssrcnote *notes)

View File

@ -64,7 +64,8 @@ namespace js {
* non-looping statement enumerators, add them before STMT_DO_LOOP or you will
* break the STMT_TYPE_IS_LOOP macro.
*
* Also remember to keep the statementName array in jsemit.c in sync.
* Also remember to keep the statementName array in BytecodeGenerator.cpp in
* sync.
*/
enum StmtType {
STMT_LABEL, /* labeled statement: L: s */
@ -194,7 +195,7 @@ struct StmtInfo {
#define TCF_DECL_DESTRUCTURING 0x10000
/*
* A request flag passed to Compiler::compileScript and then down via
* A request flag passed to BytecodeCompiler::compileScript and then down via
* CodeGenerator to JSScript::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).
@ -356,7 +357,7 @@ struct TreeContext { /* tree context for semantic checks */
FunctionBox *funbox; /* null or box for function we're compiling
if (flags & TCF_IN_FUNCTION) and not in
Compiler::compileFunctionBody */
BytecodeCompiler::compileFunctionBody */
FunctionBox *functionList;
ParseNode *innermostWith; /* innermost WITH parse node */
@ -434,7 +435,7 @@ struct TreeContext { /* tree context for semantic checks */
int sharpSlotBase;
bool ensureSharpSlots();
Compiler *compiler() { return (Compiler *) parser; }
BytecodeCompiler *compiler() { return (BytecodeCompiler *) parser; }
// Return true there is a generator function within |skip| lexical scopes
// (going upward) from this context's lexical scope. Always return true if

View File

@ -44,10 +44,10 @@
* This is a recursive-descent parser for the JavaScript language specified by
* "The JavaScript 1.5 Language Specification". It uses lexical and semantic
* feedback to disambiguate non-LL(1) structures. It generates trees of nodes
* induced by the recursive parsing (not precise syntax trees, see jsparse.h).
* induced by the recursive parsing (not precise syntax trees, see Parser.h).
* After tree construction, it rewrites trees to fold constants and evaluate
* compile-time expressions. Finally, it calls js_EmitTree (see jsemit.h) to
* generate bytecode.
* compile-time expressions. Finally, it calls js::frontend::EmitTree (see
* CodeGenerator.h) to generate bytecode.
*
* This parser attempts no error recovery.
*/
@ -1382,7 +1382,7 @@ CanFlattenUpvar(Definition *dn, FunctionBox *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 Compiler::compileFunctionBody.
* in from BytecodeCompiler::compileFunctionBody.
*/
if (dnKind == Definition::ARG &&
((afunbox->parent ? afunbox->parent->tcflags : tcflags) & TCF_FUN_USES_ARGUMENTS)) {
@ -2089,8 +2089,8 @@ Parser::functionDef(PropertyName *funName, FunctionType type, FunctionSyntaxKind
* variable to bind its name to its value, and not an activation object
* property (it might also need the activation property, if the outer
* function contains with statements, e.g., but the stack slot wins
* when jsemit.cpp's BindNameToSlot can optimize a JSOP_NAME into a
* JSOP_GETLOCAL bytecode).
* when BytecodeGenerator.cpp's BindNameToSlot can optimize a JSOP_NAME
* into a JSOP_GETLOCAL bytecode).
*/
if (bodyLevel && tc->inFunction()) {
/*
@ -2597,8 +2597,8 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, TreeContext *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, Compiler::compileScript will adjust the slot again to
* include script->nfixed.
* and eval code, BytecodeCompiler::compileScript will adjust the slot
* again to include script->nfixed.
*/
pn->setOp(JSOP_GETLOCAL);
pn->pn_cookie.set(tc->staticLevel, uint16(n));
@ -2616,8 +2616,8 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, TreeContext *tc)
* Store pn temporarily in what would be shape-mapped slots in a cloned
* block object (once the prototype's final population is known, after all
* 'let' bindings for this block have been parsed). We free these slots in
* jsemit.cpp:EmitEnterBlock so they don't tie up unused space in the so-
* called "static" prototype Block.
* BytecodeGenerator.cpp:EmitEnterBlock so they don't tie up unused space
* in the so-called "static" prototype Block.
*/
blockObj->setSlot(shape->slot, PrivateValue(pn));
return true;

View File

@ -124,7 +124,7 @@ struct Parser : private AutoGCRooter
friend void AutoGCRooter::trace(JSTracer *trc);
friend struct TreeContext;
friend struct Compiler;
friend struct BytecodeCompiler;
/*
* Initialize a parser. Parameters are passed on to init tokenStream.

View File

@ -922,7 +922,7 @@ TokenStream::getXMLTextOrTag(TokenKind *ttp, Token **tpp)
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=336551
*
* The check for this is in jsparse.cpp, Compiler::compileScript.
* The check for this is in BytecodeCompiler::compileScript.
*/
bool
TokenStream::getXMLMarkup(TokenKind *ttp, Token **tpp)

View File

@ -4578,8 +4578,8 @@ CompileUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj, JSPrincipals *p
AutoLastFrameCheck lfc(cx);
uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT | TCF_NEED_SCRIPT_OBJECT;
return Compiler::compileScript(cx, obj, NULL, principals, tcflags,
chars, length, filename, lineno, version);
return BytecodeCompiler::compileScript(cx, obj, NULL, principals, tcflags, chars, length,
filename, lineno, version);
}
extern JS_PUBLIC_API(JSScript *)
@ -4755,8 +4755,8 @@ CompileFileHelper(JSContext *cx, JSObject *obj, JSPrincipals *principals,
JS_ASSERT(i <= len);
len = i;
uint32 tcflags = JS_OPTIONS_TO_TCFLAGS(cx) | TCF_NEED_MUTABLE_SCRIPT | TCF_NEED_SCRIPT_OBJECT;
script = Compiler::compileScript(cx, obj, NULL, principals, tcflags, buf, len, filename, 1,
cx->findVersion());
script = BytecodeCompiler::compileScript(cx, obj, NULL, principals, tcflags, buf, len,
filename, 1, cx->findVersion());
cx->free_(buf);
return script;
}
@ -4855,14 +4855,16 @@ CompileUCFunctionForPrincipalsCommon(JSContext *cx, JSObject *obj,
if (!fun)
return NULL;
if (!Compiler::compileFunctionBody(cx, fun, principals, &bindings,
chars, length, filename, lineno, version)) {
if (!BytecodeCompiler::compileFunctionBody(cx, fun, principals, &bindings,
chars, length, filename, lineno, version))
{
return NULL;
}
if (obj && funAtom &&
!obj->defineGeneric(cx, ATOM_TO_JSID(funAtom), ObjectValue(*fun),
NULL, NULL, JSPROP_ENUMERATE)) {
!obj->defineGeneric(cx, ATOM_TO_JSID(funAtom), ObjectValue(*fun), NULL, NULL,
JSPROP_ENUMERATE))
{
return NULL;
}
@ -5017,8 +5019,8 @@ EvaluateUCScriptForPrincipalsCommon(JSContext *cx, JSObject *obj,
CHECK_REQUEST(cx);
AutoLastFrameCheck lfc(cx);
JSScript *script = Compiler::compileScript(cx, obj, NULL, principals, flags,
chars, length, filename, lineno, compileVersion);
JSScript *script = BytecodeCompiler::compileScript(cx, obj, NULL, principals, flags, chars,
length, filename, lineno, compileVersion);
if (!script)
return false;

View File

@ -1241,7 +1241,7 @@ js_ReportUncaughtException(JSContext *cx)
JS_ClearPendingException(cx);
reportp = js_ErrorFromException(cx, exn);
/* XXX L10N angels cry once again (see also jsemit.c, /L10N gaffes/) */
/* XXX L10N angels cry once again. see also everywhere else */
str = js_ValueToString(cx, exn);
JSAutoByteString bytesStorage;
if (!str) {

View File

@ -2284,9 +2284,8 @@ Function(JSContext *cx, uintN argc, Value *vp)
return false;
JSPrincipals *principals = PrincipalsForCompiledCode(args, cx);
bool ok = Compiler::compileFunctionBody(cx, fun, principals, &bindings,
chars, length, filename, lineno,
cx->findVersion());
bool ok = BytecodeCompiler::compileFunctionBody(cx, fun, principals, &bindings, chars, length,
filename, lineno, cx->findVersion());
args.rval().setObject(*fun);
return ok;
}

View File

@ -1027,14 +1027,14 @@ EvalCacheLookup(JSContext *cx, JSLinearString *str, StackFrame *caller, uintN st
script->principals->subsume(script->principals, principals)))) {
/*
* Get the prior (cache-filling) eval's saved caller function.
* See Compiler::compileScript in jsparse.cpp.
* See BytecodeCompiler::compileScript.
*/
JSFunction *fun = script->getCallerFunction();
if (fun == caller->fun()) {
/*
* Get the source string passed for safekeeping in the
* atom map by the prior eval to Compiler::compileScript.
* Get the source string passed for safekeeping in the atom map
* by the prior eval to BytecodeCompiler::compileScript.
*/
JSAtom *src = script->atoms[0];
@ -1273,9 +1273,10 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, StackFrame *c
? CALLED_FROM_JSOP_EVAL
: NOT_CALLED_FROM_JSOP_EVAL);
uint32 tcflags = TCF_COMPILE_N_GO | TCF_NEED_MUTABLE_SCRIPT | TCF_COMPILE_FOR_EVAL;
JSScript *compiled = Compiler::compileScript(cx, &scopeobj, caller, principals, tcflags,
chars, length, filename, lineno,
cx->findVersion(), linearStr, staticLevel);
JSScript *compiled = BytecodeCompiler::compileScript(cx, &scopeobj, caller, principals,
tcflags, chars, length, filename,
lineno, cx->findVersion(), linearStr,
staticLevel);
if (!compiled)
return false;
@ -3583,7 +3584,7 @@ js_PutBlockObject(JSContext *cx, JSBool normalUnwind)
JS_ASSERT(depth <= size_t(cx->regs().sp - fp->base()));
JS_ASSERT(count <= size_t(cx->regs().sp - fp->base() - depth));
/* See comments in CheckDestructuring from jsparse.cpp. */
/* See comments in CheckDestructuring in frontend/Parser.cpp. */
JS_ASSERT(count >= 1);
if (normalUnwind) {

View File

@ -134,7 +134,7 @@ typedef enum JSOp {
#define JOF_SHARPSLOT (1U<<24) /* first immediate is uint16 stack slot no.
that needs fixup when in global code (see
Compiler::compileScript) */
BytecodeCompiler::compileScript) */
#define JOF_GNAME (1U<<25) /* predicted global name */
#define JOF_TYPESET (1U<<26) /* has an entry in a script's type sets */
#define JOF_DECOMPOSE (1U<<27) /* followed by an equivalent decomposed
@ -177,7 +177,8 @@ typedef enum JSOp {
* When a short jump won't hold a relative offset, its 2-byte immediate offset
* operand is an unsigned index of a span-dependency record, maintained until
* code generation finishes -- after which some (but we hope not nearly all)
* span-dependent jumps must be extended (see OptimizeSpanDeps in jsemit.c).
* span-dependent jumps must be extended (see js::frontend::OptimizeSpanDeps in
* frontend/BytecodeGenerator.cpp).
*
* If the span-dependency record index overflows SPANDEP_INDEX_MAX, the jump
* offset will contain SPANDEP_INDEX_HUGE, indicating that the record must be

View File

@ -158,12 +158,18 @@ class FrameRegsIter;
class CallReceiver;
class CallArgs;
struct Compiler;
struct BytecodeCompiler;
struct CodeGenerator;
struct Definition;
struct FunctionBox;
struct ObjectBox;
struct ParseNode;
struct Parser;
class TokenStream;
struct Token;
struct TokenPos;
struct TokenPtr;
struct TreeContext;
class UpvarCookie;
class Proxy;
@ -209,13 +215,6 @@ struct Shape;
struct EmptyShape;
class Bindings;
struct CodeGenerator;
struct Definition;
struct FunctionBox;
struct ObjectBox;
struct ParseNode;
struct TreeContext;
class MultiDeclRange;
class ParseMapPool;
class DefnOrHeader;

View File

@ -4617,42 +4617,6 @@ static JSPropertySpec its_props[] = {
{NULL,0,0,NULL,NULL}
};
#ifdef JSD_LOWLEVEL_SOURCE
/*
* This facilitates sending source to JSD (the debugger system) in the shell
* where the source is loaded using the JSFILE hack in jsscan. The function
* below is used as a callback for the jsdbgapi JS_SetSourceHandler hook.
* A more normal embedding (e.g. mozilla) loads source itself and can send
* source directly to JSD without using this hook scheme.
*/
static void
SendSourceToJSDebugger(const char *filename, uintN lineno,
jschar *str, size_t length,
void **listenerTSData, JSDContext* jsdc)
{
JSDSourceText *jsdsrc = (JSDSourceText *) *listenerTSData;
if (!jsdsrc) {
if (!filename)
filename = "typein";
if (1 == lineno) {
jsdsrc = JSD_NewSourceText(jsdc, filename);
} else {
jsdsrc = JSD_FindSourceForURL(jsdc, filename);
if (jsdsrc && JSD_SOURCE_PARTIAL !=
JSD_GetSourceStatus(jsdc, jsdsrc)) {
jsdsrc = NULL;
}
}
}
if (jsdsrc) {
jsdsrc = JSD_AppendUCSourceText(jsdc,jsdsrc, str, length,
JSD_SOURCE_PARTIAL);
}
*listenerTSData = jsdsrc;
}
#endif /* JSD_LOWLEVEL_SOURCE */
static JSBool its_noisy; /* whether to be noisy when finalizing it */
static JSBool its_enum_fail;/* whether to fail when enumerating it */

View File

@ -2742,11 +2742,12 @@ EvaluateInScope(JSContext *cx, JSObject *scobj, StackFrame *fp, const jschar *ch
* we use a static level that will cause us not to attempt to optimize
* variable references made by this frame.
*/
JSScript *script = Compiler::compileScript(cx, scobj, fp, fp->scopeChain().principals(cx),
JSScript *script = BytecodeCompiler::compileScript(cx, scobj, fp,
fp->scopeChain().principals(cx),
TCF_COMPILE_N_GO | TCF_NEED_SCRIPT_OBJECT,
chars, length,
filename, lineno, cx->findVersion(),
NULL, UpvarCookie::UPVAR_LEVEL_LIMIT);
chars, length, filename, lineno,
cx->findVersion(), NULL,
UpvarCookie::UPVAR_LEVEL_LIMIT);
if (!script)
return false;