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

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

Issue 26906008: Use utf8 instead of ascii in baseline scanner. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 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 28 matching lines...) Expand all
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 #include "lexer.h"
46 46
47 using namespace v8::internal; 47 using namespace v8::internal;
48 48
49 Handle<String> ReadFile(const char* name, Isolate* isolate) { 49 const byte* ReadFile(const char* name, Isolate* isolate, int* size) {
50 FILE* file = fopen(name, "rb"); 50 FILE* file = fopen(name, "rb");
51 if (file == NULL) return Handle<String>(); 51 *size = 0;
52 if (file == NULL) return NULL;
52 53
53 fseek(file, 0, SEEK_END); 54 fseek(file, 0, SEEK_END);
54 int size = ftell(file); 55 *size = ftell(file);
55 rewind(file); 56 rewind(file);
56 57
57 uint8_t* chars = new uint8_t[size + 1]; 58 byte* chars = new byte[*size + 1];
58 chars[size] = '\0'; 59 chars[*size] = 0;
59 for (int i = 0; i < size;) { 60 for (int i = 0; i < *size;) {
60 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); 61 int read = static_cast<int>(fread(&chars[i], 1, *size - i, file));
61 i += read; 62 i += read;
62 } 63 }
63 fclose(file); 64 fclose(file);
64 Handle<String> result = isolate->factory()->NewStringFromOneByte( 65 return chars;
65 Vector<const uint8_t>(chars, size));
66 delete[] chars;
67 return result;
68 } 66 }
69 67
70 68
71 class BaselineScanner { 69 class BaselineScanner {
72 public: 70 public:
73 BaselineScanner(const char* fname, Isolate* isolate) { 71 BaselineScanner(const char* fname, Isolate* isolate) {
74 Handle<String> source = ReadFile(fname, isolate); 72 int length = 0;
73 source_ = ReadFile(fname, isolate, &length);
75 unicode_cache_ = new UnicodeCache(); 74 unicode_cache_ = new UnicodeCache();
76 scanner_ = new Scanner(unicode_cache_); 75 scanner_ = new Scanner(unicode_cache_);
77 stream_ = new GenericStringUtf16CharacterStream( 76 stream_ = new Utf8ToUtf16CharacterStream(source_, length);
78 source, 0, source->length());
79 scanner_->Initialize(stream_); 77 scanner_->Initialize(stream_);
80 } 78 }
81 79
82 ~BaselineScanner() { 80 ~BaselineScanner() {
83 delete scanner_; 81 delete scanner_;
84 delete stream_; 82 delete stream_;
85 delete unicode_cache_; 83 delete unicode_cache_;
84 delete source_;
86 } 85 }
87 86
88 Token::Value Next(int* beg_pos, int* end_pos) { 87 Token::Value Next(int* beg_pos, int* end_pos) {
89 Token::Value res = scanner_->Next(); 88 Token::Value res = scanner_->Next();
90 *beg_pos = scanner_->location().beg_pos; 89 *beg_pos = scanner_->location().beg_pos;
91 *end_pos = scanner_->location().end_pos; 90 *end_pos = scanner_->location().end_pos;
92 return res; 91 return res;
93 } 92 }
94 93
95 private: 94 private:
96 UnicodeCache* unicode_cache_; 95 UnicodeCache* unicode_cache_;
97 Scanner* scanner_; 96 Scanner* scanner_;
98 GenericStringUtf16CharacterStream* stream_; 97 const byte* source_;
98 Utf8ToUtf16CharacterStream* stream_;
99 }; 99 };
100 100
101 101
102 int main(int argc, char* argv[]) { 102 int main(int argc, char* argv[]) {
103 v8::V8::InitializeICU(); 103 v8::V8::InitializeICU();
104 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 104 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
105 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 105 v8::Isolate* isolate = v8::Isolate::GetCurrent();
106 { 106 {
107 v8::HandleScope handle_scope(isolate); 107 v8::HandleScope handle_scope(isolate);
108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
(...skipping 24 matching lines...) Expand all
133 Token::Name(actual_token), 133 Token::Name(actual_token),
134 actual_beg, actual_end); 134 actual_beg, actual_end);
135 return 1; 135 return 1;
136 } 136 }
137 } while (actual_token != Token::EOS); 137 } while (actual_token != Token::EOS);
138 } 138 }
139 } 139 }
140 v8::V8::Dispose(); 140 v8::V8::Dispose();
141 return 0; 141 return 0;
142 } 142 }
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