Changeset 47664 in webkit for trunk/JavaScriptCore/parser/Nodes.h
- Timestamp:
- Aug 21, 2009, 11:40:53 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Nodes.h
r47582 r47664 35 35 #include "SymbolTable.h" 36 36 #include <wtf/MathExtras.h> 37 #include <wtf/OwnPtr.h>38 37 39 38 namespace JSC { … … 41 40 class ArgumentListNode; 42 41 class BytecodeGenerator; 43 class CodeBlock;44 class EvalCodeBlock;45 class EvalExecutable;46 class FuncDeclNode;47 42 class FunctionBodyNode; 48 class FunctionCodeBlock;49 class JSFunction;50 class ProgramCodeBlock;51 class ProgramExecutable;52 43 class PropertyListNode; 53 44 class ReadModifyResolveNode; 54 45 class RegisterID; 55 46 class ScopeChainNode; 47 class ScopeNode; 56 48 57 49 typedef unsigned CodeFeatures; … … 91 83 namespace DeclarationStacks { 92 84 enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; 93 typedef Vector<std::pair< Identifier, unsigned> > VarStack;85 typedef Vector<std::pair<const Identifier*, unsigned> > VarStack; 94 86 typedef Vector<FunctionBodyNode*> FunctionStack; 95 87 } … … 101 93 }; 102 94 95 class ParserArenaFreeable { 96 public: 97 // ParserArenaFreeable objects are are freed when the arena is deleted. 98 // Destructors are not called. Clients must not call delete on such objects. 99 void* operator new(size_t, JSGlobalData*); 100 }; 101 103 102 class ParserArenaDeletable { 104 protected:105 ParserArenaDeletable() { }106 107 103 public: 108 104 virtual ~ParserArenaDeletable() { } 109 105 110 // Objects created with this version of new are deleted when the arena is deleted. 106 // ParserArenaDeletable objects are deleted when the arena is deleted. 107 // Clients must not call delete directly on such objects. 111 108 void* operator new(size_t, JSGlobalData*); 112 113 // Objects created with this version of new are not deleted when the arena is deleted. 114 // Other arrangements must be made. 115 void* operator new(size_t); 116 117 void operator delete(void*); 118 }; 119 120 class ParserArenaRefCounted : public RefCountedCustomAllocated<ParserArenaRefCounted> { 109 }; 110 111 class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> { 121 112 protected: 122 113 ParserArenaRefCounted(JSGlobalData*); … … 129 120 }; 130 121 131 class Node : public ParserArena Deletable {122 class Node : public ParserArenaFreeable { 132 123 protected: 133 124 Node(JSGlobalData*); 134 125 135 126 public: 136 /* 137 Return value: The register holding the production's value. 138 dst: An optional parameter specifying the most efficient 139 destination at which to store the production's value. 140 The callee must honor dst. 141 142 dst provides for a crude form of copy propagation. For example, 143 144 x = 1 145 146 becomes 147 148 load r[x], 1 149 150 instead of 151 152 load r0, 1 153 mov r[x], r0 154 155 because the assignment node, "x =", passes r[x] as dst to the number 156 node, "1". 157 */ 158 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0) = 0; 127 virtual ~Node() { } 128 129 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0; 159 130 160 131 int lineNo() const { return m_line; } … … 165 136 166 137 class ExpressionNode : public Node { 167 p ublic:138 protected: 168 139 ExpressionNode(JSGlobalData*, ResultType = ResultType::unknownType()); 169 140 141 public: 170 142 virtual bool isNumber() const { return false; } 171 143 virtual bool isString() const { return false; } … … 185 157 ResultType resultDescriptor() const { return m_resultType; } 186 158 187 // This needs to be in public in order to compile using GCC 3.x188 typedef enum { EvalOperator, FunctionCall } CallerType;189 190 159 private: 191 160 ResultType m_resultType; … … 193 162 194 163 class StatementNode : public Node { 195 p ublic:164 protected: 196 165 StatementNode(JSGlobalData*); 197 166 198 void setLoc(int line0, int line1); 167 public: 168 void setLoc(int firstLine, int lastLine); 199 169 int firstLine() const { return lineNo(); } 200 170 int lastLine() const { return m_lastLine; } … … 234 204 class NumberNode : public ExpressionNode { 235 205 public: 236 NumberNode(JSGlobalData*, double v );237 238 double value() const { return m_ double; }239 void setValue(double d) { m_double = d; }206 NumberNode(JSGlobalData*, double value); 207 208 double value() const { return m_value; } 209 void setValue(double value) { m_value = value; } 240 210 241 211 private: … … 245 215 virtual bool isPure(BytecodeGenerator&) const { return true; } 246 216 247 double m_ double;217 double m_value; 248 218 }; 249 219 250 220 class StringNode : public ExpressionNode { 251 221 public: 252 StringNode(JSGlobalData*, const Identifier& v);222 StringNode(JSGlobalData*, const Identifier&); 253 223 254 224 const Identifier& value() { return m_value; } 225 226 private: 255 227 virtual bool isPure(BytecodeGenerator&) const { return true; } 256 228 257 private:258 229 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 259 230 260 231 virtual bool isString() const { return true; } 261 232 262 Identifierm_value;233 const Identifier& m_value; 263 234 }; 264 235 … … 291 262 292 263 protected: 293 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg); 294 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const Identifier&); 264 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message); 265 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message, const UString&); 266 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* message, const Identifier&); 295 267 296 268 private: … … 303 275 public: 304 276 ThrowableSubExpressionData() 305 : ThrowableExpressionData() 306 , m_subexpressionDivotOffset(0) 277 : m_subexpressionDivotOffset(0) 307 278 , m_subexpressionEndOffset(0) 308 279 { … … 333 304 public: 334 305 ThrowablePrefixedSubExpressionData() 335 : ThrowableExpressionData() 336 , m_subexpressionDivotOffset(0) 306 : m_subexpressionDivotOffset(0) 337 307 , m_subexpressionStartOffset(0) 338 308 { … … 367 337 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 368 338 369 Identifierm_pattern;370 Identifierm_flags;339 const Identifier& m_pattern; 340 const Identifier& m_flags; 371 341 }; 372 342 … … 392 362 virtual bool isResolveNode() const { return true; } 393 363 394 Identifierm_ident;364 const Identifier& m_ident; 395 365 int32_t m_startOffset; 396 366 }; 397 367 398 class ElementNode : public ParserArena Deletable {368 class ElementNode : public ParserArenaFreeable { 399 369 public: 400 370 ElementNode(JSGlobalData*, int elision, ExpressionNode*); … … 429 399 }; 430 400 431 class PropertyNode : public ParserArena Deletable {401 class PropertyNode : public ParserArenaFreeable { 432 402 public: 433 403 enum Type { Constant, Getter, Setter }; … … 440 410 private: 441 411 friend class PropertyListNode; 442 Identifierm_name;412 const Identifier& m_name; 443 413 ExpressionNode* m_assign; 444 414 Type m_type; … … 500 470 501 471 ExpressionNode* m_base; 502 Identifierm_ident;472 const Identifier& m_ident; 503 473 }; 504 474 … … 515 485 }; 516 486 517 class ArgumentsNode : public ParserArena Deletable {487 class ArgumentsNode : public ParserArenaFreeable { 518 488 public: 519 489 ArgumentsNode(JSGlobalData*); … … 563 533 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 564 534 565 Identifierm_ident;535 const Identifier& m_ident; 566 536 ArgumentsNode* m_args; 567 537 size_t m_index; // Used by LocalVarFunctionCallNode. … … 590 560 protected: 591 561 ExpressionNode* m_base; 592 const Identifier m_ident;562 const Identifier& m_ident; 593 563 ArgumentsNode* m_args; 594 564 }; … … 615 585 616 586 protected: 617 const Identifier m_ident;587 const Identifier& m_ident; 618 588 }; 619 589 … … 648 618 649 619 ExpressionNode* m_base; 650 Identifierm_ident;620 const Identifier& m_ident; 651 621 Operator m_operator; 652 622 }; … … 670 640 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 671 641 672 Identifierm_ident;642 const Identifier& m_ident; 673 643 }; 674 644 … … 692 662 693 663 ExpressionNode* m_base; 694 Identifierm_ident;664 const Identifier& m_ident; 695 665 }; 696 666 … … 724 694 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 725 695 726 Identifierm_ident;696 const Identifier& m_ident; 727 697 }; 728 698 … … 767 737 768 738 ExpressionNode* m_base; 769 Identifierm_ident;739 const Identifier& m_ident; 770 740 Operator m_operator; 771 741 }; … … 826 796 BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); 827 797 828 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* d st, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);798 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0); 829 799 830 800 private: … … 1009 979 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1010 980 1011 Identifierm_ident;981 const Identifier& m_ident; 1012 982 ExpressionNode* m_right; 1013 983 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1023 993 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1024 994 1025 Identifierm_ident;995 const Identifier& m_ident; 1026 996 ExpressionNode* m_right; 1027 997 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1066 1036 1067 1037 ExpressionNode* m_base; 1068 Identifierm_ident;1038 const Identifier& m_ident; 1069 1039 ExpressionNode* m_right; 1070 1040 bool m_rightHasAssignments; … … 1079 1049 1080 1050 ExpressionNode* m_base; 1081 Identifierm_ident;1051 const Identifier& m_ident; 1082 1052 ExpressionNode* m_right; 1083 1053 Operator m_operator : 31; … … 1123 1093 virtual RegisterID* emitCodeSingle(BytecodeGenerator&); 1124 1094 1125 Identifierm_ident;1095 const Identifier& m_ident; 1126 1096 1127 1097 public: … … 1142 1112 }; 1143 1113 1144 typedef Vector<StatementNode*> StatementVector;1145 1146 1114 class SourceElements : public ParserArenaDeletable { 1147 1115 public: … … 1149 1117 1150 1118 void append(StatementNode*); 1151 void releaseContentsIntoVector(StatementVector& destination) 1152 { 1153 ASSERT(destination.isEmpty()); 1154 m_statements.swap(destination); 1155 destination.shrinkToFit(); 1156 } 1157 1158 private: 1159 StatementVector m_statements; 1119 1120 StatementNode* singleStatement() const; 1121 StatementNode* lastStatement() const; 1122 1123 void emitBytecode(BytecodeGenerator&, RegisterID* destination); 1124 1125 private: 1126 Vector<StatementNode*> m_statements; 1160 1127 }; 1161 1128 1162 1129 class BlockNode : public StatementNode { 1163 1130 public: 1164 BlockNode(JSGlobalData*, SourceElements* children);1165 1166 Statement Vector& children() { return m_children; }1131 BlockNode(JSGlobalData*, SourceElements* = 0); 1132 1133 StatementNode* lastStatement() const; 1167 1134 1168 1135 private: … … 1171 1138 virtual bool isBlock() const { return true; } 1172 1139 1173 S tatementVector m_children;1140 SourceElements* m_statements; 1174 1141 }; 1175 1142 … … 1281 1248 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1282 1249 1283 Identifierm_ident;1250 const Identifier& m_ident; 1284 1251 ExpressionNode* m_init; 1285 1252 ExpressionNode* m_lexpr; … … 1297 1264 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1298 1265 1299 Identifierm_ident;1266 const Identifier& m_ident; 1300 1267 }; 1301 1268 … … 1308 1275 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1309 1276 1310 Identifierm_ident;1277 const Identifier& m_ident; 1311 1278 }; 1312 1279 … … 1343 1310 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1344 1311 1345 Identifierm_name;1312 const Identifier& m_name; 1346 1313 StatementNode* m_statement; 1347 1314 }; … … 1362 1329 1363 1330 private: 1364 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst= 0);1331 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1365 1332 1366 1333 StatementNode* m_tryBlock; 1367 Identifierm_exceptionIdent;1334 const Identifier& m_exceptionIdent; 1368 1335 StatementNode* m_catchBlock; 1369 1336 StatementNode* m_finallyBlock; … … 1371 1338 }; 1372 1339 1373 class ParameterNode : public ParserArena Deletable {1340 class ParameterNode : public ParserArenaFreeable { 1374 1341 public: 1375 1342 ParameterNode(JSGlobalData*, const Identifier&); … … 1380 1347 1381 1348 private: 1382 Identifierm_ident;1349 const Identifier& m_ident; 1383 1350 ParameterNode* m_next; 1384 1351 }; … … 1394 1361 FunctionStack m_functionStack; 1395 1362 int m_numConstants; 1396 S tatementVector m_children;1363 SourceElements* m_statements; 1397 1364 }; 1398 1365 … … 1404 1371 ScopeNode(JSGlobalData*); 1405 1372 ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, CodeFeatures, int numConstants); 1373 1374 using ParserArenaRefCounted::operator new; 1406 1375 1407 1376 void adoptData(std::auto_ptr<ScopeNodeData> data) … … 1430 1399 FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } 1431 1400 1432 StatementVector& children() { ASSERT(m_data); return m_data->m_children; }1433 1434 1401 int neededConstants() 1435 1402 { … … 1440 1407 } 1441 1408 1409 StatementNode* singleStatement() const; 1410 1411 void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination); 1412 1442 1413 protected: 1443 1414 void setSource(const SourceCode& source) { m_source = source; } … … 1488 1459 const Identifier& ident() { return m_ident; } 1489 1460 1490 void reparseDataIfNecessary(ScopeChainNode* scopeChainNode);1461 void reparseDataIfNecessary(ScopeChainNode*); 1491 1462 1492 1463 private: 1493 1464 FunctionBodyNode(JSGlobalData*); 1494 1465 FunctionBodyNode(JSGlobalData*, SourceElements*, VarStack*, FunctionStack*, const SourceCode&, CodeFeatures, int numConstants); 1466 1495 1467 Identifier m_ident; 1496 1468 Identifier* m_parameters; … … 1502 1474 FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0); 1503 1475 1504 FunctionBodyNode* body() { return m_body .get(); }1476 FunctionBodyNode* body() { return m_body; } 1505 1477 1506 1478 private: … … 1509 1481 virtual bool isFuncExprNode() const { return true; } 1510 1482 1511 RefPtr<FunctionBodyNode>m_body;1483 FunctionBodyNode* m_body; 1512 1484 }; 1513 1485 … … 1516 1488 FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); 1517 1489 1518 FunctionBodyNode* body() { return m_body.get(); } 1519 1520 private: 1521 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1522 1523 RefPtr<FunctionBodyNode> m_body; 1524 }; 1525 1526 class CaseClauseNode : public ParserArenaDeletable { 1527 public: 1528 CaseClauseNode(JSGlobalData*, ExpressionNode*); 1529 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*); 1490 FunctionBodyNode* body() { return m_body; } 1491 1492 private: 1493 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1494 1495 FunctionBodyNode* m_body; 1496 }; 1497 1498 class CaseClauseNode : public ParserArenaFreeable { 1499 public: 1500 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements* = 0); 1530 1501 1531 1502 ExpressionNode* expr() const { return m_expr; } 1532 StatementVector& children() { return m_children; } 1533 1534 private: 1535 ExpressionNode* m_expr; 1536 StatementVector m_children; 1537 }; 1538 1539 class ClauseListNode : public ParserArenaDeletable { 1503 1504 void emitBytecode(BytecodeGenerator&, RegisterID* destination); 1505 1506 private: 1507 ExpressionNode* m_expr; 1508 SourceElements* m_statements; 1509 }; 1510 1511 class ClauseListNode : public ParserArenaFreeable { 1540 1512 public: 1541 1513 ClauseListNode(JSGlobalData*, CaseClauseNode*); … … 1550 1522 }; 1551 1523 1552 class CaseBlockNode : public ParserArena Deletable {1524 class CaseBlockNode : public ParserArenaFreeable { 1553 1525 public: 1554 1526 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); 1555 1527 1556 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* d st = 0);1528 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination); 1557 1529 1558 1530 private:
Note:
See TracChangeset
for help on using the changeset viewer.