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

Side by Side Diff: pkg/compiler/lib/src/js_backend/patch_resolver.dart

Issue 1383503002: Add Resolution and Parsing interfaces for computeType, ensureResolved and parseNode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add TODOs. 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.js_backend.patch_resolver; 5 library dart2js.js_backend.patch_resolver;
6 6
7 import '../common/resolution.dart' show
8 Resolution;
7 import '../common/tasks.dart' show 9 import '../common/tasks.dart' show
8 CompilerTask; 10 CompilerTask;
9 import '../compiler.dart' show 11 import '../compiler.dart' show
10 Compiler; 12 Compiler;
11 import '../dart_types.dart'; 13 import '../dart_types.dart';
12 import '../diagnostics/diagnostic_listener.dart' show 14 import '../diagnostics/diagnostic_listener.dart' show
13 DiagnosticMessage; 15 DiagnosticMessage;
14 import '../diagnostics/invariant.dart' show 16 import '../diagnostics/invariant.dart' show
15 invariant; 17 invariant;
16 import '../diagnostics/messages.dart' show 18 import '../diagnostics/messages.dart' show
17 MessageKind; 19 MessageKind;
18 import '../elements/elements.dart'; 20 import '../elements/elements.dart';
19 import '../elements/modelx.dart'; 21 import '../elements/modelx.dart';
20 import '../tree/tree.dart'; 22 import '../tree/tree.dart';
21 23
22 class PatchResolverTask extends CompilerTask { 24 class PatchResolverTask extends CompilerTask {
23 PatchResolverTask(Compiler compiler) : super(compiler); 25 PatchResolverTask(Compiler compiler) : super(compiler);
24 26
27 Resolution get resolution => compiler.resolution;
28
25 String get name => 'JavaScript patch resolver'; 29 String get name => 'JavaScript patch resolver';
26 30
27 FunctionElement resolveExternalFunction(FunctionElementX element) { 31 FunctionElement resolveExternalFunction(FunctionElementX element) {
28 if (element.isPatched) { 32 if (element.isPatched) {
29 FunctionElementX patch = element.patch; 33 FunctionElementX patch = element.patch;
30 compiler.withCurrentElement(patch, () { 34 compiler.withCurrentElement(patch, () {
31 patch.parseNode(compiler); 35 patch.computeType(resolution);
32 patch.computeType(compiler);
33 }); 36 });
34 checkMatchingPatchSignatures(element, patch); 37 checkMatchingPatchSignatures(element, patch);
35 element = patch; 38 element = patch;
36 } else { 39 } else {
37 compiler.reportErrorMessage( 40 compiler.reportErrorMessage(
38 element, MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 41 element, MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
39 } 42 }
40 return element; 43 return element;
41 } 44 }
42 45
43 void checkMatchingPatchParameters(FunctionElement origin, 46 void checkMatchingPatchParameters(FunctionElement origin,
44 List<Element> originParameters, 47 List<Element> originParameters,
45 List<Element> patchParameters) { 48 List<Element> patchParameters) {
46 49
47 assert(originParameters.length == patchParameters.length); 50 assert(originParameters.length == patchParameters.length);
48 for (int index = 0; index < originParameters.length; index++) { 51 for (int index = 0; index < originParameters.length; index++) {
49 ParameterElementX originParameter = originParameters[index]; 52 ParameterElementX originParameter = originParameters[index];
50 ParameterElementX patchParameter = patchParameters[index]; 53 ParameterElementX patchParameter = patchParameters[index];
51 // TODO(johnniwinther): Remove the conditional patching when we never 54 // TODO(johnniwinther): Remove the conditional patching when we never
52 // resolve the same method twice. 55 // resolve the same method twice.
53 if (!originParameter.isPatched) { 56 if (!originParameter.isPatched) {
54 originParameter.applyPatch(patchParameter); 57 originParameter.applyPatch(patchParameter);
55 } else { 58 } else {
56 assert(invariant(origin, originParameter.patch == patchParameter, 59 assert(invariant(origin, originParameter.patch == patchParameter,
57 message: "Inconsistent repatch of $originParameter.")); 60 message: "Inconsistent repatch of $originParameter."));
58 } 61 }
59 DartType originParameterType = originParameter.computeType(compiler); 62 DartType originParameterType = originParameter.computeType(resolution);
60 DartType patchParameterType = patchParameter.computeType(compiler); 63 DartType patchParameterType = patchParameter.computeType(resolution);
61 if (originParameterType != patchParameterType) { 64 if (originParameterType != patchParameterType) {
62 compiler.reportError( 65 compiler.reportError(
63 compiler.createMessage( 66 compiler.createMessage(
64 originParameter.parseNode(compiler), 67 originParameter,
65 MessageKind.PATCH_PARAMETER_TYPE_MISMATCH, 68 MessageKind.PATCH_PARAMETER_TYPE_MISMATCH,
66 {'methodName': origin.name, 69 {'methodName': origin.name,
67 'parameterName': originParameter.name, 70 'parameterName': originParameter.name,
68 'originParameterType': originParameterType, 71 'originParameterType': originParameterType,
69 'patchParameterType': patchParameterType}), 72 'patchParameterType': patchParameterType}),
70 <DiagnosticMessage>[ 73 <DiagnosticMessage>[
71 compiler.createMessage( 74 compiler.createMessage(
72 patchParameter, 75 patchParameter,
73 MessageKind.PATCH_POINT_TO_PARAMETER, 76 MessageKind.PATCH_POINT_TO_PARAMETER,
74 {'parameterName': patchParameter.name}), 77 {'parameterName': patchParameter.name}),
75 ]); 78 ]);
76 } else { 79 } else {
77 // Hack: Use unparser to test parameter equality. This only works 80 // Hack: Use unparser to test parameter equality. This only works
78 // because we are restricting patch uses and the approach cannot be used 81 // because we are restricting patch uses and the approach cannot be used
79 // elsewhere. 82 // elsewhere.
80 83
81 // The node contains the type, so there is a potential overlap. 84 // The node contains the type, so there is a potential overlap.
82 // Therefore we only check the text if the types are identical. 85 // Therefore we only check the text if the types are identical.
83 String originParameterText = 86 String originParameterText = originParameter.node.toString();
84 originParameter.parseNode(compiler).toString(); 87 String patchParameterText = patchParameter.node.toString();
85 String patchParameterText =
86 patchParameter.parseNode(compiler).toString();
87 if (originParameterText != patchParameterText 88 if (originParameterText != patchParameterText
88 // We special case the list constructor because of the 89 // We special case the list constructor because of the
89 // optional parameter. 90 // optional parameter.
90 && origin != compiler.unnamedListConstructor) { 91 && origin != compiler.unnamedListConstructor) {
91 compiler.reportError( 92 compiler.reportError(
92 compiler.createMessage( 93 compiler.createMessage(
93 originParameter.parseNode(compiler), 94 originParameter,
94 MessageKind.PATCH_PARAMETER_MISMATCH, 95 MessageKind.PATCH_PARAMETER_MISMATCH,
95 {'methodName': origin.name, 96 {'methodName': origin.name,
96 'originParameter': originParameterText, 97 'originParameter': originParameterText,
97 'patchParameter': patchParameterText}), 98 'patchParameter': patchParameterText}),
98 <DiagnosticMessage>[ 99 <DiagnosticMessage>[
99 compiler.createMessage( 100 compiler.createMessage(
100 patchParameter, 101 patchParameter,
101 MessageKind.PATCH_POINT_TO_PARAMETER, 102 MessageKind.PATCH_POINT_TO_PARAMETER,
102 {'parameterName': patchParameter.name}), 103 {'parameterName': patchParameter.name}),
103 ]); 104 ]);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 'patchParameterCount': patchSignature.optionalParameterCount}); 164 'patchParameterCount': patchSignature.optionalParameterCount});
164 }); 165 });
165 } else { 166 } else {
166 checkMatchingPatchParameters(origin, 167 checkMatchingPatchParameters(origin,
167 originSignature.optionalParameters, 168 originSignature.optionalParameters,
168 patchSignature.optionalParameters); 169 patchSignature.optionalParameters);
169 } 170 }
170 } 171 }
171 172
172 } 173 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart ('k') | pkg/compiler/lib/src/js_backend/runtime_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698