Skip to content

Commit fca5191

Browse files
authoredApr 11, 2024··
[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
1 parent be10070 commit fca5191

File tree

76 files changed

+602
-666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+602
-666
lines changed
 

‎clang/include/clang/AST/ASTContext.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3411,13 +3411,13 @@ const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
34113411

34123412
/// Utility function for constructing a nullary selector.
34133413
inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {
3414-
IdentifierInfo* II = &Ctx.Idents.get(name);
3414+
const IdentifierInfo *II = &Ctx.Idents.get(name);
34153415
return Ctx.Selectors.getSelector(0, &II);
34163416
}
34173417

34183418
/// Utility function for constructing an unary selector.
34193419
inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) {
3420-
IdentifierInfo* II = &Ctx.Idents.get(name);
3420+
const IdentifierInfo *II = &Ctx.Idents.get(name);
34213421
return Ctx.Selectors.getSelector(1, &II);
34223422
}
34233423

‎clang/include/clang/AST/Decl.h

+20-17
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ class ImplicitParamDecl : public VarDecl {
17311731
static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
17321732

17331733
ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
1734-
IdentifierInfo *Id, QualType Type,
1734+
const IdentifierInfo *Id, QualType Type,
17351735
ImplicitParamKind ParamKind)
17361736
: VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
17371737
/*TInfo=*/nullptr, SC_None) {
@@ -1765,7 +1765,7 @@ class ParmVarDecl : public VarDecl {
17651765

17661766
protected:
17671767
ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1768-
SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
1768+
SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
17691769
TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
17701770
: VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
17711771
assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
@@ -1777,10 +1777,10 @@ class ParmVarDecl : public VarDecl {
17771777

17781778
public:
17791779
static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1780-
SourceLocation StartLoc,
1781-
SourceLocation IdLoc, IdentifierInfo *Id,
1782-
QualType T, TypeSourceInfo *TInfo,
1783-
StorageClass S, Expr *DefArg);
1780+
SourceLocation StartLoc, SourceLocation IdLoc,
1781+
const IdentifierInfo *Id, QualType T,
1782+
TypeSourceInfo *TInfo, StorageClass S,
1783+
Expr *DefArg);
17841784

17851785
static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
17861786

@@ -3095,7 +3095,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
30953095

30963096
protected:
30973097
FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
3098-
SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
3098+
SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
30993099
TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
31003100
InClassInitStyle InitStyle)
31013101
: DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
@@ -3111,7 +3111,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31113111

31123112
static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
31133113
SourceLocation StartLoc, SourceLocation IdLoc,
3114-
IdentifierInfo *Id, QualType T,
3114+
const IdentifierInfo *Id, QualType T,
31153115
TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
31163116
InClassInitStyle InitStyle);
31173117

@@ -3332,8 +3332,9 @@ class IndirectFieldDecl : public ValueDecl,
33323332
friend class ASTDeclReader;
33333333

33343334
static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3335-
SourceLocation L, IdentifierInfo *Id,
3336-
QualType T, llvm::MutableArrayRef<NamedDecl *> CH);
3335+
SourceLocation L, const IdentifierInfo *Id,
3336+
QualType T,
3337+
llvm::MutableArrayRef<NamedDecl *> CH);
33373338

33383339
static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
33393340

@@ -3381,9 +3382,9 @@ class TypeDecl : public NamedDecl {
33813382
void anchor() override;
33823383

33833384
protected:
3384-
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
3385+
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id,
33853386
SourceLocation StartL = SourceLocation())
3386-
: NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3387+
: NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
33873388

33883389
public:
33893390
// Low-level accessor. If you just want the type defined by this node,
@@ -3425,7 +3426,7 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
34253426
protected:
34263427
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
34273428
SourceLocation StartLoc, SourceLocation IdLoc,
3428-
IdentifierInfo *Id, TypeSourceInfo *TInfo)
3429+
const IdentifierInfo *Id, TypeSourceInfo *TInfo)
34293430
: TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
34303431
MaybeModedTInfo(TInfo, 0) {}
34313432

@@ -3512,13 +3513,14 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
35123513
/// type specifier.
35133514
class TypedefDecl : public TypedefNameDecl {
35143515
TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3515-
SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
3516+
SourceLocation IdLoc, const IdentifierInfo *Id,
3517+
TypeSourceInfo *TInfo)
35163518
: TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
35173519

35183520
public:
35193521
static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
35203522
SourceLocation StartLoc, SourceLocation IdLoc,
3521-
IdentifierInfo *Id, TypeSourceInfo *TInfo);
3523+
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
35223524
static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
35233525

35243526
SourceRange getSourceRange() const override LLVM_READONLY;
@@ -3535,14 +3537,15 @@ class TypeAliasDecl : public TypedefNameDecl {
35353537
TypeAliasTemplateDecl *Template;
35363538

35373539
TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3538-
SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
3540+
SourceLocation IdLoc, const IdentifierInfo *Id,
3541+
TypeSourceInfo *TInfo)
35393542
: TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
35403543
Template(nullptr) {}
35413544

35423545
public:
35433546
static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
35443547
SourceLocation StartLoc, SourceLocation IdLoc,
3545-
IdentifierInfo *Id, TypeSourceInfo *TInfo);
3548+
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
35463549
static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
35473550

35483551
SourceRange getSourceRange() const override LLVM_READONLY;

0 commit comments

Comments
 (0)
Please sign in to comment.