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