OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
7 | 7 |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 299 |
300 /// Converts [annotations] into a list of [ConstantValue]s. | 300 /// Converts [annotations] into a list of [ConstantValue]s. |
301 List<ConstantValue> getMetadata(List<ir.Expression> annotations) { | 301 List<ConstantValue> getMetadata(List<ir.Expression> annotations) { |
302 if (annotations.isEmpty) return const <ConstantValue>[]; | 302 if (annotations.isEmpty) return const <ConstantValue>[]; |
303 List<ConstantValue> metadata = <ConstantValue>[]; | 303 List<ConstantValue> metadata = <ConstantValue>[]; |
304 annotations.forEach((ir.Expression node) { | 304 annotations.forEach((ir.Expression node) { |
305 metadata.add(getConstantValue(node)); | 305 metadata.add(getConstantValue(node)); |
306 }); | 306 }); |
307 return metadata; | 307 return metadata; |
308 } | 308 } |
| 309 |
| 310 FunctionEntity getSuperNoSuchMethod(ClassEntity cls) { |
| 311 while (cls != null) { |
| 312 cls = elementEnvironment.getSuperClass(cls); |
| 313 MemberEntity member = |
| 314 elementEnvironment.lookupClassMember(cls, Identifiers.noSuchMethod_); |
| 315 if (member != null) { |
| 316 if (member.isFunction) { |
| 317 FunctionEntity function = member; |
| 318 if (function.parameterStructure.positionalParameters >= 1) { |
| 319 return function; |
| 320 } |
| 321 } |
| 322 // If [member] is not a valid `noSuchMethod` the target is |
| 323 // `Object.superNoSuchMethod`. |
| 324 break; |
| 325 } |
| 326 } |
| 327 FunctionEntity function = elementEnvironment.lookupClassMember( |
| 328 commonElements.objectClass, Identifiers.noSuchMethod_); |
| 329 assert(function != null, |
| 330 failedAt(cls, "No super noSuchMethod found for class $cls.")); |
| 331 return function; |
| 332 } |
309 } | 333 } |
310 | 334 |
311 abstract class KernelToElementMapForImpactMixin | 335 abstract class KernelToElementMapForImpactMixin |
312 implements KernelToElementMapForImpact, KernelToElementMapBaseMixin { | 336 implements KernelToElementMapForImpact, KernelToElementMapBaseMixin { |
313 DiagnosticReporter get reporter; | 337 DiagnosticReporter get reporter; |
314 native.BehaviorBuilder get nativeBehaviorBuilder; | 338 native.BehaviorBuilder get nativeBehaviorBuilder; |
315 | 339 |
316 /// Returns `true` is [node] has a `@Native(...)` annotation. | 340 /// Returns `true` is [node] has a `@Native(...)` annotation. |
317 // TODO(johnniwinther): Cache this for later use. | 341 // TODO(johnniwinther): Cache this for later use. |
318 bool isNativeClass(ir.Class node) { | 342 bool isNativeClass(ir.Class node) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 DartType type = getFunctionType(procedure.function); | 408 DartType type = getFunctionType(procedure.function); |
385 List<ConstantValue> metadata = getMetadata(procedure.annotations); | 409 List<ConstantValue> metadata = getMetadata(procedure.annotations); |
386 return nativeBehaviorBuilder.buildMethodBehavior( | 410 return nativeBehaviorBuilder.buildMethodBehavior( |
387 type, metadata, typeLookup(resolveAsRaw: false), | 411 type, metadata, typeLookup(resolveAsRaw: false), |
388 isJsInterop: isJsInterop); | 412 isJsInterop: isJsInterop); |
389 } | 413 } |
390 } | 414 } |
391 | 415 |
392 abstract class KernelToElementMapForBuildingMixin | 416 abstract class KernelToElementMapForBuildingMixin |
393 implements KernelToElementMapForBuilding, KernelToElementMapBaseMixin { | 417 implements KernelToElementMapForBuilding, KernelToElementMapBaseMixin { |
394 @override | |
395 FunctionEntity getSuperNoSuchMethod(ClassEntity cls) { | |
396 while (cls != null) { | |
397 cls = elementEnvironment.getSuperClass(cls); | |
398 MemberEntity member = | |
399 elementEnvironment.lookupClassMember(cls, Identifiers.noSuchMethod_); | |
400 if (member != null) { | |
401 if (member.isFunction) { | |
402 FunctionEntity function = member; | |
403 if (function.parameterStructure.positionalParameters >= 1) { | |
404 return function; | |
405 } | |
406 } | |
407 // If [member] is not a valid `noSuchMethod` the target is | |
408 // `Object.superNoSuchMethod`. | |
409 break; | |
410 } | |
411 } | |
412 FunctionEntity function = elementEnvironment.lookupClassMember( | |
413 commonElements.objectClass, Identifiers.noSuchMethod_); | |
414 assert(function != null, | |
415 failedAt(cls, "No super noSuchMethod found for class $cls.")); | |
416 return function; | |
417 } | |
418 | |
419 js.Template getJsBuiltinTemplate( | 418 js.Template getJsBuiltinTemplate( |
420 ConstantValue constant, CodeEmitterTask emitter) { | 419 ConstantValue constant, CodeEmitterTask emitter) { |
421 int index = _extractEnumIndexFromConstantValue( | 420 int index = _extractEnumIndexFromConstantValue( |
422 constant, commonElements.jsBuiltinEnum); | 421 constant, commonElements.jsBuiltinEnum); |
423 if (index == null) return null; | 422 if (index == null) return null; |
424 return emitter.builtinTemplateFor(JsBuiltin.values[index]); | 423 return emitter.builtinTemplateFor(JsBuiltin.values[index]); |
425 } | 424 } |
426 } | 425 } |
427 | 426 |
428 /// Visitor that converts string literals and concatenations of string literals | 427 /// Visitor that converts string literals and concatenations of string literals |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 } | 842 } |
844 if (isRedirecting) { | 843 if (isRedirecting) { |
845 return new RedirectingGenerativeConstantConstructor( | 844 return new RedirectingGenerativeConstantConstructor( |
846 defaultValues, superConstructorInvocation); | 845 defaultValues, superConstructorInvocation); |
847 } else { | 846 } else { |
848 return new GenerativeConstantConstructor( | 847 return new GenerativeConstantConstructor( |
849 type, defaultValues, fieldMap, superConstructorInvocation); | 848 type, defaultValues, fieldMap, superConstructorInvocation); |
850 } | 849 } |
851 } | 850 } |
852 } | 851 } |
OLD | NEW |