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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart

Issue 2732793002: Add NativeDataResolver (Closed)
Patch Set: Cleanup. Created 3 years, 9 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
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 library dart2js.js_emitter.program_builder; 5 library dart2js.js_emitter.program_builder;
6 6
7 import '../../closure.dart' show ClosureFieldElement; 7 import '../../closure.dart' show ClosureFieldElement;
8 import '../../common.dart'; 8 import '../../common.dart';
9 import '../../common/names.dart' show Names, Selectors; 9 import '../../common/names.dart' show Names, Selectors;
10 import '../../compiler.dart' show Compiler; 10 import '../../compiler.dart' show Compiler;
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // Interceptor class with implementations that directly call the 344 // Interceptor class with implementations that directly call the
345 // corresponding JavaScript member. We do not attempt to bind this when 345 // corresponding JavaScript member. We do not attempt to bind this when
346 // tearing off JavaScript methods as we cannot distinguish between calling 346 // tearing off JavaScript methods as we cannot distinguish between calling
347 // a regular getter that returns a JavaScript function and tearing off 347 // a regular getter that returns a JavaScript function and tearing off
348 // a method in the case where there exist multiple JavaScript classes 348 // a method in the case where there exist multiple JavaScript classes
349 // that conflict on whether the member is a getter or a method. 349 // that conflict on whether the member is a getter or a method.
350 var interceptorClass = _classes[helpers.jsJavaScriptObjectClass]; 350 var interceptorClass = _classes[helpers.jsJavaScriptObjectClass];
351 var stubNames = new Set<String>(); 351 var stubNames = new Set<String>();
352 librariesMap.forEach((LibraryElement library, List<Element> elements) { 352 librariesMap.forEach((LibraryElement library, List<Element> elements) {
353 for (Element e in elements) { 353 for (Element e in elements) {
354 if (e is ClassElement && backend.nativeData.isJsInterop(e)) { 354 if (e is ClassElement && backend.nativeData.isJsInteropClass(e)) {
355 e.declaration.forEachMember((_, Element member) { 355 e.declaration.forEachMember((_, Element member) {
356 var jsName = 356 var jsName =
357 backend.nativeData.getUnescapedJSInteropName(member.name); 357 backend.nativeData.getUnescapedJSInteropName(member.name);
358 if (!member.isInstanceMember) return; 358 if (!member.isInstanceMember) return;
359 if (member.isGetter || member.isField || member.isFunction) { 359 if (member.isGetter || member.isField || member.isFunction) {
360 var selectors = worldBuilder.getterInvocationsByName(member.name); 360 var selectors = worldBuilder.getterInvocationsByName(member.name);
361 if (selectors != null && !selectors.isEmpty) { 361 if (selectors != null && !selectors.isEmpty) {
362 for (var selector in selectors.keys) { 362 for (var selector in selectors.keys) {
363 var stubName = namer.invocationName(selector); 363 var stubName = namer.invocationName(selector);
364 if (stubNames.add(stubName.key)) { 364 if (stubNames.add(stubName.key)) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 List<Field> staticFieldsForReflection = 489 List<Field> staticFieldsForReflection =
490 _buildFields(library, visitStatics: visitStatics); 490 _buildFields(library, visitStatics: visitStatics);
491 491
492 return new Library( 492 return new Library(
493 library, uri, statics, classes, staticFieldsForReflection); 493 library, uri, statics, classes, staticFieldsForReflection);
494 } 494 }
495 495
496 Class _buildClass(ClassElement element) { 496 Class _buildClass(ClassElement element) {
497 bool onlyForRti = collector.classesOnlyNeededForRti.contains(element); 497 bool onlyForRti = collector.classesOnlyNeededForRti.contains(element);
498 bool hasRtiField = backend.rtiNeed.classNeedsRtiField(element); 498 bool hasRtiField = backend.rtiNeed.classNeedsRtiField(element);
499 if (backend.nativeData.isJsInterop(element)) { 499 if (backend.nativeData.isJsInteropClass(element)) {
500 // TODO(jacobr): check whether the class has any active static fields 500 // TODO(jacobr): check whether the class has any active static fields
501 // if it does not we can suppress it completely. 501 // if it does not we can suppress it completely.
502 onlyForRti = true; 502 onlyForRti = true;
503 } 503 }
504 504
505 List<Method> methods = []; 505 List<Method> methods = [];
506 List<StubMethod> callStubs = <StubMethod>[]; 506 List<StubMethod> callStubs = <StubMethod>[];
507 507
508 ClassStubGenerator classStubGenerator = new ClassStubGenerator( 508 ClassStubGenerator classStubGenerator = new ClassStubGenerator(
509 namer, backend, worldBuilder, closedWorld, 509 namer, backend, worldBuilder, closedWorld,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 List<Field> staticFieldsForReflection = onlyForRti 577 List<Field> staticFieldsForReflection = onlyForRti
578 ? const <Field>[] 578 ? const <Field>[]
579 : _buildFields(element, 579 : _buildFields(element,
580 visitStatics: true, isHolderInterceptedClass: isInterceptedClass); 580 visitStatics: true, isHolderInterceptedClass: isInterceptedClass);
581 581
582 TypeTestProperties typeTests = runtimeTypeGenerator.generateIsTests(element, 582 TypeTestProperties typeTests = runtimeTypeGenerator.generateIsTests(element,
583 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata); 583 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata);
584 584
585 List<StubMethod> checkedSetters = <StubMethod>[]; 585 List<StubMethod> checkedSetters = <StubMethod>[];
586 List<StubMethod> isChecks = <StubMethod>[]; 586 List<StubMethod> isChecks = <StubMethod>[];
587 if (backend.nativeData.isJsInterop(element)) { 587 if (backend.nativeData.isJsInteropClass(element)) {
588 typeTests.properties.forEach((js.Name name, js.Node code) { 588 typeTests.properties.forEach((js.Name name, js.Node code) {
589 _classes[helpers.jsInterceptorClass] 589 _classes[helpers.jsInterceptorClass]
590 .isChecks 590 .isChecks
591 .add(_buildStubMethod(name, code)); 591 .add(_buildStubMethod(name, code));
592 }); 592 });
593 } else { 593 } else {
594 for (Field field in instanceFields) { 594 for (Field field in instanceFields) {
595 if (field.needsCheckedSetter) { 595 if (field.needsCheckedSetter) {
596 assert(!field.needsUncheckedSetter); 596 assert(!field.needsUncheckedSetter);
597 FieldElement element = field.element; 597 FieldElement element = field.element;
598 js.Expression code = backend.generatedCode[element]; 598 js.Expression code = backend.generatedCode[element];
599 assert(code != null); 599 assert(code != null);
600 js.Name name = namer.deriveSetterName(field.accessorName); 600 js.Name name = namer.deriveSetterName(field.accessorName);
601 checkedSetters.add(_buildStubMethod(name, code, element: element)); 601 checkedSetters.add(_buildStubMethod(name, code, element: element));
602 } 602 }
603 } 603 }
604 604
605 typeTests.properties.forEach((js.Name name, js.Node code) { 605 typeTests.properties.forEach((js.Name name, js.Node code) {
606 isChecks.add(_buildStubMethod(name, code)); 606 isChecks.add(_buildStubMethod(name, code));
607 }); 607 });
608 } 608 }
609 609
610 js.Name name = namer.className(element); 610 js.Name name = namer.className(element);
611 String holderName = namer.globalObjectFor(element); 611 String holderName = namer.globalObjectFor(element);
612 // TODO(floitsch): we shouldn't update the registry in the middle of 612 // TODO(floitsch): we shouldn't update the registry in the middle of
613 // building a class. 613 // building a class.
614 Holder holder = _registry.registerHolder(holderName); 614 Holder holder = _registry.registerHolder(holderName);
615 bool isInstantiated = !backend.nativeData.isJsInterop(element) && 615 bool isInstantiated = !backend.nativeData.isJsInteropClass(element) &&
616 worldBuilder.directlyInstantiatedClasses.contains(element); 616 worldBuilder.directlyInstantiatedClasses.contains(element);
617 617
618 Class result; 618 Class result;
619 if (element.isMixinApplication && !onlyForRti) { 619 if (element.isMixinApplication && !onlyForRti) {
620 assert(!backend.nativeData.isNativeClass(element)); 620 assert(!backend.nativeData.isNativeClass(element));
621 assert(methods.isEmpty); 621 assert(methods.isEmpty);
622 622
623 result = new MixinApplication( 623 result = new MixinApplication(
624 element, 624 element,
625 name, 625 name,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 Constant constant = new Constant(name, holder, constantValue); 975 Constant constant = new Constant(name, holder, constantValue);
976 _constants[constantValue] = constant; 976 _constants[constantValue] = constant;
977 } 977 }
978 } 978 }
979 979
980 Holder _registerStaticStateHolder() { 980 Holder _registerStaticStateHolder() {
981 return _registry.registerHolder(namer.staticStateHolder, 981 return _registry.registerHolder(namer.staticStateHolder,
982 isStaticStateHolder: true); 982 isStaticStateHolder: true);
983 } 983 }
984 } 984 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698