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