1 | // -*- c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2001 Harri Porten ([email protected])
|
---|
5 | * Copyright (C) 2001 Peter Kelly ([email protected])
|
---|
6 | * Copyright (C) 2003, 2006, 2007 Apple Inc.
|
---|
7 | *
|
---|
8 | * This library is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU Library General Public
|
---|
10 | * License as published by the Free Software Foundation; either
|
---|
11 | * version 2 of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This library is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | * Library General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU Library General Public License
|
---|
19 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
21 | * Boston, MA 02110-1301, USA.
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 | #ifndef Parser_h
|
---|
26 | #define Parser_h
|
---|
27 |
|
---|
28 | #include "nodes.h"
|
---|
29 | #include "SourceProvider.h"
|
---|
30 | #include <wtf/Forward.h>
|
---|
31 | #include <wtf/Noncopyable.h>
|
---|
32 | #include <wtf/OwnPtr.h>
|
---|
33 | #include <wtf/RefPtr.h>
|
---|
34 |
|
---|
35 | namespace KJS {
|
---|
36 |
|
---|
37 | class FunctionBodyNode;
|
---|
38 | class ProgramNode;
|
---|
39 | class UString;
|
---|
40 |
|
---|
41 | template <typename T> struct ParserRefCountedData : ParserRefCounted {
|
---|
42 | ParserRefCountedData(JSGlobalData* globalData)
|
---|
43 | : ParserRefCounted(globalData)
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | T data;
|
---|
48 | };
|
---|
49 |
|
---|
50 | class Parser : Noncopyable {
|
---|
51 | public:
|
---|
52 | template <class ParsedNode>
|
---|
53 | PassRefPtr<ParsedNode> parse(ExecState*, const UString& sourceURL, int startingLineNumber,
|
---|
54 | PassRefPtr<SourceProvider> source,
|
---|
55 | int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
|
---|
56 |
|
---|
57 | UString sourceURL() const { return m_sourceURL; }
|
---|
58 | int sourceId() const { return m_sourceId; }
|
---|
59 |
|
---|
60 | void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
|
---|
61 | ParserRefCountedData<DeclarationStacks::FunctionStack>*, bool usesEval, bool needsClosure, int lastLine);
|
---|
62 |
|
---|
63 | private:
|
---|
64 | friend struct JSGlobalData;
|
---|
65 | Parser();
|
---|
66 |
|
---|
67 | void parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
|
---|
68 | int* sourceId, int* errLine, UString* errMsg);
|
---|
69 |
|
---|
70 | UString m_sourceURL;
|
---|
71 | int m_sourceId;
|
---|
72 | RefPtr<SourceElements> m_sourceElements;
|
---|
73 | RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
|
---|
74 | RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
|
---|
75 | bool m_usesEval;
|
---|
76 | bool m_needsClosure;
|
---|
77 | int m_lastLine;
|
---|
78 | };
|
---|
79 |
|
---|
80 | template <class ParsedNode>
|
---|
81 | PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber,
|
---|
82 | PassRefPtr<SourceProvider> source,
|
---|
83 | int* sourceId, int* errLine, UString* errMsg)
|
---|
84 | {
|
---|
85 | m_sourceURL = sourceURL;
|
---|
86 | parse(exec, sourceURL, startingLineNumber, source, sourceId, errLine, errMsg);
|
---|
87 | if (!m_sourceElements) {
|
---|
88 | m_sourceURL = UString();
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 | RefPtr<ParsedNode> node = ParsedNode::create(&exec->globalData(),
|
---|
92 | m_sourceElements.release().get(),
|
---|
93 | m_varDeclarations ? &m_varDeclarations->data : 0,
|
---|
94 | m_funcDeclarations ? &m_funcDeclarations->data : 0,
|
---|
95 | m_usesEval,
|
---|
96 | m_needsClosure);
|
---|
97 | m_varDeclarations = 0;
|
---|
98 | m_funcDeclarations = 0;
|
---|
99 | m_sourceURL = UString();
|
---|
100 | node->setLoc(startingLineNumber, m_lastLine);
|
---|
101 | return node.release();
|
---|
102 | }
|
---|
103 |
|
---|
104 | } // namespace KJS
|
---|
105 |
|
---|
106 | #endif // Parser_h
|
---|