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

Side by Side Diff: pkg/compiler/lib/src/kernel/element_adapter.dart

Issue 2685673004: Handle Creates and Returns annotations in KernelBehaviorBuilder (Closed)
Patch Set: Updated cf. comment Created 3 years, 10 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart'; 8 import '../common/names.dart';
9 import '../constants/constructors.dart'; 9 import '../constants/constructors.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 /// Return `true` if [node] is the `dart:_foreign_helper` library. 239 /// Return `true` if [node] is the `dart:_foreign_helper` library.
240 bool isForeignLibrary(ir.Library node) { 240 bool isForeignLibrary(ir.Library node) {
241 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER; 241 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER;
242 } 242 }
243 243
244 /// Looks up [typeName] for use in the spec-string of a `JS` called. 244 /// Looks up [typeName] for use in the spec-string of a `JS` called.
245 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling 245 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling
246 // the `ForeignResolver`. 246 // the `ForeignResolver`.
247 // TODO(johnniwinther): Cache the result to avoid redundant lookups? 247 // TODO(johnniwinther): Cache the result to avoid redundant lookups?
248 native.TypeLookup typeLookup({bool resolveAsRaw: true}) { 248 native.TypeLookup typeLookup({bool resolveAsRaw: true}) {
249 return (String typeName) { 249 DartType lookup(String typeName, {bool required}) {
250 DartType findIn(Uri uri) { 250 DartType findIn(Uri uri) {
251 LibraryEntity library = elementEnvironment.lookupLibrary(uri); 251 LibraryEntity library = elementEnvironment.lookupLibrary(uri);
252 if (library != null) { 252 if (library != null) {
253 ClassEntity cls = elementEnvironment.lookupClass(library, typeName); 253 ClassEntity cls = elementEnvironment.lookupClass(library, typeName);
254 if (cls != null) { 254 if (cls != null) {
255 // TODO(johnniwinther): Align semantics. 255 // TODO(johnniwinther): Align semantics.
256 return resolveAsRaw 256 return resolveAsRaw
257 ? elementEnvironment.getRawType(cls) 257 ? elementEnvironment.getRawType(cls)
258 : elementEnvironment.getThisType(cls); 258 : elementEnvironment.getThisType(cls);
259 } 259 }
260 } 260 }
261 return null; 261 return null;
262 } 262 }
263 263
264 DartType type = findIn(Uris.dart_core); 264 DartType type = findIn(Uris.dart_core);
265 type ??= findIn(BackendHelpers.DART_JS_HELPER); 265 type ??= findIn(BackendHelpers.DART_JS_HELPER);
266 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); 266 type ??= findIn(BackendHelpers.DART_INTERCEPTORS);
267 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); 267 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER);
268 type ??= findIn(Uris.dart_collection); 268 type ??= findIn(Uris.dart_collection);
269 type ??= findIn(Uris.dart_html); 269 type ??= findIn(Uris.dart_html);
270 type ??= findIn(Uris.dart_svg); 270 type ??= findIn(Uris.dart_svg);
271 type ??= findIn(Uris.dart_web_audio); 271 type ??= findIn(Uris.dart_web_audio);
272 type ??= findIn(Uris.dart_web_gl); 272 type ??= findIn(Uris.dart_web_gl);
273 if (type == null && required) {
274 reporter.reportErrorMessage(CURRENT_ELEMENT_SPANNABLE,
275 MessageKind.GENERIC, {'text': "Type '$typeName' not found."});
276 }
273 return type; 277 return type;
274 }; 278 }
279
280 return lookup;
275 } 281 }
276 282
277 String _getStringArgument(ir.StaticInvocation node, int index) { 283 String _getStringArgument(ir.StaticInvocation node, int index) {
278 return node.arguments.positional[index].accept(new Stringifier()); 284 return node.arguments.positional[index].accept(new Stringifier());
279 } 285 }
280 286
281 /// Computes the [native.NativeBehavior] for a call to the [JS] function. 287 /// Computes the [native.NativeBehavior] for a call to the [JS] function.
282 // TODO(johnniwinther): Cache this for later use. 288 // TODO(johnniwinther): Cache this for later use.
283 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node) { 289 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node) {
284 if (node.arguments.positional.length < 2 || 290 if (node.arguments.positional.length < 2 ||
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 568 }
563 if (isRedirecting) { 569 if (isRedirecting) {
564 return new RedirectingGenerativeConstantConstructor( 570 return new RedirectingGenerativeConstantConstructor(
565 defaultValues, superConstructorInvocation); 571 defaultValues, superConstructorInvocation);
566 } else { 572 } else {
567 return new GenerativeConstantConstructor( 573 return new GenerativeConstantConstructor(
568 type, defaultValues, fieldMap, superConstructorInvocation); 574 type, defaultValues, fieldMap, superConstructorInvocation);
569 } 575 }
570 } 576 }
571 } 577 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend_serialization.dart ('k') | pkg/compiler/lib/src/kernel/world_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698