| OLD | NEW |
| 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 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; | 5 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart'; | 8 import '../common/backend_api.dart'; |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| 11 import '../elements/elements.dart' | 11 import '../elements/elements.dart' |
| 12 show | 12 show |
| 13 ClassElement, | 13 ClassElement, |
| 14 Element, | 14 Element, |
| 15 FieldElement, |
| 15 LibraryElement, | 16 LibraryElement, |
| 16 MemberElement, | 17 MemberElement, |
| 17 MetadataAnnotation, | 18 MetadataAnnotation, |
| 18 MethodElement; | 19 MethodElement; |
| 19 import '../elements/modelx.dart' show FunctionElementX, MetadataAnnotationX; | 20 import '../elements/modelx.dart' show FunctionElementX, MetadataAnnotationX; |
| 20 import '../elements/resolution_types.dart' show ResolutionDartType; | 21 import '../elements/resolution_types.dart' show ResolutionDartType; |
| 21 import '../js_backend/js_backend.dart'; | 22 import '../js_backend/js_backend.dart'; |
| 22 import '../js_backend/native_data.dart'; | 23 import '../js_backend/native_data.dart'; |
| 23 import '../patch_parser.dart'; | 24 import '../patch_parser.dart'; |
| 24 import '../tree/tree.dart'; | 25 import '../tree/tree.dart'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 return isJsInterop; | 65 return isJsInterop; |
| 65 } | 66 } |
| 66 | 67 |
| 67 void resolveNativeMember(MemberElement element, NativeRegistry registry) { | 68 void resolveNativeMember(MemberElement element, NativeRegistry registry) { |
| 68 bool isJsInterop = isJsInteropMember(element); | 69 bool isJsInterop = isJsInteropMember(element); |
| 69 if (element.isFunction || | 70 if (element.isFunction || |
| 70 element.isConstructor || | 71 element.isConstructor || |
| 71 element.isGetter || | 72 element.isGetter || |
| 72 element.isSetter) { | 73 element.isSetter) { |
| 73 bool isNative = _processMethodAnnotations(element); | 74 MethodElement method = element; |
| 75 bool isNative = _processMethodAnnotations(method); |
| 74 if (isNative || isJsInterop) { | 76 if (isNative || isJsInterop) { |
| 75 NativeBehavior behavior = NativeBehavior | 77 NativeBehavior behavior = NativeBehavior |
| 76 .ofMethodElement(element, _compiler, isJsInterop: isJsInterop); | 78 .ofMethodElement(method, _compiler, isJsInterop: isJsInterop); |
| 77 _nativeDataBuilder.setNativeMethodBehavior(element, behavior); | 79 _nativeDataBuilder.setNativeMethodBehavior(method, behavior); |
| 78 registry.registerNativeData(behavior); | 80 registry.registerNativeData(behavior); |
| 79 } | 81 } |
| 80 } else if (element.isField) { | 82 } else if (element.isField) { |
| 81 bool isNative = _processFieldAnnotations(element); | 83 FieldElement field = element; |
| 84 bool isNative = _processFieldAnnotations(field); |
| 82 if (isNative || isJsInterop) { | 85 if (isNative || isJsInterop) { |
| 83 NativeBehavior fieldLoadBehavior = NativeBehavior | 86 NativeBehavior fieldLoadBehavior = NativeBehavior |
| 84 .ofFieldElementLoad(element, _compiler, isJsInterop: isJsInterop); | 87 .ofFieldElementLoad(field, _compiler, isJsInterop: isJsInterop); |
| 85 NativeBehavior fieldStoreBehavior = | 88 NativeBehavior fieldStoreBehavior = |
| 86 NativeBehavior.ofFieldElementStore(element, _compiler); | 89 NativeBehavior.ofFieldElementStore(field, _compiler); |
| 87 _nativeDataBuilder.setNativeFieldLoadBehavior( | 90 _nativeDataBuilder.setNativeFieldLoadBehavior(field, fieldLoadBehavior); |
| 88 element, fieldLoadBehavior); | |
| 89 _nativeDataBuilder.setNativeFieldStoreBehavior( | 91 _nativeDataBuilder.setNativeFieldStoreBehavior( |
| 90 element, fieldStoreBehavior); | 92 field, fieldStoreBehavior); |
| 91 | 93 |
| 92 // TODO(sra): Process fields for storing separately. | 94 // TODO(sra): Process fields for storing separately. |
| 93 // We have to handle both loading and storing to the field because we | 95 // We have to handle both loading and storing to the field because we |
| 94 // only get one look at each member and there might be a load or store | 96 // only get one look at each member and there might be a load or store |
| 95 // we have not seen yet. | 97 // we have not seen yet. |
| 96 registry.registerNativeData(fieldLoadBehavior); | 98 registry.registerNativeData(fieldLoadBehavior); |
| 97 registry.registerNativeData(fieldStoreBehavior); | 99 registry.registerNativeData(fieldStoreBehavior); |
| 98 } | 100 } |
| 99 } | 101 } |
| 100 } | 102 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (argument is StringToken) { | 242 if (argument is StringToken) { |
| 241 return argument.value; | 243 return argument.value; |
| 242 } | 244 } |
| 243 } | 245 } |
| 244 return null; | 246 return null; |
| 245 } | 247 } |
| 246 | 248 |
| 247 String apply( | 249 String apply( |
| 248 Compiler compiler, Element element, MetadataAnnotation annotation) { | 250 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 249 if (element.isClass) { | 251 if (element.isClass) { |
| 252 ClassElement cls = element; |
| 250 String native = getNativeAnnotation(annotation); | 253 String native = getNativeAnnotation(annotation); |
| 251 if (native != null) { | 254 if (native != null) { |
| 252 _nativeClassDataBuilder.setNativeClassTagInfo(element, native); | 255 _nativeClassDataBuilder.setNativeClassTagInfo(cls, native); |
| 253 return native; | 256 return native; |
| 254 } | 257 } |
| 255 } | 258 } |
| 256 return null; | 259 return null; |
| 257 } | 260 } |
| 258 | 261 |
| 259 void validate(Compiler compiler, Element element, | 262 void validate(Compiler compiler, Element element, |
| 260 MetadataAnnotation annotation, ConstantValue constant) { | 263 MetadataAnnotation annotation, ConstantValue constant) { |
| 261 ResolutionDartType annotationType = | 264 ResolutionDartType annotationType = |
| 262 constant.getType(compiler.commonElements); | 265 constant.getType(compiler.commonElements); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 273 bool checkJsInteropAnnotation(Element element) { | 276 bool checkJsInteropAnnotation(Element element) { |
| 274 return EagerAnnotationHandler.checkAnnotation( | 277 return EagerAnnotationHandler.checkAnnotation( |
| 275 compiler, element, const JsInteropAnnotationHandler()); | 278 compiler, element, const JsInteropAnnotationHandler()); |
| 276 } | 279 } |
| 277 | 280 |
| 278 if (checkJsInteropAnnotation(library)) { | 281 if (checkJsInteropAnnotation(library)) { |
| 279 nativeClassDataBuilder.markAsJsInteropLibrary(library); | 282 nativeClassDataBuilder.markAsJsInteropLibrary(library); |
| 280 } | 283 } |
| 281 library.forEachLocalMember((Element element) { | 284 library.forEachLocalMember((Element element) { |
| 282 if (element.isClass) { | 285 if (element.isClass) { |
| 286 ClassElement cls = element; |
| 283 if (checkJsInteropAnnotation(element)) { | 287 if (checkJsInteropAnnotation(element)) { |
| 284 nativeClassDataBuilder.markAsJsInteropClass(element); | 288 nativeClassDataBuilder.markAsJsInteropClass(cls); |
| 285 } | 289 } |
| 286 } | 290 } |
| 287 }); | 291 }); |
| 288 } | 292 } |
| 289 | 293 |
| 290 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element, | 294 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element, |
| 291 NativeDataBuilder nativeDataBuilder) { | 295 NativeDataBuilder nativeDataBuilder) { |
| 292 bool isJsInterop = EagerAnnotationHandler.checkAnnotation( | 296 bool isJsInterop = EagerAnnotationHandler.checkAnnotation( |
| 293 compiler, element, const JsInteropAnnotationHandler()); | 297 compiler, element, const JsInteropAnnotationHandler()); |
| 294 if (isJsInterop) { | 298 if (isJsInterop) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 316 JavaScriptBackend backend = compiler.backend; | 320 JavaScriptBackend backend = compiler.backend; |
| 317 ResolutionDartType type = constant.getType(compiler.commonElements); | 321 ResolutionDartType type = constant.getType(compiler.commonElements); |
| 318 if (type.element != backend.helpers.jsAnnotationClass) { | 322 if (type.element != backend.helpers.jsAnnotationClass) { |
| 319 compiler.reporter | 323 compiler.reporter |
| 320 .internalError(annotation, 'Invalid @JS(...) annotation.'); | 324 .internalError(annotation, 'Invalid @JS(...) annotation.'); |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 | 327 |
| 324 bool get defaultResult => false; | 328 bool get defaultResult => false; |
| 325 } | 329 } |
| OLD | NEW |