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

Unified Diff: runtime/lib/mirrors.cc

Issue 1071703002: Remove some duplication in code that extracts the source for a function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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/vm/compiler_test.cc » ('j') | runtime/vm/compiler_test.cc » ('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 c4605cf2e031c2a80bbda8d1c550c8849210cb50..2b063e1e736587d44237e29ce8d2c06b34491c82 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -1868,45 +1868,7 @@ DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 2) {
DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
const Function& func = Function::Handle(ref.GetFunctionReferent());
- if (func.IsImplicitConstructor() || func.IsSignatureFunction()) {
- // We may need to handle more cases when the restrictions on mixins are
- // relaxed. In particular we might start associating some source with the
- // forwarding constructors when it becomes possible to specify a particular
- // constructor from the mixin to use.
- return Instance::null();
- }
- const Script& script = Script::Handle(func.script());
- const TokenStream& stream = TokenStream::Handle(script.tokens());
- if (!script.HasSource()) {
- // When source is not available, avoid printing the whole token stream and
- // doing expensive position calculations.
- return stream.GenerateSource(func.token_pos(), func.end_token_pos() + 1);
- }
-
- 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 the token
- // semicolon belongs to the assignment so we skip it.
- if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1.
- (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2.
- (tkit.CurrentTokenKind() == Token::kSEMICOLON &&
- String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3.
- last_tok_len = 0;
- }
- const Instance& result = Instance::Handle(
- script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len));
- ASSERT(!result.IsNull());
- return result.raw();
+ return func.GetSource();
}
« no previous file with comments | « no previous file | runtime/vm/compiler_test.cc » ('j') | runtime/vm/compiler_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698