| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::vector<int> literal; | 172 std::vector<int> literal; |
| 173 bool is_ascii; | 173 bool is_ascii; |
| 174 // The location of the latest octal position when the token was seen. |
| 175 int octal_beg; |
| 176 int octal_end; |
| 174 TokenWithLocation() : | 177 TokenWithLocation() : |
| 175 value(Token::ILLEGAL), beg(0), end(0), is_ascii(false) { } | 178 value(Token::ILLEGAL), beg(0), end(0), is_ascii(false) { } |
| 176 TokenWithLocation(Token::Value value, size_t beg, size_t end) : | 179 TokenWithLocation(Token::Value value, size_t beg, size_t end, |
| 177 value(value), beg(beg), end(end), is_ascii(false) { } | 180 int octal_beg, int octal_end) : |
| 181 value(value), beg(beg), end(end), is_ascii(false), octal_beg(octal_beg), |
| 182 octal_end(octal_end) { } |
| 178 bool operator==(const TokenWithLocation& other) { | 183 bool operator==(const TokenWithLocation& other) { |
| 184 // The octal_end of the baseline scanner is inconsistent between octal |
| 185 // numbers (end = one beyond the last digit) and octal escapes (end = the |
| 186 // last digit). Ignore that. |
| 179 return value == other.value && beg == other.beg && end == other.end && | 187 return value == other.value && beg == other.beg && end == other.end && |
| 180 literal == other.literal && is_ascii == other.is_ascii; | 188 literal == other.literal && is_ascii == other.is_ascii && |
| 189 octal_beg == other.octal_beg && |
| 190 octal_end >= other.octal_end - 1 && octal_end <= other.octal_end + 1; |
| 181 } | 191 } |
| 182 bool operator!=(const TokenWithLocation& other) { | 192 bool operator!=(const TokenWithLocation& other) { |
| 183 return !(*this == other); | 193 return !(*this == other); |
| 184 } | 194 } |
| 185 void Print(const char* prefix) const { | 195 void Print(const char* prefix) const { |
| 186 printf("%s %11s at (%d, %d)", | 196 printf("%s %11s at (%d, %d)", |
| 187 prefix, Token::Name(value), | 197 prefix, Token::Name(value), |
| 188 static_cast<int>(beg), static_cast<int>(end)); | 198 static_cast<int>(beg), static_cast<int>(end)); |
| 189 if (literal.size() > 0) { | 199 if (literal.size() > 0) { |
| 190 for (size_t i = 0; i < literal.size(); i++) { | 200 for (size_t i = 0; i < literal.size(); i++) { |
| 191 printf(is_ascii ? " %02x" : " %04x", literal[i]); | 201 printf(is_ascii ? " %02x" : " %04x", literal[i]); |
| 192 } | 202 } |
| 193 } | 203 } |
| 194 printf("\n"); | 204 printf(" (last octal: %d %d)\n", octal_beg, octal_end); |
| 195 } | 205 } |
| 196 }; | 206 }; |
| 197 | 207 |
| 198 | 208 |
| 199 bool HasLiteral(Token::Value token) { | 209 bool HasLiteral(Token::Value token) { |
| 200 return token == Token::IDENTIFIER || | 210 return token == Token::IDENTIFIER || |
| 201 token == Token::STRING || | 211 token == Token::STRING || |
| 202 token == Token::NUMBER; | 212 token == Token::NUMBER; |
| 203 } | 213 } |
| 204 | 214 |
| 205 | 215 |
| 206 template<typename Char> | 216 template<typename Char> |
| 207 std::vector<int> ToStdVector(const Vector<Char>& literal) { | 217 std::vector<int> ToStdVector(const Vector<Char>& literal) { |
| 208 std::vector<int> result; | 218 std::vector<int> result; |
| 209 for (int i = 0; i < literal.length(); i++) { | 219 for (int i = 0; i < literal.length(); i++) { |
| 210 result.push_back(literal[i]); | 220 result.push_back(literal[i]); |
| 211 } | 221 } |
| 212 return result; | 222 return result; |
| 213 } | 223 } |
| 214 | 224 |
| 215 | 225 |
| 216 template<typename Scanner> | 226 template<typename Scanner> |
| 217 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) { | 227 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) { |
| 218 int beg = scanner->location().beg_pos; | 228 int beg = scanner->location().beg_pos; |
| 219 int end = scanner->location().end_pos; | 229 int end = scanner->location().end_pos; |
| 220 TokenWithLocation result(token, beg, end); | 230 TokenWithLocation result(token, beg, end, scanner->octal_position().beg_pos, |
| 231 scanner->octal_position().end_pos); |
| 221 if (HasLiteral(token)) { | 232 if (HasLiteral(token)) { |
| 222 result.is_ascii = scanner->is_literal_ascii(); | 233 result.is_ascii = scanner->is_literal_ascii(); |
| 223 if (scanner->is_literal_ascii()) { | 234 if (scanner->is_literal_ascii()) { |
| 224 result.literal = ToStdVector(scanner->literal_ascii_string()); | 235 result.literal = ToStdVector(scanner->literal_ascii_string()); |
| 225 } else { | 236 } else { |
| 226 result.literal = ToStdVector(scanner->literal_utf16_string()); | 237 result.literal = ToStdVector(scanner->literal_utf16_string()); |
| 227 } | 238 } |
| 228 } | 239 } |
| 229 return result; | 240 return result; |
| 230 } | 241 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 if (run_experimental) { | 479 if (run_experimental) { |
| 469 if (benchmark.empty()) benchmark = "Experimental"; | 480 if (benchmark.empty()) benchmark = "Experimental"; |
| 470 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), | 481 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 471 experimental_total); | 482 experimental_total); |
| 472 } | 483 } |
| 473 } | 484 } |
| 474 } | 485 } |
| 475 v8::V8::Dispose(); | 486 v8::V8::Dispose(); |
| 476 return 0; | 487 return 0; |
| 477 } | 488 } |
| OLD | NEW |