Changeset 47571 in webkit for trunk/JavaScriptCore/parser
- Timestamp:
- Aug 20, 2009, 7:24:49 AM (16 years ago)
- Location:
- trunk/JavaScriptCore/parser
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Grammar.y
r47264 r47571 126 126 } 127 127 128 static void appendToVarDeclarationList(JSGlobalData* globalData, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)128 static inline void appendToVarDeclarationList(JSGlobalData* globalData, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs) 129 129 { 130 130 if (!varDecls) 131 131 varDecls = new (globalData) ParserArenaData<DeclarationStacks::VarStack>; 132 132 133 varDecls->data.append(make_pair(ident, attrs)); 134 133 varDecls->data.append(make_pair(&ident, attrs)); 135 134 } 136 135 … … 148 147 int intValue; 149 148 double doubleValue; 150 Identifier*ident;149 const Identifier* ident; 151 150 152 151 // expression subtrees -
trunk/JavaScriptCore/parser/Lexer.cpp
r47236 r47571 142 142 } 143 143 144 void Lexer::setCode(const SourceCode& source) 145 { 144 void Lexer::setCode(const SourceCode& source, ParserArena& arena) 145 { 146 m_arena = &arena.identifierArena(); 147 146 148 m_lineNumber = source.firstLine(); 147 149 m_delimited = false; … … 205 207 } 206 208 207 ALWAYS_INLINE Identifier* Lexer::makeIdentifier(const UChar* characters, size_t length) 208 { 209 m_identifiers.append(Identifier(m_globalData, characters, length)); 210 return &m_identifiers.last(); 209 ALWAYS_INLINE const Identifier* Lexer::makeIdentifier(const UChar* characters, size_t length) 210 { 211 return &m_arena->makeIdentifier(m_globalData, characters, length); 211 212 } 212 213 … … 1012 1013 void Lexer::clear() 1013 1014 { 1014 m_ identifiers.clear();1015 m_arena = 0; 1015 1016 m_codeWithoutBOMs.clear(); 1016 1017 -
trunk/JavaScriptCore/parser/Lexer.h
r47236 r47571 24 24 25 25 #include "Lookup.h" 26 #include "ParserArena.h" 26 27 #include "SourceCode.h" 27 28 #include <wtf/ASCIICType.h> … … 43 44 44 45 // Functions to set up parsing. 45 void setCode(const SourceCode& );46 void setCode(const SourceCode&, ParserArena&); 46 47 void setIsReparsing() { m_isReparsing = true; } 47 48 … … 79 80 const UChar* currentCharacter() const; 80 81 81 JSC::Identifier* makeIdentifier(const UChar* buffer, size_t length);82 const Identifier* makeIdentifier(const UChar* characters, size_t length); 82 83 83 84 bool lastTokenWasRestrKeyword() const; 84 85 85 86 static const size_t initialReadBufferCapacity = 32; 86 static const size_t initialIdentifierTableCapacity = 64;87 87 88 88 int m_lineNumber; … … 108 108 int m_next3; 109 109 110 WTF::SegmentedVector<JSC::Identifier, initialIdentifierTableCapacity> m_identifiers;110 IdentifierArena* m_arena; 111 111 112 112 JSGlobalData* m_globalData; -
trunk/JavaScriptCore/parser/NodeConstructors.h
r47259 r47571 28 28 namespace JSC { 29 29 30 inline void* ParserArenaFreeable::operator new(size_t size, JSGlobalData* globalData) 31 { 32 return globalData->parser->arena().allocateFreeable(size); 33 } 34 30 35 inline void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData) 31 36 { 32 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 33 globalData->parser->arena().deleteWithArena(deletable); 34 return deletable; 35 } 36 37 inline void* ParserArenaDeletable::operator new(size_t size) 38 { 39 return fastMalloc(size); 40 } 41 42 inline void ParserArenaDeletable::operator delete(void* p) 43 { 44 fastFree(p); 37 return globalData->parser->arena().allocateDeletable(size); 45 38 } 46 39 … … 78 71 } 79 72 80 inline NumberNode::NumberNode(JSGlobalData* globalData, double v )73 inline NumberNode::NumberNode(JSGlobalData* globalData, double value) 81 74 : ExpressionNode(globalData, ResultType::numberType()) 82 , m_ double(v)83 { 84 } 85 86 inline StringNode::StringNode(JSGlobalData* globalData, const Identifier& v )75 , m_value(value) 76 { 77 } 78 79 inline StringNode::StringNode(JSGlobalData* globalData, const Identifier& value) 87 80 : ExpressionNode(globalData, ResultType::stringType()) 88 , m_value(v )81 , m_value(value) 89 82 { 90 83 } … … 156 149 157 150 inline PropertyNode::PropertyNode(JSGlobalData* globalData, double name, ExpressionNode* assign, Type type) 158 : m_name( Identifier(globalData, UString::from(name)))151 : m_name(globalData->parser->arena().identifierArena().makeNumericIdentifier(globalData, name)) 159 152 , m_assign(assign) 160 153 , m_type(type) … … 749 742 inline ContinueNode::ContinueNode(JSGlobalData* globalData) 750 743 : StatementNode(globalData) 744 , m_ident(globalData->propertyNames->nullIdentifier) 751 745 { 752 746 } … … 760 754 inline BreakNode::BreakNode(JSGlobalData* globalData) 761 755 : StatementNode(globalData) 756 , m_ident(globalData->propertyNames->nullIdentifier) 762 757 { 763 758 } … … 834 829 } 835 830 836 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr )831 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* statements) 837 832 : m_expr(expr) 838 { 839 } 840 841 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* children) 842 : m_expr(expr) 843 { 844 if (children) 845 children->releaseContentsIntoVector(m_children); 833 , m_statements(statements) 834 { 846 835 } 847 836 … … 881 870 } 882 871 883 inline BlockNode::BlockNode(JSGlobalData* globalData, SourceElements* children) 884 : StatementNode(globalData) 885 { 886 if (children) 887 children->releaseContentsIntoVector(m_children); 872 inline BlockNode::BlockNode(JSGlobalData* globalData, SourceElements* statements) 873 : StatementNode(globalData) 874 , m_statements(statements) 875 { 888 876 } 889 877 890 878 inline ForInNode::ForInNode(JSGlobalData* globalData, ExpressionNode* l, ExpressionNode* expr, StatementNode* statement) 891 879 : StatementNode(globalData) 880 , m_ident(globalData->propertyNames->nullIdentifier) 892 881 , m_init(0) 893 882 , m_lexpr(l) -
trunk/JavaScriptCore/parser/Nodes.cpp
r47412 r47571 50 50 namespace JSC { 51 51 52 static void substitute(UString& string, const UString& substring); 52 /* 53 Details of the emitBytecode function. 54 55 Return value: The register holding the production's value. 56 dst: An optional parameter specifying the most efficient destination at 57 which to store the production's value. The callee must honor dst. 58 59 The dst argument provides for a crude form of copy propagation. For example, 60 61 x = 1 62 63 becomes 64 65 load r[x], 1 66 67 instead of 68 69 load r0, 1 70 mov r[x], r0 71 72 because the assignment node, "x =", passes r[x] as dst to the number node, "1". 73 */ 53 74 54 75 // ------------------------------ ThrowableExpressionData -------------------------------- … … 64 85 } 65 86 66 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType e, const char* msg)87 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* message) 67 88 { 68 89 generator.emitExpressionInfo(divot(), startOffset(), endOffset()); 69 RegisterID* exception = generator.emitNewError(generator.newTemporary(), e, jsString(generator.globalData(), msg));90 RegisterID* exception = generator.emitNewError(generator.newTemporary(), type, jsString(generator.globalData(), message)); 70 91 generator.emitThrow(exception); 71 92 return exception; 72 93 } 73 94 74 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType e, const char* msg, const Identifier& label)75 { 76 UString message = m sg;77 substitute(message, label .ustring());95 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* messageTemplate, const UString& label) 96 { 97 UString message = messageTemplate; 98 substitute(message, label); 78 99 generator.emitExpressionInfo(divot(), startOffset(), endOffset()); 79 RegisterID* exception = generator.emitNewError(generator.newTemporary(), e, jsString(generator.globalData(), message));100 RegisterID* exception = generator.emitNewError(generator.newTemporary(), type, jsString(generator.globalData(), message)); 80 101 generator.emitThrow(exception); 81 102 return exception; 103 } 104 105 inline RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* messageTemplate, const Identifier& label) 106 { 107 return emitThrowError(generator, type, messageTemplate, label.ustring()); 82 108 } 83 109 … … 99 125 } 100 126 127 inline StatementNode* SourceElements::singleStatement() const 128 { 129 size_t size = m_statements.size(); 130 return size == 1 ? m_statements[0] : 0; 131 } 132 133 inline StatementNode* SourceElements::lastStatement() const 134 { 135 size_t size = m_statements.size(); 136 return size ? m_statements[size - 1] : 0; 137 } 138 101 139 // ------------------------------ NullNode ------------------------------------- 102 140 … … 123 161 if (dst == generator.ignoredResult()) 124 162 return 0; 125 return generator.emitLoad(dst, m_ double);163 return generator.emitLoad(dst, m_value); 126 164 } 127 165 … … 141 179 RefPtr<RegExp> regExp = RegExp::create(generator.globalData(), m_pattern.ustring(), m_flags.ustring()); 142 180 if (!regExp->isValid()) 143 return emitThrowError(generator, SyntaxError, ("Invalid regular expression: " + UString(regExp->errorMessage())).UTF8String().c_str());181 return emitThrowError(generator, SyntaxError, "Invalid regular expression: %s", regExp->errorMessage()); 144 182 if (dst == generator.ignoredResult()) 145 183 return 0; … … 597 635 RegisterID* PostfixErrorNode::emitBytecode(BytecodeGenerator& generator, RegisterID*) 598 636 { 599 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus ? "Postfix ++ operator applied to value that is not a reference." : "Postfix -- operator applied to value that is not a reference."); 637 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus 638 ? "Postfix ++ operator applied to value that is not a reference." 639 : "Postfix -- operator applied to value that is not a reference."); 600 640 } 601 641 … … 759 799 RegisterID* PrefixErrorNode::emitBytecode(BytecodeGenerator& generator, RegisterID*) 760 800 { 761 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus ? "Prefix ++ operator applied to value that is not a reference." : "Prefix -- operator applied to value that is not a reference."); 801 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus 802 ? "Prefix ++ operator applied to value that is not a reference." 803 : "Prefix -- operator applied to value that is not a reference."); 762 804 } 763 805 … … 1237 1279 } 1238 1280 1239 // ------------------------------ Helper functions for handling Vectors of StatementNode-------------------------------1240 1241 static inline void statementListEmitCode(const StatementVector& statements,BytecodeGenerator& generator, RegisterID* dst)1242 { 1243 size_t size = statements.size();1281 // ------------------------------ SourceElements ------------------------------- 1282 1283 inline void SourceElements::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1284 { 1285 size_t size = m_statements.size(); 1244 1286 for (size_t i = 0; i < size; ++i) 1245 generator.emitNode(dst, statements[i]);1287 generator.emitNode(dst, m_statements[i]); 1246 1288 } 1247 1289 1248 1290 // ------------------------------ BlockNode ------------------------------------ 1249 1291 1292 inline StatementNode* BlockNode::lastStatement() const 1293 { 1294 return m_statements ? m_statements->lastStatement() : 0; 1295 } 1296 1250 1297 RegisterID* BlockNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1251 1298 { 1252 statementListEmitCode(m_children, generator, dst); 1299 if (m_statements) 1300 m_statements->emitBytecode(generator, dst); 1253 1301 return 0; 1254 1302 } … … 1550 1598 generator.emitPopScope(); 1551 1599 return result; 1600 } 1601 1602 // ------------------------------ CaseClauseNode -------------------------------- 1603 1604 inline void CaseClauseNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1605 { 1606 if (m_statements) 1607 m_statements->emitBytecode(generator, dst); 1552 1608 } 1553 1609 … … 1671 1727 for (ClauseListNode* list = m_list1; list; list = list->getNext()) { 1672 1728 generator.emitLabel(labelVector[i++].get()); 1673 statementListEmitCode(list->getClause()->children(),generator, dst);1729 list->getClause()->emitBytecode(generator, dst); 1674 1730 } 1675 1731 1676 1732 if (m_defaultClause) { 1677 1733 generator.emitLabel(defaultLabel.get()); 1678 statementListEmitCode(m_defaultClause->children(),generator, dst);1734 m_defaultClause->emitBytecode(generator, dst); 1679 1735 } 1680 1736 1681 1737 for (ClauseListNode* list = m_list2; list; list = list->getNext()) { 1682 1738 generator.emitLabel(labelVector[i++].get()); 1683 statementListEmitCode(list->getClause()->children(),generator, dst);1739 list->getClause()->emitBytecode(generator, dst); 1684 1740 } 1685 1741 if (!m_defaultClause) … … 1813 1869 // -----------------------------ScopeNodeData --------------------------- 1814 1870 1815 ScopeNodeData::ScopeNodeData(ParserArena& arena, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, int numConstants)1871 ScopeNodeData::ScopeNodeData(ParserArena& arena, SourceElements* statements, VarStack* varStack, FunctionStack* funcStack, int numConstants) 1816 1872 : m_numConstants(numConstants) 1873 , m_statements(statements) 1817 1874 { 1818 1875 m_arena.swap(arena); … … 1821 1878 if (funcStack) 1822 1879 m_functionStack.swap(*funcStack); 1823 if (children)1824 children->releaseContentsIntoVector(m_children);1825 1880 } 1826 1881 … … 1851 1906 } 1852 1907 1908 inline void ScopeNode::emitStatementsBytecode(BytecodeGenerator& generator, RegisterID* dst) 1909 { 1910 if (m_data->m_statements) 1911 m_data->m_statements->emitBytecode(generator, dst); 1912 } 1913 1914 StatementNode* ScopeNode::singleStatement() const 1915 { 1916 return m_data->m_statements ? m_data->m_statements->singleStatement() : 0; 1917 } 1918 1853 1919 // ------------------------------ ProgramNode ----------------------------- 1854 1920 … … 1875 1941 RefPtr<RegisterID> dstRegister = generator.newTemporary(); 1876 1942 generator.emitLoad(dstRegister.get(), jsUndefined()); 1877 statementListEmitCode(children(),generator, dstRegister.get());1943 emitStatementsBytecode(generator, dstRegister.get()); 1878 1944 1879 1945 generator.emitDebugHook(DidExecuteProgram, firstLine(), lastLine()); … … 1906 1972 RefPtr<RegisterID> dstRegister = generator.newTemporary(); 1907 1973 generator.emitLoad(dstRegister.get(), jsUndefined()); 1908 statementListEmitCode(children(),generator, dstRegister.get());1974 emitStatementsBytecode(generator, dstRegister.get()); 1909 1975 1910 1976 generator.emitDebugHook(DidExecuteProgram, firstLine(), lastLine()); … … 1983 2049 { 1984 2050 generator.emitDebugHook(DidEnterCallFrame, firstLine(), lastLine()); 1985 statementListEmitCode(children(), generator, generator.ignoredResult()); 1986 if (children().size() && children().last()->isBlock()) { 1987 BlockNode* blockNode = static_cast<BlockNode*>(children().last()); 1988 if (blockNode->children().size() && blockNode->children().last()->isReturnNode()) 2051 emitStatementsBytecode(generator, generator.ignoredResult()); 2052 StatementNode* singleStatement = this->singleStatement(); 2053 if (singleStatement && singleStatement->isBlock()) { 2054 StatementNode* lastStatementInBlock = static_cast<BlockNode*>(singleStatement)->lastStatement(); 2055 if (lastStatementInBlock && lastStatementInBlock->isReturnNode()) 1989 2056 return 0; 1990 2057 } -
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: -
trunk/JavaScriptCore/parser/Parser.cpp
r44224 r47571 54 54 55 55 Lexer& lexer = *globalData->lexer; 56 lexer.setCode(*m_source );56 lexer.setCode(*m_source, m_arena); 57 57 58 58 int parseError = jscyyparse(globalData); -
trunk/JavaScriptCore/parser/Parser.h
r47307 r47571 28 28 #include "JSGlobalObject.h" 29 29 #include "Nodes.h" 30 #include "ParserArena.h" 30 31 #include "SourceProvider.h" 31 32 #include <wtf/Forward.h> … … 126 127 { 127 128 RefPtr<ProgramNode> program = parse<ProgramNode>(exec, debugger, source, errLine, errMsg); 128 129 129 if (!program) 130 130 return 0; 131 131 132 StatementVector& children = program->children(); 133 if (children.size() != 1) 134 return 0; 135 136 StatementNode* exprStatement = children[0]; 132 StatementNode* exprStatement = program->singleStatement(); 137 133 ASSERT(exprStatement); 138 134 ASSERT(exprStatement->isExprStatement()); … … 146 142 return 0; 147 143 148 RefPtr<FunctionBodyNode>body = static_cast<FuncExprNode*>(funcExpr)->body();144 FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body(); 149 145 ASSERT(body); 150 return body .release();146 return body; 151 147 } 152 148 -
trunk/JavaScriptCore/parser/ParserArena.cpp
r43661 r47571 31 31 namespace JSC { 32 32 33 ParserArena::ParserArena() 34 : m_freeableMemory(0) 35 , m_freeablePoolEnd(0) 36 , m_identifierArena(new IdentifierArena) 37 { 38 } 39 40 inline void* ParserArena::freeablePool() 41 { 42 ASSERT(m_freeablePoolEnd); 43 return m_freeablePoolEnd - freeablePoolSize; 44 } 45 46 inline void ParserArena::deallocateObjects() 47 { 48 if (m_freeablePoolEnd) 49 fastFree(freeablePool()); 50 51 size_t size = m_freeablePools.size(); 52 for (size_t i = 0; i < size; ++i) 53 fastFree(m_freeablePools[i]); 54 55 size = m_deletableObjects.size(); 56 for (size_t i = 0; i < size; ++i) { 57 ParserArenaDeletable* object = m_deletableObjects[i]; 58 object->~ParserArenaDeletable(); 59 fastFree(object); 60 } 61 } 62 33 63 ParserArena::~ParserArena() 34 64 { 35 de leteAllValues(m_deletableObjects);65 deallocateObjects(); 36 66 } 37 67 … … 53 83 void ParserArena::reset() 54 84 { 55 deleteAllValues(m_deletableObjects); 56 m_deletableObjects.shrink(0); 57 m_refCountedObjects.shrink(0); 85 // Since this code path is used only when parsing fails, it's not bothering to reuse 86 // any of the memory the arena allocated. We could improve that later if we want to 87 // efficiently reuse the same arena. 88 89 deallocateObjects(); 90 91 m_freeableMemory = 0; 92 m_freeablePoolEnd = 0; 93 m_identifierArena->clear(); 94 m_freeablePools.clear(); 95 m_deletableObjects.clear(); 96 m_refCountedObjects.clear(); 97 } 98 99 void ParserArena::allocateFreeablePool() 100 { 101 if (m_freeablePoolEnd) 102 m_freeablePools.append(freeablePool()); 103 104 char* pool = static_cast<char*>(fastMalloc(freeablePoolSize)); 105 m_freeableMemory = pool; 106 m_freeablePoolEnd = pool + freeablePoolSize; 107 ASSERT(freeablePool() == pool); 108 } 109 110 bool ParserArena::isEmpty() const 111 { 112 return !m_freeablePoolEnd 113 && m_identifierArena->isEmpty() 114 && m_freeablePools.isEmpty() 115 && m_deletableObjects.isEmpty() 116 && m_refCountedObjects.isEmpty(); 58 117 } 59 118 -
trunk/JavaScriptCore/parser/ParserArena.h
r43661 r47571 27 27 #define ParserArena_h 28 28 29 #include <wtf/PassRefPtr.h> 30 #include <wtf/RefPtr.h> 31 #include <wtf/Vector.h> 29 #include "Identifier.h" 30 #include <wtf/SegmentedVector.h> 32 31 33 32 namespace JSC { … … 36 35 class ParserArenaRefCounted; 37 36 38 class ParserArena {37 class IdentifierArena { 39 38 public: 39 ALWAYS_INLINE const Identifier& makeIdentifier(JSGlobalData*, const UChar* characters, size_t length); 40 const Identifier& makeNumericIdentifier(JSGlobalData*, double number); 41 42 void clear() { m_identifiers.clear(); } 43 bool isEmpty() const { return m_identifiers.isEmpty(); } 44 45 private: 46 typedef SegmentedVector<Identifier, 64> IdentifierVector; 47 IdentifierVector m_identifiers; 48 }; 49 50 ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length) 51 { 52 m_identifiers.append(Identifier(globalData, characters, length)); 53 return m_identifiers.last(); 54 } 55 56 inline const Identifier& IdentifierArena::makeNumericIdentifier(JSGlobalData* globalData, double number) 57 { 58 m_identifiers.append(Identifier(globalData, UString::from(number))); 59 return m_identifiers.last(); 60 } 61 62 class ParserArena : Noncopyable { 63 public: 64 ParserArena(); 65 ~ParserArena(); 66 40 67 void swap(ParserArena& otherArena) 41 68 { 69 std::swap(m_freeableMemory, otherArena.m_freeableMemory); 70 std::swap(m_freeablePoolEnd, otherArena.m_freeablePoolEnd); 71 m_identifierArena.swap(otherArena.m_identifierArena); 72 m_freeablePools.swap(otherArena.m_freeablePools); 42 73 m_deletableObjects.swap(otherArena.m_deletableObjects); 43 74 m_refCountedObjects.swap(otherArena.m_refCountedObjects); 44 75 } 45 ~ParserArena();46 76 47 void deleteWithArena(ParserArenaDeletable* object) { m_deletableObjects.append(object); } 77 void* allocateFreeable(size_t size) 78 { 79 ASSERT(size); 80 ASSERT(size <= freeablePoolSize); 81 size_t alignedSize = alignSize(size); 82 ASSERT(alignedSize <= freeablePoolSize); 83 if (UNLIKELY(static_cast<size_t>(m_freeablePoolEnd - m_freeableMemory) < alignedSize)) 84 allocateFreeablePool(); 85 void* block = m_freeableMemory; 86 m_freeableMemory += alignedSize; 87 return block; 88 } 89 90 void* allocateDeletable(size_t size) 91 { 92 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 93 m_deletableObjects.append(deletable); 94 return deletable; 95 } 96 48 97 void derefWithArena(PassRefPtr<ParserArenaRefCounted> object) { m_refCountedObjects.append(object); } 49 50 98 bool contains(ParserArenaRefCounted*) const; 51 99 ParserArenaRefCounted* last() const; 52 100 void removeLast(); 53 101 54 bool isEmpty() const { return m_deletableObjects.isEmpty() && m_refCountedObjects.isEmpty(); }102 bool isEmpty() const; 55 103 void reset(); 56 104 105 IdentifierArena& identifierArena() { return *m_identifierArena; } 106 57 107 private: 108 static const size_t freeablePoolSize = 8000; 109 110 static size_t alignSize(size_t size) 111 { 112 return (size + sizeof(WTF::AllocAlignmentInteger) - 1) & ~(sizeof(WTF::AllocAlignmentInteger) - 1); 113 } 114 115 void* freeablePool(); 116 void allocateFreeablePool(); 117 void deallocateObjects(); 118 119 char* m_freeableMemory; 120 char* m_freeablePoolEnd; 121 122 OwnPtr<IdentifierArena> m_identifierArena; 123 Vector<void*> m_freeablePools; 58 124 Vector<ParserArenaDeletable*> m_deletableObjects; 59 125 Vector<RefPtr<ParserArenaRefCounted> > m_refCountedObjects;
Note:
See TracChangeset
for help on using the changeset viewer.