[clang] ed673aa - [clang][NFC] Convert `Sema::OffsetOfKind` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 21:49:53 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-02T07:49:47+03:00
New Revision: ed673aac7aa78896ec55aa615e37432006c2830a
URL: https://github.com/llvm/llvm-project/commit/ed673aac7aa78896ec55aa615e37432006c2830a
DIFF: https://github.com/llvm/llvm-project/commit/ed673aac7aa78896ec55aa615e37432006c2830a.diff
LOG: [clang][NFC] Convert `Sema::OffsetOfKind` to scoped enum
Added:
Modified:
clang/include/clang/Parse/Parser.h
clang/include/clang/Parse/RAIIObjectsForParser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index c30fe7c04e28d..84d46136ff574 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -374,7 +374,7 @@ class Parser : public CodeCompletionHandler {
/// function call.
bool CalledSignatureHelp = false;
- Sema::OffsetOfKind OffsetOfState = Sema::OffsetOfKind::OOK_Outside;
+ OffsetOfKind OffsetOfState = OffsetOfKind::Outside;
/// The "depth" of the template parameters currently being parsed.
unsigned TemplateParameterDepth;
diff --git a/clang/include/clang/Parse/RAIIObjectsForParser.h b/clang/include/clang/Parse/RAIIObjectsForParser.h
index 480efccb19cf7..3adcbfe9d7016 100644
--- a/clang/include/clang/Parse/RAIIObjectsForParser.h
+++ b/clang/include/clang/Parse/RAIIObjectsForParser.h
@@ -361,11 +361,11 @@ namespace clang {
};
class OffsetOfStateRAIIObject {
- Sema::OffsetOfKind &OffsetOfState;
- Sema::OffsetOfKind OldValue;
+ OffsetOfKind &OffsetOfState;
+ OffsetOfKind OldValue;
public:
- OffsetOfStateRAIIObject(Parser &P, Sema::OffsetOfKind Value)
+ OffsetOfStateRAIIObject(Parser &P, OffsetOfKind Value)
: OffsetOfState(P.OffsetOfState), OldValue(P.OffsetOfState) {
OffsetOfState = Value;
}
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e641a4ac865d0..d874adf0643f1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -609,6 +609,16 @@ enum class NonTagKind {
TemplateTemplateArgument,
};
+enum class OffsetOfKind {
+ // Not parsing a type within __builtin_offsetof.
+ Outside,
+ // Parsing a type within __builtin_offsetof.
+ Builtin,
+ // Parsing a type within macro "offsetof", defined in __buitin_offsetof
+ // To improve our diagnostic message.
+ Macro,
+};
+
/// Sema - This implements semantic analysis and AST building for C.
/// \nosubgrouping
class Sema final : public SemaBase {
@@ -4001,16 +4011,6 @@ class Sema final : public SemaBase {
bool isDefinition, SourceLocation NewTagLoc,
const IdentifierInfo *Name);
- enum OffsetOfKind {
- // Not parsing a type within __builtin_offsetof.
- OOK_Outside,
- // Parsing a type within __builtin_offsetof.
- OOK_Builtin,
- // Parsing a type within macro "offsetof", defined in __buitin_offsetof
- // To improve our diagnostic message.
- OOK_Macro,
- };
-
/// This is invoked when we see 'struct foo' or 'struct {'. In the
/// former case, Name will be non-null. In the later case, Name will be null.
/// TagSpec indicates what kind of tag this is. TUK indicates whether this is
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index a5dd08529cf37..4b5d677f4ba87 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2796,12 +2796,12 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() {
}
case tok::kw___builtin_offsetof: {
SourceLocation TypeLoc = Tok.getLocation();
- auto OOK = Sema::OffsetOfKind::OOK_Builtin;
+ auto OOK = OffsetOfKind::Builtin;
if (Tok.getLocation().isMacroID()) {
StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
Tok.getLocation(), PP.getSourceManager(), getLangOpts());
if (MacroName == "offsetof")
- OOK = Sema::OffsetOfKind::OOK_Macro;
+ OOK = OffsetOfKind::Macro;
}
TypeResult Ty;
{
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d4c0fe62653ad..22a8b19807a10 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18240,10 +18240,10 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
}
// Only C23 and later allow defining new types in 'offsetof()'.
- if (OOK != OOK_Outside && TUK == TagUseKind::Definition &&
+ if (OOK != OffsetOfKind::Outside && TUK == TagUseKind::Definition &&
!getLangOpts().CPlusPlus && !getLangOpts().C23)
Diag(New->getLocation(), diag::ext_type_defined_in_offsetof)
- << (OOK == OOK_Macro) << New->getSourceRange();
+ << (OOK == OffsetOfKind::Macro) << New->getSourceRange();
// C++11 [dcl.type]p3:
// A type-specifier-seq shall not define a class or enumeration [...].
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a7e68682d5320..f02fc855d5b3d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -18000,7 +18000,8 @@ DeclResult Sema::ActOnTemplatedFriendTag(
/*ScopedEnumUsesClassTag=*/false,
/*UnderlyingType=*/TypeResult(),
/*IsTypeSpecifier=*/false,
- /*IsTemplateParamOrArg=*/false, /*OOK=*/OOK_Outside);
+ /*IsTemplateParamOrArg=*/false,
+ /*OOK=*/OffsetOfKind::Outside);
}
ElaboratedTypeKeyword Keyword
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c062837ed830a..466e6b5a10457 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -10070,7 +10070,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc,
Attr, AS_none, /*ModulePrivateLoc=*/SourceLocation(),
MultiTemplateParamsArg(), Owned, IsDependent, SourceLocation(),
false, TypeResult(), /*IsTypeSpecifier*/ false,
- /*IsTemplateParamOrArg*/ false, /*OOK=*/OOK_Outside)
+ /*IsTemplateParamOrArg*/ false, /*OOK=*/OffsetOfKind::Outside)
.get();
assert(!IsDependent && "explicit instantiation of dependent name not yet handled");
More information about the cfe-commits
mailing list