[messages] Only populate analyzerCodes for shared messages.

The `Code.analyzerCodes` field is only used for error codes that are
shared between the analyzer and the CFE. Error codes that are
generated into to `pkg/front_end` don't need them.

This paves the way for a follow-up CL in which I intend to change the
`analyzerCodes` field to an enum. It will avoid the need to put
unnecessary entries in the enum.

Change-Id: I6a6a69642d1ce012ebaf8fcc5ba11db8dc1b2535
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449722
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Paul Berry
2025-09-17 14:31:07 -07:00
committed by Commit Queue
parent fcb1e9da9d
commit d874ad2ed5
2 changed files with 10 additions and 300 deletions
File diff suppressed because it is too large Load Diff
+10 -3
View File
@@ -89,18 +89,21 @@ part of 'cfe_codes.dart';
}
}
}
var forFeAnalyzerShared =
errorCodeInfo is SharedErrorCodeInfo ||
errorCodeInfo is FrontEndErrorCodeInfo && errorCodeInfo.pseudoShared;
String template;
try {
template = _TemplateCompiler(
name: name,
index: index,
errorCodeInfo: errorCodeInfo,
forFeAnalyzerShared: forFeAnalyzerShared,
).compile();
} catch (e, st) {
Error.throwWithStackTrace('Error while compiling $name: $e', st);
}
if (errorCodeInfo is SharedErrorCodeInfo ||
errorCodeInfo is FrontEndErrorCodeInfo && errorCodeInfo.pseudoShared) {
if (forFeAnalyzerShared) {
sharedMessages.writeln(template);
} else {
cfeMessages.writeln(template);
@@ -154,6 +157,9 @@ class _TemplateCompiler {
final String? severity;
final Map<String, ErrorCodeParameter> parameters;
/// Whether the template will be generated into `pkg/_fe_analyzer_shared`.
final bool forFeAnalyzerShared;
late final Set<String> usedNames = {
'conversions',
'labeler',
@@ -170,6 +176,7 @@ class _TemplateCompiler {
required this.name,
required this.index,
required CfeStyleErrorCodeInfo errorCodeInfo,
required this.forFeAnalyzerShared,
}) : problemMessage = errorCodeInfo.problemMessage,
correctionMessage = errorCodeInfo.correctionMessage,
analyzerCodes = errorCodeInfo.analyzerCodes,
@@ -180,7 +187,7 @@ class _TemplateCompiler {
var codeArguments = <String>[
if (index != null)
'index: $index'
else if (analyzerCodes.isNotEmpty)
else if (forFeAnalyzerShared && analyzerCodes.isNotEmpty)
// If "index:" is defined, then "analyzerCode:" should not be generated
// in the front end. See comment in messages.yaml
'analyzerCodes: <String>["${analyzerCodes.join('", "')}"]',