Add Forest method to access the name of a variable declaration

Change-Id: I2c24961573887ea56b0a09152c8926b3445e6c01
Reviewed-on: https://dart-review.googlesource.com/57006
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2018-05-30 13:46:23 +00:00 committed by commit-bot@chromium.org
parent 3b86f823d0
commit 13987b073d
4 changed files with 16 additions and 3 deletions

View file

@ -247,6 +247,11 @@ class AstBuildingForest
int getTypeCount(TypeArgumentList typeArguments) =>
typeArguments.arguments.length;
@override
String getVariableDeclarationName(VariableDeclaration declaration) {
return declaration.name.name;
}
@override
Statement ifStatement(
Token ifKeyword,

View file

@ -358,8 +358,8 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
}
}
void declareVariable(VariableDeclaration variable, Scope scope) {
String name = variable.name;
void declareVariable(Object variable, Scope scope) {
String name = forest.getVariableDeclarationName(variable);
Builder existing = scope.local[name];
if (existing != null) {
// This reports an error for duplicated declarations in the same scope:
@ -373,7 +373,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
return;
}
LocatedMessage context = scope.declare(
variable.name,
forest.getVariableDeclarationName(variable),
new KernelVariableBuilder(
variable, member ?? classBuilder ?? library, uri),
uri);

View file

@ -545,6 +545,11 @@ class Fangorn extends Forest<Expression, Statement, Token, Arguments> {
@override
int getLabelOffset(Label label) => label.charOffset;
@override
String getVariableDeclarationName(VariableDeclaration declaration) {
return declaration.name;
}
@override
bool isBlock(Object node) => node is Block;

View file

@ -322,6 +322,9 @@ abstract class Forest<Expression, Statement, Location, Arguments> {
/// Return the offset of the given [label].
int getLabelOffset(covariant label);
/// Return the name of the given variable [declaration].
String getVariableDeclarationName(covariant declaration);
bool isBlock(Object node);
/// Return `true` if the given [statement] is the representation of an empty