Changeset 251684 in webkit
- Timestamp:
- Oct 28, 2019 4:42:05 PM (4 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r251671 r251684 1 2019-10-28 Ross Kirsling <ross.kirsling@sony.com> 2 3 [JSC] Lexer flags should be an OptionSet 4 https://bugs.webkit.org/show_bug.cgi?id=203032 5 6 Reviewed by Yusuke Suzuki. 7 8 LexerFlags has an annoyingly misspelled value LexexFlagsDontBuildKeywords; 9 let's use this as an opportunity to modernize this enum. 10 11 * parser/ASTBuilder.h: 12 * parser/Lexer.cpp: 13 (JSC::Lexer<LChar>::parseIdentifier): 14 (JSC::Lexer<UChar>::parseIdentifier): 15 (JSC::Lexer<CharacterType>::parseIdentifierSlowCase): 16 (JSC::Lexer<T>::lexWithoutClearingLineTerminator): 17 * parser/Lexer.h: 18 (JSC::Lexer<T>::lexExpectIdentifier): 19 (JSC::Lexer<T>::lex): 20 * parser/Parser.cpp: 21 (JSC::Parser<LexerType>::parseProperty): 22 (JSC::Parser<LexerType>::parseMemberExpression): 23 * parser/Parser.h: 24 (JSC::Parser::next): 25 (JSC::Parser::nextWithoutClearingLineTerminator): 26 (JSC::Parser::nextExpectIdentifier): 27 (JSC::Parser::consume): 28 * parser/SyntaxChecker.h: 29 1 30 2019-10-28 Yusuke Suzuki <ysuzuki@apple.com> 2 31 -
trunk/Source/JavaScriptCore/parser/ASTBuilder.h
r250005 r251684 126 126 static constexpr bool NeedsFreeVariableInfo = true; 127 127 static constexpr bool CanUseFunctionCache = true; 128 static constexpr int DontBuildKeywords = 0;129 static constexpr int DontBuildStrings = 0;128 static constexpr OptionSet<LexerFlags> DontBuildKeywords = { }; 129 static constexpr OptionSet<LexerFlags> DontBuildStrings = { }; 130 130 131 131 ExpressionNode* makeBinaryNode(const JSTokenLocation&, int token, std::pair<ExpressionNode*, BinaryOpInfo>, std::pair<ExpressionNode*, BinaryOpInfo>); -
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r249175 r251684 928 928 929 929 template <> 930 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsignedlexerFlags, bool strictMode)930 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode) 931 931 { 932 932 tokenData->escaped = false; 933 933 const ptrdiff_t remaining = m_codeEnd - m_code; 934 if ((remaining >= maxTokenLength) && ! (lexerFlags & LexerFlagsIgnoreReservedWords)) {934 if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) { 935 935 JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData); 936 936 if (keyword != IDENT) { … … 976 976 tokenData->ident = nullptr; 977 977 978 if (UNLIKELY((remaining < maxTokenLength) && ! (lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {978 if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) { 979 979 ASSERT(shouldCreateIdentifier); 980 980 if (remaining < maxTokenLength) { … … 993 993 994 994 template <> 995 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, unsignedlexerFlags, bool strictMode)995 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode) 996 996 { 997 997 tokenData->escaped = false; 998 998 const ptrdiff_t remaining = m_codeEnd - m_code; 999 if ((remaining >= maxTokenLength) && ! (lexerFlags & LexerFlagsIgnoreReservedWords)) {999 if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) { 1000 1000 JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData); 1001 1001 if (keyword != IDENT) { … … 1054 1054 tokenData->ident = nullptr; 1055 1055 1056 if (UNLIKELY((remaining < maxTokenLength) && ! (lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {1056 if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) { 1057 1057 ASSERT(shouldCreateIdentifier); 1058 1058 if (remaining < maxTokenLength) { … … 1070 1070 } 1071 1071 1072 template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, unsignedlexerFlags, bool strictMode)1072 template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode) 1073 1073 { 1074 1074 tokenData->escaped = true; … … 1120 1120 m_buffer16.shrink(0); 1121 1121 1122 if (LIKELY(! (lexerFlags & LexerFlagsIgnoreReservedWords))) {1122 if (LIKELY(!lexerFlags.contains(LexerFlags::IgnoreReservedWords))) { 1123 1123 ASSERT(shouldCreateIdentifier); 1124 1124 const HashTableValue* entry = JSC::mainTable.entry(*ident); … … 1860 1860 1861 1861 template <typename T> 1862 JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, unsignedlexerFlags, bool strictMode)1862 JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode) 1863 1863 { 1864 1864 JSTokenData* tokenData = &tokenRecord->m_data; … … 2380 2380 case CharacterQuote: { 2381 2381 StringParseResult result = StringCannotBeParsed; 2382 if (lexerFlags & LexerFlagsDontBuildStrings)2382 if (lexerFlags.contains(LexerFlags::DontBuildStrings)) 2383 2383 result = parseString<false>(tokenData, strictMode); 2384 2384 else … … 2398 2398 case CharacterBackSlash: 2399 2399 parseIdent: 2400 if (lexerFlags & LexexFlagsDontBuildKeywords)2400 if (lexerFlags.contains(LexerFlags::DontBuildKeywords)) 2401 2401 token = parseIdentifier<false>(tokenData, lexerFlags, strictMode); 2402 2402 else -
trunk/Source/JavaScriptCore/parser/Lexer.h
r251263 r251684 33 33 namespace JSC { 34 34 35 enum LexerFlags{36 LexerFlagsIgnoreReservedWords = 1,37 LexerFlagsDontBuildStrings = 2,38 LexexFlagsDontBuildKeywords = 435 enum class LexerFlags : uint8_t { 36 IgnoreReservedWords = 1 << 0, 37 DontBuildStrings = 1 << 1, 38 DontBuildKeywords = 1 << 2 39 39 }; 40 40 … … 65 65 bool isReparsingFunction() const { return m_isReparsingFunction; } 66 66 67 JSTokenType lex(JSToken*, unsigned, bool strictMode);68 JSTokenType lexWithoutClearingLineTerminator(JSToken*, unsigned, bool strictMode);67 JSTokenType lex(JSToken*, OptionSet<LexerFlags>, bool strictMode); 68 JSTokenType lexWithoutClearingLineTerminator(JSToken*, OptionSet<LexerFlags>, bool strictMode); 69 69 bool nextTokenIsColon(); 70 70 int lineNumber() const { return m_lineNumber; } … … 117 117 } 118 118 119 JSTokenType lexExpectIdentifier(JSToken*, unsigned, bool strictMode);119 JSTokenType lexExpectIdentifier(JSToken*, OptionSet<LexerFlags>, bool strictMode); 120 120 121 121 ALWAYS_INLINE StringView getToken(const JSToken& token) … … 165 165 template <int shiftAmount> void internalShift(); 166 166 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*); 167 template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned lexerFlags, bool strictMode);168 template <bool shouldBuildIdentifiers> NEVER_INLINE JSTokenType parseIdentifierSlowCase(JSTokenData*, unsigned lexerFlags, bool strictMode);167 template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, OptionSet<LexerFlags>, bool strictMode); 168 template <bool shouldBuildIdentifiers> NEVER_INLINE JSTokenType parseIdentifierSlowCase(JSTokenData*, OptionSet<LexerFlags>, bool strictMode); 169 169 enum StringParseResult { 170 170 StringParsedSuccessfully, … … 341 341 342 342 template <typename T> 343 ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, unsignedlexerFlags, bool strictMode)343 ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode) 344 344 { 345 345 JSTokenData* tokenData = &tokenRecord->m_data; 346 346 JSTokenLocation* tokenLocation = &tokenRecord->m_location; 347 ASSERT( (lexerFlags & LexerFlagsIgnoreReservedWords));347 ASSERT(lexerFlags.contains(LexerFlags::IgnoreReservedWords)); 348 348 const T* start = m_code; 349 349 const T* ptr = start; … … 375 375 376 376 // Create the identifier if needed 377 if (lexerFlags & LexexFlagsDontBuildKeywords377 if (lexerFlags.contains(LexerFlags::DontBuildKeywords) 378 378 #if !ASSERT_DISABLED 379 379 && !m_parsingBuiltinFunction … … 406 406 407 407 template <typename T> 408 ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, unsignedlexerFlags, bool strictMode)408 ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode) 409 409 { 410 410 m_hasLineTerminatorBeforeToken = false; -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r250548 r251684 4004 4004 4005 4005 if (complete || (wasIdent && !isGeneratorMethodParseMode(parseMode) && (*ident == m_vm.propertyNames->get || *ident == m_vm.propertyNames->set))) 4006 nextExpectIdentifier(LexerFlags IgnoreReservedWords);4006 nextExpectIdentifier(LexerFlags::IgnoreReservedWords); 4007 4007 else 4008 nextExpectIdentifier( LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);4008 nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords); 4009 4009 4010 4010 if (!isGeneratorMethodParseMode(parseMode) && !isAsyncMethodParseMode(parseMode) && match(COLON)) { … … 4850 4850 m_parserState.nonTrivialExpressionCount++; 4851 4851 JSTextPosition expressionEnd = lastTokenEndPosition(); 4852 nextExpectIdentifier( LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);4852 nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords); 4853 4853 matchOrFail(IDENT, "Expected a property name after ", optionalChainBase ? "'?.'" : "'.'"); 4854 4854 base = context.createDotAccess(startLocation, base, m_token.m_data.ident, expressionStart, expressionEnd, tokenEndPosition()); -
trunk/Source/JavaScriptCore/parser/Parser.h
r250180 r251684 1356 1356 bool isFunctionMetadataNode(FunctionMetadataNode*) { return true; } 1357 1357 1358 ALWAYS_INLINE void next( unsigned lexerFlags = 0)1358 ALWAYS_INLINE void next(OptionSet<LexerFlags> lexerFlags = { }) 1359 1359 { 1360 1360 int lastLine = m_token.m_location.line; … … 1366 1366 } 1367 1367 1368 ALWAYS_INLINE void nextWithoutClearingLineTerminator( unsigned lexerFlags = 0)1368 ALWAYS_INLINE void nextWithoutClearingLineTerminator(OptionSet<LexerFlags> lexerFlags = { }) 1369 1369 { 1370 1370 int lastLine = m_token.m_location.line; … … 1376 1376 } 1377 1377 1378 ALWAYS_INLINE void nextExpectIdentifier( unsigned lexerFlags = 0)1378 ALWAYS_INLINE void nextExpectIdentifier(OptionSet<LexerFlags> lexerFlags = { }) 1379 1379 { 1380 1380 int lastLine = m_token.m_location.line; … … 1397 1397 } 1398 1398 1399 ALWAYS_INLINE bool consume(JSTokenType expected, unsigned flags = 0)1399 ALWAYS_INLINE bool consume(JSTokenType expected, OptionSet<LexerFlags> flags = { }) 1400 1400 { 1401 1401 bool result = m_token.m_type == expected; -
trunk/Source/JavaScriptCore/parser/SyntaxChecker.h
r250005 r251684 144 144 static constexpr bool NeedsFreeVariableInfo = false; 145 145 static constexpr bool CanUseFunctionCache = true; 146 static constexpr unsigned DontBuildKeywords = LexexFlagsDontBuildKeywords;147 static constexpr unsigned DontBuildStrings = LexerFlagsDontBuildStrings;146 static constexpr OptionSet<LexerFlags> DontBuildKeywords = LexerFlags::DontBuildKeywords; 147 static constexpr OptionSet<LexerFlags> DontBuildStrings = LexerFlags::DontBuildStrings; 148 148 149 149 int createSourceElements() { return SourceElementsResult; }
Note: See TracChangeset
for help on using the changeset viewer.