Ignore:
Timestamp:
Apr 21, 2012, 12:46:02 PM (13 years ago)
Author:
Darin Adler
Message:

Change JavaScript lexer to use 0 instead of -1 for sentinel, eliminating the need to put characters into ints
https://bugs.webkit.org/show_bug.cgi?id=84523

Reviewed by Oliver Hunt.

Separate preparation step of copyright dates, renaming, and other small tweaks.

  • parser/Lexer.cpp:

(JSC::Lexer::invalidCharacterMessage): Removed "get" from name to match WebKit naming conventions.
(JSC::Lexer::peek): Removed meaningless comment.
(JSC::Lexer::parseFourDigitUnicodeHex): Renamed from getUnicodeCharacter to be more precise about
what this function does.
(JSC::Lexer::shiftLineTerminator): Renamed local variable that had a data-member-style name.
(JSC::Lexer::parseStringSlowCase): Updated for new name of parseFourDigitUnicodeHex.
(JSC::Lexer::lex): Updated for new name of invalidCharacterMessage.

  • parser/Lexer.h: Removed an unneeded forward declaration of the RegExp class.

Renamed getInvalidCharMessage to invalidCharacterMessage and made it const. Renamed
getUnicodeCharacter to parseFourDigitUnicodeHex.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r114153 r114844  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    3  *  Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All Rights Reserved.
     3 *  Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All Rights Reserved.
    44 *  Copyright (C) 2007 Cameron Zwarich ([email protected])
    55 *  Copyright (C) 2010 Zoltan Herczeg ([email protected])
     
    369369
    370370template <typename T>
    371 UString Lexer<T>::getInvalidCharMessage()
     371UString Lexer<T>::invalidCharacterMessage() const
    372372{
    373373    switch (m_current) {
     
    451451ALWAYS_INLINE int Lexer<T>::peek(int offset)
    452452{
    453     // Only use if necessary
    454453    ASSERT(offset > 0 && offset < 5);
    455454    const T* code = m_code + offset;
     
    458457
    459458template <typename T>
    460 int Lexer<T>::getUnicodeCharacter()
     459int Lexer<T>::parseFourDigitUnicodeHex()
    461460{
    462461    int char1 = peek(1);
     
    480479    ASSERT(isLineTerminator(static_cast<T>(m_current)));
    481480
    482     int m_prev = m_current;
     481    int prev = m_current;
    483482    shift();
    484483
    485484    // Allow both CRLF and LFCR.
    486     if (m_prev + m_current == '\n' + '\r')
     485    if (prev + m_current == '\n' + '\r')
    487486        shift();
    488487
     
    634633
    635634template <>
    636     template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
     635template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer<LChar>::parseIdentifier(JSTokenData* tokenData, unsigned lexerFlags, bool strictMode)
    637636{
    638637    const ptrdiff_t remaining = m_codeEnd - m_code;
     
    692691        }
    693692    }
     693
    694694    const UChar* identifierStart = currentCharacter();
    695695
     
    763763            return ERRORTOK;
    764764        shift();
    765         int character = getUnicodeCharacter();
     765        int character = parseFourDigitUnicodeHex();
    766766        if (UNLIKELY(character == -1))
    767767            return ERRORTOK;
     
    911911            } else if (m_current == 'u') {
    912912                shift();
    913                 int character = getUnicodeCharacter();
     913                int character = parseFourDigitUnicodeHex();
    914914                if (character != -1) {
    915915                    if (shouldBuildStrings)
     
    15091509        goto start;
    15101510    case CharacterInvalid:
    1511         m_lexErrorMessage = getInvalidCharMessage();
     1511        m_lexErrorMessage = invalidCharacterMessage();
    15121512        goto returnError;
    15131513    default:
Note: See TracChangeset for help on using the changeset viewer.