Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: runtime/vm/object.cc

Issue 11824067: Support for embedded Dart scripts (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 5143 matching lines...) Expand 10 before | Expand all | Expand 10 after
5154 const String& src = String::Handle(Source()); 5154 const String& src = String::Handle(Source());
5155 Scanner scanner(src, private_key); 5155 Scanner scanner(src, private_key);
5156 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream(), 5156 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream(),
5157 private_key))); 5157 private_key)));
5158 if (FLAG_compiler_stats) { 5158 if (FLAG_compiler_stats) {
5159 CompilerStats::src_length += src.Length(); 5159 CompilerStats::src_length += src.Length();
5160 } 5160 }
5161 } 5161 }
5162 5162
5163 5163
5164 void Script::SetLocationOffset(intptr_t line_offset,
5165 intptr_t col_offset) const {
5166 ASSERT(line_offset >= 0);
5167 ASSERT(col_offset >= 0);
5168 raw_ptr()->line_offset_ = line_offset;
5169 raw_ptr()->col_offset_ = col_offset;
siva 2013/01/10 21:17:20 the fields line_offset_ and col_offset_ are declar
hausner 2013/01/10 21:46:03 Made everything intptr_t. I tried to save a few by
5170 }
5171
5172
5164 void Script::GetTokenLocation(intptr_t token_pos, 5173 void Script::GetTokenLocation(intptr_t token_pos,
5165 intptr_t* line, 5174 intptr_t* line,
5166 intptr_t* column) const { 5175 intptr_t* column) const {
5167 const String& src = String::Handle(Source()); 5176 const String& src = String::Handle(Source());
5168 const TokenStream& tkns = TokenStream::Handle(tokens()); 5177 const TokenStream& tkns = TokenStream::Handle(tokens());
5169 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); 5178 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos);
5170 Scanner scanner(src, Symbols::Empty()); 5179 Scanner scanner(src, Symbols::Empty());
5171 scanner.ScanTo(src_pos); 5180 scanner.ScanTo(src_pos);
5172 *line = scanner.CurrentPosition().line; 5181 intptr_t relative_line = scanner.CurrentPosition().line;
5182 *line = relative_line + line_offset();
5173 *column = scanner.CurrentPosition().column; 5183 *column = scanner.CurrentPosition().column;
5184 // On the first line of the script we must add the column offset.
5185 if (relative_line == 1) {
5186 *column += col_offset();
5187 }
5174 } 5188 }
5175 5189
5176 5190
5177 void Script::TokenRangeAtLine(intptr_t line_number, 5191 void Script::TokenRangeAtLine(intptr_t line_number,
5178 intptr_t* first_token_index, 5192 intptr_t* first_token_index,
5179 intptr_t* last_token_index) const { 5193 intptr_t* last_token_index) const {
5180 const String& src = String::Handle(Source()); 5194 const String& src = String::Handle(Source());
5181 const TokenStream& tkns = TokenStream::Handle(tokens()); 5195 const TokenStream& tkns = TokenStream::Handle(tokens());
5196 line_number -= line_offset();
5197 if (line_number < 1) line_number = 1;
5182 Scanner scanner(src, Symbols::Empty()); 5198 Scanner scanner(src, Symbols::Empty());
5183 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index); 5199 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index);
5184 if (*first_token_index >= 0) { 5200 if (*first_token_index >= 0) {
5185 *first_token_index = tkns.ComputeTokenPosition(*first_token_index); 5201 *first_token_index = tkns.ComputeTokenPosition(*first_token_index);
5186 } 5202 }
5187 if (*last_token_index >= 0) { 5203 if (*last_token_index >= 0) {
5188 *last_token_index = tkns.ComputeTokenPosition(*last_token_index); 5204 *last_token_index = tkns.ComputeTokenPosition(*last_token_index);
5189 } 5205 }
5190 } 5206 }
5191 5207
5192 5208
5193 RawString* Script::GetLine(intptr_t line_number) const { 5209 RawString* Script::GetLine(intptr_t line_number) const {
5194 const String& src = String::Handle(Source()); 5210 const String& src = String::Handle(Source());
5211 intptr_t relative_line_number = line_number - line_offset();
5195 intptr_t current_line = 1; 5212 intptr_t current_line = 1;
5196 intptr_t line_start = -1; 5213 intptr_t line_start_idx = -1;
5197 intptr_t last_char = -1; 5214 intptr_t last_char_idx = -1;
5198 for (intptr_t ix = 0; 5215 for (intptr_t ix = 0;
5199 (ix < src.Length()) && (current_line <= line_number); 5216 (ix < src.Length()) && (current_line <= relative_line_number);
5200 ix++) { 5217 ix++) {
5201 if ((current_line == line_number) && (line_start < 0)) { 5218 if ((current_line == relative_line_number) && (line_start_idx < 0)) {
5202 line_start = ix; 5219 line_start_idx = ix;
5203 } 5220 }
5204 if (src.CharAt(ix) == '\n') { 5221 if (src.CharAt(ix) == '\n') {
5205 current_line++; 5222 current_line++;
5206 } else if (src.CharAt(ix) == '\r') { 5223 } else if (src.CharAt(ix) == '\r') {
5207 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) { 5224 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) {
5208 current_line++; 5225 current_line++;
5209 } 5226 }
5210 } else { 5227 } else {
5211 last_char = ix; 5228 last_char_idx = ix;
5212 } 5229 }
5213 } 5230 }
5214 // Guarantee that returned string is never NULL. 5231 // Guarantee that returned string is never NULL.
5215 if (line_start >= 0) { 5232
5216 const String& line = String::Handle( 5233 if (line_start_idx >= 0) {
5217 String::SubString(src, line_start, last_char - line_start + 1)); 5234 return String::SubString(src,
5218 return line.raw(); 5235 line_start_idx,
5236 last_char_idx - line_start_idx + 1);
5219 } else { 5237 } else {
5220 return Symbols::Empty().raw(); 5238 return Symbols::Empty().raw();
5221 } 5239 }
5222 } 5240 }
5223 5241
5224 5242
5225 RawString* Script::GetSnippet(intptr_t from_line, 5243 RawString* Script::GetSnippet(intptr_t from_line,
5226 intptr_t from_column, 5244 intptr_t from_column,
5227 intptr_t to_line, 5245 intptr_t to_line,
5228 intptr_t to_column) const { 5246 intptr_t to_column) const {
5229 const String& src = String::Handle(Source()); 5247 const String& src = String::Handle(Source());
5230 intptr_t length = src.Length(); 5248 intptr_t length = src.Length();
5231 intptr_t line = 1; 5249 intptr_t line = 1 + line_offset();
5232 intptr_t column = 1; 5250 intptr_t column = 1;
5233 intptr_t lookahead = 0; 5251 intptr_t lookahead = 0;
5234 intptr_t snippet_start = -1; 5252 intptr_t snippet_start = -1;
5235 intptr_t snippet_end = -1; 5253 intptr_t snippet_end = -1;
5254 if (from_line - line_offset() == 1) {
5255 column += col_offset();
5256 }
5236 char c = src.CharAt(lookahead); 5257 char c = src.CharAt(lookahead);
5237 while (lookahead != length) { 5258 while (lookahead != length) {
5238 if (snippet_start == -1) { 5259 if (snippet_start == -1) {
5239 if ((line == from_line) && (column == from_column)) { 5260 if ((line == from_line) && (column == from_column)) {
5240 snippet_start = lookahead; 5261 snippet_start = lookahead;
5241 } 5262 }
5242 } else if ((line == to_line) && (column == to_column)) { 5263 } else if ((line == to_line) && (column == to_column)) {
5243 snippet_end = lookahead; 5264 snippet_end = lookahead;
5244 break; 5265 break;
5245 } 5266 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5279 } 5300 }
5280 5301
5281 5302
5282 RawScript* Script::New(const String& url, 5303 RawScript* Script::New(const String& url,
5283 const String& source, 5304 const String& source,
5284 RawScript::Kind kind) { 5305 RawScript::Kind kind) {
5285 const Script& result = Script::Handle(Script::New()); 5306 const Script& result = Script::Handle(Script::New());
5286 result.set_url(String::Handle(Symbols::New(url))); 5307 result.set_url(String::Handle(Symbols::New(url)));
5287 result.set_source(source); 5308 result.set_source(source);
5288 result.set_kind(kind); 5309 result.set_kind(kind);
5310 result.SetLocationOffset(0, 0);
5289 return result.raw(); 5311 return result.raw();
5290 } 5312 }
5291 5313
5292 5314
5293 const char* Script::ToCString() const { 5315 const char* Script::ToCString() const {
5294 return "Script"; 5316 return "Script";
5295 } 5317 }
5296 5318
5297 5319
5298 DictionaryIterator::DictionaryIterator(const Library& library) 5320 DictionaryIterator::DictionaryIterator(const Library& library)
(...skipping 7130 matching lines...) Expand 10 before | Expand all | Expand 10 after
12429 } 12451 }
12430 return result.raw(); 12452 return result.raw();
12431 } 12453 }
12432 12454
12433 12455
12434 const char* WeakProperty::ToCString() const { 12456 const char* WeakProperty::ToCString() const {
12435 return "_WeakProperty"; 12457 return "_WeakProperty";
12436 } 12458 }
12437 12459
12438 } // namespace dart 12460 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698