source: webkit/trunk/JavaScriptCore/parser/Parser.h@ 43479

Last change on this file since 43479 was 43479, checked in by Darin Adler, 16 years ago

2009-05-10 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Bug 25674: syntax tree nodes should use arena allocation
https://bugs.webkit.org/show_bug.cgi?id=25674

Part two: Remove reference counting from most nodes.

  • JavaScriptCore.xcodeproj/project.pbxproj: Added ParserArena.h and .cpp.
  • parser/Grammar.y: Replaced uses of ParserRefCountedData with uses of ParserArenaData. Took out now-nonfunctional code that tries to manually release declaration list. Changed the new calls that create FuncDeclNode and FuncExprNode so that they use the proper version of operator new for the reference-counted idiom, not the deletion idiom.
  • parser/NodeConstructors.h: (JSC::ParserArenaDeletable::operator new): Added. (JSC::ParserArenaRefCounted::ParserArenaRefCounted): Added. (JSC::Node::Node): Removed ParserRefCounted initializer. (JSC::ElementNode::ElementNode): Ditto. (JSC::PropertyNode::PropertyNode): Ditto. (JSC::ArgumentsNode::ArgumentsNode): Ditto. (JSC::SourceElements::SourceElements): Ditto. (JSC::ParameterNode::ParameterNode): Ditto. (JSC::FuncExprNode::FuncExprNode): Added ParserArenaRefCounted initializer. (JSC::FuncDeclNode::FuncDeclNode): Ditto. (JSC::CaseClauseNode::CaseClauseNode): Removed ParserRefCounted initializer. (JSC::ClauseListNode::ClauseListNode): Ditto. (JSC::CaseBlockNode::CaseBlockNode): Ditto.
  • parser/NodeInfo.h: Replaced uses of ParserRefCountedData with uses of ParserArenaData.
  • parser/Nodes.cpp: (JSC::ScopeNode::ScopeNode): Added ParserArenaRefCounted initializer. (JSC::ProgramNode::create): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. Use the arena contains function instead of the vecctor find function. (JSC::EvalNode::create): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. Use the arena reset function instead of the vector shrink function. (JSC::FunctionBodyNode::createNativeThunk): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. (JSC::FunctionBodyNode::create): More of the same.
  • parser/Nodes.h: Added ParserArenaDeletable and ParserArenaRefCounted to replace ParserRefCounted. Fixed inheritance so only the classes that need reference counting inherit from ParserArenaRefCounted.
  • parser/Parser.cpp: (JSC::Parser::parse): Set m_sourceElements to 0 since it now starts uninitialized. Just set it to 0 again in the failure case, since it's now just a raw pointer, not an owning one. (JSC::Parser::reparseInPlace): Removed now-unneeded get() function. (JSC::Parser::didFinishParsing): Replaced uses of ParserRefCountedData with uses of ParserArenaData.
  • parser/Parser.h: Less RefPtr, more arena.
  • parser/ParserArena.cpp: Added.
  • parser/ParserArena.h: Added.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::~JSGlobalData): Removed arena-related code, since it's now in the Parser. (JSC::JSGlobalData::createLeaked): Removed unneeded #ifndef. (JSC::JSGlobalData::createNativeThunk): Tweaked #if a bit.
  • runtime/JSGlobalData.h: Removed parserArena, which is now in Parser.
  • wtf/RefCounted.h: Added deletionHasBegun function, for use in assertions to catch deletion not done by the deref function.
  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef Parser_h
24#define Parser_h
25
26#include "Debugger.h"
27#include "Nodes.h"
28#include "SourceProvider.h"
29#include <wtf/Forward.h>
30#include <wtf/Noncopyable.h>
31#include <wtf/OwnPtr.h>
32#include <wtf/RefPtr.h>
33
34namespace JSC {
35
36 class FunctionBodyNode;
37 class ProgramNode;
38 class UString;
39
40 template <typename T> struct ParserArenaData : ParserArenaDeletable { T data; };
41
42 class Parser : Noncopyable {
43 public:
44 template <class ParsedNode> PassRefPtr<ParsedNode> parse(ExecState*, Debugger*, const SourceCode&, int* errLine = 0, UString* errMsg = 0);
45 template <class ParsedNode> PassRefPtr<ParsedNode> reparse(JSGlobalData*, ParsedNode*);
46 void reparseInPlace(JSGlobalData*, FunctionBodyNode*);
47
48 void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*,
49 ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures features, int lastLine, int numConstants);
50
51 ParserArena& arena() { return m_arena; }
52
53 private:
54 void parse(JSGlobalData*, int* errLine, UString* errMsg);
55
56 ParserArena m_arena;
57 const SourceCode* m_source;
58 SourceElements* m_sourceElements;
59 ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations;
60 ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
61 CodeFeatures m_features;
62 int m_lastLine;
63 int m_numConstants;
64 };
65
66 template <class ParsedNode> PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, Debugger* debugger, const SourceCode& source, int* errLine, UString* errMsg)
67 {
68 m_source = &source;
69 parse(&exec->globalData(), errLine, errMsg);
70 RefPtr<ParsedNode> result;
71 if (m_sourceElements) {
72 result = ParsedNode::create(&exec->globalData(),
73 m_sourceElements,
74 m_varDeclarations ? &m_varDeclarations->data : 0,
75 m_funcDeclarations ? &m_funcDeclarations->data : 0,
76 *m_source,
77 m_features,
78 m_numConstants);
79 result->setLoc(m_source->firstLine(), m_lastLine);
80 }
81
82 m_arena.reset();
83
84 m_source = 0;
85 m_varDeclarations = 0;
86 m_funcDeclarations = 0;
87
88 if (debugger)
89 debugger->sourceParsed(exec, source, *errLine, *errMsg);
90 return result.release();
91 }
92
93 template <class ParsedNode> PassRefPtr<ParsedNode> Parser::reparse(JSGlobalData* globalData, ParsedNode* oldParsedNode)
94 {
95 m_source = &oldParsedNode->source();
96 parse(globalData, 0, 0);
97 RefPtr<ParsedNode> result;
98 if (m_sourceElements) {
99 result = ParsedNode::create(globalData,
100 m_sourceElements,
101 m_varDeclarations ? &m_varDeclarations->data : 0,
102 m_funcDeclarations ? &m_funcDeclarations->data : 0,
103 *m_source,
104 oldParsedNode->features(),
105 m_numConstants);
106 result->setLoc(m_source->firstLine(), m_lastLine);
107 }
108
109 m_arena.reset();
110
111 m_source = 0;
112 m_varDeclarations = 0;
113 m_funcDeclarations = 0;
114
115 return result.release();
116 }
117
118} // namespace JSC
119
120#endif // Parser_h
Note: See TracBrowser for help on using the repository browser.