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 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 "SourceProvider.h"
|
---|
27 | #include "nodes.h"
|
---|
28 | #include <wtf/Forward.h>
|
---|
29 | #include <wtf/Noncopyable.h>
|
---|
30 | #include <wtf/OwnPtr.h>
|
---|
31 | #include <wtf/RefPtr.h>
|
---|
32 |
|
---|
33 | namespace JSC {
|
---|
34 |
|
---|
35 | class FunctionBodyNode;
|
---|
36 | class ProgramNode;
|
---|
37 | class UString;
|
---|
38 |
|
---|
39 | template <typename T>
|
---|
40 | struct ParserRefCountedData : ParserRefCounted {
|
---|
41 | ParserRefCountedData(JSGlobalData* globalData)
|
---|
42 | : ParserRefCounted(globalData)
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 | T data;
|
---|
47 | };
|
---|
48 |
|
---|
49 | class Parser : Noncopyable {
|
---|
50 | public:
|
---|
51 | template <class ParsedNode> PassRefPtr<ParsedNode> parse(ExecState*, PassRefPtr<SourceProvider>, int* errLine = 0, UString* errMsg = 0);
|
---|
52 | template <class ParsedNode> PassRefPtr<ParsedNode> parse(ExecState*, const SourceCode&, int* errLine = 0, UString* errMsg = 0);
|
---|
53 |
|
---|
54 | void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
|
---|
55 | ParserRefCountedData<DeclarationStacks::FunctionStack>*, bool usesEval, bool needsClosure, bool usesArguments, int lastLine, int numConstants);
|
---|
56 |
|
---|
57 | private:
|
---|
58 | friend class JSGlobalData;
|
---|
59 |
|
---|
60 | void parse(ExecState*, int* errLine, UString* errMsg);
|
---|
61 |
|
---|
62 | const SourceCode* m_source;
|
---|
63 | RefPtr<SourceElements> m_sourceElements;
|
---|
64 | RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
|
---|
65 | RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
|
---|
66 | bool m_usesEval;
|
---|
67 | bool m_needsClosure;
|
---|
68 | bool m_usesArguments;
|
---|
69 | int m_lastLine;
|
---|
70 | int m_numConstants;
|
---|
71 | };
|
---|
72 |
|
---|
73 | template <class ParsedNode> PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const SourceCode& source, int* errLine, UString* errMsg)
|
---|
74 | {
|
---|
75 | m_source = &source;
|
---|
76 | parse(exec, errLine, errMsg);
|
---|
77 | RefPtr<ParsedNode> result;
|
---|
78 | if (m_sourceElements) {
|
---|
79 | result = ParsedNode::create(&exec->globalData(),
|
---|
80 | m_sourceElements.get(),
|
---|
81 | m_varDeclarations ? &m_varDeclarations->data : 0,
|
---|
82 | m_funcDeclarations ? &m_funcDeclarations->data : 0,
|
---|
83 | *m_source,
|
---|
84 | m_usesEval,
|
---|
85 | m_needsClosure,
|
---|
86 | m_usesArguments,
|
---|
87 | m_numConstants);
|
---|
88 | result->setLoc(m_source->firstLine(), m_lastLine);
|
---|
89 | }
|
---|
90 |
|
---|
91 | m_source = 0;
|
---|
92 | m_sourceElements = 0;
|
---|
93 | m_varDeclarations = 0;
|
---|
94 | m_funcDeclarations = 0;
|
---|
95 | return result.release();
|
---|
96 | }
|
---|
97 |
|
---|
98 | } // namespace JSC
|
---|
99 |
|
---|
100 | #endif // Parser_h
|
---|