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

Side by Side Diff: pkg/compiler/lib/src/mirrors/dart2js_mirrors.dart

Issue 716913005: Replace ResolvedNode by ConstantExpression. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 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 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 library dart2js.mirrors; 5 library dart2js.mirrors;
6 6
7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView; 7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView;
8 8
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // TODO(johnniwinther): make sure that these are returned in declaration 441 // TODO(johnniwinther): make sure that these are returned in declaration
442 // order. 442 // order.
443 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f); 443 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f);
444 444
445 Iterable<DeclarationMirror> _getDeclarationMirrors(Element element) => 445 Iterable<DeclarationMirror> _getDeclarationMirrors(Element element) =>
446 _library._getDeclarationMirrors(element); 446 _library._getDeclarationMirrors(element);
447 447
448 Uri get uri => _element.script.resourceUri; 448 Uri get uri => _element.script.resourceUri;
449 } 449 }
450 450
451 class ResolvedNode {
452 final node;
453 final _elements;
454 final _mirrorSystem;
455 ResolvedNode(this.node, this._elements, this._mirrorSystem);
456
457 Mirror resolvedMirror(node) {
458 var element = _elements[node];
459 if (element == null) return null;
460 return _convertElementToDeclarationMirror(_mirrorSystem, element);
461 }
462 }
463
464 /** 451 /**
465 * Transitional class that allows access to features that have not yet 452 * Transitional class that allows access to features that have not yet
466 * made it to the mirror API. 453 * made it to the mirror API.
467 * 454 *
468 * All API in this class is experimental. 455 * All API in this class is experimental.
469 */ 456 */
470 class BackDoor { 457 class BackDoor {
471 /// Return the compilation units comprising [library]. 458 /// Return the compilation units comprising [library].
472 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { 459 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) {
473 return library._element.compilationUnits.mapToList( 460 return library._element.compilationUnits.mapToList(
474 (cu) => new Dart2JsCompilationUnitMirror(cu, library)); 461 (cu) => new Dart2JsCompilationUnitMirror(cu, library));
475 } 462 }
476 463
477 static Iterable metadataSyntaxOf(Dart2JsElementMirror declaration) { 464 static Iterable<ConstantExpression> metadataSyntaxOf(
478 Compiler compiler = declaration.mirrorSystem.compiler; 465 Dart2JsElementMirror declaration) {
479 return declaration._element.metadata.map((metadata) { 466 return declaration._element.metadata.map((metadata) => metadata.constant);
480 var node = metadata.parseNode(compiler);
481 var treeElements = metadata.annotatedElement.treeElements;
482 return new ResolvedNode(
483 node, treeElements, declaration.mirrorSystem);
484 });
485 } 467 }
486 468
487 static ResolvedNode initializerSyntaxOf(Dart2JsFieldMirror variable) { 469 static ConstantExpression initializerSyntaxOf(Dart2JsFieldMirror variable) {
488 var node = variable._variable.initializer; 470 Compiler compiler = variable.mirrorSystem.compiler;
489 if (node == null) return null; 471 return compiler.constants.getConstantForVariable(variable._variable);
490 return new ResolvedNode(
491 node, variable._variable.treeElements, variable.mirrorSystem);
492 } 472 }
493 473
494 static ResolvedNode defaultValueSyntaxOf(Dart2JsParameterMirror parameter) { 474 static ConstantExpression defaultValueSyntaxOf(
475 Dart2JsParameterMirror parameter) {
495 if (!parameter.hasDefaultValue) return null; 476 if (!parameter.hasDefaultValue) return null;
496 ParameterElement parameterElement = parameter._element; 477 ParameterElement parameterElement = parameter._element;
497 var node = parameterElement.initializer; 478 Compiler compiler = parameter.mirrorSystem.compiler;
498 var treeElements = parameterElement.treeElements; 479 return compiler.constants.getConstantForVariable(parameterElement);
499 return new ResolvedNode(node, treeElements, parameter.mirrorSystem); 480 }
481
482 static Mirror getMirrorFromElement(Dart2JsMirror mirror, Element element) {
483 return _convertElementToDeclarationMirror(mirror.mirrorSystem, element);
500 } 484 }
501 } 485 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart ('k') | pkg/docgen/lib/src/models/annotation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698