[tint][sem] Add more Declaration() methods

These are overloaded to return the appropriate AST node pointer, without the need for a dynamic cast.

Change-Id: I2134b2b98d505aa756c81ebcd6c060d07a585ba1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/174284
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/wgsl/sem/function_expression.cc b/src/tint/lang/wgsl/sem/function_expression.cc
index d20ab00..d033140 100644
--- a/src/tint/lang/wgsl/sem/function_expression.cc
+++ b/src/tint/lang/wgsl/sem/function_expression.cc
@@ -26,16 +26,21 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "src/tint/lang/wgsl/sem/function_expression.h"
+#include "src/tint/lang/wgsl/ast/identifier_expression.h"
 
 TINT_INSTANTIATE_TYPEINFO(tint::sem::FunctionExpression);
 
 namespace tint::sem {
 
-FunctionExpression::FunctionExpression(const ast::Expression* declaration,
+FunctionExpression::FunctionExpression(const ast::IdentifierExpression* declaration,
                                        const Statement* statement,
                                        const sem::Function* function)
     : Base(declaration, statement), function_(function) {}
 
 FunctionExpression::~FunctionExpression() = default;
 
+const ast::IdentifierExpression* FunctionExpression::Declaration() const {
+    return static_cast<const ast::IdentifierExpression*>(Base::Declaration());
+}
+
 }  // namespace tint::sem
diff --git a/src/tint/lang/wgsl/sem/function_expression.h b/src/tint/lang/wgsl/sem/function_expression.h
index 5b0625f..8e2c4de 100644
--- a/src/tint/lang/wgsl/sem/function_expression.h
+++ b/src/tint/lang/wgsl/sem/function_expression.h
@@ -31,6 +31,9 @@
 #include "src/tint/lang/wgsl/sem/expression.h"
 
 // Forward declarations
+namespace tint::ast {
+class IdentifierExpression;
+}  // namespace tint::ast
 namespace tint::sem {
 class Function;
 }  // namespace tint::sem
@@ -45,13 +48,16 @@
     /// @param declaration the AST node
     /// @param statement the statement that owns this expression
     /// @param function the function that the expression resolved to
-    FunctionExpression(const ast::Expression* declaration,
+    FunctionExpression(const ast::IdentifierExpression* declaration,
                        const Statement* statement,
                        const sem::Function* function);
 
     /// Destructor
     ~FunctionExpression() override;
 
+    /// @returns the AST node
+    const ast::IdentifierExpression* Declaration() const;
+
     /// @return the function that the expression resolved to
     const sem::Function* Function() const { return function_; }
 
diff --git a/src/tint/lang/wgsl/sem/member_accessor_expression.cc b/src/tint/lang/wgsl/sem/member_accessor_expression.cc
index 68bcd7a..8a10ac1 100644
--- a/src/tint/lang/wgsl/sem/member_accessor_expression.cc
+++ b/src/tint/lang/wgsl/sem/member_accessor_expression.cc
@@ -48,6 +48,10 @@
 
 MemberAccessorExpression::~MemberAccessorExpression() = default;
 
+const ast::MemberAccessorExpression* MemberAccessorExpression::Declaration() const {
+    return static_cast<const ast::MemberAccessorExpression*>(declaration_);
+}
+
 StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* declaration,
                                        const core::type::Type* type,
                                        const Statement* statement,
diff --git a/src/tint/lang/wgsl/sem/member_accessor_expression.h b/src/tint/lang/wgsl/sem/member_accessor_expression.h
index 67dcf08..bb6f388 100644
--- a/src/tint/lang/wgsl/sem/member_accessor_expression.h
+++ b/src/tint/lang/wgsl/sem/member_accessor_expression.h
@@ -48,6 +48,9 @@
     /// Destructor
     ~MemberAccessorExpression() override;
 
+    /// @returns the AST node
+    const ast::MemberAccessorExpression* Declaration() const;
+
   protected:
     /// Constructor
     /// @param declaration the AST node
diff --git a/src/tint/lang/wgsl/sem/variable.cc b/src/tint/lang/wgsl/sem/variable.cc
index 9d5e1b2..e056c77 100644
--- a/src/tint/lang/wgsl/sem/variable.cc
+++ b/src/tint/lang/wgsl/sem/variable.cc
@@ -94,4 +94,8 @@
 
 VariableUser::~VariableUser() = default;
 
+const ast::IdentifierExpression* VariableUser::Declaration() const {
+    return static_cast<const ast::IdentifierExpression*>(Base::Declaration());
+}
+
 }  // namespace tint::sem
diff --git a/src/tint/lang/wgsl/sem/variable.h b/src/tint/lang/wgsl/sem/variable.h
index 9809fcb..15ca981 100644
--- a/src/tint/lang/wgsl/sem/variable.h
+++ b/src/tint/lang/wgsl/sem/variable.h
@@ -292,6 +292,9 @@
                  sem::Variable* variable);
     ~VariableUser() override;
 
+    /// @returns the AST node
+    const ast::IdentifierExpression* Declaration() const;
+
     /// @returns the variable that this expression refers to
     const sem::Variable* Variable() const { return variable_; }