tint: Unkeyword 'var' template args

Change the address space and access mode in ast::Var from enums
to Expressions. Have the resolver resolve these, like we do for
other template arguments.

As the AST nodes now have identifier expressions, the tint-internal
'in' and 'out' address spaces have been prefixed with underscores to
prevent input code from using this.

Change-Id: Ie8abf371ee6a7031613709b83b575d2723418fcf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120405
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc
index 16a3f8e..75e377f 100644
--- a/src/tint/resolver/dependency_graph.cc
+++ b/src/tint/resolver/dependency_graph.cc
@@ -183,13 +183,9 @@
                 Declare(func->name->symbol, func);
                 TraverseFunction(func);
             },
-            [&](const ast::Variable* var) {
-                Declare(var->name->symbol, var);
-                TraverseTypeExpression(var->type);
-                TraverseAttributes(var->attributes);
-                if (var->initializer) {
-                    TraverseValueExpression(var->initializer);
-                }
+            [&](const ast::Variable* v) {
+                Declare(v->name->symbol, v);
+                TraverseVariable(v);
             },
             [&](const ast::DiagnosticDirective*) {
                 // Diagnostic directives do not affect the dependency graph.
@@ -204,8 +200,18 @@
     }
 
   private:
-    /// Traverses the function, performing symbol resolution and determining
-    /// global dependencies.
+    /// Traverses the variable, performing symbol resolution.
+    void TraverseVariable(const ast::Variable* v) {
+        if (auto* var = v->As<ast::Var>()) {
+            TraverseAddressSpaceExpression(var->declared_address_space);
+            TraverseAccessExpression(var->declared_access);
+        }
+        TraverseTypeExpression(v->type);
+        TraverseAttributes(v->attributes);
+        TraverseValueExpression(v->initializer);
+    }
+
+    /// Traverses the function, performing symbol resolution and determining global dependencies.
     void TraverseFunction(const ast::Function* func) {
         TraverseAttributes(func->attributes);
         TraverseAttributes(func->return_type_attributes);
@@ -301,8 +307,7 @@
                 if (auto* shadows = scope_stack_.Get(v->variable->name->symbol)) {
                     graph_.shadows.Add(v->variable, shadows);
                 }
-                TraverseTypeExpression(v->variable->type);
-                TraverseValueExpression(v->variable->initializer);
+                TraverseVariable(v->variable);
                 Declare(v->variable->name->symbol, v->variable);
             },
             [&](const ast::WhileStatement* w) {
@@ -345,6 +350,18 @@
         TraverseExpression(root, "type", "references");
     }
 
+    /// Traverses the expression @p root_expr for the intended use as an address space, performing
+    /// symbol resolution and determining global dependencies.
+    void TraverseAddressSpaceExpression(const ast::Expression* root) {
+        TraverseExpression(root, "address space", "references");
+    }
+
+    /// Traverses the expression @p root_expr for the intended use as an access, performing symbol
+    /// resolution and determining global dependencies.
+    void TraverseAccessExpression(const ast::Expression* root) {
+        TraverseExpression(root, "access", "references");
+    }
+
     /// Traverses the expression @p root_expr for the intended use as a call target, performing
     /// symbol resolution and determining global dependencies.
     void TraverseCallableExpression(const ast::Expression* root) {