1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/resolver/resolver.h"
16
17 #include "gmock/gmock.h"
18 #include "src/ast/call_statement.h"
19 #include "src/resolver/resolver_test_helper.h"
20
21 namespace tint {
22 namespace resolver {
23 namespace {
24 // Helpers and typedefs
25 template <typename T>
26 using DataType = builder::DataType<T>;
27 template <int N, typename T>
28 using vec = builder::vec<N, T>;
29 template <typename T>
30 using vec2 = builder::vec2<T>;
31 template <typename T>
32 using vec3 = builder::vec3<T>;
33 template <typename T>
34 using vec4 = builder::vec4<T>;
35 template <int N, int M, typename T>
36 using mat = builder::mat<N, M, T>;
37 template <typename T>
38 using mat2x2 = builder::mat2x2<T>;
39 template <typename T>
40 using mat2x3 = builder::mat2x3<T>;
41 template <typename T>
42 using mat3x2 = builder::mat3x2<T>;
43 template <typename T>
44 using mat3x3 = builder::mat3x3<T>;
45 template <typename T>
46 using mat4x4 = builder::mat4x4<T>;
47 template <typename T, int ID = 0>
48 using alias = builder::alias<T, ID>;
49 template <typename T>
50 using alias1 = builder::alias1<T>;
51 template <typename T>
52 using alias2 = builder::alias2<T>;
53 template <typename T>
54 using alias3 = builder::alias3<T>;
55 using f32 = builder::f32;
56 using i32 = builder::i32;
57 using u32 = builder::u32;
58
59 using ResolverCallTest = ResolverTest;
60
61 struct Params {
62 builder::ast_expr_func_ptr create_value;
63 builder::ast_type_func_ptr create_type;
64 };
65
66 template <typename T>
ParamsFor()67 constexpr Params ParamsFor() {
68 return Params{DataType<T>::Expr, DataType<T>::AST};
69 }
70
71 static constexpr Params all_param_types[] = {
72 ParamsFor<bool>(), //
73 ParamsFor<u32>(), //
74 ParamsFor<i32>(), //
75 ParamsFor<f32>(), //
76 ParamsFor<vec3<bool>>(), //
77 ParamsFor<vec3<i32>>(), //
78 ParamsFor<vec3<u32>>(), //
79 ParamsFor<vec3<f32>>(), //
80 ParamsFor<mat3x3<f32>>(), //
81 ParamsFor<mat2x3<f32>>(), //
82 ParamsFor<mat3x2<f32>>() //
83 };
84
TEST_F(ResolverCallTest,Valid)85 TEST_F(ResolverCallTest, Valid) {
86 ast::VariableList params;
87 ast::ExpressionList args;
88 for (auto& p : all_param_types) {
89 params.push_back(Param(Sym(), p.create_type(*this)));
90 args.push_back(p.create_value(*this, 0));
91 }
92
93 auto* func = Func("foo", std::move(params), ty.f32(), {Return(1.23f)});
94 auto* call_expr = Call("foo", std::move(args));
95 WrapInFunction(call_expr);
96
97 EXPECT_TRUE(r()->Resolve()) << r()->error();
98
99 auto* call = Sem().Get(call_expr);
100 EXPECT_NE(call, nullptr);
101 EXPECT_EQ(call->Target(), Sem().Get(func));
102 }
103
104 } // namespace
105 } // namespace resolver
106 } // namespace tint
107