Skip to content

Commit 1708789

Browse files
committed
let RootSignatureElement retain its source location
1 parent bef7466 commit 1708789

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,31 +29,36 @@ bool RootSignatureParser::parse() {
2929
// end of the stream
3030
while (!peekExpectedToken(TokenKind::end_of_stream)) {
3131
if (tryConsumeExpectedToken(TokenKind::kw_RootFlags)) {
32+
SourceLocation ElementLoc = getTokenLocation(CurToken);
3233
auto Flags = parseRootFlags();
3334
if (!Flags.has_value())
3435
return true;
35-
Elements.emplace_back(RootSignatureElement(*Flags));
36+
Elements.emplace_back(RootSignatureElement(ElementLoc, *Flags));
3637
} else if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) {
38+
SourceLocation ElementLoc = getTokenLocation(CurToken);
3739
auto Constants = parseRootConstants();
3840
if (!Constants.has_value())
3941
return true;
40-
Elements.emplace_back(RootSignatureElement(*Constants));
42+
Elements.emplace_back(RootSignatureElement(ElementLoc, *Constants));
4143
} else if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
44+
SourceLocation ElementLoc = getTokenLocation(CurToken);
4245
auto Table = parseDescriptorTable();
4346
if (!Table.has_value())
4447
return true;
45-
Elements.emplace_back(RootSignatureElement(*Table));
48+
Elements.emplace_back(RootSignatureElement(ElementLoc, *Table));
4649
} else if (tryConsumeExpectedToken(
4750
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
51+
SourceLocation ElementLoc = getTokenLocation(CurToken);
4852
auto Descriptor = parseRootDescriptor();
4953
if (!Descriptor.has_value())
5054
return true;
51-
Elements.emplace_back(RootSignatureElement(*Descriptor));
55+
Elements.emplace_back(RootSignatureElement(ElementLoc, *Descriptor));
5256
} else if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
57+
SourceLocation ElementLoc = getTokenLocation(CurToken);
5358
auto Sampler = parseStaticSampler();
5459
if (!Sampler.has_value())
5560
return true;
56-
Elements.emplace_back(RootSignatureElement(*Sampler));
61+
Elements.emplace_back(RootSignatureElement(ElementLoc, *Sampler));
5762
}
5863

5964
// ',' denotes another element, otherwise, expected to be at end of stream
@@ -245,10 +250,11 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
245250
if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
246251
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
247252
// DescriptorTableClause - CBV, SRV, UAV, or Sampler
253+
SourceLocation ElementLoc = getTokenLocation(CurToken);
248254
auto Clause = parseDescriptorTableClause();
249255
if (!Clause.has_value())
250256
return std::nullopt;
251-
Elements.push_back(RootSignatureElement(*Clause));
257+
Elements.push_back(RootSignatureElement(ElementLoc, *Clause));
252258
Table.NumClauses++;
253259
} else if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
254260
// visibility = SHADER_VISIBILITY

0 commit comments

Comments
 (0)