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

Side by Side Diff: pkg/compiler/lib/src/native/resolver.dart

Issue 2935663002: Remove Compiler.commonElements (Closed)
Patch Set: Remove Compiler._commonElements Created 3 years, 6 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
« no previous file with comments | « pkg/compiler/lib/src/native/behavior.dart ('k') | pkg/compiler/lib/src/patch_parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; 5 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token;
6 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN; 6 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN;
7 import 'package:front_end/src/scanner/token.dart' show BeginToken; 7 import 'package:front_end/src/scanner/token.dart' show BeginToken;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common_elements.dart' show CommonElements, ElementEnvironment; 10 import '../common_elements.dart' show CommonElements, ElementEnvironment;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 class NativeDataResolverImpl extends NativeMemberResolverBase 212 class NativeDataResolverImpl extends NativeMemberResolverBase
213 implements NativeDataResolver { 213 implements NativeDataResolver {
214 final Compiler _compiler; 214 final Compiler _compiler;
215 215
216 NativeDataResolverImpl(this._compiler); 216 NativeDataResolverImpl(this._compiler);
217 217
218 JavaScriptBackend get _backend => _compiler.backend; 218 JavaScriptBackend get _backend => _compiler.backend;
219 DiagnosticReporter get _reporter => _compiler.reporter; 219 DiagnosticReporter get _reporter => _compiler.reporter;
220 ElementEnvironment get elementEnvironment => _compiler.elementEnvironment; 220 ElementEnvironment get elementEnvironment => _compiler.elementEnvironment;
221 CommonElements get commonElements => _compiler.commonElements; 221 CommonElements get commonElements => _compiler.resolution.commonElements;
222 NativeBasicData get nativeBasicData => _backend.nativeBasicData; 222 NativeBasicData get nativeBasicData => _backend.nativeBasicData;
223 NativeDataBuilder get nativeDataBuilder => _backend.nativeDataBuilder; 223 NativeDataBuilder get nativeDataBuilder => _backend.nativeDataBuilder;
224 224
225 @override 225 @override
226 bool isJsInteropMember(MemberElement element) { 226 bool isJsInteropMember(MemberElement element) {
227 // TODO(johnniwinther): Avoid computing this twice for external function; 227 // TODO(johnniwinther): Avoid computing this twice for external function;
228 // once from JavaScriptBackendTarget.resolveExternalFunction and once 228 // once from JavaScriptBackendTarget.resolveExternalFunction and once
229 // through JavaScriptBackendTarget.resolveNativeMember. 229 // through JavaScriptBackendTarget.resolveNativeMember.
230 bool isJsInterop = 230 bool isJsInterop =
231 checkJsInteropMemberAnnotations(_compiler, element, nativeDataBuilder); 231 checkJsInteropMemberAnnotations(_compiler, element, nativeDataBuilder);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 @override 286 @override
287 bool _processFieldAnnotations(FieldElement element) { 287 bool _processFieldAnnotations(FieldElement element) {
288 if (_compiler.serialization.isDeserialized(element)) { 288 if (_compiler.serialization.isDeserialized(element)) {
289 return false; 289 return false;
290 } 290 }
291 return super._processFieldAnnotations(element); 291 return super._processFieldAnnotations(element);
292 } 292 }
293 293
294 @override 294 @override
295 NativeBehavior resolveJsCall(Send node, ForeignResolver resolver) { 295 NativeBehavior resolveJsCall(Send node, ForeignResolver resolver) {
296 return NativeBehavior.ofJsCallSend(node, _reporter, 296 return NativeBehavior.ofJsCallSend(
297 _compiler.parsingContext, _compiler.commonElements, resolver); 297 node, _reporter, _compiler.parsingContext, commonElements, resolver);
298 } 298 }
299 299
300 @override 300 @override
301 NativeBehavior resolveJsEmbeddedGlobalCall( 301 NativeBehavior resolveJsEmbeddedGlobalCall(
302 Send node, ForeignResolver resolver) { 302 Send node, ForeignResolver resolver) {
303 return NativeBehavior.ofJsEmbeddedGlobalCallSend( 303 return NativeBehavior.ofJsEmbeddedGlobalCallSend(
304 node, _reporter, _compiler.commonElements, resolver); 304 node, _reporter, commonElements, resolver);
305 } 305 }
306 306
307 @override 307 @override
308 NativeBehavior resolveJsBuiltinCall(Send node, ForeignResolver resolver) { 308 NativeBehavior resolveJsBuiltinCall(Send node, ForeignResolver resolver) {
309 return NativeBehavior.ofJsBuiltinCallSend( 309 return NativeBehavior.ofJsBuiltinCallSend(
310 node, _reporter, _compiler.commonElements, resolver); 310 node, _reporter, commonElements, resolver);
311 } 311 }
312 } 312 }
313 313
314 /// Annotation handler for pre-resolution detection of `@Native(...)` 314 /// Annotation handler for pre-resolution detection of `@Native(...)`
315 /// annotations. 315 /// annotations.
316 class NativeAnnotationHandler extends EagerAnnotationHandler<String> { 316 class NativeAnnotationHandler extends EagerAnnotationHandler<String> {
317 final NativeBasicDataBuilder _nativeBasicDataBuilder; 317 final NativeBasicDataBuilder _nativeBasicDataBuilder;
318 318
319 NativeAnnotationHandler(this._nativeBasicDataBuilder); 319 NativeAnnotationHandler(this._nativeBasicDataBuilder);
320 320
(...skipping 19 matching lines...) Expand all
340 _nativeBasicDataBuilder.setNativeClassTagInfo(cls, tagText); 340 _nativeBasicDataBuilder.setNativeClassTagInfo(cls, tagText);
341 return native; 341 return native;
342 } 342 }
343 } 343 }
344 return null; 344 return null;
345 } 345 }
346 346
347 void validate(Compiler compiler, Element element, 347 void validate(Compiler compiler, Element element,
348 MetadataAnnotation annotation, ConstantValue constant) { 348 MetadataAnnotation annotation, ConstantValue constant) {
349 ResolutionDartType annotationType = 349 ResolutionDartType annotationType =
350 constant.getType(compiler.commonElements); 350 constant.getType(compiler.resolution.commonElements);
351 if (annotationType.element != 351 if (annotationType.element !=
352 compiler.commonElements.nativeAnnotationClass) { 352 compiler.resolution.commonElements.nativeAnnotationClass) {
353 DiagnosticReporter reporter = compiler.reporter; 353 DiagnosticReporter reporter = compiler.reporter;
354 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); 354 reporter.internalError(annotation, 'Invalid @Native(...) annotation.');
355 } 355 }
356 } 356 }
357 } 357 }
358 358
359 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element, 359 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element,
360 NativeDataBuilder nativeDataBuilder) { 360 NativeDataBuilder nativeDataBuilder) {
361 bool isJsInterop = EagerAnnotationHandler.checkAnnotation( 361 bool isJsInterop = EagerAnnotationHandler.checkAnnotation(
362 compiler, element, const JsInteropAnnotationHandler()); 362 compiler, element, const JsInteropAnnotationHandler());
(...skipping 13 matching lines...) Expand all
376 annotation.beginToken.next.lexeme == 'JS'; 376 annotation.beginToken.next.lexeme == 'JS';
377 377
378 bool apply( 378 bool apply(
379 Compiler compiler, Element element, MetadataAnnotation annotation) { 379 Compiler compiler, Element element, MetadataAnnotation annotation) {
380 return hasJsNameAnnotation(annotation); 380 return hasJsNameAnnotation(annotation);
381 } 381 }
382 382
383 @override 383 @override
384 void validate(Compiler compiler, Element element, 384 void validate(Compiler compiler, Element element,
385 MetadataAnnotation annotation, ConstantValue constant) { 385 MetadataAnnotation annotation, ConstantValue constant) {
386 ResolutionDartType type = constant.getType(compiler.commonElements); 386 ResolutionDartType type =
387 if (type.element != compiler.commonElements.jsAnnotationClass) { 387 constant.getType(compiler.resolution.commonElements);
388 if (type.element != compiler.resolution.commonElements.jsAnnotationClass) {
388 compiler.reporter 389 compiler.reporter
389 .internalError(annotation, 'Invalid @JS(...) annotation.'); 390 .internalError(annotation, 'Invalid @JS(...) annotation.');
390 } 391 }
391 } 392 }
392 393
393 bool get defaultResult => false; 394 bool get defaultResult => false;
394 } 395 }
395 396
396 /// Determines all native classes in a set of libraries. 397 /// Determines all native classes in a set of libraries.
397 abstract class NativeClassFinder { 398 abstract class NativeClassFinder {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 616
616 Iterable<ConstantValue> fields = constructedObject.fields.values; 617 Iterable<ConstantValue> fields = constructedObject.fields.values;
617 // TODO(sra): Better validation of the constant. 618 // TODO(sra): Better validation of the constant.
618 if (fields.length != 1 || fields.single is! StringConstantValue) { 619 if (fields.length != 1 || fields.single is! StringConstantValue) {
619 throw new SpannableAssertionFailure( 620 throw new SpannableAssertionFailure(
620 spannable, 'Annotations needs one string: ${value.toStructuredText()}'); 621 spannable, 'Annotations needs one string: ${value.toStructuredText()}');
621 } 622 }
622 StringConstantValue specStringConstant = fields.single; 623 StringConstantValue specStringConstant = fields.single;
623 return specStringConstant.primitiveValue; 624 return specStringConstant.primitiveValue;
624 } 625 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/native/behavior.dart ('k') | pkg/compiler/lib/src/patch_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698