mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[cfe] Add preamble to visitor generators
Change-Id: I3d0e873f7e4b03e107cb713ec375e0078e2de1a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211002 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
ae81cd5dab
commit
6ee9cd0df1
4 changed files with 38 additions and 9 deletions
|
@ -29,6 +29,10 @@ Future<String> generateAstCoverage(Uri repoDir, [AstModel astModel]) async {
|
|||
class CoverageVisitorStrategy extends Visitor0Strategy {
|
||||
Map<String, Set<String>> nestedClassNames = {};
|
||||
|
||||
@override
|
||||
String get generatorCommand =>
|
||||
'dart pkg/front_end/tool/generate_ast_coverage.dart';
|
||||
|
||||
@override
|
||||
String get returnType => 'void';
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ class EquivalenceVisitorStrategy extends Visitor1Strategy {
|
|||
|
||||
EquivalenceVisitorStrategy();
|
||||
|
||||
@override
|
||||
String get generatorCommand =>
|
||||
'dart pkg/front_end/tool/generate_ast_equivalence.dart';
|
||||
|
||||
@override
|
||||
String get argumentType => 'Node';
|
||||
|
||||
|
@ -414,13 +418,7 @@ class EquivalenceVisitorStrategy extends Visitor1Strategy {
|
|||
|
||||
void generateHeader(AstModel astModel, StringBuffer sb) {
|
||||
sb.writeln('''
|
||||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Run 'dart pkg/front_end/tool/generate_ast_equivalence.dart' to update.
|
||||
$preamble
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
import 'package:kernel/src/printer.dart';
|
||||
|
|
|
@ -84,6 +84,23 @@ String generateVisitor(AstModel astModel, VisitorStrategy strategy,
|
|||
abstract class VisitorStrategy {
|
||||
const VisitorStrategy();
|
||||
|
||||
/// Preamble comment used in the generated file.
|
||||
String get preamble => '''
|
||||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Run '$generatorCommand' to update.
|
||||
''';
|
||||
|
||||
/// The command used to generate the visitor.
|
||||
///
|
||||
/// This is inserted in the [preamble] along with a comment that the file
|
||||
/// is generated.
|
||||
String get generatorCommand;
|
||||
|
||||
/// Comment used as doc comment for the generated visitor class.
|
||||
String get visitorComment => '';
|
||||
|
||||
|
@ -128,6 +145,8 @@ abstract class Visitor0Strategy extends VisitorStrategy {
|
|||
|
||||
void generateHeader(AstModel astModel, StringBuffer sb) {
|
||||
sb.writeln('''
|
||||
$preamble
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
||||
$visitorComment
|
||||
|
@ -199,7 +218,7 @@ class $visitorName$visitorTypeParameters implements Visitor<$returnType> {''');
|
|||
}
|
||||
|
||||
/// Strategy for creating an empty `Visitor<void>` implementation.
|
||||
class VoidVisitor0Strategy extends Visitor0Strategy {
|
||||
abstract class VoidVisitor0Strategy extends Visitor0Strategy {
|
||||
const VoidVisitor0Strategy();
|
||||
|
||||
@override
|
||||
|
@ -312,7 +331,7 @@ class $visitorName$visitorTypeParameters
|
|||
}
|
||||
|
||||
/// Strategy for creating an empty `Visitor1<void,Null>` implementation.
|
||||
class VoidVisitor1Strategy extends Visitor1Strategy {
|
||||
abstract class VoidVisitor1Strategy extends Visitor1Strategy {
|
||||
const VoidVisitor1Strategy();
|
||||
|
||||
@override
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Run 'dart pkg/front_end/tool/generate_ast_coverage.dart' to update.
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
||||
/// Recursive visitor that collects kinds for all visited nodes.
|
||||
|
|
Loading…
Reference in a new issue