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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend_helpers.dart

Issue 2531303002: Decouple WorkItem from Compiler (Closed)
Patch Set: Updated cf. comments. Created 4 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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_backend.helpers; 5 library dart2js.js_backend.helpers;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show Identifiers, Uris; 8 import '../common/names.dart' show Identifiers, Uris;
9 import '../common/resolution.dart' show Resolution; 9 import '../common/resolution.dart' show Resolution;
10 import '../compiler.dart' show Compiler; 10 import '../compiler.dart' show Compiler;
11 import '../core_types.dart' show CoreClasses; 11 import '../core_types.dart' show CoreClasses;
12 import '../elements/elements.dart' 12 import '../elements/elements.dart'
13 show 13 show
14 AbstractFieldElement, 14 AbstractFieldElement,
15 ClassElement, 15 ClassElement,
16 ConstructorElement, 16 ConstructorElement,
17 Element, 17 Element,
18 EnumClassElement, 18 EnumClassElement,
19 FieldElement, 19 FieldElement,
20 FunctionElement, 20 FunctionElement,
21 LibraryElement, 21 LibraryElement,
22 MemberElement, 22 MemberElement,
23 MethodElement, 23 MethodElement,
24 Name,
24 PublicName; 25 PublicName;
25 import '../library_loader.dart' show LoadedLibraries; 26 import '../library_loader.dart' show LoadedLibraries;
26 import '../universe/call_structure.dart' show CallStructure; 27 import '../universe/call_structure.dart' show CallStructure;
27 import '../universe/selector.dart' show Selector; 28 import '../universe/selector.dart' show Selector;
28 import 'js_backend.dart'; 29 import 'js_backend.dart';
29 30
30 /// Helper classes and functions for the JavaScript backend. 31 /// Helper classes and functions for the JavaScript backend.
31 class BackendHelpers { 32 class BackendHelpers {
32 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); 33 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper');
33 static final Uri DART_INTERCEPTORS = 34 static final Uri DART_INTERCEPTORS =
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 MethodElement jsArrayAdd; 114 MethodElement jsArrayAdd;
114 MethodElement jsStringSplit; 115 MethodElement jsStringSplit;
115 Element jsStringToString; 116 Element jsStringToString;
116 Element jsStringOperatorAdd; 117 Element jsStringOperatorAdd;
117 Element objectEquals; 118 Element objectEquals;
118 119
119 ClassElement typeLiteralClass; 120 ClassElement typeLiteralClass;
120 ClassElement mapLiteralClass; 121 ClassElement mapLiteralClass;
121 ClassElement constMapLiteralClass; 122 ClassElement constMapLiteralClass;
122 ClassElement typeVariableClass; 123 ClassElement typeVariableClass;
123 ConstructorElement mapLiteralConstructor;
124 ConstructorElement mapLiteralConstructorEmpty;
125 Element mapLiteralUntypedMaker;
126 Element mapLiteralUntypedEmptyMaker;
127 124
128 ClassElement noSideEffectsClass; 125 ClassElement noSideEffectsClass;
129 ClassElement noThrowsClass; 126 ClassElement noThrowsClass;
130 ClassElement noInlineClass; 127 ClassElement noInlineClass;
131 ClassElement forceInlineClass; 128 ClassElement forceInlineClass;
132 ClassElement irRepresentationClass; 129 ClassElement irRepresentationClass;
133 130
134 ClassElement jsAnnotationClass; 131 ClassElement jsAnnotationClass;
135 ClassElement jsAnonymousClass; 132 ClassElement jsAnonymousClass;
136 133
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add'); 386 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add');
390 387
391 jsStringClass.ensureResolved(resolution); 388 jsStringClass.ensureResolved(resolution);
392 jsStringSplit = compiler.lookupElementIn(jsStringClass, 'split'); 389 jsStringSplit = compiler.lookupElementIn(jsStringClass, 'split');
393 jsStringOperatorAdd = compiler.lookupElementIn(jsStringClass, '+'); 390 jsStringOperatorAdd = compiler.lookupElementIn(jsStringClass, '+');
394 jsStringToString = compiler.lookupElementIn(jsStringClass, 'toString'); 391 jsStringToString = compiler.lookupElementIn(jsStringClass, 'toString');
395 392
396 objectEquals = compiler.lookupElementIn(coreClasses.objectClass, '=='); 393 objectEquals = compiler.lookupElementIn(coreClasses.objectClass, '==');
397 } 394 }
398 395
396 ConstructorElement _mapLiteralConstructor;
397 ConstructorElement _mapLiteralConstructorEmpty;
398 Element _mapLiteralUntypedMaker;
399 Element _mapLiteralUntypedEmptyMaker;
400
401 ConstructorElement get mapLiteralConstructor {
402 _ensureMapLiteralHelpers();
403 return _mapLiteralConstructor;
404 }
405
406 ConstructorElement get mapLiteralConstructorEmpty {
407 _ensureMapLiteralHelpers();
408 return _mapLiteralConstructorEmpty;
409 }
410
411 Element get mapLiteralUntypedMaker {
412 _ensureMapLiteralHelpers();
413 return _mapLiteralUntypedMaker;
414 }
415
416 Element get mapLiteralUntypedEmptyMaker {
417 _ensureMapLiteralHelpers();
418 return _mapLiteralUntypedEmptyMaker;
419 }
420
421 void _ensureMapLiteralHelpers() {
422 if (_mapLiteralConstructor != null) return;
423
424 // For map literals, the dependency between the implementation class
425 // and [Map] is not visible, so we have to add it manually.
426 Element getFactory(String name, int arity) {
427 // The constructor is on the patch class, but dart2js unit tests don't
428 // have a patch class.
429 ClassElement implementation = mapLiteralClass.implementation;
430 ConstructorElement ctor = implementation.lookupConstructor(name);
431 if (ctor == null ||
432 (Name.isPrivateName(name) &&
433 ctor.library != mapLiteralClass.library)) {
434 reporter.internalError(
435 mapLiteralClass,
436 "Map literal class ${mapLiteralClass} missing "
437 "'$name' constructor"
438 " ${mapLiteralClass.constructors}");
439 }
440 return ctor;
441 }
442
443 Element getMember(String name) {
444 // The constructor is on the patch class, but dart2js unit tests don't
445 // have a patch class.
446 ClassElement implementation = mapLiteralClass.implementation;
447 Element element = implementation.lookupLocalMember(name);
448 if (element == null || !element.isFunction || !element.isStatic) {
449 reporter.internalError(
450 mapLiteralClass,
451 "Map literal class ${mapLiteralClass} missing "
452 "'$name' static member function");
453 }
454 return element;
455 }
456
457 _mapLiteralConstructor = getFactory('_literal', 1);
458 _mapLiteralConstructorEmpty = getFactory('_empty', 0);
459 _mapLiteralUntypedMaker = getMember('_makeLiteral');
460 _mapLiteralUntypedEmptyMaker = getMember('_makeEmpty');
461 }
462
399 Element get badMain { 463 Element get badMain {
400 return findHelper('badMain'); 464 return findHelper('badMain');
401 } 465 }
402 466
403 Element get missingMain { 467 Element get missingMain {
404 return findHelper('missingMain'); 468 return findHelper('missingMain');
405 } 469 }
406 470
407 Element get mainHasTooManyParameters { 471 Element get mainHasTooManyParameters {
408 return findHelper('mainHasTooManyParameters'); 472 return findHelper('mainHasTooManyParameters');
409 } 473 }
410 474
411 MethodElement get loadLibraryWrapper { 475 MethodElement get loadLibraryWrapper {
412 return findHelper("_loadLibraryWrapper"); 476 return findHelper("_loadLibraryWrapper");
413 } 477 }
414 478
415 Element get boolConversionCheck { 479 Element get boolConversionCheck {
416 return findHelper('boolConversionCheck'); 480 return findHelper('boolConversionCheck');
417 } 481 }
418 482
419 Element get consoleTraceHelper { 483 MethodElement _traceHelper;
484
485 MethodElement get traceHelper {
486 return _traceHelper ??= JavaScriptBackend.TRACE_METHOD == 'console'
487 ? _consoleTraceHelper
488 : _postTraceHelper;
489 }
490
491 MethodElement get _consoleTraceHelper {
420 return findHelper('consoleTraceHelper'); 492 return findHelper('consoleTraceHelper');
421 } 493 }
422 494
423 Element get postTraceHelper { 495 MethodElement get _postTraceHelper {
424 return findHelper('postTraceHelper'); 496 return findHelper('postTraceHelper');
425 } 497 }
426 498
427 FunctionElement get closureFromTearOff { 499 FunctionElement get closureFromTearOff {
428 return findHelper('closureFromTearOff'); 500 return findHelper('closureFromTearOff');
429 } 501 }
430 502
431 Element get isJsIndexable { 503 Element get isJsIndexable {
432 return findHelper('isJsIndexable'); 504 return findHelper('isJsIndexable');
433 } 505 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 MethodElement _objectNoSuchMethod; 795 MethodElement _objectNoSuchMethod;
724 796
725 MethodElement get objectNoSuchMethod { 797 MethodElement get objectNoSuchMethod {
726 if (_objectNoSuchMethod == null) { 798 if (_objectNoSuchMethod == null) {
727 _objectNoSuchMethod = 799 _objectNoSuchMethod =
728 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_); 800 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_);
729 } 801 }
730 return _objectNoSuchMethod; 802 return _objectNoSuchMethod;
731 } 803 }
732 } 804 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_backend/backend_impact.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698