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

Unified Diff: runtime/lib/mirrors.cc

Issue 23038010: Fix Function.end_token_pos() and implement MethodMirror.source getter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors.cc
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
index 7ab68b6a0c650a8e397e785e62f31e4daa7eccca..b7b3b7ccac9ede5d9235dae5f15285e55d8e58da 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -1277,6 +1277,35 @@ DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
}
+DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
+ GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
+ const Function& func = Function::Handle(ref.GetFunctionReferent());
+ const Script& script = Script::Handle(func.script());
+ const TokenStream& stream = TokenStream::Handle(script.tokens());
+ const TokenStream::Iterator tkit(stream, func.end_token_pos());
+ intptr_t from_line;
+ intptr_t from_col;
+ intptr_t to_line;
+ intptr_t to_col;
+ script.GetTokenLocation(func.token_pos(), &from_line, &from_col);
+ script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col);
+ intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length();
+ // Handle special cases for end tokens of closures (where we exclude the last
+ // token):
+ // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
+ // (2) "foo(() => null);": End token is ')`, but we don't print it.
+ // (3) "var foo = () => null": End token is `;', but in this case we are in
siva 2013/08/21 22:21:05 In your comment you mention end token is ';' but I
Michael Lippautz (Google) 2013/08/21 23:19:20 Done.
+ // an assignment, and we don't want it printed.
+ if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // (1)
siva 2013/08/21 22:21:05 what does "(1)" mean?
Michael Lippautz (Google) 2013/08/21 23:19:20 I tried to refer to the comment above in the if st
siva 2013/08/26 02:31:28 Maybe replace with "foo() => null, bar);" case On
+ (tkit.CurrentTokenKind() == Token::kRPAREN) ||
+ (tkit.CurrentTokenKind() == Token::kSEMICOLON &&
+ String::Handle(func.name()).Equals("<anonymous closure>"))) {
+ last_tok_len = 0;
+ }
+ return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len);
+}
+
+
DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
const Class& cls = Class::Handle(ref.GetClassReferent());
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698