Changeset 251684 in webkit


Ignore:
Timestamp:
Oct 28, 2019 4:42:05 PM (4 years ago)
Author:
Ross Kirsling
Message:

[JSC] Lexer flags should be an OptionSet
https://bugs.webkit.org/show_bug.cgi?id=203032

Reviewed by Yusuke Suzuki.

LexerFlags has an annoyingly misspelled value LexexFlagsDontBuildKeywords;
let's use this as an opportunity to modernize this enum.

  • parser/ASTBuilder.h:
  • parser/Lexer.cpp:

(JSC::Lexer<LChar>::parseIdentifier):
(JSC::Lexer<UChar>::parseIdentifier):
(JSC::Lexer<CharacterType>::parseIdentifierSlowCase):
(JSC::Lexer<T>::lexWithoutClearingLineTerminator):

  • parser/Lexer.h:

(JSC::Lexer<T>::lexExpectIdentifier):
(JSC::Lexer<T>::lex):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseProperty):
(JSC::Parser<LexerType>::parseMemberExpression):

  • parser/Parser.h:

(JSC::Parser::next):
(JSC::Parser::nextWithoutClearingLineTerminator):
(JSC::Parser::nextExpectIdentifier):
(JSC::Parser::consume):

  • parser/SyntaxChecker.h:
Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r251671 r251684  
     12019-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
    1302019-10-28  Yusuke Suzuki  <ysuzuki@apple.com>
    231
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r250005 r251684  
    126126    static constexpr bool NeedsFreeVariableInfo = true;
    127127    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 = { };
    130130
    131131    ExpressionNode* makeBinaryNode(const JSTokenLocation&, int token, std::pair<ExpressionNode*, BinaryOpInfo>, std::pair<ExpressionNode*, BinaryOpInfo>);
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r249175 r251684  
    928928   
    929929template <>
    930 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
     930template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    931931{
    932932    tokenData->escaped = false;
    933933    const ptrdiff_t remaining = m_codeEnd - m_code;
    934     if ((remaining >= maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) {
     934    if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) {
    935935        JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData);
    936936        if (keyword != IDENT) {
     
    976976        tokenData->ident = nullptr;
    977977
    978     if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {
     978    if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) {
    979979        ASSERT(shouldCreateIdentifier);
    980980        if (remaining < maxTokenLength) {
     
    993993
    994994template <>
    995 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
     995template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<UChar>::parseIdentifier(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    996996{
    997997    tokenData->escaped = false;
    998998    const ptrdiff_t remaining = m_codeEnd - m_code;
    999     if ((remaining >= maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) {
     999    if ((remaining >= maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) {
    10001000        JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData);
    10011001        if (keyword != IDENT) {
     
    10541054        tokenData->ident = nullptr;
    10551055   
    1056     if (UNLIKELY((remaining < maxTokenLength) && !(lexerFlags & LexerFlagsIgnoreReservedWords)) && !isPrivateName) {
     1056    if (UNLIKELY((remaining < maxTokenLength) && !lexerFlags.contains(LexerFlags::IgnoreReservedWords)) && !isPrivateName) {
    10571057        ASSERT(shouldCreateIdentifier);
    10581058        if (remaining < maxTokenLength) {
     
    10701070}
    10711071
    1072 template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
     1072template<typename CharacterType> template<bool shouldCreateIdentifier> JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    10731073{
    10741074    tokenData->escaped = true;
     
    11201120    m_buffer16.shrink(0);
    11211121
    1122     if (LIKELY(!(lexerFlags & LexerFlagsIgnoreReservedWords))) {
     1122    if (LIKELY(!lexerFlags.contains(LexerFlags::IgnoreReservedWords))) {
    11231123        ASSERT(shouldCreateIdentifier);
    11241124        const HashTableValue* entry = JSC::mainTable.entry(*ident);
     
    18601860
    18611861template <typename T>
    1862 JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
     1862JSTokenType Lexer<T>::lexWithoutClearingLineTerminator(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    18631863{
    18641864    JSTokenData* tokenData = &tokenRecord->m_data;
     
    23802380    case CharacterQuote: {
    23812381        StringParseResult result = StringCannotBeParsed;
    2382         if (lexerFlags & LexerFlagsDontBuildStrings)
     2382        if (lexerFlags.contains(LexerFlags::DontBuildStrings))
    23832383            result = parseString<false>(tokenData, strictMode);
    23842384        else
     
    23982398    case CharacterBackSlash:
    23992399        parseIdent:
    2400         if (lexerFlags & LexexFlagsDontBuildKeywords)
     2400        if (lexerFlags.contains(LexerFlags::DontBuildKeywords))
    24012401            token = parseIdentifier<false>(tokenData, lexerFlags, strictMode);
    24022402        else
  • trunk/Source/JavaScriptCore/parser/Lexer.h

    r251263 r251684  
    3333namespace JSC {
    3434
    35 enum LexerFlags {
    36     LexerFlagsIgnoreReservedWords = 1,
    37     LexerFlagsDontBuildStrings = 2,
    38     LexexFlagsDontBuildKeywords = 4
     35enum class LexerFlags : uint8_t {
     36    IgnoreReservedWords = 1 << 0,
     37    DontBuildStrings = 1 << 1,
     38    DontBuildKeywords = 1 << 2
    3939};
    4040
     
    6565    bool isReparsingFunction() const { return m_isReparsingFunction; }
    6666
    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);
    6969    bool nextTokenIsColon();
    7070    int lineNumber() const { return m_lineNumber; }
     
    117117    }
    118118
    119     JSTokenType lexExpectIdentifier(JSToken*, unsigned, bool strictMode);
     119    JSTokenType lexExpectIdentifier(JSToken*, OptionSet<LexerFlags>, bool strictMode);
    120120
    121121    ALWAYS_INLINE StringView getToken(const JSToken& token)
     
    165165    template <int shiftAmount> void internalShift();
    166166    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);
    169169    enum StringParseResult {
    170170        StringParsedSuccessfully,
     
    341341
    342342template <typename T>
    343 ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
     343ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    344344{
    345345    JSTokenData* tokenData = &tokenRecord->m_data;
    346346    JSTokenLocation* tokenLocation = &tokenRecord->m_location;
    347     ASSERT((lexerFlags & LexerFlagsIgnoreReservedWords));
     347    ASSERT(lexerFlags.contains(LexerFlags::IgnoreReservedWords));
    348348    const T* start = m_code;
    349349    const T* ptr = start;
     
    375375
    376376    // Create the identifier if needed
    377     if (lexerFlags & LexexFlagsDontBuildKeywords
     377    if (lexerFlags.contains(LexerFlags::DontBuildKeywords)
    378378#if !ASSERT_DISABLED
    379379        && !m_parsingBuiltinFunction
     
    406406
    407407template <typename T>
    408 ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, unsigned lexerFlags, bool strictMode)
     408ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
    409409{
    410410    m_hasLineTerminatorBeforeToken = false;
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r250548 r251684  
    40044004
    40054005        if (complete || (wasIdent && !isGeneratorMethodParseMode(parseMode)  && (*ident == m_vm.propertyNames->get || *ident == m_vm.propertyNames->set)))
    4006             nextExpectIdentifier(LexerFlagsIgnoreReservedWords);
     4006            nextExpectIdentifier(LexerFlags::IgnoreReservedWords);
    40074007        else
    4008             nextExpectIdentifier(LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);
     4008            nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords);
    40094009
    40104010        if (!isGeneratorMethodParseMode(parseMode) && !isAsyncMethodParseMode(parseMode) && match(COLON)) {
     
    48504850                m_parserState.nonTrivialExpressionCount++;
    48514851                JSTextPosition expressionEnd = lastTokenEndPosition();
    4852                 nextExpectIdentifier(LexerFlagsIgnoreReservedWords | TreeBuilder::DontBuildKeywords);
     4852                nextExpectIdentifier(TreeBuilder::DontBuildKeywords | LexerFlags::IgnoreReservedWords);
    48534853                matchOrFail(IDENT, "Expected a property name after ", optionalChainBase ? "'?.'" : "'.'");
    48544854                base = context.createDotAccess(startLocation, base, m_token.m_data.ident, expressionStart, expressionEnd, tokenEndPosition());
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r250180 r251684  
    13561356    bool isFunctionMetadataNode(FunctionMetadataNode*) { return true; }
    13571357
    1358     ALWAYS_INLINE void next(unsigned lexerFlags = 0)
     1358    ALWAYS_INLINE void next(OptionSet<LexerFlags> lexerFlags = { })
    13591359    {
    13601360        int lastLine = m_token.m_location.line;
     
    13661366    }
    13671367
    1368     ALWAYS_INLINE void nextWithoutClearingLineTerminator(unsigned lexerFlags = 0)
     1368    ALWAYS_INLINE void nextWithoutClearingLineTerminator(OptionSet<LexerFlags> lexerFlags = { })
    13691369    {
    13701370        int lastLine = m_token.m_location.line;
     
    13761376    }
    13771377
    1378     ALWAYS_INLINE void nextExpectIdentifier(unsigned lexerFlags = 0)
     1378    ALWAYS_INLINE void nextExpectIdentifier(OptionSet<LexerFlags> lexerFlags = { })
    13791379    {
    13801380        int lastLine = m_token.m_location.line;
     
    13971397    }
    13981398
    1399     ALWAYS_INLINE bool consume(JSTokenType expected, unsigned flags = 0)
     1399    ALWAYS_INLINE bool consume(JSTokenType expected, OptionSet<LexerFlags> flags = { })
    14001400    {
    14011401        bool result = m_token.m_type == expected;
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r250005 r251684  
    144144    static constexpr bool NeedsFreeVariableInfo = false;
    145145    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;
    148148
    149149    int createSourceElements() { return SourceElementsResult; }
Note: See TracChangeset for help on using the changeset viewer.