Skip to content

Commit 2826346

Browse files
committed
review: move ActOn methods to SemaHLSL
1 parent 6e3af13 commit 2826346

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,19 +3619,6 @@ class Sema final : public SemaBase {
36193619
SourceLocation NameLoc,
36203620
bool IsTemplateTypeArg);
36213621

3622-
/// Computes the unique Root Signature identifier from the given signature,
3623-
/// then lookup if there is a previousy created Root Signature decl.
3624-
///
3625-
/// Returns the identifier and if it was found
3626-
std::pair<IdentifierInfo *, bool>
3627-
ActOnStartRootSignatureDecl(StringRef Signature);
3628-
3629-
/// Creates the Root Signature decl of the parsed Root Signature elements
3630-
/// onto the AST and push it onto current Scope
3631-
void ActOnFinishRootSignatureDecl(
3632-
SourceLocation Loc, IdentifierInfo *DeclIdent,
3633-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements);
3634-
36353622
class NameClassification {
36363623
NameClassificationKind Kind;
36373624
union {

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ class SemaHLSL : public SemaBase {
119119
bool IsCompAssign);
120120
void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
121121

122+
/// Computes the unique Root Signature identifier from the given signature,
123+
/// then lookup if there is a previousy created Root Signature decl.
124+
///
125+
/// Returns the identifier and if it was found
126+
std::pair<IdentifierInfo *, bool>
127+
ActOnStartRootSignatureDecl(StringRef Signature);
128+
129+
/// Creates the Root Signature decl of the parsed Root Signature elements
130+
/// onto the AST and push it onto current Scope
131+
void ActOnFinishRootSignatureDecl(
132+
SourceLocation Loc, IdentifierInfo *DeclIdent,
133+
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements);
134+
122135
void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
123136
void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
124137
void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "clang/Sema/ParsedTemplate.h"
3030
#include "clang/Sema/Scope.h"
3131
#include "clang/Sema/SemaCodeCompletion.h"
32+
#include "clang/Sema/SemaHLSL.h"
3233
#include "llvm/Support/TimeProfiler.h"
3334
#include <optional>
3435

@@ -4942,7 +4943,8 @@ void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49424943

49434944
// Construct our identifier
49444945
StringRef Signature = StrLiteral.value()->getString();
4945-
auto [DeclIdent, Found] = Actions.ActOnStartRootSignatureDecl(Signature);
4946+
auto [DeclIdent, Found] =
4947+
Actions.HLSL().ActOnStartRootSignatureDecl(Signature);
49464948
// If we haven't found an already defined DeclIdent then parse the root
49474949
// signature string and construct the in-memory elements
49484950
if (!Found) {
@@ -4959,8 +4961,8 @@ void Parser::ParseMicrosoftRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49594961
}
49604962

49614963
// Construct the declaration.
4962-
Actions.ActOnFinishRootSignatureDecl(RootSignatureLoc, DeclIdent,
4963-
RootElements);
4964+
Actions.HLSL().ActOnFinishRootSignatureDecl(RootSignatureLoc, DeclIdent,
4965+
RootElements);
49644966
}
49654967

49664968
// Create the arg for the ParsedAttr

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -654,29 +654,6 @@ ParsedType Sema::ActOnMSVCUnknownTypeName(const IdentifierInfo &II,
654654
return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
655655
}
656656

657-
std::pair<IdentifierInfo *, bool>
658-
Sema::ActOnStartRootSignatureDecl(StringRef Signature) {
659-
auto Hash = llvm::hash_value(Signature);
660-
std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
661-
IdentifierInfo *DeclIdent = &(getASTContext().Idents.get(IdStr));
662-
663-
// Check if we have already found a decl of the same name.
664-
LookupResult R(*this, DeclIdent, SourceLocation(), Sema::LookupOrdinaryName);
665-
bool Found = LookupQualifiedName(R, this->CurContext);
666-
return {DeclIdent, Found};
667-
}
668-
669-
void Sema::ActOnFinishRootSignatureDecl(
670-
SourceLocation Loc, IdentifierInfo *DeclIdent,
671-
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements) {
672-
673-
auto *SignatureDecl = HLSLRootSignatureDecl::Create(
674-
getASTContext(), /*DeclContext=*/CurContext, Loc, DeclIdent, Elements);
675-
676-
SignatureDecl->setImplicit();
677-
PushOnScopeChains(SignatureDecl, getCurScope());
678-
}
679-
680657
DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) {
681658
// Do a tag name lookup in this scope.
682659
LookupResult R(*this, &II, SourceLocation(), LookupTagName);

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,31 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS,
971971
<< NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
972972
}
973973

974+
std::pair<IdentifierInfo *, bool>
975+
SemaHLSL::ActOnStartRootSignatureDecl(StringRef Signature) {
976+
auto Hash = llvm::hash_value(Signature);
977+
std::string IdStr = "__hlsl_rootsig_decl_" + std::to_string(Hash);
978+
IdentifierInfo *DeclIdent = &(getASTContext().Idents.get(IdStr));
979+
980+
// Check if we have already found a decl of the same name.
981+
LookupResult R(SemaRef, DeclIdent, SourceLocation(),
982+
Sema::LookupOrdinaryName);
983+
bool Found = SemaRef.LookupQualifiedName(R, SemaRef.CurContext);
984+
return {DeclIdent, Found};
985+
}
986+
987+
void SemaHLSL::ActOnFinishRootSignatureDecl(
988+
SourceLocation Loc, IdentifierInfo *DeclIdent,
989+
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements) {
990+
991+
auto *SignatureDecl = HLSLRootSignatureDecl::Create(
992+
SemaRef.getASTContext(), /*DeclContext=*/SemaRef.CurContext, Loc,
993+
DeclIdent, Elements);
994+
995+
SignatureDecl->setImplicit();
996+
SemaRef.PushOnScopeChains(SignatureDecl, SemaRef.getCurScope());
997+
}
998+
974999
void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) {
9751000
if (AL.getNumArgs() != 1) {
9761001
Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;

0 commit comments

Comments
 (0)