diff options
Diffstat (limited to 'Source/JavaScriptCore/parser/ASTBuilder.h')
-rw-r--r-- | Source/JavaScriptCore/parser/ASTBuilder.h | 515 |
1 files changed, 274 insertions, 241 deletions
diff --git a/Source/JavaScriptCore/parser/ASTBuilder.h b/Source/JavaScriptCore/parser/ASTBuilder.h index 6e7334f97..43d9b4f1b 100644 --- a/Source/JavaScriptCore/parser/ASTBuilder.h +++ b/Source/JavaScriptCore/parser/ASTBuilder.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,50 +33,68 @@ namespace JSC { class ASTBuilder { + struct PositionInfo { + unsigned startPos; + unsigned line; + unsigned lineStartPos; + }; + struct BinaryOpInfo { BinaryOpInfo() {} - BinaryOpInfo(int s, int d, int e, bool r) - : start(s) - , divot(d) - , end(e) - , hasAssignment(r) + BinaryOpInfo(int otherStart, int otherDivot, int otherEnd, unsigned otherDivotLine, unsigned otherDivotLineStart, bool rhsHasAssignment) + : start(otherStart) + , divot(otherDivot) + , end(otherEnd) + , divotLine(otherDivotLine) + , divotLineStart(otherDivotLineStart) + , hasAssignment(rhsHasAssignment) { } BinaryOpInfo(const BinaryOpInfo& lhs, const BinaryOpInfo& rhs) : start(lhs.start) , divot(rhs.start) , end(rhs.end) + , divotLine(rhs.divotLine) + , divotLineStart(rhs.divotLineStart) , hasAssignment(lhs.hasAssignment || rhs.hasAssignment) { } int start; int divot; int end; + unsigned divotLine; + unsigned divotLineStart; bool hasAssignment; }; struct AssignmentInfo { AssignmentInfo() {} - AssignmentInfo(ExpressionNode* node, int start, int divot, int initAssignments, Operator op) + AssignmentInfo(ExpressionNode* node, unsigned start, unsigned divot, unsigned divotLine, unsigned divotLineStart, int initAssignments, Operator op) : m_node(node) , m_start(start) , m_divot(divot) + , m_divotLine(divotLine) + , m_divotLineStart(divotLineStart) , m_initAssignments(initAssignments) , m_op(op) { + ASSERT(m_divot >= m_divotLineStart); + ASSERT(m_start >= m_divotLineStart); } ExpressionNode* m_node; - int m_start; - int m_divot; + unsigned m_start; + unsigned m_divot; + unsigned m_divotLine; + unsigned m_divotLineStart; int m_initAssignments; Operator m_op; }; public: - ASTBuilder(JSGlobalData* globalData, SourceCode* sourceCode) - : m_globalData(globalData) + ASTBuilder(VM* vm, SourceCode* sourceCode) + : m_vm(vm) , m_sourceCode(sourceCode) - , m_scope(globalData) + , m_scope(vm) , m_evalCount(0) { } @@ -113,9 +131,9 @@ public: static const int DontBuildStrings = 0; ExpressionNode* makeBinaryNode(const JSTokenLocation&, int token, std::pair<ExpressionNode*, BinaryOpInfo>, std::pair<ExpressionNode*, BinaryOpInfo>); - ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, ArgumentsNode* args, int start, int divot, int end); + ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, ArgumentsNode* args, int start, unsigned divot, int end, unsigned divotLine, unsigned divotLineStart); - JSC::SourceElements* createSourceElements() { return new (m_globalData) JSC::SourceElements(); } + JSC::SourceElements* createSourceElements() { return new (m_vm) JSC::SourceElements(); } ParserArenaData<DeclarationStacks::VarStack>* varDeclarations() { return m_scope.m_varDeclarations; } ParserArenaData<DeclarationStacks::FunctionStack>* funcDeclarations() { return m_scope.m_funcDeclarations; } @@ -124,13 +142,13 @@ public: void appendToComma(CommaNode* commaNode, ExpressionNode* expr) { commaNode->append(expr); } - CommaNode* createCommaExpr(const JSTokenLocation& location, ExpressionNode* lhs, ExpressionNode* rhs) { return new (m_globalData) CommaNode(location, lhs, rhs); } + CommaNode* createCommaExpr(const JSTokenLocation& location, ExpressionNode* lhs, ExpressionNode* rhs) { return new (m_vm) CommaNode(location, lhs, rhs); } - ExpressionNode* makeAssignNode(const JSTokenLocation&, ExpressionNode* left, Operator, ExpressionNode* right, bool leftHasAssignments, bool rightHasAssignments, int start, int divot, int end); - ExpressionNode* makePrefixNode(const JSTokenLocation&, ExpressionNode*, Operator, int start, int divot, int end); - ExpressionNode* makePostfixNode(const JSTokenLocation&, ExpressionNode*, Operator, int start, int divot, int end); + ExpressionNode* makeAssignNode(const JSTokenLocation&, ExpressionNode* left, Operator, ExpressionNode* right, bool leftHasAssignments, bool rightHasAssignments, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart); + ExpressionNode* makePrefixNode(const JSTokenLocation&, ExpressionNode*, Operator, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart); + ExpressionNode* makePostfixNode(const JSTokenLocation&, ExpressionNode*, Operator, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart); ExpressionNode* makeTypeOfNode(const JSTokenLocation&, ExpressionNode*); - ExpressionNode* makeDeleteNode(const JSTokenLocation&, ExpressionNode*, int start, int divot, int end); + ExpressionNode* makeDeleteNode(const JSTokenLocation&, ExpressionNode*, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart); ExpressionNode* makeNegateNode(const JSTokenLocation&, ExpressionNode*); ExpressionNode* makeBitwiseNotNode(const JSTokenLocation&, ExpressionNode*); ExpressionNode* makeMultNode(const JSTokenLocation&, ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments); @@ -145,355 +163,359 @@ public: ExpressionNode* makeRightShiftNode(const JSTokenLocation&, ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments); ExpressionNode* makeURightShiftNode(const JSTokenLocation&, ExpressionNode* left, ExpressionNode* right, bool rightHasAssignments); - ExpressionNode* createLogicalNot(const JSTokenLocation& location, ExpressionNode* expr) { return new (m_globalData) LogicalNotNode(location, expr); } - ExpressionNode* createUnaryPlus(const JSTokenLocation& location, ExpressionNode* expr) { return new (m_globalData) UnaryPlusNode(location, expr); } + ExpressionNode* createLogicalNot(const JSTokenLocation& location, ExpressionNode* expr) + { + if (expr->isNumber()) + return createBoolean(location, isZeroOrUnordered(static_cast<NumberNode*>(expr)->value())); + + return new (m_vm) LogicalNotNode(location, expr); + } + ExpressionNode* createUnaryPlus(const JSTokenLocation& location, ExpressionNode* expr) { return new (m_vm) UnaryPlusNode(location, expr); } ExpressionNode* createVoid(const JSTokenLocation& location, ExpressionNode* expr) { incConstants(); - return new (m_globalData) VoidNode(location, expr); + return new (m_vm) VoidNode(location, expr); } ExpressionNode* thisExpr(const JSTokenLocation& location) { usesThis(); - return new (m_globalData) ThisNode(location); + return new (m_vm) ThisNode(location); } - ExpressionNode* createResolve(const JSTokenLocation& location, const Identifier* ident, int start) + ExpressionNode* createResolve(const JSTokenLocation& location, const Identifier* ident, unsigned start, unsigned divotLine, unsigned divotLineStart) { - if (m_globalData->propertyNames->arguments == *ident) + if (m_vm->propertyNames->arguments == *ident) usesArguments(); - return new (m_globalData) ResolveNode(location, *ident, start); + return new (m_vm) ResolveNode(location, *ident, start, divotLine, divotLineStart); } - ExpressionNode* createObjectLiteral(const JSTokenLocation& location) { return new (m_globalData) ObjectLiteralNode(location); } - ExpressionNode* createObjectLiteral(const JSTokenLocation& location, PropertyListNode* properties) { return new (m_globalData) ObjectLiteralNode(location, properties); } + ExpressionNode* createObjectLiteral(const JSTokenLocation& location) { return new (m_vm) ObjectLiteralNode(location); } + ExpressionNode* createObjectLiteral(const JSTokenLocation& location, PropertyListNode* properties) { return new (m_vm) ObjectLiteralNode(location, properties); } ExpressionNode* createArray(const JSTokenLocation& location, int elisions) { if (elisions) incConstants(); - return new (m_globalData) ArrayNode(location, elisions); + return new (m_vm) ArrayNode(location, elisions); } - ExpressionNode* createArray(const JSTokenLocation& location, ElementNode* elems) { return new (m_globalData) ArrayNode(location, elems); } + ExpressionNode* createArray(const JSTokenLocation& location, ElementNode* elems) { return new (m_vm) ArrayNode(location, elems); } ExpressionNode* createArray(const JSTokenLocation& location, int elisions, ElementNode* elems) { if (elisions) incConstants(); - return new (m_globalData) ArrayNode(location, elisions, elems); + return new (m_vm) ArrayNode(location, elisions, elems); } ExpressionNode* createNumberExpr(const JSTokenLocation& location, double d) { incConstants(); - return new (m_globalData) NumberNode(location, d); + return new (m_vm) NumberNode(location, d); } ExpressionNode* createString(const JSTokenLocation& location, const Identifier* string) { incConstants(); - return new (m_globalData) StringNode(location, *string); + return new (m_vm) StringNode(location, *string); } ExpressionNode* createBoolean(const JSTokenLocation& location, bool b) { incConstants(); - return new (m_globalData) BooleanNode(location, b); + return new (m_vm) BooleanNode(location, b); } ExpressionNode* createNull(const JSTokenLocation& location) { incConstants(); - return new (m_globalData) NullNode(location); + return new (m_vm) NullNode(location); } - ExpressionNode* createBracketAccess(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* property, bool propertyHasAssignments, int start, int divot, int end) + ExpressionNode* createBracketAccess(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* property, bool propertyHasAssignments, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { - BracketAccessorNode* node = new (m_globalData) BracketAccessorNode(location, base, property, propertyHasAssignments); - setExceptionLocation(node, start, divot, end); + BracketAccessorNode* node = new (m_vm) BracketAccessorNode(location, base, property, propertyHasAssignments); + setExceptionLocation(node, start, divot, end, divotLine, divotLineStart); return node; } - ExpressionNode* createDotAccess(const JSTokenLocation& location, ExpressionNode* base, const Identifier* property, int start, int divot, int end) + ExpressionNode* createDotAccess(const JSTokenLocation& location, ExpressionNode* base, const Identifier* property, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { - DotAccessorNode* node = new (m_globalData) DotAccessorNode(location, base, *property); - setExceptionLocation(node, start, divot, end); + DotAccessorNode* node = new (m_vm) DotAccessorNode(location, base, *property); + setExceptionLocation(node, start, divot, end, divotLine, divotLineStart); return node; } - ExpressionNode* createRegExp(const JSTokenLocation& location, const Identifier& pattern, const Identifier& flags, int start) + ExpressionNode* createRegExp(const JSTokenLocation& location, const Identifier& pattern, const Identifier& flags, int start, unsigned divotLine, unsigned divotLineStart) { if (Yarr::checkSyntax(pattern.string())) return 0; - RegExpNode* node = new (m_globalData) RegExpNode(location, pattern, flags); + RegExpNode* node = new (m_vm) RegExpNode(location, pattern, flags); int size = pattern.length() + 2; // + 2 for the two /'s - setExceptionLocation(node, start, start + size, start + size); + setExceptionLocation(node, start, start + size, start + size, divotLine, divotLineStart); return node; } - ExpressionNode* createNewExpr(const JSTokenLocation& location, ExpressionNode* expr, ArgumentsNode* arguments, int start, int divot, int end) + ExpressionNode* createNewExpr(const JSTokenLocation& location, ExpressionNode* expr, ArgumentsNode* arguments, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { - NewExprNode* node = new (m_globalData) NewExprNode(location, expr, arguments); - setExceptionLocation(node, start, divot, end); + NewExprNode* node = new (m_vm) NewExprNode(location, expr, arguments); + setExceptionLocation(node, start, divot, end, divotLine, divotLineStart); return node; } - ExpressionNode* createNewExpr(const JSTokenLocation& location, ExpressionNode* expr, int start, int end) + ExpressionNode* createNewExpr(const JSTokenLocation& location, ExpressionNode* expr, int start, int end, unsigned divotLine, unsigned divotLineStart) { - NewExprNode* node = new (m_globalData) NewExprNode(location, expr); - setExceptionLocation(node, start, end, end); + NewExprNode* node = new (m_vm) NewExprNode(location, expr); + setExceptionLocation(node, start, end, end, divotLine, divotLineStart); return node; } ExpressionNode* createConditionalExpr(const JSTokenLocation& location, ExpressionNode* condition, ExpressionNode* lhs, ExpressionNode* rhs) { - return new (m_globalData) ConditionalNode(location, condition, lhs, rhs); + return new (m_vm) ConditionalNode(location, condition, lhs, rhs); } - ExpressionNode* createAssignResolve(const JSTokenLocation& location, const Identifier& ident, ExpressionNode* rhs, int start, int divot, int end) + ExpressionNode* createAssignResolve(const JSTokenLocation& location, const Identifier& ident, ExpressionNode* rhs, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { if (rhs->isFuncExprNode()) static_cast<FuncExprNode*>(rhs)->body()->setInferredName(ident); - AssignResolveNode* node = new (m_globalData) AssignResolveNode(location, ident, rhs); - setExceptionLocation(node, start, divot, end); + AssignResolveNode* node = new (m_vm) AssignResolveNode(location, ident, rhs); + setExceptionLocation(node, start, divot, end, divotLine, divotLineStart); return node; } - ExpressionNode* createFunctionExpr(const JSTokenLocation& location, const Identifier* name, FunctionBodyNode* body, ParameterNode* parameters, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine) + ExpressionNode* createFunctionExpr(const JSTokenLocation& location, const Identifier* name, FunctionBodyNode* body, ParameterNode* parameters, unsigned openBraceOffset, unsigned closeBraceOffset, int bodyStartLine, int bodyEndLine, unsigned startColumn) { - FuncExprNode* result = new (m_globalData) FuncExprNode(location, *name, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), parameters); - body->setLoc(bodyStartLine, bodyEndLine, location.column); + FuncExprNode* result = new (m_vm) FuncExprNode(location, *name, body, m_sourceCode->subExpression(openBraceOffset, closeBraceOffset, bodyStartLine, startColumn), parameters); + body->setLoc(bodyStartLine, bodyEndLine, location.startOffset, location.lineStartOffset); return result; } - FunctionBodyNode* createFunctionBody(const JSTokenLocation& location, bool inStrictContext) + FunctionBodyNode* createFunctionBody(const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, bool inStrictContext) + { + return FunctionBodyNode::create(m_vm, startLocation, endLocation, startColumn, inStrictContext); + } + + void setFunctionStart(FunctionBodyNode* body, int functionStart) { - return FunctionBodyNode::create(m_globalData, location, inStrictContext); + body->setFunctionStart(functionStart); } - template <bool> PropertyNode* createGetterOrSetterProperty(const JSTokenLocation& location, PropertyNode::Type type, const Identifier* name, ParameterNode* params, FunctionBodyNode* body, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine) + template <bool> PropertyNode* createGetterOrSetterProperty(const JSTokenLocation& location, PropertyNode::Type type, const Identifier* name, ParameterNode* params, FunctionBodyNode* body, unsigned openBraceOffset, unsigned closeBraceOffset, int bodyStartLine, int bodyEndLine, unsigned bodyStartColumn) { ASSERT(name); - body->setLoc(bodyStartLine, bodyEndLine, location.column); + body->setLoc(bodyStartLine, bodyEndLine, location.startOffset, location.lineStartOffset); body->setInferredName(*name); - return new (m_globalData) PropertyNode(m_globalData, *name, new (m_globalData) FuncExprNode(location, m_globalData->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), params), type); + return new (m_vm) PropertyNode(m_vm, *name, new (m_vm) FuncExprNode(location, m_vm->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn), params), type); } - template <bool> PropertyNode* createGetterOrSetterProperty(JSGlobalData*, const JSTokenLocation& location, PropertyNode::Type type, double name, ParameterNode* params, FunctionBodyNode* body, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine) + template <bool> PropertyNode* createGetterOrSetterProperty(VM*, const JSTokenLocation& location, PropertyNode::Type type, double name, ParameterNode* params, FunctionBodyNode* body, unsigned openBraceOffset, unsigned closeBraceOffset, int bodyStartLine, int bodyEndLine, unsigned bodyStartColumn) { - body->setLoc(bodyStartLine, bodyEndLine, location.column); - return new (m_globalData) PropertyNode(m_globalData, name, new (m_globalData) FuncExprNode(location, m_globalData->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), params), type); + body->setLoc(bodyStartLine, bodyEndLine, location.startOffset, location.lineStartOffset); + return new (m_vm) PropertyNode(m_vm, name, new (m_vm) FuncExprNode(location, m_vm->propertyNames->nullIdentifier, body, m_sourceCode->subExpression(openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn), params), type); } - ArgumentsNode* createArguments() { return new (m_globalData) ArgumentsNode(); } - ArgumentsNode* createArguments(ArgumentListNode* args) { return new (m_globalData) ArgumentsNode(args); } - ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ExpressionNode* arg) { return new (m_globalData) ArgumentListNode(location, arg); } - ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ArgumentListNode* args, ExpressionNode* arg) { return new (m_globalData) ArgumentListNode(location, args, arg); } + ArgumentsNode* createArguments() { return new (m_vm) ArgumentsNode(); } + ArgumentsNode* createArguments(ArgumentListNode* args) { return new (m_vm) ArgumentsNode(args); } + ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ExpressionNode* arg) { return new (m_vm) ArgumentListNode(location, arg); } + ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ArgumentListNode* args, ExpressionNode* arg) { return new (m_vm) ArgumentListNode(location, args, arg); } template <bool> PropertyNode* createProperty(const Identifier* propertyName, ExpressionNode* node, PropertyNode::Type type) { if (node->isFuncExprNode()) static_cast<FuncExprNode*>(node)->body()->setInferredName(*propertyName); - return new (m_globalData) PropertyNode(m_globalData, *propertyName, node, type); + return new (m_vm) PropertyNode(m_vm, *propertyName, node, type); } - template <bool> PropertyNode* createProperty(JSGlobalData*, double propertyName, ExpressionNode* node, PropertyNode::Type type) { return new (m_globalData) PropertyNode(m_globalData, propertyName, node, type); } - PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property) { return new (m_globalData) PropertyListNode(location, property); } - PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property, PropertyListNode* tail) { return new (m_globalData) PropertyListNode(location, property, tail); } + template <bool> PropertyNode* createProperty(VM*, double propertyName, ExpressionNode* node, PropertyNode::Type type) { return new (m_vm) PropertyNode(m_vm, propertyName, node, type); } + PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property) { return new (m_vm) PropertyListNode(location, property); } + PropertyListNode* createPropertyList(const JSTokenLocation& location, PropertyNode* property, PropertyListNode* tail) { return new (m_vm) PropertyListNode(location, property, tail); } - ElementNode* createElementList(int elisions, ExpressionNode* expr) { return new (m_globalData) ElementNode(elisions, expr); } - ElementNode* createElementList(ElementNode* elems, int elisions, ExpressionNode* expr) { return new (m_globalData) ElementNode(elems, elisions, expr); } + ElementNode* createElementList(int elisions, ExpressionNode* expr) { return new (m_vm) ElementNode(elisions, expr); } + ElementNode* createElementList(ElementNode* elems, int elisions, ExpressionNode* expr) { return new (m_vm) ElementNode(elems, elisions, expr); } - ParameterNode* createFormalParameterList(const Identifier& ident) { return new (m_globalData) ParameterNode(ident); } - ParameterNode* createFormalParameterList(ParameterNode* list, const Identifier& ident) { return new (m_globalData) ParameterNode(list, ident); } + ParameterNode* createFormalParameterList(const Identifier& ident) { return new (m_vm) ParameterNode(ident); } + ParameterNode* createFormalParameterList(ParameterNode* list, const Identifier& ident) { return new (m_vm) ParameterNode(list, ident); } - CaseClauseNode* createClause(ExpressionNode* expr, JSC::SourceElements* statements) { return new (m_globalData) CaseClauseNode(expr, statements); } - ClauseListNode* createClauseList(CaseClauseNode* clause) { return new (m_globalData) ClauseListNode(clause); } - ClauseListNode* createClauseList(ClauseListNode* tail, CaseClauseNode* clause) { return new (m_globalData) ClauseListNode(tail, clause); } + CaseClauseNode* createClause(ExpressionNode* expr, JSC::SourceElements* statements) { return new (m_vm) CaseClauseNode(expr, statements); } + ClauseListNode* createClauseList(CaseClauseNode* clause) { return new (m_vm) ClauseListNode(clause); } + ClauseListNode* createClauseList(ClauseListNode* tail, CaseClauseNode* clause) { return new (m_vm) ClauseListNode(tail, clause); } void setUsesArguments(FunctionBodyNode* node) { node->setUsesArguments(); } - StatementNode* createFuncDeclStatement(const JSTokenLocation& location, const Identifier* name, FunctionBodyNode* body, ParameterNode* parameters, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine) + StatementNode* createFuncDeclStatement(const JSTokenLocation& location, const Identifier* name, FunctionBodyNode* body, ParameterNode* parameters, unsigned openBraceOffset, unsigned closeBraceOffset, int bodyStartLine, int bodyEndLine, unsigned bodyStartColumn) { - FuncDeclNode* decl = new (m_globalData) FuncDeclNode(location, *name, body, m_sourceCode->subExpression(openBracePos, closeBracePos, bodyStartLine), parameters); - if (*name == m_globalData->propertyNames->arguments) + FuncDeclNode* decl = new (m_vm) FuncDeclNode(location, *name, body, m_sourceCode->subExpression(openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn), parameters); + if (*name == m_vm->propertyNames->arguments) usesArguments(); m_scope.m_funcDeclarations->data.append(decl->body()); - body->setLoc(bodyStartLine, bodyEndLine, location.column); + body->setLoc(bodyStartLine, bodyEndLine, location.startOffset, location.lineStartOffset); return decl; } StatementNode* createBlockStatement(const JSTokenLocation& location, JSC::SourceElements* elements, int startLine, int endLine) { - BlockNode* block = new (m_globalData) BlockNode(location, elements); - block->setLoc(startLine, endLine, location.column); + BlockNode* block = new (m_vm) BlockNode(location, elements); + block->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return block; } StatementNode* createExprStatement(const JSTokenLocation& location, ExpressionNode* expr, int start, int end) { - ExprStatementNode* result = new (m_globalData) ExprStatementNode(location, expr); - result->setLoc(start, end, location.column); - return result; - } - - StatementNode* createIfStatement(const JSTokenLocation& location, ExpressionNode* condition, StatementNode* trueBlock, int start, int end) - { - IfNode* result = new (m_globalData) IfNode(location, condition, trueBlock); - result->setLoc(start, end, location.column); + ExprStatementNode* result = new (m_vm) ExprStatementNode(location, expr); + result->setLoc(start, end, location.startOffset, location.lineStartOffset); return result; } StatementNode* createIfStatement(const JSTokenLocation& location, ExpressionNode* condition, StatementNode* trueBlock, StatementNode* falseBlock, int start, int end) { - IfNode* result = new (m_globalData) IfElseNode(location, condition, trueBlock, falseBlock); - result->setLoc(start, end, location.column); + IfElseNode* result = new (m_vm) IfElseNode(location, condition, trueBlock, falseBlock); + result->setLoc(start, end, location.startOffset, location.lineStartOffset); return result; } StatementNode* createForLoop(const JSTokenLocation& location, ExpressionNode* initializer, ExpressionNode* condition, ExpressionNode* iter, StatementNode* statements, int start, int end) { - ForNode* result = new (m_globalData) ForNode(location, initializer, condition, iter, statements); - result->setLoc(start, end); + ForNode* result = new (m_vm) ForNode(location, initializer, condition, iter, statements); + result->setLoc(start, end, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createForInLoop(const JSTokenLocation& location, const Identifier* ident, ExpressionNode* initializer, ExpressionNode* iter, StatementNode* statements, int start, int divot, int end, int initStart, int initEnd, int startLine, int endLine) + StatementNode* createForInLoop(const JSTokenLocation& location, const Identifier* ident, ExpressionNode* initializer, ExpressionNode* iter, StatementNode* statements, int start, int divot, int end, int initStart, int initEnd, int startLine, int endLine, unsigned divotLine, unsigned divotLineStart) { - ForInNode* result = new (m_globalData) ForInNode(m_globalData, location, *ident, initializer, iter, statements, initStart, initStart - start, initEnd - initStart); - result->setLoc(startLine, endLine, location.column); - setExceptionLocation(result, start, divot + 1, end); + ForInNode* result = new (m_vm) ForInNode(m_vm, location, *ident, initializer, iter, statements, initStart, initStart - start, initEnd - initStart, divotLine, divotLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); + setExceptionLocation(result, start, divot + 1, end, divotLine, divotLineStart); return result; } - StatementNode* createForInLoop(const JSTokenLocation& location, ExpressionNode* lhs, ExpressionNode* iter, StatementNode* statements, int eStart, int eDivot, int eEnd, int start, int end) + StatementNode* createForInLoop(const JSTokenLocation& location, ExpressionNode* lhs, ExpressionNode* iter, StatementNode* statements, int eStart, int eDivot, int eEnd, int start, int end, unsigned divotLine, unsigned divotLineStart) { - ForInNode* result = new (m_globalData) ForInNode(location, lhs, iter, statements); - result->setLoc(start, end, location.column); - setExceptionLocation(result, eStart, eDivot, eEnd); + ForInNode* result = new (m_vm) ForInNode(location, lhs, iter, statements); + result->setLoc(start, end, location.startOffset, location.lineStartOffset); + setExceptionLocation(result, eStart, eDivot, eEnd, divotLine, divotLineStart); return result; } - StatementNode* createEmptyStatement(const JSTokenLocation& location) { return new (m_globalData) EmptyStatementNode(location); } + StatementNode* createEmptyStatement(const JSTokenLocation& location) { return new (m_vm) EmptyStatementNode(location); } StatementNode* createVarStatement(const JSTokenLocation& location, ExpressionNode* expr, int start, int end) { StatementNode* result; if (!expr) - result = new (m_globalData) EmptyStatementNode(location); + result = new (m_vm) EmptyStatementNode(location); else - result = new (m_globalData) VarStatementNode(location, expr); - result->setLoc(start, end, location.column); + result = new (m_vm) VarStatementNode(location, expr); + result->setLoc(start, end, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createReturnStatement(const JSTokenLocation& location, ExpressionNode* expression, int eStart, int eEnd, int startLine, int endLine) + StatementNode* createReturnStatement(const JSTokenLocation& location, ExpressionNode* expression, int eStart, int eEnd, int startLine, int endLine, unsigned divotLine, unsigned divotLineStart) { - ReturnNode* result = new (m_globalData) ReturnNode(location, expression); - setExceptionLocation(result, eStart, eEnd, eEnd); - result->setLoc(startLine, endLine, location.column); + ReturnNode* result = new (m_vm) ReturnNode(location, expression); + setExceptionLocation(result, eStart, eEnd, eEnd, divotLine, divotLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createBreakStatement(const JSTokenLocation& location, int eStart, int eEnd, int startLine, int endLine) + StatementNode* createBreakStatement(const JSTokenLocation& location, int eStart, int eEnd, int startLine, int endLine, unsigned endLineStart) { - BreakNode* result = new (m_globalData) BreakNode(m_globalData, location); - setExceptionLocation(result, eStart, eEnd, eEnd); - result->setLoc(startLine, endLine, location.column); + BreakNode* result = new (m_vm) BreakNode(m_vm, location); + setExceptionLocation(result, eStart, eEnd, eEnd, endLine, endLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createBreakStatement(const JSTokenLocation& location, const Identifier* ident, int eStart, int eEnd, int startLine, int endLine) + StatementNode* createBreakStatement(const JSTokenLocation& location, const Identifier* ident, int eStart, int eEnd, int startLine, int endLine, unsigned endLineStart) { - BreakNode* result = new (m_globalData) BreakNode(location, *ident); - setExceptionLocation(result, eStart, eEnd, eEnd); - result->setLoc(startLine, endLine, location.column); + BreakNode* result = new (m_vm) BreakNode(location, *ident); + setExceptionLocation(result, eStart, eEnd, eEnd, endLine, endLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createContinueStatement(const JSTokenLocation& location, int eStart, int eEnd, int startLine, int endLine) + StatementNode* createContinueStatement(const JSTokenLocation& location, int eStart, int eEnd, int startLine, int endLine, unsigned endLineStart) { - ContinueNode* result = new (m_globalData) ContinueNode(m_globalData, location); - setExceptionLocation(result, eStart, eEnd, eEnd); - result->setLoc(startLine, endLine, location.column); + ContinueNode* result = new (m_vm) ContinueNode(m_vm, location); + setExceptionLocation(result, eStart, eEnd, eEnd, endLine, endLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createContinueStatement(const JSTokenLocation& location, const Identifier* ident, int eStart, int eEnd, int startLine, int endLine) + StatementNode* createContinueStatement(const JSTokenLocation& location, const Identifier* ident, int eStart, int eEnd, int startLine, int endLine, unsigned endLineStart) { - ContinueNode* result = new (m_globalData) ContinueNode(location, *ident); - setExceptionLocation(result, eStart, eEnd, eEnd); - result->setLoc(startLine, endLine, location.column); + ContinueNode* result = new (m_vm) ContinueNode(location, *ident); + setExceptionLocation(result, eStart, eEnd, eEnd, endLine, endLineStart); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } StatementNode* createTryStatement(const JSTokenLocation& location, StatementNode* tryBlock, const Identifier* ident, StatementNode* catchBlock, StatementNode* finallyBlock, int startLine, int endLine) { - TryNode* result = new (m_globalData) TryNode(location, tryBlock, *ident, catchBlock, finallyBlock); + TryNode* result = new (m_vm) TryNode(location, tryBlock, *ident, catchBlock, finallyBlock); if (catchBlock) usesCatch(); - result->setLoc(startLine, endLine, location.column); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } StatementNode* createSwitchStatement(const JSTokenLocation& location, ExpressionNode* expr, ClauseListNode* firstClauses, CaseClauseNode* defaultClause, ClauseListNode* secondClauses, int startLine, int endLine) { - CaseBlockNode* cases = new (m_globalData) CaseBlockNode(firstClauses, defaultClause, secondClauses); - SwitchNode* result = new (m_globalData) SwitchNode(location, expr, cases); - result->setLoc(startLine, endLine, location.column); + CaseBlockNode* cases = new (m_vm) CaseBlockNode(firstClauses, defaultClause, secondClauses); + SwitchNode* result = new (m_vm) SwitchNode(location, expr, cases); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } StatementNode* createWhileStatement(const JSTokenLocation& location, ExpressionNode* expr, StatementNode* statement, int startLine, int endLine) { - WhileNode* result = new (m_globalData) WhileNode(location, expr, statement); - result->setLoc(startLine, endLine, location.column); + WhileNode* result = new (m_vm) WhileNode(location, expr, statement); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } StatementNode* createDoWhileStatement(const JSTokenLocation& location, StatementNode* statement, ExpressionNode* expr, int startLine, int endLine) { - DoWhileNode* result = new (m_globalData) DoWhileNode(location, statement, expr); - result->setLoc(startLine, endLine, location.column); + DoWhileNode* result = new (m_vm) DoWhileNode(location, statement, expr); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createLabelStatement(const JSTokenLocation& location, const Identifier* ident, StatementNode* statement, int start, int end) + StatementNode* createLabelStatement(const JSTokenLocation& location, const Identifier* ident, StatementNode* statement, unsigned start, unsigned end, unsigned divotLine, unsigned divotLineStart) { - LabelNode* result = new (m_globalData) LabelNode(location, *ident, statement); - setExceptionLocation(result, start, end, end); + LabelNode* result = new (m_vm) LabelNode(location, *ident, statement); + setExceptionLocation(result, start, end, end, divotLine, divotLineStart); return result; } - StatementNode* createWithStatement(const JSTokenLocation& location, ExpressionNode* expr, StatementNode* statement, int start, int end, int startLine, int endLine) + StatementNode* createWithStatement(const JSTokenLocation& location, ExpressionNode* expr, StatementNode* statement, unsigned start, unsigned end, unsigned startLine, unsigned endLine, unsigned divotLine, unsigned divotLineStart) { usesWith(); - WithNode* result = new (m_globalData) WithNode(location, expr, statement, end, end - start); - result->setLoc(startLine, endLine, location.column); + WithNode* result = new (m_vm) WithNode(location, expr, statement, end, divotLine, divotLineStart, end - start); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } - StatementNode* createThrowStatement(const JSTokenLocation& location, ExpressionNode* expr, int start, int end, int startLine, int endLine) + StatementNode* createThrowStatement(const JSTokenLocation& location, ExpressionNode* expr, int start, int end, int startLine, int endLine, unsigned divotLine, unsigned divotLineStart) { - ThrowNode* result = new (m_globalData) ThrowNode(location, expr); - result->setLoc(startLine, endLine, location.column); - setExceptionLocation(result, start, end, end); + ThrowNode* result = new (m_vm) ThrowNode(location, expr); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); + setExceptionLocation(result, start, end, end, divotLine, divotLineStart); return result; } StatementNode* createDebugger(const JSTokenLocation& location, int startLine, int endLine) { - DebuggerStatementNode* result = new (m_globalData) DebuggerStatementNode(location); - result->setLoc(startLine, endLine, location.column); + DebuggerStatementNode* result = new (m_vm) DebuggerStatementNode(location); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } StatementNode* createConstStatement(const JSTokenLocation& location, ConstDeclNode* decls, int startLine, int endLine) { - ConstStatementNode* result = new (m_globalData) ConstStatementNode(location, decls); - result->setLoc(startLine, endLine, location.column); + ConstStatementNode* result = new (m_vm) ConstStatementNode(location, decls); + result->setLoc(startLine, endLine, location.startOffset, location.lineStartOffset); return result; } ConstDeclNode* appendConstDecl(const JSTokenLocation& location, ConstDeclNode* tail, const Identifier* name, ExpressionNode* initializer) { - ConstDeclNode* result = new (m_globalData) ConstDeclNode(location, *name, initializer); + ConstDeclNode* result = new (m_vm) ConstDeclNode(location, *name, initializer); if (tail) tail->m_next = result; return result; @@ -506,7 +528,7 @@ public: void addVar(const Identifier* ident, int attrs) { - if (m_globalData->propertyNames->arguments == *ident) + if (m_vm->propertyNames->arguments == *ident) usesArguments(); m_scope.m_varDeclarations->data.append(std::make_pair(ident, attrs)); } @@ -519,15 +541,15 @@ public: static_cast<CommaNode*>(list)->append(init); return list; } - return new (m_globalData) CommaNode(location, list, init); + return new (m_vm) CommaNode(location, list, init); } int evalCount() const { return m_evalCount; } - void appendBinaryExpressionInfo(int& operandStackDepth, ExpressionNode* current, int exprStart, int lhs, int rhs, bool hasAssignments) + void appendBinaryExpressionInfo(int& operandStackDepth, ExpressionNode* current, int exprStart, int lhs, int rhs, unsigned divotLine, unsigned divotLineStart, bool hasAssignments) { operandStackDepth++; - m_binaryOperandStack.append(std::make_pair(current, BinaryOpInfo(exprStart, lhs, rhs, hasAssignments))); + m_binaryOperandStack.append(std::make_pair(current, BinaryOpInfo(exprStart, lhs, rhs, divotLine, divotLineStart, hasAssignments))); } // Logic to handle datastructures used during parsing of binary expressions @@ -564,10 +586,11 @@ public: return result; } - void appendUnaryToken(int& tokenStackDepth, int type, int start) + void appendUnaryToken(int& tokenStackDepth, int type, unsigned start, unsigned divotLine, unsigned divotLineStart) { tokenStackDepth++; - m_unaryTokenStack.append(std::make_pair(type, start)); + PositionInfo position = { start, divotLine, divotLineStart }; + m_unaryTokenStack.append(std::make_pair(type, position)); } int unaryTokenStackLastType(int&) @@ -575,26 +598,34 @@ public: return m_unaryTokenStack.last().first; } - int unaryTokenStackLastStart(int&) + unsigned unaryTokenStackLastStart(int&) { - return m_unaryTokenStack.last().second; + return m_unaryTokenStack.last().second.startPos; } + unsigned unaryTokenStackLastLineStartPosition(int&) + { + return m_unaryTokenStack.last().second.lineStartPos; + } + void unaryTokenStackRemoveLast(int& tokenStackDepth) { tokenStackDepth--; m_unaryTokenStack.removeLast(); } - void assignmentStackAppend(int& assignmentStackDepth, ExpressionNode* node, int start, int divot, int assignmentCount, Operator op) + void assignmentStackAppend(int& assignmentStackDepth, ExpressionNode* node, unsigned start, unsigned divot, unsigned divotLine, unsigned divotLineStart, int assignmentCount, Operator op) { assignmentStackDepth++; - m_assignmentInfoStack.append(AssignmentInfo(node, start, divot, assignmentCount, op)); + ASSERT(start >= divotLineStart); + ASSERT(divot >= divotLineStart); + m_assignmentInfoStack.append(AssignmentInfo(node, start, divot, divotLine, divotLineStart, assignmentCount, op)); } ExpressionNode* createAssignment(const JSTokenLocation& location, int& assignmentStackDepth, ExpressionNode* rhs, int initialAssignmentCount, int currentAssignmentCount, int lastTokenEnd) { - ExpressionNode* result = makeAssignNode(location, m_assignmentInfoStack.last().m_node, m_assignmentInfoStack.last().m_op, rhs, m_assignmentInfoStack.last().m_initAssignments != initialAssignmentCount, m_assignmentInfoStack.last().m_initAssignments != currentAssignmentCount, m_assignmentInfoStack.last().m_start, m_assignmentInfoStack.last().m_divot + 1, lastTokenEnd); + AssignmentInfo& info = m_assignmentInfoStack.last(); + ExpressionNode* result = makeAssignNode(location, info.m_node, info.m_op, rhs, info.m_initAssignments != initialAssignmentCount, info.m_initAssignments != currentAssignmentCount, info.m_start, info.m_divot + 1, lastTokenEnd, info.m_divotLine, info.m_divotLineStart); m_assignmentInfoStack.removeLast(); assignmentStackDepth--; return result; @@ -607,9 +638,9 @@ public: private: struct Scope { - Scope(JSGlobalData* globalData) - : m_varDeclarations(new (globalData) ParserArenaData<DeclarationStacks::VarStack>) - , m_funcDeclarations(new (globalData) ParserArenaData<DeclarationStacks::FunctionStack>) + Scope(VM* vm) + : m_varDeclarations(new (vm) ParserArenaData<DeclarationStacks::VarStack>) + , m_funcDeclarations(new (vm) ParserArenaData<DeclarationStacks::FunctionStack>) , m_features(0) , m_numConstants(0) { @@ -620,9 +651,10 @@ private: int m_numConstants; }; - static void setExceptionLocation(ThrowableExpressionData* node, unsigned start, unsigned divot, unsigned end) + static void setExceptionLocation(ThrowableExpressionData* node, unsigned start, unsigned divot, unsigned end, unsigned divotLine, unsigned divotLineStart) { - node->setExceptionSourceCode(divot, divot - start, end - divot); + ASSERT(divot >= divotLineStart); + node->setExceptionSourceCode(divot, divot - start, end - divot, divotLine, divotLineStart); } void incConstants() { m_scope.m_numConstants++; } @@ -637,16 +669,16 @@ private: } ExpressionNode* createNumber(const JSTokenLocation& location, double d) { - return new (m_globalData) NumberNode(location, d); + return new (m_vm) NumberNode(location, d); } - JSGlobalData* m_globalData; + VM* m_vm; SourceCode* m_sourceCode; Scope m_scope; - Vector<BinaryOperand, 10> m_binaryOperandStack; - Vector<AssignmentInfo, 10> m_assignmentInfoStack; - Vector<pair<int, int>, 10> m_binaryOperatorStack; - Vector<pair<int, int>, 10> m_unaryTokenStack; + Vector<BinaryOperand, 10, UnsafeVectorOverflow> m_binaryOperandStack; + Vector<AssignmentInfo, 10, UnsafeVectorOverflow> m_assignmentInfoStack; + Vector<pair<int, int>, 10, UnsafeVectorOverflow> m_binaryOperatorStack; + Vector<pair<int, PositionInfo>, 10, UnsafeVectorOverflow> m_unaryTokenStack; int m_evalCount; }; @@ -654,26 +686,26 @@ ExpressionNode* ASTBuilder::makeTypeOfNode(const JSTokenLocation& location, Expr { if (expr->isResolveNode()) { ResolveNode* resolve = static_cast<ResolveNode*>(expr); - return new (m_globalData) TypeOfResolveNode(location, resolve->identifier()); + return new (m_vm) TypeOfResolveNode(location, resolve->identifier()); } - return new (m_globalData) TypeOfValueNode(location, expr); + return new (m_vm) TypeOfValueNode(location, expr); } -ExpressionNode* ASTBuilder::makeDeleteNode(const JSTokenLocation& location, ExpressionNode* expr, int start, int divot, int end) +ExpressionNode* ASTBuilder::makeDeleteNode(const JSTokenLocation& location, ExpressionNode* expr, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { if (!expr->isLocation()) - return new (m_globalData) DeleteValueNode(location, expr); + return new (m_vm) DeleteValueNode(location, expr); if (expr->isResolveNode()) { ResolveNode* resolve = static_cast<ResolveNode*>(expr); - return new (m_globalData) DeleteResolveNode(location, resolve->identifier(), divot, divot - start, end - divot); + return new (m_vm) DeleteResolveNode(location, resolve->identifier(), divot, divot - start, end - divot, divotLine, divotLineStart); } if (expr->isBracketAccessorNode()) { BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr); - return new (m_globalData) DeleteBracketNode(location, bracket->base(), bracket->subscript(), divot, divot - start, end - divot); + return new (m_vm) DeleteBracketNode(location, bracket->base(), bracket->subscript(), divot, divot - start, end - divot, divotLine, divotLineStart); } ASSERT(expr->isDotAccessorNode()); DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr); - return new (m_globalData) DeleteDotNode(location, dot->base(), dot->identifier(), divot, divot - start, end - divot); + return new (m_vm) DeleteDotNode(location, dot->base(), dot->identifier(), divot, divot - start, end - divot, divotLine, divotLineStart); } ExpressionNode* ASTBuilder::makeNegateNode(const JSTokenLocation& location, ExpressionNode* n) @@ -684,14 +716,14 @@ ExpressionNode* ASTBuilder::makeNegateNode(const JSTokenLocation& location, Expr return numberNode; } - return new (m_globalData) NegateNode(location, n); + return new (m_vm) NegateNode(location, n); } ExpressionNode* ASTBuilder::makeBitwiseNotNode(const JSTokenLocation& location, ExpressionNode* expr) { if (expr->isNumber()) return createNumber(location, ~toInt32(static_cast<NumberNode*>(expr)->value())); - return new (m_globalData) BitwiseNotNode(location, expr); + return new (m_vm) BitwiseNotNode(location, expr); } ExpressionNode* ASTBuilder::makeMultNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) @@ -703,12 +735,12 @@ ExpressionNode* ASTBuilder::makeMultNode(const JSTokenLocation& location, Expres return createNumber(location, static_cast<NumberNode*>(expr1)->value() * static_cast<NumberNode*>(expr2)->value()); if (expr1->isNumber() && static_cast<NumberNode*>(expr1)->value() == 1) - return new (m_globalData) UnaryPlusNode(location, expr2); + return new (m_vm) UnaryPlusNode(location, expr2); if (expr2->isNumber() && static_cast<NumberNode*>(expr2)->value() == 1) - return new (m_globalData) UnaryPlusNode(location, expr1); + return new (m_vm) UnaryPlusNode(location, expr1); - return new (m_globalData) MultNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) MultNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeDivNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) @@ -718,7 +750,7 @@ ExpressionNode* ASTBuilder::makeDivNode(const JSTokenLocation& location, Express if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, static_cast<NumberNode*>(expr1)->value() / static_cast<NumberNode*>(expr2)->value()); - return new (m_globalData) DivNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) DivNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeModNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) @@ -728,14 +760,14 @@ ExpressionNode* ASTBuilder::makeModNode(const JSTokenLocation& location, Express if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, fmod(static_cast<NumberNode*>(expr1)->value(), static_cast<NumberNode*>(expr2)->value())); - return new (m_globalData) ModNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) ModNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeAddNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, static_cast<NumberNode*>(expr1)->value() + static_cast<NumberNode*>(expr2)->value()); - return new (m_globalData) AddNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) AddNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeSubNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) @@ -745,80 +777,81 @@ ExpressionNode* ASTBuilder::makeSubNode(const JSTokenLocation& location, Express if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, static_cast<NumberNode*>(expr1)->value() - static_cast<NumberNode*>(expr2)->value()); - return new (m_globalData) SubNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) SubNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeLeftShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toInt32(static_cast<NumberNode*>(expr1)->value()) << (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f)); - return new (m_globalData) LeftShiftNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) LeftShiftNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeRightShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f)); - return new (m_globalData) RightShiftNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) RightShiftNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeURightShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toUInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f)); - return new (m_globalData) UnsignedRightShiftNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) UnsignedRightShiftNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeBitOrNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toInt32(static_cast<NumberNode*>(expr1)->value()) | toInt32(static_cast<NumberNode*>(expr2)->value())); - return new (m_globalData) BitOrNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) BitOrNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeBitAndNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toInt32(static_cast<NumberNode*>(expr1)->value()) & toInt32(static_cast<NumberNode*>(expr2)->value())); - return new (m_globalData) BitAndNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) BitAndNode(location, expr1, expr2, rightHasAssignments); } ExpressionNode* ASTBuilder::makeBitXOrNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber()) return createNumber(location, toInt32(static_cast<NumberNode*>(expr1)->value()) ^ toInt32(static_cast<NumberNode*>(expr2)->value())); - return new (m_globalData) BitXOrNode(location, expr1, expr2, rightHasAssignments); + return new (m_vm) BitXOrNode(location, expr1, expr2, rightHasAssignments); } -ExpressionNode* ASTBuilder::makeFunctionCallNode(const JSTokenLocation& location, ExpressionNode* func, ArgumentsNode* args, int start, int divot, int end) +ExpressionNode* ASTBuilder::makeFunctionCallNode(const JSTokenLocation& location, ExpressionNode* func, ArgumentsNode* args, int start, unsigned divot, int end, unsigned divotLine, unsigned divotLineStart) { + ASSERT(divot >= divotLineStart); if (!func->isLocation()) - return new (m_globalData) FunctionCallValueNode(location, func, args, divot, divot - start, end - divot); + return new (m_vm) FunctionCallValueNode(location, func, args, divot, divot - start, end - divot, divotLine, divotLineStart); if (func->isResolveNode()) { ResolveNode* resolve = static_cast<ResolveNode*>(func); const Identifier& identifier = resolve->identifier(); - if (identifier == m_globalData->propertyNames->eval) { + if (identifier == m_vm->propertyNames->eval) { usesEval(); - return new (m_globalData) EvalFunctionCallNode(location, args, divot, divot - start, end - divot); + return new (m_vm) EvalFunctionCallNode(location, args, divot, divot - start, end - divot, divotLine, divotLineStart); } - return new (m_globalData) FunctionCallResolveNode(location, identifier, args, divot, divot - start, end - divot); + return new (m_vm) FunctionCallResolveNode(location, identifier, args, divot, divot - start, end - divot, divotLine, divotLineStart); } if (func->isBracketAccessorNode()) { BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func); - FunctionCallBracketNode* node = new (m_globalData) FunctionCallBracketNode(location, bracket->base(), bracket->subscript(), args, divot, divot - start, end - divot); - node->setSubexpressionInfo(bracket->divot(), bracket->endOffset()); + FunctionCallBracketNode* node = new (m_vm) FunctionCallBracketNode(location, bracket->base(), bracket->subscript(), args, divot, divot - start, end - divot, divotLine, divotLineStart); + node->setSubexpressionInfo(bracket->divot(), bracket->divotEndOffset(), bracket->divotLine(), bracket->divotLineStart()); return node; } ASSERT(func->isDotAccessorNode()); DotAccessorNode* dot = static_cast<DotAccessorNode*>(func); FunctionCallDotNode* node; - if (dot->identifier() == m_globalData->propertyNames->call) - node = new (m_globalData) CallFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot); - else if (dot->identifier() == m_globalData->propertyNames->apply) - node = new (m_globalData) ApplyFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot); + if (dot->identifier() == m_vm->propertyNames->call) + node = new (m_vm) CallFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot, divotLine, divotLineStart); + else if (dot->identifier() == m_vm->propertyNames->apply) + node = new (m_vm) ApplyFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot, divotLine, divotLineStart); else - node = new (m_globalData) FunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot); - node->setSubexpressionInfo(dot->divot(), dot->endOffset()); + node = new (m_vm) FunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divot - start, end - divot, divotLine, divotLineStart); + node->setSubexpressionInfo(dot->divot(), dot->divotEndOffset(), dot->divotLine(), dot->divotLineStart()); return node; } @@ -826,10 +859,10 @@ ExpressionNode* ASTBuilder::makeBinaryNode(const JSTokenLocation& location, int { switch (token) { case OR: - return new (m_globalData) LogicalOpNode(location, lhs.first, rhs.first, OpLogicalOr); + return new (m_vm) LogicalOpNode(location, lhs.first, rhs.first, OpLogicalOr); case AND: - return new (m_globalData) LogicalOpNode(location, lhs.first, rhs.first, OpLogicalAnd); + return new (m_vm) LogicalOpNode(location, lhs.first, rhs.first, OpLogicalAnd); case BITOR: return makeBitOrNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); @@ -841,38 +874,38 @@ ExpressionNode* ASTBuilder::makeBinaryNode(const JSTokenLocation& location, int return makeBitAndNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case EQEQ: - return new (m_globalData) EqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) EqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case NE: - return new (m_globalData) NotEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) NotEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case STREQ: - return new (m_globalData) StrictEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) StrictEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case STRNEQ: - return new (m_globalData) NotStrictEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) NotStrictEqualNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case LT: - return new (m_globalData) LessNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) LessNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case GT: - return new (m_globalData) GreaterNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) GreaterNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case LE: - return new (m_globalData) LessEqNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) LessEqNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case GE: - return new (m_globalData) GreaterEqNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + return new (m_vm) GreaterEqNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); case INSTANCEOF: { - InstanceOfNode* node = new (m_globalData) InstanceOfNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); - setExceptionLocation(node, lhs.second.start, rhs.second.start, rhs.second.end); + InstanceOfNode* node = new (m_vm) InstanceOfNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + setExceptionLocation(node, lhs.second.start, rhs.second.start, rhs.second.end, rhs.second.divotLine, rhs.second.divotLineStart); return node; } case INTOKEN: { - InNode* node = new (m_globalData) InNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); - setExceptionLocation(node, lhs.second.start, rhs.second.start, rhs.second.end); + InNode* node = new (m_vm) InNode(location, lhs.first, rhs.first, rhs.second.hasAssignment); + setExceptionLocation(node, lhs.second.start, rhs.second.start, rhs.second.end, rhs.second.divotLine, rhs.second.divotLineStart); return node; } @@ -904,28 +937,28 @@ ExpressionNode* ASTBuilder::makeBinaryNode(const JSTokenLocation& location, int return 0; } -ExpressionNode* ASTBuilder::makeAssignNode(const JSTokenLocation& location, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end) +ExpressionNode* ASTBuilder::makeAssignNode(const JSTokenLocation& location, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { if (!loc->isLocation()) - return new (m_globalData) AssignErrorNode(location, divot, divot - start, end - divot); + return new (m_vm) AssignErrorNode(location, divot, divot - start, end - divot, divotLine, divotLineStart); if (loc->isResolveNode()) { ResolveNode* resolve = static_cast<ResolveNode*>(loc); if (op == OpEqual) { if (expr->isFuncExprNode()) static_cast<FuncExprNode*>(expr)->body()->setInferredName(resolve->identifier()); - AssignResolveNode* node = new (m_globalData) AssignResolveNode(location, resolve->identifier(), expr); - setExceptionLocation(node, start, divot, end); + AssignResolveNode* node = new (m_vm) AssignResolveNode(location, resolve->identifier(), expr); + setExceptionLocation(node, start, divot, end, divotLine, divotLineStart); return node; } - return new (m_globalData) ReadModifyResolveNode(location, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot); + return new (m_vm) ReadModifyResolveNode(location, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot, divotLine, divotLineStart); } if (loc->isBracketAccessorNode()) { BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc); if (op == OpEqual) - return new (m_globalData) AssignBracketNode(location, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot()); - ReadModifyBracketNode* node = new (m_globalData) ReadModifyBracketNode(location, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot); - node->setSubexpressionInfo(bracket->divot(), bracket->endOffset()); + return new (m_vm) AssignBracketNode(location, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot(), bracket->divotLine(), bracket->divotLineStart()); + ReadModifyBracketNode* node = new (m_vm) ReadModifyBracketNode(location, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot, divotLine, divotLineStart); + node->setSubexpressionInfo(bracket->divot(), bracket->divotEndOffset(), bracket->divotLine(), bracket->divotLineStart()); return node; } ASSERT(loc->isDotAccessorNode()); @@ -933,22 +966,22 @@ ExpressionNode* ASTBuilder::makeAssignNode(const JSTokenLocation& location, Expr if (op == OpEqual) { if (expr->isFuncExprNode()) static_cast<FuncExprNode*>(expr)->body()->setInferredName(dot->identifier()); - return new (m_globalData) AssignDotNode(location, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot()); + return new (m_vm) AssignDotNode(location, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot(), dot->divotLine(), dot->divotLineStart()); } - ReadModifyDotNode* node = new (m_globalData) ReadModifyDotNode(location, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot); - node->setSubexpressionInfo(dot->divot(), dot->endOffset()); + ReadModifyDotNode* node = new (m_vm) ReadModifyDotNode(location, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot, divotLine, divotLineStart); + node->setSubexpressionInfo(dot->divot(), dot->divotEndOffset(), dot->divotLine(), dot->divotLineStart()); return node; } -ExpressionNode* ASTBuilder::makePrefixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator op, int start, int divot, int end) +ExpressionNode* ASTBuilder::makePrefixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator op, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { - return new (m_globalData) PrefixNode(location, expr, op, divot, divot - start, end - divot); + return new (m_vm) PrefixNode(location, expr, op, divot, divot - start, end - divot, divotLine, divotLineStart); } -ExpressionNode* ASTBuilder::makePostfixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator op, int start, int divot, int end) +ExpressionNode* ASTBuilder::makePostfixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator op, int start, int divot, int end, unsigned divotLine, unsigned divotLineStart) { - return new (m_globalData) PostfixNode(location, expr, op, divot, divot - start, end - divot); + return new (m_vm) PostfixNode(location, expr, op, divot, divot - start, end - divot, divotLine, divotLineStart); } } |