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

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

Issue 1888803002: Support serialization of all resolved asts from dart:core (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix unittests. Created 4 years, 8 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) 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 FunctionElement, 19 FunctionElement,
20 LibraryElement, 20 LibraryElement,
21 MethodElement; 21 MethodElement,
22 PublicName;
22 import '../library_loader.dart' show LoadedLibraries; 23 import '../library_loader.dart' show LoadedLibraries;
24 import '../universe/call_structure.dart' show CallStructure;
25 import '../universe/selector.dart' show Selector;
23 26
24 import 'js_backend.dart'; 27 import 'js_backend.dart';
25 28
26 /// Helper classes and functions for the JavaScript backend. 29 /// Helper classes and functions for the JavaScript backend.
27 class BackendHelpers { 30 class BackendHelpers {
28 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); 31 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper');
29 static final Uri DART_INTERCEPTORS = 32 static final Uri DART_INTERCEPTORS =
30 new Uri(scheme: 'dart', path: '_interceptors'); 33 new Uri(scheme: 'dart', path: '_interceptors');
31 static final Uri DART_FOREIGN_HELPER = 34 static final Uri DART_FOREIGN_HELPER =
32 new Uri(scheme: 'dart', path: '_foreign_helper'); 35 new Uri(scheme: 'dart', path: '_foreign_helper');
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 170
168 /// Holds the method "requiresPreamble" in _js_helper. 171 /// Holds the method "requiresPreamble" in _js_helper.
169 FunctionElement requiresPreambleMarker; 172 FunctionElement requiresPreambleMarker;
170 173
171 /// Holds the class for the [JsGetName] enum. 174 /// Holds the class for the [JsGetName] enum.
172 EnumClassElement jsGetNameEnum; 175 EnumClassElement jsGetNameEnum;
173 176
174 /// Holds the class for the [JsBuiltins] enum. 177 /// Holds the class for the [JsBuiltins] enum.
175 EnumClassElement jsBuiltinEnum; 178 EnumClassElement jsBuiltinEnum;
176 179
180 ClassElement _symbolImplementationClass;
181 ClassElement get symbolImplementationClass {
182 return _symbolImplementationClass ??= find(internalLibrary, 'Symbol');
183 }
184
185 final Selector symbolValidatedConstructorSelector =
186 new Selector.call(const PublicName('validated'), CallStructure.ONE_ARG);
187
188 ConstructorElement _symbolValidatedConstructor;
189
190 bool isSymbolValidatedConstructor(Element element) {
191 if (_symbolValidatedConstructor != null) {
192 return element == _symbolValidatedConstructor;
193 }
194 return false;
195 }
196
197 ConstructorElement get symbolValidatedConstructor {
198 return _symbolValidatedConstructor ??= _findConstructor(
199 symbolImplementationClass, symbolValidatedConstructorSelector.name);
200 }
201
177 // TODO(johnniwinther): Make these private. 202 // TODO(johnniwinther): Make these private.
178 // TODO(johnniwinther): Split into findHelperFunction and findHelperClass and 203 // TODO(johnniwinther): Split into findHelperFunction and findHelperClass and
179 // add a check that the element has the expected kind. 204 // add a check that the element has the expected kind.
180 Element findHelper(String name) => find(jsHelperLibrary, name); 205 Element findHelper(String name) => find(jsHelperLibrary, name);
181 Element findAsyncHelper(String name) => find(asyncLibrary, name); 206 Element findAsyncHelper(String name) => find(asyncLibrary, name);
182 Element findInterceptor(String name) => find(interceptorsLibrary, name); 207 Element findInterceptor(String name) => find(interceptorsLibrary, name);
183 Element find(LibraryElement library, String name) { 208 Element find(LibraryElement library, String name) {
184 Element element = library.implementation.findLocal(name); 209 Element element = library.implementation.findLocal(name);
185 assert(invariant(library, element != null, 210 assert(invariant(library, element != null,
186 message: "Element '$name' not found in '${library.canonicalUri}'.")); 211 message: "Element '$name' not found in '${library.canonicalUri}'."));
187 return element; 212 return element;
188 } 213 }
189 214
215 ConstructorElement _findConstructor(ClassElement cls, String name) {
216 cls.ensureResolved(resolution);
217 ConstructorElement constructor = cls.lookupConstructor(name);
218 assert(invariant(cls, constructor != null,
219 message: "Constructor '$name' not found in '${cls}'."));
220 return constructor;
221 }
222
190 void onLibraryCreated(LibraryElement library) { 223 void onLibraryCreated(LibraryElement library) {
191 Uri uri = library.canonicalUri; 224 Uri uri = library.canonicalUri;
192 if (uri == DART_JS_HELPER) { 225 if (uri == DART_JS_HELPER) {
193 jsHelperLibrary = library; 226 jsHelperLibrary = library;
194 } else if (uri == Uris.dart_async) { 227 } else if (uri == Uris.dart_async) {
195 asyncLibrary = library; 228 asyncLibrary = library;
196 } else if (uri == Uris.dart__internal) { 229 } else if (uri == Uris.dart__internal) {
197 internalLibrary = library; 230 internalLibrary = library;
198 } else if (uri == DART_INTERCEPTORS) { 231 } else if (uri == DART_INTERCEPTORS) {
199 interceptorsLibrary = library; 232 interceptorsLibrary = library;
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 MethodElement _objectNoSuchMethod; 706 MethodElement _objectNoSuchMethod;
674 707
675 MethodElement get objectNoSuchMethod { 708 MethodElement get objectNoSuchMethod {
676 if (_objectNoSuchMethod == null) { 709 if (_objectNoSuchMethod == null) {
677 _objectNoSuchMethod = 710 _objectNoSuchMethod =
678 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_); 711 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_);
679 } 712 }
680 return _objectNoSuchMethod; 713 return _objectNoSuchMethod;
681 } 714 }
682 } 715 }
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