source: webkit/trunk/JavaScriptCore/parser/Lexer.h@ 47412

Last change on this file since 47412 was 47236, checked in by Darin Adler, 16 years ago

JavaScriptCore: JavaScriptCore tweaks to get ready for the parser arena
https://bugs.webkit.org/show_bug.cgi?id=28243

Patch by Darin Adler <Darin Adler> on 2009-08-13
Reviewed by David Levin.

Eliminate dependencies on Nodes.h outside JavaScriptCore,
and cut down on them inside JavaScriptCore.

Change regular expression parsing to use identifiers as
with other strings we parse.

Fix a couple things that are needed to use const Identifier
more, which will be part of the parser arena work.

CollectorHeapIterator.h to be project-internal.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitPushNewScope): Added const.

  • bytecompiler/BytecodeGenerator.h: Ditto.
  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions): Moved this function
here from WebCore. Here is better since it uses so many internals.
Removed unimportant optimization for the no listener case.

  • debugger/Debugger.h: Ditto. Also removed unneeded include

and tweaked formatting and comments.

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::functionName): Call asFunction instead
of doing the unchecked static_cast.
(JSC::DebuggerCallFrame::calculatedFunctionName): Ditto.

  • jit/JITStubs.cpp:

(JSC::op_call_JSFunction): Call isHostFunction on the body rather
than on the JSFunction.
(JSC::vm_lazyLinkCall): Ditto.
(JSC::op_construct_JSConstruct): Ditto.

  • parser/Grammar.y: Changed callers to use new scanRegExp with

out arguments instead of relying on state in the Lexer. And
callers that just want to skip a regular expression to use
skipRegExp.

  • parser/Lexer.cpp:

(JSC::Lexer::scanRegExp): Changed to use out arguments, and to
add a prefix argument so we can add in the "=" character as needed.
Also rewrote to streamline the logic a bit inspired by suggestions
by David Levin.
(JSC::Lexer::skipRegExp): Added. Version of the function above that
does not actually put the regular expression into a string.
(JSC::Lexer::clear): Removed code to clear m_pattern and m_flags.

  • parser/Lexer.h: Changed scanRegExp to have out arguments. Added

skipRegExp. Eliminated pattern, flags, m_pattern, and m_flags.

  • parser/NodeConstructors.h:

(JSC::RegExpNode::RegExpNode): Changed to take const Identifier&.

  • parser/Nodes.cpp:

(JSC::RegExpNode::emitBytecode): Changed since m_pattern and
m_flags are now Identifier instead of UString.
(JSC::FunctionBodyNode::make): Moved this function here instead
of putting it in the JSFunction.h header.

  • parser/Nodes.h: Changed RegExpNode to use Identifier.
  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier): Changed to use isHostFunction
on the body instead of on the JSFunction object.

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString): Ditto.

  • runtime/JSFunction.cpp:

(JSC::JSFunction::isHostFunction): Moved here from header.
(JSC::JSFunction::isHostFunctionNonInline): Added.
(JSC::JSFunction::JSFunction): Removed unneeded initialization of
m_body to 0.
(JSC::JSFunction::setBody): Moved here from header.

  • runtime/JSFunction.h: Removed unneeded includes. Moved private

constructor down to the private section. Made virtual functions
private. Removed unneeded overload of setBody and moved the body
of the function into the .cpp file. Changed assertions to use
the non-inline version of isHostFunction.

  • runtime/PropertySlot.cpp:

(JSC::PropertySlot::functionGetter): Use asFunction instead
of doing the unchecked static_cast.

  • wtf/SegmentedVector.h:

(WTF::SegmentedVector::isEmpty): Added.

WebCore: JavaScriptCore tweaks to get ready for the parser arena
https://bugs.webkit.org/show_bug.cgi?id=28243

Patch by Darin Adler <Darin Adler> on 2009-08-13
Reviewed by David Levin.

  • ForwardingHeaders/runtime/CollectorHeapIterator.h: Removed.
  • WebCore.xcodeproj/project.pbxproj: Exposed a couple header

files as Private that are now needed to compile Mac WebKit.

  • bindings/js/JSAudioConstructor.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageConstructor.cpp:
  • bindings/js/JSLazyEventListener.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessageChannelConstructor.cpp:
  • bindings/js/JSOptionConstructor.cpp:
  • bindings/js/JSWebSocketConstructor.cpp:
  • bindings/js/JSWebSocketCustom.cpp:
  • bindings/js/JSWorkerConstructor.cpp:
  • bindings/js/JSXMLHttpRequestConstructor.cpp:
  • bridge/jni/jni_jsobject.mm:

Updated includes.

  • inspector/JavaScriptDebugServer.cpp:

(WebCore::JavaScriptDebugServer::sourceParsed):
Change to not assert if this is called with no listeners.
I don't think this was guaranteed before, and we now use
this code path when recompiling. Slightly less efficient,
but this is a one-time cost when turning on the debugger.
(WebCore::JavaScriptDebugServer::recompileAllJSFunctions):
Change to call Debugger::recompileAllJSFunctions.

WebKit/mac: * Plugins/Hosted/NetscapePluginInstanceProxy.mm: Updated includes.

  • WebView/WebScriptDebugger.mm: Ditto.
  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef Lexer_h
23#define Lexer_h
24
25#include "Lookup.h"
26#include "SourceCode.h"
27#include <wtf/ASCIICType.h>
28#include <wtf/SegmentedVector.h>
29#include <wtf/Vector.h>
30#include <wtf/unicode/Unicode.h>
31
32namespace JSC {
33
34 class RegExp;
35
36 class Lexer : public Noncopyable {
37 public:
38 // Character manipulation functions.
39 static bool isWhiteSpace(int character);
40 static bool isLineTerminator(int character);
41 static unsigned char convertHex(int c1, int c2);
42 static UChar convertUnicode(int c1, int c2, int c3, int c4);
43
44 // Functions to set up parsing.
45 void setCode(const SourceCode&);
46 void setIsReparsing() { m_isReparsing = true; }
47
48 // Functions for the parser itself.
49 int lex(void* lvalp, void* llocp);
50 int lineNumber() const { return m_lineNumber; }
51 bool prevTerminator() const { return m_terminator; }
52 SourceCode sourceCode(int openBrace, int closeBrace, int firstLine);
53 bool scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar patternPrefix = 0);
54 bool skipRegExp();
55
56 // Functions for use after parsing.
57 bool sawError() const { return m_error; }
58 void clear();
59
60 private:
61 friend class JSGlobalData;
62
63 Lexer(JSGlobalData*);
64 ~Lexer();
65
66 void shift1();
67 void shift2();
68 void shift3();
69 void shift4();
70 void shiftLineTerminator();
71
72 void record8(int);
73 void record16(int);
74 void record16(UChar);
75
76 void copyCodeWithoutBOMs();
77
78 int currentOffset() const;
79 const UChar* currentCharacter() const;
80
81 JSC::Identifier* makeIdentifier(const UChar* buffer, size_t length);
82
83 bool lastTokenWasRestrKeyword() const;
84
85 static const size_t initialReadBufferCapacity = 32;
86 static const size_t initialIdentifierTableCapacity = 64;
87
88 int m_lineNumber;
89
90 Vector<char> m_buffer8;
91 Vector<UChar> m_buffer16;
92 bool m_terminator;
93 bool m_delimited; // encountered delimiter like "'" and "}" on last run
94 int m_lastToken;
95
96 const SourceCode* m_source;
97 const UChar* m_code;
98 const UChar* m_codeStart;
99 const UChar* m_codeEnd;
100 bool m_isReparsing;
101 bool m_atLineStart;
102 bool m_error;
103
104 // current and following unicode characters (int to allow for -1 for end-of-file marker)
105 int m_current;
106 int m_next1;
107 int m_next2;
108 int m_next3;
109
110 WTF::SegmentedVector<JSC::Identifier, initialIdentifierTableCapacity> m_identifiers;
111
112 JSGlobalData* m_globalData;
113
114 const HashTable m_keywordTable;
115
116 Vector<UChar> m_codeWithoutBOMs;
117 };
118
119 inline bool Lexer::isWhiteSpace(int ch)
120 {
121 return isASCII(ch) ? (ch == ' ' || ch == '\t' || ch == 0xB || ch == 0xC) : WTF::Unicode::isSeparatorSpace(ch);
122 }
123
124 inline bool Lexer::isLineTerminator(int ch)
125 {
126 return ch == '\r' || ch == '\n' || (ch & ~1) == 0x2028;
127 }
128
129 inline unsigned char Lexer::convertHex(int c1, int c2)
130 {
131 return (toASCIIHexValue(c1) << 4) | toASCIIHexValue(c2);
132 }
133
134 inline UChar Lexer::convertUnicode(int c1, int c2, int c3, int c4)
135 {
136 return (convertHex(c1, c2) << 8) | convertHex(c3, c4);
137 }
138
139} // namespace JSC
140
141#endif // Lexer_h
Note: See TracBrowser for help on using the repository browser.