| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 } | 63 } |
| 64 | 64 |
| 65 ExperimentalScanner::ExperimentalScanner(const char* fname, | 65 ExperimentalScanner::ExperimentalScanner(const char* fname, |
| 66 bool read_all_at_once, | 66 bool read_all_at_once, |
| 67 Isolate* isolate) | 67 Isolate* isolate) |
| 68 : current_(0), | 68 : current_(0), |
| 69 fetched_(0), | 69 fetched_(0), |
| 70 read_all_at_once_(read_all_at_once), | 70 read_all_at_once_(read_all_at_once), |
| 71 already_pushed_(false), |
| 71 source_(0), | 72 source_(0), |
| 72 length_(0) { | 73 length_(0) { |
| 73 file_ = fopen(fname, "rb"); | 74 file_ = fopen(fname, "rb"); |
| 74 scanner_ = new PushScanner(this, isolate->unicode_cache()); | 75 scanner_ = new PushScanner(this, isolate->unicode_cache()); |
| 75 if (read_all_at_once_) { | 76 if (read_all_at_once_) { |
| 76 source_ = ReadFile(fname, isolate, &length_); | 77 source_ = ReadFile(fname, isolate, &length_); |
| 77 token_.resize(1500); | 78 token_.resize(1500); |
| 78 } else { | 79 } else { |
| 79 token_.resize(BUFFER_SIZE); | 80 token_.resize(BUFFER_SIZE); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 | 84 |
| 84 ExperimentalScanner::~ExperimentalScanner() { | 85 ExperimentalScanner::~ExperimentalScanner() { |
| 85 fclose(file_); | 86 fclose(file_); |
| 86 delete[] source_; | 87 delete[] source_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 | 90 |
| 90 void ExperimentalScanner::FillTokens() { | 91 void ExperimentalScanner::FillTokens() { |
| 91 current_ = 0; | 92 current_ = 0; |
| 92 fetched_ = 0; | 93 fetched_ = 0; |
| 93 if (read_all_at_once_) { | 94 if (read_all_at_once_) { |
| 94 scanner_->push(source_, length_ + 1); | 95 if (!already_pushed_) { |
| 96 scanner_->push(source_, length_ + 1); |
| 97 already_pushed_ = true; |
| 98 } else { |
| 99 scanner_->push(0, 0); |
| 100 } |
| 95 } else { | 101 } else { |
| 96 uint8_t chars[BUFFER_SIZE]; | 102 uint8_t chars[BUFFER_SIZE]; |
| 97 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); | 103 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); |
| 98 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0; | 104 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0; |
| 99 scanner_->push(chars, BUFFER_SIZE); | 105 scanner_->push(chars, BUFFER_SIZE); |
| 100 } | 106 } |
| 101 } | 107 } |
| 102 | 108 |
| 103 | 109 |
| 104 Token::Value ExperimentalScanner::Next() { | 110 Token::Value ExperimentalScanner::Next() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 123 if (fetched_ >= token_.size()) { | 129 if (fetched_ >= token_.size()) { |
| 124 token_.resize(token_.size() * 2); | 130 token_.resize(token_.size() * 2); |
| 125 } | 131 } |
| 126 token_[fetched_].value = token; | 132 token_[fetched_].value = token; |
| 127 token_[fetched_].beg = beg; | 133 token_[fetched_].beg = beg; |
| 128 token_[fetched_].end = end; | 134 token_[fetched_].end = end; |
| 129 fetched_++; | 135 fetched_++; |
| 130 } | 136 } |
| 131 | 137 |
| 132 } } // namespace v8::internal | 138 } } // namespace v8::internal |
| OLD | NEW |