diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/JavaScriptCore/parser/Lexer.h | |
parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/JavaScriptCore/parser/Lexer.h')
-rw-r--r-- | Source/JavaScriptCore/parser/Lexer.h | 122 |
1 files changed, 63 insertions, 59 deletions
diff --git a/Source/JavaScriptCore/parser/Lexer.h b/Source/JavaScriptCore/parser/Lexer.h index e5f56cca4..28c61ba19 100644 --- a/Source/JavaScriptCore/parser/Lexer.h +++ b/Source/JavaScriptCore/parser/Lexer.h @@ -30,26 +30,49 @@ #include <wtf/ASCIICType.h> #include <wtf/SegmentedVector.h> #include <wtf/Vector.h> +#include <wtf/unicode/Unicode.h> namespace JSC { +class Keywords { +public: + bool isKeyword(const Identifier& ident) const + { + return m_keywordTable.entry(m_vm, ident); + } + + const HashEntry* getKeyword(const Identifier& ident) const + { + return m_keywordTable.entry(m_vm, ident); + } + + ~Keywords() + { + m_keywordTable.deleteTable(); + } + +private: + friend class VM; + + explicit Keywords(VM&); + + VM& m_vm; + const HashTable m_keywordTable; +}; + enum LexerFlags { LexerFlagsIgnoreReservedWords = 1, LexerFlagsDontBuildStrings = 2, LexexFlagsDontBuildKeywords = 4 }; -struct ParsedUnicodeEscapeValue; - -bool isLexerKeyword(const Identifier&); - template <typename T> class Lexer { WTF_MAKE_NONCOPYABLE(Lexer); WTF_MAKE_FAST_ALLOCATED; public: - Lexer(VM*, JSParserBuiltinMode); + Lexer(VM*); ~Lexer(); // Character manipulation functions. @@ -60,10 +83,9 @@ public: // Functions to set up parsing. void setCode(const SourceCode&, ParserArena*); - void setIsReparsingFunction() { m_isReparsingFunction = true; } - bool isReparsingFunction() const { return m_isReparsingFunction; } + void setIsReparsing() { m_isReparsing = true; } + bool isReparsing() const { return m_isReparsing; } - void setTokenPosition(JSToken* tokenRecord); JSTokenType lex(JSToken*, unsigned, bool strictMode); bool nextTokenIsColon(); int lineNumber() const { return m_lineNumber; } @@ -74,15 +96,10 @@ public: return JSTextPosition(m_lineNumber, currentOffset(), currentLineStartOffset()); } JSTextPosition positionBeforeLastNewline() const { return m_positionBeforeLastNewline; } - JSTokenLocation lastTokenLocation() const { return m_lastTockenLocation; } void setLastLineNumber(int lastLineNumber) { m_lastLineNumber = lastLineNumber; } int lastLineNumber() const { return m_lastLineNumber; } bool prevTerminator() const { return m_terminator; } bool scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar patternPrefix = 0); -#if ENABLE(ES6_TEMPLATE_LITERAL_SYNTAX) - enum class RawStringsBuildMode { BuildRawStrings, DontBuildRawStrings }; - JSTokenType scanTrailingTemplateString(JSToken*, RawStringsBuildMode); -#endif bool skipRegExp(); // Functions for use after parsing. @@ -109,10 +126,6 @@ public: { m_lineNumber = line; } - void setTerminator(bool terminator) - { - m_terminator = terminator; - } SourceProvider* sourceProvider() const { return m_source->provider(); } @@ -123,15 +136,42 @@ private: void append8(const T*, size_t); void record16(int); void record16(T); - void recordUnicodeCodePoint(UChar32); void append16(const LChar*, size_t); void append16(const UChar* characters, size_t length) { m_buffer16.append(characters, length); } ALWAYS_INLINE void shift(); ALWAYS_INLINE bool atEnd() const; ALWAYS_INLINE T peek(int offset) const; - - ParsedUnicodeEscapeValue parseUnicodeEscape(); + struct UnicodeHexValue { + + enum ValueType { ValidHex, IncompleteHex, InvalidHex }; + + explicit UnicodeHexValue(int value) + : m_value(value) + { + } + explicit UnicodeHexValue(ValueType type) + : m_value(type == IncompleteHex ? -2 : -1) + { + } + + ValueType valueType() const + { + if (m_value >= 0) + return ValidHex; + return m_value == -2 ? IncompleteHex : InvalidHex; + } + bool isValid() const { return m_value >= 0; } + int value() const + { + ASSERT(m_value >= 0); + return m_value; + } + + private: + int m_value; + }; + UnicodeHexValue parseFourDigitUnicodeHex(); void shiftLineTerminator(); ALWAYS_INLINE int offsetFromSourcePtr(const T* ptr) const { return ptr - m_codeStart; } @@ -149,7 +189,6 @@ private: ALWAYS_INLINE const Identifier* makeLCharIdentifier(const UChar* characters, size_t length); ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(const UChar* characters, size_t length, UChar orAllChars); ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(const UChar* characters, size_t length); - ALWAYS_INLINE const Identifier* makeEmptyIdentifier(); ALWAYS_INLINE bool lastTokenWasRestrKeyword() const; @@ -164,14 +203,7 @@ private: }; template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseString(JSTokenData*, bool strictMode); template <bool shouldBuildStrings> NEVER_INLINE StringParseResult parseStringSlowCase(JSTokenData*, bool strictMode); - - enum class EscapeParseMode { Template, String }; - template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseComplexEscape(EscapeParseMode, bool strictMode, T stringQuoteCharacter); -#if ENABLE(ES6_TEMPLATE_LITERAL_SYNTAX) - template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseTemplateLiteral(JSTokenData*, RawStringsBuildMode); -#endif ALWAYS_INLINE void parseHex(double& returnValue); - ALWAYS_INLINE bool parseBinary(double& returnValue); ALWAYS_INLINE bool parseOctal(double& returnValue); ALWAYS_INLINE bool parseDecimal(double& returnValue); ALWAYS_INLINE void parseNumberAfterDecimalPoint(); @@ -185,7 +217,6 @@ private: Vector<LChar> m_buffer8; Vector<UChar> m_buffer16; - Vector<UChar> m_bufferForRawTemplateString16; bool m_terminator; int m_lastToken; @@ -197,8 +228,7 @@ private: const T* m_codeStartPlusOffset; const T* m_lineStart; JSTextPosition m_positionBeforeLastNewline; - JSTokenLocation m_lastTockenLocation; - bool m_isReparsingFunction; + bool m_isReparsing; bool m_atLineStart; bool m_error; String m_lexErrorMessage; @@ -208,7 +238,6 @@ private: IdentifierArena* m_arena; VM* m_vm; - bool m_parsingBuiltinFunction; }; template <> @@ -220,8 +249,7 @@ ALWAYS_INLINE bool Lexer<LChar>::isWhiteSpace(LChar ch) template <> ALWAYS_INLINE bool Lexer<UChar>::isWhiteSpace(UChar ch) { - // 0x180E used to be in Zs category before Unicode 6.3, and EcmaScript says that we should keep treating it as such. - return (ch < 256) ? Lexer<LChar>::isWhiteSpace(static_cast<LChar>(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == 0x180E || ch == 0xFEFF); + return (ch < 256) ? Lexer<LChar>::isWhiteSpace(static_cast<LChar>(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == 0xFEFF); } template <> @@ -275,12 +303,6 @@ ALWAYS_INLINE const Identifier* Lexer<UChar>::makeRightSizedIdentifier(const UCh return &m_arena->makeIdentifier(m_vm, characters, length); } -template <typename T> -ALWAYS_INLINE const Identifier* Lexer<T>::makeEmptyIdentifier() -{ - return &m_arena->makeEmptyIdentifier(m_vm); -} - template <> ALWAYS_INLINE void Lexer<LChar>::setCodeStart(const StringImpl* sourceString) { @@ -313,12 +335,6 @@ ALWAYS_INLINE const Identifier* Lexer<T>::makeLCharIdentifier(const UChar* chara return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters, length); } -#if ASSERT_DISABLED -ALWAYS_INLINE bool isSafeBuiltinIdentifier(VM&, const Identifier*) { return true; } -#else -bool isSafeBuiltinIdentifier(VM&, const Identifier*); -#endif - template <typename T> ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode) { @@ -354,15 +370,10 @@ ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, un ASSERT(currentOffset() >= currentLineStartOffset()); // Create the identifier if needed - if (lexerFlags & LexexFlagsDontBuildKeywords -#if !ASSERT_DISABLED - && !m_parsingBuiltinFunction -#endif - ) + if (lexerFlags & LexexFlagsDontBuildKeywords) tokenData->ident = 0; else tokenData->ident = makeLCharIdentifier(start, ptr - start); - tokenLocation->line = m_lineNumber; tokenLocation->lineStartOffset = currentLineStartOffset(); tokenLocation->startOffset = offsetFromSourcePtr(start); @@ -370,13 +381,6 @@ ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, un ASSERT(tokenLocation->startOffset >= tokenLocation->lineStartOffset); tokenRecord->m_startPosition = startPosition; tokenRecord->m_endPosition = currentPosition(); -#if !ASSERT_DISABLED - if (m_parsingBuiltinFunction) { - if (!isSafeBuiltinIdentifier(*m_vm, tokenData->ident)) - return ERRORTOK; - } -#endif - m_lastToken = IDENT; return IDENT; |