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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
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 "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 1270
1271 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1271 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1272 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1272 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1273 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1273 const Function& func = Function::Handle(ref.GetFunctionReferent());
1274 // We handle constructors in Dart code. 1274 // We handle constructors in Dart code.
1275 ASSERT(!func.IsConstructor()); 1275 ASSERT(!func.IsConstructor());
1276 return func.result_type(); 1276 return func.result_type();
1277 } 1277 }
1278 1278
1279 1279
1280 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
1281 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1282 const Function& func = Function::Handle(ref.GetFunctionReferent());
1283 const Script& script = Script::Handle(func.script());
1284 const TokenStream& stream = TokenStream::Handle(script.tokens());
1285 const TokenStream::Iterator tkit(stream, func.end_token_pos());
1286 intptr_t from_line;
1287 intptr_t from_col;
1288 intptr_t to_line;
1289 intptr_t to_col;
1290 script.GetTokenLocation(func.token_pos(), &from_line, &from_col);
1291 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col);
1292 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length();
1293 // Handle special cases for end tokens of closures (where we exclude the last
1294 // token):
1295 // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
1296 // (2) "foo(() => null);": End token is ')`, but we don't print it.
1297 // (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.
1298 // an assignment, and we don't want it printed.
1299 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
1300 (tkit.CurrentTokenKind() == Token::kRPAREN) ||
1301 (tkit.CurrentTokenKind() == Token::kSEMICOLON &&
1302 String::Handle(func.name()).Equals("<anonymous closure>"))) {
1303 last_tok_len = 0;
1304 }
1305 return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len);
1306 }
1307
1308
1280 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { 1309 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
1281 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1310 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1282 const Class& cls = Class::Handle(ref.GetClassReferent()); 1311 const Class& cls = Class::Handle(ref.GetClassReferent());
1283 const Function& sig_func = Function::Handle(cls.signature_function()); 1312 const Function& sig_func = Function::Handle(cls.signature_function());
1284 const Class& sig_cls = Class::Handle(sig_func.signature_class()); 1313 const Class& sig_cls = Class::Handle(sig_func.signature_class());
1285 return MirrorReference::New(sig_cls); 1314 return MirrorReference::New(sig_cls);
1286 } 1315 }
1287 1316
1288 1317
1289 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { 1318 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) {
1290 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1319 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1291 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); 1320 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1));
1292 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1321 const Function& func = Function::Handle(ref.GetFunctionReferent());
1293 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()); 1322 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value());
1294 } 1323 }
1295 1324
1296 1325
1297 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1326 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1298 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1299 const Field& field = Field::Handle(ref.GetFieldReferent()); 1328 const Field& field = Field::Handle(ref.GetFieldReferent());
1300 return field.type(); 1329 return field.type();
1301 } 1330 }
1302 1331
1303 } // namespace dart 1332 } // namespace dart
OLDNEW
« 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