2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
25 #include "Identifier.h"
27 #include "SegmentedVector.h"
28 #include "SourceCode.h"
29 #include <wtf/Vector.h>
35 class Lexer
: Noncopyable
{
37 void setCode(const SourceCode
&);
38 void setIsReparsing() { m_isReparsing
= true; }
39 int lex(void* lvalp
, void* llocp
);
41 int lineNo() const { return yylineno
; }
43 bool prevTerminator() const { return m_terminator
; }
49 InIdentifierOrKeyword
,
51 InIdentifierStartUnicodeEscapeStart
,
52 InIdentifierStartUnicodeEscape
,
53 InIdentifierPartUnicodeEscapeStart
,
54 InIdentifierPartUnicodeEscape
,
78 const UString
& pattern() const { return m_pattern
; }
79 const UString
& flags() const { return m_flags
; }
81 static unsigned char convertHex(int);
82 static unsigned char convertHex(int c1
, int c2
);
83 static UChar
convertUnicode(int c1
, int c2
, int c3
, int c4
);
84 static bool isIdentStart(int);
85 static bool isIdentPart(int);
86 static bool isHexDigit(int);
88 bool sawError() const { return m_error
; }
91 SourceCode
sourceCode(int openBrace
, int closeBrace
, int firstLine
) { return SourceCode(m_source
->provider(), openBrace
, closeBrace
+ 1, firstLine
); }
94 friend class JSGlobalData
;
99 void shift(unsigned int p
);
101 int lookupKeyword(const char *);
103 bool isWhiteSpace() const;
104 bool isLineTerminator();
105 static bool isOctalDigit(int);
107 ALWAYS_INLINE
int matchPunctuator(int& charPos
, int c1
, int c2
, int c3
, int c4
);
108 static unsigned short singleEscape(unsigned short);
109 static unsigned short convertOctal(int c1
, int c2
, int c3
);
113 void record16(UChar
);
115 JSC::Identifier
* makeIdentifier(const Vector
<UChar
>& buffer
)
117 m_identifiers
.append(JSC::Identifier(m_globalData
, buffer
.data(), buffer
.size()));
118 return &m_identifiers
.last();
121 static const size_t initialReadBufferCapacity
= 32;
122 static const size_t initialIdentifierTableCapacity
= 64;
128 Vector
<char> m_buffer8
;
129 Vector
<UChar
> m_buffer16
;
132 bool m_delimited
; // encountered delimiter like "'" and "}" on last run
135 bool m_eatNextIdentifier
;
140 unsigned int m_position
;
141 const SourceCode
* m_source
;
143 unsigned int m_length
;
148 // current and following unicode characters (int to allow for -1 for end-of-file marker)
159 SegmentedVector
<JSC::Identifier
, initialIdentifierTableCapacity
> m_identifiers
;
161 JSGlobalData
* m_globalData
;
166 const HashTable m_mainTable
;