source: webkit/trunk/JavaScriptCore/kjs/Parser.h@ 34424

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

Reviewed by Darin.

Combine per-thread objects into one, to make it easier to support legacy clients (for
which they shouldn't be really per-thread).

No change on SunSpider total.

  • kjs/JSGlobalData.cpp: Added. (KJS::JSGlobalData::JSGlobalData): (KJS::JSGlobalData::~JSGlobalData): (KJS::JSGlobalData::threadInstance):
  • kjs/JSGlobalData.h: Added. This class encapsulates all data that should be per-thread (or shared between legacy clients). It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.
  • kjs/identifier.h: (KJS::Identifier::Identifier): Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually, all of them should, but this will be a separate patch.
  • kjs/identifier.cpp: (KJS::IdentifierTable::literalTable): (KJS::createIdentifierTable): (KJS::deleteIdentifierTable): (KJS::Identifier::add): (KJS::Identifier::addSlowCase): Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.
  • kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::EvalFunctionCallNode::emitCode): (KJS::ScopeNode::ScopeNode): Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a temporary measure, they will need to use JSGlobalData explicitly.
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::callEval):
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::CommonIdentifiers):
  • kjs/CommonIdentifiers.h:
  • kjs/DebuggerCallFrame.cpp: (KJS::DebuggerCallFrame::evaluate):
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState):
  • kjs/ExecState.h: (KJS::ExecState::globalData): (KJS::ExecState::identifierTable): (KJS::ExecState::propertyNames): (KJS::ExecState::emptyList): (KJS::ExecState::lexer): (KJS::ExecState::parser): (KJS::ExecState::arrayTable): (KJS::ExecState::dateTable): (KJS::ExecState::mathTable): (KJS::ExecState::numberTable): (KJS::ExecState::RegExpImpTable): (KJS::ExecState::RegExpObjectImpTable): (KJS::ExecState::stringTable):
  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce):
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::init):
  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData): (KJS::JSGlobalObject::head): (KJS::JSGlobalObject::globalData):
  • kjs/Parser.cpp: (KJS::Parser::parse):
  • kjs/Parser.h:
  • kjs/function.cpp: (KJS::FunctionImp::getParameterName): (KJS::IndexToNameMap::unMap): (KJS::globalFuncEval):
  • kjs/function_object.cpp: (KJS::FunctionObjectImp::construct):
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate):
  • kjs/lexer.cpp: (kjsyylex):
  • kjs/lexer.h:
  • kjs/testkjs.cpp: (prettyPrintScript): Updated for the above changes. Most of threadInstance uses here will need to be replaced with explicitly passed pointers to support legacy JSC clients.
  • Property svn:eol-style set to native
File size: 3.8 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#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
35namespace KJS {
36
37 class FunctionBodyNode;
38 class ProgramNode;
39 class UString;
40
41 template <typename T> struct ParserRefCountedData : ParserRefCounted {
42 T data;
43 };
44
45 class Parser : Noncopyable {
46 public:
47 template <class ParsedNode>
48 PassRefPtr<ParsedNode> parse(ExecState*, const UString& sourceURL, int startingLineNumber,
49 PassRefPtr<SourceProvider> source,
50 int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
51
52 UString sourceURL() const { return m_sourceURL; }
53 int sourceId() const { return m_sourceId; }
54
55 void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*,
56 ParserRefCountedData<DeclarationStacks::FunctionStack>*, bool usesEval, bool needsClosure, int lastLine);
57
58 private:
59 friend struct JSGlobalData;
60 Parser();
61
62 void parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
63 int* sourceId, int* errLine, UString* errMsg);
64
65 UString m_sourceURL;
66 int m_sourceId;
67 RefPtr<SourceElements> m_sourceElements;
68 RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
69 RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
70 bool m_usesEval;
71 bool m_needsClosure;
72 int m_lastLine;
73 };
74
75 template <class ParsedNode>
76 PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber,
77 PassRefPtr<SourceProvider> source,
78 int* sourceId, int* errLine, UString* errMsg)
79 {
80 m_sourceURL = sourceURL;
81 parse(exec, sourceURL, startingLineNumber, source, sourceId, errLine, errMsg);
82 if (!m_sourceElements) {
83 m_sourceURL = UString();
84 return 0;
85 }
86 RefPtr<ParsedNode> node = ParsedNode::create(m_sourceElements.release().get(),
87 m_varDeclarations ? &m_varDeclarations->data : 0,
88 m_funcDeclarations ? &m_funcDeclarations->data : 0,
89 m_usesEval,
90 m_needsClosure);
91 m_varDeclarations = 0;
92 m_funcDeclarations = 0;
93 m_sourceURL = UString();
94 node->setLoc(startingLineNumber, m_lastLine);
95 return node.release();
96 }
97
98} // namespace KJS
99
100#endif // Parser_h
Note: See TracBrowser for help on using the repository browser.