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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 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 mirrors_dart2js; 5 library mirrors_dart2js;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../../compiler/compiler.dart' as diagnostics; 10 import '../../compiler.dart' as diagnostics;
11 import '../../../../compiler/implementation/elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../../../../compiler/implementation/resolution/resolution.dart' 12 import '../resolution/resolution.dart' show ResolverTask, ResolverVisitor;
13 show ResolverTask, ResolverVisitor; 13 import '../apiimpl.dart' as api;
14 import '../../../../compiler/implementation/apiimpl.dart' as api; 14 import '../scanner/scannerlib.dart';
15 import '../../../../compiler/implementation/scanner/scannerlib.dart'; 15 import '../ssa/ssa.dart';
16 import '../../../../compiler/implementation/ssa/ssa.dart'; 16 import '../dart2jslib.dart';
17 import '../../../../compiler/implementation/dart2jslib.dart'; 17 import '../filenames.dart';
18 import '../../../../compiler/implementation/filenames.dart'; 18 import '../source_file.dart';
19 import '../../../../compiler/implementation/source_file.dart'; 19 import '../tree/tree.dart';
20 import '../../../../compiler/implementation/tree/tree.dart'; 20 import '../util/util.dart';
21 import '../../../../compiler/implementation/util/util.dart'; 21 import '../util/uri_extras.dart';
22 import '../../../../compiler/implementation/util/uri_extras.dart'; 22 import '../dart2js.dart';
23 import '../../../../compiler/implementation/dart2js.dart'; 23 import '../util/characters.dart';
24 import '../../../../compiler/implementation/util/characters.dart';
25 24
26 // TODO(rnystrom): Use "package:" URL (#4968). 25 import 'mirrors.dart';
27 import '../../mirrors.dart';
28 import 'util.dart'; 26 import 'util.dart';
29 27
30 //------------------------------------------------------------------------------ 28 //------------------------------------------------------------------------------
31 // Utility types and functions for the dart2js mirror system 29 // Utility types and functions for the dart2js mirror system
32 //------------------------------------------------------------------------------ 30 //------------------------------------------------------------------------------
33 31
34 bool _isPrivate(String name) { 32 bool _isPrivate(String name) {
35 return name.startsWith('_'); 33 return name.startsWith('_');
36 } 34 }
37 35
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 } 1346 }
1349 } 1347 }
1350 1348
1351 //------------------------------------------------------------------------------ 1349 //------------------------------------------------------------------------------
1352 // Member mirrors implementation. 1350 // Member mirrors implementation.
1353 //------------------------------------------------------------------------------ 1351 //------------------------------------------------------------------------------
1354 1352
1355 class Dart2JsMethodMirror extends Dart2JsMemberMirror 1353 class Dart2JsMethodMirror extends Dart2JsMemberMirror
1356 implements MethodMirror { 1354 implements MethodMirror {
1357 final Dart2JsContainerMirror _objectMirror; 1355 final Dart2JsContainerMirror _objectMirror;
1358 String _simpleName; 1356 final String simpleName;
1359 String _displayName; 1357 final String displayName;
1360 String _constructorName; 1358 final String constructorName;
1361 String _operatorName; 1359 final String operatorName;
1362 Dart2JsMethodKind _kind; 1360 final Dart2JsMethodKind _kind;
1363 1361
1364 Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror, 1362 Dart2JsMethodMirror._internal(Dart2JsContainerMirror objectMirror,
1365 FunctionElement function) 1363 FunctionElement function,
1364 String this.simpleName,
1365 String this.displayName,
1366 String this.constructorName,
1367 String this.operatorName,
1368 Dart2JsMethodKind this._kind)
1366 : this._objectMirror = objectMirror, 1369 : this._objectMirror = objectMirror,
1367 super(objectMirror.mirrors, function) { 1370 super(objectMirror.mirrors, function);
1368 _simpleName = _element.name.slowToString(); 1371
1369 if (_function.kind == ElementKind.GETTER) { 1372 factory Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror,
1370 _kind = Dart2JsMethodKind.GETTER; 1373 FunctionElement function) {
1371 _displayName = _simpleName; 1374 String simpleName = function.name.slowToString();
1372 } else if (_function.kind == ElementKind.SETTER) { 1375 String displayName;
1373 _kind = Dart2JsMethodKind.SETTER; 1376 String constructorName = null;
1374 _displayName = _simpleName; 1377 String operatorName = null;
1375 _simpleName = '$_simpleName='; 1378 Dart2JsMethodKind kind;
1376 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 1379 if (function.kind == ElementKind.GETTER) {
1380 kind = Dart2JsMethodKind.GETTER;
1381 displayName = simpleName;
1382 } else if (function.kind == ElementKind.SETTER) {
1383 kind = Dart2JsMethodKind.SETTER;
1384 displayName = simpleName;
1385 simpleName = '$simpleName=';
1386 } else if (function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
1377 // TODO(johnniwinther): Support detection of redirecting constructors. 1387 // TODO(johnniwinther): Support detection of redirecting constructors.
1378 _constructorName = ''; 1388 constructorName = '';
1379 int dollarPos = _simpleName.indexOf('\$'); 1389 int dollarPos = simpleName.indexOf('\$');
1380 if (dollarPos != -1) { 1390 if (dollarPos != -1) {
1381 _constructorName = _simpleName.substring(dollarPos + 1); 1391 constructorName = simpleName.substring(dollarPos + 1);
1382 _simpleName = _simpleName.substring(0, dollarPos); 1392 simpleName = simpleName.substring(0, dollarPos);
1383 // Simple name is TypeName.constructorName. 1393 // Simple name is TypeName.constructorName.
1384 _simpleName = '$_simpleName.$_constructorName'; 1394 simpleName = '$simpleName.$constructorName';
1385 } else { 1395 } else {
1386 // Simple name is TypeName. 1396 // Simple name is TypeName.
1387 } 1397 }
1388 if (_function.modifiers.isConst()) { 1398 if (function.modifiers.isConst()) {
1389 _kind = Dart2JsMethodKind.CONST; 1399 kind = Dart2JsMethodKind.CONST;
1390 } else { 1400 } else {
1391 _kind = Dart2JsMethodKind.GENERATIVE; 1401 kind = Dart2JsMethodKind.GENERATIVE;
1392 } 1402 }
1393 _displayName = _simpleName; 1403 displayName = simpleName;
1394 } else if (_function.modifiers.isFactory()) { 1404 } else if (function.modifiers.isFactory()) {
1395 _kind = Dart2JsMethodKind.FACTORY; 1405 kind = Dart2JsMethodKind.FACTORY;
1396 _constructorName = ''; 1406 constructorName = '';
1397 int dollarPos = _simpleName.indexOf('\$'); 1407 int dollarPos = simpleName.indexOf('\$');
1398 if (dollarPos != -1) { 1408 if (dollarPos != -1) {
1399 _constructorName = _simpleName.substring(dollarPos+1); 1409 constructorName = simpleName.substring(dollarPos+1);
1400 _simpleName = _simpleName.substring(0, dollarPos); 1410 simpleName = simpleName.substring(0, dollarPos);
1401 _simpleName = '$_simpleName.$_constructorName'; 1411 simpleName = '$simpleName.$constructorName';
1402 } 1412 }
1403 // Simple name is TypeName.constructorName. 1413 // Simple name is TypeName.constructorName.
1404 _displayName = _simpleName; 1414 displayName = simpleName;
1405 } else if (_simpleName == 'negate') { 1415 } else if (simpleName == 'negate') {
1406 _kind = Dart2JsMethodKind.OPERATOR; 1416 kind = Dart2JsMethodKind.OPERATOR;
1407 _operatorName = '-'; 1417 operatorName = '-';
1408 // Simple name is 'unary-'. 1418 // Simple name is 'unary-'.
1409 _simpleName = Mirror.UNARY_MINUS; 1419 simpleName = Mirror.UNARY_MINUS;
1410 // Display name is 'operator operatorName'. 1420 // Display name is 'operator operatorName'.
1411 _displayName = 'operator -'; 1421 displayName = 'operator -';
1412 } else if (_simpleName.startsWith('operator\$')) { 1422 } else if (simpleName.startsWith('operator\$')) {
1413 String str = _simpleName.substring(9); 1423 String str = simpleName.substring(9);
1414 _simpleName = 'operator'; 1424 simpleName = 'operator';
1415 _kind = Dart2JsMethodKind.OPERATOR; 1425 kind = Dart2JsMethodKind.OPERATOR;
1416 _operatorName = _getOperatorFromOperatorName(str); 1426 operatorName = _getOperatorFromOperatorName(str);
1417 // Simple name is 'operator operatorName'. 1427 // Simple name is 'operator operatorName'.
1418 _simpleName = _operatorName; 1428 simpleName = operatorName;
1419 // Display name is 'operator operatorName'. 1429 // Display name is 'operator operatorName'.
1420 _displayName = 'operator $_operatorName'; 1430 displayName = 'operator $operatorName';
1421 } else { 1431 } else {
1422 _kind = Dart2JsMethodKind.REGULAR; 1432 kind = Dart2JsMethodKind.REGULAR;
1423 _displayName = _simpleName; 1433 displayName = simpleName;
1424 } 1434 }
1435 return new Dart2JsMethodMirror._internal(objectMirror, function,
1436 simpleName, displayName, constructorName, operatorName, kind);
1425 } 1437 }
1426 1438
1427 FunctionElement get _function => _element; 1439 FunctionElement get _function => _element;
1428 1440
1429 String get simpleName => _simpleName;
1430
1431 String get displayName => _displayName;
1432
1433 String get qualifiedName 1441 String get qualifiedName
1434 => '${owner.qualifiedName}.$simpleName'; 1442 => '${owner.qualifiedName}.$simpleName';
1435 1443
1436 DeclarationMirror get owner => _objectMirror; 1444 DeclarationMirror get owner => _objectMirror;
1437 1445
1438 bool get isTopLevel => _objectMirror is LibraryMirror; 1446 bool get isTopLevel => _objectMirror is LibraryMirror;
1439 1447
1440 bool get isConstructor 1448 bool get isConstructor
1441 => isGenerativeConstructor || isConstConstructor || 1449 => isGenerativeConstructor || isConstConstructor ||
1442 isFactoryConstructor || isRedirectingConstructor; 1450 isFactoryConstructor || isRedirectingConstructor;
(...skipping 19 matching lines...) Expand all
1462 bool get isRegularMethod => !(isGetter || isSetter || isConstructor); 1470 bool get isRegularMethod => !(isGetter || isSetter || isConstructor);
1463 1471
1464 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST; 1472 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST;
1465 1473
1466 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE; 1474 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE;
1467 1475
1468 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING; 1476 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING;
1469 1477
1470 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY; 1478 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY;
1471 1479
1472 String get constructorName => _constructorName;
1473
1474 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; 1480 bool get isGetter => _kind == Dart2JsMethodKind.GETTER;
1475 1481
1476 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; 1482 bool get isSetter => _kind == Dart2JsMethodKind.SETTER;
1477 1483
1478 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; 1484 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR;
1479 1485
1480 String get operatorName => _operatorName;
1481
1482 SourceLocation get location { 1486 SourceLocation get location {
1483 var node = _function.parseNode(_diagnosticListener); 1487 var node = _function.parseNode(_diagnosticListener);
1484 if (node != null) { 1488 if (node != null) {
1485 var script = _function.getCompilationUnit().script; 1489 var script = _function.getCompilationUnit().script;
1486 var span = mirrors.compiler.spanFromNode(node, script.uri); 1490 var span = mirrors.compiler.spanFromNode(node, script.uri);
1487 return new Dart2JsSourceLocation(script, span); 1491 return new Dart2JsSourceLocation(script, span);
1488 } 1492 }
1489 return super.location; 1493 return super.location;
1490 } 1494 }
1491 1495
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 if (node != null) { 1530 if (node != null) {
1527 var span = mirrors.compiler.spanFromNode(node, script.uri); 1531 var span = mirrors.compiler.spanFromNode(node, script.uri);
1528 return new Dart2JsSourceLocation(script, span); 1532 return new Dart2JsSourceLocation(script, span);
1529 } else { 1533 } else {
1530 var span = mirrors.compiler.spanFromElement(_variable); 1534 var span = mirrors.compiler.spanFromElement(_variable);
1531 return new Dart2JsSourceLocation(script, span); 1535 return new Dart2JsSourceLocation(script, span);
1532 } 1536 }
1533 } 1537 }
1534 } 1538 }
1535 1539
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698