4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "CommonIdentifiers.h"
37 #include <wtf/MathExtras.h>
39 // Not sure why, but yacc doesn't add this define along with the others.
40 #define yylloc kjsyylloc
42 #define YYMAXDEPTH 10000
43 #define YYENABLE_NLS 0
45 /* default values for bison */
46 #define YYDEBUG 0 // Set to 1 to debug a parse error.
47 #define kjsyydebug 0 // Set to 1 to debug a parse error.
49 // avoid triggering warnings in older bison
50 #define YYERROR_VERBOSE
53 extern int kjsyylex();
54 int kjsyyerror(const char *);
55 static bool allowAutomaticSemicolon();
57 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon()) YYABORT; } while (0)
58 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line)
63 static AddNode* makeAddNode(ExpressionNode*, ExpressionNode*);
64 static LessNode* makeLessNode(ExpressionNode*, ExpressionNode*);
65 static ExpressionNode* makeAssignNode(ExpressionNode* loc, Operator, ExpressionNode* expr);
66 static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator);
67 static ExpressionNode* makePostfixNode(ExpressionNode* expr, Operator);
68 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*);
69 static ExpressionNode* makeFunctionCallNode(ExpressionNode* func, ArgumentsNode*);
70 static ExpressionNode* makeTypeOfNode(ExpressionNode*);
71 static ExpressionNode* makeDeleteNode(ExpressionNode*);
72 static ExpressionNode* makeNegateNode(ExpressionNode*);
73 static NumberNode* makeNumberNode(double);
74 static StatementNode* makeVarStatementNode(ExpressionNode*);
75 static ExpressionNode* combineVarInitializers(ExpressionNode* list, AssignResolveNode* init);
80 #pragma warning(disable: 4065)
81 #pragma warning(disable: 4244)
82 #pragma warning(disable: 4702)
84 // At least some of the time, the declarations of malloc and free that bison
85 // generates are causing warnings. A way to avoid this is to explicitly define
86 // the macros so that bison doesn't try to declare malloc and free.
87 #define YYMALLOC malloc
92 template <typename T> NodeInfo<T> createNodeInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls,
93 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcDecls)
95 NodeInfo<T> result = {node, varDecls, funcDecls};
99 template <typename T> T mergeDeclarationLists(T decls1, T decls2)
101 // decls1 or both are null
104 // only decls1 is non-null
109 decls1->data.append(decls2->data);
111 // We manually release the declaration lists to avoid accumulating many many
112 // unused heap allocated vectors
118 static void appendToVarDeclarationList(ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)
121 varDecls = new ParserRefCountedData<DeclarationStacks::VarStack>;
123 varDecls->data.append(make_pair(ident, attrs));
127 static inline void appendToVarDeclarationList(ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl)
129 unsigned attrs = DeclarationStacks::IsConstant;
131 attrs |= DeclarationStacks::HasInitializer;
132 appendToVarDeclarationList(varDecls, decl->m_ident, attrs);
143 // expression subtrees
144 ExpressionNode* expressionNode;
145 FuncDeclNode* funcDeclNode;
146 PropertyNode* propertyNode;
147 ArgumentsNode* argumentsNode;
148 ConstDeclNode* constDeclNode;
149 CaseBlockNodeInfo caseBlockNode;
150 CaseClauseNodeInfo caseClauseNode;
151 FuncExprNode* funcExprNode;
154 StatementNodeInfo statementNode;
155 FunctionBodyNode* functionBodyNode;
156 ProgramNode* programNode;
158 SourceElementsInfo sourceElements;
159 PropertyList propertyList;
160 ArgumentList argumentList;
161 VarDeclListInfo varDeclList;
162 ConstDeclListInfo constDeclList;
163 ClauseListInfo clauseList;
164 ElementList elementList;
165 ParameterList parameterList;
173 %token NULLTOKEN TRUETOKEN FALSETOKEN
176 %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE
177 %token FUNCTION RETURN VOIDTOKEN DELETETOKEN
178 %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
179 %token SWITCH WITH RESERVED
180 %token THROW TRY CATCH FINALLY
183 /* give an if without an else higher precedence than an else to resolve the ambiguity */
184 %nonassoc IF_WITHOUT_ELSE
188 %token EQEQ NE /* == and != */
189 %token STREQ STRNEQ /* === and !== */
190 %token LE GE /* < and > */
191 %token OR AND /* || and && */
192 %token PLUSPLUS MINUSMINUS /* ++ and -- */
193 %token LSHIFT /* << */
194 %token RSHIFT URSHIFT /* >> and >>> */
195 %token PLUSEQUAL MINUSEQUAL /* += and -= */
196 %token MULTEQUAL DIVEQUAL /* *= and /= */
197 %token LSHIFTEQUAL /* <<= */
198 %token RSHIFTEQUAL URSHIFTEQUAL /* >>= and >>>= */
199 %token ANDEQUAL MODEQUAL /* &= and %= */
200 %token XOREQUAL OREQUAL /* ^= and |= */
203 %token <doubleValue> NUMBER
204 %token <string> STRING
207 /* automatically inserted semicolon */
208 %token AUTOPLUSPLUS AUTOMINUSMINUS
210 /* non-terminal types */
211 %type <expressionNode> Literal ArrayLiteral
213 %type <expressionNode> PrimaryExpr PrimaryExprNoBrace
214 %type <expressionNode> MemberExpr MemberExprNoBF /* BF => brace or function */
215 %type <expressionNode> NewExpr NewExprNoBF
216 %type <expressionNode> CallExpr CallExprNoBF
217 %type <expressionNode> LeftHandSideExpr LeftHandSideExprNoBF
218 %type <expressionNode> PostfixExpr PostfixExprNoBF
219 %type <expressionNode> UnaryExpr UnaryExprNoBF UnaryExprCommon
220 %type <expressionNode> MultiplicativeExpr MultiplicativeExprNoBF
221 %type <expressionNode> AdditiveExpr AdditiveExprNoBF
222 %type <expressionNode> ShiftExpr ShiftExprNoBF
223 %type <expressionNode> RelationalExpr RelationalExprNoIn RelationalExprNoBF
224 %type <expressionNode> EqualityExpr EqualityExprNoIn EqualityExprNoBF
225 %type <expressionNode> BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF
226 %type <expressionNode> BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF
227 %type <expressionNode> BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF
228 %type <expressionNode> LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF
229 %type <expressionNode> LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF
230 %type <expressionNode> ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF
231 %type <expressionNode> AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF
232 %type <expressionNode> Expr ExprNoIn ExprNoBF
234 %type <expressionNode> ExprOpt ExprNoInOpt
236 %type <statementNode> Statement Block
237 %type <statementNode> VariableStatement ConstStatement EmptyStatement ExprStatement
238 %type <statementNode> IfStatement IterationStatement ContinueStatement
239 %type <statementNode> BreakStatement ReturnStatement WithStatement
240 %type <statementNode> SwitchStatement LabelledStatement
241 %type <statementNode> ThrowStatement TryStatement
242 %type <statementNode> DebuggerStatement
243 %type <statementNode> SourceElement
245 %type <expressionNode> Initializer InitializerNoIn
246 %type <funcDeclNode> FunctionDeclaration
247 %type <funcExprNode> FunctionExpr
248 %type <functionBodyNode> FunctionBody
249 %type <sourceElements> SourceElements
250 %type <parameterList> FormalParameterList
251 %type <op> AssignmentOperator
252 %type <argumentsNode> Arguments
253 %type <argumentList> ArgumentList
254 %type <varDeclList> VariableDeclarationList VariableDeclarationListNoIn
255 %type <constDeclList> ConstDeclarationList
256 %type <constDeclNode> ConstDeclaration
257 %type <caseBlockNode> CaseBlock
258 %type <caseClauseNode> CaseClause DefaultClause
259 %type <clauseList> CaseClauses CaseClausesOpt
260 %type <intValue> Elision ElisionOpt
261 %type <elementList> ElementList
262 %type <propertyNode> Property
263 %type <propertyList> PropertyList
267 NULLTOKEN { $$ = new NullNode; }
268 | TRUETOKEN { $$ = new TrueNode; }
269 | FALSETOKEN { $$ = new FalseNode; }
270 | NUMBER { $$ = makeNumberNode($1); }
271 | STRING { $$ = new StringNode($1); }
276 $$ = new RegExpNode(l.pattern(), l.flags());
278 | DIVEQUAL /* regexp with /= */ {
282 $$ = new RegExpNode("=" + l.pattern(), l.flags());
287 IDENT ':' AssignmentExpr { $$ = new PropertyNode(*$1, $3, PropertyNode::Constant); }
288 | STRING ':' AssignmentExpr { $$ = new PropertyNode(Identifier(*$1), $3, PropertyNode::Constant); }
289 | NUMBER ':' AssignmentExpr { $$ = new PropertyNode(Identifier(UString::from($1)), $3, PropertyNode::Constant); }
290 | IDENT IDENT '(' ')' '{' FunctionBody '}' { $$ = makeGetterOrSetterPropertyNode(*$1, *$2, 0, $6); DBG($6, @5, @7); if (!$$) YYABORT; }
291 | IDENT IDENT '(' FormalParameterList ')' '{' FunctionBody '}'
292 { $$ = makeGetterOrSetterPropertyNode(*$1, *$2, $4.head, $7); DBG($7, @6, @8); if (!$$) YYABORT; }
296 Property { $$.head = new PropertyListNode($1);
298 | PropertyList ',' Property { $$.head = $1.head;
299 $$.tail = new PropertyListNode($3, $1.tail); }
304 | '{' '}' { $$ = new ObjectLiteralNode(); }
305 | '{' PropertyList '}' { $$ = new ObjectLiteralNode($2.head); }
306 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
307 | '{' PropertyList ',' '}' { $$ = new ObjectLiteralNode($2.head); }
311 THISTOKEN { $$ = new ThisNode(); }
314 | IDENT { $$ = new ResolveNode(*$1); }
315 | '(' Expr ')' { $$ = $2; }
319 '[' ElisionOpt ']' { $$ = new ArrayNode($2); }
320 | '[' ElementList ']' { $$ = new ArrayNode($2.head); }
321 | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2.head); }
325 ElisionOpt AssignmentExpr { $$.head = new ElementNode($1, $2);
327 | ElementList ',' ElisionOpt AssignmentExpr
329 $$.tail = new ElementNode($1.tail, $3, $4); }
333 /* nothing */ { $$ = 0; }
339 | Elision ',' { $$ = $1 + 1; }
344 | FunctionExpr { $$ = $1; }
345 | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
346 | MemberExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
347 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
352 | MemberExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
353 | MemberExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
354 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
359 | NEW NewExpr { $$ = new NewExprNode($2); }
364 | NEW NewExpr { $$ = new NewExprNode($2); }
368 MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
369 | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
370 | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
371 | CallExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
375 MemberExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
376 | CallExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
377 | CallExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
378 | CallExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
382 '(' ')' { $$ = new ArgumentsNode(); }
383 | '(' ArgumentList ')' { $$ = new ArgumentsNode($2.head); }
387 AssignmentExpr { $$.head = new ArgumentListNode($1);
389 | ArgumentList ',' AssignmentExpr { $$.head = $1.head;
390 $$.tail = new ArgumentListNode($1.tail, $3); }
398 LeftHandSideExprNoBF:
405 | LeftHandSideExpr PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
406 | LeftHandSideExpr MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
411 | LeftHandSideExprNoBF PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
412 | LeftHandSideExprNoBF MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
416 DELETETOKEN UnaryExpr { $$ = makeDeleteNode($2); }
417 | VOIDTOKEN UnaryExpr { $$ = new VoidNode($2); }
418 | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); }
419 | PLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
420 | AUTOPLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
421 | MINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
422 | AUTOMINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
423 | '+' UnaryExpr { $$ = new UnaryPlusNode($2); }
424 | '-' UnaryExpr { $$ = makeNegateNode($2); }
425 | '~' UnaryExpr { $$ = new BitwiseNotNode($2); }
426 | '!' UnaryExpr { $$ = new LogicalNotNode($2); }
440 | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3); }
441 | MultiplicativeExpr '/' UnaryExpr { $$ = new DivNode($1, $3); }
442 | MultiplicativeExpr '%' UnaryExpr { $$ = new ModNode($1, $3); }
445 MultiplicativeExprNoBF:
447 | MultiplicativeExprNoBF '*' UnaryExpr
448 { $$ = new MultNode($1, $3); }
449 | MultiplicativeExprNoBF '/' UnaryExpr
450 { $$ = new DivNode($1, $3); }
451 | MultiplicativeExprNoBF '%' UnaryExpr
452 { $$ = new ModNode($1, $3); }
457 | AdditiveExpr '+' MultiplicativeExpr { $$ = makeAddNode($1, $3); }
458 | AdditiveExpr '-' MultiplicativeExpr { $$ = new SubNode($1, $3); }
462 MultiplicativeExprNoBF
463 | AdditiveExprNoBF '+' MultiplicativeExpr
464 { $$ = makeAddNode($1, $3); }
465 | AdditiveExprNoBF '-' MultiplicativeExpr
466 { $$ = new SubNode($1, $3); }
471 | ShiftExpr LSHIFT AdditiveExpr { $$ = new LeftShiftNode($1, $3); }
472 | ShiftExpr RSHIFT AdditiveExpr { $$ = new RightShiftNode($1, $3); }
473 | ShiftExpr URSHIFT AdditiveExpr { $$ = new UnsignedRightShiftNode($1, $3); }
478 | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = new LeftShiftNode($1, $3); }
479 | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = new RightShiftNode($1, $3); }
480 | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = new UnsignedRightShiftNode($1, $3); }
485 | RelationalExpr '<' ShiftExpr { $$ = makeLessNode($1, $3); }
486 | RelationalExpr '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
487 | RelationalExpr LE ShiftExpr { $$ = new LessEqNode($1, $3); }
488 | RelationalExpr GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
489 | RelationalExpr INSTANCEOF ShiftExpr { $$ = new InstanceOfNode($1, $3); }
490 | RelationalExpr INTOKEN ShiftExpr { $$ = new InNode($1, $3); }
495 | RelationalExprNoIn '<' ShiftExpr { $$ = makeLessNode($1, $3); }
496 | RelationalExprNoIn '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
497 | RelationalExprNoIn LE ShiftExpr { $$ = new LessEqNode($1, $3); }
498 | RelationalExprNoIn GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
499 | RelationalExprNoIn INSTANCEOF ShiftExpr
500 { $$ = new InstanceOfNode($1, $3); }
505 | RelationalExprNoBF '<' ShiftExpr { $$ = makeLessNode($1, $3); }
506 | RelationalExprNoBF '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
507 | RelationalExprNoBF LE ShiftExpr { $$ = new LessEqNode($1, $3); }
508 | RelationalExprNoBF GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
509 | RelationalExprNoBF INSTANCEOF ShiftExpr
510 { $$ = new InstanceOfNode($1, $3); }
511 | RelationalExprNoBF INTOKEN ShiftExpr { $$ = new InNode($1, $3); }
516 | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, $3); }
517 | EqualityExpr NE RelationalExpr { $$ = new NotEqualNode($1, $3); }
518 | EqualityExpr STREQ RelationalExpr { $$ = new StrictEqualNode($1, $3); }
519 | EqualityExpr STRNEQ RelationalExpr { $$ = new NotStrictEqualNode($1, $3); }
524 | EqualityExprNoIn EQEQ RelationalExprNoIn
525 { $$ = new EqualNode($1, $3); }
526 | EqualityExprNoIn NE RelationalExprNoIn
527 { $$ = new NotEqualNode($1, $3); }
528 | EqualityExprNoIn STREQ RelationalExprNoIn
529 { $$ = new StrictEqualNode($1, $3); }
530 | EqualityExprNoIn STRNEQ RelationalExprNoIn
531 { $$ = new NotStrictEqualNode($1, $3); }
536 | EqualityExprNoBF EQEQ RelationalExpr
537 { $$ = new EqualNode($1, $3); }
538 | EqualityExprNoBF NE RelationalExpr { $$ = new NotEqualNode($1, $3); }
539 | EqualityExprNoBF STREQ RelationalExpr
540 { $$ = new StrictEqualNode($1, $3); }
541 | EqualityExprNoBF STRNEQ RelationalExpr
542 { $$ = new NotStrictEqualNode($1, $3); }
547 | BitwiseANDExpr '&' EqualityExpr { $$ = new BitAndNode($1, $3); }
552 | BitwiseANDExprNoIn '&' EqualityExprNoIn
553 { $$ = new BitAndNode($1, $3); }
558 | BitwiseANDExprNoBF '&' EqualityExpr { $$ = new BitAndNode($1, $3); }
563 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = new BitXOrNode($1, $3); }
568 | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn
569 { $$ = new BitXOrNode($1, $3); }
574 | BitwiseXORExprNoBF '^' BitwiseANDExpr
575 { $$ = new BitXOrNode($1, $3); }
580 | BitwiseORExpr '|' BitwiseXORExpr { $$ = new BitOrNode($1, $3); }
585 | BitwiseORExprNoIn '|' BitwiseXORExprNoIn
586 { $$ = new BitOrNode($1, $3); }
591 | BitwiseORExprNoBF '|' BitwiseXORExpr
592 { $$ = new BitOrNode($1, $3); }
597 | LogicalANDExpr AND BitwiseORExpr { $$ = new LogicalAndNode($1, $3); }
602 | LogicalANDExprNoIn AND BitwiseORExprNoIn
603 { $$ = new LogicalAndNode($1, $3); }
608 | LogicalANDExprNoBF AND BitwiseORExpr
609 { $$ = new LogicalAndNode($1, $3); }
614 | LogicalORExpr OR LogicalANDExpr { $$ = new LogicalOrNode($1, $3); }
619 | LogicalORExprNoIn OR LogicalANDExprNoIn
620 { $$ = new LogicalOrNode($1, $3); }
625 | LogicalORExprNoBF OR LogicalANDExpr { $$ = new LogicalOrNode($1, $3); }
630 | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
631 { $$ = new ConditionalNode($1, $3, $5); }
636 | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn
637 { $$ = new ConditionalNode($1, $3, $5); }
642 | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr
643 { $$ = new ConditionalNode($1, $3, $5); }
648 | LeftHandSideExpr AssignmentOperator AssignmentExpr
649 { $$ = makeAssignNode($1, $2, $3); }
654 | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn
655 { $$ = makeAssignNode($1, $2, $3); }
660 | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr
661 { $$ = makeAssignNode($1, $2, $3); }
665 '=' { $$ = OpEqual; }
666 | PLUSEQUAL { $$ = OpPlusEq; }
667 | MINUSEQUAL { $$ = OpMinusEq; }
668 | MULTEQUAL { $$ = OpMultEq; }
669 | DIVEQUAL { $$ = OpDivEq; }
670 | LSHIFTEQUAL { $$ = OpLShift; }
671 | RSHIFTEQUAL { $$ = OpRShift; }
672 | URSHIFTEQUAL { $$ = OpURShift; }
673 | ANDEQUAL { $$ = OpAndEq; }
674 | XOREQUAL { $$ = OpXOrEq; }
675 | OREQUAL { $$ = OpOrEq; }
676 | MODEQUAL { $$ = OpModEq; }
681 | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
686 | ExprNoIn ',' AssignmentExprNoIn { $$ = new CommaNode($1, $3); }
691 | ExprNoBF ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
714 '{' '}' { $$ = createNodeInfo<StatementNode*>(new BlockNode(0), 0, 0);
715 DBG($$.m_node, @1, @2); }
716 | '{' SourceElements '}' { $$ = createNodeInfo<StatementNode*>(new BlockNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
717 DBG($$.m_node, @1, @3); }
721 VAR VariableDeclarationList ';' { $$ = createNodeInfo<StatementNode*>(makeVarStatementNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
722 DBG($$.m_node, @1, @3); }
723 | VAR VariableDeclarationList error { $$ = createNodeInfo<StatementNode*>(makeVarStatementNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
724 DBG($$.m_node, @1, @2);
728 VariableDeclarationList:
729 IDENT { $$.m_node = 0;
730 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
731 appendToVarDeclarationList($$.m_varDeclarations, *$1, 0);
732 $$.m_funcDeclarations = 0;
734 | IDENT Initializer { $$.m_node = new AssignResolveNode(*$1, $2);
735 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
736 appendToVarDeclarationList($$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
737 $$.m_funcDeclarations = 0;
739 | VariableDeclarationList ',' IDENT
740 { $$.m_node = $1.m_node;
741 $$.m_varDeclarations = $1.m_varDeclarations;
742 appendToVarDeclarationList($$.m_varDeclarations, *$3, 0);
743 $$.m_funcDeclarations = 0;
745 | VariableDeclarationList ',' IDENT Initializer
746 { $$.m_node = combineVarInitializers($1.m_node, new AssignResolveNode(*$3, $4));
747 $$.m_varDeclarations = $1.m_varDeclarations;
748 appendToVarDeclarationList($$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
749 $$.m_funcDeclarations = 0;
753 VariableDeclarationListNoIn:
754 IDENT { $$.m_node = 0;
755 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
756 appendToVarDeclarationList($$.m_varDeclarations, *$1, 0);
757 $$.m_funcDeclarations = 0;
759 | IDENT InitializerNoIn { $$.m_node = new AssignResolveNode(*$1, $2);
760 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
761 appendToVarDeclarationList($$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
762 $$.m_funcDeclarations = 0;
764 | VariableDeclarationListNoIn ',' IDENT
765 { $$.m_node = $1.m_node;
766 $$.m_varDeclarations = $1.m_varDeclarations;
767 appendToVarDeclarationList($$.m_varDeclarations, *$3, 0);
768 $$.m_funcDeclarations = 0;
770 | VariableDeclarationListNoIn ',' IDENT InitializerNoIn
771 { $$.m_node = combineVarInitializers($1.m_node, new AssignResolveNode(*$3, $4));
772 $$.m_varDeclarations = $1.m_varDeclarations;
773 appendToVarDeclarationList($$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
774 $$.m_funcDeclarations = 0;
779 CONSTTOKEN ConstDeclarationList ';' { $$ = createNodeInfo<StatementNode*>(new ConstStatementNode($2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations);
780 DBG($$.m_node, @1, @3); }
781 | CONSTTOKEN ConstDeclarationList error
782 { $$ = createNodeInfo<StatementNode*>(new ConstStatementNode($2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations);
783 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
786 ConstDeclarationList:
787 ConstDeclaration { $$.m_node.head = $1;
788 $$.m_node.tail = $$.m_node.head;
789 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
790 appendToVarDeclarationList($$.m_varDeclarations, $1);
791 $$.m_funcDeclarations = 0; }
792 | ConstDeclarationList ',' ConstDeclaration
793 { $$.m_node.head = $1.m_node.head;
794 $1.m_node.tail->m_next = $3;
796 $$.m_varDeclarations = $1.m_varDeclarations;
797 appendToVarDeclarationList($$.m_varDeclarations, $3);
798 $$.m_funcDeclarations = 0; }
802 IDENT { $$ = new ConstDeclNode(*$1, 0); }
803 | IDENT Initializer { $$ = new ConstDeclNode(*$1, $2); }
807 '=' AssignmentExpr { $$ = $2; }
811 '=' AssignmentExprNoIn { $$ = $2; }
815 ';' { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0); }
819 ExprNoBF ';' { $$ = createNodeInfo<StatementNode*>(new ExprStatementNode($1), 0, 0);
820 DBG($$.m_node, @1, @2); }
821 | ExprNoBF error { $$ = createNodeInfo<StatementNode*>(new ExprStatementNode($1), 0, 0);
822 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
826 IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
827 { $$ = createNodeInfo<StatementNode*>(new IfNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
828 DBG($$.m_node, @1, @4); }
829 | IF '(' Expr ')' Statement ELSE Statement
830 { $$ = createNodeInfo<StatementNode*>(new IfElseNode($3, $5.m_node, $7.m_node), mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations));
831 DBG($$.m_node, @1, @4); }
835 DO Statement WHILE '(' Expr ')' ';' { $$ = createNodeInfo<StatementNode*>(new DoWhileNode($2.m_node, $5), $2.m_varDeclarations, $2.m_funcDeclarations);
836 DBG($$.m_node, @1, @3); }
837 | DO Statement WHILE '(' Expr ')' error { $$ = createNodeInfo<StatementNode*>(new DoWhileNode($2.m_node, $5), $2.m_varDeclarations, $2.m_funcDeclarations);
838 DBG($$.m_node, @1, @3); } // Always performs automatic semicolon insertion.
839 | WHILE '(' Expr ')' Statement { $$ = createNodeInfo<StatementNode*>(new WhileNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
840 DBG($$.m_node, @1, @4); }
841 | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement
842 { $$ = createNodeInfo<StatementNode*>(new ForNode($3, $5, $7, $9.m_node, false), $9.m_varDeclarations, $9.m_funcDeclarations);
843 DBG($$.m_node, @1, @8);
845 | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
846 { $$ = createNodeInfo<StatementNode*>(new ForNode($4.m_node, $6, $8, $10.m_node, true),
847 mergeDeclarationLists($4.m_varDeclarations, $10.m_varDeclarations),
848 mergeDeclarationLists($4.m_funcDeclarations, $10.m_funcDeclarations));
849 DBG($$.m_node, @1, @9); }
850 | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
852 ExpressionNode* n = $3;
853 if (!n->isLocation())
855 $$ = createNodeInfo<StatementNode*>(new ForInNode(n, $5, $7.m_node), $7.m_varDeclarations, $7.m_funcDeclarations);
856 DBG($$.m_node, @1, @6);
858 | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
859 { ForInNode *forIn = new ForInNode(*$4, 0, $6, $8.m_node);
860 appendToVarDeclarationList($8.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
861 $$ = createNodeInfo<StatementNode*>(forIn, $8.m_varDeclarations, $8.m_funcDeclarations);
862 DBG($$.m_node, @1, @7); }
863 | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
864 { ForInNode *forIn = new ForInNode(*$4, $5, $7, $9.m_node);
865 appendToVarDeclarationList($9.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
866 $$ = createNodeInfo<StatementNode*>(forIn, $9.m_varDeclarations, $9.m_funcDeclarations);
867 DBG($$.m_node, @1, @8); }
871 /* nothing */ { $$ = 0; }
876 /* nothing */ { $$ = 0; }
881 CONTINUE ';' { $$ = createNodeInfo<StatementNode*>(new ContinueNode(), 0, 0);
882 DBG($$.m_node, @1, @2); }
883 | CONTINUE error { $$ = createNodeInfo<StatementNode*>(new ContinueNode(), 0, 0);
884 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
885 | CONTINUE IDENT ';' { $$ = createNodeInfo<StatementNode*>(new ContinueNode(*$2), 0, 0);
886 DBG($$.m_node, @1, @3); }
887 | CONTINUE IDENT error { $$ = createNodeInfo<StatementNode*>(new ContinueNode(*$2), 0, 0);
888 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
892 BREAK ';' { $$ = createNodeInfo<StatementNode*>(new BreakNode(), 0, 0); DBG($$.m_node, @1, @2); }
893 | BREAK error { $$ = createNodeInfo<StatementNode*>(new BreakNode(), 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
894 | BREAK IDENT ';' { $$ = createNodeInfo<StatementNode*>(new BreakNode(*$2), 0, 0); DBG($$.m_node, @1, @3); }
895 | BREAK IDENT error { $$ = createNodeInfo<StatementNode*>(new BreakNode(*$2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
899 RETURN ';' { $$ = createNodeInfo<StatementNode*>(new ReturnNode(0), 0, 0); DBG($$.m_node, @1, @2); }
900 | RETURN error { $$ = createNodeInfo<StatementNode*>(new ReturnNode(0), 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
901 | RETURN Expr ';' { $$ = createNodeInfo<StatementNode*>(new ReturnNode($2), 0, 0); DBG($$.m_node, @1, @3); }
902 | RETURN Expr error { $$ = createNodeInfo<StatementNode*>(new ReturnNode($2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
906 WITH '(' Expr ')' Statement { $$ = createNodeInfo<StatementNode*>(new WithNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
907 DBG($$.m_node, @1, @4); }
911 SWITCH '(' Expr ')' CaseBlock { $$ = createNodeInfo<StatementNode*>(new SwitchNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
912 DBG($$.m_node, @1, @4); }
916 '{' CaseClausesOpt '}' { $$ = createNodeInfo<CaseBlockNode*>(new CaseBlockNode($2.m_node.head, 0, 0), $2.m_varDeclarations, $2.m_funcDeclarations); }
917 | '{' CaseClausesOpt DefaultClause CaseClausesOpt '}'
918 { $$ = createNodeInfo<CaseBlockNode*>(new CaseBlockNode($2.m_node.head, $3.m_node, $4.m_node.head),
919 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $3.m_varDeclarations), $4.m_varDeclarations),
920 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $3.m_funcDeclarations), $4.m_funcDeclarations)); }
924 /* nothing */ { $$.m_node.head = 0; $$.m_node.tail = 0; $$.m_varDeclarations = 0; $$.m_funcDeclarations = 0; }
929 CaseClause { $$.m_node.head = new ClauseListNode($1.m_node);
930 $$.m_node.tail = $$.m_node.head;
931 $$.m_varDeclarations = $1.m_varDeclarations;
932 $$.m_funcDeclarations = $1.m_funcDeclarations; }
933 | CaseClauses CaseClause { $$.m_node.head = $1.m_node.head;
934 $$.m_node.tail = new ClauseListNode($1.m_node.tail, $2.m_node);
935 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
936 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
941 CASE Expr ':' { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode($2), 0, 0); }
942 | CASE Expr ':' SourceElements { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode($2, $4.m_node), $4.m_varDeclarations, $4.m_funcDeclarations); }
946 DEFAULT ':' { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode(0), 0, 0); }
947 | DEFAULT ':' SourceElements { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode(0, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations); }
951 IDENT ':' Statement { $3.m_node->pushLabel(*$1);
952 $$ = createNodeInfo<StatementNode*>(new LabelNode(*$1, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations); }
956 THROW Expr ';' { $$ = createNodeInfo<StatementNode*>(new ThrowNode($2), 0, 0); DBG($$.m_node, @1, @3); }
957 | THROW Expr error { $$ = createNodeInfo<StatementNode*>(new ThrowNode($2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
961 TRY Block FINALLY Block { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, CommonIdentifiers::shared()->nullIdentifier, 0, $4.m_node),
962 mergeDeclarationLists($2.m_varDeclarations, $4.m_varDeclarations),
963 mergeDeclarationLists($2.m_funcDeclarations, $4.m_funcDeclarations));
964 DBG($$.m_node, @1, @2); }
965 | TRY Block CATCH '(' IDENT ')' Block { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, *$5, $7.m_node, 0),
966 mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations),
967 mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations));
968 DBG($$.m_node, @1, @2); }
969 | TRY Block CATCH '(' IDENT ')' Block FINALLY Block
970 { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, *$5, $7.m_node, $9.m_node),
971 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations), $9.m_varDeclarations),
972 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations), $9.m_funcDeclarations));
973 DBG($$.m_node, @1, @2); }
977 DEBUGGER ';' { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0);
978 DBG($$.m_node, @1, @2); }
979 | DEBUGGER error { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0);
980 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
984 FUNCTION IDENT '(' ')' '{' FunctionBody '}' { $$ = new FuncDeclNode(*$2, $6); DBG($6, @5, @7); }
985 | FUNCTION IDENT '(' FormalParameterList ')' '{' FunctionBody '}'
986 { $$ = new FuncDeclNode(*$2, $4.head, $7); DBG($7, @6, @8); }
990 FUNCTION '(' ')' '{' FunctionBody '}' { $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $5); DBG($5, @4, @6); }
991 | FUNCTION '(' FormalParameterList ')' '{' FunctionBody '}' { $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $6, $3.head); DBG($6, @5, @7); }
992 | FUNCTION IDENT '(' ')' '{' FunctionBody '}' { $$ = new FuncExprNode(*$2, $6); DBG($6, @5, @7); }
993 | FUNCTION IDENT '(' FormalParameterList ')' '{' FunctionBody '}' { $$ = new FuncExprNode(*$2, $7, $4.head); DBG($7, @6, @8); }
997 IDENT { $$.head = new ParameterNode(*$1);
999 | FormalParameterList ',' IDENT { $$.head = $1.head;
1000 $$.tail = new ParameterNode($1.tail, *$3); }
1004 /* not in spec */ { $$ = FunctionBodyNode::create(0, 0, 0); }
1005 | SourceElements { $$ = FunctionBodyNode::create($1.m_node, $1.m_varDeclarations ? &$1.m_varDeclarations->data : 0,
1006 $1.m_funcDeclarations ? &$1.m_funcDeclarations->data : 0);
1007 // As in mergeDeclarationLists() we have to ref/deref to safely get rid of
1008 // the declaration lists.
1009 if ($1.m_varDeclarations) {
1010 $1.m_varDeclarations->ref();
1011 $1.m_varDeclarations->deref();
1013 if ($1.m_funcDeclarations) {
1014 $1.m_funcDeclarations->ref();
1015 $1.m_funcDeclarations->deref();
1021 /* not in spec */ { parser().didFinishParsing(0, 0, 0, @0.last_line); }
1022 | SourceElements { parser().didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations, @1.last_line); }
1026 SourceElement { $$.m_node = new SourceElements;
1027 $$.m_node->append($1.m_node);
1028 $$.m_varDeclarations = $1.m_varDeclarations;
1029 $$.m_funcDeclarations = $1.m_funcDeclarations;
1031 | SourceElements SourceElement { $$.m_node->append($2.m_node);
1032 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1033 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1038 FunctionDeclaration { $$ = createNodeInfo<StatementNode*>($1, 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>); $$.m_funcDeclarations->data.append($1); }
1039 | Statement { $$ = $1; }
1044 static AddNode* makeAddNode(ExpressionNode* left, ExpressionNode* right)
1046 JSType t1 = left->expectedReturnType();
1047 JSType t2 = right->expectedReturnType();
1049 if (t1 == NumberType && t2 == NumberType)
1050 return new AddNumbersNode(left, right);
1051 if (t1 == StringType && t2 == StringType)
1052 return new AddStringsNode(left, right);
1053 if (t1 == StringType)
1054 return new AddStringLeftNode(left, right);
1055 if (t2 == StringType)
1056 return new AddStringRightNode(left, right);
1057 return new AddNode(left, right);
1060 static LessNode* makeLessNode(ExpressionNode* left, ExpressionNode* right)
1062 JSType t1 = left->expectedReturnType();
1063 JSType t2 = right->expectedReturnType();
1065 if (t1 == StringType && t2 == StringType)
1066 return new LessStringsNode(left, right);
1068 // There are certainly more efficient ways to do this type check if necessary
1069 if (t1 == NumberType || t1 == BooleanType || t1 == UndefinedType || t1 == NullType ||
1070 t2 == NumberType || t2 == BooleanType || t2 == UndefinedType || t2 == NullType)
1071 return new LessNumbersNode(left, right);
1073 // Neither is certain to be a number, nor were both certain to be strings, so we use the default (slow) implementation.
1074 return new LessNode(left, right);
1077 static ExpressionNode* makeAssignNode(ExpressionNode* loc, Operator op, ExpressionNode* expr)
1079 if (!loc->isLocation())
1080 return new AssignErrorNode(loc, op, expr);
1082 if (loc->isResolveNode()) {
1083 ResolveNode* resolve = static_cast<ResolveNode*>(loc);
1085 return new AssignResolveNode(resolve->identifier(), expr);
1087 return new ReadModifyResolveNode(resolve->identifier(), op, expr);
1089 if (loc->isBracketAccessorNode()) {
1090 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc);
1092 return new AssignBracketNode(bracket->base(), bracket->subscript(), expr);
1094 return new ReadModifyBracketNode(bracket->base(), bracket->subscript(), op, expr);
1096 ASSERT(loc->isDotAccessorNode());
1097 DotAccessorNode* dot = static_cast<DotAccessorNode*>(loc);
1099 return new AssignDotNode(dot->base(), dot->identifier(), expr);
1100 return new ReadModifyDotNode(dot->base(), dot->identifier(), op, expr);
1103 static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator op)
1105 if (!expr->isLocation())
1106 return new PrefixErrorNode(expr, op);
1108 if (expr->isResolveNode()) {
1109 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1110 if (op == OpPlusPlus)
1111 return new PreIncResolveNode(resolve->identifier());
1113 return new PreDecResolveNode(resolve->identifier());
1115 if (expr->isBracketAccessorNode()) {
1116 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1117 if (op == OpPlusPlus)
1118 return new PreIncBracketNode(bracket->base(), bracket->subscript());
1120 return new PreDecBracketNode(bracket->base(), bracket->subscript());
1122 ASSERT(expr->isDotAccessorNode());
1123 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1124 if (op == OpPlusPlus)
1125 return new PreIncDotNode(dot->base(), dot->identifier());
1126 return new PreDecDotNode(dot->base(), dot->identifier());
1129 static ExpressionNode* makePostfixNode(ExpressionNode* expr, Operator op)
1131 if (!expr->isLocation())
1132 return new PostfixErrorNode(expr, op);
1134 if (expr->isResolveNode()) {
1135 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1136 if (op == OpPlusPlus)
1137 return new PostIncResolveNode(resolve->identifier());
1139 return new PostDecResolveNode(resolve->identifier());
1141 if (expr->isBracketAccessorNode()) {
1142 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1143 if (op == OpPlusPlus)
1144 return new PostIncBracketNode(bracket->base(), bracket->subscript());
1146 return new PostDecBracketNode(bracket->base(), bracket->subscript());
1148 ASSERT(expr->isDotAccessorNode());
1149 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1151 if (op == OpPlusPlus)
1152 return new PostIncDotNode(dot->base(), dot->identifier());
1153 return new PostDecDotNode(dot->base(), dot->identifier());
1156 static ExpressionNode* makeFunctionCallNode(ExpressionNode* func, ArgumentsNode* args)
1158 if (!func->isLocation())
1159 return new FunctionCallValueNode(func, args);
1160 if (func->isResolveNode()) {
1161 ResolveNode* resolve = static_cast<ResolveNode*>(func);
1162 return new FunctionCallResolveNode(resolve->identifier(), args);
1164 if (func->isBracketAccessorNode()) {
1165 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func);
1166 return new FunctionCallBracketNode(bracket->base(), bracket->subscript(), args);
1168 ASSERT(func->isDotAccessorNode());
1169 DotAccessorNode* dot = static_cast<DotAccessorNode*>(func);
1170 return new FunctionCallDotNode(dot->base(), dot->identifier(), args);
1173 static ExpressionNode* makeTypeOfNode(ExpressionNode* expr)
1175 if (expr->isResolveNode()) {
1176 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1177 return new TypeOfResolveNode(resolve->identifier());
1179 return new TypeOfValueNode(expr);
1182 static ExpressionNode* makeDeleteNode(ExpressionNode* expr)
1184 if (!expr->isLocation())
1185 return new DeleteValueNode(expr);
1186 if (expr->isResolveNode()) {
1187 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1188 return new DeleteResolveNode(resolve->identifier());
1190 if (expr->isBracketAccessorNode()) {
1191 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1192 return new DeleteBracketNode(bracket->base(), bracket->subscript());
1194 ASSERT(expr->isDotAccessorNode());
1195 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1196 return new DeleteDotNode(dot->base(), dot->identifier());
1199 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body)
1201 PropertyNode::Type type;
1202 if (getOrSet == "get")
1203 type = PropertyNode::Getter;
1204 else if (getOrSet == "set")
1205 type = PropertyNode::Setter;
1208 return new PropertyNode(name, new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, body, params), type);
1211 static ExpressionNode* makeNegateNode(ExpressionNode* n)
1213 if (n->isNumber()) {
1214 NumberNode* number = static_cast<NumberNode*>(n);
1216 if (number->value() > 0.0) {
1217 number->setValue(-number->value());
1222 return new NegateNode(n);
1225 static NumberNode* makeNumberNode(double d)
1227 JSValue* value = JSImmediate::from(d);
1229 return new ImmediateNumberNode(value, d);
1230 return new NumberNode(d);
1233 /* called by yyparse on error */
1234 int yyerror(const char *)
1239 /* may we automatically insert a semicolon ? */
1240 static bool allowAutomaticSemicolon()
1242 return yychar == '}' || yychar == 0 || lexer().prevTerminator();
1245 static ExpressionNode* combineVarInitializers(ExpressionNode* list, AssignResolveNode* init)
1249 return new VarDeclCommaNode(list, init);
1252 // We turn variable declarations into either assignments or empty
1253 // statements (which later get stripped out), because the actual
1254 // declaration work is hoisted up to the start of the function body
1255 static StatementNode* makeVarStatementNode(ExpressionNode* expr)
1258 return new EmptyStatementNode();
1259 return new VarStatementNode(expr);