Changeset 47571 in webkit for trunk/JavaScriptCore/parser/Nodes.h
- Timestamp:
- Aug 20, 2009, 7:24:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Nodes.h
r47519 r47571 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 … … 292 263 protected: 293 264 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg); 265 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const UString&); 294 266 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const Identifier&); 295 267 … … 367 339 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 368 340 369 Identifierm_pattern;370 Identifierm_flags;341 const Identifier& m_pattern; 342 const Identifier& m_flags; 371 343 }; 372 344 … … 392 364 virtual bool isResolveNode() const { return true; } 393 365 394 Identifierm_ident;366 const Identifier& m_ident; 395 367 int32_t m_startOffset; 396 368 }; 397 369 398 class ElementNode : public ParserArena Deletable {370 class ElementNode : public ParserArenaFreeable { 399 371 public: 400 372 ElementNode(JSGlobalData*, int elision, ExpressionNode*); … … 429 401 }; 430 402 431 class PropertyNode : public ParserArena Deletable {403 class PropertyNode : public ParserArenaFreeable { 432 404 public: 433 405 enum Type { Constant, Getter, Setter }; … … 440 412 private: 441 413 friend class PropertyListNode; 442 Identifierm_name;414 const Identifier& m_name; 443 415 ExpressionNode* m_assign; 444 416 Type m_type; … … 500 472 501 473 ExpressionNode* m_base; 502 Identifierm_ident;474 const Identifier& m_ident; 503 475 }; 504 476 … … 515 487 }; 516 488 517 class ArgumentsNode : public ParserArena Deletable {489 class ArgumentsNode : public ParserArenaFreeable { 518 490 public: 519 491 ArgumentsNode(JSGlobalData*); … … 563 535 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 564 536 565 Identifierm_ident;537 const Identifier& m_ident; 566 538 ArgumentsNode* m_args; 567 539 size_t m_index; // Used by LocalVarFunctionCallNode. … … 590 562 protected: 591 563 ExpressionNode* m_base; 592 const Identifier m_ident;564 const Identifier& m_ident; 593 565 ArgumentsNode* m_args; 594 566 }; … … 615 587 616 588 protected: 617 const Identifier m_ident;589 const Identifier& m_ident; 618 590 }; 619 591 … … 648 620 649 621 ExpressionNode* m_base; 650 Identifierm_ident;622 const Identifier& m_ident; 651 623 Operator m_operator; 652 624 }; … … 670 642 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 671 643 672 Identifierm_ident;644 const Identifier& m_ident; 673 645 }; 674 646 … … 692 664 693 665 ExpressionNode* m_base; 694 Identifierm_ident;666 const Identifier& m_ident; 695 667 }; 696 668 … … 724 696 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 725 697 726 Identifierm_ident;698 const Identifier& m_ident; 727 699 }; 728 700 … … 767 739 768 740 ExpressionNode* m_base; 769 Identifierm_ident;741 const Identifier& m_ident; 770 742 Operator m_operator; 771 743 }; … … 826 798 BinaryOpNode(JSGlobalData*, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments); 827 799 828 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* d st, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);800 RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0); 829 801 830 802 private: … … 1009 981 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1010 982 1011 Identifierm_ident;983 const Identifier& m_ident; 1012 984 ExpressionNode* m_right; 1013 985 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1023 995 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1024 996 1025 Identifierm_ident;997 const Identifier& m_ident; 1026 998 ExpressionNode* m_right; 1027 999 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1066 1038 1067 1039 ExpressionNode* m_base; 1068 Identifierm_ident;1040 const Identifier& m_ident; 1069 1041 ExpressionNode* m_right; 1070 1042 bool m_rightHasAssignments; … … 1079 1051 1080 1052 ExpressionNode* m_base; 1081 Identifierm_ident;1053 const Identifier& m_ident; 1082 1054 ExpressionNode* m_right; 1083 1055 Operator m_operator : 31; … … 1123 1095 virtual RegisterID* emitCodeSingle(BytecodeGenerator&); 1124 1096 1125 Identifierm_ident;1097 const Identifier& m_ident; 1126 1098 1127 1099 public: … … 1142 1114 }; 1143 1115 1144 typedef Vector<StatementNode*> StatementVector;1145 1146 1116 class SourceElements : public ParserArenaDeletable { 1147 1117 public: … … 1149 1119 1150 1120 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; 1121 1122 StatementNode* singleStatement() const; 1123 StatementNode* lastStatement() const; 1124 1125 void emitBytecode(BytecodeGenerator&, RegisterID* destination); 1126 1127 private: 1128 Vector<StatementNode*> m_statements; 1160 1129 }; 1161 1130 1162 1131 class BlockNode : public StatementNode { 1163 1132 public: 1164 BlockNode(JSGlobalData*, SourceElements* children);1165 1166 Statement Vector& children() { return m_children; }1133 BlockNode(JSGlobalData*, SourceElements* = 0); 1134 1135 StatementNode* lastStatement() const; 1167 1136 1168 1137 private: … … 1171 1140 virtual bool isBlock() const { return true; } 1172 1141 1173 S tatementVector m_children;1142 SourceElements* m_statements; 1174 1143 }; 1175 1144 … … 1281 1250 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1282 1251 1283 Identifierm_ident;1252 const Identifier& m_ident; 1284 1253 ExpressionNode* m_init; 1285 1254 ExpressionNode* m_lexpr; … … 1297 1266 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1298 1267 1299 Identifierm_ident;1268 const Identifier& m_ident; 1300 1269 }; 1301 1270 … … 1308 1277 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1309 1278 1310 Identifierm_ident;1279 const Identifier& m_ident; 1311 1280 }; 1312 1281 … … 1343 1312 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1344 1313 1345 Identifierm_name;1314 const Identifier& m_name; 1346 1315 StatementNode* m_statement; 1347 1316 }; … … 1362 1331 1363 1332 private: 1364 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst= 0);1333 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); 1365 1334 1366 1335 StatementNode* m_tryBlock; 1367 Identifierm_exceptionIdent;1336 const Identifier& m_exceptionIdent; 1368 1337 StatementNode* m_catchBlock; 1369 1338 StatementNode* m_finallyBlock; … … 1371 1340 }; 1372 1341 1373 class ParameterNode : public ParserArena Deletable {1342 class ParameterNode : public ParserArenaFreeable { 1374 1343 public: 1375 1344 ParameterNode(JSGlobalData*, const Identifier&); … … 1380 1349 1381 1350 private: 1382 Identifierm_ident;1351 const Identifier& m_ident; 1383 1352 ParameterNode* m_next; 1384 1353 }; … … 1394 1363 FunctionStack m_functionStack; 1395 1364 int m_numConstants; 1396 S tatementVector m_children;1365 SourceElements* m_statements; 1397 1366 }; 1398 1367 … … 1404 1373 ScopeNode(JSGlobalData*); 1405 1374 ScopeNode(JSGlobalData*, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, CodeFeatures, int numConstants); 1375 1376 using ParserArenaRefCounted::operator new; 1406 1377 1407 1378 void adoptData(std::auto_ptr<ScopeNodeData> data) … … 1430 1401 FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } 1431 1402 1432 StatementVector& children() { ASSERT(m_data); return m_data->m_children; }1433 1434 1403 int neededConstants() 1435 1404 { … … 1440 1409 } 1441 1410 1411 StatementNode* singleStatement() const; 1412 1413 void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination); 1414 1442 1415 protected: 1443 1416 void setSource(const SourceCode& source) { m_source = source; } … … 1488 1461 const Identifier& ident() { return m_ident; } 1489 1462 1490 void reparseDataIfNecessary(ScopeChainNode* scopeChainNode);1463 void reparseDataIfNecessary(ScopeChainNode*); 1491 1464 1492 1465 private: … … 1524 1497 }; 1525 1498 1526 class CaseClauseNode : public ParserArenaDeletable { 1527 public: 1528 CaseClauseNode(JSGlobalData*, ExpressionNode*); 1529 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*); 1499 class CaseClauseNode : public ParserArenaFreeable { 1500 public: 1501 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements* = 0); 1530 1502 1531 1503 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 { 1504 1505 void emitBytecode(BytecodeGenerator&, RegisterID* destination); 1506 1507 private: 1508 ExpressionNode* m_expr; 1509 SourceElements* m_statements; 1510 }; 1511 1512 class ClauseListNode : public ParserArenaFreeable { 1540 1513 public: 1541 1514 ClauseListNode(JSGlobalData*, CaseClauseNode*); … … 1550 1523 }; 1551 1524 1552 class CaseBlockNode : public ParserArena Deletable {1525 class CaseBlockNode : public ParserArenaFreeable { 1553 1526 public: 1554 1527 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); 1555 1528 1556 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* d st = 0);1529 RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination); 1557 1530 1558 1531 private:
Note:
See TracChangeset
for help on using the changeset viewer.