9using namespace shader::parser;
10using namespace shader;
18void func() { T::fn(); }
19template void func<A>();
23void funcTA() { A_fn(); }
26 auto [
output, _, error] = process_test_string(input);
32template<typename T> void f(T a) {}
36 auto [
output, _, error] = process_test_string(input);
43template void func<float>();
54 auto [
output, _, error] = process_test_string(input, Language::BSL);
61int func() { return U; }
62template void func<1 + 3>();
71 auto [
output, _, error] = process_test_string(input, Language::BSL);
78template<typename T> struct A {
91 string expect = R
"(#line 9
96U U_ctor_() {U r;r._pad=0;return r;}
99void _f(_ref(U ,this_));
102 void _f(_ref(U ,this_)) {
111ATU ATU_ctor_() {ATU r;r._pad=0;return r;}
114void _f(_ref(ATU ,this_), U _0);
117 void _f(_ref(ATU ,this_), U t)
123 auto [
output, _, error] = process_test_string(input, Language::BSL);
131template void func<float>(float a);
134template void foo<float>(float &a);
144void func(float a) {a;}
147void foo(_ref(float ,a)) {a;}
156 auto [
output, _, error] = process_test_string(input);
163template<typename T> void foo(T a) { a; }
164template void foo<float>(float a);
165template void foo<int>(int a);
166template<> void foo<uint>(uint a) {}
168void f(float a, int b, uint c)
179 void fooTfloat(float a) {
183 void fooTint(int a) {
188 void fooTuint(uint a) { }
190void f(float a, int b, uint c)
200 auto [
output, _, error] = process_test_string(input, Language::BSL);
206template<typename T, int i>
210template void func<float, 1>(float a);
214void funcTfloatT1(float a) {
219 auto [
output, _, error] = process_test_string(input);
225enum E : char { A, B };
226template<int i, uint j, int k> int foo() { return int(i + j + k); }
227template int foo<0xF + 2, 2, -1 - 2>();
228template<enum E e, char i> E f() { return e; }
233 foo<0xF + 2, 2, -1 - 2>();
241static constexpr char A = 0;
243static constexpr char B = 1;
246 return int(17 + 2 + -3);
261 auto [
output, _, error] = process_test_string(input, Language::BSL);
267template<int i, uint j, int k> E func() { return E(i + j + k); }
268template E func<0x1, 2, -1>();
271E funcT0x1T2T_1() { return E(0x1 + 2 + -1); }
274 auto [
output, _, error] = process_test_string(input);
280template<enum E e, char i> E func() { return E(e + i); }
281template E func<v, 2>();
284E funcTvT2() { return E(v + 2); }
287 auto [
output, _, error] = process_test_string(input);
293template<> void func<T, Q>(T a) {a}
296 void funcTTTQ(T a) {a}
298 auto [
output, _, error] = process_test_string(input);
303 string input = R
"(template<typename T, int i = 0> void func(T a) {a;})";
304 auto [
output, _, error] = process_test_string(input);
305 EXPECT_EQ(error,
"Default arguments are not supported inside template declaration");
308 string input = R
"(template void func(float a);)";
309 auto [
output, _, error] = process_test_string(input);
311 "Template instantiation and specialization require explicit template arguments");
314 string input = R
"(template A<f> fn(A<f> a);)";
315 auto [
output, _, error] = process_test_string(input);
317 "Template instantiation and specialization require explicit template arguments");
320 string input = R
"(template<> A fn(A a) {})";
321 auto [
output, _, error] = process_test_string(input);
323 "Template instantiation and specialization require explicit template arguments");
326 string input = R
"(template<> A<f> fn(A<f> a) {})";
327 auto [
output, _, error] = process_test_string(input);
329 "Template instantiation and specialization require explicit template arguments");
332 string input = R
"(template<typename T, int i = 0> void func(T a) {a;})";
333 auto [
output, _, error] = process_test_string(input, Language::BSL);
334 EXPECT_EQ(error,
"Default arguments are not supported inside template declaration");
337 string input = R
"(template void func(float a);)";
338 auto [
output, _, error] = process_test_string(input, Language::BSL);
339 EXPECT_EQ(error,
"Expected template arguments");
342 string input = R
"(template A<f> fn(A<f> a);)";
343 auto [
output, _, error] = process_test_string(input, Language::BSL);
344 EXPECT_EQ(error,
"Expected template arguments");
347 string input = R
"(template<> A fn(A a) {})";
348 auto [
output, _, error] = process_test_string(input, Language::BSL);
349 EXPECT_EQ(error,
"Expected template arguments");
352 string input = R
"(template<> A<f> fn(A<f> a) {})";
353 auto [
output, _, error] = process_test_string(input, Language::BSL);
354 EXPECT_EQ(error,
"Expected template arguments");
357 string input = R
"(func<float, 1>(a);)";
358 string expect = R
"(funcTfloatT1(a);)";
359 auto [
output, _, error] = process_test_local(input);
364 string input = R
"(a.template func<float, 1>(a);)";
365 string expect = R
"(_funcTfloatT1(a, a);)";
366 auto [
output, _, error] = process_test_local(input);
371 string input = R
"(this->template func<float, 1>(a);)";
372 string expect = R
"(_funcTfloatT1(this_, a);)";
373 auto [
output, _, error] = process_test_local(input);
378 string input = R
"(A<B<1, 2>, C<1, D<T, -1>>> a;)";
379 string expect = R
"(ATBT1T2TCT1TDTTT_1 a;)";
380 auto [
output, _, error] = process_test_local(input);
387template<int T, int U> struct B {};
388template<int T, typename U> struct C {};
389template<typename T, int U> struct D {};
390template<typename T, typename U> struct A {};
392template struct B<1, 2>;
393template struct D<T, -1>;
394template struct C<1, D<T, -1>>;
395template struct A<B<1, 2>, C<1, D<T, -1>>>;
397A<B<1, 2>, C<1, D<T, -1>>> a;
404T T_ctor_() {T r;r._pad=0;return r;}
405 struct BT1T2 {int _pad;
409BT1T2 BT1T2_ctor_() {BT1T2 r;r._pad=0;return r;}
411 struct DTTT_1 {int _pad;
415DTTT_1 DTTT_1_ctor_() {DTTT_1 r;r._pad=0;return r;}
417 struct CT1TDTTT_1 {int _pad;
421CT1TDTTT_1 CT1TDTTT_1_ctor_() {CT1TDTTT_1 r;r._pad=0;return r;}
423 struct ATBT1T2TCT1TDTTT_1 {int _pad;
427ATBT1T2TCT1TDTTT_1 ATBT1T2TCT1TDTTT_1_ctor_() {ATBT1T2TCT1TDTTT_1 r;r._pad=0;return r;}
431 auto [
output, _, error] = process_test_string(input, Language::BSL);
437TEST(shader_tool, TemplateStruct)
449template struct A<float>;
460ATfloat ATfloat_ctor_();
461ATfloat _method(const ATfloat this_, float b);
464 ATfloat ATfloat_ctor_() {ATfloat r;r.a=0.0f;return r;}
466 ATfloat _method(const ATfloat this_, float b)
468 return _ctor(ATfloat) b _rotc() ;
473 auto [
output, _, error] = process_test_string(input);
481template struct A<float>;
485struct ATfloat { float a; };
487 ATfloat ATfloat_ctor_() {ATfloat r;r.a=0.0f;return r;}
490 auto [
output, _, error] = process_test_string(input);
496template<> struct A<float>{
505 ATfloat ATfloat_ctor_() {ATfloat r;r.a=0.0f;return r;}
509 auto [
output, _, error] = process_test_string(input);
515void func(A<float> a) {}
518void func(ATfloat a) {}
520 auto [
output, _, error] = process_test_string(input);
529template<typename B> struct A {
531 template<typename T> static void fn1(T a) {}
532 template<typename T> static T fn2() { return T(0); }
533 template<typename T> void fn3(T a) { i += int(fn4<T>()); }
534 template<typename T> T fn4() { fn3(0); return T(0); }
537template struct A<int>;
539template void A<int>::fn1<int>(int);
540template int A<int>::fn2<int>();
541template void A<int>::fn3<int>(int);
542template int A<int>::fn4<int>();
563N_ATint N_ATint_ctor_();
564void N_ATint_fn1(int a);
565int N_ATint_fn2Tint();
566void _fn3(_ref(N_ATint ,this_), int a);
567int _fn4Tint(_ref(N_ATint ,this_));
570 N_ATint N_ATint_ctor_() {N_ATint r;r.i=0;return r;}
572 void N_ATint_fn1(int a) {}
573 int N_ATint_fn2Tint() { return int(0); }
574void _fn3(_ref(N_ATint ,this_), int a) { this_.i += int(_fn4Tint(this_)); }
575int _fn4Tint(_ref(N_ATint ,this_)) { _fn3(this_, 0); return int(0); }
587 auto [
output, _, error] = process_test_string(input);
593template<typename T> struct A {
604template struct A<float>;
612ATfloat ATfloat_ctor_() {ATfloat r;r.a=0.0f;return r;}
615ATfloat _method(ATfloat this_, float _0);
618 ATfloat _method(ATfloat this_, float b)
628 auto [
output, _, error] = process_test_string(input, Language::BSL);
635template<int i> struct T {};
637template<> struct T<0> {
646 string expect = R
"(#line 4
651TT0 TT0_ctor_() {TT0 r;for(int a =0;a < 1;++a) {r.b[a]=0;}return r;}
658 auto [
output, _, error] = process_test_string(input, Language::BSL);
#define EXPECT_EQ(result, expect)
TEST(shader_tool, ExpressionParser)