From 13987b073d65393a5c4135d55a8e64a8d87a6cd7 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Wed, 30 May 2018 13:46:23 +0000 Subject: [PATCH] Add Forest method to access the name of a variable declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2c24961573887ea56b0a09152c8926b3445e6c01 Reviewed-on: https://dart-review.googlesource.com/57006 Reviewed-by: Dan Rubel Reviewed-by: Peter von der Ahé Commit-Queue: Brian Wilkerson --- pkg/analyzer/lib/src/fasta/ast_building_factory.dart | 5 +++++ pkg/front_end/lib/src/fasta/kernel/body_builder.dart | 6 +++--- pkg/front_end/lib/src/fasta/kernel/fangorn.dart | 5 +++++ pkg/front_end/lib/src/fasta/kernel/forest.dart | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/analyzer/lib/src/fasta/ast_building_factory.dart b/pkg/analyzer/lib/src/fasta/ast_building_factory.dart index 1279ad1cd3d..91ec0fa7abb 100644 --- a/pkg/analyzer/lib/src/fasta/ast_building_factory.dart +++ b/pkg/analyzer/lib/src/fasta/ast_building_factory.dart @@ -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, diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index 86a9cf34ad5..2f2013a07ea 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -358,8 +358,8 @@ abstract class BodyBuilder } } - 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 return; } LocatedMessage context = scope.declare( - variable.name, + forest.getVariableDeclarationName(variable), new KernelVariableBuilder( variable, member ?? classBuilder ?? library, uri), uri); diff --git a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart index a5f104166d0..4c7808bd703 100644 --- a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart +++ b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart @@ -545,6 +545,11 @@ class Fangorn extends Forest { @override int getLabelOffset(Label label) => label.charOffset; + @override + String getVariableDeclarationName(VariableDeclaration declaration) { + return declaration.name; + } + @override bool isBlock(Object node) => node is Block; diff --git a/pkg/front_end/lib/src/fasta/kernel/forest.dart b/pkg/front_end/lib/src/fasta/kernel/forest.dart index b8b3ab39dac..f92f493cf82 100644 --- a/pkg/front_end/lib/src/fasta/kernel/forest.dart +++ b/pkg/front_end/lib/src/fasta/kernel/forest.dart @@ -322,6 +322,9 @@ abstract class Forest { /// 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