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

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 2653203002: Use entities in CommonElements interface. (Closed)
Patch Set: Created 3 years, 10 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
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.resolution.members; 5 library dart2js.resolution.members;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show Selectors; 8 import '../common/names.dart' show Selectors;
9 import '../common/resolution.dart' show Resolution; 9 import '../common/resolution.dart' show Resolution;
10 import '../compile_time_constants.dart'; 10 import '../compile_time_constants.dart';
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if ((ElementCategory.SUPER & allowedCategory) == 0) { 329 if ((ElementCategory.SUPER & allowedCategory) == 0) {
330 reporter.reportErrorMessage(node, MessageKind.INVALID_USE_OF_SUPER); 330 reporter.reportErrorMessage(node, MessageKind.INVALID_USE_OF_SUPER);
331 } 331 }
332 return const NoneResult(); 332 return const NoneResult();
333 } else { 333 } else {
334 String name = node.source; 334 String name = node.source;
335 Element element = lookupInScope(reporter, node, scope, name); 335 Element element = lookupInScope(reporter, node, scope, name);
336 if (Elements.isUnresolved(element) && name == 'dynamic') { 336 if (Elements.isUnresolved(element) && name == 'dynamic') {
337 // TODO(johnniwinther): Remove this hack when we can return more complex 337 // TODO(johnniwinther): Remove this hack when we can return more complex
338 // objects than [Element] from this method. 338 // objects than [Element] from this method.
339 element = commonElements.typeClass; 339 ClassElement typeClass = commonElements.typeClass;
340 element = typeClass;
340 // Set the type to be `dynamic` to mark that this is a type literal. 341 // Set the type to be `dynamic` to mark that this is a type literal.
341 registry.setType(node, const ResolutionDynamicType()); 342 registry.setType(node, const ResolutionDynamicType());
342 } 343 }
343 element = reportLookupErrorIfAny(element, node, name); 344 element = reportLookupErrorIfAny(element, node, name);
344 if (element == null) { 345 if (element == null) {
345 if (!inInstanceContext) { 346 if (!inInstanceContext) {
346 element = reportCannotResolve(node, name); 347 element = reportCannotResolve(node, name);
347 } 348 }
348 } else if (element.isMalformed) { 349 } else if (element.isMalformed) {
349 // Use the malformed element. 350 // Use the malformed element.
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 2079
2079 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or 2080 /// Handle access to a type literal of the type 'dynamic'. Like `dynamic` or
2080 /// `dynamic()`. 2081 /// `dynamic()`.
2081 ResolutionResult handleDynamicTypeLiteralAccess(Send node) { 2082 ResolutionResult handleDynamicTypeLiteralAccess(Send node) {
2082 ResolutionDartType type = const ResolutionDynamicType(); 2083 ResolutionDartType type = const ResolutionDynamicType();
2083 ConstantExpression constant = new TypeConstantExpression( 2084 ConstantExpression constant = new TypeConstantExpression(
2084 // TODO(johnniwinther): Use [type] when evaluation of constants is done 2085 // TODO(johnniwinther): Use [type] when evaluation of constants is done
2085 // directly on the constant expressions. 2086 // directly on the constant expressions.
2086 node.isCall ? commonElements.typeType : type); 2087 node.isCall ? commonElements.typeType : type);
2087 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); 2088 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant);
2088 return handleConstantTypeLiteralAccess(node, const PublicName('dynamic'), 2089 ClassElement typeClass = commonElements.typeClass;
2089 commonElements.typeClass, type, semantics); 2090 return handleConstantTypeLiteralAccess(
2091 node, const PublicName('dynamic'), typeClass, type, semantics);
2090 } 2092 }
2091 2093
2092 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or 2094 /// Handle update to a type literal of the type 'dynamic'. Like `dynamic++` or
2093 /// `dynamic = 0`. 2095 /// `dynamic = 0`.
2094 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) { 2096 ResolutionResult handleDynamicTypeLiteralUpdate(SendSet node) {
2095 ResolutionDartType type = const ResolutionDynamicType(); 2097 ResolutionDartType type = const ResolutionDynamicType();
2096 ConstantExpression constant = 2098 ConstantExpression constant =
2097 new TypeConstantExpression(const ResolutionDynamicType()); 2099 new TypeConstantExpression(const ResolutionDynamicType());
2098 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant); 2100 AccessSemantics semantics = new ConstantAccess.dynamicTypeLiteral(constant);
2099 return handleConstantTypeLiteralUpdate(node, const PublicName('dynamic'), 2101 ClassElement typeClass = commonElements.typeClass;
2100 commonElements.typeClass, type, semantics); 2102 return handleConstantTypeLiteralUpdate(
2103 node, const PublicName('dynamic'), typeClass, type, semantics);
2101 } 2104 }
2102 2105
2103 /// Handle access to a type literal of a class. Like `C` or 2106 /// Handle access to a type literal of a class. Like `C` or
2104 /// `C()` where 'C' is class. 2107 /// `C()` where 'C' is class.
2105 ResolutionResult handleClassTypeLiteralAccess( 2108 ResolutionResult handleClassTypeLiteralAccess(
2106 Send node, Name name, ClassElement cls) { 2109 Send node, Name name, ClassElement cls) {
2107 cls.ensureResolved(resolution); 2110 cls.ensureResolved(resolution);
2108 ResolutionDartType type = cls.rawType; 2111 ResolutionDartType type = cls.rawType;
2109 ConstantExpression constant = new TypeConstantExpression(type); 2112 ConstantExpression constant = new TypeConstantExpression(type);
2110 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant); 2113 AccessSemantics semantics = new ConstantAccess.classTypeLiteral(constant);
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
3608 } 3611 }
3609 3612
3610 ResolutionResult visitYield(Yield node) { 3613 ResolutionResult visitYield(Yield node) {
3611 if (!resolution.target.supportsAsyncAwait) { 3614 if (!resolution.target.supportsAsyncAwait) {
3612 reporter.reportErrorMessage( 3615 reporter.reportErrorMessage(
3613 node.yieldToken, MessageKind.ASYNC_AWAIT_NOT_SUPPORTED); 3616 node.yieldToken, MessageKind.ASYNC_AWAIT_NOT_SUPPORTED);
3614 } else { 3617 } else {
3615 if (!currentAsyncMarker.isYielding) { 3618 if (!currentAsyncMarker.isYielding) {
3616 reporter.reportErrorMessage(node, MessageKind.INVALID_YIELD); 3619 reporter.reportErrorMessage(node, MessageKind.INVALID_YIELD);
3617 } 3620 }
3621 ClassElement cls;
3618 if (currentAsyncMarker.isAsync) { 3622 if (currentAsyncMarker.isAsync) {
3619 commonElements.streamClass.ensureResolved(resolution); 3623 cls = commonElements.streamClass;
3620 } else { 3624 } else {
3621 commonElements.iterableClass.ensureResolved(resolution); 3625 cls = commonElements.iterableClass;
3622 } 3626 }
3627 cls.ensureResolved(resolution);
3623 } 3628 }
3624 visit(node.expression); 3629 visit(node.expression);
3625 return const NoneResult(); 3630 return const NoneResult();
3626 } 3631 }
3627 3632
3628 ResolutionResult visitRedirectingFactoryBody(RedirectingFactoryBody node) { 3633 ResolutionResult visitRedirectingFactoryBody(RedirectingFactoryBody node) {
3629 if (!enclosingElement.isFactoryConstructor) { 3634 if (!enclosingElement.isFactoryConstructor) {
3630 reporter.reportErrorMessage( 3635 reporter.reportErrorMessage(
3631 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY); 3636 node, MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY);
3632 reporter.reportHintMessage( 3637 reporter.reportHintMessage(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3747 } 3752 }
3748 3753
3749 ResolutionResult visitAwait(Await node) { 3754 ResolutionResult visitAwait(Await node) {
3750 if (!resolution.target.supportsAsyncAwait) { 3755 if (!resolution.target.supportsAsyncAwait) {
3751 reporter.reportErrorMessage( 3756 reporter.reportErrorMessage(
3752 node.awaitToken, MessageKind.ASYNC_AWAIT_NOT_SUPPORTED); 3757 node.awaitToken, MessageKind.ASYNC_AWAIT_NOT_SUPPORTED);
3753 } else { 3758 } else {
3754 if (!currentAsyncMarker.isAsync) { 3759 if (!currentAsyncMarker.isAsync) {
3755 reporter.reportErrorMessage(node, MessageKind.INVALID_AWAIT); 3760 reporter.reportErrorMessage(node, MessageKind.INVALID_AWAIT);
3756 } 3761 }
3757 commonElements.futureClass.ensureResolved(resolution); 3762 ClassElement futureClass = commonElements.futureClass;
3763 futureClass.ensureResolved(resolution);
3758 } 3764 }
3759 visit(node.expression); 3765 visit(node.expression);
3760 return const NoneResult(); 3766 return const NoneResult();
3761 } 3767 }
3762 3768
3763 ResolutionResult visitVariableDefinitions(VariableDefinitions node) { 3769 ResolutionResult visitVariableDefinitions(VariableDefinitions node) {
3764 ResolutionDartType type; 3770 ResolutionDartType type;
3765 if (node.type != null) { 3771 if (node.type != null) {
3766 type = resolveTypeAnnotation(node.type); 3772 type = resolveTypeAnnotation(node.type);
3767 } else { 3773 } else {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 isValidAsConstant = false; 4134 isValidAsConstant = false;
4129 } else { 4135 } else {
4130 typeArgument = resolveTypeAnnotation(nodes.head); 4136 typeArgument = resolveTypeAnnotation(nodes.head);
4131 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { 4137 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) {
4132 reporter.reportWarningMessage( 4138 reporter.reportWarningMessage(
4133 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); 4139 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT);
4134 resolveTypeAnnotation(nodes.head); 4140 resolveTypeAnnotation(nodes.head);
4135 } 4141 }
4136 } 4142 }
4137 } 4143 }
4138 ResolutionDartType listType; 4144 ResolutionInterfaceType listType;
4139 if (typeArgument != null) { 4145 if (typeArgument != null) {
4140 if (node.isConst && typeArgument.containsTypeVariables) { 4146 if (node.isConst && typeArgument.containsTypeVariables) {
4141 reporter.reportErrorMessage( 4147 reporter.reportErrorMessage(
4142 arguments.nodes.head, MessageKind.TYPE_VARIABLE_IN_CONSTANT); 4148 arguments.nodes.head, MessageKind.TYPE_VARIABLE_IN_CONSTANT);
4143 isValidAsConstant = false; 4149 isValidAsConstant = false;
4144 } 4150 }
4145 listType = commonElements.listType(typeArgument); 4151 listType = commonElements.listType(typeArgument);
4146 } else { 4152 } else {
4147 listType = commonElements.listType(); 4153 listType = commonElements.listType();
4148 } 4154 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
4431 } else { 4437 } else {
4432 valueTypeArgument = resolveTypeAnnotation(nodes.head); 4438 valueTypeArgument = resolveTypeAnnotation(nodes.head);
4433 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) { 4439 for (nodes = nodes.tail; !nodes.isEmpty; nodes = nodes.tail) {
4434 reporter.reportWarningMessage( 4440 reporter.reportWarningMessage(
4435 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); 4441 nodes.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT);
4436 resolveTypeAnnotation(nodes.head); 4442 resolveTypeAnnotation(nodes.head);
4437 } 4443 }
4438 } 4444 }
4439 } 4445 }
4440 } 4446 }
4441 ResolutionDartType mapType; 4447 ResolutionInterfaceType mapType;
4442 if (valueTypeArgument != null) { 4448 if (valueTypeArgument != null) {
4443 mapType = commonElements.mapType(keyTypeArgument, valueTypeArgument); 4449 mapType = commonElements.mapType(keyTypeArgument, valueTypeArgument);
4444 } else { 4450 } else {
4445 mapType = commonElements.mapType(); 4451 mapType = commonElements.mapType();
4446 } 4452 }
4447 if (node.isConst && mapType.containsTypeVariables) { 4453 if (node.isConst && mapType.containsTypeVariables) {
4448 reporter.reportErrorMessage( 4454 reporter.reportErrorMessage(
4449 arguments, MessageKind.TYPE_VARIABLE_IN_CONSTANT); 4455 arguments, MessageKind.TYPE_VARIABLE_IN_CONSTANT);
4450 isValidAsConstant = false; 4456 isValidAsConstant = false;
4451 } 4457 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4486 4492
4487 ResolutionResult visitLiteralMapEntry(LiteralMapEntry node) { 4493 ResolutionResult visitLiteralMapEntry(LiteralMapEntry node) {
4488 node.visitChildren(this); 4494 node.visitChildren(this);
4489 return const NoneResult(); 4495 return const NoneResult();
4490 } 4496 }
4491 4497
4492 ResolutionResult visitNamedArgument(NamedArgument node) { 4498 ResolutionResult visitNamedArgument(NamedArgument node) {
4493 return visit(node.expression); 4499 return visit(node.expression);
4494 } 4500 }
4495 4501
4496 ResolutionDartType typeOfConstant(ConstantValue constant) { 4502 ResolutionInterfaceType typeOfConstant(ConstantValue constant) {
4497 if (constant.isInt) return commonElements.intType; 4503 if (constant.isInt) return commonElements.intType;
4498 if (constant.isBool) return commonElements.boolType; 4504 if (constant.isBool) return commonElements.boolType;
4499 if (constant.isDouble) return commonElements.doubleType; 4505 if (constant.isDouble) return commonElements.doubleType;
4500 if (constant.isString) return commonElements.stringType; 4506 if (constant.isString) return commonElements.stringType;
4501 if (constant.isNull) return commonElements.nullType; 4507 if (constant.isNull) return commonElements.nullType;
4502 if (constant.isFunction) return commonElements.functionType; 4508 if (constant.isFunction) return commonElements.functionType;
4503 assert(constant.isObject); 4509 assert(constant.isObject);
4504 ObjectConstantValue objectConstant = constant; 4510 ObjectConstantValue objectConstant = constant;
4505 ResolutionInterfaceType type = objectConstant.type; 4511 ResolutionInterfaceType type = objectConstant.type;
4506 return type; 4512 return type;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
4776 } 4782 }
4777 return const NoneResult(); 4783 return const NoneResult();
4778 } 4784 }
4779 } 4785 }
4780 4786
4781 /// Looks up [name] in [scope] and unwraps the result. 4787 /// Looks up [name] in [scope] and unwraps the result.
4782 Element lookupInScope( 4788 Element lookupInScope(
4783 DiagnosticReporter reporter, Node node, Scope scope, String name) { 4789 DiagnosticReporter reporter, Node node, Scope scope, String name) {
4784 return Elements.unwrap(scope.lookup(name), reporter, node); 4790 return Elements.unwrap(scope.lookup(name), reporter, node);
4785 } 4791 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/enum_creator.dart ('k') | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698