[asm.js] Use token position instead of stream position.
This switches the parser to use token positions (i.e. {Position}) instead of stream positions (i.e. {GetPosition}) everywhere. Access to the latter is being removed as it is unsupported when the scanner is in rewind state anyways. This prevents "skipping" a token when seeking. R=bradnelson@chromium.org BUG=v8:6127 Change-Id: I9c13dd20a981061a2bccc4fb57e5c57d2a64ac5c Reviewed-on: https://chromium-review.googlesource.com/480300 Reviewed-by: Brad Nelson <bradnelson@chromium.org> Commit-Queue: Brad Nelson <bradnelson@chromium.org> Cr-Commit-Position: refs/heads/master@{#44699}
This commit is contained in:
parent
f4a57545e8
commit
5930e0ab39
@ -29,17 +29,17 @@ namespace wasm {
|
||||
#define FAIL_AND_RETURN(ret, msg) \
|
||||
failed_ = true; \
|
||||
failure_message_ = msg; \
|
||||
failure_location_ = scanner_.GetPosition(); \
|
||||
failure_location_ = static_cast<int>(scanner_.Position()); \
|
||||
if (FLAG_trace_asm_parser) { \
|
||||
PrintF("[asm.js failure: %s, token: '%s', see: %s:%d]\n", msg, \
|
||||
scanner_.Name(scanner_.Token()).c_str(), __FILE__, __LINE__); \
|
||||
} \
|
||||
return ret;
|
||||
#else
|
||||
#define FAIL_AND_RETURN(ret, msg) \
|
||||
failed_ = true; \
|
||||
failure_message_ = msg; \
|
||||
failure_location_ = scanner_.GetPosition(); \
|
||||
#define FAIL_AND_RETURN(ret, msg) \
|
||||
failed_ = true; \
|
||||
failure_message_ = msg; \
|
||||
failure_location_ = static_cast<int>(scanner_.Position()); \
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
@ -1302,7 +1302,8 @@ void AsmJsParser::SwitchStatement() {
|
||||
pending_label_ = 0;
|
||||
// TODO(bradnelson): Make less weird.
|
||||
std::vector<int32_t> cases;
|
||||
GatherCases(&cases); // Skips { implicitly.
|
||||
GatherCases(&cases);
|
||||
EXPECT_TOKEN('{');
|
||||
size_t count = cases.size() + 1;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
BareBegin(BlockKind::kOther);
|
||||
@ -1958,17 +1959,17 @@ AsmType* AsmJsParser::BitwiseORExpression() {
|
||||
call_coercion_deferred_ = nullptr;
|
||||
// TODO(bradnelson): Make it prettier.
|
||||
bool zero = false;
|
||||
int old_pos;
|
||||
size_t old_pos;
|
||||
size_t old_code;
|
||||
if (a->IsA(AsmType::Intish()) && CheckForZero()) {
|
||||
old_pos = scanner_.GetPosition();
|
||||
old_pos = scanner_.Position();
|
||||
old_code = current_function_builder_->GetPosition();
|
||||
scanner_.Rewind();
|
||||
zero = true;
|
||||
}
|
||||
RECURSEn(b = BitwiseXORExpression());
|
||||
// Handle |0 specially.
|
||||
if (zero && old_pos == scanner_.GetPosition()) {
|
||||
if (zero && old_pos == scanner_.Position()) {
|
||||
current_function_builder_->StashCode(nullptr, old_code);
|
||||
a = AsmType::Signed();
|
||||
continue;
|
||||
@ -2440,7 +2441,7 @@ void AsmJsParser::ValidateFloatCoercion() {
|
||||
}
|
||||
|
||||
void AsmJsParser::GatherCases(std::vector<int32_t>* cases) {
|
||||
int start = scanner_.GetPosition();
|
||||
size_t start = scanner_.Position();
|
||||
int depth = 0;
|
||||
for (;;) {
|
||||
if (Peek('{')) {
|
||||
|
@ -34,7 +34,7 @@ class AsmJsParser {
|
||||
explicit AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script,
|
||||
int start, int end);
|
||||
bool Run();
|
||||
const char* failure_message() const { return failure_message_.c_str(); }
|
||||
const char* failure_message() const { return failure_message_; }
|
||||
int failure_location() const { return failure_location_; }
|
||||
WasmModuleBuilder* module_builder() { return module_builder_; }
|
||||
const AsmTyper::StdlibSet* stdlib_uses() const { return &stdlib_uses_; }
|
||||
@ -115,7 +115,7 @@ class AsmJsParser {
|
||||
|
||||
// Error Handling related
|
||||
bool failed_;
|
||||
std::string failure_message_;
|
||||
const char* failure_message_;
|
||||
int failure_location_;
|
||||
|
||||
// Module Related.
|
||||
|
@ -210,12 +210,7 @@ std::string AsmJsScanner::Name(token_t token) const {
|
||||
}
|
||||
#endif
|
||||
|
||||
int AsmJsScanner::GetPosition() const {
|
||||
DCHECK(!rewind_);
|
||||
return static_cast<int>(stream_->pos());
|
||||
}
|
||||
|
||||
void AsmJsScanner::Seek(int pos) {
|
||||
void AsmJsScanner::Seek(size_t pos) {
|
||||
stream_->Seek(pos);
|
||||
preceding_token_ = kUninitialized;
|
||||
token_ = kUninitialized;
|
||||
|
@ -62,10 +62,9 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
|
||||
std::string Name(token_t token) const;
|
||||
#endif
|
||||
|
||||
// Get current position (to use with Seek).
|
||||
int GetPosition() const;
|
||||
// Restores old position (token after that position).
|
||||
void Seek(int pos);
|
||||
// Restores old position (token after that position). Note that it is not
|
||||
// allowed to rewind right after a seek, because previous tokens are unknown.
|
||||
void Seek(size_t pos);
|
||||
|
||||
// Select whether identifiers are resolved in global or local scope,
|
||||
// and which scope new identifiers are added to.
|
||||
|
@ -254,7 +254,7 @@ TEST_F(AsmJsScannerTest, TrailingCComment) {
|
||||
TEST_F(AsmJsScannerTest, Seeking) {
|
||||
SetupSource("var eval do arguments function break\n");
|
||||
Skip(TOK(var));
|
||||
int old_pos = scanner.GetPosition();
|
||||
size_t old_pos = scanner.Position();
|
||||
Skip(TOK(eval));
|
||||
Skip(TOK(do));
|
||||
Skip(TOK(arguments));
|
||||
@ -262,6 +262,7 @@ TEST_F(AsmJsScannerTest, Seeking) {
|
||||
Skip(TOK(arguments));
|
||||
scanner.Rewind();
|
||||
scanner.Seek(old_pos);
|
||||
Skip(TOK(eval));
|
||||
Skip(TOK(do));
|
||||
Skip(TOK(arguments));
|
||||
Skip(TOK(function));
|
||||
|
Loading…
Reference in New Issue
Block a user