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

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

Issue 2265473004: Introduce "CommonElements" (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: cl Created 4 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
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 2605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2616 } else { 2616 } else {
2617 member = abstractField.setter; 2617 member = abstractField.setter;
2618 } 2618 }
2619 } else { 2619 } else {
2620 member = element; 2620 member = element;
2621 } 2621 }
2622 // TODO(johnniwinther): Needed to provoke a parsing and with it discovery 2622 // TODO(johnniwinther): Needed to provoke a parsing and with it discovery
2623 // of parse errors to make [element] erroneous. Fix this! 2623 // of parse errors to make [element] erroneous. Fix this!
2624 member.computeType(resolution); 2624 member.computeType(resolution);
2625 2625
2626 if (member == resolution.mirrorSystemGetNameFunction && 2626 if (resolution.commonElements.isMirrorSystemGetNameFunction(member) &&
2627 !resolution.mirrorUsageAnalyzerTask.hasMirrorUsage(enclosingElement)) { 2627 !resolution.mirrorUsageAnalyzerTask.hasMirrorUsage(enclosingElement)) {
2628 reporter 2628 reporter.reportHintMessage(
2629 .reportHintMessage(node.selector, MessageKind.STATIC_FUNCTION_BLOAT, { 2629 node.selector, MessageKind.STATIC_FUNCTION_BLOAT, {
2630 'class': resolution.mirrorSystemClass.name, 2630 'class': resolution.commonElements.mirrorSystemClass.name,
2631 'name': resolution.mirrorSystemGetNameFunction.name 2631 'name': member.name
2632 }); 2632 });
2633 } 2633 }
2634 2634
2635 Selector selector; 2635 Selector selector;
2636 AccessSemantics semantics = 2636 AccessSemantics semantics =
2637 computeStaticOrTopLevelAccessSemantics(node, member); 2637 computeStaticOrTopLevelAccessSemantics(node, member);
2638 if (node.isCall) { 2638 if (node.isCall) {
2639 ArgumentsResult argumentsResult = resolveArguments(node.argumentsNode); 2639 ArgumentsResult argumentsResult = resolveArguments(node.argumentsNode);
2640 CallStructure callStructure = argumentsResult.callStructure; 2640 CallStructure callStructure = argumentsResult.callStructure;
2641 selector = new Selector.call(name, callStructure); 2641 selector = new Selector.call(name, callStructure);
2642 2642
2643 bool isIncompatibleInvoke = false; 2643 bool isIncompatibleInvoke = false;
2644 switch (semantics.kind) { 2644 switch (semantics.kind) {
2645 case AccessKind.STATIC_METHOD: 2645 case AccessKind.STATIC_METHOD:
2646 case AccessKind.TOPLEVEL_METHOD: 2646 case AccessKind.TOPLEVEL_METHOD:
2647 MethodElement method = semantics.element; 2647 MethodElement method = semantics.element;
2648 method.computeType(resolution); 2648 method.computeType(resolution);
2649 if (!callStructure.signatureApplies(method.functionSignature)) { 2649 if (!callStructure.signatureApplies(method.functionSignature)) {
2650 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); 2650 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2651 registry.registerDynamicUse(new DynamicUse(selector, null)); 2651 registry.registerDynamicUse(new DynamicUse(selector, null));
2652 isIncompatibleInvoke = true; 2652 isIncompatibleInvoke = true;
2653 } else { 2653 } else {
2654 registry.registerStaticUse( 2654 registry.registerStaticUse(
2655 new StaticUse.staticInvoke(semantics.element, callStructure)); 2655 new StaticUse.staticInvoke(semantics.element, callStructure));
2656 handleForeignCall(node, semantics.element, callStructure); 2656 handleForeignCall(node, semantics.element, callStructure);
2657 if (method == resolution.identicalFunction && 2657 if (method == resolution.commonElements.identicalFunction &&
2658 argumentsResult.isValidAsConstant) { 2658 argumentsResult.isValidAsConstant) {
2659 result = new ConstantResult( 2659 result = new ConstantResult(
2660 node, 2660 node,
2661 new IdenticalConstantExpression( 2661 new IdenticalConstantExpression(
2662 argumentsResult.argumentResults[0].constant, 2662 argumentsResult.argumentResults[0].constant,
2663 argumentsResult.argumentResults[1].constant)); 2663 argumentsResult.argumentResults[1].constant));
2664 } 2664 }
2665 } 2665 }
2666 break; 2666 break;
2667 case AccessKind.STATIC_FIELD: 2667 case AccessKind.STATIC_FIELD:
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 isValidAsConstant = false; 3670 isValidAsConstant = false;
3671 } 3671 }
3672 3672
3673 registry.registerStaticUse( 3673 registry.registerStaticUse(
3674 new StaticUse.constructorRedirect(redirectionTarget)); 3674 new StaticUse.constructorRedirect(redirectionTarget));
3675 // TODO(johnniwinther): Register the effective target type as part of the 3675 // TODO(johnniwinther): Register the effective target type as part of the
3676 // static use instead. 3676 // static use instead.
3677 registry.registerTypeUse(new TypeUse.instantiation(redirectionTarget 3677 registry.registerTypeUse(new TypeUse.instantiation(redirectionTarget
3678 .enclosingClass.thisType 3678 .enclosingClass.thisType
3679 .subst(type.typeArguments, targetClass.typeVariables))); 3679 .subst(type.typeArguments, targetClass.typeVariables)));
3680 if (enclosingElement == resolution.symbolConstructor) { 3680 if (resolution.commonElements.isSymbolConstructor(enclosingElement)) {
3681 registry.registerFeature(Feature.SYMBOL_CONSTRUCTOR); 3681 registry.registerFeature(Feature.SYMBOL_CONSTRUCTOR);
3682 } 3682 }
3683 if (isValidAsConstant) { 3683 if (isValidAsConstant) {
3684 List<String> names = <String>[]; 3684 List<String> names = <String>[];
3685 List<ConstantExpression> arguments = <ConstantExpression>[]; 3685 List<ConstantExpression> arguments = <ConstantExpression>[];
3686 int index = 0; 3686 int index = 0;
3687 constructorSignature.forEachParameter((ParameterElement parameter) { 3687 constructorSignature.forEachParameter((ParameterElement parameter) {
3688 if (parameter.isNamed) { 3688 if (parameter.isNamed) {
3689 String name = parameter.name; 3689 String name = parameter.name;
3690 names.add(name); 3690 names.add(name);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
3880 constructor.declaration, callStructure)); 3880 constructor.declaration, callStructure));
3881 // TODO(johniwinther): Avoid registration of `type` in face of redirecting 3881 // TODO(johniwinther): Avoid registration of `type` in face of redirecting
3882 // factory constructors. 3882 // factory constructors.
3883 registry.registerTypeUse(new TypeUse.instantiation(type)); 3883 registry.registerTypeUse(new TypeUse.instantiation(type));
3884 } 3884 }
3885 3885
3886 ResolutionResult resolutionResult = const NoneResult(); 3886 ResolutionResult resolutionResult = const NoneResult();
3887 if (node.isConst) { 3887 if (node.isConst) {
3888 bool isValidAsConstant = !isInvalid && constructor.isConst; 3888 bool isValidAsConstant = !isInvalid && constructor.isConst;
3889 3889
3890 if (constructor == resolution.symbolConstructor) { 3890 CommonElements commonElements = resolution.commonElements;
3891 if (commonElements.isSymbolConstructor(constructor)) {
3891 Node argumentNode = node.send.arguments.head; 3892 Node argumentNode = node.send.arguments.head;
3892 ConstantExpression constant = resolver.constantCompiler 3893 ConstantExpression constant = resolver.constantCompiler
3893 .compileNode(argumentNode, registry.mapping); 3894 .compileNode(argumentNode, registry.mapping);
3894 ConstantValue name = resolution.constants.getConstantValue(constant); 3895 ConstantValue name = resolution.constants.getConstantValue(constant);
3895 if (!name.isString) { 3896 if (!name.isString) {
3896 DartType type = name.getType(coreTypes); 3897 DartType type = name.getType(coreTypes);
3897 reporter.reportErrorMessage( 3898 reporter.reportErrorMessage(
3898 argumentNode, MessageKind.STRING_EXPECTED, {'type': type}); 3899 argumentNode, MessageKind.STRING_EXPECTED, {'type': type});
3899 } else { 3900 } else {
3900 StringConstantValue stringConstant = name; 3901 StringConstantValue stringConstant = name;
3901 String nameString = stringConstant.toDartString().slowToString(); 3902 String nameString = stringConstant.toDartString().slowToString();
3902 if (validateSymbol(argumentNode, nameString)) { 3903 if (validateSymbol(argumentNode, nameString)) {
3903 registry.registerConstSymbol(nameString); 3904 registry.registerConstSymbol(nameString);
3904 } 3905 }
3905 } 3906 }
3906 } else if (constructor == resolution.mirrorsUsedConstructor) { 3907 } else if (commonElements.isMirrorsUsedConstructor(constructor)) {
3907 resolution.mirrorUsageAnalyzerTask.validate(node, registry.mapping); 3908 resolution.mirrorUsageAnalyzerTask.validate(node, registry.mapping);
3908 } 3909 }
3909 3910
3910 analyzeConstantDeferred(node); 3911 analyzeConstantDeferred(node);
3911 3912
3912 if (type.containsTypeVariables) { 3913 if (type.containsTypeVariables) {
3913 reporter.reportErrorMessage( 3914 reporter.reportErrorMessage(
3914 node.send.selector, MessageKind.TYPE_VARIABLE_IN_CONSTANT); 3915 node.send.selector, MessageKind.TYPE_VARIABLE_IN_CONSTANT);
3915 isValidAsConstant = false; 3916 isValidAsConstant = false;
3916 isInvalid = true; 3917 isInvalid = true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 // [LateConstInvokeStructure]; it might not be necessary. 3957 // [LateConstInvokeStructure]; it might not be necessary.
3957 registry.registerNewStructure(node, structure); 3958 registry.registerNewStructure(node, structure);
3958 onAnalyzed = () { 3959 onAnalyzed = () {
3959 registry.registerNewStructure(node, structure.resolve(node)); 3960 registry.registerNewStructure(node, structure.resolve(node));
3960 }; 3961 };
3961 } 3962 }
3962 3963
3963 analyzeConstantDeferred(node, onAnalyzed: onAnalyzed); 3964 analyzeConstantDeferred(node, onAnalyzed: onAnalyzed);
3964 } else { 3965 } else {
3965 // Not constant. 3966 // Not constant.
3966 if (constructor == resolution.symbolConstructor && 3967 if (resolution.commonElements.isSymbolConstructor(constructor) &&
3967 !resolution.mirrorUsageAnalyzerTask 3968 !resolution.mirrorUsageAnalyzerTask
3968 .hasMirrorUsage(enclosingElement)) { 3969 .hasMirrorUsage(enclosingElement)) {
3969 reporter.reportHintMessage(node.newToken, MessageKind.NON_CONST_BLOAT, 3970 reporter.reportHintMessage(node.newToken, MessageKind.NON_CONST_BLOAT,
3970 {'name': coreClasses.symbolClass.name}); 3971 {'name': coreClasses.symbolClass.name});
3971 } 3972 }
3972 registry.registerNewStructure( 3973 registry.registerNewStructure(
3973 node, 3974 node,
3974 new NewInvokeStructure( 3975 new NewInvokeStructure(
3975 new ConstructorAccessSemantics(kind, constructor, type), 3976 new ConstructorAccessSemantics(kind, constructor, type),
3976 selector)); 3977 selector));
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
4719 } 4720 }
4720 return const NoneResult(); 4721 return const NoneResult();
4721 } 4722 }
4722 } 4723 }
4723 4724
4724 /// Looks up [name] in [scope] and unwraps the result. 4725 /// Looks up [name] in [scope] and unwraps the result.
4725 Element lookupInScope( 4726 Element lookupInScope(
4726 DiagnosticReporter reporter, Node node, Scope scope, String name) { 4727 DiagnosticReporter reporter, Node node, Scope scope, String name) {
4727 return Elements.unwrap(scope.lookup(name), reporter, node); 4728 return Elements.unwrap(scope.lookup(name), reporter, node);
4728 } 4729 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/class_members.dart ('k') | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698