#ifndef Parser_h
#define Parser_h
-#include "SourceProvider.h"
#include "Debugger.h"
#include "Nodes.h"
+#include "SourceProvider.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
class ProgramNode;
class UString;
- template <typename T>
- struct ParserRefCountedData : ParserRefCounted {
- ParserRefCountedData(JSGlobalData* globalData)
- : ParserRefCounted(globalData)
- {
- }
-
- T data;
- };
+ template <typename T> struct ParserArenaData : ParserArenaDeletable { T data; };
class Parser : Noncopyable {
public:
template <class ParsedNode> PassRefPtr<ParsedNode> reparse(JSGlobalData*, ParsedNode*);
void reparseInPlace(JSGlobalData*, FunctionBodyNode*);
- void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
- ParserRefCountedData<DeclarationStacks::FunctionStack>*, CodeFeatures features, int lastLine, int numConstants);
+ void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*,
+ ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures features, int lastLine, int numConstants);
+
+ ParserArena& arena() { return m_arena; }
private:
void parse(JSGlobalData*, int* errLine, UString* errMsg);
+ ParserArena m_arena;
const SourceCode* m_source;
- RefPtr<SourceElements> m_sourceElements;
- RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
- RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
+ SourceElements* m_sourceElements;
+ ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations;
+ ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
CodeFeatures m_features;
int m_lastLine;
int m_numConstants;
RefPtr<ParsedNode> result;
if (m_sourceElements) {
result = ParsedNode::create(&exec->globalData(),
- m_sourceElements.get(),
+ m_sourceElements,
m_varDeclarations ? &m_varDeclarations->data : 0,
m_funcDeclarations ? &m_funcDeclarations->data : 0,
*m_source,
result->setLoc(m_source->firstLine(), m_lastLine);
}
+ m_arena.reset();
+
m_source = 0;
- m_sourceElements = 0;
m_varDeclarations = 0;
m_funcDeclarations = 0;
RefPtr<ParsedNode> result;
if (m_sourceElements) {
result = ParsedNode::create(globalData,
- m_sourceElements.get(),
+ m_sourceElements,
m_varDeclarations ? &m_varDeclarations->data : 0,
m_funcDeclarations ? &m_funcDeclarations->data : 0,
*m_source,
result->setLoc(m_source->firstLine(), m_lastLine);
}
+ m_arena.reset();
+
m_source = 0;
- m_sourceElements = 0;
m_varDeclarations = 0;
m_funcDeclarations = 0;