Skip to content

Commit 77524bc

Browse files
authored
[NFC][HLSL] Let RootSignatureParser own the references (#150310)
- this is a clean up from a review comment that we should let the parser own the constructed `RootSignatureElement`s Original comment here: #147115 (comment).
1 parent 227d1b2 commit 77524bc

File tree

4 files changed

+67
-152
lines changed

4 files changed

+67
-152
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace hlsl {
3030
class RootSignatureParser {
3131
public:
3232
RootSignatureParser(llvm::dxbc::RootSignatureVersion Version,
33-
SmallVector<RootSignatureElement> &Elements,
3433
StringLiteral *Signature, Preprocessor &PP);
3534

3635
/// Consumes tokens from the Lexer and constructs the in-memory
@@ -40,6 +39,9 @@ class RootSignatureParser {
4039
/// Returns true if a parsing error is encountered.
4140
bool parse();
4241

42+
/// Return all elements that have been parsed.
43+
ArrayRef<RootSignatureElement> getElements() { return Elements; }
44+
4345
private:
4446
DiagnosticsEngine &getDiags() { return PP.getDiagnostics(); }
4547

@@ -226,7 +228,7 @@ class RootSignatureParser {
226228

227229
private:
228230
llvm::dxbc::RootSignatureVersion Version;
229-
SmallVector<RootSignatureElement> &Elements;
231+
SmallVector<RootSignatureElement> Elements;
230232
StringLiteral *Signature;
231233
RootSignatureLexer Lexer;
232234
Preprocessor &PP;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,17 +4940,16 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49404940
// signature string and construct the in-memory elements
49414941
if (!Found) {
49424942
// Invoke the root signature parser to construct the in-memory constructs
4943-
SmallVector<hlsl::RootSignatureElement> RootElements;
4944-
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
4945-
Signature, PP);
4943+
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, Signature,
4944+
PP);
49464945
if (Parser.parse()) {
49474946
T.consumeClose();
49484947
return;
49494948
}
49504949

49514950
// Construct the declaration.
49524951
Actions.HLSL().ActOnFinishRootSignatureDecl(RootSignatureLoc, DeclIdent,
4953-
RootElements);
4952+
Parser.getElements());
49544953
}
49554954

49564955
// Create the arg for the ParsedAttr

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ static const TokenKind RootElementKeywords[] = {
2727
};
2828

2929
RootSignatureParser::RootSignatureParser(
30-
llvm::dxbc::RootSignatureVersion Version,
31-
SmallVector<RootSignatureElement> &Elements, StringLiteral *Signature,
30+
llvm::dxbc::RootSignatureVersion Version, StringLiteral *Signature,
3231
Preprocessor &PP)
33-
: Version(Version), Elements(Elements), Signature(Signature),
34-
Lexer(Signature->getString()), PP(PP), CurToken(0) {}
32+
: Version(Version), Signature(Signature), Lexer(Signature->getString()),
33+
PP(PP), CurToken(0) {}
3534

3635
bool RootSignatureParser::parse() {
3736
// Iterate as many RootSignatureElements as possible, until we hit the

0 commit comments

Comments
 (0)