| OLD | NEW |
| 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 24 matching lines...) Expand all Loading... |
| 35 #include "api.h" | 35 #include "api.h" |
| 36 #include "ast.h" | 36 #include "ast.h" |
| 37 #include "char-predicates-inl.h" | 37 #include "char-predicates-inl.h" |
| 38 #include "messages.h" | 38 #include "messages.h" |
| 39 #include "platform.h" | 39 #include "platform.h" |
| 40 #include "runtime.h" | 40 #include "runtime.h" |
| 41 #include "scanner-character-streams.h" | 41 #include "scanner-character-streams.h" |
| 42 #include "scopeinfo.h" | 42 #include "scopeinfo.h" |
| 43 #include "string-stream.h" | 43 #include "string-stream.h" |
| 44 #include "scanner.h" | 44 #include "scanner.h" |
| 45 #include "lexer.h" |
| 45 | 46 |
| 46 using namespace v8::internal; | 47 using namespace v8::internal; |
| 47 | 48 |
| 48 Handle<String> ReadFile(const char* name, Isolate* isolate) { | 49 Handle<String> ReadFile(const char* name, Isolate* isolate) { |
| 49 FILE* file = fopen(name, "rb"); | 50 FILE* file = fopen(name, "rb"); |
| 50 if (file == NULL) return Handle<String>(); | 51 if (file == NULL) return Handle<String>(); |
| 51 | 52 |
| 52 fseek(file, 0, SEEK_END); | 53 fseek(file, 0, SEEK_END); |
| 53 int size = ftell(file); | 54 int size = ftell(file); |
| 54 rewind(file); | 55 rewind(file); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 source, 0, source->length()); | 78 source, 0, source->length()); |
| 78 scanner_->Initialize(stream_); | 79 scanner_->Initialize(stream_); |
| 79 } | 80 } |
| 80 | 81 |
| 81 ~BaselineScanner() { | 82 ~BaselineScanner() { |
| 82 delete scanner_; | 83 delete scanner_; |
| 83 delete stream_; | 84 delete stream_; |
| 84 delete unicode_cache_; | 85 delete unicode_cache_; |
| 85 } | 86 } |
| 86 | 87 |
| 87 Token::Value Next() { | 88 Token::Value Next(int* beg_pos, int* end_pos) { |
| 88 return scanner_->Next(); | 89 Token::Value res = scanner_->Next(); |
| 89 } | 90 *beg_pos = scanner_->location().beg_pos; |
| 90 | 91 *end_pos = scanner_->location().end_pos; |
| 91 Scanner::Location Location() { | 92 return res; |
| 92 return scanner_->location(); | |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 UnicodeCache* unicode_cache_; | 96 UnicodeCache* unicode_cache_; |
| 97 Scanner* scanner_; | 97 Scanner* scanner_; |
| 98 GenericStringUtf16CharacterStream* stream_; | 98 GenericStringUtf16CharacterStream* stream_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 | 101 |
| 102 class ExperimentalScanner { | |
| 103 explicit ExperimentalScanner(const char* fname); | |
| 104 ~ExperimentalScanner(); | |
| 105 Token::Value Next(); | |
| 106 Scanner::Location Location(); | |
| 107 }; | |
| 108 | |
| 109 | |
| 110 int main(int argc, char* argv[]) { | 102 int main(int argc, char* argv[]) { |
| 111 v8::V8::InitializeICU(); | 103 v8::V8::InitializeICU(); |
| 112 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 104 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 113 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 105 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 114 { | 106 { |
| 115 v8::HandleScope handle_scope(isolate); | 107 v8::HandleScope handle_scope(isolate); |
| 116 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
| 117 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 109 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
| 118 ASSERT(!context.IsEmpty()); | 110 ASSERT(!context.IsEmpty()); |
| 119 { | 111 { |
| 120 v8::Context::Scope scope(context); | 112 v8::Context::Scope scope(context); |
| 121 Isolate* isolate = Isolate::Current(); | 113 Isolate* isolate = Isolate::Current(); |
| 122 HandleScope handle_scope(isolate); | 114 HandleScope handle_scope(isolate); |
| 123 BaselineScanner baseline(argv[1], isolate); | 115 BaselineScanner baseline(argv[1], isolate); |
| 124 Token::Value current; | 116 ExperimentalScanner experimental(argv[1]); |
| 125 while ((current = baseline.Next()) != Token::EOS) { | 117 Token::Value expected_token, actual_token; |
| 126 printf("%11s => (%d, %d)\n", | 118 int expected_beg, expected_end, actual_beg, actual_end; |
| 127 Token::Name(current), | 119 do { |
| 128 baseline.Location().beg_pos, | 120 expected_token = baseline.Next(&expected_beg, &expected_end); |
| 129 baseline.Location().end_pos); | 121 actual_token = experimental.Next(&actual_beg, &actual_end); |
| 130 } | 122 printf("=> %11s at (%d, %d)\n", |
| 123 Token::Name(actual_token), |
| 124 actual_beg, actual_end); |
| 125 if (expected_token != actual_token || |
| 126 expected_beg != actual_beg || |
| 127 expected_end != actual_end) { |
| 128 printf("MISMATCH:\n"); |
| 129 printf("Expected: %s at (%d, %d)\n", |
| 130 Token::Name(expected_token), |
| 131 expected_beg, expected_end); |
| 132 printf("Actual: %s at (%d, %d)\n", |
| 133 Token::Name(actual_token), |
| 134 actual_beg, actual_end); |
| 135 return 1; |
| 136 } |
| 137 } while (actual_token != Token::EOS); |
| 131 } | 138 } |
| 132 } | 139 } |
| 133 v8::V8::Dispose(); | 140 v8::V8::Dispose(); |
| 134 return 0; | 141 return 0; |
| 135 } | 142 } |
| OLD | NEW |