[validation] Validates declaration name uniqueness

This CL adds implementations and tests for these validation rules:
v-0011: Global variable names must be unique
v-0013: Variables declared in a function must be unique between that function and any global variables.
v-0014: Variables declared in a function must have unique names

Bug: tint 6
Change-Id: I793485c981f67abc6a3dc81d35be743ccc18db5b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26480
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/scope_stack.h b/src/scope_stack.h
index 5e8b57e..f127c97 100644
--- a/src/scope_stack.h
+++ b/src/scope_stack.h
@@ -64,14 +64,27 @@
   /// @param ret where to place the name
   /// @returns true if the name was successfully found, false otherwise
   bool get(const std::string& name, T* ret) const {
+    return get(name, ret, nullptr);
+  }
+
+  /// Retrieves a given name from the stack
+  /// @param name the name to look for
+  /// @param ret where to place the name
+  /// @param is_global set true if the name references a global variable
+  /// otherwise unchanged
+  /// @returns true if the name was successfully found, false otherwise
+  bool get(const std::string& name, T* ret, bool* is_global) const {
     for (auto iter = stack_.rbegin(); iter != stack_.rend(); ++iter) {
       auto& map = *iter;
-
       auto val = map.find(name);
+
       if (val != map.end()) {
         if (ret) {
           *ret = val->second;
         }
+        if (is_global && iter == stack_.rend() - 1) {
+          *is_global = true;
+        }
         return true;
       }
     }