summaryrefslogtreecommitdiff
path: root/deps/v8/src/parsing/scanner.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/parsing/scanner.h')
-rw-r--r--deps/v8/src/parsing/scanner.h151
1 files changed, 79 insertions, 72 deletions
diff --git a/deps/v8/src/parsing/scanner.h b/deps/v8/src/parsing/scanner.h
index e592debd8e..83002b53c8 100644
--- a/deps/v8/src/parsing/scanner.h
+++ b/deps/v8/src/parsing/scanner.h
@@ -21,13 +21,13 @@
namespace v8 {
namespace internal {
-
class AstRawString;
class AstValueFactory;
class DuplicateFinder;
class ExternalOneByteString;
class ExternalTwoByteString;
class ParserRecorder;
+class RuntimeCallStats;
class UnicodeCache;
// ---------------------------------------------------------------------
@@ -38,7 +38,7 @@ class Utf16CharacterStream {
public:
static const uc32 kEndOfInput = -1;
- virtual ~Utf16CharacterStream() {}
+ virtual ~Utf16CharacterStream() = default;
inline uc32 Peek() {
if (V8_LIKELY(buffer_cursor_ < buffer_end_)) {
@@ -109,8 +109,21 @@ class Utf16CharacterStream {
}
}
+ // Returns true if the stream can be cloned with Clone.
+ // TODO(rmcilroy): Remove this once ChunkedStreams can be cloned.
+ virtual bool can_be_cloned() const = 0;
+
+ // Clones the character stream to enable another independent scanner to access
+ // the same underlying stream.
+ virtual std::unique_ptr<Utf16CharacterStream> Clone() const = 0;
+
// Returns true if the stream could access the V8 heap after construction.
- virtual bool can_access_heap() = 0;
+ virtual bool can_access_heap() const = 0;
+
+ RuntimeCallStats* runtime_call_stats() const { return runtime_call_stats_; }
+ void set_runtime_call_stats(RuntimeCallStats* runtime_call_stats) {
+ runtime_call_stats_ = runtime_call_stats;
+ }
protected:
Utf16CharacterStream(const uint16_t* buffer_start,
@@ -172,6 +185,7 @@ class Utf16CharacterStream {
const uint16_t* buffer_cursor_;
const uint16_t* buffer_end_;
size_t buffer_pos_;
+ RuntimeCallStats* runtime_call_stats_;
};
// ----------------------------------------------------------------------------
@@ -186,12 +200,12 @@ class Scanner {
: scanner_(scanner), bookmark_(kNoBookmark) {
DCHECK_NOT_NULL(scanner_);
}
- ~BookmarkScope() {}
+ ~BookmarkScope() = default;
void Set();
void Apply();
- bool HasBeenSet();
- bool HasBeenApplied();
+ bool HasBeenSet() const;
+ bool HasBeenApplied() const;
private:
static const size_t kNoBookmark;
@@ -233,19 +247,21 @@ class Scanner {
// Returns the token following peek()
Token::Value PeekAhead();
// Returns the current token again.
- Token::Value current_token() { return current().token; }
+ Token::Value current_token() const { return current().token; }
- Token::Value current_contextual_token() { return current().contextual_token; }
- Token::Value next_contextual_token() { return next().contextual_token; }
+ Token::Value current_contextual_token() const {
+ return current().contextual_token;
+ }
+ Token::Value next_contextual_token() const { return next().contextual_token; }
// Returns the location information for the current token
// (the token last returned by Next()).
- Location location() const { return current().location; }
+ const Location& location() const { return current().location; }
// This error is specifically an invalid hex or unicode escape sequence.
bool has_error() const { return scanner_error_ != MessageTemplate::kNone; }
MessageTemplate::Template error() const { return scanner_error_; }
- Location error_location() const { return scanner_error_location_; }
+ const Location& error_location() const { return scanner_error_location_; }
bool has_invalid_template_escape() const {
return current().invalid_template_escape_message != MessageTemplate::kNone;
@@ -264,13 +280,14 @@ class Scanner {
// One token look-ahead (past the token returned by Next()).
Token::Value peek() const { return next().token; }
- Location peek_location() const { return next().location; }
+ const Location& peek_location() const { return next().location; }
bool literal_contains_escapes() const {
return LiteralContainsEscapes(current());
}
const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory) const;
+
const AstRawString* NextSymbol(AstValueFactory* ast_value_factory) const;
const AstRawString* CurrentRawSymbol(
AstValueFactory* ast_value_factory) const;
@@ -286,7 +303,7 @@ class Scanner {
inline bool CurrentMatchesContextual(Token::Value token) const {
DCHECK(Token::IsContextualKeyword(token));
- return current().contextual_token == token;
+ return current_contextual_token() == token;
}
// Match the token against the contextual keyword or literal buffer.
@@ -297,7 +314,7 @@ class Scanner {
// (which was escape-processed already).
// Conveniently, !current().literal_chars.is_used() for all proper
// keywords, so this second condition should exit early in common cases.
- return (current().contextual_token == token) ||
+ return (current_contextual_token() == token) ||
(current().literal_chars.is_used() &&
current().literal_chars.Equals(Vector<const char>(
Token::String(token), Token::StringLength(token))));
@@ -308,11 +325,11 @@ class Scanner {
current().literal_chars.Equals(
Vector<const char>("use strict", strlen("use strict")));
}
- bool IsGetOrSet(bool* is_get, bool* is_set) const {
- *is_get = CurrentMatchesContextual(Token::GET);
- *is_set = CurrentMatchesContextual(Token::SET);
- return *is_get || *is_set;
- }
+
+ bool IsGet() { return CurrentMatchesContextual(Token::GET); }
+
+ bool IsSet() { return CurrentMatchesContextual(Token::SET); }
+
bool IsLet() const {
return CurrentMatches(Token::LET) ||
CurrentMatchesContextualEscaped(Token::LET);
@@ -324,7 +341,7 @@ class Scanner {
bool IsDuplicateSymbol(DuplicateFinder* duplicate_finder,
AstValueFactory* ast_value_factory) const;
- UnicodeCache* unicode_cache() { return unicode_cache_; }
+ UnicodeCache* unicode_cache() const { return unicode_cache_; }
// Returns the location of the last seen octal literal.
Location octal_position() const { return octal_pos_; }
@@ -362,10 +379,9 @@ class Scanner {
Maybe<RegExp::Flags> ScanRegExpFlags();
// Scans the input as a template literal
- Token::Value ScanTemplateStart();
Token::Value ScanTemplateContinuation() {
DCHECK_EQ(next().token, Token::RBRACE);
- next().location.beg_pos = source_pos() - 1; // We already consumed }
+ DCHECK_EQ(source_pos() - 1, next().location.beg_pos);
return ScanTemplateSpan();
}
@@ -374,8 +390,6 @@ class Scanner {
bool FoundHtmlComment() const { return found_html_comment_; }
- bool allow_harmony_bigint() const { return allow_harmony_bigint_; }
- void set_allow_harmony_bigint(bool allow) { allow_harmony_bigint_ = allow; }
bool allow_harmony_private_fields() const {
return allow_harmony_private_fields_;
}
@@ -389,34 +403,19 @@ class Scanner {
allow_harmony_numeric_separator_ = allow;
}
+ const Utf16CharacterStream* stream() const { return source_; }
+
private:
// Scoped helper for saving & restoring scanner error state.
// This is used for tagged template literals, in which normally forbidden
// escape sequences are allowed.
class ErrorState;
- // Scoped helper for literal recording. Automatically drops the literal
- // if aborting the scanning before it's complete.
- class LiteralScope {
- public:
- explicit LiteralScope(Scanner* self) : scanner_(self), complete_(false) {
- scanner_->StartLiteral();
- }
- ~LiteralScope() {
- if (!complete_) scanner_->DropLiteral();
- }
- void Complete() { complete_ = true; }
-
- private:
- Scanner* scanner_;
- bool complete_;
- };
-
// LiteralBuffer - Collector of chars of literals.
class LiteralBuffer {
public:
LiteralBuffer()
- : position_(0), is_one_byte_(true), is_used_(false), backing_store_() {}
+ : backing_store_(), position_(0), is_one_byte_(true), is_used_(false) {}
~LiteralBuffer() { backing_store_.Dispose(); }
@@ -506,14 +505,32 @@ class Scanner {
void ExpandBuffer();
void ConvertToTwoByte();
+ Vector<byte> backing_store_;
int position_;
bool is_one_byte_;
bool is_used_;
- Vector<byte> backing_store_;
DISALLOW_COPY_AND_ASSIGN(LiteralBuffer);
};
+ // Scoped helper for literal recording. Automatically drops the literal
+ // if aborting the scanning before it's complete.
+ class LiteralScope {
+ public:
+ explicit LiteralScope(Scanner* scanner)
+ : buffer_(&scanner->next().literal_chars), complete_(false) {
+ buffer_->Start();
+ }
+ ~LiteralScope() {
+ if (!complete_) buffer_->Drop();
+ }
+ void Complete() { complete_ = true; }
+
+ private:
+ LiteralBuffer* buffer_;
+ bool complete_;
+ };
+
// The current and look-ahead token.
struct TokenDesc {
Location location = {0, 0};
@@ -538,7 +555,7 @@ class Scanner {
};
static const int kCharacterLookaheadBufferSize = 1;
- const int kMaxAscii = 127;
+ static const int kMaxAscii = 127;
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
template <bool capture_raw>
@@ -574,11 +591,6 @@ class Scanner {
// Seek to the next_ token at the given position.
void SeekNext(size_t position);
- // Literal buffer support
- inline void StartLiteral() { next().literal_chars.Start(); }
-
- inline void StartRawLiteral() { next().raw_literal_chars.Start(); }
-
V8_INLINE void AddLiteralChar(uc32 c) { next().literal_chars.AddChar(c); }
V8_INLINE void AddLiteralChar(char c) { next().literal_chars.AddChar(c); }
@@ -587,14 +599,7 @@ class Scanner {
next().raw_literal_chars.AddChar(c);
}
- // Stops scanning of a literal and drop the collected characters,
- // e.g., due to an encountered error.
- inline void DropLiteral() {
- next().literal_chars.Drop();
- next().raw_literal_chars.Drop();
- }
-
- inline void AddLiteralCharAdvance() {
+ V8_INLINE void AddLiteralCharAdvance() {
AddLiteralChar(c0_);
Advance();
}
@@ -714,7 +719,8 @@ class Scanner {
uc32 ScanUnlimitedLengthHexNumber(int max_value, int beg_pos);
// Scans a single JavaScript token.
- void Scan();
+ V8_INLINE Token::Value ScanSingleToken();
+ V8_INLINE void Scan();
V8_INLINE Token::Value SkipWhiteSpace();
Token::Value SkipSingleHTMLComment();
@@ -738,8 +744,10 @@ class Scanner {
bool ScanImplicitOctalDigits(int start_pos, NumberKind* kind);
Token::Value ScanNumber(bool seen_period);
- Token::Value ScanIdentifierOrKeyword();
- Token::Value ScanIdentifierOrKeywordInner(LiteralScope* literal);
+ V8_INLINE Token::Value ScanIdentifierOrKeyword();
+ V8_INLINE Token::Value ScanIdentifierOrKeywordInner(LiteralScope* literal);
+ Token::Value ScanIdentifierOrKeywordInnerSlow(LiteralScope* literal,
+ bool escaped);
Token::Value ScanString();
Token::Value ScanPrivateName();
@@ -779,13 +787,7 @@ class Scanner {
void SanityCheckTokenDesc(const TokenDesc&) const;
#endif
- UnicodeCache* unicode_cache_;
-
- // Values parsed from magic comments.
- LiteralBuffer source_url_;
- LiteralBuffer source_mapping_url_;
-
- TokenDesc token_storage_[3];
+ UnicodeCache* const unicode_cache_;
TokenDesc& next() { return *next_; }
@@ -800,23 +802,28 @@ class Scanner {
// Input stream. Must be initialized to an Utf16CharacterStream.
Utf16CharacterStream* const source_;
- // Last-seen positions of potentially problematic tokens.
- Location octal_pos_;
- MessageTemplate::Template octal_message_;
-
// One Unicode character look-ahead; c0_ < 0 at the end of the input.
uc32 c0_;
+ TokenDesc token_storage_[3];
+
// Whether this scanner encountered an HTML comment.
bool found_html_comment_;
// Harmony flags to allow ESNext features.
- bool allow_harmony_bigint_;
bool allow_harmony_private_fields_;
bool allow_harmony_numeric_separator_;
const bool is_module_;
+ // Values parsed from magic comments.
+ LiteralBuffer source_url_;
+ LiteralBuffer source_mapping_url_;
+
+ // Last-seen positions of potentially problematic tokens.
+ Location octal_pos_;
+ MessageTemplate::Template octal_message_;
+
MessageTemplate::Template scanner_error_;
Location scanner_error_location_;
};