From 05fa88892729096192f772ad75ef849f1e732335 Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Tue, 22 Jun 2010 12:31:24 +0000 Subject: [PATCH] Made scanner follow coding style. Review URL: http://codereview.chromium.org/2832018 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4916 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/scanner.cc | 3 +- src/scanner.h | 113 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/scanner.cc b/src/scanner.cc index 8943119..286f515 100755 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -200,6 +200,7 @@ void ExternalStringUTF16Buffer::SeekForward(int pos) { // ---------------------------------------------------------------------------- // Keyword Matcher + KeywordMatcher::FirstState KeywordMatcher::first_states_[] = { { "break", KEYWORD_PREFIX, Token::BREAK }, { NULL, C, Token::ILLEGAL }, @@ -335,7 +336,7 @@ void KeywordMatcher::Step(uc32 input) { // Scanner Scanner::Scanner(ParserMode pre) - : stack_overflow_(false), is_pre_parsing_(pre == PREPARSE) { } + : is_pre_parsing_(pre == PREPARSE), stack_overflow_(false) { } void Scanner::Initialize(Handle source, diff --git a/src/scanner.h b/src/scanner.h index d5efdff..2dce5a1 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -154,7 +154,12 @@ class KeywordMatcher { // *: Actually "future reserved keywords". These are the only ones we // recognized, the remaining are allowed as identifiers. public: - KeywordMatcher() : state_(INITIAL), token_(Token::IDENTIFIER) {} + KeywordMatcher() + : state_(INITIAL), + token_(Token::IDENTIFIER), + keyword_(NULL), + counter_(0), + keyword_token_(Token::ILLEGAL) {} Token::Value token() { return token_; } @@ -206,17 +211,6 @@ class KeywordMatcher { // State map for first keyword character range. static FirstState first_states_[kFirstCharRangeLength]; - // Current state. - State state_; - // Token for currently added characters. - Token::Value token_; - - // Matching a specific keyword string (there is only one possible valid - // keyword with the current prefix). - const char* keyword_; - int counter_; - Token::Value keyword_token_; - // If input equals keyword's character at position, continue matching keyword // from that position. inline bool MatchKeywordStart(uc32 input, @@ -246,15 +240,26 @@ class KeywordMatcher { char match, State new_state, Token::Value keyword_token) { - if (input == match) { // Matched "do". - state_ = new_state; - token_ = keyword_token; - return true; + if (input != match) { + return false; } - return false; + state_ = new_state; + token_ = keyword_token; + return true; } void Step(uc32 input); + + // Current state. + State state_; + // Token for currently added characters. + Token::Value token_; + + // Matching a specific keyword string (there is only one possible valid + // keyword with the current prefix). + const char* keyword_; + int counter_; + Token::Value keyword_token_; }; @@ -362,37 +367,6 @@ class Scanner { static const int kNoEndPosition = 1; private: - void Init(Handle source, - unibrow::CharacterStream* stream, - int start_position, int end_position, - ParserLanguage language); - - - // Different UTF16 buffers used to pull characters from. Based on input one of - // these will be initialized as the actual data source. - CharacterStreamUTF16Buffer char_stream_buffer_; - ExternalStringUTF16Buffer - two_byte_string_buffer_; - ExternalStringUTF16Buffer ascii_string_buffer_; - - // Source. Will point to one of the buffers declared above. - UTF16Buffer* source_; - - // Used to convert the source string into a character stream when a stream - // is not passed to the scanner. - SafeStringInputBuffer safe_string_input_buffer_; - - // Buffer to hold literal values (identifiers, strings, numbers) - // using 0-terminated UTF-8 encoding. - UTF8Buffer literal_buffer_1_; - UTF8Buffer literal_buffer_2_; - - bool stack_overflow_; - static StaticResource utf8_decoder_; - - // One Unicode character look-ahead; c0_ < 0 at the end of the input. - uc32 c0_; - // The current and look-ahead token. struct TokenDesc { Token::Value token; @@ -400,11 +374,10 @@ class Scanner { UTF8Buffer* literal_buffer; }; - TokenDesc current_; // desc for current token (as returned by Next()) - TokenDesc next_; // desc for next token (one token look-ahead) - bool has_line_terminator_before_next_; - bool is_pre_parsing_; - bool is_parsing_json_; + void Init(Handle source, + unibrow::CharacterStream* stream, + int start_position, int end_position, + ParserLanguage language); // Literal buffer support void StartLiteral(); @@ -426,6 +399,7 @@ class Scanner { return SkipJavaScriptWhiteSpace(); } } + bool SkipJavaScriptWhiteSpace(); bool SkipJsonWhiteSpace(); Token::Value SkipSingleLineComment(); @@ -460,11 +434,13 @@ class Scanner { // the integer part is zero), and may include an exponent part (e.g., "e-10"). // Hexadecimal and octal numbers are not allowed. Token::Value ScanJsonNumber(); + // A JSON string (production JSONString) is subset of valid JavaScript string // literals. The string must only be double-quoted (not single-quoted), and // the only allowed backslash-escapes are ", /, \, b, f, n, r, t and // four-digit hex escapes (uXXXX). Any other use of backslashes is invalid. Token::Value ScanJsonString(); + // Used to recognizes one of the literals "true", "false", or "null". These // are the only valid JSON identifiers (productions JSONBooleanLiteral, // JSONNullLiteral). @@ -489,6 +465,37 @@ class Scanner { // Decodes a unicode escape-sequence which is part of an identifier. // If the escape sequence cannot be decoded the result is kBadRune. uc32 ScanIdentifierUnicodeEscape(); + + TokenDesc current_; // desc for current token (as returned by Next()) + TokenDesc next_; // desc for next token (one token look-ahead) + bool has_line_terminator_before_next_; + bool is_pre_parsing_; + bool is_parsing_json_; + + // Different UTF16 buffers used to pull characters from. Based on input one of + // these will be initialized as the actual data source. + CharacterStreamUTF16Buffer char_stream_buffer_; + ExternalStringUTF16Buffer + two_byte_string_buffer_; + ExternalStringUTF16Buffer ascii_string_buffer_; + + // Source. Will point to one of the buffers declared above. + UTF16Buffer* source_; + + // Used to convert the source string into a character stream when a stream + // is not passed to the scanner. + SafeStringInputBuffer safe_string_input_buffer_; + + // Buffer to hold literal values (identifiers, strings, numbers) + // using 0-terminated UTF-8 encoding. + UTF8Buffer literal_buffer_1_; + UTF8Buffer literal_buffer_2_; + + bool stack_overflow_; + static StaticResource utf8_decoder_; + + // One Unicode character look-ahead; c0_ < 0 at the end of the input. + uc32 c0_; }; } } // namespace v8::internal -- 2.7.4