source: webkit/trunk/JavaScriptCore/parser/Nodes.h@ 47259

Last change on this file since 47259 was 47259, checked in by Darin Adler, 16 years ago

Another part of https://bugs.webkit.org/show_bug.cgi?id=28287

Patch by Darin Adler <Darin Adler> on 2009-08-13
Reviewed by George Staikos.

  • parser/Grammar.y: Pass the number to the PropertyNode instead of

first turning it into an Identifier.

  • parser/NodeConstructors.h:

(JSC::PropertyNode::PropertyNode): Add an overload that takes a double
so the code to convert to a string can be here instead of Grammar.y.

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