зеркало из https://github.com/mozilla/gecko-dev.git
Bug 695549 - Rename almost everything in the JS front end. Part 3, rename tokenizer global functions and put them in the js namespace. r=luke.
--HG-- extra : rebase_source : f5f96588fc824cc4b2462b56872905deddee012b
This commit is contained in:
Родитель
1ed99950f6
Коммит
0759730e13
|
@ -3155,7 +3155,7 @@ EmitElemOp(JSContext *cx, ParseNode *pn, JSOp op, CodeGenerator *cg)
|
|||
}
|
||||
right = &rtmp;
|
||||
right->setKind(TOK_STRING);
|
||||
right->setOp(js_IsIdentifier(pn->pn_atom) ? JSOP_QNAMEPART : JSOP_STRING);
|
||||
right->setOp(IsIdentifier(pn->pn_atom) ? JSOP_QNAMEPART : JSOP_STRING);
|
||||
right->setArity(PN_NULLARY);
|
||||
right->pn_pos = pn->pn_pos;
|
||||
right->pn_atom = pn->pn_atom;
|
||||
|
|
|
@ -434,7 +434,7 @@ struct TreeContext { /* tree context for semantic checks */
|
|||
int sharpSlotBase;
|
||||
bool ensureSharpSlots();
|
||||
|
||||
Compiler *compiler() { return (js::Compiler *)parser; }
|
||||
Compiler *compiler() { return (Compiler *) parser; }
|
||||
|
||||
// Return true there is a generator function within |skip| lexical scopes
|
||||
// (going upward) from this context's lexical scope. Always return true if
|
||||
|
|
|
@ -130,10 +130,8 @@ FindKeyword(const jschar *s, size_t length)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
||||
JSBool
|
||||
js_IsIdentifier(JSLinearString *str)
|
||||
IsIdentifier(JSLinearString *str)
|
||||
{
|
||||
const jschar *chars = str->chars();
|
||||
size_t length = str->length();
|
||||
|
@ -259,34 +257,6 @@ TokenStream::~TokenStream()
|
|||
# define fast_getc getc
|
||||
#endif
|
||||
|
||||
JS_FRIEND_API(int)
|
||||
js_fgets(char *buf, int size, FILE *file)
|
||||
{
|
||||
int n, i, c;
|
||||
JSBool crflag;
|
||||
|
||||
n = size - 1;
|
||||
if (n < 0)
|
||||
return -1;
|
||||
|
||||
crflag = JS_FALSE;
|
||||
for (i = 0; i < n && (c = fast_getc(file)) != EOF; i++) {
|
||||
buf[i] = c;
|
||||
if (c == '\n') { /* any \n ends a line */
|
||||
i++; /* keep the \n; we know there is room for \0 */
|
||||
break;
|
||||
}
|
||||
if (crflag) { /* \r not followed by \n ends line at the \r */
|
||||
ungetc(c, file);
|
||||
break; /* and overwrite c in buf with \0 */
|
||||
}
|
||||
crflag = (c == '\r');
|
||||
}
|
||||
|
||||
buf[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
JS_ALWAYS_INLINE void
|
||||
TokenStream::updateLineInfoForEOL()
|
||||
{
|
||||
|
@ -578,8 +548,8 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, uintN flags, uintN errorN
|
|||
}
|
||||
|
||||
bool
|
||||
js::ReportStrictModeError(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode *pn,
|
||||
uintN errorNumber, ...)
|
||||
ReportStrictModeError(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode *pn,
|
||||
uintN errorNumber, ...)
|
||||
{
|
||||
JS_ASSERT(ts || tc);
|
||||
JS_ASSERT(cx == ts->getContext());
|
||||
|
@ -603,8 +573,8 @@ js::ReportStrictModeError(JSContext *cx, TokenStream *ts, TreeContext *tc, Parse
|
|||
}
|
||||
|
||||
bool
|
||||
js::ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, ParseNode *pn, uintN flags,
|
||||
uintN errorNumber, ...)
|
||||
ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, ParseNode *pn, uintN flags,
|
||||
uintN errorNumber, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
@ -2158,3 +2128,32 @@ TokenStream::getTokenInternal()
|
|||
return TOK_ERROR;
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
JS_FRIEND_API(int)
|
||||
js_fgets(char *buf, int size, FILE *file)
|
||||
{
|
||||
int n, i, c;
|
||||
JSBool crflag;
|
||||
|
||||
n = size - 1;
|
||||
if (n < 0)
|
||||
return -1;
|
||||
|
||||
crflag = JS_FALSE;
|
||||
for (i = 0; i < n && (c = fast_getc(file)) != EOF; i++) {
|
||||
buf[i] = c;
|
||||
if (c == '\n') { /* any \n ends a line */
|
||||
i++; /* keep the \n; we know there is room for \0 */
|
||||
break;
|
||||
}
|
||||
if (crflag) { /* \r not followed by \n ends line at the \r */
|
||||
ungetc(c, file);
|
||||
break; /* and overwrite c in buf with \0 */
|
||||
}
|
||||
crflag = (c == '\r');
|
||||
}
|
||||
|
||||
buf[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -152,20 +152,20 @@ enum TokenKind {
|
|||
TOK_LIMIT /* domain size */
|
||||
};
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
TokenKindIsXML(TokenKind tt)
|
||||
{
|
||||
return tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
TreeTypeIsXML(TokenKind tt)
|
||||
{
|
||||
return tt == TOK_XMLCOMMENT || tt == TOK_XMLCDATA || tt == TOK_XMLPI ||
|
||||
tt == TOK_XMLELEM || tt == TOK_XMLLIST;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
inline bool
|
||||
TokenKindIsDecl(TokenKind tt)
|
||||
{
|
||||
#if JS_HAS_BLOCK_SCOPE
|
||||
|
@ -704,16 +704,6 @@ class TokenStream
|
|||
bool xml; /* see JSOPTION_XML */
|
||||
};
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
extern void
|
||||
js_CloseTokenStream(JSContext *cx, js::TokenStream *ts);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_fgets(char *buf, int size, FILE *file);
|
||||
|
||||
namespace js {
|
||||
|
||||
struct KeywordInfo {
|
||||
const char *chars; /* C string with keyword text */
|
||||
TokenKind tokentype;
|
||||
|
@ -725,23 +715,15 @@ struct KeywordInfo {
|
|||
* Returns a KeywordInfo for the specified characters, or NULL if the string is
|
||||
* not a keyword.
|
||||
*/
|
||||
extern const KeywordInfo *
|
||||
const KeywordInfo *
|
||||
FindKeyword(const jschar *s, size_t length);
|
||||
|
||||
} // namespace js
|
||||
|
||||
/*
|
||||
* Friend-exported API entry point to call a mapping function on each reserved
|
||||
* identifier in the scanner's keyword table.
|
||||
*/
|
||||
typedef void (*JSMapKeywordFun)(const char *);
|
||||
|
||||
/*
|
||||
* Check that str forms a valid JS identifier name. The function does not
|
||||
* check if str is a JS keyword.
|
||||
*/
|
||||
extern JSBool
|
||||
js_IsIdentifier(JSLinearString *str);
|
||||
JSBool
|
||||
IsIdentifier(JSLinearString *str);
|
||||
|
||||
/*
|
||||
* Steal one JSREPORT_* bit (see jsapi.h) to tell that arguments to the error
|
||||
|
@ -749,8 +731,6 @@ js_IsIdentifier(JSLinearString *str);
|
|||
*/
|
||||
#define JSREPORT_UC 0x100
|
||||
|
||||
namespace js {
|
||||
|
||||
/*
|
||||
* Report a compile-time error by its number. Return true for a warning, false
|
||||
* for an error. When pn is not null, use it to report error's location.
|
||||
|
@ -783,4 +763,7 @@ ReportStrictModeError(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode
|
|||
|
||||
} /* namespace js */
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_fgets(char *buf, int size, FILE *file);
|
||||
|
||||
#endif /* TokenStream_h__ */
|
||||
|
|
|
@ -640,7 +640,7 @@ obj_toSource(JSContext *cx, uintN argc, Value *vp)
|
|||
* If id is a string that's not an identifier, or if it's a negative
|
||||
* integer, then it must be quoted.
|
||||
*/
|
||||
bool idIsLexicalIdentifier = js_IsIdentifier(idstr);
|
||||
bool idIsLexicalIdentifier = IsIdentifier(idstr);
|
||||
if (JSID_IS_ATOM(id)
|
||||
? !idIsLexicalIdentifier
|
||||
: (!JSID_IS_INT(id) || JSID_TO_INT(id) < 0)) {
|
||||
|
|
|
@ -1753,10 +1753,8 @@ DecompileDestructuring(SprintStack *ss, jsbytecode *pc, jsbytecode *endpc)
|
|||
#if JS_HAS_DESTRUCTURING_SHORTHAND
|
||||
nameoff = ss->sprinter.offset;
|
||||
#endif
|
||||
if (!QuoteString(&ss->sprinter, atom,
|
||||
js_IsIdentifier(atom) ? 0 : (jschar)'\'')) {
|
||||
if (!QuoteString(&ss->sprinter, atom, IsIdentifier(atom) ? 0 : (jschar)'\''))
|
||||
return NULL;
|
||||
}
|
||||
if (SprintPut(&ss->sprinter, ": ", 2) < 0)
|
||||
return NULL;
|
||||
break;
|
||||
|
@ -1998,8 +1996,6 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
|||
? JSOP_IFEQ \
|
||||
: JSOP_NOP)
|
||||
|
||||
#define ATOM_IS_IDENTIFIER(atom) js_IsIdentifier(atom)
|
||||
|
||||
/*
|
||||
* Given an atom already fetched from jp->script's atom map, quote/escape its
|
||||
* string appropriately into rval, and select fmt from the quoted and unquoted
|
||||
|
@ -2008,7 +2004,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
|||
#define GET_QUOTE_AND_FMT(qfmt, ufmt, rval) \
|
||||
JS_BEGIN_MACRO \
|
||||
jschar quote_; \
|
||||
if (!ATOM_IS_IDENTIFIER(atom)) { \
|
||||
if (!IsIdentifier(atom)) { \
|
||||
quote_ = '\''; \
|
||||
fmt = qfmt; \
|
||||
} else { \
|
||||
|
@ -4563,8 +4559,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
|||
case JSOP_INITPROP:
|
||||
case JSOP_INITMETHOD:
|
||||
LOAD_ATOM(0);
|
||||
xval = QuoteString(&ss->sprinter, atom,
|
||||
jschar(ATOM_IS_IDENTIFIER(atom) ? 0 : '\''));
|
||||
xval = QuoteString(&ss->sprinter, atom, jschar(IsIdentifier(atom) ? 0 : '\''));
|
||||
if (!xval)
|
||||
return NULL;
|
||||
isFirst = IsInitializerOp(ss->opcodes[ss->top - 2]);
|
||||
|
@ -4812,7 +4807,6 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
|
|||
#undef POP_STR
|
||||
#undef POP_STR_PREC
|
||||
#undef LOCAL_ASSERT
|
||||
#undef ATOM_IS_IDENTIFIER
|
||||
#undef GET_QUOTE_AND_FMT
|
||||
#undef GET_ATOM_QUOTE_AND_FMT
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче