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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 bool ExperimentalScanner<uint16_t>::FillLiteral( | 111 bool ExperimentalScanner<uint16_t>::FillLiteral( |
112 const TokenDesc& token, LiteralDesc* literal) { | 112 const TokenDesc& token, LiteralDesc* literal) { |
113 literal->beg_pos = token.beg_pos; | 113 literal->beg_pos = token.beg_pos; |
114 const uint16_t* start = buffer_ + token.beg_pos; | 114 const uint16_t* start = buffer_ + token.beg_pos; |
115 const uint16_t* end = buffer_ + token.end_pos; | 115 const uint16_t* end = buffer_ + token.end_pos; |
116 if (token.token == Token::STRING) { | 116 if (token.token == Token::STRING) { |
117 ++start; | 117 ++start; |
118 --end; | 118 --end; |
119 } | 119 } |
120 if (!token.has_escapes) { | 120 if (!token.has_escapes) { |
121 literal->is_ascii = false; // FIXME: utf16 can contain only ascii chars. | 121 // UTF-16 can also contain only one byte chars. Note that is_ascii here |
| 122 // means is_onebyte. |
| 123 literal->is_ascii = true; |
| 124 literal->buffer.Reset(); |
| 125 for (const uint16_t* cursor = start; cursor != end; ++cursor) { |
| 126 if (*cursor >= unibrow::Latin1::kMaxChar) { |
| 127 literal->is_ascii = false; |
| 128 break; |
| 129 } |
| 130 literal->buffer.AddChar(*cursor); |
| 131 } |
122 literal->length = end - start; | 132 literal->length = end - start; |
123 literal->utf16_string = Vector<const uint16_t>(start, literal->length); | 133 if (literal->is_ascii) { |
| 134 literal->ascii_string = literal->buffer.ascii_literal(); |
| 135 } else { |
| 136 literal->buffer.Reset(); |
| 137 literal->utf16_string = Vector<const uint16_t>(start, literal->length); |
| 138 } |
124 return true; | 139 return true; |
125 } | 140 } |
126 literal->buffer.Reset(); | 141 literal->buffer.Reset(); |
127 for (const uint16_t* cursor = start; cursor != end;) { | 142 for (const uint16_t* cursor = start; cursor != end;) { |
128 if (*cursor != '\\') { | 143 if (*cursor != '\\') { |
129 literal->buffer.AddChar(*cursor++); | 144 literal->buffer.AddChar(*cursor++); |
130 } else if (token.token == Token::IDENTIFIER) { | 145 } else if (token.token == Token::IDENTIFIER) { |
131 uc32 c; | 146 uc32 c; |
132 cursor = ScanIdentifierUnicodeEscape(cursor, end, &c); | 147 cursor = ScanIdentifierUnicodeEscape(cursor, end, &c); |
133 ASSERT(cursor != NULL); | 148 ASSERT(cursor != NULL); |
(...skipping 18 matching lines...) Expand all Loading... |
152 template<> | 167 template<> |
153 bool ExperimentalScanner<int8_t>::FillLiteral( | 168 bool ExperimentalScanner<int8_t>::FillLiteral( |
154 const TokenDesc& token, LiteralDesc* literal) { | 169 const TokenDesc& token, LiteralDesc* literal) { |
155 // FIXME: implement. | 170 // FIXME: implement. |
156 return false; | 171 return false; |
157 } | 172 } |
158 | 173 |
159 | 174 |
160 } | 175 } |
161 } | 176 } |
OLD | NEW |