summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/parser
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-09-13 16:35:48 +0100
committerIain Merrick <husky@google.com>2010-09-16 12:10:42 +0100
commit5abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306 (patch)
treeddce1aa5e3b6967a69691892e500897558ff8ab6 /JavaScriptCore/parser
parent12bec63ec71e46baba27f0bd9bd9d8067683690a (diff)
downloadexternal_webkit-5abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306.zip
external_webkit-5abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306.tar.gz
external_webkit-5abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306.tar.bz2
Merge WebKit at r67178 : Initial merge by git.
Change-Id: I57e01163b6866cb029cdadf405a0394a3918bc18
Diffstat (limited to 'JavaScriptCore/parser')
-rw-r--r--JavaScriptCore/parser/JSParser.cpp73
-rw-r--r--JavaScriptCore/parser/Lexer.cpp61
-rw-r--r--JavaScriptCore/parser/Lexer.h1
3 files changed, 67 insertions, 68 deletions
diff --git a/JavaScriptCore/parser/JSParser.cpp b/JavaScriptCore/parser/JSParser.cpp
index 6852de1..820811e 100644
--- a/JavaScriptCore/parser/JSParser.cpp
+++ b/JavaScriptCore/parser/JSParser.cpp
@@ -85,11 +85,10 @@ private:
bool m_oldAllowsIn;
};
- const JSToken& token() { return m_token; }
void next(Lexer::LexType lexType = Lexer::IdentifyReservedWords)
{
- m_lastLine = token().m_info.line;
- m_lastTokenEnd = token().m_info.endOffset;
+ m_lastLine = m_token.m_info.line;
+ m_lastTokenEnd = m_token.m_info.endOffset;
m_lexer->setLastLineNumber(m_lastLine);
m_token.m_type = m_lexer->lex(&m_token.m_data, &m_token.m_info, lexType);
m_tokenCount++;
@@ -110,17 +109,17 @@ private:
int tokenStart()
{
- return token().m_info.startOffset;
+ return m_token.m_info.startOffset;
}
int tokenLine()
{
- return token().m_info.line;
+ return m_token.m_info.line;
}
int tokenEnd()
{
- return token().m_info.endOffset;
+ return m_token.m_info.endOffset;
}
template <class TreeBuilder> TreeSourceElements parseSourceElements(TreeBuilder&);
@@ -168,7 +167,7 @@ private:
bool autoSemiColon()
{
- if (token().m_type == SEMICOLON) {
+ if (m_token.m_type == SEMICOLON) {
next();
return true;
}
@@ -324,7 +323,7 @@ template <class TreeBuilder> TreeExpression JSParser::parseVarDeclarationList(Tr
int varStart = tokenStart();
identStart = varStart;
- const Identifier* name = token().m_data.ident;
+ const Identifier* name = m_token.m_data.ident;
lastIdent = name;
next();
bool hasInitializer = match(EQUAL);
@@ -356,7 +355,7 @@ template <class TreeBuilder> TreeConstDeclList JSParser::parseConstDeclarationLi
do {
next();
matchOrFail(IDENT);
- const Identifier* name = token().m_data.ident;
+ const Identifier* name = m_token.m_data.ident;
next();
bool hasInitializer = match(EQUAL);
context.addVar(name, DeclarationStacks::IsConstant | (hasInitializer ? DeclarationStacks::HasInitializer : 0));
@@ -482,7 +481,7 @@ template <class TreeBuilder> TreeStatement JSParser::parseBreakStatement(TreeBui
if (autoSemiColon())
return context.createBreakStatement(startCol, endCol, startLine, endLine);
matchOrFail(IDENT);
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
endCol = tokenEnd();
endLine = tokenLine();
next();
@@ -502,7 +501,7 @@ template <class TreeBuilder> TreeStatement JSParser::parseContinueStatement(Tree
if (autoSemiColon())
return context.createContinueStatement(startCol, endCol, startLine, endLine);
matchOrFail(IDENT);
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
endCol = tokenEnd();
endLine = tokenLine();
next();
@@ -654,7 +653,7 @@ template <class TreeBuilder> TreeStatement JSParser::parseTryStatement(TreeBuild
next();
consumeOrFail(OPENPAREN);
matchOrFail(IDENT);
- ident = token().m_data.ident;
+ ident = m_token.m_data.ident;
next();
consumeOrFail(CLOSEPAREN);
matchOrFail(OPENBRACE);
@@ -705,7 +704,7 @@ template <class TreeBuilder> TreeStatement JSParser::parseBlockStatement(TreeBui
template <class TreeBuilder> TreeStatement JSParser::parseStatement(TreeBuilder& context)
{
failIfStackOverflow();
- switch (token().m_type) {
+ switch (m_token.m_type) {
case OPENBRACE:
return parseBlockStatement(context);
case VAR:
@@ -757,14 +756,14 @@ template <class TreeBuilder> TreeStatement JSParser::parseStatement(TreeBuilder&
template <class TreeBuilder> TreeFormalParameterList JSParser::parseFormalParameters(TreeBuilder& context, bool& usesArguments)
{
matchOrFail(IDENT);
- usesArguments = m_globalData->propertyNames->arguments == *token().m_data.ident;
- TreeFormalParameterList list = context.createFormalParameterList(*token().m_data.ident);
+ usesArguments = m_globalData->propertyNames->arguments == *m_token.m_data.ident;
+ TreeFormalParameterList list = context.createFormalParameterList(*m_token.m_data.ident);
TreeFormalParameterList tail = list;
next();
while (match(COMMA)) {
next();
matchOrFail(IDENT);
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
next();
usesArguments = usesArguments || m_globalData->propertyNames->arguments == *ident;
tail = context.createFormalParameterList(tail, *ident);
@@ -784,7 +783,7 @@ template <class TreeBuilder> TreeFunctionBody JSParser::parseFunctionBody(TreeBu
template <JSParser::FunctionRequirements requirements, class TreeBuilder> bool JSParser::parseFunctionInfo(TreeBuilder& context, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, int& openBracePos, int& closeBracePos, int& bodyStartLine)
{
if (match(IDENT)) {
- name = token().m_data.ident;
+ name = m_token.m_data.ident;
next();
} else if (requirements == FunctionNeedsName)
return false;
@@ -797,7 +796,7 @@ template <JSParser::FunctionRequirements requirements, class TreeBuilder> bool J
consumeOrFail(CLOSEPAREN);
matchOrFail(OPENBRACE);
- openBracePos = token().m_data.intValue;
+ openBracePos = m_token.m_data.intValue;
bodyStartLine = tokenLine();
next();
@@ -807,7 +806,7 @@ template <JSParser::FunctionRequirements requirements, class TreeBuilder> bool J
context.setUsesArguments(body);
matchOrFail(CLOSEBRACE);
- closeBracePos = token().m_data.intValue;
+ closeBracePos = m_token.m_data.intValue;
next();
return true;
}
@@ -837,7 +836,7 @@ template <class TreeBuilder> TreeStatement JSParser::parseExpressionOrLabelState
*/
int start = tokenStart();
int startLine = tokenLine();
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
int currentToken = m_tokenCount;
TreeExpression expression = parseExpression(context);
failIfFalse(expression);
@@ -972,7 +971,7 @@ template <typename TreeBuilder> TreeExpression JSParser::parseAssignmentExpressi
Operator op;
bool hadAssignment = false;
while (true) {
- switch (token().m_type) {
+ switch (m_token.m_type) {
case EQUAL: op = OpEqual; break;
case PLUSEQUAL: op = OpPlusEq; break;
case MINUSEQUAL: op = OpMinusEq; break;
@@ -1051,11 +1050,11 @@ template <class TreeBuilder> TreeExpression JSParser::parseBinaryExpression(Tree
failIfFalse(current);
context.appendBinaryExpressionInfo(operandStackDepth, current, exprStart, lastTokenEnd(), lastTokenEnd(), initialAssignments != m_assignmentCount);
- int precedence = isBinaryOperator(token().m_type);
+ int precedence = isBinaryOperator(m_token.m_type);
if (!precedence)
break;
m_nonLHSCount++;
- int operatorToken = token().m_type;
+ int operatorToken = m_token.m_type;
next();
while (operatorStackDepth && context.operatorStackHasHigherPrecedence(operatorStackDepth, precedence)) {
@@ -1086,12 +1085,12 @@ template <class TreeBuilder> TreeExpression JSParser::parseBinaryExpression(Tree
template <bool complete, class TreeBuilder> TreeProperty JSParser::parseProperty(TreeBuilder& context)
{
bool wasIdent = false;
- switch (token().m_type) {
+ switch (m_token.m_type) {
namedProperty:
case IDENT:
wasIdent = true;
case STRING: {
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
next(Lexer::IgnoreReservedWords);
if (match(COLON)) {
next();
@@ -1118,7 +1117,7 @@ template <bool complete, class TreeBuilder> TreeProperty JSParser::parseProperty
return context.template createGetterOrSetterProperty<complete>(type, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine, m_lastLine);
}
case NUMBER: {
- double propertyName = token().m_data.doubleValue;
+ double propertyName = m_token.m_data.doubleValue;
next();
consumeOrFail(COLON);
TreeExpression node = parseAssignmentExpression(context);
@@ -1126,14 +1125,14 @@ template <bool complete, class TreeBuilder> TreeProperty JSParser::parseProperty
return context.template createProperty<complete>(m_globalData, propertyName, node, PropertyNode::Constant);
}
default:
- failIfFalse(token().m_type & KeywordTokenFlag);
+ failIfFalse(m_token.m_type & KeywordTokenFlag);
goto namedProperty;
}
}
template <class TreeBuilder> TreeExpression JSParser::parseObjectLiteral(TreeBuilder& context)
{
- int startOffset = token().m_data.intValue;
+ int startOffset = m_token.m_data.intValue;
consumeOrFail(OPENBRACE);
if (match(CLOSEBRACE)) {
@@ -1260,7 +1259,7 @@ template <class TreeBuilder> TreeExpression JSParser::parseArrayLiteral(TreeBuil
template <class TreeBuilder> TreeExpression JSParser::parsePrimaryExpression(TreeBuilder& context)
{
- switch (token().m_type) {
+ switch (m_token.m_type) {
case OPENBRACE:
return parseObjectLiteral(context);
case OPENBRACKET:
@@ -1280,17 +1279,17 @@ template <class TreeBuilder> TreeExpression JSParser::parsePrimaryExpression(Tre
}
case IDENT: {
int start = tokenStart();
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
next();
return context.createResolve(ident, start);
}
case STRING: {
- const Identifier* ident = token().m_data.ident;
+ const Identifier* ident = m_token.m_data.ident;
next();
return context.createString(ident);
}
case NUMBER: {
- double d = token().m_data.doubleValue;
+ double d = m_token.m_data.doubleValue;
next();
return context.createNumberExpr(d);
}
@@ -1372,7 +1371,7 @@ template <class TreeBuilder> TreeExpression JSParser::parseMemberExpression(Tree
failIfFalse(base);
while (true) {
- switch (token().m_type) {
+ switch (m_token.m_type) {
case OPENBRACKET: {
int expressionEnd = lastTokenEnd();
next();
@@ -1410,7 +1409,7 @@ template <class TreeBuilder> TreeExpression JSParser::parseMemberExpression(Tree
int expressionEnd = lastTokenEnd();
next(Lexer::IgnoreReservedWords);
matchOrFail(IDENT);
- base = context.createDotAccess(base, *token().m_data.ident, expressionStart, expressionEnd, tokenEnd());
+ base = context.createDotAccess(base, *m_token.m_data.ident, expressionStart, expressionEnd, tokenEnd());
next();
break;
}
@@ -1428,15 +1427,15 @@ template <class TreeBuilder> TreeExpression JSParser::parseUnaryExpression(TreeB
{
AllowInOverride allowInOverride(this);
int tokenStackDepth = 0;
- while (isUnaryOp(token().m_type)) {
+ while (isUnaryOp(m_token.m_type)) {
m_nonLHSCount++;
- context.appendUnaryToken(tokenStackDepth, token().m_type, tokenStart());
+ context.appendUnaryToken(tokenStackDepth, m_token.m_type, tokenStart());
next();
}
int subExprStart = tokenStart();
TreeExpression expr = parseMemberExpression(context);
failIfFalse(expr);
- switch (token().m_type) {
+ switch (m_token.m_type) {
case PLUSPLUS:
m_nonLHSCount++;
expr = context.makePostfixNode(expr, OpPlusPlus, subExprStart, lastTokenEnd(), tokenEnd());
diff --git a/JavaScriptCore/parser/Lexer.cpp b/JavaScriptCore/parser/Lexer.cpp
index 6c4db32..cc4321d 100644
--- a/JavaScriptCore/parser/Lexer.cpp
+++ b/JavaScriptCore/parser/Lexer.cpp
@@ -675,6 +675,27 @@ ALWAYS_INLINE bool Lexer::parseNumberAfterExponentIndicator()
return true;
}
+ALWAYS_INLINE bool Lexer::parseMultilineComment()
+{
+ while (true) {
+ while (UNLIKELY(m_current == '*')) {
+ shift();
+ if (m_current == '/') {
+ shift();
+ return true;
+ }
+ }
+
+ if (UNLIKELY(m_current == -1))
+ return false;
+
+ if (isLineTerminator(m_current))
+ shiftLineTerminator();
+ else
+ shift();
+ }
+}
+
JSTokenType Lexer::lex(JSTokenData* lvalp, JSTokenInfo* llocp, LexType lexType)
{
ASSERT(!m_error);
@@ -835,7 +856,9 @@ start:
}
if (m_current == '*') {
shift();
- goto inMultiLineComment;
+ if (parseMultilineComment())
+ goto start;
+ goto returnError;
}
if (m_current == '=') {
shift();
@@ -1002,7 +1025,8 @@ inNumberAfterDecimalPoint:
m_terminator = true;
if (lastTokenWasRestrKeyword()) {
token = SEMICOLON;
- goto doneSemicolon;
+ m_delimited = true;
+ goto returnToken;
}
goto start;
case CharacterInvalid:
@@ -1024,44 +1048,19 @@ inSingleLineComment:
shiftLineTerminator();
m_atLineStart = true;
m_terminator = true;
- if (lastTokenWasRestrKeyword())
- goto doneSemicolon;
- goto start;
-
-inMultiLineComment:
- while (true) {
- if (UNLIKELY(m_current == '*')) {
- shift();
- if (m_current == '/')
- break;
- if (m_current == '*')
- continue;
- }
-
- if (UNLIKELY(m_current == -1))
- goto returnError;
-
- if (isLineTerminator(m_current))
- shiftLineTerminator();
- else
- shift();
- }
- shift();
- goto start;
+ if (!lastTokenWasRestrKeyword())
+ goto start;
-doneSemicolon:
token = SEMICOLON;
m_delimited = true;
// Fall through into returnToken.
-returnToken: {
- int lineNumber = m_lineNumber;
- llocp->line = lineNumber;
+returnToken:
+ llocp->line = m_lineNumber;
llocp->startOffset = startOffset;
llocp->endOffset = currentOffset();
m_lastToken = token;
return token;
-}
returnError:
m_error = true;
diff --git a/JavaScriptCore/parser/Lexer.h b/JavaScriptCore/parser/Lexer.h
index da84a6b..e6c1efd 100644
--- a/JavaScriptCore/parser/Lexer.h
+++ b/JavaScriptCore/parser/Lexer.h
@@ -101,6 +101,7 @@ namespace JSC {
ALWAYS_INLINE bool parseDecimal(double& returnValue);
ALWAYS_INLINE void parseNumberAfterDecimalPoint();
ALWAYS_INLINE bool parseNumberAfterExponentIndicator();
+ ALWAYS_INLINE bool parseMultilineComment();
static const size_t initialReadBufferCapacity = 32;