2011-04-12 08:27:38 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Features shared by parsing and pre-parsing scanners.
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifndef V8_SCANNER_H_
|
|
|
|
#define V8_SCANNER_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/logging.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/char-predicates.h"
|
|
|
|
#include "src/globals.h"
|
|
|
|
#include "src/hashmap.h"
|
|
|
|
#include "src/list.h"
|
|
|
|
#include "src/token.h"
|
|
|
|
#include "src/unicode-inl.h"
|
2014-10-08 14:55:03 +00:00
|
|
|
#include "src/unicode-decoder.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/utils.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-10-17 12:45:52 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
class AstRawString;
|
|
|
|
class AstValueFactory;
|
2014-03-13 08:29:31 +00:00
|
|
|
class ParserRecorder;
|
|
|
|
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Returns the value (0 .. 15) of a hexadecimal character c.
|
|
|
|
// If c is not a legal hexadecimal character, returns a value < 0.
|
|
|
|
inline int HexValue(uc32 c) {
|
|
|
|
c -= '0';
|
|
|
|
if (static_cast<unsigned>(c) <= 9) return c;
|
|
|
|
c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36.
|
|
|
|
if (static_cast<unsigned>(c) <= 5) return c + 10;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
2012-03-12 12:35:28 +00:00
|
|
|
// Buffered stream of UTF-16 code units, using an internal UTF-16 buffer.
|
|
|
|
// A code unit is a 16 bit value representing either a 16 bit code point
|
|
|
|
// or one part of a surrogate pair that make a single 21 bit code point.
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
class Utf16CharacterStream {
|
2009-08-18 07:14:02 +00:00
|
|
|
public:
|
2012-03-12 12:35:28 +00:00
|
|
|
Utf16CharacterStream() : pos_(0) { }
|
|
|
|
virtual ~Utf16CharacterStream() { }
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Returns and advances past the next UTF-16 code unit in the input
|
|
|
|
// stream. If there are no more code units, it returns a negative
|
2011-09-08 13:06:44 +00:00
|
|
|
// value.
|
|
|
|
inline uc32 Advance() {
|
|
|
|
if (buffer_cursor_ < buffer_end_ || ReadBlock()) {
|
|
|
|
pos_++;
|
|
|
|
return static_cast<uc32>(*(buffer_cursor_++));
|
|
|
|
}
|
|
|
|
// Note: currently the following increment is necessary to avoid a
|
|
|
|
// parser problem! The scanner treats the final kEndOfInput as
|
2012-03-12 12:35:28 +00:00
|
|
|
// a code unit with a position, and does math relative to that
|
2011-09-08 13:06:44 +00:00
|
|
|
// position.
|
|
|
|
pos_++;
|
|
|
|
|
|
|
|
return kEndOfInput;
|
|
|
|
}
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Return the current position in the code unit stream.
|
2011-09-08 13:06:44 +00:00
|
|
|
// Starts at zero.
|
2015-02-05 07:54:24 +00:00
|
|
|
inline size_t pos() const { return pos_; }
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Skips forward past the next code_unit_count UTF-16 code units
|
2011-09-08 13:06:44 +00:00
|
|
|
// in the input, or until the end of input if that comes sooner.
|
2012-03-12 12:35:28 +00:00
|
|
|
// Returns the number of code units actually skipped. If less
|
|
|
|
// than code_unit_count,
|
2015-02-05 07:54:24 +00:00
|
|
|
inline size_t SeekForward(size_t code_unit_count) {
|
|
|
|
size_t buffered_chars = buffer_end_ - buffer_cursor_;
|
2012-03-12 12:35:28 +00:00
|
|
|
if (code_unit_count <= buffered_chars) {
|
|
|
|
buffer_cursor_ += code_unit_count;
|
|
|
|
pos_ += code_unit_count;
|
|
|
|
return code_unit_count;
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
2012-03-12 12:35:28 +00:00
|
|
|
return SlowSeekForward(code_unit_count);
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Pushes back the most recently read UTF-16 code unit (or negative
|
2011-09-08 13:06:44 +00:00
|
|
|
// value if at end of input), i.e., the value returned by the most recent
|
|
|
|
// call to Advance.
|
|
|
|
// Must not be used right after calling SeekForward.
|
2012-03-12 12:35:28 +00:00
|
|
|
virtual void PushBack(int32_t code_unit) = 0;
|
2010-12-07 14:03:59 +00:00
|
|
|
|
|
|
|
protected:
|
2011-09-08 13:06:44 +00:00
|
|
|
static const uc32 kEndOfInput = -1;
|
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Ensures that the buffer_cursor_ points to the code_unit at
|
2011-09-08 13:06:44 +00:00
|
|
|
// position pos_ of the input, if possible. If the position
|
|
|
|
// is at or after the end of the input, return false. If there
|
2012-03-12 12:35:28 +00:00
|
|
|
// are more code_units available, return true.
|
2011-09-08 13:06:44 +00:00
|
|
|
virtual bool ReadBlock() = 0;
|
2015-02-05 07:54:24 +00:00
|
|
|
virtual size_t SlowSeekForward(size_t code_unit_count) = 0;
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2014-03-13 09:15:14 +00:00
|
|
|
const uint16_t* buffer_cursor_;
|
|
|
|
const uint16_t* buffer_end_;
|
2015-02-05 07:54:24 +00:00
|
|
|
size_t pos_;
|
2011-09-08 13:06:44 +00:00
|
|
|
};
|
|
|
|
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Caching predicates used by scanners.
|
2013-10-10 11:58:16 +00:00
|
|
|
|
|
|
|
class UnicodeCache {
|
2011-09-08 13:06:44 +00:00
|
|
|
public:
|
|
|
|
UnicodeCache() {}
|
2012-12-20 09:20:37 +00:00
|
|
|
typedef unibrow::Utf8Decoder<512> Utf8Decoder;
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
StaticResource<Utf8Decoder>* utf8_decoder() {
|
|
|
|
return &utf8_decoder_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); }
|
|
|
|
bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); }
|
|
|
|
bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); }
|
2015-01-08 10:45:58 +00:00
|
|
|
bool IsLineTerminatorSequence(unibrow::uchar c, unibrow::uchar next) {
|
|
|
|
if (!IsLineTerminator(c)) return false;
|
|
|
|
if (c == 0x000d && next == 0x000a) return false; // CR with following LF.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); }
|
2014-02-10 12:43:10 +00:00
|
|
|
bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c) {
|
|
|
|
return kIsWhiteSpaceOrLineTerminator.get(c);
|
|
|
|
}
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
private:
|
|
|
|
unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart;
|
|
|
|
unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart;
|
|
|
|
unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator;
|
2014-02-10 12:43:10 +00:00
|
|
|
unibrow::Predicate<WhiteSpace, 128> kIsWhiteSpace;
|
|
|
|
unibrow::Predicate<WhiteSpaceOrLineTerminator, 128>
|
|
|
|
kIsWhiteSpaceOrLineTerminator;
|
2011-09-08 13:06:44 +00:00
|
|
|
StaticResource<Utf8Decoder> utf8_decoder_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(UnicodeCache);
|
2009-08-18 07:14:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-10 11:58:16 +00:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// DuplicateFinder discovers duplicate symbols.
|
|
|
|
|
|
|
|
class DuplicateFinder {
|
|
|
|
public:
|
|
|
|
explicit DuplicateFinder(UnicodeCache* constants)
|
|
|
|
: unicode_constants_(constants),
|
|
|
|
backing_store_(16),
|
|
|
|
map_(&Match) { }
|
|
|
|
|
2014-03-13 09:15:14 +00:00
|
|
|
int AddOneByteSymbol(Vector<const uint8_t> key, int value);
|
|
|
|
int AddTwoByteSymbol(Vector<const uint16_t> key, int value);
|
2013-10-10 11:58:16 +00:00
|
|
|
// Add a a number literal by converting it (if necessary)
|
|
|
|
// to the string that ToString(ToNumber(literal)) would generate.
|
2014-09-10 12:38:12 +00:00
|
|
|
// and then adding that string with AddOneByteSymbol.
|
2013-10-10 11:58:16 +00:00
|
|
|
// This string is the actual value used as key in an object literal,
|
|
|
|
// and the one that must be different from the other keys.
|
2014-03-13 09:15:14 +00:00
|
|
|
int AddNumber(Vector<const uint8_t> key, int value);
|
2013-10-10 11:58:16 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-13 09:15:14 +00:00
|
|
|
int AddSymbol(Vector<const uint8_t> key, bool is_one_byte, int value);
|
2013-10-10 11:58:16 +00:00
|
|
|
// Backs up the key and its length in the backing store.
|
|
|
|
// The backup is stored with a base 127 encoding of the
|
2014-03-13 09:15:14 +00:00
|
|
|
// length (plus a bit saying whether the string is one byte),
|
2013-10-10 11:58:16 +00:00
|
|
|
// followed by the bytes of the key.
|
2014-03-13 09:15:14 +00:00
|
|
|
uint8_t* BackupKey(Vector<const uint8_t> key, bool is_one_byte);
|
2013-10-10 11:58:16 +00:00
|
|
|
|
|
|
|
// Compare two encoded keys (both pointing into the backing store)
|
2014-09-10 12:38:12 +00:00
|
|
|
// for having the same base-127 encoded lengths and representation.
|
2013-10-10 11:58:16 +00:00
|
|
|
// and then having the same 'length' bytes following.
|
|
|
|
static bool Match(void* first, void* second);
|
|
|
|
// Creates a hash from a sequence of bytes.
|
2014-03-13 09:15:14 +00:00
|
|
|
static uint32_t Hash(Vector<const uint8_t> key, bool is_one_byte);
|
2013-10-10 11:58:16 +00:00
|
|
|
// Checks whether a string containing a JS number is its canonical
|
|
|
|
// form.
|
2014-03-13 09:15:14 +00:00
|
|
|
static bool IsNumberCanonical(Vector<const uint8_t> key);
|
2013-10-10 11:58:16 +00:00
|
|
|
|
|
|
|
// Size of buffer. Sufficient for using it to call DoubleToCString in
|
|
|
|
// from conversions.h.
|
|
|
|
static const int kBufferSize = 100;
|
|
|
|
|
|
|
|
UnicodeCache* unicode_constants_;
|
|
|
|
// Backing store used to store strings used as hashmap keys.
|
|
|
|
SequenceCollector<unsigned char> backing_store_;
|
|
|
|
HashMap map_;
|
|
|
|
// Buffer used for string->number->canonical string conversions.
|
|
|
|
char number_buffer_[kBufferSize];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// LiteralBuffer - Collector of chars of literals.
|
|
|
|
|
|
|
|
class LiteralBuffer {
|
2009-08-18 07:14:02 +00:00
|
|
|
public:
|
2014-03-12 14:03:25 +00:00
|
|
|
LiteralBuffer() : is_one_byte_(true), position_(0), backing_store_() { }
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
~LiteralBuffer() {
|
|
|
|
if (backing_store_.length() > 0) {
|
|
|
|
backing_store_.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
INLINE(void AddChar(uint32_t code_unit)) {
|
2011-09-08 13:06:44 +00:00
|
|
|
if (position_ >= backing_store_.length()) ExpandBuffer();
|
2014-03-12 14:03:25 +00:00
|
|
|
if (is_one_byte_) {
|
2013-01-09 10:30:54 +00:00
|
|
|
if (code_unit <= unibrow::Latin1::kMaxChar) {
|
2012-03-12 12:35:28 +00:00
|
|
|
backing_store_[position_] = static_cast<byte>(code_unit);
|
2013-01-09 10:30:54 +00:00
|
|
|
position_ += kOneByteSize;
|
2011-09-08 13:06:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-13 09:15:14 +00:00
|
|
|
ConvertToTwoByte();
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
2014-10-10 07:13:46 +00:00
|
|
|
if (code_unit <= unibrow::Utf16::kMaxNonSurrogateCharCode) {
|
|
|
|
*reinterpret_cast<uint16_t*>(&backing_store_[position_]) = code_unit;
|
|
|
|
position_ += kUC16Size;
|
|
|
|
} else {
|
|
|
|
*reinterpret_cast<uint16_t*>(&backing_store_[position_]) =
|
|
|
|
unibrow::Utf16::LeadSurrogate(code_unit);
|
|
|
|
position_ += kUC16Size;
|
2014-10-14 13:25:19 +00:00
|
|
|
if (position_ >= backing_store_.length()) ExpandBuffer();
|
2014-10-10 07:13:46 +00:00
|
|
|
*reinterpret_cast<uint16_t*>(&backing_store_[position_]) =
|
|
|
|
unibrow::Utf16::TrailSurrogate(code_unit);
|
|
|
|
position_ += kUC16Size;
|
|
|
|
}
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
bool is_one_byte() const { return is_one_byte_; }
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
bool is_contextual_keyword(Vector<const char> keyword) const {
|
2014-03-12 14:03:25 +00:00
|
|
|
return is_one_byte() && keyword.length() == position_ &&
|
2013-06-06 14:38:26 +00:00
|
|
|
(memcmp(keyword.start(), backing_store_.start(), position_) == 0);
|
|
|
|
}
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
Vector<const uint16_t> two_byte_literal() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!is_one_byte_);
|
|
|
|
DCHECK((position_ & 0x1) == 0);
|
2014-03-13 09:15:14 +00:00
|
|
|
return Vector<const uint16_t>(
|
|
|
|
reinterpret_cast<const uint16_t*>(backing_store_.start()),
|
2011-09-08 13:06:44 +00:00
|
|
|
position_ >> 1);
|
|
|
|
}
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
Vector<const uint8_t> one_byte_literal() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_one_byte_);
|
2014-03-13 09:15:14 +00:00
|
|
|
return Vector<const uint8_t>(
|
|
|
|
reinterpret_cast<const uint8_t*>(backing_store_.start()),
|
2011-09-08 13:06:44 +00:00
|
|
|
position_);
|
|
|
|
}
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
int length() const {
|
2014-03-12 14:03:25 +00:00
|
|
|
return is_one_byte_ ? position_ : (position_ >> 1);
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
void ReduceLength(int delta) {
|
|
|
|
position_ -= delta * (is_one_byte_ ? kOneByteSize : kUC16Size);
|
|
|
|
}
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
void Reset() {
|
|
|
|
position_ = 0;
|
2014-03-12 14:03:25 +00:00
|
|
|
is_one_byte_ = true;
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
2011-09-08 19:57:14 +00:00
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
Handle<String> Internalize(Isolate* isolate) const;
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
private:
|
|
|
|
static const int kInitialCapacity = 16;
|
|
|
|
static const int kGrowthFactory = 4;
|
|
|
|
static const int kMinConversionSlack = 256;
|
|
|
|
static const int kMaxGrowth = 1 * MB;
|
|
|
|
inline int NewCapacity(int min_capacity) {
|
|
|
|
int capacity = Max(min_capacity, backing_store_.length());
|
|
|
|
int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth);
|
|
|
|
return new_capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExpandBuffer() {
|
|
|
|
Vector<byte> new_store = Vector<byte>::New(NewCapacity(kInitialCapacity));
|
2014-05-27 07:57:22 +00:00
|
|
|
MemCopy(new_store.start(), backing_store_.start(), position_);
|
2011-09-08 13:06:44 +00:00
|
|
|
backing_store_.Dispose();
|
|
|
|
backing_store_ = new_store;
|
|
|
|
}
|
|
|
|
|
2014-03-13 09:15:14 +00:00
|
|
|
void ConvertToTwoByte() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_one_byte_);
|
2011-09-08 13:06:44 +00:00
|
|
|
Vector<byte> new_store;
|
|
|
|
int new_content_size = position_ * kUC16Size;
|
|
|
|
if (new_content_size >= backing_store_.length()) {
|
2012-03-12 12:35:28 +00:00
|
|
|
// Ensure room for all currently read code units as UC16 as well
|
|
|
|
// as the code unit about to be stored.
|
2011-09-08 13:06:44 +00:00
|
|
|
new_store = Vector<byte>::New(NewCapacity(new_content_size));
|
|
|
|
} else {
|
|
|
|
new_store = backing_store_;
|
|
|
|
}
|
2013-01-09 10:30:54 +00:00
|
|
|
uint8_t* src = backing_store_.start();
|
2014-03-13 09:15:14 +00:00
|
|
|
uint16_t* dst = reinterpret_cast<uint16_t*>(new_store.start());
|
2011-09-08 13:06:44 +00:00
|
|
|
for (int i = position_ - 1; i >= 0; i--) {
|
|
|
|
dst[i] = src[i];
|
|
|
|
}
|
|
|
|
if (new_store.start() != backing_store_.start()) {
|
|
|
|
backing_store_.Dispose();
|
|
|
|
backing_store_ = new_store;
|
|
|
|
}
|
|
|
|
position_ = new_content_size;
|
2014-03-12 14:03:25 +00:00
|
|
|
is_one_byte_ = false;
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 14:03:25 +00:00
|
|
|
bool is_one_byte_;
|
2011-09-08 13:06:44 +00:00
|
|
|
int position_;
|
|
|
|
Vector<byte> backing_store_;
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(LiteralBuffer);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2011-11-01 07:47:15 +00:00
|
|
|
// JavaScript Scanner.
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
class Scanner {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-11-01 07:47:15 +00:00
|
|
|
// Scoped helper for literal recording. Automatically drops the literal
|
|
|
|
// if aborting the scanning before it's complete.
|
2011-09-08 13:06:44 +00:00
|
|
|
class LiteralScope {
|
|
|
|
public:
|
2014-12-04 19:24:18 +00:00
|
|
|
explicit LiteralScope(Scanner* self) : scanner_(self), complete_(false) {
|
2011-11-01 07:47:15 +00:00
|
|
|
scanner_->StartLiteral();
|
|
|
|
}
|
|
|
|
~LiteralScope() {
|
|
|
|
if (!complete_) scanner_->DropLiteral();
|
|
|
|
}
|
|
|
|
void Complete() {
|
|
|
|
complete_ = true;
|
|
|
|
}
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Scanner* scanner_;
|
|
|
|
bool complete_;
|
|
|
|
};
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
// Representation of an interval of source positions.
|
2011-09-08 13:06:44 +00:00
|
|
|
struct Location {
|
|
|
|
Location(int b, int e) : beg_pos(b), end_pos(e) { }
|
|
|
|
Location() : beg_pos(0), end_pos(0) { }
|
|
|
|
|
|
|
|
bool IsValid() const {
|
|
|
|
return beg_pos >= 0 && end_pos >= beg_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Location invalid() { return Location(-1, -1); }
|
|
|
|
|
|
|
|
int beg_pos;
|
|
|
|
int end_pos;
|
|
|
|
};
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
// -1 is outside of the range of any real source code.
|
|
|
|
static const int kNoOctalLocation = -1;
|
|
|
|
|
|
|
|
explicit Scanner(UnicodeCache* scanner_contants);
|
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
void Initialize(Utf16CharacterStream* source);
|
2011-11-01 07:47:15 +00:00
|
|
|
|
|
|
|
// Returns the next token and advances input.
|
|
|
|
Token::Value Next();
|
|
|
|
// Returns the current token again.
|
|
|
|
Token::Value current_token() { return current_.token; }
|
2011-09-08 13:06:44 +00:00
|
|
|
// Returns the location information for the current token
|
2011-11-01 07:47:15 +00:00
|
|
|
// (the token last returned by Next()).
|
2011-09-08 13:06:44 +00:00
|
|
|
Location location() const { return current_.location; }
|
2014-03-13 08:29:31 +00:00
|
|
|
|
|
|
|
// Similar functions for the upcoming token.
|
|
|
|
|
|
|
|
// One token look-ahead (past the token returned by Next()).
|
|
|
|
Token::Value peek() const { return next_.token; }
|
|
|
|
|
|
|
|
Location peek_location() const { return next_.location; }
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
bool literal_contains_escapes() const {
|
|
|
|
Location location = current_.location;
|
|
|
|
int source_length = (location.end_pos - location.beg_pos);
|
|
|
|
if (current_.token == Token::STRING) {
|
|
|
|
// Subtract delimiters.
|
|
|
|
source_length -= 2;
|
|
|
|
}
|
|
|
|
return current_.literal_chars->length() != source_length;
|
|
|
|
}
|
2014-03-13 08:29:31 +00:00
|
|
|
bool is_literal_contextual_keyword(Vector<const char> keyword) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(current_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return current_.literal_chars->is_contextual_keyword(keyword);
|
2011-11-01 07:47:15 +00:00
|
|
|
}
|
2013-06-06 14:38:26 +00:00
|
|
|
bool is_next_contextual_keyword(Vector<const char> keyword) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(next_.literal_chars);
|
2013-06-06 14:38:26 +00:00
|
|
|
return next_.literal_chars->is_contextual_keyword(keyword);
|
|
|
|
}
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory);
|
|
|
|
const AstRawString* NextSymbol(AstValueFactory* ast_value_factory);
|
2014-12-03 14:17:16 +00:00
|
|
|
const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory);
|
2014-03-12 14:03:25 +00:00
|
|
|
|
|
|
|
double DoubleValue();
|
2014-10-24 15:02:29 +00:00
|
|
|
bool LiteralMatches(const char* data, int length, bool allow_escapes = true) {
|
2014-03-12 14:03:25 +00:00
|
|
|
if (is_literal_one_byte() &&
|
|
|
|
literal_length() == length &&
|
2014-10-24 15:02:29 +00:00
|
|
|
(allow_escapes || !literal_contains_escapes())) {
|
2014-03-13 09:15:14 +00:00
|
|
|
const char* token =
|
|
|
|
reinterpret_cast<const char*>(literal_one_byte_string().start());
|
|
|
|
return !strncmp(token, data, length);
|
2014-03-12 14:03:25 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-24 15:02:29 +00:00
|
|
|
inline bool UnescapedLiteralMatches(const char* data, int length) {
|
|
|
|
return LiteralMatches(data, length, false);
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:03:25 +00:00
|
|
|
void IsGetOrSet(bool* is_get, bool* is_set) {
|
|
|
|
if (is_literal_one_byte() &&
|
|
|
|
literal_length() == 3 &&
|
|
|
|
!literal_contains_escapes()) {
|
2014-03-13 09:15:14 +00:00
|
|
|
const char* token =
|
|
|
|
reinterpret_cast<const char*>(literal_one_byte_string().start());
|
2014-03-12 14:03:25 +00:00
|
|
|
*is_get = strncmp(token, "get", 3) == 0;
|
|
|
|
*is_set = !*is_get && strncmp(token, "set", 3) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 08:29:31 +00:00
|
|
|
int FindNumber(DuplicateFinder* finder, int value);
|
|
|
|
int FindSymbol(DuplicateFinder* finder, int value);
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2014-03-13 08:29:31 +00:00
|
|
|
UnicodeCache* unicode_cache() { return unicode_cache_; }
|
2011-11-01 07:47:15 +00:00
|
|
|
|
|
|
|
// Returns the location of the last seen octal literal.
|
|
|
|
Location octal_position() const { return octal_pos_; }
|
|
|
|
void clear_octal_position() { octal_pos_ = Location::invalid(); }
|
|
|
|
|
|
|
|
// Seek forward to the given position. This operation does not
|
|
|
|
// work in general, for instance when there are pushed back
|
|
|
|
// characters, but works for seeking forward until simple delimiter
|
|
|
|
// tokens, which is what it is used for.
|
|
|
|
void SeekForward(int pos);
|
|
|
|
|
|
|
|
bool HarmonyScoping() const {
|
|
|
|
return harmony_scoping_;
|
|
|
|
}
|
2012-02-08 10:53:58 +00:00
|
|
|
void SetHarmonyScoping(bool scoping) {
|
|
|
|
harmony_scoping_ = scoping;
|
|
|
|
}
|
|
|
|
bool HarmonyModules() const {
|
|
|
|
return harmony_modules_;
|
|
|
|
}
|
|
|
|
void SetHarmonyModules(bool modules) {
|
|
|
|
harmony_modules_ = modules;
|
2011-11-01 07:47:15 +00:00
|
|
|
}
|
2013-07-19 09:57:35 +00:00
|
|
|
bool HarmonyNumericLiterals() const {
|
|
|
|
return harmony_numeric_literals_;
|
|
|
|
}
|
|
|
|
void SetHarmonyNumericLiterals(bool numeric_literals) {
|
|
|
|
harmony_numeric_literals_ = numeric_literals;
|
|
|
|
}
|
2014-08-18 12:35:34 +00:00
|
|
|
bool HarmonyClasses() const {
|
|
|
|
return harmony_classes_;
|
|
|
|
}
|
|
|
|
void SetHarmonyClasses(bool classes) {
|
|
|
|
harmony_classes_ = classes;
|
|
|
|
}
|
2014-11-14 18:53:41 +00:00
|
|
|
bool HarmonyTemplates() const { return harmony_templates_; }
|
|
|
|
void SetHarmonyTemplates(bool templates) { harmony_templates_ = templates; }
|
2014-12-02 10:58:11 +00:00
|
|
|
bool HarmonyUnicode() const { return harmony_unicode_; }
|
|
|
|
void SetHarmonyUnicode(bool unicode) { harmony_unicode_ = unicode; }
|
2011-11-01 07:47:15 +00:00
|
|
|
|
|
|
|
// Returns true if there was a line terminator before the peek'ed token,
|
|
|
|
// possibly inside a multi-line comment.
|
|
|
|
bool HasAnyLineTerminatorBeforeNext() const {
|
|
|
|
return has_line_terminator_before_next_ ||
|
|
|
|
has_multiline_comment_before_next_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scans the input as a regular expression pattern, previous
|
|
|
|
// character(s) must be /(=). Returns true if a pattern is scanned.
|
|
|
|
bool ScanRegExpPattern(bool seen_equal);
|
|
|
|
// Returns true if regexp flags are scanned (always since flags can
|
|
|
|
// be empty).
|
|
|
|
bool ScanRegExpFlags();
|
|
|
|
|
2014-11-14 18:53:41 +00:00
|
|
|
// Scans the input as a template literal
|
2014-12-04 14:50:09 +00:00
|
|
|
Token::Value ScanTemplateStart();
|
|
|
|
Token::Value ScanTemplateContinuation();
|
2014-11-14 18:53:41 +00:00
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
const LiteralBuffer* source_url() const { return &source_url_; }
|
|
|
|
const LiteralBuffer* source_mapping_url() const {
|
|
|
|
return &source_mapping_url_;
|
|
|
|
}
|
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
bool IdentifierIsFutureStrictReserved(const AstRawString* string) const;
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
private:
|
2011-09-08 13:06:44 +00:00
|
|
|
// The current and look-ahead token.
|
|
|
|
struct TokenDesc {
|
|
|
|
Token::Value token;
|
|
|
|
Location location;
|
|
|
|
LiteralBuffer* literal_chars;
|
2014-12-03 14:17:16 +00:00
|
|
|
LiteralBuffer* raw_literal_chars;
|
2011-09-08 13:06:44 +00:00
|
|
|
};
|
|
|
|
|
2014-03-13 08:29:31 +00:00
|
|
|
static const int kCharacterLookaheadBufferSize = 1;
|
|
|
|
|
|
|
|
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
|
2014-12-04 19:24:18 +00:00
|
|
|
template <bool capture_raw>
|
2014-03-13 08:29:31 +00:00
|
|
|
uc32 ScanOctalEscape(uc32 c, int length);
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Call this after setting source_ to the input.
|
|
|
|
void Init() {
|
|
|
|
// Set c0_ (one character ahead)
|
|
|
|
STATIC_ASSERT(kCharacterLookaheadBufferSize == 1);
|
|
|
|
Advance();
|
|
|
|
// Initialize current_ to not refer to a literal.
|
|
|
|
current_.literal_chars = NULL;
|
2014-12-03 14:17:16 +00:00
|
|
|
current_.raw_literal_chars = NULL;
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Literal buffer support
|
|
|
|
inline void StartLiteral() {
|
|
|
|
LiteralBuffer* free_buffer = (current_.literal_chars == &literal_buffer1_) ?
|
|
|
|
&literal_buffer2_ : &literal_buffer1_;
|
|
|
|
free_buffer->Reset();
|
|
|
|
next_.literal_chars = free_buffer;
|
|
|
|
}
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
inline void StartRawLiteral() {
|
|
|
|
raw_literal_buffer_.Reset();
|
|
|
|
next_.raw_literal_chars = &raw_literal_buffer_;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:59:28 +00:00
|
|
|
INLINE(void AddLiteralChar(uc32 c)) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(next_.literal_chars);
|
2011-09-08 13:06:44 +00:00
|
|
|
next_.literal_chars->AddChar(c);
|
|
|
|
}
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
INLINE(void AddRawLiteralChar(uc32 c)) {
|
|
|
|
DCHECK_NOT_NULL(next_.raw_literal_chars);
|
|
|
|
next_.raw_literal_chars->AddChar(c);
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
INLINE(void ReduceRawLiteralLength(int delta)) {
|
|
|
|
DCHECK_NOT_NULL(next_.raw_literal_chars);
|
|
|
|
next_.raw_literal_chars->ReduceLength(delta);
|
|
|
|
}
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Stops scanning of a literal and drop the collected characters,
|
|
|
|
// e.g., due to an encountered error.
|
|
|
|
inline void DropLiteral() {
|
|
|
|
next_.literal_chars = NULL;
|
2014-12-03 14:17:16 +00:00
|
|
|
next_.raw_literal_chars = NULL;
|
2011-09-08 13:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void AddLiteralCharAdvance() {
|
|
|
|
AddLiteralChar(c0_);
|
|
|
|
Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Low-level scanning support.
|
2014-12-04 19:24:18 +00:00
|
|
|
template <bool capture_raw = false>
|
2014-10-10 07:13:46 +00:00
|
|
|
void Advance() {
|
2014-12-04 19:24:18 +00:00
|
|
|
if (capture_raw) {
|
2014-12-03 14:17:16 +00:00
|
|
|
AddRawLiteralChar(c0_);
|
|
|
|
}
|
2014-10-10 07:13:46 +00:00
|
|
|
c0_ = source_->Advance();
|
|
|
|
if (unibrow::Utf16::IsLeadSurrogate(c0_)) {
|
|
|
|
uc32 c1 = source_->Advance();
|
|
|
|
if (!unibrow::Utf16::IsTrailSurrogate(c1)) {
|
|
|
|
source_->PushBack(c1);
|
|
|
|
} else {
|
|
|
|
c0_ = unibrow::Utf16::CombineSurrogatePair(c0_, c1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
void PushBack(uc32 ch) {
|
2014-10-10 07:13:46 +00:00
|
|
|
if (ch > static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)) {
|
|
|
|
source_->PushBack(unibrow::Utf16::TrailSurrogate(c0_));
|
|
|
|
source_->PushBack(unibrow::Utf16::LeadSurrogate(c0_));
|
|
|
|
} else {
|
|
|
|
source_->PushBack(c0_);
|
|
|
|
}
|
2011-09-08 13:06:44 +00:00
|
|
|
c0_ = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Token::Value Select(Token::Value tok) {
|
|
|
|
Advance();
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_) {
|
|
|
|
Advance();
|
|
|
|
if (c0_ == next) {
|
|
|
|
Advance();
|
|
|
|
return then;
|
|
|
|
} else {
|
|
|
|
return else_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 08:29:31 +00:00
|
|
|
// Returns the literal string, if any, for the current token (the
|
|
|
|
// token last returned by Next()). The string is 0-terminated.
|
2014-12-03 14:17:16 +00:00
|
|
|
// Literal strings are collected for identifiers, strings, numbers as well
|
|
|
|
// as for template literals. For template literals we also collect the raw
|
|
|
|
// form.
|
2014-12-04 19:24:18 +00:00
|
|
|
// These functions only give the correct result if the literal was scanned
|
|
|
|
// when a LiteralScope object is alive.
|
2014-03-13 09:15:14 +00:00
|
|
|
Vector<const uint8_t> literal_one_byte_string() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(current_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return current_.literal_chars->one_byte_literal();
|
|
|
|
}
|
2014-03-13 09:15:14 +00:00
|
|
|
Vector<const uint16_t> literal_two_byte_string() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(current_.literal_chars);
|
2014-03-13 09:15:14 +00:00
|
|
|
return current_.literal_chars->two_byte_literal();
|
2014-03-13 08:29:31 +00:00
|
|
|
}
|
|
|
|
bool is_literal_one_byte() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(current_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return current_.literal_chars->is_one_byte();
|
|
|
|
}
|
|
|
|
int literal_length() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(current_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return current_.literal_chars->length();
|
|
|
|
}
|
|
|
|
// Returns the literal string for the next token (the token that
|
|
|
|
// would be returned if Next() were called).
|
2014-03-13 09:15:14 +00:00
|
|
|
Vector<const uint8_t> next_literal_one_byte_string() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(next_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return next_.literal_chars->one_byte_literal();
|
|
|
|
}
|
2014-03-13 09:15:14 +00:00
|
|
|
Vector<const uint16_t> next_literal_two_byte_string() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(next_.literal_chars);
|
2014-03-13 09:15:14 +00:00
|
|
|
return next_.literal_chars->two_byte_literal();
|
2014-03-13 08:29:31 +00:00
|
|
|
}
|
|
|
|
bool is_next_literal_one_byte() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NOT_NULL(next_.literal_chars);
|
2014-03-13 08:29:31 +00:00
|
|
|
return next_.literal_chars->is_one_byte();
|
|
|
|
}
|
2014-12-03 14:17:16 +00:00
|
|
|
Vector<const uint8_t> raw_literal_one_byte_string() {
|
|
|
|
DCHECK_NOT_NULL(current_.raw_literal_chars);
|
|
|
|
return current_.raw_literal_chars->one_byte_literal();
|
|
|
|
}
|
|
|
|
Vector<const uint16_t> raw_literal_two_byte_string() {
|
|
|
|
DCHECK_NOT_NULL(current_.raw_literal_chars);
|
|
|
|
return current_.raw_literal_chars->two_byte_literal();
|
2014-03-13 08:29:31 +00:00
|
|
|
}
|
2014-12-03 14:17:16 +00:00
|
|
|
bool is_raw_literal_one_byte() {
|
|
|
|
DCHECK_NOT_NULL(current_.raw_literal_chars);
|
|
|
|
return current_.raw_literal_chars->is_one_byte();
|
|
|
|
}
|
|
|
|
|
2014-12-04 19:24:18 +00:00
|
|
|
template <bool capture_raw>
|
2011-09-08 13:06:44 +00:00
|
|
|
uc32 ScanHexNumber(int expected_length);
|
2014-12-02 10:58:11 +00:00
|
|
|
// Scan a number of any length but not bigger than max_value. For example, the
|
|
|
|
// number can be 000000001, so it's very long in characters but its value is
|
|
|
|
// small.
|
2014-12-04 19:24:18 +00:00
|
|
|
template <bool capture_raw>
|
2014-12-02 10:58:11 +00:00
|
|
|
uc32 ScanUnlimitedLengthHexNumber(int max_value);
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
// Scans a single JavaScript token.
|
|
|
|
void Scan();
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
bool SkipWhiteSpace();
|
|
|
|
Token::Value SkipSingleLineComment();
|
2014-07-02 07:01:31 +00:00
|
|
|
Token::Value SkipSourceURLComment();
|
|
|
|
void TryToParseSourceURLComment();
|
2011-09-08 13:06:44 +00:00
|
|
|
Token::Value SkipMultiLineComment();
|
2011-11-01 07:47:15 +00:00
|
|
|
// Scans a possible HTML comment -- begins with '<!'.
|
|
|
|
Token::Value ScanHtmlComment();
|
2011-09-08 13:06:44 +00:00
|
|
|
|
|
|
|
void ScanDecimalDigits();
|
|
|
|
Token::Value ScanNumber(bool seen_period);
|
|
|
|
Token::Value ScanIdentifierOrKeyword();
|
|
|
|
Token::Value ScanIdentifierSuffix(LiteralScope* literal);
|
|
|
|
|
|
|
|
Token::Value ScanString();
|
|
|
|
|
2012-04-16 15:54:02 +00:00
|
|
|
// Scans an escape-sequence which is part of a string and adds the
|
|
|
|
// decoded character to the current literal. Returns true if a pattern
|
|
|
|
// is scanned.
|
2014-12-18 19:41:37 +00:00
|
|
|
template <bool capture_raw, bool in_template_literal>
|
2012-04-16 15:54:02 +00:00
|
|
|
bool ScanEscape();
|
2014-12-18 19:41:37 +00:00
|
|
|
|
2012-04-16 15:54:02 +00:00
|
|
|
// Decodes a Unicode escape-sequence which is part of an identifier.
|
2011-09-08 13:06:44 +00:00
|
|
|
// If the escape sequence cannot be decoded the result is kBadChar.
|
|
|
|
uc32 ScanIdentifierUnicodeEscape();
|
2014-12-02 10:58:11 +00:00
|
|
|
// Helper for the above functions.
|
2014-12-04 19:24:18 +00:00
|
|
|
template <bool capture_raw>
|
2014-12-02 10:58:11 +00:00
|
|
|
uc32 ScanUnicodeEscape();
|
2011-09-08 13:06:44 +00:00
|
|
|
|
2014-12-04 14:50:09 +00:00
|
|
|
Token::Value ScanTemplateSpan();
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
// Return the current source position.
|
|
|
|
int source_pos() {
|
2015-02-05 07:54:24 +00:00
|
|
|
return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize;
|
2011-11-01 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeCache* unicode_cache_;
|
|
|
|
|
|
|
|
// Buffers collecting literal strings, numbers, etc.
|
|
|
|
LiteralBuffer literal_buffer1_;
|
|
|
|
LiteralBuffer literal_buffer2_;
|
|
|
|
|
2014-07-02 07:01:31 +00:00
|
|
|
// Values parsed from magic comments.
|
|
|
|
LiteralBuffer source_url_;
|
|
|
|
LiteralBuffer source_mapping_url_;
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
// Buffer to store raw string values
|
|
|
|
LiteralBuffer raw_literal_buffer_;
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
TokenDesc current_; // desc for current token (as returned by Next())
|
|
|
|
TokenDesc next_; // desc for next token (one token look-ahead)
|
|
|
|
|
2012-03-12 12:35:28 +00:00
|
|
|
// Input stream. Must be initialized to an Utf16CharacterStream.
|
|
|
|
Utf16CharacterStream* source_;
|
2011-11-01 07:47:15 +00:00
|
|
|
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Start position of the octal literal last scanned.
|
|
|
|
Location octal_pos_;
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
// One Unicode character look-ahead; c0_ < 0 at the end of the input.
|
|
|
|
uc32 c0_;
|
|
|
|
|
2011-09-08 13:06:44 +00:00
|
|
|
// Whether there is a line terminator whitespace character after
|
|
|
|
// the current token, and before the next. Does not count newlines
|
|
|
|
// inside multiline comments.
|
|
|
|
bool has_line_terminator_before_next_;
|
|
|
|
// Whether there is a multi-line comment that contains a
|
|
|
|
// line-terminator after the current token, and before the next.
|
|
|
|
bool has_multiline_comment_before_next_;
|
2012-02-08 10:53:58 +00:00
|
|
|
// Whether we scan 'let' as a keyword for harmony block-scoped let bindings.
|
2011-10-12 12:23:06 +00:00
|
|
|
bool harmony_scoping_;
|
2012-02-08 10:53:58 +00:00
|
|
|
// Whether we scan 'module', 'import', 'export' as keywords.
|
|
|
|
bool harmony_modules_;
|
2013-07-19 09:57:35 +00:00
|
|
|
// Whether we scan 0o777 and 0b111 as numbers.
|
|
|
|
bool harmony_numeric_literals_;
|
2014-09-16 22:15:39 +00:00
|
|
|
// Whether we scan 'class', 'extends', 'static' and 'super' as keywords.
|
2014-08-18 12:35:34 +00:00
|
|
|
bool harmony_classes_;
|
2014-11-14 18:53:41 +00:00
|
|
|
// Whether we scan TEMPLATE_SPAN and TEMPLATE_TAIL
|
|
|
|
bool harmony_templates_;
|
2014-12-02 10:58:11 +00:00
|
|
|
// Whether we allow \u{xxxxx}.
|
|
|
|
bool harmony_unicode_;
|
2010-11-18 13:07:02 +00:00
|
|
|
};
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_SCANNER_H_
|