source: webkit/trunk/JavaScriptCore/kjs/Parser.cpp@ 33979

Last change on this file since 33979 was 33979, checked in by [email protected], 17 years ago

Merge squirrelfish branch into trunk.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
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#include "config.h"
26#include "Parser.h"
27#include "debugger.h"
28
29#include "lexer.h"
30#include <wtf/HashSet.h>
31#if USE(MULTIPLE_THREADS)
32#include <wtf/ThreadSpecific.h>
33using namespace WTF;
34#endif
35#include <wtf/Vector.h>
36
37extern int kjsyyparse(void*);
38
39namespace KJS {
40
41Parser::Parser()
42 : m_sourceId(0)
43{
44}
45
46void Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber,
47 PassRefPtr<SourceProvider> prpSource,
48 int* sourceId, int* errLine, UString* errMsg)
49{
50 ASSERT(!m_sourceElements);
51
52 int defaultSourceId;
53 int defaultErrLine;
54 UString defaultErrMsg;
55
56 RefPtr<SourceProvider> source = prpSource;
57
58 if (!sourceId)
59 sourceId = &defaultSourceId;
60 if (!errLine)
61 errLine = &defaultErrLine;
62 if (!errMsg)
63 errMsg = &defaultErrMsg;
64
65 *errLine = -1;
66 *errMsg = 0;
67
68 Lexer& lexer = KJS::lexer();
69
70 lexer.setCode(startingLineNumber, source);
71 *sourceId = ++m_sourceId;
72
73 int parseError = kjsyyparse(&lexer);
74 bool lexError = lexer.sawError();
75 lexer.clear();
76
77 ParserRefCounted::deleteNewObjects();
78
79 if (parseError || lexError) {
80 *errLine = lexer.lineNo();
81 *errMsg = "Parse error";
82 m_sourceElements.clear();
83 }
84
85 if (Debugger* debugger = exec->dynamicGlobalObject()->debugger())
86 debugger->sourceParsed(exec, *sourceId, sourceURL, *source, startingLineNumber, *errLine, *errMsg);
87}
88
89void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
90 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, bool usesEval, bool needsClosure, int lastLine)
91{
92 m_sourceElements = sourceElements;
93 m_varDeclarations = varStack;
94 m_funcDeclarations = funcStack;
95 m_usesEval = usesEval;
96 m_needsClosure = needsClosure;
97 m_lastLine = lastLine;
98}
99
100Parser& parser()
101{
102#if USE(MULTIPLE_THREADS)
103 static ThreadSpecific<Parser> staticParser;
104 return *staticParser;
105#else
106 static Parser staticParser;
107 return staticParser;
108#endif
109}
110
111} // namespace KJS
Note: See TracBrowser for help on using the repository browser.