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

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

Issue 2467493003: Compute NativeBehavior for native methods and fields. (Closed)
Patch Set: Updated cf. comments Created 4 years, 1 month 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection' show Queue; 6 import 'dart:collection' show Queue;
7 7
8 import 'package:kernel/ast.dart' as ir; 8 import 'package:kernel/ast.dart' as ir;
9 import 'package:kernel/checks.dart' show CheckParentPointers; 9 import 'package:kernel/checks.dart' show CheckParentPointers;
10 10
11 import '../common.dart'; 11 import '../common.dart';
12 import '../common/names.dart'; 12 import '../common/names.dart';
13 import '../compiler.dart' show Compiler; 13 import '../compiler.dart' show Compiler;
14 import '../constants/expressions.dart' show TypeConstantExpression; 14 import '../constants/expressions.dart' show TypeConstantExpression;
15 import '../dart_types.dart' 15 import '../dart_types.dart'
16 show DartType, FunctionType, InterfaceType, TypeKind, TypeVariableType; 16 show DartType, FunctionType, InterfaceType, TypeKind, TypeVariableType;
17 import '../diagnostics/messages.dart' show MessageKind; 17 import '../diagnostics/messages.dart' show MessageKind;
18 import '../diagnostics/spannable.dart' show Spannable; 18 import '../diagnostics/spannable.dart' show Spannable;
19 import '../elements/elements.dart' 19 import '../elements/elements.dart'
20 show 20 show
21 ClassElement, 21 ClassElement,
22 ConstructorElement, 22 ConstructorElement,
23 Element, 23 Element,
24 ExportElement, 24 ExportElement,
25 FieldElement, 25 FieldElement,
26 FunctionElement, 26 FunctionElement,
27 ImportElement, 27 ImportElement,
28 LibraryElement, 28 LibraryElement,
29 LocalFunctionElement, 29 LocalFunctionElement,
30 MetadataAnnotation,
30 MixinApplicationElement, 31 MixinApplicationElement,
31 TypeVariableElement; 32 TypeVariableElement;
32 import '../elements/modelx.dart' show ErroneousFieldElementX; 33 import '../elements/modelx.dart' show ErroneousFieldElementX;
33 import '../tree/tree.dart' show FunctionExpression, Node; 34 import '../tree/tree.dart' show FunctionExpression, Node;
35 import 'constant_visitor.dart';
34 import 'kernel_visitor.dart' show IrFunction, KernelVisitor; 36 import 'kernel_visitor.dart' show IrFunction, KernelVisitor;
35 37
36 typedef void WorkAction(); 38 typedef void WorkAction();
37 39
38 class WorkItem { 40 class WorkItem {
39 final Element element; 41 final Element element;
40 final WorkAction action; 42 final WorkAction action;
41 43
42 WorkItem(this.element, this.action); 44 WorkItem(this.element, this.action);
43 } 45 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } else { 212 } else {
211 internalError(member, "Unhandled class member: $member"); 213 internalError(member, "Unhandled class member: $member");
212 } 214 }
213 }); 215 });
214 classNode.typeParameters.addAll(typeVariablesToIr(cls.typeVariables)); 216 classNode.typeParameters.addAll(typeVariablesToIr(cls.typeVariables));
215 for (ir.InterfaceType interface 217 for (ir.InterfaceType interface
216 in typesToIr(cls.interfaces.reverse().toList())) { 218 in typesToIr(cls.interfaces.reverse().toList())) {
217 classNode.implementedTypes.add(interface); 219 classNode.implementedTypes.add(interface);
218 } 220 }
219 }); 221 });
222 addWork(cls.declaration, () {
223 for (MetadataAnnotation metadata in cls.declaration.metadata) {
224 classNode.addAnnotation(
225 const ConstantVisitor().visit(metadata.constant, this));
226 }
227 });
220 return classNode; 228 return classNode;
221 }); 229 });
222 } 230 }
223 231
224 bool hasHierarchyProblem(ClassElement cls) => cls.hasIncompleteHierarchy; 232 bool hasHierarchyProblem(ClassElement cls) => cls.hasIncompleteHierarchy;
225 233
226 ir.InterfaceType interfaceTypeToIr(InterfaceType type) { 234 ir.InterfaceType interfaceTypeToIr(InterfaceType type) {
227 ir.Class cls = classToIr(type.element); 235 ir.Class cls = classToIr(type.element);
228 if (type.typeArguments.isEmpty) { 236 if (type.typeArguments.isEmpty) {
229 return cls.rawType; 237 return cls.rawType;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 procedure.function = irFunction.node; 392 procedure.function = irFunction.node;
385 procedure.kind = irFunction.kind; 393 procedure.kind = irFunction.kind;
386 } 394 }
387 endFactoryScope(function); 395 endFactoryScope(function);
388 member.transformerFlags = visitor.transformerFlags; 396 member.transformerFlags = visitor.transformerFlags;
389 assert(() { 397 assert(() {
390 visitor.locals.forEach(checkMember); 398 visitor.locals.forEach(checkMember);
391 return true; 399 return true;
392 }); 400 });
393 }); 401 });
402 addWork(function.declaration, () {
403 for (MetadataAnnotation metadata in function.declaration.metadata) {
404 member.addAnnotation(
405 const ConstantVisitor().visit(metadata.constant, this));
406 }
407 });
394 return member; 408 return member;
395 }); 409 });
396 } 410 }
397 411
398 /// Adds the type parameters of the enclosing class of [function] to 412 /// Adds the type parameters of the enclosing class of [function] to
399 /// [factoryTypeParameters]. This serves as a local scope for type variables 413 /// [factoryTypeParameters]. This serves as a local scope for type variables
400 /// resolved inside the factory. 414 /// resolved inside the factory.
401 /// 415 ///
402 /// This method solves the problem that a factory method really is a generic 416 /// This method solves the problem that a factory method really is a generic
403 /// method that has its own type parameters, one for each type parameter in 417 /// method that has its own type parameters, one for each type parameter in
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 isConst: field.isConst); 459 isConst: field.isConst);
446 addWork(field, () { 460 addWork(field, () {
447 setParent(fieldNode, field); 461 setParent(fieldNode, field);
448 if (!field.isMalformed && field.initializer != null) { 462 if (!field.isMalformed && field.initializer != null) {
449 KernelVisitor visitor = 463 KernelVisitor visitor =
450 new KernelVisitor(field, field.treeElements, this); 464 new KernelVisitor(field, field.treeElements, this);
451 fieldNode.initializer = visitor.buildInitializer() 465 fieldNode.initializer = visitor.buildInitializer()
452 ..parent = fieldNode; 466 ..parent = fieldNode;
453 } 467 }
454 }); 468 });
469 addWork(field.declaration, () {
470 for (MetadataAnnotation metadata in field.declaration.metadata) {
471 fieldNode.addAnnotation(
472 const ConstantVisitor().visit(metadata.constant, this));
473 }
474 });
455 return fieldNode; 475 return fieldNode;
456 }); 476 });
457 } 477 }
458 478
459 ir.TypeParameter typeVariableToIr(TypeVariableElement variable) { 479 ir.TypeParameter typeVariableToIr(TypeVariableElement variable) {
460 variable = variable.declaration; 480 variable = variable.declaration;
461 ir.TypeParameter parameter = factoryTypeParameters[variable]; 481 ir.TypeParameter parameter = factoryTypeParameters[variable];
462 if (parameter != null) return parameter; 482 if (parameter != null) return parameter;
463 return typeParameters.putIfAbsent(variable, () { 483 return typeParameters.putIfAbsent(variable, () {
464 ir.TypeParameter parameter = new ir.TypeParameter(variable.name, null); 484 ir.TypeParameter parameter = new ir.TypeParameter(variable.name, null);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 690 }
671 691
672 class ConstructorTarget { 692 class ConstructorTarget {
673 final ConstructorElement element; 693 final ConstructorElement element;
674 final DartType type; 694 final DartType type;
675 695
676 ConstructorTarget(this.element, this.type); 696 ConstructorTarget(this.element, this.type);
677 697
678 String toString() => "ConstructorTarget($element, $type)"; 698 String toString() => "ConstructorTarget($element, $type)";
679 } 699 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/constant_visitor.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698