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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_field_builder.dart

Issue 2938423003: Implement override-based inference of instance fields. (Closed)
Patch Set: Created 3 years, 6 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) 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.kernel_field_builder; 5 library fasta.kernel_field_builder;
6 6
7 import 'package:front_end/src/fasta/kernel/body_builder.dart' show BodyBuilder; 7 import 'package:front_end/src/fasta/kernel/body_builder.dart' show BodyBuilder;
8 8
9 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' 9 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'
10 show KernelField; 10 show KernelField;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ..fileOffset = charOffset, 50 ..fileOffset = charOffset,
51 super(name, modifiers, compilationUnit, charOffset); 51 super(name, modifiers, compilationUnit, charOffset);
52 52
53 void set initializer(Expression value) { 53 void set initializer(Expression value) {
54 if (!hasInitializer && value is! NullLiteral && !isConst && !isFinal) { 54 if (!hasInitializer && value is! NullLiteral && !isConst && !isFinal) {
55 internalError("Attempt to set initializer on field without initializer."); 55 internalError("Attempt to set initializer on field without initializer.");
56 } 56 }
57 field.initializer = value..parent = field; 57 field.initializer = value..parent = field;
58 } 58 }
59 59
60 bool get isEligibleForInference =>
61 type == null && (hasInitializer || isInstanceMember);
62
60 Field build(SourceLibraryBuilder library) { 63 Field build(SourceLibraryBuilder library) {
61 field.name ??= new Name(name, library.target); 64 field.name ??= new Name(name, library.target);
62 if (type != null) { 65 if (type != null) {
63 field.type = type.build(library); 66 field.type = type.build(library);
64 } 67 }
65 bool isInstanceMember = !isStatic && !isTopLevel; 68 bool isInstanceMember = !isStatic && !isTopLevel;
66 field 69 field
67 ..isFinal = isFinal 70 ..isFinal = isFinal
68 ..isConst = isConst 71 ..isConst = isConst
69 ..hasImplicitGetter = isInstanceMember 72 ..hasImplicitGetter = isInstanceMember
70 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal 73 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal
71 ..isStatic = !isInstanceMember; 74 ..isStatic = !isInstanceMember;
72 if (initializerTokenForInference != null && 75 if (isEligibleForInference) {
73 !initializerTokenForInference.isEof) {
74 assert(type == null);
75 library.loader.typeInferenceEngine.recordField(field); 76 library.loader.typeInferenceEngine.recordField(field);
76 } 77 }
77 return field; 78 return field;
78 } 79 }
79 80
80 Field get target => field; 81 Field get target => field;
81 82
82 @override 83 @override
83 void prepareInitializerInference( 84 void prepareInitializerInference(
84 SourceLibraryBuilder library, ClassBuilder currentClass) { 85 SourceLibraryBuilder library, ClassBuilder currentClass) {
85 if (initializerTokenForInference != null && 86 if (isEligibleForInference) {
86 !initializerTokenForInference.isEof) {
87 var memberScope = 87 var memberScope =
88 currentClass == null ? library.scope : currentClass.scope; 88 currentClass == null ? library.scope : currentClass.scope;
89 // TODO(paulberry): Is it correct to pass library.uri into BodyBuilder, or 89 // TODO(paulberry): Is it correct to pass library.uri into BodyBuilder, or
90 // should it be the part URI? 90 // should it be the part URI?
91 var typeInferenceEngine = library.loader.typeInferenceEngine; 91 var typeInferenceEngine = library.loader.typeInferenceEngine;
92 var listener = new TypeInferenceListener(); 92 var listener = new TypeInferenceListener();
93 var typeInferrer = typeInferenceEngine.createTopLevelTypeInferrer( 93 var typeInferrer = typeInferenceEngine.createTopLevelTypeInferrer(
94 listener, field.enclosingClass?.thisType, field); 94 listener, field.enclosingClass?.thisType, field);
95 var bodyBuilder = new BodyBuilder( 95 if (hasInitializer) {
96 library, 96 var bodyBuilder = new BodyBuilder(
97 this, 97 library,
98 memberScope, 98 this,
99 null, 99 memberScope,
100 typeInferenceEngine.classHierarchy, 100 null,
101 typeInferenceEngine.coreTypes, 101 typeInferenceEngine.classHierarchy,
102 currentClass, 102 typeInferenceEngine.coreTypes,
103 isInstanceMember, 103 currentClass,
104 library.uri, 104 isInstanceMember,
105 typeInferrer); 105 library.uri,
106 Parser parser = new Parser(bodyBuilder); 106 typeInferrer);
107 Token token = parser.parseExpression(initializerTokenForInference); 107 Parser parser = new Parser(bodyBuilder);
108 Expression expression = bodyBuilder.popForValue(); 108 Token token = parser.parseExpression(initializerTokenForInference);
109 bodyBuilder.checkEmpty(token.charOffset); 109 Expression expression = bodyBuilder.popForValue();
110 initializer = expression; 110 bodyBuilder.checkEmpty(token.charOffset);
111 initializer = expression;
112 }
111 } 113 }
112 } 114 }
113 115
114 @override 116 @override
115 DartType get builtType => field.type; 117 DartType get builtType => field.type;
116 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698