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

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

Issue 2104843002: Handle fields with initializers in constant constructors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix invariants. Created 4 years, 5 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.resolution; 5 library dart2js.resolution;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show Identifiers; 10 import '../common/names.dart' show Identifiers;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 import '../tree/tree.dart'; 46 import '../tree/tree.dart';
47 import '../universe/call_structure.dart' show CallStructure; 47 import '../universe/call_structure.dart' show CallStructure;
48 import '../universe/use.dart' show StaticUse, TypeUse; 48 import '../universe/use.dart' show StaticUse, TypeUse;
49 import '../universe/world_impact.dart' show WorldImpact; 49 import '../universe/world_impact.dart' show WorldImpact;
50 import '../util/util.dart' show Link, Setlet; 50 import '../util/util.dart' show Link, Setlet;
51 import 'class_hierarchy.dart'; 51 import 'class_hierarchy.dart';
52 import 'class_members.dart' show MembersCreator; 52 import 'class_members.dart' show MembersCreator;
53 import 'constructors.dart'; 53 import 'constructors.dart';
54 import 'members.dart'; 54 import 'members.dart';
55 import 'registry.dart'; 55 import 'registry.dart';
56 import 'resolution_result.dart';
56 import 'scope.dart' show MutableScope; 57 import 'scope.dart' show MutableScope;
57 import 'signatures.dart'; 58 import 'signatures.dart';
58 import 'tree_elements.dart'; 59 import 'tree_elements.dart';
59 import 'typedefs.dart'; 60 import 'typedefs.dart';
60 61
61 class ResolverTask extends CompilerTask { 62 class ResolverTask extends CompilerTask {
62 final ConstantCompiler constantCompiler; 63 final ConstantCompiler constantCompiler;
63 final Compiler compiler; 64 final Compiler compiler;
64 65
65 ResolverTask(Compiler compiler, this.constantCompiler) 66 ResolverTask(Compiler compiler, this.constantCompiler)
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // happens for enum fields where the type is known but is not in the 381 // happens for enum fields where the type is known but is not in the
381 // synthesized AST. 382 // synthesized AST.
382 element.variables.type = const DynamicType(); 383 element.variables.type = const DynamicType();
383 } 384 }
384 385
385 Expression initializer = element.initializer; 386 Expression initializer = element.initializer;
386 Modifiers modifiers = element.modifiers; 387 Modifiers modifiers = element.modifiers;
387 if (initializer != null) { 388 if (initializer != null) {
388 // TODO(johnniwinther): Avoid analyzing initializers if 389 // TODO(johnniwinther): Avoid analyzing initializers if
389 // [Compiler.analyzeSignaturesOnly] is set. 390 // [Compiler.analyzeSignaturesOnly] is set.
390 visitor.visit(initializer); 391 ResolutionResult result = visitor.visit(initializer);
392 if (result.isConstant) {
393 element.constant = result.constant;
394 }
391 } else if (modifiers.isConst) { 395 } else if (modifiers.isConst) {
392 reporter.reportErrorMessage( 396 reporter.reportErrorMessage(
393 element, MessageKind.CONST_WITHOUT_INITIALIZER); 397 element, MessageKind.CONST_WITHOUT_INITIALIZER);
394 } else if (modifiers.isFinal && !element.isInstanceMember) { 398 } else if (modifiers.isFinal && !element.isInstanceMember) {
395 reporter.reportErrorMessage( 399 reporter.reportErrorMessage(
396 element, MessageKind.FINAL_WITHOUT_INITIALIZER); 400 element, MessageKind.FINAL_WITHOUT_INITIALIZER);
397 } else { 401 } else {
398 // TODO(johnniwinther): Register a feature instead. 402 // TODO(johnniwinther): Register a feature instead.
399 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.nullType)); 403 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.nullType));
400 } 404 }
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 TreeElements get treeElements { 1127 TreeElements get treeElements {
1124 assert(invariant(this, _treeElements != null, 1128 assert(invariant(this, _treeElements != null,
1125 message: "TreeElements have not been computed for $this.")); 1129 message: "TreeElements have not been computed for $this."));
1126 return _treeElements; 1130 return _treeElements;
1127 } 1131 }
1128 1132
1129 void reuseElement() { 1133 void reuseElement() {
1130 _treeElements = null; 1134 _treeElements = null;
1131 } 1135 }
1132 } 1136 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/constructors.dart ('k') | tests/compiler/dart2js/constant_expression_evaluate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698