| 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 "platform/json.h" | 5 #include "platform/json.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 case JSONScanner::TokenNull: | 248 case JSONScanner::TokenNull: |
| 249 scanner_.Scan(); | 249 scanner_.Scan(); |
| 250 break; | 250 break; |
| 251 default: | 251 default: |
| 252 OS::Print("Malformed JSON: expected a value but got '%s'\n", | 252 OS::Print("Malformed JSON: expected a value but got '%s'\n", |
| 253 scanner_.TokenChars()); | 253 scanner_.TokenChars()); |
| 254 FATAL("illegal JSON value found"); | 254 FATAL("illegal JSON value found"); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 |
| 259 #if defined (DEBUG) |
| 258 #define CHECK_TOKEN(token) \ | 260 #define CHECK_TOKEN(token) \ |
| 259 if (scanner_.CurrentToken() != token) { \ | 261 if (scanner_.CurrentToken() != token) { \ |
| 260 OS::Print("Malformed JSON: expected %s but got '%s'\n", \ | 262 OS::Print("Malformed JSON: expected %s but got '%s'\n", \ |
| 261 #token, scanner_.TokenChars()); \ | 263 #token, scanner_.TokenChars()); \ |
| 262 } \ | 264 intptr_t offset = scanner_.TokenChars() - this->json_object_; \ |
| 263 ASSERT(scanner_.CurrentToken() == token); | 265 OS::Print("Malformed JSON: expected %s at offset %" Pd "of buffer:\n%s\n", \ |
| 266 #token, offset, this->json_object_); \ |
| 267 ASSERT(scanner_.CurrentToken() == token); \ |
| 268 } |
| 269 #else |
| 270 #define CHECK_TOKEN(token) |
| 271 #endif |
| 272 |
| 264 | 273 |
| 265 void JSONReader::CheckArray() { | 274 void JSONReader::CheckArray() { |
| 266 CHECK_TOKEN(JSONScanner::TokenLBrack); | 275 CHECK_TOKEN(JSONScanner::TokenLBrack); |
| 267 scanner_.Scan(); | 276 scanner_.Scan(); |
| 268 while (scanner_.CurrentToken() != JSONScanner::TokenRBrack) { | 277 while (scanner_.CurrentToken() != JSONScanner::TokenRBrack) { |
| 269 CheckValue(); | 278 CheckValue(); |
| 270 if (scanner_.CurrentToken() != JSONScanner::TokenComma) { | 279 if (scanner_.CurrentToken() != JSONScanner::TokenComma) { |
| 271 break; | 280 break; |
| 272 } | 281 } |
| 273 scanner_.Scan(); | 282 scanner_.Scan(); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // the debugger front-end. | 643 // the debugger front-end. |
| 635 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity; | 644 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity; |
| 636 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); | 645 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); |
| 637 ASSERT(new_buf != NULL); | 646 ASSERT(new_buf != NULL); |
| 638 buf_ = new_buf; | 647 buf_ = new_buf; |
| 639 buf_size_ = new_size; | 648 buf_size_ = new_size; |
| 640 } | 649 } |
| 641 } | 650 } |
| 642 | 651 |
| 643 } // namespace dart | 652 } // namespace dart |
| OLD | NEW |