OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/names.dart'; | 8 import '../common/names.dart'; |
9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 }); | 61 }); |
62 } | 62 } |
63 | 63 |
64 class KernelImpactBuilder extends ir.Visitor { | 64 class KernelImpactBuilder extends ir.Visitor { |
65 final ResolvedAst resolvedAst; | 65 final ResolvedAst resolvedAst; |
66 final Compiler compiler; | 66 final Compiler compiler; |
67 | 67 |
68 JavaScriptBackend get backend => compiler.backend; | 68 JavaScriptBackend get backend => compiler.backend; |
69 | 69 |
70 ResolutionWorldImpactBuilder impactBuilder; | 70 ResolutionWorldImpactBuilder impactBuilder; |
71 KernelAstAdapter astAdapter; | 71 KernelWorldBuilder astAdapter; |
72 | 72 |
73 KernelImpactBuilder(this.resolvedAst, this.compiler, Kernel kernel) { | 73 KernelImpactBuilder(this.resolvedAst, this.compiler, Kernel kernel) { |
74 this.impactBuilder = | 74 this.impactBuilder = |
75 new ResolutionWorldImpactBuilder('${resolvedAst.element}'); | 75 new ResolutionWorldImpactBuilder('${resolvedAst.element}'); |
76 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, | 76 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, |
77 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); | 77 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); |
78 } | 78 } |
79 | 79 |
80 /// Add a checked-mode type use of [type] if it is not `dynamic`. | 80 /// Add a checked-mode type use of [type] if it is not `dynamic`. |
81 DartType checkType(ir.DartType irType) { | 81 DartType checkType(ir.DartType irType) { |
(...skipping 24 matching lines...) Expand all Loading... |
106 ResolutionImpact buildField(ir.Field field) { | 106 ResolutionImpact buildField(ir.Field field) { |
107 checkType(field.type); | 107 checkType(field.type); |
108 if (field.initializer != null) { | 108 if (field.initializer != null) { |
109 visitNode(field.initializer); | 109 visitNode(field.initializer); |
110 if (!field.isInstanceMember && | 110 if (!field.isInstanceMember && |
111 !field.isConst && | 111 !field.isConst && |
112 field.initializer is! ir.NullLiteral) { | 112 field.initializer is! ir.NullLiteral) { |
113 impactBuilder.registerFeature(Feature.LAZY_FIELD); | 113 impactBuilder.registerFeature(Feature.LAZY_FIELD); |
114 } | 114 } |
115 } | 115 } |
116 if (field.isInstanceMember && astAdapter.isNative(field.enclosingClass)) { | 116 if (field.isInstanceMember && |
| 117 astAdapter.isNativeClass(field.enclosingClass)) { |
117 impactBuilder | 118 impactBuilder |
118 .registerNativeData(astAdapter.getNativeBehaviorForFieldLoad(field)); | 119 .registerNativeData(astAdapter.getNativeBehaviorForFieldLoad(field)); |
119 impactBuilder | 120 impactBuilder |
120 .registerNativeData(astAdapter.getNativeBehaviorForFieldStore(field)); | 121 .registerNativeData(astAdapter.getNativeBehaviorForFieldStore(field)); |
121 } | 122 } |
122 return impactBuilder; | 123 return impactBuilder; |
123 } | 124 } |
124 | 125 |
125 ResolutionImpact buildConstructor(ir.Constructor constructor) { | 126 ResolutionImpact buildConstructor(ir.Constructor constructor) { |
126 handleSignature(constructor.function, checkReturnType: false); | 127 handleSignature(constructor.function, checkReturnType: false); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 251 |
251 @override | 252 @override |
252 void visitConstructorInvocation(ir.ConstructorInvocation node) { | 253 void visitConstructorInvocation(ir.ConstructorInvocation node) { |
253 handleNew(node, node.target, isConst: node.isConst); | 254 handleNew(node, node.target, isConst: node.isConst); |
254 } | 255 } |
255 | 256 |
256 void handleNew(ir.InvocationExpression node, ir.Member target, | 257 void handleNew(ir.InvocationExpression node, ir.Member target, |
257 {bool isConst: false}) { | 258 {bool isConst: false}) { |
258 _visitArguments(node.arguments); | 259 _visitArguments(node.arguments); |
259 FunctionEntity constructor = astAdapter.getConstructor(target); | 260 FunctionEntity constructor = astAdapter.getConstructor(target); |
260 ClassEntity cls = astAdapter.getClass(target.enclosingClass); | 261 InterfaceType type = astAdapter.createInterfaceType( |
261 List<DartType> typeArguments = | 262 target.enclosingClass, node.arguments.types); |
262 astAdapter.getDartTypes(node.arguments.types); | |
263 InterfaceType type = astAdapter.createInterfaceType(cls, typeArguments); | |
264 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); | 263 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); |
265 impactBuilder.registerStaticUse(isConst | 264 impactBuilder.registerStaticUse(isConst |
266 ? new StaticUse.constConstructorInvoke(constructor, callStructure, type) | 265 ? new StaticUse.constConstructorInvoke(constructor, callStructure, type) |
267 : new StaticUse.typedConstructorInvoke( | 266 : new StaticUse.typedConstructorInvoke( |
268 constructor, callStructure, type)); | 267 constructor, callStructure, type)); |
269 if (typeArguments.any((DartType type) => !type.isDynamic)) { | 268 if (type.typeArguments.any((DartType type) => !type.isDynamic)) { |
270 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 269 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
271 } | 270 } |
272 } | 271 } |
273 | 272 |
274 @override | 273 @override |
275 void visitSuperInitializer(ir.SuperInitializer node) { | 274 void visitSuperInitializer(ir.SuperInitializer node) { |
276 FunctionEntity target = astAdapter.getConstructor(node.target); | 275 FunctionEntity target = astAdapter.getConstructor(node.target); |
277 _visitArguments(node.arguments); | 276 _visitArguments(node.arguments); |
278 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 277 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
279 target, astAdapter.getCallStructure(node.arguments))); | 278 target, astAdapter.getCallStructure(node.arguments))); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 break; | 317 break; |
319 case ForeignKind.JS_BUILTIN: | 318 case ForeignKind.JS_BUILTIN: |
320 impactBuilder.registerNativeData( | 319 impactBuilder.registerNativeData( |
321 astAdapter.getNativeBehaviorForJsBuiltinCall(node)); | 320 astAdapter.getNativeBehaviorForJsBuiltinCall(node)); |
322 break; | 321 break; |
323 case ForeignKind.JS_EMBEDDED_GLOBAL: | 322 case ForeignKind.JS_EMBEDDED_GLOBAL: |
324 impactBuilder.registerNativeData( | 323 impactBuilder.registerNativeData( |
325 astAdapter.getNativeBehaviorForJsEmbeddedGlobalCall(node)); | 324 astAdapter.getNativeBehaviorForJsEmbeddedGlobalCall(node)); |
326 break; | 325 break; |
327 case ForeignKind.JS_INTERCEPTOR_CONSTANT: | 326 case ForeignKind.JS_INTERCEPTOR_CONSTANT: |
328 if (node.arguments.positional.length != 1 || | 327 InterfaceType type = |
329 node.arguments.named.isNotEmpty) { | 328 astAdapter.getInterfaceTypeForJsInterceptorCall(node); |
330 astAdapter.reporter.reportErrorMessage(CURRENT_ELEMENT_SPANNABLE, | 329 if (type != null) { |
331 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); | |
332 } | |
333 ir.Node argument = node.arguments.positional.first; | |
334 if (argument is ir.TypeLiteral && argument.type is ir.InterfaceType) { | |
335 InterfaceType type = astAdapter.getInterfaceType(argument.type); | |
336 impactBuilder.registerTypeUse(new TypeUse.instantiation(type)); | 330 impactBuilder.registerTypeUse(new TypeUse.instantiation(type)); |
337 } | 331 } |
338 break; | 332 break; |
339 case ForeignKind.NONE: | 333 case ForeignKind.NONE: |
340 break; | 334 break; |
341 } | 335 } |
342 } | 336 } |
343 | 337 |
344 @override | 338 @override |
345 void visitStaticGet(ir.StaticGet node) { | 339 void visitStaticGet(ir.StaticGet node) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 454 |
461 @override | 455 @override |
462 void visitStringConcatenation(ir.StringConcatenation node) { | 456 void visitStringConcatenation(ir.StringConcatenation node) { |
463 impactBuilder.registerFeature(Feature.STRING_INTERPOLATION); | 457 impactBuilder.registerFeature(Feature.STRING_INTERPOLATION); |
464 impactBuilder.registerFeature(Feature.STRING_JUXTAPOSITION); | 458 impactBuilder.registerFeature(Feature.STRING_JUXTAPOSITION); |
465 visitNodes(node.expressions); | 459 visitNodes(node.expressions); |
466 } | 460 } |
467 | 461 |
468 @override | 462 @override |
469 void visitFunctionDeclaration(ir.FunctionDeclaration node) { | 463 void visitFunctionDeclaration(ir.FunctionDeclaration node) { |
470 impactBuilder | 464 impactBuilder.registerStaticUse( |
471 .registerStaticUse(new StaticUse.closure(astAdapter.getElement(node))); | 465 new StaticUse.closure(astAdapter.getLocalFunction(node))); |
472 handleSignature(node.function); | 466 handleSignature(node.function); |
473 visitNode(node.function.body); | 467 visitNode(node.function.body); |
474 } | 468 } |
475 | 469 |
476 @override | 470 @override |
477 void visitFunctionExpression(ir.FunctionExpression node) { | 471 void visitFunctionExpression(ir.FunctionExpression node) { |
478 impactBuilder | 472 impactBuilder.registerStaticUse( |
479 .registerStaticUse(new StaticUse.closure(astAdapter.getElement(node))); | 473 new StaticUse.closure(astAdapter.getLocalFunction(node))); |
480 handleSignature(node.function); | 474 handleSignature(node.function); |
481 visitNode(node.function.body); | 475 visitNode(node.function.body); |
482 } | 476 } |
483 | 477 |
484 @override | 478 @override |
485 void visitVariableDeclaration(ir.VariableDeclaration node) { | 479 void visitVariableDeclaration(ir.VariableDeclaration node) { |
486 checkType(node.type); | 480 checkType(node.type); |
487 if (node.initializer != null) { | 481 if (node.initializer != null) { |
488 visitNode(node.initializer); | 482 visitNode(node.initializer); |
489 } else { | 483 } else { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 FunctionEntity target = astAdapter.getConstructor(node.target); | 565 FunctionEntity target = astAdapter.getConstructor(node.target); |
572 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 566 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
573 target, astAdapter.getCallStructure(node.arguments))); | 567 target, astAdapter.getCallStructure(node.arguments))); |
574 } | 568 } |
575 | 569 |
576 // TODO(johnniwinther): Make this throw and visit child nodes explicitly | 570 // TODO(johnniwinther): Make this throw and visit child nodes explicitly |
577 // instead to ensure that we don't visit unwanted parts of the ir. | 571 // instead to ensure that we don't visit unwanted parts of the ir. |
578 @override | 572 @override |
579 void defaultNode(ir.Node node) => node.visitChildren(this); | 573 void defaultNode(ir.Node node) => node.visitChildren(this); |
580 } | 574 } |
OLD | NEW |