| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 20 matching lines...) Expand all Loading... |
| 31 #include "handles.h" | 31 #include "handles.h" |
| 32 #include "scanner.h" | 32 #include "scanner.h" |
| 33 #include "unicode-inl.h" | 33 #include "unicode-inl.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
| 39 // UTF8Buffer | 39 // UTF8Buffer |
| 40 | 40 |
| 41 UTF8Buffer::UTF8Buffer() : buffer_(kInitialCapacity) { } | 41 UTF8Buffer::UTF8Buffer() : buffer_(kInitialCapacity), recording_(false) { } |
| 42 | 42 |
| 43 | 43 |
| 44 UTF8Buffer::~UTF8Buffer() {} | 44 UTF8Buffer::~UTF8Buffer() {} |
| 45 | 45 |
| 46 | 46 |
| 47 void UTF8Buffer::AddCharSlow(uc32 c) { | 47 void UTF8Buffer::AddCharSlow(uc32 c) { |
| 48 ASSERT(static_cast<unsigned>(c) > unibrow::Utf8::kMaxOneByteChar); | 48 ASSERT(static_cast<unsigned>(c) > unibrow::Utf8::kMaxOneByteChar); |
| 49 int length = unibrow::Utf8::Length(c); | 49 int length = unibrow::Utf8::Length(c); |
| 50 Vector<char> block = buffer_.AddBlock(length, '\0'); | 50 Vector<char> block = buffer_.AddBlock(length, '\0'); |
| 51 #ifdef DEBUG | 51 #ifdef DEBUG |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 | 118 |
| 119 void CharacterStreamUTF16Buffer::SeekForward(int pos) { | 119 void CharacterStreamUTF16Buffer::SeekForward(int pos) { |
| 120 pos_ = pos; | 120 pos_ = pos; |
| 121 ASSERT(pushback_buffer()->is_empty()); | 121 ASSERT(pushback_buffer()->is_empty()); |
| 122 stream_->Seek(pos); | 122 stream_->Seek(pos); |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 // ExternalStringUTF16Buffer | |
| 127 template <typename StringType, typename CharType> | |
| 128 ExternalStringUTF16Buffer<StringType, CharType>::ExternalStringUTF16Buffer() | |
| 129 : raw_data_(NULL) { } | |
| 130 | |
| 131 | |
| 132 template <typename StringType, typename CharType> | |
| 133 void ExternalStringUTF16Buffer<StringType, CharType>::Initialize( | |
| 134 Handle<StringType> data, | |
| 135 int start_position, | |
| 136 int end_position) { | |
| 137 ASSERT(!data.is_null()); | |
| 138 raw_data_ = data->resource()->data(); | |
| 139 | |
| 140 ASSERT(end_position <= data->length()); | |
| 141 if (start_position > 0) { | |
| 142 SeekForward(start_position); | |
| 143 } | |
| 144 end_ = | |
| 145 end_position != Scanner::kNoEndPosition ? end_position : data->length(); | |
| 146 } | |
| 147 | |
| 148 | |
| 149 template <typename StringType, typename CharType> | |
| 150 uc32 ExternalStringUTF16Buffer<StringType, CharType>::Advance() { | |
| 151 if (pos_ < end_) { | |
| 152 return raw_data_[pos_++]; | |
| 153 } else { | |
| 154 // note: currently the following increment is necessary to avoid a | |
| 155 // test-parser problem! | |
| 156 pos_++; | |
| 157 return static_cast<uc32>(-1); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 | |
| 162 template <typename StringType, typename CharType> | |
| 163 void ExternalStringUTF16Buffer<StringType, CharType>::PushBack(uc32 ch) { | |
| 164 pos_--; | |
| 165 ASSERT(pos_ >= Scanner::kCharacterLookaheadBufferSize); | |
| 166 ASSERT(raw_data_[pos_ - Scanner::kCharacterLookaheadBufferSize] == ch); | |
| 167 } | |
| 168 | |
| 169 | |
| 170 template <typename StringType, typename CharType> | |
| 171 void ExternalStringUTF16Buffer<StringType, CharType>::SeekForward(int pos) { | |
| 172 pos_ = pos; | |
| 173 } | |
| 174 | |
| 175 // ---------------------------------------------------------------------------- | 126 // ---------------------------------------------------------------------------- |
| 176 // Scanner::LiteralScope | 127 // Scanner::LiteralScope |
| 177 | 128 |
| 178 Scanner::LiteralScope::LiteralScope(Scanner* self) | 129 Scanner::LiteralScope::LiteralScope(Scanner* self) |
| 179 : scanner_(self), complete_(false) { | 130 : scanner_(self), complete_(false) { |
| 180 self->StartLiteral(); | 131 self->StartLiteral(); |
| 181 } | 132 } |
| 182 | 133 |
| 183 | 134 |
| 184 Scanner::LiteralScope::~LiteralScope() { | 135 Scanner::LiteralScope::~LiteralScope() { |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 } | 1143 } |
| 1193 AddCharAdvance(); | 1144 AddCharAdvance(); |
| 1194 } | 1145 } |
| 1195 literal.Complete(); | 1146 literal.Complete(); |
| 1196 | 1147 |
| 1197 next_.location.end_pos = source_pos() - 1; | 1148 next_.location.end_pos = source_pos() - 1; |
| 1198 return true; | 1149 return true; |
| 1199 } | 1150 } |
| 1200 | 1151 |
| 1201 } } // namespace v8::internal | 1152 } } // namespace v8::internal |
| OLD | NEW |