mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-31 01:15:56 +00:00
This CL removes the following AST nodes: * ast::Array * ast::Atomic * ast::Matrix * ast::MultisampledTexture * ast::Pointer * ast::SampledTexture * ast::Texture * ast::TypeName * ast::Vector ast::Type, which used to be the base class for all AST types, is now a thin wrapper around ast::IdentifierExpression. All types are now referred to using their type name. The resolver now handles type resolution and validation of the types listed above based on the TemplateIdentifier arguments. Other changes: * ProgramBuilder has undergone substantial refactoring. * ProgramBuilder helpers for type inferencing is now more explicit. Instead of passing 'nullptr', a new 'Infer' template argument is passed. * ast::CheckIdentifier() is used for more tests that check identifiers, including types. Bug: tint:1810 Change-Id: I8e739ef49435dc1c20a462f3ec5ba265661a7edb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118723 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
135 lines
3.6 KiB
C++
135 lines
3.6 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 "gtest/gtest-spi.h"
|
|
#include "src/tint/ast/test_helper.h"
|
|
|
|
namespace tint::ast {
|
|
namespace {
|
|
|
|
using CallExpressionTest = TestHelper;
|
|
|
|
TEST_F(CallExpressionTest, CreationIdentifier) {
|
|
auto* func = Expr("func");
|
|
utils::Vector params{
|
|
Expr("param1"),
|
|
Expr("param2"),
|
|
};
|
|
|
|
auto* stmt = Call(func, params);
|
|
EXPECT_EQ(stmt->target, func);
|
|
|
|
const auto& vec = stmt->args;
|
|
ASSERT_EQ(vec.Length(), 2u);
|
|
EXPECT_EQ(vec[0], params[0]);
|
|
EXPECT_EQ(vec[1], params[1]);
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, CreationIdentifier_WithSource) {
|
|
auto* func = Expr("func");
|
|
auto* stmt = Call(Source{{20, 2}}, func);
|
|
EXPECT_EQ(stmt->target, func);
|
|
|
|
auto src = stmt->source;
|
|
EXPECT_EQ(src.range.begin.line, 20u);
|
|
EXPECT_EQ(src.range.begin.column, 2u);
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, CreationType) {
|
|
auto* type = Expr(ty.f32());
|
|
utils::Vector params{
|
|
Expr("param1"),
|
|
Expr("param2"),
|
|
};
|
|
|
|
auto* stmt = Call(type, params);
|
|
EXPECT_EQ(stmt->target, type);
|
|
|
|
const auto& vec = stmt->args;
|
|
ASSERT_EQ(vec.Length(), 2u);
|
|
EXPECT_EQ(vec[0], params[0]);
|
|
EXPECT_EQ(vec[1], params[1]);
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, CreationType_WithSource) {
|
|
auto* type = Expr(ty.f32());
|
|
auto* stmt = Call(Source{{20, 2}}, type);
|
|
EXPECT_EQ(stmt->target, type);
|
|
|
|
auto src = stmt->source;
|
|
EXPECT_EQ(src.range.begin.line, 20u);
|
|
EXPECT_EQ(src.range.begin.column, 2u);
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, IsCall) {
|
|
auto* func = Expr("func");
|
|
auto* stmt = Call(func);
|
|
EXPECT_TRUE(stmt->Is<CallExpression>());
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, Assert_Null_Identifier) {
|
|
EXPECT_FATAL_FAILURE(
|
|
{
|
|
ProgramBuilder b;
|
|
b.Call(static_cast<Identifier*>(nullptr));
|
|
},
|
|
"internal compiler error");
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, Assert_Null_Param) {
|
|
EXPECT_FATAL_FAILURE(
|
|
{
|
|
ProgramBuilder b;
|
|
b.Call(b.Ident("func"), utils::Vector{
|
|
b.Expr("param1"),
|
|
nullptr,
|
|
b.Expr("param2"),
|
|
});
|
|
},
|
|
"internal compiler error");
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Identifier) {
|
|
EXPECT_FATAL_FAILURE(
|
|
{
|
|
ProgramBuilder b1;
|
|
ProgramBuilder b2;
|
|
b1.Call(b2.Ident("func"));
|
|
},
|
|
"internal compiler error");
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Type) {
|
|
EXPECT_FATAL_FAILURE(
|
|
{
|
|
ProgramBuilder b1;
|
|
ProgramBuilder b2;
|
|
b1.Call(b2.ty.f32());
|
|
},
|
|
"internal compiler error");
|
|
}
|
|
|
|
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Param) {
|
|
EXPECT_FATAL_FAILURE(
|
|
{
|
|
ProgramBuilder b1;
|
|
ProgramBuilder b2;
|
|
b1.Call(b1.Ident("func"), b2.Expr("param1"));
|
|
},
|
|
"internal compiler error");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace tint::ast
|