Skip to content

Commit 04a477d

Browse files
ParseType: support template types
1 parent 07b5765 commit 04a477d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

Common/interface/ParsingTools.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,31 @@ TypeDesc<TokenIterType> ParseType(const TokenIterType& Start, const TokenIterTyp
14241424
{
14251425
// unsigned long int i;
14261426
++Token;
1427+
1428+
if (Token->CompareLiteral("<"))
1429+
{
1430+
// texture2D<float, access::read>
1431+
// ^
1432+
int NumOpenAngleBrackets = 1;
1433+
++Token;
1434+
for (; Token != ClosingBrace && NumOpenAngleBrackets > 0; ++Token)
1435+
{
1436+
if (Token->CompareLiteral("<"))
1437+
{
1438+
++NumOpenAngleBrackets;
1439+
}
1440+
else if (Token->CompareLiteral(">"))
1441+
{
1442+
--NumOpenAngleBrackets;
1443+
}
1444+
}
1445+
if (Token == ClosingBrace)
1446+
{
1447+
// texture2D<float
1448+
// }
1449+
return {};
1450+
}
1451+
}
14271452
}
14281453
if (Token == ClosingBrace)
14291454
{

Tests/DiligentCoreTest/src/Common/ParsingToolsTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,18 +1842,38 @@ TEST(Common_ParsingTools, ParseType)
18421842
})",
18431843
{});
18441844

1845+
Test(R"(struct TestStruct
1846+
{
1847+
int x;
1848+
atomic<int
1849+
})",
1850+
{});
1851+
1852+
Test(R"(struct TestStruct
1853+
{
1854+
int x;
1855+
atomic<int y;
1856+
})",
1857+
{});
1858+
18451859
Test(R"(struct TestStruct
18461860
{
18471861
unsigned int x;
18481862
const int y[5];
18491863
flat float4 z[16][128];
1864+
atomic<int> a;
1865+
texture2D<float, access::read> tex;
1866+
texture2D<vector<float, 3>, access::read> tex2;
18501867
})",
18511868
{
18521869
"TestStruct",
18531870
{
18541871
{"unsigned int", "x"},
18551872
{"const int", "y", {"5"}},
18561873
{"flat float4", "z", {"16", "128"}},
1874+
{"atomic < int >", "a"},
1875+
{"texture2D < float , access :: read >", "tex"},
1876+
{"texture2D < vector < float , 3 > , access :: read >", "tex2"},
18571877
},
18581878
});
18591879

@@ -1862,6 +1882,8 @@ TEST(Common_ParsingTools, ParseType)
18621882
int x, y, z;
18631883
float a[10], b[20][30], c[40][50][60];
18641884
unsigned int m, n[5], o[6][7];
1885+
atomic<int> p, q[8], r[9][10];
1886+
texture2D<float, access::read> tex1, tex2[4], tex3[5][6];
18651887
})",
18661888
{
18671889
"TestStruct",
@@ -1875,6 +1897,12 @@ TEST(Common_ParsingTools, ParseType)
18751897
{"unsigned int", "m"},
18761898
{"unsigned int", "n", {"5"}},
18771899
{"unsigned int", "o", {"6", "7"}},
1900+
{"atomic < int >", "p"},
1901+
{"atomic < int >", "q", {"8"}},
1902+
{"atomic < int >", "r", {"9", "10"}},
1903+
{"texture2D < float , access :: read >", "tex1"},
1904+
{"texture2D < float , access :: read >", "tex2", {"4"}},
1905+
{"texture2D < float , access :: read >", "tex3", {"5", "6"}},
18781906
},
18791907
});
18801908
}

0 commit comments

Comments
 (0)