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

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

Issue 2686243004: Handler the last native annotations (Closed)
Patch Set: Cleanup. 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Selector getSetterSelector(ir.Name irName) { 196 Selector getSetterSelector(ir.Name irName) {
197 Name name = new Name( 197 Name name = new Name(
198 irName.name, irName.isPrivate ? getLibrary(irName.library) : null); 198 irName.name, irName.isPrivate ? getLibrary(irName.library) : null);
199 return new Selector.setter(name); 199 return new Selector.setter(name);
200 } 200 }
201 201
202 /// Converts [annotations] into a list of [ConstantExpression]s. 202 /// Converts [annotations] into a list of [ConstantExpression]s.
203 List<ConstantExpression> getMetadata(List<ir.Expression> annotations) { 203 List<ConstantExpression> getMetadata(List<ir.Expression> annotations) {
204 List<ConstantExpression> metadata = <ConstantExpression>[]; 204 List<ConstantExpression> metadata = <ConstantExpression>[];
205 annotations.forEach((ir.Expression node) { 205 annotations.forEach((ir.Expression node) {
206 ConstantExpression constant = node.accept(new Constantifier(this)); 206 ConstantExpression constant = new Constantifier(this).visit(node);
207 if (constant == null) { 207 if (constant == null) {
208 throw new UnsupportedError( 208 throw new UnsupportedError(
209 'No constant for ${DebugPrinter.prettyPrint(node)}'); 209 'No constant for ${DebugPrinter.prettyPrint(node)}');
210 } 210 }
211 metadata.add(constant); 211 metadata.add(constant);
212 }); 212 });
213 return metadata; 213 return metadata;
214 } 214 }
215 215
216 /// Returns `true` is [node] has a `@Native(...)` annotation. 216 /// Returns `true` is [node] has a `@Native(...)` annotation.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 : elementEnvironment.getThisType(cls); 266 : elementEnvironment.getThisType(cls);
267 } 267 }
268 } 268 }
269 return null; 269 return null;
270 } 270 }
271 271
272 DartType type = findIn(Uris.dart_core); 272 DartType type = findIn(Uris.dart_core);
273 type ??= findIn(BackendHelpers.DART_JS_HELPER); 273 type ??= findIn(BackendHelpers.DART_JS_HELPER);
274 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); 274 type ??= findIn(BackendHelpers.DART_INTERCEPTORS);
275 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); 275 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER);
276 type ??= findIn(Uris.dart__native_typed_data);
276 type ??= findIn(Uris.dart_collection); 277 type ??= findIn(Uris.dart_collection);
278 type ??= findIn(Uris.dart_math);
277 type ??= findIn(Uris.dart_html); 279 type ??= findIn(Uris.dart_html);
280 type ??= findIn(Uris.dart_html_common);
278 type ??= findIn(Uris.dart_svg); 281 type ??= findIn(Uris.dart_svg);
279 type ??= findIn(Uris.dart_web_audio); 282 type ??= findIn(Uris.dart_web_audio);
280 type ??= findIn(Uris.dart_web_gl); 283 type ??= findIn(Uris.dart_web_gl);
284 type ??= findIn(Uris.dart_web_sql);
Siggi Cherem (dart-lang) 2017/02/10 23:00:54 It would be nice if we could make the sequence of
Johnni Winther 2017/02/12 09:51:49 Add a TODO.
285 type ??= findIn(Uris.dart_indexed_db);
286 type ??= findIn(Uris.dart_typed_data);
281 if (type == null && required) { 287 if (type == null && required) {
282 reporter.reportErrorMessage(CURRENT_ELEMENT_SPANNABLE, 288 reporter.reportErrorMessage(CURRENT_ELEMENT_SPANNABLE,
283 MessageKind.GENERIC, {'text': "Type '$typeName' not found."}); 289 MessageKind.GENERIC, {'text': "Type '$typeName' not found."});
284 } 290 }
285 return type; 291 return type;
286 } 292 }
287 293
288 return lookup; 294 return lookup;
289 } 295 }
290 296
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (value == null) return null; 453 if (value == null) return null;
448 sb.write(value); 454 sb.write(value);
449 } 455 }
450 return sb.toString(); 456 return sb.toString();
451 } 457 }
452 } 458 }
453 459
454 /// Visitor that converts a kernel constant expression into a 460 /// Visitor that converts a kernel constant expression into a
455 /// [ConstantExpression]. 461 /// [ConstantExpression].
456 class Constantifier extends ir.ExpressionVisitor<ConstantExpression> { 462 class Constantifier extends ir.ExpressionVisitor<ConstantExpression> {
463 final bool requireConstant;
457 final KernelElementAdapter elementAdapter; 464 final KernelElementAdapter elementAdapter;
458 465
459 Constantifier(this.elementAdapter); 466 Constantifier(this.elementAdapter, {this.requireConstant: true});
467
468 ConstantExpression visit(ir.Expression node) {
469 ConstantExpression constant = node.accept(this);
470 if (constant == null && requireConstant) {
471 throw new UnsupportedError(
472 "No constant computed for $node (${node.runtimeType})");
473 }
474 return constant;
475 }
460 476
461 ConstantExpression defaultExpression(ir.Expression node) { 477 ConstantExpression defaultExpression(ir.Expression node) {
462 throw new UnimplementedError( 478 throw new UnimplementedError(
463 'Unimplemented constant expression $node (${node.runtimeType})'); 479 'Unimplemented constant expression $node (${node.runtimeType})');
464 } 480 }
465 481
466 List<ConstantExpression> _computeList(List<ir.Expression> expressions) { 482 List<ConstantExpression> _computeList(List<ir.Expression> expressions) {
467 List<ConstantExpression> list = <ConstantExpression>[]; 483 List<ConstantExpression> list = <ConstantExpression>[];
468 for (ir.Expression expression in expressions) { 484 for (ir.Expression expression in expressions) {
469 ConstantExpression constant = expression.accept(this); 485 ConstantExpression constant = visit(expression);
470 if (constant == null) return null; 486 if (constant == null) return null;
471 list.add(constant); 487 list.add(constant);
472 } 488 }
473 return list; 489 return list;
474 } 490 }
475 491
476 List<ConstantExpression> _computeArguments(ir.Arguments node) { 492 List<ConstantExpression> _computeArguments(ir.Arguments node) {
477 List<ConstantExpression> arguments = <ConstantExpression>[]; 493 List<ConstantExpression> arguments = <ConstantExpression>[];
478 for (ir.Expression argument in node.positional) { 494 for (ir.Expression argument in node.positional) {
479 ConstantExpression constant = argument.accept(this); 495 ConstantExpression constant = visit(argument);
480 if (constant == null) return null; 496 if (constant == null) return null;
481 arguments.add(constant); 497 arguments.add(constant);
482 } 498 }
483 for (ir.NamedExpression argument in node.named) { 499 for (ir.NamedExpression argument in node.named) {
484 ConstantExpression constant = argument.value.accept(this); 500 ConstantExpression constant = visit(argument.value);
485 if (constant == null) return null; 501 if (constant == null) return null;
486 arguments.add(constant); 502 arguments.add(constant);
487 } 503 }
488 return arguments; 504 return arguments;
489 } 505 }
490 506
491 ConstructedConstantExpression _computeConstructorInvocation( 507 ConstructedConstantExpression _computeConstructorInvocation(
492 ir.Constructor target, ir.Arguments arguments) { 508 ir.Constructor target, ir.Arguments arguments) {
493 return new ConstructedConstantExpression( 509 return new ConstructedConstantExpression(
494 elementAdapter.createInterfaceType( 510 elementAdapter.createInterfaceType(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 assert(node.isConst); 556 assert(node.isConst);
541 ir.Class cls = node.enclosingClass; 557 ir.Class cls = node.enclosingClass;
542 InterfaceType type = elementAdapter.elementEnvironment 558 InterfaceType type = elementAdapter.elementEnvironment
543 .getThisType(elementAdapter.getClass(cls)); 559 .getThisType(elementAdapter.getClass(cls));
544 560
545 Map<dynamic, ConstantExpression> defaultValues = 561 Map<dynamic, ConstantExpression> defaultValues =
546 <dynamic, ConstantExpression>{}; 562 <dynamic, ConstantExpression>{};
547 int parameterIndex = 0; 563 int parameterIndex = 0;
548 node.function.positionalParameters 564 node.function.positionalParameters
549 .forEach((ir.VariableDeclaration parameter) { 565 .forEach((ir.VariableDeclaration parameter) {
550 if (parameter.initializer != null) { 566 if (parameterIndex >= node.function.requiredParameterCount) {
551 defaultValues[parameterIndex] = parameter.initializer.accept(this); 567 if (parameter.initializer != null) {
568 defaultValues[parameterIndex] = parameter.initializer.accept(this);
569 } else {
570 defaultValues[parameterIndex] = new NullConstantExpression();
571 }
552 } 572 }
553 parameterIndex++; 573 parameterIndex++;
554 }); 574 });
555 node.function.namedParameters.forEach((ir.VariableDeclaration parameter) { 575 node.function.namedParameters.forEach((ir.VariableDeclaration parameter) {
556 defaultValues[parameter.name] = parameter.initializer.accept(this); 576 defaultValues[parameter.name] = parameter.initializer.accept(this);
557 }); 577 });
558 578
559 bool isRedirecting = node.initializers.length == 1 && 579 bool isRedirecting = node.initializers.length == 1 &&
560 node.initializers.single is ir.RedirectingInitializer; 580 node.initializers.single is ir.RedirectingInitializer;
561 581
(...skipping 29 matching lines...) Expand all
591 } 611 }
592 if (isRedirecting) { 612 if (isRedirecting) {
593 return new RedirectingGenerativeConstantConstructor( 613 return new RedirectingGenerativeConstantConstructor(
594 defaultValues, superConstructorInvocation); 614 defaultValues, superConstructorInvocation);
595 } else { 615 } else {
596 return new GenerativeConstantConstructor( 616 return new GenerativeConstantConstructor(
597 type, defaultValues, fieldMap, superConstructorInvocation); 617 type, defaultValues, fieldMap, superConstructorInvocation);
598 } 618 }
599 } 619 }
600 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698