| 1 | /* |
| 2 | * Copyright (C) 2008-2016 Apple Inc. All Rights Reserved. |
| 3 | * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ |
| 4 | * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #pragma once |
| 29 | |
| 30 | #if COMPILER(MSVC) |
| 31 | // Disable the "unreachable code" warning so we can compile the ASSERT_NOT_REACHED in the END_STATE macro. |
| 32 | #pragma warning(disable: 4702) |
| 33 | #endif |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | inline bool isTokenizerWhitespace(UChar character) |
| 38 | { |
| 39 | return character == ' ' || character == '\x0A' || character == '\x09' || character == '\x0C'; |
| 40 | } |
| 41 | |
| 42 | #define BEGIN_STATE(stateName) \ |
| 43 | case stateName: \ |
| 44 | stateName: { \ |
| 45 | constexpr auto currentState = stateName; \ |
| 46 | UNUSED_PARAM(currentState); |
| 47 | |
| 48 | #define END_STATE() \ |
| 49 | ASSERT_NOT_REACHED(); \ |
| 50 | break; \ |
| 51 | } |
| 52 | |
| 53 | #define RETURN_IN_CURRENT_STATE(expression) \ |
| 54 | do { \ |
| 55 | m_state = currentState; \ |
| 56 | return expression; \ |
| 57 | } while (false) |
| 58 | |
| 59 | // We use this macro when the HTML spec says "reconsume the current input character in the <mumble> state." |
| 60 | #define RECONSUME_IN(newState) \ |
| 61 | do { \ |
| 62 | goto newState; \ |
| 63 | } while (false) |
| 64 | |
| 65 | // We use this macro when the HTML spec says "consume the next input character ... and switch to the <mumble> state." |
| 66 | #define ADVANCE_TO(newState) \ |
| 67 | do { \ |
| 68 | if (!m_preprocessor.advance(source, isNullCharacterSkippingState(newState))) { \ |
| 69 | m_state = newState; \ |
| 70 | return haveBufferedCharacterToken(); \ |
| 71 | } \ |
| 72 | character = m_preprocessor.nextInputCharacter(); \ |
| 73 | goto newState; \ |
| 74 | } while (false) |
| 75 | #define ADVANCE_PAST_NON_NEWLINE_TO(newState) \ |
| 76 | do { \ |
| 77 | if (!m_preprocessor.advancePastNonNewline(source, isNullCharacterSkippingState(newState))) { \ |
| 78 | m_state = newState; \ |
| 79 | return haveBufferedCharacterToken(); \ |
| 80 | } \ |
| 81 | character = m_preprocessor.nextInputCharacter(); \ |
| 82 | goto newState; \ |
| 83 | } while (false) |
| 84 | |
| 85 | // For more complex cases, caller consumes the characters first and then uses this macro. |
| 86 | #define SWITCH_TO(newState) \ |
| 87 | do { \ |
| 88 | if (!m_preprocessor.peek(source, isNullCharacterSkippingState(newState))) { \ |
| 89 | m_state = newState; \ |
| 90 | return haveBufferedCharacterToken(); \ |
| 91 | } \ |
| 92 | character = m_preprocessor.nextInputCharacter(); \ |
| 93 | goto newState; \ |
| 94 | } while (false) |
| 95 | |
| 96 | } // namespace WebCore |
| 97 | |