Skip to content

Commit f6d6d97

Browse files
committed
let RootSignatureElement retain its source location
1 parent 4a5cde3 commit f6d6d97

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ namespace hlsl {
2929
// Introduce a wrapper struct around the underlying RootElement. This structure
3030
// will retain extra clang diagnostic information that is not available in llvm.
3131
struct RootSignatureElement {
32-
RootSignatureElement(llvm::hlsl::rootsig::RootElement Element)
33-
: Element(Element) {}
32+
RootSignatureElement(SourceLocation Loc,
33+
llvm::hlsl::rootsig::RootElement Element)
34+
: Loc(Loc), Element(Element) {}
3435

3536
const llvm::hlsl::rootsig::RootElement &getElement() const { return Element; }
37+
const SourceLocation &getLocation() const { return Loc; }
3638

3739
private:
40+
SourceLocation Loc;
3841
llvm::hlsl::rootsig::RootElement Element;
3942
};
4043

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,44 @@ bool RootSignatureParser::parse() {
2929
do {
3030
std::optional<RootSignatureElement> Element = std::nullopt;
3131
if (tryConsumeExpectedToken(TokenKind::kw_RootFlags)) {
32+
SourceLocation ElementLoc = getTokenLocation(CurToken);
3233
auto Flags = parseRootFlags();
3334
if (!Flags.has_value())
3435
return true;
35-
Element = RootSignatureElement(*Flags);
36+
Element = RootSignatureElement(ElementLoc, *Flags);
3637
}
3738

3839
if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) {
40+
SourceLocation ElementLoc = getTokenLocation(CurToken);
3941
auto Constants = parseRootConstants();
4042
if (!Constants.has_value())
4143
return true;
42-
Element = RootSignatureElement(*Constants);
44+
Element = RootSignatureElement(ElementLoc, *Constants);
4345
}
4446

4547
if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
48+
SourceLocation ElementLoc = getTokenLocation(CurToken);
4649
auto Table = parseDescriptorTable();
4750
if (!Table.has_value())
4851
return true;
49-
Element = RootSignatureElement(*Table);
52+
Element = RootSignatureElement(ElementLoc, *Table);
5053
}
5154

5255
if (tryConsumeExpectedToken(
5356
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
57+
SourceLocation ElementLoc = getTokenLocation(CurToken);
5458
auto Descriptor = parseRootDescriptor();
5559
if (!Descriptor.has_value())
5660
return true;
57-
Element = RootSignatureElement(*Descriptor);
61+
Element = RootSignatureElement(ElementLoc, *Descriptor);
5862
}
5963

6064
if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
65+
SourceLocation ElementLoc = getTokenLocation(CurToken);
6166
auto Sampler = parseStaticSampler();
6267
if (!Sampler.has_value())
6368
return true;
64-
Element = RootSignatureElement(*Sampler);
69+
Element = RootSignatureElement(ElementLoc, *Sampler);
6570
}
6671

6772
if (Element.has_value())
@@ -258,10 +263,11 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
258263
do {
259264
if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
260265
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
266+
SourceLocation ElementLoc = getTokenLocation(CurToken);
261267
auto Clause = parseDescriptorTableClause();
262268
if (!Clause.has_value())
263269
return std::nullopt;
264-
Elements.push_back(RootSignatureElement(*Clause));
270+
Elements.push_back(RootSignatureElement(ElementLoc, *Clause));
265271
Table.NumClauses++;
266272
}
267273

0 commit comments

Comments
 (0)