OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include <cmath> | 30 #include <cmath> |
31 | 31 |
32 #include "scanner.h" | 32 #include "scanner.h" |
33 | 33 |
34 #include "../include/v8stdint.h" | 34 #include "../include/v8stdint.h" |
35 #include "char-predicates-inl.h" | 35 #include "char-predicates-inl.h" |
36 #include "conversions-inl.h" | 36 #include "conversions-inl.h" |
37 #include "list-inl.h" | 37 #include "list-inl.h" |
38 #include "v8.h" | 38 #include "v8.h" |
| 39 #include "parser.h" |
39 | 40 |
40 namespace v8 { | 41 namespace v8 { |
41 namespace internal { | 42 namespace internal { |
42 | 43 |
43 // ---------------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------------- |
44 // Scanner | 45 // Scanner |
45 | 46 |
46 Scanner::Scanner(UnicodeCache* unicode_cache) | 47 Scanner::Scanner(UnicodeCache* unicode_cache) |
47 : unicode_cache_(unicode_cache), | 48 : unicode_cache_(unicode_cache), |
48 octal_pos_(Location::invalid()), | 49 octal_pos_(Location::invalid()), |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 Advance(); | 1109 Advance(); |
1109 } | 1110 } |
1110 } | 1111 } |
1111 literal.Complete(); | 1112 literal.Complete(); |
1112 | 1113 |
1113 next_.location.end_pos = source_pos() - 1; | 1114 next_.location.end_pos = source_pos() - 1; |
1114 return true; | 1115 return true; |
1115 } | 1116 } |
1116 | 1117 |
1117 | 1118 |
1118 Handle<String> Scanner::AllocateLiteralString(Isolate* isolate, | |
1119 PretenureFlag tenured) { | |
1120 if (is_literal_one_byte()) { | |
1121 return isolate->factory()->NewStringFromOneByte( | |
1122 Vector<const uint8_t>::cast(literal_one_byte_string()), tenured); | |
1123 } else { | |
1124 return isolate->factory()->NewStringFromTwoByte( | |
1125 literal_utf16_string(), tenured); | |
1126 } | |
1127 } | |
1128 | |
1129 | |
1130 Handle<String> Scanner::AllocateNextLiteralString(Isolate* isolate, | 1119 Handle<String> Scanner::AllocateNextLiteralString(Isolate* isolate, |
1131 PretenureFlag tenured) { | 1120 PretenureFlag tenured) { |
1132 if (is_next_literal_one_byte()) { | 1121 if (is_next_literal_one_byte()) { |
1133 return isolate->factory()->NewStringFromOneByte( | 1122 return isolate->factory()->NewStringFromOneByte( |
1134 Vector<const uint8_t>::cast(next_literal_one_byte_string()), tenured); | 1123 Vector<const uint8_t>::cast(next_literal_one_byte_string()), tenured); |
1135 } else { | 1124 } else { |
1136 return isolate->factory()->NewStringFromTwoByte( | 1125 return isolate->factory()->NewStringFromTwoByte( |
1137 next_literal_utf16_string(), tenured); | 1126 next_literal_utf16_string(), tenured); |
1138 } | 1127 } |
1139 } | 1128 } |
(...skipping 11 matching lines...) Expand all Loading... |
1151 | 1140 |
1152 | 1141 |
1153 double Scanner::DoubleValue() { | 1142 double Scanner::DoubleValue() { |
1154 ASSERT(is_literal_one_byte()); | 1143 ASSERT(is_literal_one_byte()); |
1155 return StringToDouble( | 1144 return StringToDouble( |
1156 unicode_cache_, literal_one_byte_string(), | 1145 unicode_cache_, literal_one_byte_string(), |
1157 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | 1146 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); |
1158 } | 1147 } |
1159 | 1148 |
1160 | 1149 |
| 1150 int Scanner::FindNumber(DuplicateFinder* finder, int value) { |
| 1151 return finder->AddNumber(literal_one_byte_string(), value); |
| 1152 } |
| 1153 |
| 1154 |
| 1155 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { |
| 1156 if (is_literal_one_byte()) { |
| 1157 return finder->AddAsciiSymbol(literal_one_byte_string(), value); |
| 1158 } |
| 1159 return finder->AddUtf16Symbol(literal_utf16_string(), value); |
| 1160 } |
| 1161 |
| 1162 |
| 1163 void Scanner::LogSymbol(ParserRecorder* log, int position) { |
| 1164 if (is_literal_one_byte()) { |
| 1165 log->LogAsciiSymbol(position, literal_one_byte_string()); |
| 1166 } else { |
| 1167 log->LogUtf16Symbol(position, literal_utf16_string()); |
| 1168 } |
| 1169 } |
| 1170 |
| 1171 |
1161 int DuplicateFinder::AddAsciiSymbol(Vector<const char> key, int value) { | 1172 int DuplicateFinder::AddAsciiSymbol(Vector<const char> key, int value) { |
1162 return AddSymbol(Vector<const byte>::cast(key), true, value); | 1173 return AddSymbol(Vector<const byte>::cast(key), true, value); |
1163 } | 1174 } |
1164 | 1175 |
1165 | 1176 |
1166 int DuplicateFinder::AddUtf16Symbol(Vector<const uint16_t> key, int value) { | 1177 int DuplicateFinder::AddUtf16Symbol(Vector<const uint16_t> key, int value) { |
1167 return AddSymbol(Vector<const byte>::cast(key), false, value); | 1178 return AddSymbol(Vector<const byte>::cast(key), false, value); |
1168 } | 1179 } |
1169 | 1180 |
1170 | 1181 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 } | 1298 } |
1288 backing_store_.Add(static_cast<byte>((one_byte_length >> 7) | 0x80u)); | 1299 backing_store_.Add(static_cast<byte>((one_byte_length >> 7) | 0x80u)); |
1289 } | 1300 } |
1290 backing_store_.Add(static_cast<byte>(one_byte_length & 0x7f)); | 1301 backing_store_.Add(static_cast<byte>(one_byte_length & 0x7f)); |
1291 | 1302 |
1292 backing_store_.AddBlock(bytes); | 1303 backing_store_.AddBlock(bytes); |
1293 return backing_store_.EndSequence().start(); | 1304 return backing_store_.EndSequence().start(); |
1294 } | 1305 } |
1295 | 1306 |
1296 } } // namespace v8::internal | 1307 } } // namespace v8::internal |
OLD | NEW |