]> git.saurik.com Git - apple/javascriptcore.git/blob - parser/Nodes.h
a9f88b7378352994bf6ccf3049d8a0227fb1b0ce
[apple/javascriptcore.git] / parser / Nodes.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
6 * Copyright (C) 2007 Maks Orlovich
7 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 *
24 */
25
26 #ifndef Nodes_h
27 #define Nodes_h
28
29 #include "Error.h"
30 #include "JITCode.h"
31 #include "Opcode.h"
32 #include "ParserArena.h"
33 #include "ResultType.h"
34 #include "SourceCode.h"
35 #include "SymbolTable.h"
36 #include <wtf/MathExtras.h>
37 #include <wtf/OwnPtr.h>
38
39 namespace JSC {
40
41 class ArgumentListNode;
42 class CodeBlock;
43 class BytecodeGenerator;
44 class FuncDeclNode;
45 class EvalCodeBlock;
46 class JSFunction;
47 class ProgramCodeBlock;
48 class PropertyListNode;
49 class ReadModifyResolveNode;
50 class RegisterID;
51 class ScopeChainNode;
52
53 typedef unsigned CodeFeatures;
54
55 const CodeFeatures NoFeatures = 0;
56 const CodeFeatures EvalFeature = 1 << 0;
57 const CodeFeatures ClosureFeature = 1 << 1;
58 const CodeFeatures AssignFeature = 1 << 2;
59 const CodeFeatures ArgumentsFeature = 1 << 3;
60 const CodeFeatures WithFeature = 1 << 4;
61 const CodeFeatures CatchFeature = 1 << 5;
62 const CodeFeatures ThisFeature = 1 << 6;
63 const CodeFeatures AllFeatures = EvalFeature | ClosureFeature | AssignFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature;
64
65 enum Operator {
66 OpEqual,
67 OpPlusEq,
68 OpMinusEq,
69 OpMultEq,
70 OpDivEq,
71 OpPlusPlus,
72 OpMinusMinus,
73 OpAndEq,
74 OpXOrEq,
75 OpOrEq,
76 OpModEq,
77 OpLShift,
78 OpRShift,
79 OpURShift
80 };
81
82 enum LogicalOperator {
83 OpLogicalAnd,
84 OpLogicalOr
85 };
86
87 namespace DeclarationStacks {
88 enum VarAttrs { IsConstant = 1, HasInitializer = 2 };
89 typedef Vector<std::pair<Identifier, unsigned> > VarStack;
90 typedef Vector<FuncDeclNode*> FunctionStack;
91 }
92
93 struct SwitchInfo {
94 enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString };
95 uint32_t bytecodeOffset;
96 SwitchType switchType;
97 };
98
99 class ParserArenaDeletable {
100 protected:
101 ParserArenaDeletable() { }
102
103 public:
104 virtual ~ParserArenaDeletable() { }
105
106 // Objects created with this version of new are deleted when the arena is deleted.
107 void* operator new(size_t, JSGlobalData*);
108
109 // Objects created with this version of new are not deleted when the arena is deleted.
110 // Other arrangements must be made.
111 void* operator new(size_t);
112 };
113
114 class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
115 protected:
116 ParserArenaRefCounted(JSGlobalData*);
117
118 public:
119 virtual ~ParserArenaRefCounted()
120 {
121 ASSERT(deletionHasBegun());
122 }
123 };
124
125 class Node : public ParserArenaDeletable {
126 protected:
127 Node(JSGlobalData*);
128
129 public:
130 /*
131 Return value: The register holding the production's value.
132 dst: An optional parameter specifying the most efficient
133 destination at which to store the production's value.
134 The callee must honor dst.
135
136 dst provides for a crude form of copy propagation. For example,
137
138 x = 1
139
140 becomes
141
142 load r[x], 1
143
144 instead of
145
146 load r0, 1
147 mov r[x], r0
148
149 because the assignment node, "x =", passes r[x] as dst to the number
150 node, "1".
151 */
152 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0) = 0;
153
154 int lineNo() const { return m_line; }
155
156 protected:
157 int m_line;
158 };
159
160 class ExpressionNode : public Node {
161 public:
162 ExpressionNode(JSGlobalData*, ResultType = ResultType::unknownType());
163
164 virtual bool isNumber() const { return false; }
165 virtual bool isString() const { return false; }
166 virtual bool isNull() const { return false; }
167 virtual bool isPure(BytecodeGenerator&) const { return false; }
168 virtual bool isLocation() const { return false; }
169 virtual bool isResolveNode() const { return false; }
170 virtual bool isBracketAccessorNode() const { return false; }
171 virtual bool isDotAccessorNode() const { return false; }
172 virtual bool isFuncExprNode() const { return false; }
173 virtual bool isCommaNode() const { return false; }
174 virtual bool isSimpleArray() const { return false; }
175 virtual bool isAdd() const { return false; }
176
177 virtual ExpressionNode* stripUnaryPlus() { return this; }
178
179 ResultType resultDescriptor() const { return m_resultType; }
180
181 // This needs to be in public in order to compile using GCC 3.x
182 typedef enum { EvalOperator, FunctionCall } CallerType;
183
184 private:
185 ResultType m_resultType;
186 };
187
188 class StatementNode : public Node {
189 public:
190 StatementNode(JSGlobalData*);
191
192 void setLoc(int line0, int line1);
193 int firstLine() const { return lineNo(); }
194 int lastLine() const { return m_lastLine; }
195
196 virtual bool isEmptyStatement() const { return false; }
197 virtual bool isReturnNode() const { return false; }
198 virtual bool isExprStatement() const { return false; }
199
200 virtual bool isBlock() const { return false; }
201
202 private:
203 int m_lastLine;
204 };
205
206 class NullNode : public ExpressionNode {
207 public:
208 NullNode(JSGlobalData*);
209
210 private:
211 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
212
213 virtual bool isNull() const { return true; }
214 };
215
216 class BooleanNode : public ExpressionNode {
217 public:
218 BooleanNode(JSGlobalData*, bool value);
219
220 private:
221 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
222
223 virtual bool isPure(BytecodeGenerator&) const { return true; }
224
225 bool m_value;
226 };
227
228 class NumberNode : public ExpressionNode {
229 public:
230 NumberNode(JSGlobalData*, double v);
231
232 double value() const { return m_double; }
233 void setValue(double d) { m_double = d; }
234
235 private:
236 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
237
238 virtual bool isNumber() const { return true; }
239 virtual bool isPure(BytecodeGenerator&) const { return true; }
240
241 double m_double;
242 };
243
244 class StringNode : public ExpressionNode {
245 public:
246 StringNode(JSGlobalData*, const Identifier& v);
247
248 const Identifier& value() { return m_value; }
249 virtual bool isPure(BytecodeGenerator&) const { return true; }
250
251 private:
252 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
253
254 virtual bool isString() const { return true; }
255
256 Identifier m_value;
257 };
258
259 class ThrowableExpressionData {
260 public:
261 ThrowableExpressionData()
262 : m_divot(static_cast<uint32_t>(-1))
263 , m_startOffset(static_cast<uint16_t>(-1))
264 , m_endOffset(static_cast<uint16_t>(-1))
265 {
266 }
267
268 ThrowableExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
269 : m_divot(divot)
270 , m_startOffset(startOffset)
271 , m_endOffset(endOffset)
272 {
273 }
274
275 void setExceptionSourceCode(unsigned divot, unsigned startOffset, unsigned endOffset)
276 {
277 m_divot = divot;
278 m_startOffset = startOffset;
279 m_endOffset = endOffset;
280 }
281
282 uint32_t divot() const { return m_divot; }
283 uint16_t startOffset() const { return m_startOffset; }
284 uint16_t endOffset() const { return m_endOffset; }
285
286 protected:
287 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg);
288 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const Identifier&);
289
290 private:
291 uint32_t m_divot;
292 uint16_t m_startOffset;
293 uint16_t m_endOffset;
294 };
295
296 class ThrowableSubExpressionData : public ThrowableExpressionData {
297 public:
298 ThrowableSubExpressionData()
299 : ThrowableExpressionData()
300 , m_subexpressionDivotOffset(0)
301 , m_subexpressionEndOffset(0)
302 {
303 }
304
305 ThrowableSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
306 : ThrowableExpressionData(divot, startOffset, endOffset)
307 , m_subexpressionDivotOffset(0)
308 , m_subexpressionEndOffset(0)
309 {
310 }
311
312 void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
313 {
314 ASSERT(subexpressionDivot <= divot());
315 if ((divot() - subexpressionDivot) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
316 return;
317 m_subexpressionDivotOffset = divot() - subexpressionDivot;
318 m_subexpressionEndOffset = subexpressionOffset;
319 }
320
321 protected:
322 uint16_t m_subexpressionDivotOffset;
323 uint16_t m_subexpressionEndOffset;
324 };
325
326 class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData {
327 public:
328 ThrowablePrefixedSubExpressionData()
329 : ThrowableExpressionData()
330 , m_subexpressionDivotOffset(0)
331 , m_subexpressionStartOffset(0)
332 {
333 }
334
335 ThrowablePrefixedSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset)
336 : ThrowableExpressionData(divot, startOffset, endOffset)
337 , m_subexpressionDivotOffset(0)
338 , m_subexpressionStartOffset(0)
339 {
340 }
341
342 void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset)
343 {
344 ASSERT(subexpressionDivot >= divot());
345 if ((subexpressionDivot - divot()) & ~0xFFFF) // Overflow means we can't do this safely, so just point at the primary divot
346 return;
347 m_subexpressionDivotOffset = subexpressionDivot - divot();
348 m_subexpressionStartOffset = subexpressionOffset;
349 }
350
351 protected:
352 uint16_t m_subexpressionDivotOffset;
353 uint16_t m_subexpressionStartOffset;
354 };
355
356 class RegExpNode : public ExpressionNode, public ThrowableExpressionData {
357 public:
358 RegExpNode(JSGlobalData*, const UString& pattern, const UString& flags);
359
360 private:
361 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
362
363 UString m_pattern;
364 UString m_flags;
365 };
366
367 class ThisNode : public ExpressionNode {
368 public:
369 ThisNode(JSGlobalData*);
370
371 private:
372 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
373 };
374
375 class ResolveNode : public ExpressionNode {
376 public:
377 ResolveNode(JSGlobalData*, const Identifier&, int startOffset);
378
379 const Identifier& identifier() const { return m_ident; }
380
381 private:
382 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
383
384 virtual bool isPure(BytecodeGenerator&) const ;
385 virtual bool isLocation() const { return true; }
386 virtual bool isResolveNode() const { return true; }
387
388 Identifier m_ident;
389 int32_t m_startOffset;
390 };
391
392 class ElementNode : public ParserArenaDeletable {
393 public:
394 ElementNode(JSGlobalData*, int elision, ExpressionNode*);
395 ElementNode(JSGlobalData*, ElementNode*, int elision, ExpressionNode*);
396
397 int elision() const { return m_elision; }
398 ExpressionNode* value() { return m_node; }
399 ElementNode* next() { return m_next; }
400
401 private:
402 ElementNode* m_next;
403 int m_elision;
404 ExpressionNode* m_node;
405 };
406
407 class ArrayNode : public ExpressionNode {
408 public:
409 ArrayNode(JSGlobalData*, int elision);
410 ArrayNode(JSGlobalData*, ElementNode*);
411 ArrayNode(JSGlobalData*, int elision, ElementNode*);
412
413 ArgumentListNode* toArgumentList(JSGlobalData*) const;
414
415 private:
416 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
417
418 virtual bool isSimpleArray() const ;
419
420 ElementNode* m_element;
421 int m_elision;
422 bool m_optional;
423 };
424
425 class PropertyNode : public ParserArenaDeletable {
426 public:
427 enum Type { Constant, Getter, Setter };
428
429 PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type);
430
431 const Identifier& name() const { return m_name; }
432
433 private:
434 friend class PropertyListNode;
435 Identifier m_name;
436 ExpressionNode* m_assign;
437 Type m_type;
438 };
439
440 class PropertyListNode : public Node {
441 public:
442 PropertyListNode(JSGlobalData*, PropertyNode*);
443 PropertyListNode(JSGlobalData*, PropertyNode*, PropertyListNode*);
444
445 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
446
447 private:
448 PropertyNode* m_node;
449 PropertyListNode* m_next;
450 };
451
452 class ObjectLiteralNode : public ExpressionNode {
453 public:
454 ObjectLiteralNode(JSGlobalData*);
455 ObjectLiteralNode(JSGlobalData*, PropertyListNode*);
456
457 private:
458 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
459
460 PropertyListNode* m_list;
461 };
462
463 class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData {
464 public:
465 BracketAccessorNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments);
466
467 ExpressionNode* base() const { return m_base; }
468 ExpressionNode* subscript() const { return m_subscript; }
469
470 private:
471 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
472
473 virtual bool isLocation() const { return true; }
474 virtual bool isBracketAccessorNode() const { return true; }
475
476 ExpressionNode* m_base;
477 ExpressionNode* m_subscript;
478 bool m_subscriptHasAssignments;
479 };
480
481 class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData {
482 public:
483 DotAccessorNode(JSGlobalData*, ExpressionNode* base, const Identifier&);
484
485 ExpressionNode* base() const { return m_base; }
486 const Identifier& identifier() const { return m_ident; }
487
488 private:
489 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
490
491 virtual bool isLocation() const { return true; }
492 virtual bool isDotAccessorNode() const { return true; }
493
494 ExpressionNode* m_base;
495 Identifier m_ident;
496 };
497
498 class ArgumentListNode : public Node {
499 public:
500 ArgumentListNode(JSGlobalData*, ExpressionNode*);
501 ArgumentListNode(JSGlobalData*, ArgumentListNode*, ExpressionNode*);
502
503 ArgumentListNode* m_next;
504 ExpressionNode* m_expr;
505
506 private:
507 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
508 };
509
510 class ArgumentsNode : public ParserArenaDeletable {
511 public:
512 ArgumentsNode(JSGlobalData*);
513 ArgumentsNode(JSGlobalData*, ArgumentListNode*);
514
515 ArgumentListNode* m_listNode;
516 };
517
518 class NewExprNode : public ExpressionNode, public ThrowableExpressionData {
519 public:
520 NewExprNode(JSGlobalData*, ExpressionNode*);
521 NewExprNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*);
522
523 private:
524 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
525
526 ExpressionNode* m_expr;
527 ArgumentsNode* m_args;
528 };
529
530 class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData {
531 public:
532 EvalFunctionCallNode(JSGlobalData*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
533
534 private:
535 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
536
537 ArgumentsNode* m_args;
538 };
539
540 class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData {
541 public:
542 FunctionCallValueNode(JSGlobalData*, ExpressionNode*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
543
544 private:
545 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
546
547 ExpressionNode* m_expr;
548 ArgumentsNode* m_args;
549 };
550
551 class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData {
552 public:
553 FunctionCallResolveNode(JSGlobalData*, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
554
555 private:
556 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
557
558 Identifier m_ident;
559 ArgumentsNode* m_args;
560 size_t m_index; // Used by LocalVarFunctionCallNode.
561 size_t m_scopeDepth; // Used by ScopedVarFunctionCallNode and NonLocalVarFunctionCallNode
562 };
563
564 class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
565 public:
566 FunctionCallBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
567
568 private:
569 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
570
571 ExpressionNode* m_base;
572 ExpressionNode* m_subscript;
573 ArgumentsNode* m_args;
574 };
575
576 class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData {
577 public:
578 FunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
579
580 private:
581 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
582
583 protected:
584 ExpressionNode* m_base;
585 const Identifier m_ident;
586 ArgumentsNode* m_args;
587 };
588
589 class CallFunctionCallDotNode : public FunctionCallDotNode {
590 public:
591 CallFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
592
593 private:
594 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
595 };
596
597 class ApplyFunctionCallDotNode : public FunctionCallDotNode {
598 public:
599 ApplyFunctionCallDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset);
600
601 private:
602 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
603 };
604
605 class PrePostResolveNode : public ExpressionNode, public ThrowableExpressionData {
606 public:
607 PrePostResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
608
609 protected:
610 const Identifier m_ident;
611 };
612
613 class PostfixResolveNode : public PrePostResolveNode {
614 public:
615 PostfixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
616
617 private:
618 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
619
620 Operator m_operator;
621 };
622
623 class PostfixBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
624 public:
625 PostfixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
626
627 private:
628 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
629
630 ExpressionNode* m_base;
631 ExpressionNode* m_subscript;
632 Operator m_operator;
633 };
634
635 class PostfixDotNode : public ExpressionNode, public ThrowableSubExpressionData {
636 public:
637 PostfixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
638
639 private:
640 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
641
642 ExpressionNode* m_base;
643 Identifier m_ident;
644 Operator m_operator;
645 };
646
647 class PostfixErrorNode : public ExpressionNode, public ThrowableSubExpressionData {
648 public:
649 PostfixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
650
651 private:
652 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
653
654 ExpressionNode* m_expr;
655 Operator m_operator;
656 };
657
658 class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData {
659 public:
660 DeleteResolveNode(JSGlobalData*, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
661
662 private:
663 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
664
665 Identifier m_ident;
666 };
667
668 class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData {
669 public:
670 DeleteBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset);
671
672 private:
673 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
674
675 ExpressionNode* m_base;
676 ExpressionNode* m_subscript;
677 };
678
679 class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData {
680 public:
681 DeleteDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset);
682
683 private:
684 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
685
686 ExpressionNode* m_base;
687 Identifier m_ident;
688 };
689
690 class DeleteValueNode : public ExpressionNode {
691 public:
692 DeleteValueNode(JSGlobalData*, ExpressionNode*);
693
694 private:
695 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
696
697 ExpressionNode* m_expr;
698 };
699
700 class VoidNode : public ExpressionNode {
701 public:
702 VoidNode(JSGlobalData*, ExpressionNode*);
703
704 private:
705 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
706
707 ExpressionNode* m_expr;
708 };
709
710 class TypeOfResolveNode : public ExpressionNode {
711 public:
712 TypeOfResolveNode(JSGlobalData*, const Identifier&);
713
714 const Identifier& identifier() const { return m_ident; }
715
716 private:
717 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
718
719 Identifier m_ident;
720 };
721
722 class TypeOfValueNode : public ExpressionNode {
723 public:
724 TypeOfValueNode(JSGlobalData*, ExpressionNode*);
725
726 private:
727 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
728
729 ExpressionNode* m_expr;
730 };
731
732 class PrefixResolveNode : public PrePostResolveNode {
733 public:
734 PrefixResolveNode(JSGlobalData*, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
735
736 private:
737 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
738
739 Operator m_operator;
740 };
741
742 class PrefixBracketNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
743 public:
744 PrefixBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
745
746 private:
747 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
748
749 ExpressionNode* m_base;
750 ExpressionNode* m_subscript;
751 Operator m_operator;
752 };
753
754 class PrefixDotNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
755 public:
756 PrefixDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
757
758 private:
759 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
760
761 ExpressionNode* m_base;
762 Identifier m_ident;
763 Operator m_operator;
764 };
765
766 class PrefixErrorNode : public ExpressionNode, public ThrowableExpressionData {
767 public:
768 PrefixErrorNode(JSGlobalData*, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset);
769
770 private:
771 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
772
773 ExpressionNode* m_expr;
774 Operator m_operator;
775 };
776
777 class UnaryOpNode : public ExpressionNode {
778 public:
779 UnaryOpNode(JSGlobalData*, ResultType, ExpressionNode*, OpcodeID);
780
781 protected:
782 ExpressionNode* expr() { return m_expr; }
783
784 private:
785 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
786
787 OpcodeID opcodeID() const { return m_opcodeID; }
788
789 ExpressionNode* m_expr;
790 OpcodeID m_opcodeID;
791 };
792
793 class UnaryPlusNode : public UnaryOpNode {
794 public:
795 UnaryPlusNode(JSGlobalData*, ExpressionNode*);
796
797 private:
798 virtual ExpressionNode* stripUnaryPlus() { return expr(); }
799 };
800
801 class NegateNode : public UnaryOpNode {
802 public:
803 NegateNode(JSGlobalData*, ExpressionNode*);
804 };
805
806 class BitwiseNotNode : public UnaryOpNode {
807 public:
808 BitwiseNotNode(JSGlobalData*, ExpressionNode*);
809 };
810
811 class LogicalNotNode : public UnaryOpNode {
812 public:
813 LogicalNotNode(JSGlobalData*, ExpressionNode*);
814 };
815
816 class BinaryOpNode : public ExpressionNode {
817 public:
818 BinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
819 BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
820
821 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* dst, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);
822
823 private:
824 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
825
826 protected:
827 OpcodeID opcodeID() const { return m_opcodeID; }
828
829 protected:
830 ExpressionNode* m_expr1;
831 ExpressionNode* m_expr2;
832 private:
833 OpcodeID m_opcodeID;
834 protected:
835 bool m_rightHasAssignments;
836 };
837
838 class ReverseBinaryOpNode : public BinaryOpNode {
839 public:
840 ReverseBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
841 ReverseBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
842
843 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
844 };
845
846 class MultNode : public BinaryOpNode {
847 public:
848 MultNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
849 };
850
851 class DivNode : public BinaryOpNode {
852 public:
853 DivNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
854 };
855
856 class ModNode : public BinaryOpNode {
857 public:
858 ModNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
859 };
860
861 class AddNode : public BinaryOpNode {
862 public:
863 AddNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
864
865 virtual bool isAdd() const { return true; }
866 };
867
868 class SubNode : public BinaryOpNode {
869 public:
870 SubNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
871 };
872
873 class LeftShiftNode : public BinaryOpNode {
874 public:
875 LeftShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
876 };
877
878 class RightShiftNode : public BinaryOpNode {
879 public:
880 RightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
881 };
882
883 class UnsignedRightShiftNode : public BinaryOpNode {
884 public:
885 UnsignedRightShiftNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
886 };
887
888 class LessNode : public BinaryOpNode {
889 public:
890 LessNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
891 };
892
893 class GreaterNode : public ReverseBinaryOpNode {
894 public:
895 GreaterNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
896 };
897
898 class LessEqNode : public BinaryOpNode {
899 public:
900 LessEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
901 };
902
903 class GreaterEqNode : public ReverseBinaryOpNode {
904 public:
905 GreaterEqNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
906 };
907
908 class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData {
909 public:
910 ThrowableBinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
911 ThrowableBinaryOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
912
913 private:
914 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
915 };
916
917 class InstanceOfNode : public ThrowableBinaryOpNode {
918 public:
919 InstanceOfNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
920
921 private:
922 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
923 };
924
925 class InNode : public ThrowableBinaryOpNode {
926 public:
927 InNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
928 };
929
930 class EqualNode : public BinaryOpNode {
931 public:
932 EqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
933
934 private:
935 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
936 };
937
938 class NotEqualNode : public BinaryOpNode {
939 public:
940 NotEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
941 };
942
943 class StrictEqualNode : public BinaryOpNode {
944 public:
945 StrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
946
947 private:
948 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
949 };
950
951 class NotStrictEqualNode : public BinaryOpNode {
952 public:
953 NotStrictEqualNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
954 };
955
956 class BitAndNode : public BinaryOpNode {
957 public:
958 BitAndNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
959 };
960
961 class BitOrNode : public BinaryOpNode {
962 public:
963 BitOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
964 };
965
966 class BitXOrNode : public BinaryOpNode {
967 public:
968 BitXOrNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
969 };
970
971 // m_expr1 && m_expr2, m_expr1 || m_expr2
972 class LogicalOpNode : public ExpressionNode {
973 public:
974 LogicalOpNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator);
975
976 private:
977 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
978
979 ExpressionNode* m_expr1;
980 ExpressionNode* m_expr2;
981 LogicalOperator m_operator;
982 };
983
984 // The ternary operator, "m_logical ? m_expr1 : m_expr2"
985 class ConditionalNode : public ExpressionNode {
986 public:
987 ConditionalNode(JSGlobalData*, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2);
988
989 private:
990 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
991
992 ExpressionNode* m_logical;
993 ExpressionNode* m_expr1;
994 ExpressionNode* m_expr2;
995 };
996
997 class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData {
998 public:
999 ReadModifyResolveNode(JSGlobalData*, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1000
1001 private:
1002 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1003
1004 Identifier m_ident;
1005 ExpressionNode* m_right;
1006 size_t m_index; // Used by ReadModifyLocalVarNode.
1007 Operator m_operator;
1008 bool m_rightHasAssignments;
1009 };
1010
1011 class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData {
1012 public:
1013 AssignResolveNode(JSGlobalData*, const Identifier&, ExpressionNode* right, bool rightHasAssignments);
1014
1015 private:
1016 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1017
1018 Identifier m_ident;
1019 ExpressionNode* m_right;
1020 size_t m_index; // Used by ReadModifyLocalVarNode.
1021 bool m_rightHasAssignments;
1022 };
1023
1024 class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
1025 public:
1026 ReadModifyBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1027
1028 private:
1029 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1030
1031 ExpressionNode* m_base;
1032 ExpressionNode* m_subscript;
1033 ExpressionNode* m_right;
1034 Operator m_operator : 30;
1035 bool m_subscriptHasAssignments : 1;
1036 bool m_rightHasAssignments : 1;
1037 };
1038
1039 class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData {
1040 public:
1041 AssignBracketNode(JSGlobalData*, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1042
1043 private:
1044 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1045
1046 ExpressionNode* m_base;
1047 ExpressionNode* m_subscript;
1048 ExpressionNode* m_right;
1049 bool m_subscriptHasAssignments : 1;
1050 bool m_rightHasAssignments : 1;
1051 };
1052
1053 class AssignDotNode : public ExpressionNode, public ThrowableExpressionData {
1054 public:
1055 AssignDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1056
1057 private:
1058 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1059
1060 ExpressionNode* m_base;
1061 Identifier m_ident;
1062 ExpressionNode* m_right;
1063 bool m_rightHasAssignments;
1064 };
1065
1066 class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData {
1067 public:
1068 ReadModifyDotNode(JSGlobalData*, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset);
1069
1070 private:
1071 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1072
1073 ExpressionNode* m_base;
1074 Identifier m_ident;
1075 ExpressionNode* m_right;
1076 Operator m_operator : 31;
1077 bool m_rightHasAssignments : 1;
1078 };
1079
1080 class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData {
1081 public:
1082 AssignErrorNode(JSGlobalData*, ExpressionNode* left, Operator, ExpressionNode* right, unsigned divot, unsigned startOffset, unsigned endOffset);
1083
1084 private:
1085 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1086
1087 ExpressionNode* m_left;
1088 Operator m_operator;
1089 ExpressionNode* m_right;
1090 };
1091
1092 typedef Vector<ExpressionNode*, 8> ExpressionVector;
1093
1094 class CommaNode : public ExpressionNode {
1095 public:
1096 CommaNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2);
1097
1098 void append(ExpressionNode* expr) { m_expressions.append(expr); }
1099
1100 private:
1101 virtual bool isCommaNode() const { return true; }
1102 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1103
1104 ExpressionVector m_expressions;
1105 };
1106
1107 class ConstDeclNode : public ExpressionNode {
1108 public:
1109 ConstDeclNode(JSGlobalData*, const Identifier&, ExpressionNode*);
1110
1111 bool hasInitializer() const { return m_init; }
1112 const Identifier& ident() { return m_ident; }
1113
1114 private:
1115 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1116 virtual RegisterID* emitCodeSingle(BytecodeGenerator&);
1117
1118 Identifier m_ident;
1119
1120 public:
1121 ConstDeclNode* m_next;
1122
1123 private:
1124 ExpressionNode* m_init;
1125 };
1126
1127 class ConstStatementNode : public StatementNode {
1128 public:
1129 ConstStatementNode(JSGlobalData*, ConstDeclNode* next);
1130
1131 private:
1132 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1133
1134 ConstDeclNode* m_next;
1135 };
1136
1137 typedef Vector<StatementNode*> StatementVector;
1138
1139 class SourceElements : public ParserArenaDeletable {
1140 public:
1141 SourceElements(JSGlobalData*);
1142
1143 void append(StatementNode*);
1144 void releaseContentsIntoVector(StatementVector& destination)
1145 {
1146 ASSERT(destination.isEmpty());
1147 m_statements.swap(destination);
1148 destination.shrinkToFit();
1149 }
1150
1151 private:
1152 StatementVector m_statements;
1153 };
1154
1155 class BlockNode : public StatementNode {
1156 public:
1157 BlockNode(JSGlobalData*, SourceElements* children);
1158
1159 StatementVector& children() { return m_children; }
1160
1161 private:
1162 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1163
1164 virtual bool isBlock() const { return true; }
1165
1166 StatementVector m_children;
1167 };
1168
1169 class EmptyStatementNode : public StatementNode {
1170 public:
1171 EmptyStatementNode(JSGlobalData*);
1172
1173 private:
1174 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1175
1176 virtual bool isEmptyStatement() const { return true; }
1177 };
1178
1179 class DebuggerStatementNode : public StatementNode {
1180 public:
1181 DebuggerStatementNode(JSGlobalData*);
1182
1183 private:
1184 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1185 };
1186
1187 class ExprStatementNode : public StatementNode {
1188 public:
1189 ExprStatementNode(JSGlobalData*, ExpressionNode*);
1190
1191 ExpressionNode* expr() const { return m_expr; }
1192
1193 private:
1194 virtual bool isExprStatement() const { return true; }
1195
1196 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1197
1198 ExpressionNode* m_expr;
1199 };
1200
1201 class VarStatementNode : public StatementNode {
1202 public:
1203 VarStatementNode(JSGlobalData*, ExpressionNode*);
1204
1205 private:
1206 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1207
1208 ExpressionNode* m_expr;
1209 };
1210
1211 class IfNode : public StatementNode {
1212 public:
1213 IfNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock);
1214
1215 protected:
1216 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1217
1218 ExpressionNode* m_condition;
1219 StatementNode* m_ifBlock;
1220 };
1221
1222 class IfElseNode : public IfNode {
1223 public:
1224 IfElseNode(JSGlobalData*, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock);
1225
1226 private:
1227 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1228
1229 StatementNode* m_elseBlock;
1230 };
1231
1232 class DoWhileNode : public StatementNode {
1233 public:
1234 DoWhileNode(JSGlobalData*, StatementNode* statement, ExpressionNode*);
1235
1236 private:
1237 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1238
1239 StatementNode* m_statement;
1240 ExpressionNode* m_expr;
1241 };
1242
1243 class WhileNode : public StatementNode {
1244 public:
1245 WhileNode(JSGlobalData*, ExpressionNode*, StatementNode* statement);
1246
1247 private:
1248 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1249
1250 ExpressionNode* m_expr;
1251 StatementNode* m_statement;
1252 };
1253
1254 class ForNode : public StatementNode {
1255 public:
1256 ForNode(JSGlobalData*, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode* statement, bool expr1WasVarDecl);
1257
1258 private:
1259 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1260
1261 ExpressionNode* m_expr1;
1262 ExpressionNode* m_expr2;
1263 ExpressionNode* m_expr3;
1264 StatementNode* m_statement;
1265 bool m_expr1WasVarDecl;
1266 };
1267
1268 class ForInNode : public StatementNode, public ThrowableExpressionData {
1269 public:
1270 ForInNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, StatementNode*);
1271 ForInNode(JSGlobalData*, const Identifier&, ExpressionNode*, ExpressionNode*, StatementNode*, int divot, int startOffset, int endOffset);
1272
1273 private:
1274 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1275
1276 Identifier m_ident;
1277 ExpressionNode* m_init;
1278 ExpressionNode* m_lexpr;
1279 ExpressionNode* m_expr;
1280 StatementNode* m_statement;
1281 bool m_identIsVarDecl;
1282 };
1283
1284 class ContinueNode : public StatementNode, public ThrowableExpressionData {
1285 public:
1286 ContinueNode(JSGlobalData*);
1287 ContinueNode(JSGlobalData*, const Identifier&);
1288
1289 private:
1290 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1291
1292 Identifier m_ident;
1293 };
1294
1295 class BreakNode : public StatementNode, public ThrowableExpressionData {
1296 public:
1297 BreakNode(JSGlobalData*);
1298 BreakNode(JSGlobalData*, const Identifier&);
1299
1300 private:
1301 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1302
1303 Identifier m_ident;
1304 };
1305
1306 class ReturnNode : public StatementNode, public ThrowableExpressionData {
1307 public:
1308 ReturnNode(JSGlobalData*, ExpressionNode* value);
1309
1310 private:
1311 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1312
1313 virtual bool isReturnNode() const { return true; }
1314
1315 ExpressionNode* m_value;
1316 };
1317
1318 class WithNode : public StatementNode {
1319 public:
1320 WithNode(JSGlobalData*, ExpressionNode*, StatementNode*, uint32_t divot, uint32_t expressionLength);
1321
1322 private:
1323 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1324
1325 ExpressionNode* m_expr;
1326 StatementNode* m_statement;
1327 uint32_t m_divot;
1328 uint32_t m_expressionLength;
1329 };
1330
1331 class LabelNode : public StatementNode, public ThrowableExpressionData {
1332 public:
1333 LabelNode(JSGlobalData*, const Identifier& name, StatementNode*);
1334
1335 private:
1336 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1337
1338 Identifier m_name;
1339 StatementNode* m_statement;
1340 };
1341
1342 class ThrowNode : public StatementNode, public ThrowableExpressionData {
1343 public:
1344 ThrowNode(JSGlobalData*, ExpressionNode*);
1345
1346 private:
1347 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1348
1349 ExpressionNode* m_expr;
1350 };
1351
1352 class TryNode : public StatementNode {
1353 public:
1354 TryNode(JSGlobalData*, StatementNode* tryBlock, const Identifier& exceptionIdent, bool catchHasEval, StatementNode* catchBlock, StatementNode* finallyBlock);
1355
1356 private:
1357 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0);
1358
1359 StatementNode* m_tryBlock;
1360 Identifier m_exceptionIdent;
1361 StatementNode* m_catchBlock;
1362 StatementNode* m_finallyBlock;
1363 bool m_catchHasEval;
1364 };
1365
1366 class ParameterNode : public ParserArenaDeletable {
1367 public:
1368 ParameterNode(JSGlobalData*, const Identifier&);
1369 ParameterNode(JSGlobalData*, ParameterNode*, const Identifier&);
1370
1371 const Identifier& ident() const { return m_ident; }
1372 ParameterNode* nextParam() const { return m_next; }
1373
1374 private:
1375 Identifier m_ident;
1376 ParameterNode* m_next;
1377 };
1378
1379 struct ScopeNodeData {
1380 typedef DeclarationStacks::VarStack VarStack;
1381 typedef DeclarationStacks::FunctionStack FunctionStack;
1382
1383 ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, int numConstants);
1384
1385 ParserArena m_arena;
1386 VarStack m_varStack;
1387 FunctionStack m_functionStack;
1388 int m_numConstants;
1389 StatementVector m_children;
1390
1391 void mark();
1392 };
1393
1394 class ScopeNode : public StatementNode, public ParserArenaRefCounted {
1395 public:
1396 typedef DeclarationStacks::VarStack VarStack;
1397 typedef DeclarationStacks::FunctionStack FunctionStack;
1398
1399 ScopeNode(JSGlobalData*);
1400 ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, CodeFeatures, int numConstants);
1401
1402 void adoptData(std::auto_ptr<ScopeNodeData> data)
1403 {
1404 ASSERT(!data->m_arena.contains(this));
1405 ASSERT(!m_data);
1406 m_data.adopt(data);
1407 }
1408 ScopeNodeData* data() const { return m_data.get(); }
1409 void destroyData() { m_data.clear(); }
1410
1411 const SourceCode& source() const { return m_source; }
1412 const UString& sourceURL() const { return m_source.provider()->url(); }
1413 intptr_t sourceID() const { return m_source.provider()->asID(); }
1414
1415 void setFeatures(CodeFeatures features) { m_features = features; }
1416 CodeFeatures features() { return m_features; }
1417
1418 bool usesEval() const { return m_features & EvalFeature; }
1419 bool usesArguments() const { return m_features & ArgumentsFeature; }
1420 void setUsesArguments() { m_features |= ArgumentsFeature; }
1421 bool usesThis() const { return m_features & ThisFeature; }
1422 bool needsActivation() const { return m_features & (EvalFeature | ClosureFeature | WithFeature | CatchFeature); }
1423
1424 VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; }
1425 FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; }
1426
1427 StatementVector& children() { ASSERT(m_data); return m_data->m_children; }
1428
1429 int neededConstants()
1430 {
1431 ASSERT(m_data);
1432 // We may need 2 more constants than the count given by the parser,
1433 // because of the various uses of jsUndefined() and jsNull().
1434 return m_data->m_numConstants + 2;
1435 }
1436
1437 virtual void mark() { }
1438
1439 #if ENABLE(JIT)
1440 JITCode& generatedJITCode()
1441 {
1442 ASSERT(m_jitCode);
1443 return m_jitCode;
1444 }
1445
1446 ExecutablePool* getExecutablePool()
1447 {
1448 return m_jitCode.getExecutablePool();
1449 }
1450
1451 void setJITCode(const JITCode jitCode)
1452 {
1453 m_jitCode = jitCode;
1454 }
1455 #endif
1456
1457 protected:
1458 void setSource(const SourceCode& source) { m_source = source; }
1459
1460 #if ENABLE(JIT)
1461 JITCode m_jitCode;
1462 #endif
1463
1464 private:
1465 OwnPtr<ScopeNodeData> m_data;
1466 CodeFeatures m_features;
1467 SourceCode m_source;
1468 };
1469
1470 class ProgramNode : public ScopeNode {
1471 public:
1472 static PassRefPtr<ProgramNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1473
1474 ProgramCodeBlock& bytecode(ScopeChainNode* scopeChain)
1475 {
1476 if (!m_code)
1477 generateBytecode(scopeChain);
1478 return *m_code;
1479 }
1480
1481 #if ENABLE(JIT)
1482 JITCode& jitCode(ScopeChainNode* scopeChain)
1483 {
1484 if (!m_jitCode)
1485 generateJITCode(scopeChain);
1486 return m_jitCode;
1487 }
1488 #endif
1489
1490 private:
1491 ProgramNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1492
1493 void generateBytecode(ScopeChainNode*);
1494 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1495
1496 #if ENABLE(JIT)
1497 void generateJITCode(ScopeChainNode*);
1498 #endif
1499
1500 OwnPtr<ProgramCodeBlock> m_code;
1501 };
1502
1503 class EvalNode : public ScopeNode {
1504 public:
1505 static PassRefPtr<EvalNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1506
1507 EvalCodeBlock& bytecode(ScopeChainNode* scopeChain)
1508 {
1509 if (!m_code)
1510 generateBytecode(scopeChain);
1511 return *m_code;
1512 }
1513
1514 EvalCodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
1515
1516 virtual void mark();
1517
1518 #if ENABLE(JIT)
1519 JITCode& jitCode(ScopeChainNode* scopeChain)
1520 {
1521 if (!m_jitCode)
1522 generateJITCode(scopeChain);
1523 return m_jitCode;
1524 }
1525 #endif
1526
1527 private:
1528 EvalNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1529
1530 void generateBytecode(ScopeChainNode*);
1531 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1532
1533 #if ENABLE(JIT)
1534 void generateJITCode(ScopeChainNode*);
1535 #endif
1536
1537 OwnPtr<EvalCodeBlock> m_code;
1538 };
1539
1540 class FunctionBodyNode : public ScopeNode {
1541 friend class JIT;
1542 public:
1543 #if ENABLE(JIT)
1544 static PassRefPtr<FunctionBodyNode> createNativeThunk(JSGlobalData*);
1545 #endif
1546 static FunctionBodyNode* create(JSGlobalData*);
1547 static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1548 virtual ~FunctionBodyNode();
1549
1550 const Identifier* parameters() const { return m_parameters; }
1551 size_t parameterCount() const { return m_parameterCount; }
1552 UString paramString() const ;
1553 Identifier* copyParameters();
1554
1555 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1556
1557 bool isGenerated() const
1558 {
1559 return m_code;
1560 }
1561
1562 bool isHostFunction() const;
1563
1564 virtual void mark();
1565
1566 void finishParsing(const SourceCode&, ParameterNode*);
1567 void finishParsing(Identifier* parameters, size_t parameterCount);
1568
1569 UString toSourceString() const { return source().toString(); }
1570
1571 CodeBlock& bytecodeForExceptionInfoReparse(ScopeChainNode*, CodeBlock*);
1572 #if ENABLE(JIT)
1573 JITCode& jitCode(ScopeChainNode* scopeChain)
1574 {
1575 if (!m_jitCode)
1576 generateJITCode(scopeChain);
1577 return m_jitCode;
1578 }
1579 #endif
1580
1581 CodeBlock& bytecode(ScopeChainNode* scopeChain)
1582 {
1583 ASSERT(scopeChain);
1584 if (!m_code)
1585 generateBytecode(scopeChain);
1586 return *m_code;
1587 }
1588
1589 CodeBlock& generatedBytecode()
1590 {
1591 ASSERT(m_code);
1592 return *m_code;
1593 }
1594
1595 private:
1596 FunctionBodyNode(JSGlobalData*);
1597 FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants);
1598
1599 void generateBytecode(ScopeChainNode*);
1600 #if ENABLE(JIT)
1601 void generateJITCode(ScopeChainNode*);
1602 #endif
1603 Identifier* m_parameters;
1604 size_t m_parameterCount;
1605 OwnPtr<CodeBlock> m_code;
1606 };
1607
1608 class FuncExprNode : public ExpressionNode, public ParserArenaRefCounted {
1609 public:
1610 FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0);
1611
1612 JSFunction* makeFunction(ExecState*, ScopeChainNode*);
1613
1614 FunctionBodyNode* body() { return m_body.get(); }
1615
1616 private:
1617 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1618
1619 virtual bool isFuncExprNode() const { return true; }
1620
1621 Identifier m_ident;
1622 RefPtr<FunctionBodyNode> m_body;
1623 };
1624
1625 class FuncDeclNode : public StatementNode, public ParserArenaRefCounted {
1626 public:
1627 FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
1628
1629 JSFunction* makeFunction(ExecState*, ScopeChainNode*);
1630
1631 Identifier m_ident;
1632
1633 FunctionBodyNode* body() { return m_body.get(); }
1634
1635 private:
1636 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1637
1638 RefPtr<FunctionBodyNode> m_body;
1639 };
1640
1641 class CaseClauseNode : public ParserArenaDeletable {
1642 public:
1643 CaseClauseNode(JSGlobalData*, ExpressionNode*);
1644 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*);
1645
1646 ExpressionNode* expr() const { return m_expr; }
1647 StatementVector& children() { return m_children; }
1648
1649 private:
1650 ExpressionNode* m_expr;
1651 StatementVector m_children;
1652 };
1653
1654 class ClauseListNode : public ParserArenaDeletable {
1655 public:
1656 ClauseListNode(JSGlobalData*, CaseClauseNode*);
1657 ClauseListNode(JSGlobalData*, ClauseListNode*, CaseClauseNode*);
1658
1659 CaseClauseNode* getClause() const { return m_clause; }
1660 ClauseListNode* getNext() const { return m_next; }
1661
1662 private:
1663 CaseClauseNode* m_clause;
1664 ClauseListNode* m_next;
1665 };
1666
1667 class CaseBlockNode : public ParserArenaDeletable {
1668 public:
1669 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
1670
1671 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* dst = 0);
1672
1673 private:
1674 SwitchInfo::SwitchType tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
1675 ClauseListNode* m_list1;
1676 CaseClauseNode* m_defaultClause;
1677 ClauseListNode* m_list2;
1678 };
1679
1680 class SwitchNode : public StatementNode {
1681 public:
1682 SwitchNode(JSGlobalData*, ExpressionNode*, CaseBlockNode*);
1683
1684 private:
1685 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
1686
1687 ExpressionNode* m_expr;
1688 CaseBlockNode* m_block;
1689 };
1690
1691 struct ElementList {
1692 ElementNode* head;
1693 ElementNode* tail;
1694 };
1695
1696 struct PropertyList {
1697 PropertyListNode* head;
1698 PropertyListNode* tail;
1699 };
1700
1701 struct ArgumentList {
1702 ArgumentListNode* head;
1703 ArgumentListNode* tail;
1704 };
1705
1706 struct ConstDeclList {
1707 ConstDeclNode* head;
1708 ConstDeclNode* tail;
1709 };
1710
1711 struct ParameterList {
1712 ParameterNode* head;
1713 ParameterNode* tail;
1714 };
1715
1716 struct ClauseList {
1717 ClauseListNode* head;
1718 ClauseListNode* tail;
1719 };
1720
1721 } // namespace JSC
1722
1723 #endif // Nodes_h