Files
sdk/pkg/kernel/lib/text/debug_printer.dart
T
Johnni Winther e30cd0322c [cfe][Contexts] Split VariableDeclaration and VariableStatement
This separates VariableDeclaration from Statement. VariableDeclaration no longer implements Statement and variable declared in a block or in a for-statement are now wrapped by a VariableStatement.

Currently there are two VariableStatement implementations; LegacyVariableStatement for variables in the current model, called LegacyVariable, and VariableInitialization for variables used in the new, still experimental, encoding that supports scope computation.

This CL is a step towards realigning the AST nodes to the new model in which each kind of variable has its own distinct subclass. (LocalVariable, PositionalParameter, NamedParameter, SyntheticVariable, etc.)

Note that it is not the intent to use VariableStatement in ForStatement going forward but that will be handled in a follow-up.

TEST=existing.

Change-Id: I5b309cd62c9b138f95b74fb054686edffa49a393
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502681
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-05-18 05:49:28 -07:00

114 lines
3.0 KiB
Dart

// Copyright (c) 2016, 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.
/// Helper for debug Kernel nodes.
library kernel.debug;
import 'package:kernel/ast.dart';
import 'indentation.dart' show Indentation, Tagging;
class DebugPrinter extends VisitorDefault<void>
with Indentation, Tagging<Node>, VisitorVoidMixin {
@override
StringBuffer sb = new StringBuffer();
void visitNodeWithChildren(Node node, String type, [Map? params]) {
openNode(node, type, params);
node.visitChildren(this);
closeNode();
}
@override
void defaultNode(Node node) {
visitNodeWithChildren(node, '${node.runtimeType}');
}
@override
void visitName(Name node) {
openAndCloseNode(node, '${node.runtimeType}', {
'name': node.text,
'library': node.library?.name,
});
}
@override
void visitIntLiteral(IntLiteral node) {
openAndCloseNode(node, '${node.runtimeType}', {'value': '${node.value}'});
}
@override
void visitVariableGet(VariableGet node) {
openAndCloseNode(node, '${node.runtimeType}', {
'variable': '${node.variable}',
});
}
@override
void visitStaticGet(StaticGet node) {
openAndCloseNode(node, '${node.runtimeType}', {'target': '${node.target}'});
}
@override
void visitStaticInvocation(StaticInvocation node) {
openNode(node, '${node.runtimeType}', {'target': '${node.target}'});
node.visitChildren(this);
closeNode();
}
@override
void visitArguments(Arguments node) {
openNode(node, '${node.runtimeType}', {
'typeArgs': '${node.types}',
'positionalArgs': '${node.positional}',
'namedArgs': '${node.named}',
});
node.visitChildren(this);
closeNode();
}
@override
void visitAsExpression(AsExpression node) {
openNode(node, '${node.runtimeType}', {
'operand': '${node.operand}',
'DartType': '${node.type}',
});
node.visitChildren(this);
closeNode();
}
@override
void visitStringLiteral(StringLiteral node) {
openAndCloseNode(node, '${node.runtimeType}', {'value': '${node.value}'});
}
@override
void defaultVariableDeclaration(VariableDeclaration node) {
openNode(node, '${node.runtimeType}', {
'name': '${node.name ?? '--unnamed--'}',
'isFinal': '${node.isFinal}',
'isConst': '${node.isConst}',
'isInitializingFormal': '${node.isInitializingFormal}',
'isSuperInitializingFormal': '${node.isSuperInitializingFormal}',
});
node.visitChildren(this);
closeNode();
}
@override
void visitInterfaceType(InterfaceType node) {
openNode(node, '${node.runtimeType}', {'name': '${node.classNode.name}'});
node.visitChildren(this);
closeNode();
}
/// Pretty-prints given node tree into string.
static String prettyPrint(Node node) {
DebugPrinter p = new DebugPrinter();
node.accept(p);
return p.sb.toString();
}
}