Skip to content

Commit d91de5f

Browse files
committed
nfc: move invocation of parsing to common location
1 parent 29fa5b7 commit d91de5f

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ class RootSignatureParser {
236236
RootSignatureToken CurToken;
237237
};
238238

239+
IdentifierInfo *ParseHLSLRootSignature(Sema &Actions,
240+
llvm::dxbc::RootSignatureVersion Version,
241+
StringLiteral *Signature);
242+
239243
} // namespace hlsl
240244
} // namespace clang
241245

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4923,33 +4923,20 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49234923
return std::nullopt;
49244924
};
49254925

4926-
auto StrLiteral = ProcessStringLiteral();
4927-
if (!StrLiteral.has_value()) {
4926+
auto Signature = ProcessStringLiteral();
4927+
if (!Signature.has_value()) {
49284928
Diag(Tok, diag::err_expected_string_literal)
4929-
<< /*in attributes...*/ 4 << RootSignatureIdent->getName();
4930-
SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
4931-
T.consumeClose();
4929+
<< /*in attributes...*/ 4 << "RootSignature";
49324930
return;
49334931
}
49344932

49354933
// Construct our identifier
4936-
StringLiteral *Signature = StrLiteral.value();
4937-
auto [DeclIdent, Found] =
4938-
Actions.HLSL().ActOnStartRootSignatureDecl(Signature->getString());
4939-
// If we haven't found an already defined DeclIdent then parse the root
4940-
// signature string and construct the in-memory elements
4941-
if (!Found) {
4942-
// Invoke the root signature parser to construct the in-memory constructs
4943-
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, Signature,
4944-
PP);
4945-
if (Parser.parse()) {
4946-
T.consumeClose();
4947-
return;
4948-
}
4949-
4950-
// Construct the declaration.
4951-
Actions.HLSL().ActOnFinishRootSignatureDecl(RootSignatureLoc, DeclIdent,
4952-
Parser.getElements());
4934+
IdentifierInfo *DeclIdent = hlsl::ParseHLSLRootSignature(
4935+
Actions, getLangOpts().HLSLRootSigVer, *Signature);
4936+
if (!DeclIdent) {
4937+
SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
4938+
T.consumeClose();
4939+
return;
49534940
}
49544941

49554942
// Create the arg for the ParsedAttr

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "clang/Parse/ParseHLSLRootSignature.h"
1010

1111
#include "clang/Lex/LiteralSupport.h"
12+
#include "clang/Sema/Sema.h"
1213

1314
using namespace llvm::hlsl::rootsig;
1415

@@ -1448,5 +1449,28 @@ SourceLocation RootSignatureParser::getTokenLocation(RootSignatureToken Tok) {
14481449
PP.getLangOpts(), PP.getTargetInfo());
14491450
}
14501451

1452+
IdentifierInfo *ParseHLSLRootSignature(Sema &Actions,
1453+
llvm::dxbc::RootSignatureVersion Version,
1454+
StringLiteral *Signature) {
1455+
// Construct our identifier
1456+
auto [DeclIdent, Found] =
1457+
Actions.HLSL().ActOnStartRootSignatureDecl(Signature->getString());
1458+
// If we haven't found an already defined DeclIdent then parse the root
1459+
// signature string and construct the in-memory elements
1460+
if (!Found) {
1461+
// Invoke the root signature parser to construct the in-memory constructs
1462+
hlsl::RootSignatureParser Parser(Version, Signature,
1463+
Actions.getPreprocessor());
1464+
if (Parser.parse())
1465+
return nullptr;
1466+
1467+
// Construct the declaration.
1468+
Actions.HLSL().ActOnFinishRootSignatureDecl(
1469+
Signature->getBeginLoc(), DeclIdent, Parser.getElements());
1470+
}
1471+
1472+
return DeclIdent;
1473+
}
1474+
14511475
} // namespace hlsl
14521476
} // namespace clang

0 commit comments

Comments
 (0)