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

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

Issue 91213004: Fix setting of has_escape for first char of identifier. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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 | src/lexer/lexer_py.re » ('j') | 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 UnicodeCache* unicode_cache_; 162 UnicodeCache* unicode_cache_;
163 const byte* source_; 163 const byte* source_;
164 BufferedUtf16CharacterStream* stream_; 164 BufferedUtf16CharacterStream* stream_;
165 }; 165 };
166 166
167 167
168 struct TokenWithLocation { 168 struct TokenWithLocation {
169 Token::Value value; 169 Token::Value value;
170 size_t beg; 170 size_t beg;
171 size_t end; 171 size_t end;
172 std::string ascii_literal; 172 std::vector<int> literal;
173 std::wstring utf16_literal; 173 bool is_ascii;
174 TokenWithLocation() : value(Token::ILLEGAL), beg(0), end(0) { } 174 TokenWithLocation() :
175 value(Token::ILLEGAL), beg(0), end(0), is_ascii(false) { }
175 TokenWithLocation(Token::Value value, size_t beg, size_t end) : 176 TokenWithLocation(Token::Value value, size_t beg, size_t end) :
176 value(value), beg(beg), end(end) { } 177 value(value), beg(beg), end(end), is_ascii(false) { }
177 bool operator==(const TokenWithLocation& other) { 178 bool operator==(const TokenWithLocation& other) {
178 return value == other.value && beg == other.beg && end == other.end && 179 return value == other.value && beg == other.beg && end == other.end &&
179 ascii_literal == other.ascii_literal && 180 literal == other.literal && is_ascii == other.is_ascii;
180 utf16_literal == other.utf16_literal;
181 } 181 }
182 bool operator!=(const TokenWithLocation& other) { 182 bool operator!=(const TokenWithLocation& other) {
183 return !(*this == other); 183 return !(*this == other);
184 } 184 }
185 void Print(const char* prefix) const { 185 void Print(const char* prefix) const {
186 printf("%s %11s at (%d, %d)", 186 printf("%s %11s at (%d, %d)",
187 prefix, Token::Name(value), 187 prefix, Token::Name(value),
188 static_cast<int>(beg), static_cast<int>(end)); 188 static_cast<int>(beg), static_cast<int>(end));
189 if (ascii_literal.size() > 0) { 189 if (literal.size() > 0) {
190 for (size_t i = 0; i < ascii_literal.size(); i++) { 190 for (size_t i = 0; i < literal.size(); i++) {
191 printf(" %02x", static_cast<int>(ascii_literal[i])); 191 printf(is_ascii ? " %02x" : " %04x", literal[i]);
192 }
193 }
194 if (utf16_literal.size() > 0) {
195 for (size_t i = 0; i < utf16_literal.size(); i++) {
196 printf(" %04x", static_cast<int>(utf16_literal[i]));
197 } 192 }
198 } 193 }
199 printf("\n"); 194 printf("\n");
200 } 195 }
201 }; 196 };
202 197
203 198
204 bool HasLiteral(Token::Value token) { 199 bool HasLiteral(Token::Value token) {
205 return token == Token::IDENTIFIER || 200 return token == Token::IDENTIFIER ||
206 token == Token::STRING || 201 token == Token::STRING ||
207 token == Token::NUMBER; 202 token == Token::NUMBER;
208 } 203 }
209 204
210 205
211 std::string ToStdString(const Vector<const char>& literal) { 206 template<typename Char>
212 return std::string(literal.start(), literal.length()); 207 std::vector<int> ToStdVector(const Vector<Char>& literal) {
208 std::vector<int> result;
209 for (int i = 0; i < literal.length(); i++) {
210 result.push_back(literal[i]);
211 }
212 return result;
213 } 213 }
214 214
215 215
216 std::wstring ToStdWString(const Vector<const uint16_t>& literal) {
217 return std::wstring(reinterpret_cast<const wchar_t*>(literal.start()),
218 literal.length());
219 }
220
221
222 template<typename Scanner> 216 template<typename Scanner>
223 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) { 217 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) {
224 int beg = scanner->location().beg_pos; 218 int beg = scanner->location().beg_pos;
225 int end = scanner->location().end_pos; 219 int end = scanner->location().end_pos;
226 TokenWithLocation result(token, beg, end); 220 TokenWithLocation result(token, beg, end);
227 if (HasLiteral(token)) { 221 if (HasLiteral(token)) {
222 result.is_ascii = scanner->is_literal_ascii();
228 if (scanner->is_literal_ascii()) { 223 if (scanner->is_literal_ascii()) {
229 result.ascii_literal = ToStdString(scanner->literal_ascii_string()); 224 result.literal = ToStdVector(scanner->literal_ascii_string());
230 } else { 225 } else {
231 result.utf16_literal = ToStdWString(scanner->literal_utf16_string()); 226 result.literal = ToStdVector(scanner->literal_utf16_string());
232 } 227 }
233 } 228 }
234 return result; 229 return result;
235 } 230 }
236 231
237 232
238 TimeDelta RunBaselineScanner(const char* fname, 233 TimeDelta RunBaselineScanner(const char* fname,
239 Isolate* isolate, 234 Isolate* isolate,
240 Encoding encoding, 235 Encoding encoding,
241 bool dump_tokens, 236 bool dump_tokens,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 if (run_experimental) { 468 if (run_experimental) {
474 if (benchmark.empty()) benchmark = "Experimental"; 469 if (benchmark.empty()) benchmark = "Experimental";
475 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), 470 printf("%s(RunTime): %.f ms\n", benchmark.c_str(),
476 experimental_total); 471 experimental_total);
477 } 472 }
478 } 473 }
479 } 474 }
480 v8::V8::Dispose(); 475 v8::V8::Dispose();
481 return 0; 476 return 0;
482 } 477 }
OLDNEW
« no previous file with comments | « no previous file | src/lexer/lexer_py.re » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698