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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 77dab5ded8929b88f2c51f8a2fce2d788425ec97..f1f2289b6119e85f7f598c850b9010ba5f3dc39e 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5447,6 +5447,13 @@ RawString* Function::QualifiedUserVisibleName() const {
}
+RawString* Function::GetSource() {
+ const Script& func_script = Script::Handle(script());
+ // Without the + 1 the final "}" is not included.
+ return func_script.GetSnippet(token_pos(), end_token_pos() + 1);
+}
+
+
// Construct fingerprint from token stream. The token stream contains also
// arguments.
int32_t Function::SourceFingerprint() const {
@@ -6968,6 +6975,16 @@ RawString* Script::GetLine(intptr_t line_number) const {
}
+RawString* Script::GetSnippet(intptr_t from_token_pos,
+ intptr_t to_token_pos) const {
+ intptr_t from_line, from_column;
+ intptr_t to_line, to_column;
+ GetTokenLocation(from_token_pos, &from_line, &from_column);
+ GetTokenLocation(to_token_pos, &to_line, &to_column);
+ return GetSnippet(from_line, from_column, to_line, to_column);
+}
+
+
RawString* Script::GetSnippet(intptr_t from_line,
intptr_t from_column,
intptr_t to_line,
« 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