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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 10916252: Implement more of the mirrors library, primarily stuff to do with types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_debugger_api.h" 6 #include "include/dart_debugger_api.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 Dart_Handle unwrapped_arg = UnwrapArg(arg); 186 Dart_Handle unwrapped_arg = UnwrapArg(arg);
187 if (Dart_IsError(unwrapped_arg)) { 187 if (Dart_IsError(unwrapped_arg)) {
188 return unwrapped_arg; 188 return unwrapped_arg;
189 } 189 }
190 arg_array->Add(unwrapped_arg); 190 arg_array->Add(unwrapped_arg);
191 } 191 }
192 return Dart_True(); 192 return Dart_True();
193 } 193 }
194 194
195 195
196 static Dart_Handle CreateLazyMirror(Dart_Handle target);
197
198
199 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) {
200 int64_t fixed_param_count;
201 int64_t opt_param_count;
202 Dart_Handle result = Dart_FunctionParameterCounts(func,
203 &fixed_param_count,
204 &opt_param_count);
205 if (Dart_IsError(result)) {
206 return result;
207 }
208
209 int64_t param_count = fixed_param_count + opt_param_count;
210 Dart_Handle parameter_list = Dart_NewList(param_count);
211 if (Dart_IsError(parameter_list)) {
212 return result;
213 }
214
215 Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl");
216 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name);
217 if (Dart_IsError(param_cls)) {
218 return param_cls;
219 }
220
221 for (int i = 0; i < param_count; i++) {
222 Dart_Handle param_type = Dart_FunctionParameterType(func, i);
223 if (Dart_IsError(param_type)) {
224 return param_type;
225 }
226 Dart_Handle args[] = {
227 CreateLazyMirror(param_type),
228 Dart_NewBoolean(i >= fixed_param_count), // optional param?
229 };
230 Dart_Handle param =
231 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args);
232 if (Dart_IsError(param)) {
233 return param;
234 }
235 result = Dart_ListSetAt(parameter_list, i, param);
236 if (Dart_IsError(result)) {
237 return result;
238 }
239 }
240 return parameter_list;
241 }
242
243
196 static Dart_Handle CreateLazyMirror(Dart_Handle target) { 244 static Dart_Handle CreateLazyMirror(Dart_Handle target) {
197 if (Dart_IsNull(target)) { 245 if (Dart_IsNull(target) || Dart_IsError(target)) {
198 return target; 246 return target;
199 } 247 }
200 if (Dart_IsLibrary(target)) { 248 if (Dart_IsLibrary(target)) {
201 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); 249 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror");
202 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 250 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
203 Dart_Handle args[] = { Dart_LibraryName(target) }; 251 Dart_Handle args[] = { Dart_LibraryName(target) };
204 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 252 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
205 } else { 253
206 ASSERT(Dart_IsClass(target) || Dart_IsInterface(target)); 254 } else if (Dart_IsClass(target) || Dart_IsInterface(target)) {
cshapiro 2012/09/12 18:52:07 why else if when you return on line 252? That is
turnidge 2012/09/12 21:39:30 Got rid of all of the else-ifs. Didn't add the as
207 Dart_Handle cls_name = Dart_NewString("_LazyClassMirror"); 255 if (Dart_ClassIsFunctionType(target)) {
256 Dart_Handle cls_name = Dart_NewString("_LazyFunctionTypeMirror");
257 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
258
259 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target);
260 Dart_Handle return_type = Dart_FunctionReturnType(sig);
261 if (Dart_IsError(return_type)) {
262 return return_type;
263 }
264
265 Dart_Handle args[] = {
266 CreateLazyMirror(return_type),
267 CreateParameterMirrorList(sig),
268 };
269 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
270
271 } else {
272 Dart_Handle cls_name = Dart_NewString("_LazyTypeMirror");
273 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
274 Dart_Handle lib = Dart_ClassGetLibrary(target);
275 Dart_Handle lib_name;
276 if (Dart_IsNull(lib)) {
277 lib_name = Dart_Null();
278 } else {
279 lib_name = Dart_LibraryName(lib);
280 }
281 Dart_Handle args[] = { lib_name, Dart_ClassName(target) };
282 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
283 }
284 } else if (Dart_IsTypeVariable(target)) {
cshapiro 2012/09/12 18:52:07 instead of else if, make this an ASSERT instead?
285 Dart_Handle var_name = Dart_TypeVariableName(target);
286 Dart_Handle owner = Dart_TypeVariableOwner(target);
287 Dart_Handle owner_mirror = CreateLazyMirror(owner);
288
289 Dart_Handle cls_name = Dart_NewString("_LazyTypeVariableMirror");
208 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 290 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
209 291
210 Dart_Handle lib = Dart_ClassGetLibrary(target); 292 Dart_Handle args[] = { var_name, owner_mirror };
211 Dart_Handle lib_name; 293 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
212 if (Dart_IsNull(lib)) {
213 lib_name = Dart_Null();
214 } else {
215 lib_name = Dart_LibraryName(lib);
216 }
217 294
218 Dart_Handle args[] = { lib_name, Dart_ClassName(target) }; 295 } else {
219 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 296 UNIMPLEMENTED();
297 return Dart_Null();
220 } 298 }
221 } 299 }
222 300
223 301
224 static Dart_Handle CreateImplementsList(Dart_Handle intf) { 302 static Dart_Handle CreateImplementsList(Dart_Handle intf) {
225 intptr_t len = 0; 303 intptr_t len = 0;
226 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len); 304 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len);
227 if (Dart_IsError(result)) { 305 if (Dart_IsError(result)) {
228 return result; 306 return result;
229 } 307 }
(...skipping 14 matching lines...) Expand all
244 } 322 }
245 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); 323 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror);
246 if (Dart_IsError(result)) { 324 if (Dart_IsError(result)) {
247 return result; 325 return result;
248 } 326 }
249 } 327 }
250 return mirror_list; 328 return mirror_list;
251 } 329 }
252 330
253 331
254 static Dart_Handle CreateMemberMap(Dart_Handle owner); 332 static Dart_Handle CreateTypeVariableMirror(Dart_Handle type_var,
333 Dart_Handle type_var_name,
334 Dart_Handle owner_mirror) {
335 ASSERT(Dart_IsTypeVariable(type_var));
336 Dart_Handle cls_name = Dart_NewString("_LocalTypeVariableMirrorImpl");
337 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
338 if (Dart_IsError(cls)) {
339 return cls;
340 }
341
342 Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var);
343 if (Dart_IsError(upper_bound)) {
344 return upper_bound;
345 }
346
347 Dart_Handle args[] = {
348 type_var_name,
349 owner_mirror,
350 CreateLazyMirror(upper_bound),
351 };
352 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
353 return mirror;
354 }
355
356
357 static Dart_Handle CreateTypeVariableMap(Dart_Handle owner,
358 Dart_Handle owner_mirror) {
359 ASSERT(Dart_IsClass(owner) || Dart_IsInterface(owner));
360 // TODO(turnidge): This should be an immutable map.
361 Dart_Handle result;
cshapiro 2012/09/12 18:52:07 move this down to line 372.
turnidge 2012/09/12 21:39:30 Done.
362 Dart_Handle map = MapNew();
363 if (Dart_IsError(map)) {
364 return map;
365 }
366
367 Dart_Handle names = Dart_GetTypeVariableNames(owner);
368 if (Dart_IsError(names)) {
369 return names;
370 }
371 intptr_t len;
372 result = Dart_ListLength(names, &len);
373 if (Dart_IsError(result)) {
374 return result;
375 }
376 for (int i = 0; i < len; i++) {
cshapiro 2012/09/12 18:52:07 intptr_t ?
turnidge 2012/09/12 21:39:30 Changed here and about 8 other places.
377 Dart_Handle type_var_name = Dart_ListGetAt(names, i);
378 Dart_Handle type_var = Dart_LookupTypeVariable(owner, type_var_name);
379 if (Dart_IsError(type_var)) {
380 return type_var;
381 }
382 ASSERT(!Dart_IsNull(type_var));
383 Dart_Handle type_var_mirror =
384 CreateTypeVariableMirror(type_var, type_var_name, owner_mirror);
385 if (Dart_IsError(type_var_mirror)) {
386 return type_var_mirror;
387 }
388 result = MapAdd(map, type_var_name, type_var_mirror);
389 if (Dart_IsError(result)) {
390 return result;
391 }
392 }
393 return map;
394 }
395
396
397 static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
398 Dart_Handle cls_name,
399 Dart_Handle owner,
400 Dart_Handle owner_mirror) {
401 Dart_Handle mirror_cls_name = Dart_NewString("_LocalTypedefMirrorImpl");
402 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
403 if (Dart_IsError(mirror_cls)) {
404 return mirror_cls;
405 }
406
407 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls);
408 if (Dart_IsError(referent)) {
409 return referent;
410 }
411
412 Dart_Handle args[] = {
413 cls_name,
414 owner_mirror,
415 CreateLazyMirror(referent),
416 };
417 Dart_Handle mirror =
418 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args);
419 return mirror;
420 }
421
422
423 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror);
255 424
256 425
257 static Dart_Handle CreateClassMirror(Dart_Handle intf, 426 static Dart_Handle CreateClassMirror(Dart_Handle intf,
258 Dart_Handle intf_name, 427 Dart_Handle intf_name,
259 Dart_Handle lib, 428 Dart_Handle lib,
260 Dart_Handle lib_mirror) { 429 Dart_Handle lib_mirror) {
261 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); 430 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf));
431 if (Dart_ClassIsTypedef(intf)) {
432 // This class is actually a typedef. Represent it specially in
433 // reflection.
434 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror);
435 }
436
262 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl"); 437 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl");
263 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 438 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
264 if (Dart_IsError(cls)) { 439 if (Dart_IsError(cls)) {
265 return cls; 440 return cls;
266 } 441 }
267 442
268 // TODO(turnidge): Why am I getting Null when I expect Object? 443 // TODO(turnidge): Why am I getting Null when I expect Object?
269 Dart_Handle super_class = Dart_GetSuperclass(intf); 444 Dart_Handle super_class = Dart_GetSuperclass(intf);
270 if (Dart_IsNull(super_class)) { 445 if (Dart_IsNull(super_class)) {
271 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); 446 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object"));
272 } 447 }
273 Dart_Handle default_class = Dart_ClassGetDefault(intf); 448 Dart_Handle default_class = Dart_ClassGetDefault(intf);
274 Dart_Handle member_map = CreateMemberMap(intf); 449
450 Dart_Handle intf_mirror = CreateLazyMirror(intf);
451 if (Dart_IsError(intf_mirror)) {
452 return intf_mirror;
453 }
454 Dart_Handle member_map = CreateMemberMap(intf, intf_mirror);
275 if (Dart_IsError(member_map)) { 455 if (Dart_IsError(member_map)) {
276 return member_map; 456 return member_map;
277 } 457 }
458 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror);
459 if (Dart_IsError(type_var_map)) {
460 return type_var_map;
461 }
278 462
279 Dart_Handle args[] = { 463 Dart_Handle args[] = {
280 CreateVMReference(intf), 464 CreateVMReference(intf),
281 intf_name, 465 intf_name,
282 Dart_NewBoolean(Dart_IsClass(intf)), 466 Dart_NewBoolean(Dart_IsClass(intf)),
283 lib_mirror, 467 lib_mirror,
284 CreateLazyMirror(super_class), 468 CreateLazyMirror(super_class),
285 CreateImplementsList(intf), 469 CreateImplementsList(intf),
286 CreateLazyMirror(default_class), 470 CreateLazyMirror(default_class),
287 member_map, 471 member_map,
472 type_var_map,
288 }; 473 };
289 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 474 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
290 return mirror; 475 return mirror;
291 } 476 }
292 477
293 478
294 static Dart_Handle CreateMethodMirror(Dart_Handle func, 479 static Dart_Handle CreateMethodMirror(Dart_Handle func,
295 Dart_Handle func_name, 480 Dart_Handle func_name,
296 Dart_Handle owner_mirror) { 481 Dart_Handle owner_mirror) {
297 ASSERT(Dart_IsFunction(func)); 482 ASSERT(Dart_IsFunction(func));
298 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl"); 483 Dart_Handle mirror_cls_name = Dart_NewString("_LocalMethodMirrorImpl");
299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 484 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
300 if (Dart_IsError(cls)) { 485 if (Dart_IsError(mirror_cls)) {
301 return cls; 486 return mirror_cls;
302 } 487 }
303 488
304 bool is_static = false; 489 bool is_static = false;
305 bool is_abstract = false; 490 bool is_abstract = false;
306 bool is_getter = false; 491 bool is_getter = false;
307 bool is_setter = false; 492 bool is_setter = false;
308 bool is_constructor = false; 493 bool is_constructor = false;
309 494
310 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static); 495 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static);
311 if (Dart_IsError(result)) { 496 if (Dart_IsError(result)) {
312 return result; 497 return result;
313 } 498 }
314 result = Dart_FunctionIsAbstract(func, &is_abstract); 499 result = Dart_FunctionIsAbstract(func, &is_abstract);
315 if (Dart_IsError(result)) { 500 if (Dart_IsError(result)) {
316 return result; 501 return result;
317 } 502 }
318 result = Dart_FunctionIsGetter(func, &is_getter); 503 result = Dart_FunctionIsGetter(func, &is_getter);
319 if (Dart_IsError(result)) { 504 if (Dart_IsError(result)) {
320 return result; 505 return result;
321 } 506 }
322 result = Dart_FunctionIsSetter(func, &is_setter); 507 result = Dart_FunctionIsSetter(func, &is_setter);
323 if (Dart_IsError(result)) { 508 if (Dart_IsError(result)) {
324 return result; 509 return result;
325 } 510 }
326 result = Dart_FunctionIsConstructor(func, &is_constructor); 511 result = Dart_FunctionIsConstructor(func, &is_constructor);
327 if (Dart_IsError(result)) { 512 if (Dart_IsError(result)) {
328 return result; 513 return result;
329 } 514 }
330 515
516 Dart_Handle return_type = Dart_FunctionReturnType(func);
517 if (Dart_IsError(return_type)) {
518 return return_type;
519 }
520
331 int64_t fixed_param_count; 521 int64_t fixed_param_count;
332 int64_t opt_param_count; 522 int64_t opt_param_count;
333 result = Dart_FunctionParameterCounts(func, 523 result = Dart_FunctionParameterCounts(func,
334 &fixed_param_count, 524 &fixed_param_count,
335 &opt_param_count); 525 &opt_param_count);
336 if (Dart_IsError(result)) { 526 if (Dart_IsError(result)) {
337 return result; 527 return result;
338 } 528 }
339 529
340 Dart_Handle parameter_mirrors =
341 Dart_NewList(fixed_param_count + opt_param_count);
342 if (Dart_IsError(parameter_mirrors)) {
343 return result;
344 }
345
346 Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl");
347 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name);
348 if (Dart_IsError(param_cls)) {
349 return param_cls;
350 }
351
352 // TODO(rmacnak): Fill the parameter mirrors with more than whether they are
353 // are optional.
354 for (int i = 0; i < fixed_param_count; i++) {
355 Dart_Handle args[] = { Dart_False() };
356 Dart_Handle fixed_param =
357 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args);
358 if (Dart_IsError(fixed_param)) {
359 return fixed_param;
360 }
361 result = Dart_ListSetAt(parameter_mirrors, i, fixed_param);
362 if (Dart_IsError(result)) {
363 return result;
364 }
365 }
366
367 for (int i = 0; i < opt_param_count; i++) {
368 Dart_Handle args[] = { Dart_True() };
369 Dart_Handle opt_param =
370 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args);
371 if (Dart_IsError(opt_param)) {
372 return opt_param;
373 }
374 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param);
375 if (Dart_IsError(result)) {
376 return result;
377 }
378 }
379
380 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). 530 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10).
381 Dart_Handle args[] = { 531 Dart_Handle args[] = {
382 func_name, 532 func_name,
383 owner_mirror, 533 owner_mirror,
384 parameter_mirrors, 534 CreateParameterMirrorList(func),
535 CreateLazyMirror(return_type),
385 Dart_NewBoolean(is_static), 536 Dart_NewBoolean(is_static),
386 Dart_NewBoolean(is_abstract), 537 Dart_NewBoolean(is_abstract),
387 Dart_NewBoolean(is_getter), 538 Dart_NewBoolean(is_getter),
388 Dart_NewBoolean(is_setter), 539 Dart_NewBoolean(is_setter),
389 Dart_NewBoolean(is_constructor), 540 Dart_NewBoolean(is_constructor),
390 Dart_False(), 541 Dart_False(),
391 Dart_False(), 542 Dart_False(),
392 Dart_False(), 543 Dart_False(),
393 Dart_False(), 544 Dart_False(),
394 }; 545 };
395 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 546 Dart_Handle mirror =
547 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args);
396 return mirror; 548 return mirror;
397 } 549 }
398 550
399 551
400 static Dart_Handle CreateVariableMirror(Dart_Handle var, 552 static Dart_Handle CreateVariableMirror(Dart_Handle var,
401 Dart_Handle var_name, 553 Dart_Handle var_name,
402 Dart_Handle lib_mirror) { 554 Dart_Handle lib_mirror) {
403 ASSERT(Dart_IsVariable(var)); 555 ASSERT(Dart_IsVariable(var));
404 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl"); 556 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl");
405 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 557 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
406 if (Dart_IsError(cls)) { 558 if (Dart_IsError(cls)) {
407 return cls; 559 return cls;
408 } 560 }
409 561
410 bool is_static = false; 562 bool is_static = false;
411 bool is_final = false; 563 bool is_final = false;
412 564
565 Dart_Handle type = Dart_VariableType(var);
cshapiro 2012/09/12 18:52:07 move this above the is_* stuff?
turnidge 2012/09/12 21:39:30 Rearranged.
566 if (Dart_IsError(type)) {
567 return type;
568 }
569
413 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); 570 Dart_Handle result = Dart_VariableIsStatic(var, &is_static);
414 if (Dart_IsError(result)) { 571 if (Dart_IsError(result)) {
415 return result; 572 return result;
416 } 573 }
417 result = Dart_VariableIsFinal(var, &is_final); 574 result = Dart_VariableIsFinal(var, &is_final);
418 if (Dart_IsError(result)) { 575 if (Dart_IsError(result)) {
419 return result; 576 return result;
420 } 577 }
421 578
422 Dart_Handle args[] = { 579 Dart_Handle args[] = {
423 var_name, 580 var_name,
424 lib_mirror, 581 lib_mirror,
582 CreateLazyMirror(type),
425 Dart_NewBoolean(is_static), 583 Dart_NewBoolean(is_static),
426 Dart_NewBoolean(is_final), 584 Dart_NewBoolean(is_final),
427 }; 585 };
428 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 586 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
429 return mirror; 587 return mirror;
430 } 588 }
431 589
432 590
433 static Dart_Handle AddMemberClasses(Dart_Handle map, 591 static Dart_Handle AddMemberClasses(Dart_Handle map,
434 Dart_Handle owner, 592 Dart_Handle owner,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 681 }
524 result = MapAdd(map, var_name, var_mirror); 682 result = MapAdd(map, var_name, var_mirror);
525 if (Dart_IsError(result)) { 683 if (Dart_IsError(result)) {
526 return result; 684 return result;
527 } 685 }
528 } 686 }
529 return Dart_True(); 687 return Dart_True();
530 } 688 }
531 689
532 690
533 static Dart_Handle CreateMemberMap(Dart_Handle owner) { 691 static Dart_Handle CreateMemberMap(Dart_Handle owner,
692 Dart_Handle owner_mirror) {
534 // TODO(turnidge): This should be an immutable map. 693 // TODO(turnidge): This should be an immutable map.
535 Dart_Handle owner_mirror = CreateLazyMirror(owner);
536 if (Dart_IsError(owner_mirror)) { 694 if (Dart_IsError(owner_mirror)) {
537 return owner_mirror; 695 return owner_mirror;
538 } 696 }
539 Dart_Handle result; 697 Dart_Handle result;
540 Dart_Handle map = MapNew(); 698 Dart_Handle map = MapNew();
541 if (Dart_IsLibrary(owner)) { 699 if (Dart_IsLibrary(owner)) {
542 result = AddMemberClasses(map, owner, owner_mirror); 700 result = AddMemberClasses(map, owner, owner_mirror);
543 if (Dart_IsError(result)) { 701 if (Dart_IsError(result)) {
544 return result; 702 return result;
545 } 703 }
546 } 704 }
547 result = AddMemberFunctions(map, owner, owner_mirror); 705 result = AddMemberFunctions(map, owner, owner_mirror);
548 if (Dart_IsError(result)) { 706 if (Dart_IsError(result)) {
549 return result; 707 return result;
550 } 708 }
551 result = AddMemberVariables(map, owner, owner_mirror); 709 result = AddMemberVariables(map, owner, owner_mirror);
552 if (Dart_IsError(result)) { 710 if (Dart_IsError(result)) {
553 return result; 711 return result;
554 } 712 }
555 return map; 713 return map;
556 } 714 }
557 715
558 716
559 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { 717 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) {
560 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); 718 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl");
561 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 719 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
562 if (Dart_IsError(cls)) { 720 if (Dart_IsError(cls)) {
563 return cls; 721 return cls;
564 } 722 }
565 Dart_Handle member_map = CreateMemberMap(lib); 723 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib);
724 if (Dart_IsError(lazy_lib_mirror)) {
725 return lazy_lib_mirror;
726 }
727 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror);
566 if (Dart_IsError(member_map)) { 728 if (Dart_IsError(member_map)) {
567 return member_map; 729 return member_map;
568 } 730 }
569 Dart_Handle args[] = { 731 Dart_Handle args[] = {
570 CreateVMReference(lib), 732 CreateVMReference(lib),
571 Dart_LibraryName(lib), 733 Dart_LibraryName(lib),
572 Dart_LibraryUrl(lib), 734 Dart_LibraryUrl(lib),
573 member_map, 735 member_map,
574 }; 736 };
575 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 737 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return mirror; 832 return mirror;
671 } 833 }
672 834
673 835
674 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { 836 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
675 if (Dart_IsNull(instance)) { 837 if (Dart_IsNull(instance)) {
676 return CreateNullMirror(); 838 return CreateNullMirror();
677 } 839 }
678 ASSERT(Dart_IsInstance(instance)); 840 ASSERT(Dart_IsInstance(instance));
679 841
680 bool is_closure = Dart_IsClosure(instance);
681 Dart_Handle cls_name = Dart_NewString(
682 is_closure ? "_LocalClosureMirrorImpl" : "_LocalInstanceMirrorImpl");
683 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
684 if (Dart_IsError(cls)) {
685 return cls;
686 }
687 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); 842 Dart_Handle instance_cls = Dart_InstanceGetClass(instance);
688 if (Dart_IsError(instance_cls)) { 843 if (Dart_IsError(instance_cls)) {
689 return instance_cls; 844 return instance_cls;
690 } 845 }
691 846
692 Dart_Handle args[] = { 847 if (Dart_IsClosure(instance)) {
693 CreateVMReference(instance), 848 Dart_Handle cls_name = Dart_NewString("_LocalClosureMirrorImpl");
694 CreateLazyMirror(instance_cls), 849 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
695 instance 850 if (Dart_IsError(cls)) {
696 }; 851 return cls;
697 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 852 }
698
699 if (is_closure) {
700 // We set the function field of ClosureMirrors outside of the constructor 853 // We set the function field of ClosureMirrors outside of the constructor
701 // to break the mutual recursion. 854 // to break the mutual recursion.
702 Dart_Handle func = Dart_ClosureFunction(instance); 855 Dart_Handle func = Dart_ClosureFunction(instance);
703 if (Dart_IsError(func)) { 856 if (Dart_IsError(func)) {
704 return func; 857 return func;
705 } 858 }
859
860 // TODO(turnidge): Why not use the real function name here?
706 Dart_Handle func_name = Dart_NewString("call"); 861 Dart_Handle func_name = Dart_NewString("call");
707 // TODO(turnidge): Passing in 'mirror' here as the method owner 862 Dart_Handle func_owner = Dart_FunctionOwner(func);
708 // seems wrong to me. Investigate. 863 if (Dart_IsError(func_owner)) {
709 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror); 864 return func_owner;
865 }
866
867 // TODO(turnidge): Pass the function owner here. This will require
868 // us to support functions in CreateLazyMirror.
869 Dart_Handle func_mirror =
870 CreateMethodMirror(func, func_name, Dart_Null());
710 if (Dart_IsError(func_mirror)) { 871 if (Dart_IsError(func_mirror)) {
711 return func_mirror; 872 return func_mirror;
712 } 873 }
874 Dart_Handle args[] = {
875 CreateVMReference(instance),
876 CreateLazyMirror(instance_cls),
877 instance,
878 func_mirror,
879 };
880 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
713 881
714 Dart_Handle func_field_name = Dart_NewString("_function"); 882 } else {
715 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror); 883 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl");
716 if (Dart_IsError(result)) { 884 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
717 return result; 885 if (Dart_IsError(cls)) {
886 return cls;
718 } 887 }
888 Dart_Handle args[] = {
889 CreateVMReference(instance),
890 CreateLazyMirror(instance_cls),
891 instance,
892 };
893 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
719 } 894 }
720 return mirror;
721 } 895 }
722 896
723 897
724 static Dart_Handle CreateMirroredError(Dart_Handle error) { 898 static Dart_Handle CreateMirroredError(Dart_Handle error) {
725 ASSERT(Dart_IsError(error)); 899 ASSERT(Dart_IsError(error));
726 if (Dart_IsUnhandledExceptionError(error)) { 900 if (Dart_IsUnhandledExceptionError(error)) {
727 Dart_Handle exc = Dart_ErrorGetException(error); 901 Dart_Handle exc = Dart_ErrorGetException(error);
728 if (Dart_IsError(exc)) { 902 if (Dart_IsError(exc)) {
729 return exc; 903 return exc;
730 } 904 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 } 1097 }
924 1098
925 1099
926 void HandleMirrorsMessage(Isolate* isolate, 1100 void HandleMirrorsMessage(Isolate* isolate,
927 Dart_Port reply_port, 1101 Dart_Port reply_port,
928 const Instance& message) { 1102 const Instance& message) {
929 UNIMPLEMENTED(); 1103 UNIMPLEMENTED();
930 } 1104 }
931 1105
932 } // namespace dart 1106 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698