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

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

Issue 60993002: Add ability for Function to generate source (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 5429 matching lines...) Expand 10 before | Expand all | Expand 10 after
5440 } else { 5440 } else {
5441 tmp = cls.UserVisibleName(); 5441 tmp = cls.UserVisibleName();
5442 } 5442 }
5443 } 5443 }
5444 tmp = String::Concat(tmp, Symbols::Dot()); 5444 tmp = String::Concat(tmp, Symbols::Dot());
5445 const String& suffix = String::Handle(UserVisibleName()); 5445 const String& suffix = String::Handle(UserVisibleName());
5446 return String::Concat(tmp, suffix); 5446 return String::Concat(tmp, suffix);
5447 } 5447 }
5448 5448
5449 5449
5450 RawString* Function::GetSource() {
5451 const Script& func_script = Script::Handle(script());
5452 // Without the + 1 the final "}" is not included.
5453 return func_script.GetSnippet(token_pos(), end_token_pos() + 1);
5454 }
5455
5456
5450 // Construct fingerprint from token stream. The token stream contains also 5457 // Construct fingerprint from token stream. The token stream contains also
5451 // arguments. 5458 // arguments.
5452 int32_t Function::SourceFingerprint() const { 5459 int32_t Function::SourceFingerprint() const {
5453 uint32_t result = String::Handle(Signature()).Hash(); 5460 uint32_t result = String::Handle(Signature()).Hash();
5454 TokenStream::Iterator tokens_iterator(TokenStream::Handle( 5461 TokenStream::Iterator tokens_iterator(TokenStream::Handle(
5455 Script::Handle(script()).tokens()), token_pos()); 5462 Script::Handle(script()).tokens()), token_pos());
5456 Object& obj = Object::Handle(); 5463 Object& obj = Object::Handle();
5457 String& literal = String::Handle(); 5464 String& literal = String::Handle();
5458 while (tokens_iterator.CurrentPosition() < end_token_pos()) { 5465 while (tokens_iterator.CurrentPosition() < end_token_pos()) {
5459 uint32_t val = 0; 5466 uint32_t val = 0;
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after
6961 if (line_start_idx >= 0) { 6968 if (line_start_idx >= 0) {
6962 return String::SubString(src, 6969 return String::SubString(src,
6963 line_start_idx, 6970 line_start_idx,
6964 last_char_idx - line_start_idx + 1); 6971 last_char_idx - line_start_idx + 1);
6965 } else { 6972 } else {
6966 return Symbols::Empty().raw(); 6973 return Symbols::Empty().raw();
6967 } 6974 }
6968 } 6975 }
6969 6976
6970 6977
6978 RawString* Script::GetSnippet(intptr_t from_token_pos,
6979 intptr_t to_token_pos) const {
6980 intptr_t from_line, from_column;
6981 intptr_t to_line, to_column;
6982 GetTokenLocation(from_token_pos, &from_line, &from_column);
6983 GetTokenLocation(to_token_pos, &to_line, &to_column);
6984 return GetSnippet(from_line, from_column, to_line, to_column);
6985 }
6986
6987
6971 RawString* Script::GetSnippet(intptr_t from_line, 6988 RawString* Script::GetSnippet(intptr_t from_line,
6972 intptr_t from_column, 6989 intptr_t from_column,
6973 intptr_t to_line, 6990 intptr_t to_line,
6974 intptr_t to_column) const { 6991 intptr_t to_column) const {
6975 const String& src = String::Handle(Source()); 6992 const String& src = String::Handle(Source());
6976 intptr_t length = src.Length(); 6993 intptr_t length = src.Length();
6977 intptr_t line = 1 + line_offset(); 6994 intptr_t line = 1 + line_offset();
6978 intptr_t column = 1; 6995 intptr_t column = 1;
6979 intptr_t lookahead = 0; 6996 intptr_t lookahead = 0;
6980 intptr_t snippet_start = -1; 6997 intptr_t snippet_start = -1;
(...skipping 8783 matching lines...) Expand 10 before | Expand all | Expand 10 after
15764 return "_MirrorReference"; 15781 return "_MirrorReference";
15765 } 15782 }
15766 15783
15767 15784
15768 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15785 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15769 JSONObject jsobj(stream); 15786 JSONObject jsobj(stream);
15770 } 15787 }
15771 15788
15772 15789
15773 } // namespace dart 15790 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698