| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/scanner.h" | 5 #include "vm/scanner.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 bool Scanner::IsIdentChar(int32_t c) { | 156 bool Scanner::IsIdentChar(int32_t c) { |
| 157 return IsLetter(c) || IsDecimalDigit(c) || (c == '_') || (c == '$'); | 157 return IsLetter(c) || IsDecimalDigit(c) || (c == '_') || (c == '$'); |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 bool Scanner::IsIdent(const String& str) { | 161 bool Scanner::IsIdent(const String& str) { |
| 162 if (!str.IsOneByteString()) { | 162 if (!str.IsOneByteString()) { |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 if (str.Length() == 0 || !IsIdentStartChar(str.CharAt(0))) { | 165 if (str.Length() == 0 || !IsIdentStartChar(str.CodeUnitAt(0))) { |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 for (int i = 1; i < str.Length(); i++) { | 168 for (int i = 1; i < str.Length(); i++) { |
| 169 if (!IsIdentChar(str.CharAt(i))) { | 169 if (!IsIdentChar(str.CodeUnitAt(i))) { |
| 170 return false; | 170 return false; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 return true; | 173 return true; |
| 174 } | 174 } |
| 175 | 175 |
| 176 | 176 |
| 177 void Scanner::ReadChar() { | 177 void Scanner::ReadChar() { |
| 178 if (lookahead_pos_ < source_length_) { | 178 if (lookahead_pos_ < source_length_) { |
| 179 if (c0_ == '\n') { | 179 if (c0_ == '\n') { |
| 180 newline_seen_ = true; | 180 newline_seen_ = true; |
| 181 c0_pos_.line++; | 181 c0_pos_.line++; |
| 182 c0_pos_.column = 0; | 182 c0_pos_.column = 0; |
| 183 if (source_.CharAt(lookahead_pos_) == '\r') { | 183 if (source_.CodeUnitAt(lookahead_pos_) == '\r') { |
| 184 // Replace a sequence of '\r' '\n' with a single '\n'. | 184 // Replace a sequence of '\r' '\n' with a single '\n'. |
| 185 if (LookaheadChar(1) == '\n') { | 185 if (LookaheadChar(1) == '\n') { |
| 186 lookahead_pos_++; | 186 lookahead_pos_++; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 lookahead_pos_++; | 190 lookahead_pos_++; |
| 191 c0_pos_.column++; | 191 c0_pos_.column++; |
| 192 c0_ = LookaheadChar(0); | 192 c0_ = LookaheadChar(0); |
| 193 // Replace '\r' with '\n'. | 193 // Replace '\r' with '\n'. |
| 194 if (c0_ == '\r') { | 194 if (c0_ == '\r') { |
| 195 c0_ = '\n'; | 195 c0_ = '\n'; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 // Look ahead 'how_many' characters. Returns the character, or '\0' if | 201 // Look ahead 'how_many' characters. Returns the character, or '\0' if |
| 202 // the lookahead position is beyond the end of the string. Does not | 202 // the lookahead position is beyond the end of the string. Does not |
| 203 // normalize line end characters into '\n'. | 203 // normalize line end characters into '\n'. |
| 204 int32_t Scanner::LookaheadChar(int how_many) { | 204 int32_t Scanner::LookaheadChar(int how_many) { |
| 205 ASSERT(how_many >= 0); | 205 ASSERT(how_many >= 0); |
| 206 int32_t lookahead_char = '\0'; | 206 int32_t lookahead_char = '\0'; |
| 207 if (lookahead_pos_ + how_many < source_length_) { | 207 if (lookahead_pos_ + how_many < source_length_) { |
| 208 lookahead_char = source_.CharAt(lookahead_pos_ + how_many); | 208 lookahead_char = source_.CodeUnitAt(lookahead_pos_ + how_many); |
| 209 } | 209 } |
| 210 return lookahead_char; | 210 return lookahead_char; |
| 211 } | 211 } |
| 212 | 212 |
| 213 | 213 |
| 214 void Scanner::ConsumeWhiteSpace() { | 214 void Scanner::ConsumeWhiteSpace() { |
| 215 while (c0_ == ' ' || c0_ == '\t' || c0_ == '\n') { | 215 while (c0_ == ' ' || c0_ == '\t' || c0_ == '\n') { |
| 216 ReadChar(); | 216 ReadChar(); |
| 217 } | 217 } |
| 218 } | 218 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 current_token_.kind = | 253 current_token_.kind = |
| 254 (nesting_level == 0) ? Token::kWHITESP : Token::kILLEGAL; | 254 (nesting_level == 0) ? Token::kWHITESP : Token::kILLEGAL; |
| 255 } | 255 } |
| 256 | 256 |
| 257 | 257 |
| 258 void Scanner::ScanIdentChars(bool allow_dollar) { | 258 void Scanner::ScanIdentChars(bool allow_dollar) { |
| 259 ASSERT(IsIdentStartChar(c0_)); | 259 ASSERT(IsIdentStartChar(c0_)); |
| 260 ASSERT(allow_dollar || (c0_ != '$')); | 260 ASSERT(allow_dollar || (c0_ != '$')); |
| 261 int ident_length = 0; | 261 int ident_length = 0; |
| 262 int ident_pos = lookahead_pos_; | 262 int ident_pos = lookahead_pos_; |
| 263 int32_t ident_char0 = source_.CharAt(ident_pos); | 263 int32_t ident_char0 = source_.CodeUnitAt(ident_pos); |
| 264 while (IsIdentChar(c0_) && (allow_dollar || (c0_ != '$'))) { | 264 while (IsIdentChar(c0_) && (allow_dollar || (c0_ != '$'))) { |
| 265 ReadChar(); | 265 ReadChar(); |
| 266 ident_length++; | 266 ident_length++; |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Check whether the characters we read are a known keyword. | 269 // Check whether the characters we read are a known keyword. |
| 270 // Note, can't use strcmp since token_chars is not null-terminated. | 270 // Note, can't use strcmp since token_chars is not null-terminated. |
| 271 int i = 0; | 271 int i = 0; |
| 272 while (i < Token::numKeywords && | 272 while (i < Token::numKeywords && |
| 273 keywords_[i].keyword_chars[0] <= ident_char0) { | 273 keywords_[i].keyword_chars[0] <= ident_char0) { |
| 274 if (keywords_[i].keyword_len == ident_length) { | 274 if (keywords_[i].keyword_len == ident_length) { |
| 275 const char* keyword = keywords_[i].keyword_chars; | 275 const char* keyword = keywords_[i].keyword_chars; |
| 276 int char_pos = 0; | 276 int char_pos = 0; |
| 277 while ((char_pos < ident_length) && | 277 while ((char_pos < ident_length) && |
| 278 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { | 278 (static_cast<uint32_t>(keyword[char_pos]) == |
| 279 source_.CodeUnitAt(ident_pos + char_pos))) { |
| 279 char_pos++; | 280 char_pos++; |
| 280 } | 281 } |
| 281 if (char_pos == ident_length) { | 282 if (char_pos == ident_length) { |
| 282 if (keywords_[i].keyword_symbol == NULL) { | 283 if (keywords_[i].keyword_symbol == NULL) { |
| 283 String& symbol = String::ZoneHandle(); | 284 String& symbol = String::ZoneHandle(); |
| 284 symbol ^= keyword_symbol_table_.At(i); | 285 symbol ^= keyword_symbol_table_.At(i); |
| 285 ASSERT(!symbol.IsNull()); | 286 ASSERT(!symbol.IsNull()); |
| 286 keywords_[i].keyword_symbol = &symbol; | 287 keywords_[i].keyword_symbol = &symbol; |
| 287 } | 288 } |
| 288 current_token_.literal = keywords_[i].keyword_symbol; | 289 current_token_.literal = keywords_[i].keyword_symbol; |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 "%c%#"Px"", kPrivateKeySeparator, key_value); | 953 "%c%#"Px"", kPrivateKeySeparator, key_value); |
| 953 const String& result = String::Handle(String::New(private_key, Heap::kOld)); | 954 const String& result = String::Handle(String::New(private_key, Heap::kOld)); |
| 954 return result.raw(); | 955 return result.raw(); |
| 955 } | 956 } |
| 956 | 957 |
| 957 | 958 |
| 958 void Scanner::InitOnce() { | 959 void Scanner::InitOnce() { |
| 959 } | 960 } |
| 960 | 961 |
| 961 } // namespace dart | 962 } // namespace dart |
| OLD | NEW |