Bug 836616 - allow ParseNodes to distinguish numbers containing a decimal point (r=njn)

--HG--
extra : rebase_source : c1b048a3008ac492149488d427f14c9bb5cf5c31
This commit is contained in:
Luke Wagner 2013-01-14 08:25:28 -08:00
parent 22f8a7ad49
commit e0251d0e52
4 changed files with 41 additions and 16 deletions

View File

@ -623,7 +623,10 @@ struct ParseNode {
blockid:20; /* block number, for subset dominance
computation */
} name;
double dval; /* aligned numeric literal value */
struct {
double value; /* aligned numeric literal value */
DecimalPoint decimalPoint; /* Whether the number has a decimal point */
} number;
class {
friend class LoopControlStatement;
PropertyName *label; /* target of break/continue statement */
@ -659,7 +662,7 @@ struct ParseNode {
#define pn_objbox pn_u.name.objbox
#define pn_expr pn_u.name.expr
#define pn_lexdef pn_u.name.lexdef
#define pn_dval pn_u.dval
#define pn_dval pn_u.number.value
protected:
void init(TokenKind type, JSOp op, ParseNodeArity arity) {
@ -869,6 +872,13 @@ struct ParseNode {
return (ParseNode *)(uintptr_t(pn_tail) - offsetof(ParseNode, pn_next));
}
void initNumber(const Token &tok) {
JS_ASSERT(pn_arity == PN_NULLARY);
JS_ASSERT(getKind() == PNK_NUMBER);
pn_u.number.value = tok.number();
pn_u.number.decimalPoint = tok.decimalPoint();
}
void makeEmpty() {
JS_ASSERT(pn_arity == PN_LIST);
pn_head = NULL;

View File

@ -6650,7 +6650,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
pn3 = NullaryNode::create(PNK_NUMBER, this);
if (!pn3)
return NULL;
pn3->pn_dval = tokenStream.currentToken().number();
pn3->initNumber(tokenStream.currentToken());
atom = ToAtom<CanGC>(context, DoubleValue(pn3->pn_dval));
if (!atom)
return NULL;
@ -6697,7 +6697,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
pn3 = NullaryNode::create(PNK_NUMBER, this);
if (!pn3)
return NULL;
pn3->pn_dval = tokenStream.currentToken().number();
pn3->initNumber(tokenStream.currentToken());
atom = ToAtom<CanGC>(context, DoubleValue(pn3->pn_dval));
if (!atom)
return NULL;
@ -6965,7 +6965,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (!pn)
return NULL;
pn->setOp(JSOP_DOUBLE);
pn->pn_dval = tokenStream.currentToken().number();
pn->initNumber(tokenStream.currentToken());
break;
case TOK_TRUE:

View File

@ -1439,7 +1439,8 @@ TokenStream::getTokenInternal()
Token *tp;
FirstCharKind c1kind;
const jschar *numStart;
bool hasFracOrExp;
bool hasExp;
DecimalPoint decimalPoint;
const jschar *identStart;
bool hadUnicodeEscape;
@ -1594,6 +1595,8 @@ TokenStream::getTokenInternal()
c = getCharIgnoreEOL();
if (JS7_ISDEC(c)) {
numStart = userbuf.addressOfNextRawChar() - 2;
decimalPoint = HasDecimal;
hasExp = false;
goto decimal_dot;
}
if (c == '.') {
@ -1740,19 +1743,20 @@ TokenStream::getTokenInternal()
numStart = userbuf.addressOfNextRawChar() - 1;
decimal:
hasFracOrExp = false;
decimalPoint = NoDecimal;
hasExp = false;
while (JS7_ISDEC(c))
c = getCharIgnoreEOL();
if (c == '.') {
decimalPoint = HasDecimal;
decimal_dot:
hasFracOrExp = true;
do {
c = getCharIgnoreEOL();
} while (JS7_ISDEC(c));
}
if (c == 'e' || c == 'E') {
hasFracOrExp = true;
hasExp = true;
c = getCharIgnoreEOL();
if (c == '+' || c == '-')
c = getCharIgnoreEOL();
@ -1779,14 +1783,14 @@ TokenStream::getTokenInternal()
*/
double dval;
const jschar *dummy;
if (!hasFracOrExp) {
if (!((decimalPoint == HasDecimal) || hasExp)) {
if (!GetPrefixInteger(cx, numStart, userbuf.addressOfNextRawChar(), 10, &dummy, &dval))
goto error;
} else {
if (!js_strtod(cx, numStart, userbuf.addressOfNextRawChar(), &dummy, &dval))
goto error;
}
tp->setNumber(dval);
tp->setNumber(dval, decimalPoint);
tt = TOK_NUMBER;
goto out;
}
@ -1871,7 +1875,7 @@ TokenStream::getTokenInternal()
const jschar *dummy;
if (!GetPrefixInteger(cx, numStart, userbuf.addressOfNextRawChar(), radix, &dummy, &dval))
goto error;
tp->setNumber(dval);
tp->setNumber(dval, NoDecimal);
tt = TOK_NUMBER;
goto out;
}

View File

@ -273,6 +273,8 @@ struct TokenPos {
}
};
enum DecimalPoint { NoDecimal = false, HasDecimal = true };
struct Token {
TokenKind type; /* char value or above enumerator */
TokenPos pos; /* token position in file */
@ -294,7 +296,10 @@ struct Token {
PropertyName *target; /* non-empty */
JSAtom *data; /* maybe empty, never null */
} xmlpi;
double number; /* floating point number */
struct {
double value; /* floating point number */
DecimalPoint decimalPoint; /* literal contains . or exponent */
} number;
RegExpFlag reflags; /* regexp flags, use tokenbuf to access
regexp chars */
} u;
@ -335,8 +340,9 @@ struct Token {
u.reflags = flags;
}
void setNumber(double n) {
u.number = n;
void setNumber(double n, DecimalPoint decimalPoint) {
u.number.value = n;
u.number.decimalPoint = decimalPoint;
}
/* Type-safe accessors */
@ -374,7 +380,12 @@ struct Token {
double number() const {
JS_ASSERT(type == TOK_NUMBER);
return u.number;
return u.number.value;
}
DecimalPoint decimalPoint() const {
JS_ASSERT(type == TOK_NUMBER);
return u.number.decimalPoint;
}
};