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

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

Issue 1520293002: Add token invariant to DiagnosticReporter (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebase + status update Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.constructors; 5 library dart2js.resolution.constructors;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart' show 8 import '../common/resolution.dart' show
9 Feature; 9 Feature;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 DiagnosticReporter get reporter => visitor.reporter; 60 DiagnosticReporter get reporter => visitor.reporter;
61 61
62 bool isFieldInitializer(SendSet node) { 62 bool isFieldInitializer(SendSet node) {
63 if (node.selector.asIdentifier() == null) return false; 63 if (node.selector.asIdentifier() == null) return false;
64 if (node.receiver == null) return true; 64 if (node.receiver == null) return true;
65 if (node.receiver.asIdentifier() == null) return false; 65 if (node.receiver.asIdentifier() == null) return false;
66 return node.receiver.asIdentifier().isThis(); 66 return node.receiver.asIdentifier().isThis();
67 } 67 }
68 68
69 reportDuplicateInitializerError(Element field, Node init, Node existing) { 69 reportDuplicateInitializerError(Element field,
70 Node init,
71 Spannable existing) {
70 reporter.reportError( 72 reporter.reportError(
71 reporter.createMessage( 73 reporter.createMessage(
72 init, 74 init,
73 MessageKind.DUPLICATE_INITIALIZER, 75 MessageKind.DUPLICATE_INITIALIZER,
74 {'fieldName': field.name}), 76 {'fieldName': field.name}),
75 <DiagnosticMessage>[ 77 <DiagnosticMessage>[
76 reporter.createMessage( 78 reporter.createMessage(
77 existing, 79 existing,
78 MessageKind.ALREADY_INITIALIZED, 80 MessageKind.ALREADY_INITIALIZED,
79 {'fieldName': field.name}), 81 {'fieldName': field.name}),
80 ]); 82 ]);
81 isValidAsConstant = false; 83 isValidAsConstant = false;
82 } 84 }
83 85
84 void checkForDuplicateInitializers(FieldElementX field, Node init) { 86 void checkForDuplicateInitializers(FieldElementX field, Node init) {
85 // [field] can be null if it could not be resolved. 87 // [field] can be null if it could not be resolved.
86 if (field == null) return; 88 if (field == null) return;
87 if (initialized.containsKey(field)) { 89 if (initialized.containsKey(field)) {
88 reportDuplicateInitializerError(field, init, initialized[field]); 90 reportDuplicateInitializerError(field, init, initialized[field]);
89 } else if (field.isFinal) { 91 } else if (field.isFinal) {
90 field.parseNode(visitor.resolution.parsing); 92 field.parseNode(visitor.resolution.parsing);
91 Expression initializer = field.initializer; 93 Expression initializer = field.initializer;
92 if (initializer != null) { 94 if (initializer != null) {
93 reportDuplicateInitializerError(field, init, initializer); 95 reportDuplicateInitializerError(field, init,
96 reporter.withCurrentElement(field,
97 () => reporter.spanFromSpannable(initializer)));
94 } 98 }
95 } 99 }
96 initialized[field] = init; 100 initialized[field] = init;
97 } 101 }
98 102
99 void resolveFieldInitializer(SendSet init) { 103 void resolveFieldInitializer(SendSet init) {
100 // init is of the form [this.]field = value. 104 // init is of the form [this.]field = value.
101 final Node selector = init.selector; 105 final Node selector = init.selector;
102 final String name = selector.asIdentifier().source; 106 final String name = selector.asIdentifier().source;
103 // Lookup target field. 107 // Lookup target field.
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 // constructors. 871 // constructors.
868 return null; 872 return null;
869 } 873 }
870 // TODO(johnniwinther): Use [Name] for lookup. 874 // TODO(johnniwinther): Use [Name] for lookup.
871 ConstructorElement constructor = cls.lookupConstructor(constructorName); 875 ConstructorElement constructor = cls.lookupConstructor(constructorName);
872 if (constructor != null) { 876 if (constructor != null) {
873 constructor = constructor.declaration; 877 constructor = constructor.declaration;
874 } 878 }
875 return constructor; 879 return constructor;
876 } 880 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/invariant.dart ('k') | pkg/compiler/lib/src/resolution/enum_creator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698