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

Side by Side Diff: tests/compiler/dart2js/related_types.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes after rebase. Created 5 years, 2 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 related_types; 5 library related_types;
6 6
7 import 'package:compiler/src/commandline_options.dart'; 7 import 'package:compiler/src/commandline_options.dart';
8 import 'package:compiler/src/compiler.dart'; 8 import 'package:compiler/src/compiler.dart';
9 import 'package:compiler/src/core_types.dart'; 9 import 'package:compiler/src/core_types.dart';
10 import 'package:compiler/src/dart_types.dart'; 10 import 'package:compiler/src/dart_types.dart';
11 import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
11 import 'package:compiler/src/diagnostics/messages.dart'; 12 import 'package:compiler/src/diagnostics/messages.dart';
12 import 'package:compiler/src/elements/elements.dart'; 13 import 'package:compiler/src/elements/elements.dart';
13 import 'package:compiler/src/filenames.dart'; 14 import 'package:compiler/src/filenames.dart';
14 import 'package:compiler/src/resolution/semantic_visitor.dart'; 15 import 'package:compiler/src/resolution/semantic_visitor.dart';
15 import 'package:compiler/src/tree/tree.dart'; 16 import 'package:compiler/src/tree/tree.dart';
16 import 'package:compiler/src/universe/call_structure.dart'; 17 import 'package:compiler/src/universe/call_structure.dart';
17 import 'package:compiler/src/universe/selector.dart'; 18 import 'package:compiler/src/universe/selector.dart';
18 import 'package:compiler/src/world.dart'; 19 import 'package:compiler/src/world.dart';
19 import 'memory_compiler.dart'; 20 import 'memory_compiler.dart';
20 21
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 55 }
55 56
56 /// Check [member] for unrelated types. 57 /// Check [member] for unrelated types.
57 void checkMemberElement(Compiler compiler, MemberElement member) { 58 void checkMemberElement(Compiler compiler, MemberElement member) {
58 if (!compiler.enqueuer.resolution.hasBeenResolved(member)) return; 59 if (!compiler.enqueuer.resolution.hasBeenResolved(member)) return;
59 60
60 ResolvedAst resolvedAst = member.resolvedAst; 61 ResolvedAst resolvedAst = member.resolvedAst;
61 RelatedTypesChecker relatedTypesChecker = 62 RelatedTypesChecker relatedTypesChecker =
62 new RelatedTypesChecker(compiler, resolvedAst); 63 new RelatedTypesChecker(compiler, resolvedAst);
63 if (resolvedAst.node != null) { 64 if (resolvedAst.node != null) {
64 compiler.withCurrentElement(member.implementation, () { 65 compiler.reporter.withCurrentElement(member.implementation, () {
65 relatedTypesChecker.apply(resolvedAst.node); 66 relatedTypesChecker.apply(resolvedAst.node);
66 }); 67 });
67 } 68 }
68 } 69 }
69 70
70 class RelatedTypesChecker extends TraversalVisitor<DartType, dynamic> { 71 class RelatedTypesChecker extends TraversalVisitor<DartType, dynamic> {
71 final Compiler compiler; 72 final Compiler compiler;
72 final ResolvedAst resolvedAst; 73 final ResolvedAst resolvedAst;
73 74
74 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst) 75 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst)
75 : this.resolvedAst = resolvedAst, 76 : this.resolvedAst = resolvedAst,
76 super(resolvedAst.elements); 77 super(resolvedAst.elements);
77 78
78 ClassWorld get world => compiler.world; 79 ClassWorld get world => compiler.world;
79 80
80 CoreTypes get coreTypes => compiler.coreTypes; 81 CoreTypes get coreTypes => compiler.coreTypes;
81 82
83 DiagnosticReporter get reporter => compiler.reporter;
84
82 InterfaceType get thisType => resolvedAst.element.enclosingClass.thisType; 85 InterfaceType get thisType => resolvedAst.element.enclosingClass.thisType;
83 86
84 /// Returns `true` if there exists no common subtype of [left] and [right]. 87 /// Returns `true` if there exists no common subtype of [left] and [right].
85 bool hasEmptyIntersection(DartType left, DartType right) { 88 bool hasEmptyIntersection(DartType left, DartType right) {
86 if (left == right) return false; 89 if (left == right) return false;
87 if (left == null || right == null) return false; 90 if (left == null || right == null) return false;
88 ClassElement leftClass = const ClassFinder().findClass(left); 91 ClassElement leftClass = const ClassFinder().findClass(left);
89 ClassElement rightClass = const ClassFinder().findClass(right); 92 ClassElement rightClass = const ClassFinder().findClass(right);
90 if (leftClass != null && rightClass != null) { 93 if (leftClass != null && rightClass != null) {
91 return !world.haveAnyCommonSubtypes(leftClass, rightClass); 94 return !world.haveAnyCommonSubtypes(leftClass, rightClass);
92 } 95 }
93 return false; 96 return false;
94 } 97 }
95 98
96 /// Checks that there exists a common subtype of [left] and [right] or report 99 /// Checks that there exists a common subtype of [left] and [right] or report
97 /// a hint otherwise. 100 /// a hint otherwise.
98 void checkRelated(Node node, DartType left, DartType right) { 101 void checkRelated(Node node, DartType left, DartType right) {
99 if (hasEmptyIntersection(left, right)) { 102 if (hasEmptyIntersection(left, right)) {
100 compiler.reportHint(compiler.createMessage( 103 reporter.reportHintMessage(
101 node, 104 node,
102 MessageKind.NO_COMMON_SUBTYPES, 105 MessageKind.NO_COMMON_SUBTYPES,
103 {'left': left, 'right': right})); 106 {'left': left, 'right': right});
104 } 107 }
105 } 108 }
106 109
107 /// Check weakly typed collection methods, like `Map.containsKey`, 110 /// Check weakly typed collection methods, like `Map.containsKey`,
108 /// `Map.containsValue` and `Iterable.contains`. 111 /// `Map.containsValue` and `Iterable.contains`.
109 void checkDynamicInvoke( 112 void checkDynamicInvoke(
110 Node node, 113 Node node,
111 DartType receiverType, 114 DartType receiverType,
112 List<DartType> argumentTypes, 115 List<DartType> argumentTypes,
113 Selector selector) { 116 Selector selector) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 ClassElement findClass(DartType type) => type.accept(this, null); 427 ClassElement findClass(DartType type) => type.accept(this, null);
425 428
426 @override 429 @override
427 ClassElement visitType(DartType type, _) => null; 430 ClassElement visitType(DartType type, _) => null;
428 431
429 @override 432 @override
430 ClassElement visitInterfaceType(InterfaceType type, _) { 433 ClassElement visitInterfaceType(InterfaceType type, _) {
431 return type.element; 434 return type.element;
432 } 435 }
433 } 436 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/parser_test.dart ('k') | tests/compiler/dart2js/semantic_visitor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698