Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: src/lexer/lexer-shell.cc

Issue 206203004: Experimental parser: eos test prints less stuff (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 printf(is_one_byte ? " %02x" : " %04x", literal[i]); 274 printf(is_one_byte ? " %02x" : " %04x", literal[i]);
275 } 275 }
276 printf(" (is_one_byte: %d)", is_one_byte); 276 printf(" (is_one_byte: %d)", is_one_byte);
277 } 277 }
278 if (octal_beg >= 0) { 278 if (octal_beg >= 0) {
279 printf(" (last octal start: %d)", octal_beg); 279 printf(" (last octal start: %d)", octal_beg);
280 } 280 }
281 printf("\n"); 281 printf("\n");
282 } 282 }
283 283
284 bool operator==(const TokenWithLocation& that) {
285 if (this->beg != that.beg ||
286 this->end != that.end ||
287 this->is_one_byte != that.is_one_byte ||
288 this->literal_length != that.literal_length ||
289 this->octal_beg != that.octal_beg ||
290 this->octal_end != that.octal_end
291 ) {
292 return false;
293 }
294 for (int i = 0; i < literal_length; i++) {
295 if (this->literal[i] != that.literal[i]) return false;
296 }
297 return true;
298 }
299
284 private: 300 private:
285 Token::Value value; 301 Token::Value value;
286 int beg; 302 int beg;
287 int end; 303 int end;
288 bool is_one_byte; 304 bool is_one_byte;
289 SmartArrayPointer<uint16_t> literal; 305 SmartArrayPointer<uint16_t> literal;
290 int literal_length; 306 int literal_length;
291 // The location of the latest octal position when the token was seen. 307 // The location of the latest octal position when the token was seen.
292 int octal_beg; 308 int octal_beg;
293 int octal_end; 309 int octal_end;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 364 }
349 if (settings.print_tokens) { 365 if (settings.print_tokens) {
350 tokens->push_back(new TokenWithLocation(token, &scanner, literal)); 366 tokens->push_back(new TokenWithLocation(token, &scanner, literal));
351 } 367 }
352 if (token == Token::ILLEGAL && settings.break_after_illegal) break; 368 if (token == Token::ILLEGAL && settings.break_after_illegal) break;
353 } while (token != Token::EOS); 369 } while (token != Token::EOS);
354 return timer.Elapsed(); 370 return timer.Elapsed();
355 } 371 }
356 372
357 373
374 static void DumpTokens(const LexerShellSettings& settings,
375 TokenVector* first_tokens,
376 TokenVector* eos_tokens) {
377 if (!settings.print_tokens) return;
378 bool first_run = eos_tokens->size() == 0;
379 if (first_run && !settings.print_tokens_for_compare) {
380 printf("No of tokens:\t%d\n", static_cast<int>(first_tokens->size()));
381 }
382 if (first_run) {
383 for (size_t i = 0; i < first_tokens->size(); ++i) {
384 first_tokens->at(i)->Print(settings.print_tokens_for_compare);
385 }
386 return;
387 }
388 for (size_t i = 0; i < eos_tokens->size(); ++i) {
389 if (i <= first_tokens->size() &&
390 eos_tokens->at(i)->operator==(*first_tokens->at(i))) {
391 continue;
392 }
393 eos_tokens->at(i)->Print(settings.print_tokens_for_compare);
394 }
395 }
396
397
398 static void Clear(TokenVector* tokens) {
399 for (size_t i = 0; i < tokens->size(); ++i) delete tokens->at(i);
400 tokens->clear();
401 }
402
403
358 static void Run(const LexerShellSettings& settings, 404 static void Run(const LexerShellSettings& settings,
359 const FileData& file_data) { 405 const FileData& file_data) {
360 Isolate* isolate = Isolate::Current(); 406 Isolate* isolate = Isolate::Current();
361 HandleScope handle_scope(isolate); 407 HandleScope handle_scope(isolate);
362 v8::Context::Scope scope(v8::Context::New(v8::Isolate::GetCurrent())); 408 v8::Context::Scope scope(v8::Context::New(v8::Isolate::GetCurrent()));
363 double total_time = 0; 409 double total_time = 0;
364 std::vector<TokenWithLocation*> tokens; 410 TokenVector first_tokens;
411 TokenVector eos_tokens;
365 const uint16_t* const buffer = file_data.data; 412 const uint16_t* const buffer = file_data.data;
366 const uint8_t* const char_data = reinterpret_cast<const uint8_t*>(buffer); 413 const uint8_t* const char_data = reinterpret_cast<const uint8_t*>(buffer);
367 for (unsigned truncate_by = 0; 414 for (unsigned truncate_by = 0;
368 truncate_by <= file_data.length_in_bytes; 415 truncate_by <= file_data.length_in_bytes;
369 truncate_by += file_data.encoding == UTF16 ? 2 : 1) { 416 truncate_by += file_data.encoding == UTF16 ? 2 : 1) {
370 if (settings.print_tokens && !settings.print_tokens_for_compare) { 417 if (settings.print_tokens && !settings.print_tokens_for_compare) {
371 printf("Processing file %s, truncating by %d bytes\n", 418 printf("Processing file %s, truncating by %d bytes\n",
372 file_data.file_name, truncate_by); 419 file_data.file_name, truncate_by);
373 } 420 }
374 HandleScope handle_scope(isolate); 421 HandleScope handle_scope(isolate);
375 const uint8_t* buffer_end = 422 const uint8_t* buffer_end =
376 &char_data[file_data.length_in_bytes] - truncate_by; 423 &char_data[file_data.length_in_bytes] - truncate_by;
424 TokenVector* tokens = truncate_by == 0 ? &first_tokens : &eos_tokens;
377 TimeDelta delta = RunLexer( 425 TimeDelta delta = RunLexer(
378 buffer, buffer_end, isolate, file_data.encoding, settings, &tokens); 426 buffer, buffer_end, isolate, file_data.encoding, settings, tokens);
379 total_time += delta.InMillisecondsF(); 427 total_time += delta.InMillisecondsF();
380 // Dump tokens. 428 // Dump tokens.
381 if (settings.print_tokens) { 429 DumpTokens(settings, &first_tokens, &eos_tokens);
382 if (!settings.print_tokens_for_compare) { 430 if (!settings.eos_test) break;
383 printf("No of tokens:\t%d\n", static_cast<int>(tokens.size()));
384 }
385 for (size_t i = 0; i < tokens.size(); ++i) {
386 tokens[i]->Print(settings.print_tokens_for_compare);
387 }
388 }
389 // Destroy tokens. 431 // Destroy tokens.
390 for (size_t i = 0; i < tokens.size(); ++i) { 432 Clear(&eos_tokens);
391 delete tokens[i];
392 }
393 tokens.clear();
394 if (!settings.eos_test) break;
395 } 433 }
434 // Destroy tokens.
435 Clear(&first_tokens);
396 if (!settings.print_tokens_for_compare) { 436 if (!settings.print_tokens_for_compare) {
397 printf("RunTime: %.f ms\n", total_time); 437 printf("RunTime: %.f ms\n", total_time);
398 } 438 }
399 } 439 }
400 440
401 441
402 int main(int argc, char* argv[]) { 442 int main(int argc, char* argv[]) {
403 v8::V8::InitializeICU(); 443 v8::V8::InitializeICU();
404 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 444 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
405 std::string file_name; 445 std::string file_name;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 file_name = std::string(argv[i]); 483 file_name = std::string(argv[i]);
444 } 484 }
445 } 485 }
446 CHECK_NE(0, file_name.size()); 486 CHECK_NE(0, file_name.size());
447 FileData file_data = ReadFile(file_name.c_str(), settings); 487 FileData file_data = ReadFile(file_name.c_str(), settings);
448 Run(settings, file_data); 488 Run(settings, file_data);
449 delete[] file_data.data; 489 delete[] file_data.data;
450 v8::V8::Dispose(); 490 v8::V8::Dispose();
451 return 0; 491 return 0;
452 } 492 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698