| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 KernelAstAdapter astAdapter; | 71 KernelAstAdapter 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 ResolutionDartType checkType(ir.DartType irType) { |
| 82 DartType type = astAdapter.getDartType(irType); | 82 ResolutionDartType type = astAdapter.getDartType(irType); |
| 83 if (!type.isDynamic) { | 83 if (!type.isDynamic) { |
| 84 impactBuilder.registerTypeUse(new TypeUse.checkedModeCheck(type)); | 84 impactBuilder.registerTypeUse(new TypeUse.checkedModeCheck(type)); |
| 85 } | 85 } |
| 86 return type; | 86 return type; |
| 87 } | 87 } |
| 88 | 88 |
| 89 /// Add checked-mode type use for the parameter type and constant for the | 89 /// Add checked-mode type use for the parameter type and constant for the |
| 90 /// default value of [parameter]. | 90 /// default value of [parameter]. |
| 91 void handleParameter(ir.VariableDeclaration parameter) { | 91 void handleParameter(ir.VariableDeclaration parameter) { |
| 92 checkType(parameter.type); | 92 checkType(parameter.type); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 @override | 214 @override |
| 215 void visitNullLiteral(ir.NullLiteral literal) { | 215 void visitNullLiteral(ir.NullLiteral literal) { |
| 216 impactBuilder.registerConstantLiteral(new NullConstantExpression()); | 216 impactBuilder.registerConstantLiteral(new NullConstantExpression()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 @override | 219 @override |
| 220 void visitListLiteral(ir.ListLiteral literal) { | 220 void visitListLiteral(ir.ListLiteral literal) { |
| 221 visitNodes(literal.expressions); | 221 visitNodes(literal.expressions); |
| 222 DartType elementType = checkType(literal.typeArgument); | 222 ResolutionDartType elementType = checkType(literal.typeArgument); |
| 223 | 223 |
| 224 impactBuilder.registerListLiteral(new ListLiteralUse( | 224 impactBuilder.registerListLiteral(new ListLiteralUse( |
| 225 compiler.commonElements.listType(elementType), | 225 compiler.commonElements.listType(elementType), |
| 226 isConstant: literal.isConst, | 226 isConstant: literal.isConst, |
| 227 isEmpty: literal.expressions.isEmpty)); | 227 isEmpty: literal.expressions.isEmpty)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 @override | 230 @override |
| 231 void visitMapLiteral(ir.MapLiteral literal) { | 231 void visitMapLiteral(ir.MapLiteral literal) { |
| 232 visitNodes(literal.entries); | 232 visitNodes(literal.entries); |
| 233 DartType keyType = checkType(literal.keyType); | 233 ResolutionDartType keyType = checkType(literal.keyType); |
| 234 DartType valueType = checkType(literal.valueType); | 234 ResolutionDartType valueType = checkType(literal.valueType); |
| 235 impactBuilder.registerMapLiteral(new MapLiteralUse( | 235 impactBuilder.registerMapLiteral(new MapLiteralUse( |
| 236 compiler.commonElements.mapType(keyType, valueType), | 236 compiler.commonElements.mapType(keyType, valueType), |
| 237 isConstant: literal.isConst, | 237 isConstant: literal.isConst, |
| 238 isEmpty: literal.entries.isEmpty)); | 238 isEmpty: literal.entries.isEmpty)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void visitMapEntry(ir.MapEntry entry) { | 241 void visitMapEntry(ir.MapEntry entry) { |
| 242 visitNode(entry.key); | 242 visitNode(entry.key); |
| 243 visitNode(entry.value); | 243 visitNode(entry.value); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void _visitArguments(ir.Arguments arguments) { | 246 void _visitArguments(ir.Arguments arguments) { |
| 247 arguments.positional.forEach(visitNode); | 247 arguments.positional.forEach(visitNode); |
| 248 arguments.named.forEach(visitNode); | 248 arguments.named.forEach(visitNode); |
| 249 } | 249 } |
| 250 | 250 |
| 251 @override | 251 @override |
| 252 void visitConstructorInvocation(ir.ConstructorInvocation node) { | 252 void visitConstructorInvocation(ir.ConstructorInvocation node) { |
| 253 handleNew(node, node.target, isConst: node.isConst); | 253 handleNew(node, node.target, isConst: node.isConst); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void handleNew(ir.InvocationExpression node, ir.Member target, | 256 void handleNew(ir.InvocationExpression node, ir.Member target, |
| 257 {bool isConst: false}) { | 257 {bool isConst: false}) { |
| 258 _visitArguments(node.arguments); | 258 _visitArguments(node.arguments); |
| 259 Element element = astAdapter.getElement(target).declaration; | 259 Element element = astAdapter.getElement(target).declaration; |
| 260 ClassElement cls = astAdapter.getElement(target.enclosingClass); | 260 ClassElement cls = astAdapter.getElement(target.enclosingClass); |
| 261 List<DartType> typeArguments = | 261 List<ResolutionDartType> typeArguments = |
| 262 astAdapter.getDartTypes(node.arguments.types); | 262 astAdapter.getDartTypes(node.arguments.types); |
| 263 InterfaceType type = new InterfaceType(cls, typeArguments); | 263 ResolutionInterfaceType type = |
| 264 new ResolutionInterfaceType(cls, typeArguments); |
| 264 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); | 265 CallStructure callStructure = astAdapter.getCallStructure(node.arguments); |
| 265 impactBuilder.registerStaticUse(isConst | 266 impactBuilder.registerStaticUse(isConst |
| 266 ? new StaticUse.constConstructorInvoke(element, callStructure, type) | 267 ? new StaticUse.constConstructorInvoke(element, callStructure, type) |
| 267 : new StaticUse.typedConstructorInvoke(element, callStructure, type)); | 268 : new StaticUse.typedConstructorInvoke(element, callStructure, type)); |
| 268 if (typeArguments.any((DartType type) => !type.isDynamic)) { | 269 if (typeArguments.any((ResolutionDartType type) => !type.isDynamic)) { |
| 269 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 270 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 | 273 |
| 273 @override | 274 @override |
| 274 void visitSuperInitializer(ir.SuperInitializer node) { | 275 void visitSuperInitializer(ir.SuperInitializer node) { |
| 275 Element target = astAdapter.getElement(node.target).declaration; | 276 Element target = astAdapter.getElement(node.target).declaration; |
| 276 _visitArguments(node.arguments); | 277 _visitArguments(node.arguments); |
| 277 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 278 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
| 278 target, astAdapter.getCallStructure(node.arguments))); | 279 target, astAdapter.getCallStructure(node.arguments))); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 Element target = astAdapter.getElement(node.target).declaration; | 568 Element target = astAdapter.getElement(node.target).declaration; |
| 568 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( | 569 impactBuilder.registerStaticUse(new StaticUse.superConstructorInvoke( |
| 569 target, astAdapter.getCallStructure(node.arguments))); | 570 target, astAdapter.getCallStructure(node.arguments))); |
| 570 } | 571 } |
| 571 | 572 |
| 572 // TODO(johnniwinther): Make this throw and visit child nodes explicitly | 573 // TODO(johnniwinther): Make this throw and visit child nodes explicitly |
| 573 // instead to ensure that we don't visit unwanted parts of the ir. | 574 // instead to ensure that we don't visit unwanted parts of the ir. |
| 574 @override | 575 @override |
| 575 void defaultNode(ir.Node node) => node.visitChildren(this); | 576 void defaultNode(ir.Node node) => node.visitChildren(this); |
| 576 } | 577 } |
| OLD | NEW |