mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-08 15:43:41 +00:00
And remove a whole load of const_cast hackery. Semantic nodes may contain internally mutable fields (although only ever modified during resolving), so these are always passed by `const` pointer. While all AST nodes are internally immutable, we have decided that pointers to AST nodes should also be marked `const`, for consistency. There's still a collection of const_cast calls in the Resolver. These will be fixed up in a later change. Bug: tint:745 Change-Id: I046309b8e586772605fc0fe6b2d27f28806d40ef Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66606 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: David Neto <dneto@google.com>
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
// Copyright 2020 The Tint Authors. //
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/scope_stack.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "src/program_builder.h"
|
|
|
|
namespace tint {
|
|
namespace {
|
|
|
|
class ScopeStackTest : public ProgramBuilder, public testing::Test {};
|
|
|
|
TEST_F(ScopeStackTest, Global) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
s.set_global(sym, 5);
|
|
|
|
uint32_t val = 0;
|
|
EXPECT_TRUE(s.get(sym, &val));
|
|
EXPECT_EQ(val, 5u);
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, Global_SetWithPointer) {
|
|
auto* v = Var("my_var", ty.f32(), ast::StorageClass::kNone);
|
|
ScopeStack<const ast::Variable*> s;
|
|
s.set_global(v->symbol, v);
|
|
|
|
const ast::Variable* v2 = nullptr;
|
|
EXPECT_TRUE(s.get(v->symbol, &v2));
|
|
EXPECT_EQ(v2->symbol, v->symbol);
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, Global_CanNotPop) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
s.set_global(sym, 5);
|
|
s.pop_scope();
|
|
|
|
uint32_t val = 0;
|
|
EXPECT_TRUE(s.get(sym, &val));
|
|
EXPECT_EQ(val, 5u);
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, Scope) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
s.push_scope();
|
|
s.set(sym, 5);
|
|
|
|
uint32_t val = 0;
|
|
EXPECT_TRUE(s.get(sym, &val));
|
|
EXPECT_EQ(val, 5u);
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, Get_MissingSymbol) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
uint32_t ret = 0;
|
|
EXPECT_FALSE(s.get(sym, &ret));
|
|
EXPECT_EQ(ret, 0u);
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, Has) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
Symbol sym2(2, ID());
|
|
s.set_global(sym2, 3);
|
|
s.push_scope();
|
|
s.set(sym, 5);
|
|
|
|
EXPECT_TRUE(s.has(sym));
|
|
EXPECT_TRUE(s.has(sym2));
|
|
}
|
|
|
|
TEST_F(ScopeStackTest, ReturnsScopeBeforeGlobalFirst) {
|
|
ScopeStack<uint32_t> s;
|
|
Symbol sym(1, ID());
|
|
s.set_global(sym, 3);
|
|
s.push_scope();
|
|
s.set(sym, 5);
|
|
|
|
uint32_t ret;
|
|
EXPECT_TRUE(s.get(sym, &ret));
|
|
EXPECT_EQ(ret, 5u);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace tint
|