V8 Project
v8::internal::Scanner Class Reference

#include <scanner.h>

+ Collaboration diagram for v8::internal::Scanner:

Classes

class  LiteralScope
 
struct  Location
 
struct  TokenDesc
 

Public Member Functions

 Scanner (UnicodeCache *scanner_contants)
 
void Initialize (Utf16CharacterStream *source)
 
Token::Value Next ()
 
Token::Value current_token ()
 
Location location () const
 
Token::Value peek () const
 
Location peek_location () const
 
bool literal_contains_escapes () const
 
bool is_literal_contextual_keyword (Vector< const char > keyword)
 
bool is_next_contextual_keyword (Vector< const char > keyword)
 
const AstRawStringCurrentSymbol (AstValueFactory *ast_value_factory)
 
const AstRawStringNextSymbol (AstValueFactory *ast_value_factory)
 
double DoubleValue ()
 
bool UnescapedLiteralMatches (const char *data, int length)
 
void IsGetOrSet (bool *is_get, bool *is_set)
 
int FindNumber (DuplicateFinder *finder, int value)
 
int FindSymbol (DuplicateFinder *finder, int value)
 
UnicodeCacheunicode_cache ()
 
Location octal_position () const
 
void clear_octal_position ()
 
void SeekForward (int pos)
 
bool HarmonyScoping () const
 
void SetHarmonyScoping (bool scoping)
 
bool HarmonyModules () const
 
void SetHarmonyModules (bool modules)
 
bool HarmonyNumericLiterals () const
 
void SetHarmonyNumericLiterals (bool numeric_literals)
 
bool HarmonyClasses () const
 
void SetHarmonyClasses (bool classes)
 
bool HasAnyLineTerminatorBeforeNext () const
 
bool ScanRegExpPattern (bool seen_equal)
 
bool ScanRegExpFlags ()
 
const LiteralBuffersource_url () const
 
const LiteralBuffersource_mapping_url () const
 
bool IdentifierIsFutureStrictReserved (const AstRawString *string) const
 

Static Public Attributes

static const int kNoOctalLocation = -1
 

Private Member Functions

uc32 ScanOctalEscape (uc32 c, int length)
 
void Init ()
 
void StartLiteral ()
 
 INLINE (void AddLiteralChar(uc32 c))
 
void TerminateLiteral ()
 
void DropLiteral ()
 
void AddLiteralCharAdvance ()
 
void Advance ()
 
void PushBack (uc32 ch)
 
Token::Value Select (Token::Value tok)
 
Token::Value Select (uc32 next, Token::Value then, Token::Value else_)
 
Vector< const uint8_t > literal_one_byte_string ()
 
Vector< const uint16_t > literal_two_byte_string ()
 
bool is_literal_one_byte ()
 
int literal_length () const
 
Vector< const uint8_t > next_literal_one_byte_string ()
 
Vector< const uint16_t > next_literal_two_byte_string ()
 
bool is_next_literal_one_byte ()
 
int next_literal_length () const
 
uc32 ScanHexNumber (int expected_length)
 
void Scan ()
 
bool SkipWhiteSpace ()
 
Token::Value SkipSingleLineComment ()
 
Token::Value SkipSourceURLComment ()
 
void TryToParseSourceURLComment ()
 
Token::Value SkipMultiLineComment ()
 
Token::Value ScanHtmlComment ()
 
void ScanDecimalDigits ()
 
Token::Value ScanNumber (bool seen_period)
 
Token::Value ScanIdentifierOrKeyword ()
 
Token::Value ScanIdentifierSuffix (LiteralScope *literal)
 
Token::Value ScanString ()
 
bool ScanEscape ()
 
uc32 ScanIdentifierUnicodeEscape ()
 
bool ScanLiteralUnicodeEscape ()
 
int source_pos ()
 

Private Attributes

UnicodeCacheunicode_cache_
 
LiteralBuffer literal_buffer1_
 
LiteralBuffer literal_buffer2_
 
LiteralBuffer source_url_
 
LiteralBuffer source_mapping_url_
 
TokenDesc current_
 
TokenDesc next_
 
Utf16CharacterStreamsource_
 
Location octal_pos_
 
uc32 c0_
 
bool has_line_terminator_before_next_
 
bool has_multiline_comment_before_next_
 
bool harmony_scoping_
 
bool harmony_modules_
 
bool harmony_numeric_literals_
 
bool harmony_classes_
 

Static Private Attributes

static const int kCharacterLookaheadBufferSize = 1
 

Detailed Description

Definition at line 305 of file scanner.h.

Constructor & Destructor Documentation

◆ Scanner()

v8::internal::Scanner::Scanner ( UnicodeCache scanner_contants)
explicit

Definition at line 34 of file scanner.cc.

37  harmony_scoping_(false),
38  harmony_modules_(false),
40  harmony_classes_(false) { }
UnicodeCache * unicode_cache()
Definition: scanner.h:411
UnicodeCache * unicode_cache_
Definition: scanner.h:620
Location octal_pos_
Definition: scanner.h:638
bool harmony_numeric_literals_
Definition: scanner.h:655
static Location invalid()
Definition: scanner.h:337

Member Function Documentation

◆ AddLiteralCharAdvance()

void v8::internal::Scanner::AddLiteralCharAdvance ( )
inlineprivate

Definition at line 515 of file scanner.h.

515  {
516  AddLiteralChar(c0_);
517  Advance();
518  }

References Advance(), and c0_.

Referenced by ScanDecimalDigits(), ScanNumber(), ScanRegExpFlags(), and ScanRegExpPattern().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Advance()

void v8::internal::Scanner::Advance ( )
inlineprivate

Definition at line 521 of file scanner.h.

521 { c0_ = source_->Advance(); }
Utf16CharacterStream * source_
Definition: scanner.h:634

References v8::internal::Utf16CharacterStream::Advance(), c0_, and source_.

Referenced by AddLiteralCharAdvance(), Init(), Next(), Scan(), ScanEscape(), ScanHexNumber(), ScanHtmlComment(), ScanIdentifierOrKeyword(), ScanIdentifierSuffix(), ScanIdentifierUnicodeEscape(), ScanLiteralUnicodeEscape(), ScanOctalEscape(), ScanRegExpFlags(), ScanRegExpPattern(), ScanString(), SeekForward(), Select(), SkipMultiLineComment(), SkipSingleLineComment(), SkipSourceURLComment(), SkipWhiteSpace(), and TryToParseSourceURLComment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear_octal_position()

void v8::internal::Scanner::clear_octal_position ( )
inline

Definition at line 415 of file scanner.h.

References v8::internal::Scanner::Location::invalid(), and octal_pos_.

Referenced by v8::internal::ParserBase< Traits >::CheckOctalLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ current_token()

Token::Value v8::internal::Scanner::current_token ( )
inline

Definition at line 353 of file scanner.h.

353 { return current_.token; }
TokenDesc current_
Definition: scanner.h:630

References current_, and v8::internal::Scanner::TokenDesc::token.

Referenced by v8::internal::PreParserTraits::GetSymbol().

+ Here is the caller graph for this function:

◆ CurrentSymbol()

const AstRawString * v8::internal::Scanner::CurrentSymbol ( AstValueFactory ast_value_factory)

Definition at line 1195 of file scanner.cc.

1195  {
1196  if (is_literal_one_byte()) {
1197  return ast_value_factory->GetOneByteString(literal_one_byte_string());
1198  }
1199  return ast_value_factory->GetTwoByteString(literal_two_byte_string());
1200 }
Vector< const uint8_t > literal_one_byte_string()
Definition: scanner.h:548
bool is_literal_one_byte()
Definition: scanner.h:556
Vector< const uint16_t > literal_two_byte_string()
Definition: scanner.h:552

References v8::internal::AstValueFactory::GetOneByteString(), v8::internal::AstValueFactory::GetTwoByteString(), is_literal_one_byte(), literal_one_byte_string(), and literal_two_byte_string().

Referenced by v8::internal::ParserTraits::GetSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoubleValue()

double v8::internal::Scanner::DoubleValue ( )

Definition at line 1211 of file scanner.cc.

1211  {
1213  return StringToDouble(
1217 }
#define DCHECK(condition)
Definition: logging.h:205
@ ALLOW_IMPLICIT_OCTAL
Definition: conversions.h:104
double StringToDouble(UnicodeCache *unicode_cache, const char *str, int flags, double empty_string_val)
Definition: conversions.cc:70

References v8::internal::ALLOW_BINARY, v8::internal::ALLOW_HEX, v8::internal::ALLOW_IMPLICIT_OCTAL, v8::internal::ALLOW_OCTAL, DCHECK, is_literal_one_byte(), literal_one_byte_string(), v8::internal::StringToDouble(), and unicode_cache_.

Referenced by v8::internal::ParserTraits::ExpressionFromLiteral(), and v8::internal::ParserTraits::GetNumberAsSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DropLiteral()

void v8::internal::Scanner::DropLiteral ( )
inlineprivate

Definition at line 511 of file scanner.h.

511  {
513  }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
LiteralBuffer * literal_chars
Definition: scanner.h:474

References v8::internal::Scanner::TokenDesc::literal_chars, next_, and NULL.

Referenced by v8::internal::Scanner::LiteralScope::~LiteralScope().

+ Here is the caller graph for this function:

◆ FindNumber()

int v8::internal::Scanner::FindNumber ( DuplicateFinder finder,
int  value 
)

Definition at line 1220 of file scanner.cc.

1220  {
1221  return finder->AddNumber(literal_one_byte_string(), value);
1222 }

References v8::internal::DuplicateFinder::AddNumber(), and literal_one_byte_string().

Referenced by v8::internal::ParserBase< Traits >::ObjectLiteralChecker::CheckProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindSymbol()

int v8::internal::Scanner::FindSymbol ( DuplicateFinder finder,
int  value 
)

Definition at line 1225 of file scanner.cc.

1225  {
1226  if (is_literal_one_byte()) {
1227  return finder->AddOneByteSymbol(literal_one_byte_string(), value);
1228  }
1229  return finder->AddTwoByteSymbol(literal_two_byte_string(), value);
1230 }

References v8::internal::DuplicateFinder::AddOneByteSymbol(), v8::internal::DuplicateFinder::AddTwoByteSymbol(), is_literal_one_byte(), literal_one_byte_string(), and literal_two_byte_string().

Referenced by v8::internal::ParserBase< Traits >::ObjectLiteralChecker::CheckProperty(), and v8::internal::PreParser::ParseFunctionLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HarmonyClasses()

bool v8::internal::Scanner::HarmonyClasses ( ) const
inline

Definition at line 441 of file scanner.h.

441  {
442  return harmony_classes_;
443  }

References harmony_classes_.

Referenced by v8::internal::ParserBase< Traits >::allow_classes().

+ Here is the caller graph for this function:

◆ HarmonyModules()

bool v8::internal::Scanner::HarmonyModules ( ) const
inline

Definition at line 429 of file scanner.h.

429  {
430  return harmony_modules_;
431  }

References harmony_modules_.

Referenced by v8::internal::ParserBase< Traits >::allow_modules().

+ Here is the caller graph for this function:

◆ HarmonyNumericLiterals()

bool v8::internal::Scanner::HarmonyNumericLiterals ( ) const
inline

Definition at line 435 of file scanner.h.

435  {
437  }

References harmony_numeric_literals_.

Referenced by v8::internal::ParserBase< Traits >::allow_harmony_numeric_literals().

+ Here is the caller graph for this function:

◆ HarmonyScoping()

bool v8::internal::Scanner::HarmonyScoping ( ) const
inline

Definition at line 423 of file scanner.h.

423  {
424  return harmony_scoping_;
425  }

References harmony_scoping_.

Referenced by v8::internal::ParserBase< Traits >::allow_harmony_scoping().

+ Here is the caller graph for this function:

◆ HasAnyLineTerminatorBeforeNext()

bool v8::internal::Scanner::HasAnyLineTerminatorBeforeNext ( ) const
inline

Definition at line 450 of file scanner.h.

450  {
453  }
bool has_multiline_comment_before_next_
Definition: scanner.h:649
bool has_line_terminator_before_next_
Definition: scanner.h:646

References has_line_terminator_before_next_, and has_multiline_comment_before_next_.

◆ IdentifierIsFutureStrictReserved()

bool v8::internal::Scanner::IdentifierIsFutureStrictReserved ( const AstRawString string) const

Definition at line 1017 of file scanner.cc.

1018  {
1019  // Keywords are always 1-byte strings.
1020  return string->is_one_byte() &&
1021  Token::FUTURE_STRICT_RESERVED_WORD ==
1022  KeywordOrIdentifierToken(string->raw_data(), string->length(),
1025 }
static Token::Value KeywordOrIdentifierToken(const uint8_t *input, int input_length, bool harmony_scoping, bool harmony_modules, bool harmony_classes)
Definition: scanner.cc:975

References harmony_classes_, harmony_modules_, harmony_scoping_, v8::internal::KeywordOrIdentifierToken(), v8::internal::AstRawString::length(), and v8::internal::AstRawString::raw_data().

Referenced by v8::internal::ParserTraits::IsFutureStrictReserved().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Init()

void v8::internal::Scanner::Init ( )
inlineprivate

Definition at line 483 of file scanner.h.

483  {
484  // Set c0_ (one character ahead)
486  Advance();
487  // Initialize current_ to not refer to a literal.
489  }
static const int kCharacterLookaheadBufferSize
Definition: scanner.h:477
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))

References Advance(), current_, kCharacterLookaheadBufferSize, v8::internal::Scanner::TokenDesc::literal_chars, NULL, and v8::internal::STATIC_ASSERT().

Referenced by Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void v8::internal::Scanner::Initialize ( Utf16CharacterStream source)

Definition at line 43 of file scanner.cc.

43  {
44  source_ = source;
45  // Need to capture identifiers in order to recognize "get" and "set"
46  // in object literals.
47  Init();
48  // Skip initial whitespace allowing HTML comment ends just like
49  // after a newline and scan first token.
52  Scan();
53 }

References has_line_terminator_before_next_, Init(), Scan(), SkipWhiteSpace(), and source_.

Referenced by v8::internal::Parser::ParseLazy(), v8::internal::Parser::ParseOnBackground(), and v8::internal::Parser::ParseProgram().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ INLINE()

v8::internal::Scanner::INLINE ( void   AddLiteralCharuc32 c)
inlineprivate

Definition at line 499 of file scanner.h.

499  {
501  next_.literal_chars->AddChar(c);
502  }
#define DCHECK_NOT_NULL(p)
Definition: logging.h:213

References DCHECK_NOT_NULL, v8::internal::Scanner::TokenDesc::literal_chars, and next_.

◆ is_literal_contextual_keyword()

bool v8::internal::Scanner::is_literal_contextual_keyword ( Vector< const char >  keyword)
inline

Definition at line 374 of file scanner.h.

374  {
377  }
bool is_contextual_keyword(Vector< const char > keyword) const
Definition: scanner.h:221

References current_, DCHECK_NOT_NULL, v8::internal::LiteralBuffer::is_contextual_keyword(), and v8::internal::Scanner::TokenDesc::literal_chars.

+ Here is the call graph for this function:

◆ is_literal_one_byte()

bool v8::internal::Scanner::is_literal_one_byte ( )
inlineprivate

Definition at line 556 of file scanner.h.

556  {
559  }
bool is_one_byte() const
Definition: scanner.h:219

References current_, DCHECK_NOT_NULL, v8::internal::LiteralBuffer::is_one_byte(), and v8::internal::Scanner::TokenDesc::literal_chars.

Referenced by CurrentSymbol(), DoubleValue(), FindSymbol(), IsGetOrSet(), and UnescapedLiteralMatches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_next_contextual_keyword()

bool v8::internal::Scanner::is_next_contextual_keyword ( Vector< const char >  keyword)
inline

Definition at line 378 of file scanner.h.

378  {
380  return next_.literal_chars->is_contextual_keyword(keyword);
381  }

References DCHECK_NOT_NULL, v8::internal::LiteralBuffer::is_contextual_keyword(), v8::internal::Scanner::TokenDesc::literal_chars, and next_.

+ Here is the call graph for this function:

◆ is_next_literal_one_byte()

bool v8::internal::Scanner::is_next_literal_one_byte ( )
inlineprivate

Definition at line 574 of file scanner.h.

574  {
576  return next_.literal_chars->is_one_byte();
577  }

References DCHECK_NOT_NULL, v8::internal::LiteralBuffer::is_one_byte(), v8::internal::Scanner::TokenDesc::literal_chars, and next_.

Referenced by NextSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsGetOrSet()

void v8::internal::Scanner::IsGetOrSet ( bool is_get,
bool is_set 
)
inline

Definition at line 397 of file scanner.h.

397  {
398  if (is_literal_one_byte() &&
399  literal_length() == 3 &&
401  const char* token =
402  reinterpret_cast<const char*>(literal_one_byte_string().start());
403  *is_get = strncmp(token, "get", 3) == 0;
404  *is_set = !*is_get && strncmp(token, "set", 3) == 0;
405  }
406  }
bool literal_contains_escapes() const
Definition: scanner.h:365
int literal_length() const
Definition: scanner.h:560

References is_literal_one_byte(), literal_contains_escapes(), literal_length(), and literal_one_byte_string().

+ Here is the call graph for this function:

◆ literal_contains_escapes()

bool v8::internal::Scanner::literal_contains_escapes ( ) const
inline

Definition at line 365 of file scanner.h.

365  {
366  Location location = current_.location;
367  int source_length = (location.end_pos - location.beg_pos);
368  if (current_.token == Token::STRING) {
369  // Subtract delimiters.
370  source_length -= 2;
371  }
372  return current_.literal_chars->length() != source_length;
373  }
Location location() const
Definition: scanner.h:356
@ STRING

References v8::internal::Scanner::Location::beg_pos, current_, v8::internal::Scanner::Location::end_pos, v8::internal::LiteralBuffer::length(), v8::internal::Scanner::TokenDesc::literal_chars, location(), v8::internal::Scanner::TokenDesc::location, STRING, and v8::internal::Scanner::TokenDesc::token.

Referenced by IsGetOrSet(), and UnescapedLiteralMatches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ literal_length()

int v8::internal::Scanner::literal_length ( ) const
inlineprivate

Definition at line 560 of file scanner.h.

560  {
562  return current_.literal_chars->length();
563  }

References current_, DCHECK_NOT_NULL, v8::internal::LiteralBuffer::length(), and v8::internal::Scanner::TokenDesc::literal_chars.

Referenced by IsGetOrSet(), and UnescapedLiteralMatches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ literal_one_byte_string()

Vector<const uint8_t> v8::internal::Scanner::literal_one_byte_string ( )
inlineprivate

Definition at line 548 of file scanner.h.

548  {
551  }
Vector< const uint8_t > one_byte_literal() const
Definition: scanner.h:234

References current_, DCHECK_NOT_NULL, v8::internal::Scanner::TokenDesc::literal_chars, and v8::internal::LiteralBuffer::one_byte_literal().

Referenced by CurrentSymbol(), DoubleValue(), FindNumber(), FindSymbol(), IsGetOrSet(), and UnescapedLiteralMatches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ literal_two_byte_string()

Vector<const uint16_t> v8::internal::Scanner::literal_two_byte_string ( )
inlineprivate

Definition at line 552 of file scanner.h.

552  {
555  }
Vector< const uint16_t > two_byte_literal() const
Definition: scanner.h:226

References current_, DCHECK_NOT_NULL, v8::internal::Scanner::TokenDesc::literal_chars, and v8::internal::LiteralBuffer::two_byte_literal().

Referenced by CurrentSymbol(), and FindSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ location()

◆ Next()

Token::Value v8::internal::Scanner::Next ( )

Definition at line 219 of file scanner.cc.

219  {
220  current_ = next_;
223  if (static_cast<unsigned>(c0_) <= 0x7f) {
224  Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]);
225  if (token != Token::ILLEGAL) {
226  int pos = source_pos();
227  next_.token = token;
228  next_.location.beg_pos = pos;
229  next_.location.end_pos = pos + 1;
230  Advance();
231  return current_.token;
232  }
233  }
234  Scan();
235  return current_.token;
236 }
static const byte one_char_tokens[]
Definition: scanner.cc:87

References Advance(), v8::internal::Scanner::Location::beg_pos, c0_, current_, v8::internal::Scanner::Location::end_pos, has_line_terminator_before_next_, has_multiline_comment_before_next_, v8::internal::Scanner::TokenDesc::location, next_, v8::internal::one_char_tokens, Scan(), source_pos(), and v8::internal::Scanner::TokenDesc::token.

Referenced by v8::internal::ParserBase< Traits >::INLINE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ next_literal_length()

int v8::internal::Scanner::next_literal_length ( ) const
inlineprivate

Definition at line 578 of file scanner.h.

578  {
580  return next_.literal_chars->length();
581  }

References DCHECK_NOT_NULL, v8::internal::LiteralBuffer::length(), v8::internal::Scanner::TokenDesc::literal_chars, and next_.

+ Here is the call graph for this function:

◆ next_literal_one_byte_string()

Vector<const uint8_t> v8::internal::Scanner::next_literal_one_byte_string ( )
inlineprivate

Definition at line 566 of file scanner.h.

566  {
569  }

References DCHECK_NOT_NULL, v8::internal::Scanner::TokenDesc::literal_chars, next_, and v8::internal::LiteralBuffer::one_byte_literal().

Referenced by NextSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ next_literal_two_byte_string()

Vector<const uint16_t> v8::internal::Scanner::next_literal_two_byte_string ( )
inlineprivate

Definition at line 570 of file scanner.h.

570  {
573  }

References DCHECK_NOT_NULL, v8::internal::Scanner::TokenDesc::literal_chars, next_, and v8::internal::LiteralBuffer::two_byte_literal().

Referenced by NextSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NextSymbol()

const AstRawString * v8::internal::Scanner::NextSymbol ( AstValueFactory ast_value_factory)

Definition at line 1203 of file scanner.cc.

1203  {
1204  if (is_next_literal_one_byte()) {
1205  return ast_value_factory->GetOneByteString(next_literal_one_byte_string());
1206  }
1207  return ast_value_factory->GetTwoByteString(next_literal_two_byte_string());
1208 }
Vector< const uint16_t > next_literal_two_byte_string()
Definition: scanner.h:570
bool is_next_literal_one_byte()
Definition: scanner.h:574
Vector< const uint8_t > next_literal_one_byte_string()
Definition: scanner.h:566

References v8::internal::AstValueFactory::GetOneByteString(), v8::internal::AstValueFactory::GetTwoByteString(), is_next_literal_one_byte(), next_literal_one_byte_string(), and next_literal_two_byte_string().

Referenced by v8::internal::ParserTraits::GetNextSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ octal_position()

Location v8::internal::Scanner::octal_position ( ) const
inline

Definition at line 414 of file scanner.h.

414 { return octal_pos_; }

References octal_pos_.

Referenced by v8::internal::ParserBase< Traits >::CheckOctalLiteral().

+ Here is the caller graph for this function:

◆ peek()

Token::Value v8::internal::Scanner::peek ( ) const
inline

Definition at line 361 of file scanner.h.

361 { return next_.token; }

References next_, and v8::internal::Scanner::TokenDesc::token.

Referenced by v8::internal::ParserBase< Traits >::INLINE().

+ Here is the caller graph for this function:

◆ peek_location()

Location v8::internal::Scanner::peek_location ( ) const
inline

◆ PushBack()

void v8::internal::Scanner::PushBack ( uc32  ch)
inlineprivate

Definition at line 522 of file scanner.h.

522  {
523  source_->PushBack(c0_);
524  c0_ = ch;
525  }
virtual void PushBack(int32_t code_unit)=0

References c0_, v8::internal::Utf16CharacterStream::PushBack(), and source_.

Referenced by Scan(), ScanHexNumber(), ScanHtmlComment(), ScanIdentifierUnicodeEscape(), ScanLiteralUnicodeEscape(), and SkipWhiteSpace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Scan()

void v8::internal::Scanner::Scan ( )
private

Definition at line 411 of file scanner.cc.

411  {
413  Token::Value token;
414  do {
415  // Remember the position of the next token
417 
418  switch (c0_) {
419  case ' ':
420  case '\t':
421  Advance();
422  token = Token::WHITESPACE;
423  break;
424 
425  case '\n':
426  Advance();
428  token = Token::WHITESPACE;
429  break;
430 
431  case '"': case '\'':
432  token = ScanString();
433  break;
434 
435  case '<':
436  // < <= << <<= <!--
437  Advance();
438  if (c0_ == '=') {
439  token = Select(Token::LTE);
440  } else if (c0_ == '<') {
441  token = Select('=', Token::ASSIGN_SHL, Token::SHL);
442  } else if (c0_ == '!') {
443  token = ScanHtmlComment();
444  } else {
445  token = Token::LT;
446  }
447  break;
448 
449  case '>':
450  // > >= >> >>= >>> >>>=
451  Advance();
452  if (c0_ == '=') {
453  token = Select(Token::GTE);
454  } else if (c0_ == '>') {
455  // >> >>= >>> >>>=
456  Advance();
457  if (c0_ == '=') {
458  token = Select(Token::ASSIGN_SAR);
459  } else if (c0_ == '>') {
460  token = Select('=', Token::ASSIGN_SHR, Token::SHR);
461  } else {
462  token = Token::SAR;
463  }
464  } else {
465  token = Token::GT;
466  }
467  break;
468 
469  case '=':
470  // = == === =>
471  Advance();
472  if (c0_ == '=') {
473  token = Select('=', Token::EQ_STRICT, Token::EQ);
474  } else if (c0_ == '>') {
475  token = Select(Token::ARROW);
476  } else {
477  token = Token::ASSIGN;
478  }
479  break;
480 
481  case '!':
482  // ! != !==
483  Advance();
484  if (c0_ == '=') {
485  token = Select('=', Token::NE_STRICT, Token::NE);
486  } else {
487  token = Token::NOT;
488  }
489  break;
490 
491  case '+':
492  // + ++ +=
493  Advance();
494  if (c0_ == '+') {
495  token = Select(Token::INC);
496  } else if (c0_ == '=') {
497  token = Select(Token::ASSIGN_ADD);
498  } else {
499  token = Token::ADD;
500  }
501  break;
502 
503  case '-':
504  // - -- --> -=
505  Advance();
506  if (c0_ == '-') {
507  Advance();
508  if (c0_ == '>' && has_line_terminator_before_next_) {
509  // For compatibility with SpiderMonkey, we skip lines that
510  // start with an HTML comment end '-->'.
511  token = SkipSingleLineComment();
512  } else {
513  token = Token::DEC;
514  }
515  } else if (c0_ == '=') {
516  token = Select(Token::ASSIGN_SUB);
517  } else {
518  token = Token::SUB;
519  }
520  break;
521 
522  case '*':
523  // * *=
524  token = Select('=', Token::ASSIGN_MUL, Token::MUL);
525  break;
526 
527  case '%':
528  // % %=
529  token = Select('=', Token::ASSIGN_MOD, Token::MOD);
530  break;
531 
532  case '/':
533  // / // /* /=
534  Advance();
535  if (c0_ == '/') {
536  Advance();
537  if (c0_ == '@' || c0_ == '#') {
538  Advance();
539  token = SkipSourceURLComment();
540  } else {
541  PushBack(c0_);
542  token = SkipSingleLineComment();
543  }
544  } else if (c0_ == '*') {
545  token = SkipMultiLineComment();
546  } else if (c0_ == '=') {
547  token = Select(Token::ASSIGN_DIV);
548  } else {
549  token = Token::DIV;
550  }
551  break;
552 
553  case '&':
554  // & && &=
555  Advance();
556  if (c0_ == '&') {
557  token = Select(Token::AND);
558  } else if (c0_ == '=') {
559  token = Select(Token::ASSIGN_BIT_AND);
560  } else {
561  token = Token::BIT_AND;
562  }
563  break;
564 
565  case '|':
566  // | || |=
567  Advance();
568  if (c0_ == '|') {
569  token = Select(Token::OR);
570  } else if (c0_ == '=') {
571  token = Select(Token::ASSIGN_BIT_OR);
572  } else {
573  token = Token::BIT_OR;
574  }
575  break;
576 
577  case '^':
578  // ^ ^=
579  token = Select('=', Token::ASSIGN_BIT_XOR, Token::BIT_XOR);
580  break;
581 
582  case '.':
583  // . Number
584  Advance();
585  if (IsDecimalDigit(c0_)) {
586  token = ScanNumber(true);
587  } else {
588  token = Token::PERIOD;
589  }
590  break;
591 
592  case ':':
593  token = Select(Token::COLON);
594  break;
595 
596  case ';':
597  token = Select(Token::SEMICOLON);
598  break;
599 
600  case ',':
601  token = Select(Token::COMMA);
602  break;
603 
604  case '(':
605  token = Select(Token::LPAREN);
606  break;
607 
608  case ')':
609  token = Select(Token::RPAREN);
610  break;
611 
612  case '[':
613  token = Select(Token::LBRACK);
614  break;
615 
616  case ']':
617  token = Select(Token::RBRACK);
618  break;
619 
620  case '{':
621  token = Select(Token::LBRACE);
622  break;
623 
624  case '}':
625  token = Select(Token::RBRACE);
626  break;
627 
628  case '?':
629  token = Select(Token::CONDITIONAL);
630  break;
631 
632  case '~':
633  token = Select(Token::BIT_NOT);
634  break;
635 
636  default:
638  token = ScanIdentifierOrKeyword();
639  } else if (IsDecimalDigit(c0_)) {
640  token = ScanNumber(false);
641  } else if (SkipWhiteSpace()) {
642  token = Token::WHITESPACE;
643  } else if (c0_ < 0) {
644  token = Token::EOS;
645  } else {
646  token = Select(Token::ILLEGAL);
647  }
648  break;
649  }
650 
651  // Continue scanning for tokens as long as we're just skipping
652  // whitespace.
653  } while (token == Token::WHITESPACE);
654 
656  next_.token = token;
657 }
Token::Value ScanString()
Definition: scanner.cc:757
Token::Value ScanNumber(bool seen_period)
Definition: scanner.cc:786
Token::Value SkipMultiLineComment()
Definition: scanner.cc:370
Token::Value ScanIdentifierOrKeyword()
Definition: scanner.cc:1028
Token::Value SkipSourceURLComment()
Definition: scanner.cc:308
void PushBack(uc32 ch)
Definition: scanner.h:522
Token::Value SkipSingleLineComment()
Definition: scanner.cc:292
Token::Value ScanHtmlComment()
Definition: scanner.cc:396
Token::Value Select(Token::Value tok)
Definition: scanner.h:527
bool IsIdentifierStart(unibrow::uchar c)
Definition: scanner.h:120
#define COMMA
bool IsDecimalDigit(uc32 c)

References v8::internal::ADD, Advance(), v8::internal::AND, v8::internal::Scanner::Location::beg_pos, c0_, COMMA, v8::internal::DIV, v8::internal::Scanner::Location::end_pos, v8::internal::EQ, has_line_terminator_before_next_, v8::internal::IsDecimalDigit(), v8::internal::UnicodeCache::IsIdentifierStart(), v8::internal::Scanner::TokenDesc::literal_chars, v8::internal::Scanner::TokenDesc::location, v8::internal::MUL, next_, v8::internal::NOT, NULL, v8::internal::OR, PushBack(), ScanHtmlComment(), ScanIdentifierOrKeyword(), ScanNumber(), ScanString(), Select(), SkipMultiLineComment(), SkipSingleLineComment(), SkipSourceURLComment(), SkipWhiteSpace(), source_pos(), v8::internal::SUB, v8::internal::Scanner::TokenDesc::token, and unicode_cache_.

Referenced by Initialize(), Next(), and SeekForward().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanDecimalDigits()

void v8::internal::Scanner::ScanDecimalDigits ( )
private

Definition at line 780 of file scanner.cc.

780  {
781  while (IsDecimalDigit(c0_))
783 }
void AddLiteralCharAdvance()
Definition: scanner.h:515

References AddLiteralCharAdvance(), c0_, and v8::internal::IsDecimalDigit().

Referenced by ScanNumber().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanEscape()

bool v8::internal::Scanner::ScanEscape ( )
private

Definition at line 681 of file scanner.cc.

681  {
682  uc32 c = c0_;
683  Advance();
684 
685  // Skip escaped newlines.
687  // Allow CR+LF newlines in multiline string literals.
688  if (IsCarriageReturn(c) && IsLineFeed(c0_)) Advance();
689  // Allow LF+CR newlines in multiline string literals.
690  if (IsLineFeed(c) && IsCarriageReturn(c0_)) Advance();
691  return true;
692  }
693 
694  switch (c) {
695  case '\'': // fall through
696  case '"' : // fall through
697  case '\\': break;
698  case 'b' : c = '\b'; break;
699  case 'f' : c = '\f'; break;
700  case 'n' : c = '\n'; break;
701  case 'r' : c = '\r'; break;
702  case 't' : c = '\t'; break;
703  case 'u' : {
704  c = ScanHexNumber(4);
705  if (c < 0) return false;
706  break;
707  }
708  case 'v' : c = '\v'; break;
709  case 'x' : {
710  c = ScanHexNumber(2);
711  if (c < 0) return false;
712  break;
713  }
714  case '0' : // fall through
715  case '1' : // fall through
716  case '2' : // fall through
717  case '3' : // fall through
718  case '4' : // fall through
719  case '5' : // fall through
720  case '6' : // fall through
721  case '7' : c = ScanOctalEscape(c, 2); break;
722  }
723 
724  // According to ECMA-262, section 7.8.4, characters not covered by the
725  // above cases should be illegal, but they are commonly handled as
726  // non-escaped characters by JS VMs.
727  AddLiteralChar(c);
728  return true;
729 }
uc32 ScanOctalEscape(uc32 c, int length)
Definition: scanner.cc:734
uc32 ScanHexNumber(int expected_length)
Definition: scanner.cc:56
bool IsLineTerminator(unibrow::uchar c)
Definition: scanner.h:122
bool IsCarriageReturn(uc32 c)
bool IsLineFeed(uc32 c)
int32_t uc32
Definition: globals.h:185

References Advance(), c0_, v8::internal::IsCarriageReturn(), v8::internal::IsLineFeed(), v8::internal::UnicodeCache::IsLineTerminator(), ScanHexNumber(), ScanOctalEscape(), and unicode_cache_.

Referenced by ScanString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanHexNumber()

uc32 v8::internal::Scanner::ScanHexNumber ( int  expected_length)
private

Definition at line 56 of file scanner.cc.

56  {
57  DCHECK(expected_length <= 4); // prevent overflow
58 
59  uc32 digits[4] = { 0, 0, 0, 0 };
60  uc32 x = 0;
61  for (int i = 0; i < expected_length; i++) {
62  digits[i] = c0_;
63  int d = HexValue(c0_);
64  if (d < 0) {
65  // According to ECMA-262, 3rd, 7.8.4, page 18, these hex escapes
66  // should be illegal, but other JS VMs just return the
67  // non-escaped version of the original character.
68 
69  // Push back digits that we have advanced past.
70  for (int j = i-1; j >= 0; j--) {
71  PushBack(digits[j]);
72  }
73  return -1;
74  }
75  x = x * 16 + d;
76  Advance();
77  }
78 
79  return x;
80 }
int HexValue(uc32 c)
Definition: scanner.h:31

References Advance(), c0_, DCHECK, v8::internal::HexValue(), and PushBack().

Referenced by ScanEscape(), and ScanIdentifierUnicodeEscape().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanHtmlComment()

Token::Value v8::internal::Scanner::ScanHtmlComment ( )
private

Definition at line 396 of file scanner.cc.

396  {
397  // Check for <!-- comments.
398  DCHECK(c0_ == '!');
399  Advance();
400  if (c0_ == '-') {
401  Advance();
402  if (c0_ == '-') return SkipSingleLineComment();
403  PushBack('-'); // undo Advance()
404  }
405  PushBack('!'); // undo Advance()
406  DCHECK(c0_ == '!');
407  return Token::LT;
408 }

References Advance(), c0_, DCHECK, PushBack(), and SkipSingleLineComment().

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanIdentifierOrKeyword()

Token::Value v8::internal::Scanner::ScanIdentifierOrKeyword ( )
private

Definition at line 1028 of file scanner.cc.

1028  {
1030  LiteralScope literal(this);
1031  // Scan identifier start character.
1032  if (c0_ == '\\') {
1034  // Only allow legal identifier start characters.
1035  if (c < 0 ||
1036  c == '\\' || // No recursive escapes.
1038  return Token::ILLEGAL;
1039  }
1040  AddLiteralChar(c);
1041  return ScanIdentifierSuffix(&literal);
1042  }
1043 
1044  uc32 first_char = c0_;
1045  Advance();
1046  AddLiteralChar(first_char);
1047 
1048  // Scan the rest of the identifier characters.
1049  while (unicode_cache_->IsIdentifierPart(c0_)) {
1050  if (c0_ != '\\') {
1051  uc32 next_char = c0_;
1052  Advance();
1053  AddLiteralChar(next_char);
1054  continue;
1055  }
1056  // Fallthrough if no longer able to complete keyword.
1057  return ScanIdentifierSuffix(&literal);
1058  }
1059 
1060  literal.Complete();
1061 
1062  if (next_.literal_chars->is_one_byte()) {
1063  Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
1064  return KeywordOrIdentifierToken(chars.start(),
1065  chars.length(),
1069  }
1070 
1071  return Token::IDENTIFIER;
1072 }
uc32 ScanIdentifierUnicodeEscape()
Definition: scanner.cc:892
Token::Value ScanIdentifierSuffix(LiteralScope *literal)
Definition: scanner.cc:1075
bool IsIdentifierPart(unibrow::uchar c)
Definition: scanner.h:121

References Advance(), c0_, v8::internal::Scanner::LiteralScope::Complete(), DCHECK, harmony_classes_, harmony_modules_, harmony_scoping_, v8::internal::LiteralBuffer::is_one_byte(), v8::internal::UnicodeCache::IsIdentifierPart(), v8::internal::UnicodeCache::IsIdentifierStart(), v8::internal::KeywordOrIdentifierToken(), v8::internal::Vector< T >::length(), v8::internal::Scanner::TokenDesc::literal_chars, next_, v8::internal::LiteralBuffer::one_byte_literal(), ScanIdentifierSuffix(), ScanIdentifierUnicodeEscape(), v8::internal::Vector< T >::start(), and unicode_cache_.

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanIdentifierSuffix()

Token::Value v8::internal::Scanner::ScanIdentifierSuffix ( LiteralScope literal)
private

Definition at line 1075 of file scanner.cc.

1075  {
1076  // Scan the rest of the identifier characters.
1077  while (unicode_cache_->IsIdentifierPart(c0_)) {
1078  if (c0_ == '\\') {
1080  // Only allow legal identifier part characters.
1081  if (c < 0 ||
1082  c == '\\' ||
1084  return Token::ILLEGAL;
1085  }
1086  AddLiteralChar(c);
1087  } else {
1088  AddLiteralChar(c0_);
1089  Advance();
1090  }
1091  }
1092  literal->Complete();
1093 
1094  return Token::IDENTIFIER;
1095 }

References Advance(), c0_, v8::internal::Scanner::LiteralScope::Complete(), v8::internal::UnicodeCache::IsIdentifierPart(), ScanIdentifierUnicodeEscape(), and unicode_cache_.

Referenced by ScanIdentifierOrKeyword().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanIdentifierUnicodeEscape()

uc32 v8::internal::Scanner::ScanIdentifierUnicodeEscape ( )
private

Definition at line 892 of file scanner.cc.

892  {
893  Advance();
894  if (c0_ != 'u') return -1;
895  Advance();
896  uc32 result = ScanHexNumber(4);
897  if (result < 0) PushBack('u');
898  return result;
899 }

References Advance(), c0_, PushBack(), and ScanHexNumber().

Referenced by ScanIdentifierOrKeyword(), and ScanIdentifierSuffix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanLiteralUnicodeEscape()

bool v8::internal::Scanner::ScanLiteralUnicodeEscape ( )
private

Definition at line 1145 of file scanner.cc.

1145  {
1146  DCHECK(c0_ == '\\');
1147  uc32 chars_read[6] = {'\\', 'u', 0, 0, 0, 0};
1148  Advance();
1149  int i = 1;
1150  if (c0_ == 'u') {
1151  i++;
1152  while (i < 6) {
1153  Advance();
1154  if (!IsHexDigit(c0_)) break;
1155  chars_read[i] = c0_;
1156  i++;
1157  }
1158  }
1159  if (i < 6) {
1160  // Incomplete escape. Undo all advances and return false.
1161  while (i > 0) {
1162  i--;
1163  PushBack(chars_read[i]);
1164  }
1165  return false;
1166  }
1167  // Complete escape. Add all chars to current literal buffer.
1168  for (int i = 0; i < 6; i++) {
1169  AddLiteralChar(chars_read[i]);
1170  }
1171  return true;
1172 }
bool IsHexDigit(uc32 c)

References Advance(), c0_, DCHECK, v8::internal::IsHexDigit(), and PushBack().

Referenced by ScanRegExpFlags().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanNumber()

Token::Value v8::internal::Scanner::ScanNumber ( bool  seen_period)
private

Definition at line 786 of file scanner.cc.

786  {
787  DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction
788 
789  enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL;
790 
791  LiteralScope literal(this);
792  if (seen_period) {
793  // we have already seen a decimal point of the float
794  AddLiteralChar('.');
795  ScanDecimalDigits(); // we know we have at least one digit
796 
797  } else {
798  // if the first character is '0' we must check for octals and hex
799  if (c0_ == '0') {
800  int start_pos = source_pos(); // For reporting octal positions.
802 
803  // either 0, 0exxx, 0Exxx, 0.xxx, a hex number, a binary number or
804  // an octal number.
805  if (c0_ == 'x' || c0_ == 'X') {
806  // hex number
807  kind = HEX;
809  if (!IsHexDigit(c0_)) {
810  // we must have at least one hex digit after 'x'/'X'
811  return Token::ILLEGAL;
812  }
813  while (IsHexDigit(c0_)) {
815  }
816  } else if (harmony_numeric_literals_ && (c0_ == 'o' || c0_ == 'O')) {
817  kind = OCTAL;
819  if (!IsOctalDigit(c0_)) {
820  // we must have at least one octal digit after 'o'/'O'
821  return Token::ILLEGAL;
822  }
823  while (IsOctalDigit(c0_)) {
825  }
826  } else if (harmony_numeric_literals_ && (c0_ == 'b' || c0_ == 'B')) {
827  kind = BINARY;
829  if (!IsBinaryDigit(c0_)) {
830  // we must have at least one binary digit after 'b'/'B'
831  return Token::ILLEGAL;
832  }
833  while (IsBinaryDigit(c0_)) {
835  }
836  } else if ('0' <= c0_ && c0_ <= '7') {
837  // (possible) octal number
838  kind = IMPLICIT_OCTAL;
839  while (true) {
840  if (c0_ == '8' || c0_ == '9') {
841  kind = DECIMAL;
842  break;
843  }
844  if (c0_ < '0' || '7' < c0_) {
845  // Octal literal finished.
846  octal_pos_ = Location(start_pos, source_pos());
847  break;
848  }
850  }
851  }
852  }
853 
854  // Parse decimal digits and allow trailing fractional part.
855  if (kind == DECIMAL) {
856  ScanDecimalDigits(); // optional
857  if (c0_ == '.') {
859  ScanDecimalDigits(); // optional
860  }
861  }
862  }
863 
864  // scan exponent, if any
865  if (c0_ == 'e' || c0_ == 'E') {
866  DCHECK(kind != HEX); // 'e'/'E' must be scanned as part of the hex number
867  if (kind != DECIMAL) return Token::ILLEGAL;
868  // scan exponent
870  if (c0_ == '+' || c0_ == '-')
872  if (!IsDecimalDigit(c0_)) {
873  // we must have at least one decimal digit after 'e'/'E'
874  return Token::ILLEGAL;
875  }
877  }
878 
879  // The source character immediately following a numeric literal must
880  // not be an identifier start or a decimal digit; see ECMA-262
881  // section 7.8.3, page 17 (note that we read only one decimal digit
882  // if the value is 0).
884  return Token::ILLEGAL;
885 
886  literal.Complete();
887 
888  return Token::NUMBER;
889 }
void ScanDecimalDigits()
Definition: scanner.cc:780
bool IsOctalDigit(uc32 c)
bool IsBinaryDigit(uc32 c)

References AddLiteralCharAdvance(), c0_, v8::internal::Scanner::LiteralScope::Complete(), DCHECK, harmony_numeric_literals_, v8::internal::IsBinaryDigit(), v8::internal::IsDecimalDigit(), v8::internal::IsHexDigit(), v8::internal::UnicodeCache::IsIdentifierStart(), v8::internal::IsOctalDigit(), octal_pos_, ScanDecimalDigits(), source_pos(), and unicode_cache_.

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanOctalEscape()

uc32 v8::internal::Scanner::ScanOctalEscape ( uc32  c,
int  length 
)
private

Definition at line 734 of file scanner.cc.

734  {
735  uc32 x = c - '0';
736  int i = 0;
737  for (; i < length; i++) {
738  int d = c0_ - '0';
739  if (d < 0 || d > 7) break;
740  int nx = x * 8 + d;
741  if (nx >= 256) break;
742  x = nx;
743  Advance();
744  }
745  // Anything except '\0' is an octal escape sequence, illegal in strict mode.
746  // Remember the position of octal escape sequences so that an error
747  // can be reported later (in strict mode).
748  // We don't report the error immediately, because the octal escape can
749  // occur before the "use strict" directive.
750  if (c != '0' || i > 0) {
751  octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
752  }
753  return x;
754 }

References Advance(), c0_, octal_pos_, and source_pos().

Referenced by ScanEscape().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ScanRegExpFlags()

bool v8::internal::Scanner::ScanRegExpFlags ( )

Definition at line 1175 of file scanner.cc.

1175  {
1176  // Scan regular expression flags.
1177  LiteralScope literal(this);
1178  while (unicode_cache_->IsIdentifierPart(c0_)) {
1179  if (c0_ != '\\') {
1181  } else {
1182  if (!ScanLiteralUnicodeEscape()) {
1183  break;
1184  }
1185  Advance();
1186  }
1187  }
1188  literal.Complete();
1189 
1190  next_.location.end_pos = source_pos() - 1;
1191  return true;
1192 }
bool ScanLiteralUnicodeEscape()
Definition: scanner.cc:1145

References AddLiteralCharAdvance(), Advance(), c0_, v8::internal::Scanner::LiteralScope::Complete(), v8::internal::Scanner::Location::end_pos, v8::internal::UnicodeCache::IsIdentifierPart(), v8::internal::Scanner::TokenDesc::location, next_, ScanLiteralUnicodeEscape(), source_pos(), and unicode_cache_.

+ Here is the call graph for this function:

◆ ScanRegExpPattern()

bool v8::internal::Scanner::ScanRegExpPattern ( bool  seen_equal)

Definition at line 1098 of file scanner.cc.

1098  {
1099  // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags
1100  bool in_character_class = false;
1101 
1102  // Previous token is either '/' or '/=', in the second case, the
1103  // pattern starts at =.
1104  next_.location.beg_pos = source_pos() - (seen_equal ? 2 : 1);
1105  next_.location.end_pos = source_pos() - (seen_equal ? 1 : 0);
1106 
1107  // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5,
1108  // the scanner should pass uninterpreted bodies to the RegExp
1109  // constructor.
1110  LiteralScope literal(this);
1111  if (seen_equal) {
1112  AddLiteralChar('=');
1113  }
1114 
1115  while (c0_ != '/' || in_character_class) {
1116  if (unicode_cache_->IsLineTerminator(c0_) || c0_ < 0) return false;
1117  if (c0_ == '\\') { // Escape sequence.
1119  if (unicode_cache_->IsLineTerminator(c0_) || c0_ < 0) return false;
1121  // If the escape allows more characters, i.e., \x??, \u????, or \c?,
1122  // only "safe" characters are allowed (letters, digits, underscore),
1123  // otherwise the escape isn't valid and the invalid character has
1124  // its normal meaning. I.e., we can just continue scanning without
1125  // worrying whether the following characters are part of the escape
1126  // or not, since any '/', '\\' or '[' is guaranteed to not be part
1127  // of the escape sequence.
1128 
1129  // TODO(896): At some point, parse RegExps more throughly to capture
1130  // octal esacpes in strict mode.
1131  } else { // Unescaped character.
1132  if (c0_ == '[') in_character_class = true;
1133  if (c0_ == ']') in_character_class = false;
1135  }
1136  }
1137  Advance(); // consume '/'
1138 
1139  literal.Complete();
1140 
1141  return true;
1142 }

References AddLiteralCharAdvance(), Advance(), v8::internal::Scanner::Location::beg_pos, c0_, v8::internal::Scanner::LiteralScope::Complete(), v8::internal::Scanner::Location::end_pos, v8::internal::UnicodeCache::IsLineTerminator(), v8::internal::Scanner::TokenDesc::location, next_, source_pos(), and unicode_cache_.

+ Here is the call graph for this function:

◆ ScanString()

Token::Value v8::internal::Scanner::ScanString ( )
private

Definition at line 757 of file scanner.cc.

757  {
758  uc32 quote = c0_;
759  Advance(); // consume quote
760 
761  LiteralScope literal(this);
762  while (c0_ != quote && c0_ >= 0
764  uc32 c = c0_;
765  Advance();
766  if (c == '\\') {
767  if (c0_ < 0 || !ScanEscape()) return Token::ILLEGAL;
768  } else {
769  AddLiteralChar(c);
770  }
771  }
772  if (c0_ != quote) return Token::ILLEGAL;
773  literal.Complete();
774 
775  Advance(); // consume quote
776  return Token::STRING;
777 }

References Advance(), c0_, v8::internal::Scanner::LiteralScope::Complete(), v8::internal::UnicodeCache::IsLineTerminator(), ScanEscape(), STRING, and unicode_cache_.

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SeekForward()

void v8::internal::Scanner::SeekForward ( int  pos)

Definition at line 660 of file scanner.cc.

660  {
661  // After this call, we will have the token at the given position as
662  // the "next" token. The "current" token will be invalid.
663  if (pos == next_.location.beg_pos) return;
664  int current_pos = source_pos();
665  DCHECK_EQ(next_.location.end_pos, current_pos);
666  // Positions inside the lookahead token aren't supported.
667  DCHECK(pos >= current_pos);
668  if (pos != current_pos) {
669  source_->SeekForward(pos - source_->pos());
670  Advance();
671  // This function is only called to seek to the location
672  // of the end of a function (at the "}" token). It doesn't matter
673  // whether there was a line terminator in the part we skip.
676  }
677  Scan();
678 }
unsigned SeekForward(unsigned code_unit_count)
Definition: scanner.h:75
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References Advance(), v8::internal::Scanner::Location::beg_pos, DCHECK, DCHECK_EQ, v8::internal::Scanner::Location::end_pos, has_line_terminator_before_next_, has_multiline_comment_before_next_, v8::internal::Scanner::TokenDesc::location, next_, v8::internal::Utf16CharacterStream::pos(), Scan(), v8::internal::Utf16CharacterStream::SeekForward(), source_, and source_pos().

Referenced by v8::internal::Parser::SkipLazyFunctionBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Select() [1/2]

Token::Value v8::internal::Scanner::Select ( Token::Value  tok)
inlineprivate

Definition at line 527 of file scanner.h.

527  {
528  Advance();
529  return tok;
530  }

References Advance().

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Select() [2/2]

Token::Value v8::internal::Scanner::Select ( uc32  next,
Token::Value  then,
Token::Value  else_ 
)
inlineprivate

Definition at line 532 of file scanner.h.

532  {
533  Advance();
534  if (c0_ == next) {
535  Advance();
536  return then;
537  } else {
538  return else_;
539  }
540  }

References Advance(), and c0_.

+ Here is the call graph for this function:

◆ SetHarmonyClasses()

void v8::internal::Scanner::SetHarmonyClasses ( bool  classes)
inline

Definition at line 444 of file scanner.h.

444  {
445  harmony_classes_ = classes;
446  }

References harmony_classes_.

Referenced by v8::internal::ParserBase< Traits >::set_allow_classes().

+ Here is the caller graph for this function:

◆ SetHarmonyModules()

void v8::internal::Scanner::SetHarmonyModules ( bool  modules)
inline

Definition at line 432 of file scanner.h.

432  {
433  harmony_modules_ = modules;
434  }

References harmony_modules_.

Referenced by v8::internal::ParserBase< Traits >::set_allow_modules().

+ Here is the caller graph for this function:

◆ SetHarmonyNumericLiterals()

void v8::internal::Scanner::SetHarmonyNumericLiterals ( bool  numeric_literals)
inline

Definition at line 438 of file scanner.h.

438  {
439  harmony_numeric_literals_ = numeric_literals;
440  }

References harmony_numeric_literals_.

Referenced by v8::internal::ParserBase< Traits >::set_allow_harmony_numeric_literals().

+ Here is the caller graph for this function:

◆ SetHarmonyScoping()

void v8::internal::Scanner::SetHarmonyScoping ( bool  scoping)
inline

Definition at line 426 of file scanner.h.

426  {
427  harmony_scoping_ = scoping;
428  }

References harmony_scoping_.

Referenced by v8::internal::ParserBase< Traits >::set_allow_harmony_scoping().

+ Here is the caller graph for this function:

◆ SkipMultiLineComment()

Token::Value v8::internal::Scanner::SkipMultiLineComment ( )
private

Definition at line 370 of file scanner.cc.

370  {
371  DCHECK(c0_ == '*');
372  Advance();
373 
374  while (c0_ >= 0) {
375  uc32 ch = c0_;
376  Advance();
377  if (unicode_cache_->IsLineTerminator(ch)) {
378  // Following ECMA-262, section 7.4, a comment containing
379  // a newline will make the comment count as a line-terminator.
381  }
382  // If we have reached the end of the multi-line comment, we
383  // consume the '/' and insert a whitespace. This way all
384  // multi-line comments are treated as whitespace.
385  if (ch == '*' && c0_ == '/') {
386  c0_ = ' ';
387  return Token::WHITESPACE;
388  }
389  }
390 
391  // Unterminated multi-line comment.
392  return Token::ILLEGAL;
393 }

References Advance(), c0_, DCHECK, has_multiline_comment_before_next_, v8::internal::UnicodeCache::IsLineTerminator(), and unicode_cache_.

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SkipSingleLineComment()

Token::Value v8::internal::Scanner::SkipSingleLineComment ( )
private

Definition at line 292 of file scanner.cc.

292  {
293  Advance();
294 
295  // The line terminator at the end of the line is not considered
296  // to be part of the single-line comment; it is recognized
297  // separately by the lexical grammar and becomes part of the
298  // stream of input elements for the syntactic grammar (see
299  // ECMA-262, section 7.4).
300  while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
301  Advance();
302  }
303 
304  return Token::WHITESPACE;
305 }

References Advance(), c0_, v8::internal::UnicodeCache::IsLineTerminator(), and unicode_cache_.

Referenced by Scan(), ScanHtmlComment(), and SkipWhiteSpace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SkipSourceURLComment()

Token::Value v8::internal::Scanner::SkipSourceURLComment ( )
private

Definition at line 308 of file scanner.cc.

308  {
310  while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
311  Advance();
312  }
313 
314  return Token::WHITESPACE;
315 }
void TryToParseSourceURLComment()
Definition: scanner.cc:318

References Advance(), c0_, v8::internal::UnicodeCache::IsLineTerminator(), TryToParseSourceURLComment(), and unicode_cache_.

Referenced by Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SkipWhiteSpace()

bool v8::internal::Scanner::SkipWhiteSpace ( )
private

Definition at line 252 of file scanner.cc.

252  {
253  int start_position = source_pos();
254 
255  while (true) {
256  while (true) {
257  // Advance as long as character is a WhiteSpace or LineTerminator.
258  // Remember if the latter is the case.
261  } else if (!unicode_cache_->IsWhiteSpace(c0_) &&
263  break;
264  }
265  Advance();
266  }
267 
268  // If there is an HTML comment end '-->' at the beginning of a
269  // line (with only whitespace in front of it), we treat the rest
270  // of the line as a comment. This is in line with the way
271  // SpiderMonkey handles it.
272  if (c0_ == '-' && has_line_terminator_before_next_) {
273  Advance();
274  if (c0_ == '-') {
275  Advance();
276  if (c0_ == '>') {
277  // Treat the rest of the line as a comment.
279  // Continue skipping white space after the comment.
280  continue;
281  }
282  PushBack('-'); // undo Advance()
283  }
284  PushBack('-'); // undo Advance()
285  }
286  // Return whether or not we skipped any characters.
287  return source_pos() != start_position;
288  }
289 }
bool IsWhiteSpace(unibrow::uchar c)
Definition: scanner.h:123
static bool IsLittleEndianByteOrderMark(uc32 c)
Definition: scanner.cc:240

References Advance(), c0_, has_line_terminator_before_next_, v8::internal::UnicodeCache::IsLineTerminator(), v8::internal::IsLittleEndianByteOrderMark(), v8::internal::UnicodeCache::IsWhiteSpace(), PushBack(), SkipSingleLineComment(), source_pos(), and unicode_cache_.

Referenced by Initialize(), and Scan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_mapping_url()

const LiteralBuffer* v8::internal::Scanner::source_mapping_url ( ) const
inline

Definition at line 463 of file scanner.h.

463  {
464  return &source_mapping_url_;
465  }
LiteralBuffer source_mapping_url_
Definition: scanner.h:628

References source_mapping_url_.

Referenced by v8::internal::Parser::HandleSourceURLComments().

+ Here is the caller graph for this function:

◆ source_pos()

int v8::internal::Scanner::source_pos ( )
inlineprivate

Definition at line 616 of file scanner.h.

616  {
618  }

References kCharacterLookaheadBufferSize, v8::internal::Utf16CharacterStream::pos(), and source_.

Referenced by Next(), Scan(), ScanNumber(), ScanOctalEscape(), ScanRegExpFlags(), ScanRegExpPattern(), SeekForward(), and SkipWhiteSpace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_url()

const LiteralBuffer* v8::internal::Scanner::source_url ( ) const
inline

Definition at line 462 of file scanner.h.

462 { return &source_url_; }
LiteralBuffer source_url_
Definition: scanner.h:627

References source_url_.

Referenced by v8::internal::Parser::HandleSourceURLComments().

+ Here is the caller graph for this function:

◆ StartLiteral()

void v8::internal::Scanner::StartLiteral ( )
inlineprivate

Definition at line 492 of file scanner.h.

492  {
493  LiteralBuffer* free_buffer = (current_.literal_chars == &literal_buffer1_) ?
495  free_buffer->Reset();
496  next_.literal_chars = free_buffer;
497  }
LiteralBuffer literal_buffer2_
Definition: scanner.h:624
LiteralBuffer literal_buffer1_
Definition: scanner.h:623

References current_, literal_buffer1_, literal_buffer2_, v8::internal::Scanner::TokenDesc::literal_chars, next_, and v8::internal::LiteralBuffer::Reset().

Referenced by v8::internal::Scanner::LiteralScope::LiteralScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TerminateLiteral()

void v8::internal::Scanner::TerminateLiteral ( )
inlineprivate

Definition at line 505 of file scanner.h.

505  {
506  // Does nothing in the current implementation.
507  }

Referenced by v8::internal::Scanner::LiteralScope::Complete().

+ Here is the caller graph for this function:

◆ TryToParseSourceURLComment()

void v8::internal::Scanner::TryToParseSourceURLComment ( )
private

Definition at line 318 of file scanner.cc.

318  {
319  // Magic comments are of the form: //[#@]\s<name>=\s*<value>\s*.* and this
320  // function will just return if it cannot parse a magic comment.
322  return;
323  Advance();
324  LiteralBuffer name;
326  c0_ != '=') {
327  name.AddChar(c0_);
328  Advance();
329  }
330  if (!name.is_one_byte()) return;
331  Vector<const uint8_t> name_literal = name.one_byte_literal();
332  LiteralBuffer* value;
333  if (name_literal == STATIC_CHAR_VECTOR("sourceURL")) {
334  value = &source_url_;
335  } else if (name_literal == STATIC_CHAR_VECTOR("sourceMappingURL")) {
336  value = &source_mapping_url_;
337  } else {
338  return;
339  }
340  if (c0_ != '=')
341  return;
342  Advance();
343  value->Reset();
344  while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) {
345  Advance();
346  }
347  while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
348  // Disallowed characters.
349  if (c0_ == '"' || c0_ == '\'') {
350  value->Reset();
351  return;
352  }
354  break;
355  }
356  value->AddChar(c0_);
357  Advance();
358  }
359  // Allow whitespace at the end.
360  while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
362  value->Reset();
363  break;
364  }
365  Advance();
366  }
367 }
bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c)
Definition: scanner.h:124
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define STATIC_CHAR_VECTOR(x)
Definition: vector.h:154

References Advance(), c0_, v8::internal::UnicodeCache::IsLineTerminator(), v8::internal::UnicodeCache::IsWhiteSpace(), v8::internal::UnicodeCache::IsWhiteSpaceOrLineTerminator(), name, v8::internal::LiteralBuffer::Reset(), source_mapping_url_, source_url_, STATIC_CHAR_VECTOR, and unicode_cache_.

Referenced by SkipSourceURLComment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UnescapedLiteralMatches()

bool v8::internal::Scanner::UnescapedLiteralMatches ( const char *  data,
int  length 
)
inline

Definition at line 387 of file scanner.h.

387  {
388  if (is_literal_one_byte() &&
389  literal_length() == length &&
391  const char* token =
392  reinterpret_cast<const char*>(literal_one_byte_string().start());
393  return !strncmp(token, data, length);
394  }
395  return false;
396  }

References is_literal_one_byte(), literal_contains_escapes(), literal_length(), and literal_one_byte_string().

Referenced by v8::internal::PreParserTraits::ExpressionFromString(), and v8::internal::PreParserTraits::GetSymbol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unicode_cache()

UnicodeCache* v8::internal::Scanner::unicode_cache ( )
inline

Definition at line 411 of file scanner.h.

411 { return unicode_cache_; }

References unicode_cache_.

Member Data Documentation

◆ c0_

◆ current_

◆ harmony_classes_

bool v8::internal::Scanner::harmony_classes_
private

◆ harmony_modules_

bool v8::internal::Scanner::harmony_modules_
private

◆ harmony_numeric_literals_

bool v8::internal::Scanner::harmony_numeric_literals_
private

Definition at line 655 of file scanner.h.

Referenced by HarmonyNumericLiterals(), ScanNumber(), and SetHarmonyNumericLiterals().

◆ harmony_scoping_

bool v8::internal::Scanner::harmony_scoping_
private

◆ has_line_terminator_before_next_

bool v8::internal::Scanner::has_line_terminator_before_next_
private

◆ has_multiline_comment_before_next_

bool v8::internal::Scanner::has_multiline_comment_before_next_
private

Definition at line 649 of file scanner.h.

Referenced by HasAnyLineTerminatorBeforeNext(), Next(), SeekForward(), and SkipMultiLineComment().

◆ kCharacterLookaheadBufferSize

const int v8::internal::Scanner::kCharacterLookaheadBufferSize = 1
staticprivate

Definition at line 477 of file scanner.h.

Referenced by Init(), and source_pos().

◆ kNoOctalLocation

const int v8::internal::Scanner::kNoOctalLocation = -1
static

Definition at line 344 of file scanner.h.

◆ literal_buffer1_

LiteralBuffer v8::internal::Scanner::literal_buffer1_
private

Definition at line 623 of file scanner.h.

Referenced by StartLiteral().

◆ literal_buffer2_

LiteralBuffer v8::internal::Scanner::literal_buffer2_
private

Definition at line 624 of file scanner.h.

Referenced by StartLiteral().

◆ next_

◆ octal_pos_

Location v8::internal::Scanner::octal_pos_
private

Definition at line 638 of file scanner.h.

Referenced by clear_octal_position(), octal_position(), ScanNumber(), and ScanOctalEscape().

◆ source_

Utf16CharacterStream* v8::internal::Scanner::source_
private

Definition at line 634 of file scanner.h.

Referenced by Advance(), Initialize(), PushBack(), SeekForward(), and source_pos().

◆ source_mapping_url_

LiteralBuffer v8::internal::Scanner::source_mapping_url_
private

Definition at line 628 of file scanner.h.

Referenced by source_mapping_url(), and TryToParseSourceURLComment().

◆ source_url_

LiteralBuffer v8::internal::Scanner::source_url_
private

Definition at line 627 of file scanner.h.

Referenced by source_url(), and TryToParseSourceURLComment().

◆ unicode_cache_


The documentation for this class was generated from the following files: