Skip to content

Commit aac695d

Browse files
committed
[NFC] [Serialization] Use semantical type 'DeclID' for 'CreateDeserialized'
Previously we use 'unsigned' as the type of ID in 'CreateDeserialized'. And the type of `DeclID` in serialization is 'uint32_t', so there is minor inconsistency. Also more importantly, if we want to extend the type of DeclID from uint32_t to uint64_t, we may be in trouble due to we forgot updating the a lot of 'CreateDeserialized'. So this patch tries to use semantical type 'DeclID' for '*Decl::CreateDeserialized' to make sure it is tightly consistent.
1 parent 1412210 commit aac695d

File tree

15 files changed

+177
-173
lines changed

15 files changed

+177
-173
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class PragmaCommentDecl final
157157
SourceLocation CommentLoc,
158158
PragmaMSCommentKind CommentKind,
159159
StringRef Arg);
160-
static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID,
160+
static PragmaCommentDecl *CreateDeserialized(ASTContext &C, DeclID ID,
161161
unsigned ArgSize);
162162

163163
PragmaMSCommentKind getCommentKind() const { return CommentKind; }
@@ -192,7 +192,7 @@ class PragmaDetectMismatchDecl final
192192
SourceLocation Loc, StringRef Name,
193193
StringRef Value);
194194
static PragmaDetectMismatchDecl *
195-
CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
195+
CreateDeserialized(ASTContext &C, DeclID ID, unsigned NameValueSize);
196196

197197
StringRef getName() const { return getTrailingObjects<char>(); }
198198
StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
@@ -518,7 +518,7 @@ class LabelDecl : public NamedDecl {
518518
static LabelDecl *Create(ASTContext &C, DeclContext *DC,
519519
SourceLocation IdentL, IdentifierInfo *II,
520520
SourceLocation GnuLabelL);
521-
static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
521+
static LabelDecl *CreateDeserialized(ASTContext &C, DeclID ID);
522522

523523
LabelStmt *getStmt() const { return TheStmt; }
524524
void setStmt(LabelStmt *T) { TheStmt = T; }
@@ -581,7 +581,7 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
581581
IdentifierInfo *Id, NamespaceDecl *PrevDecl,
582582
bool Nested);
583583

584-
static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
584+
static NamespaceDecl *CreateDeserialized(ASTContext &C, DeclID ID);
585585

586586
using redecl_range = redeclarable_base::redecl_range;
587587
using redecl_iterator = redeclarable_base::redecl_iterator;
@@ -1146,7 +1146,7 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
11461146
const IdentifierInfo *Id, QualType T,
11471147
TypeSourceInfo *TInfo, StorageClass S);
11481148

1149-
static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1149+
static VarDecl *CreateDeserialized(ASTContext &C, DeclID ID);
11501150

11511151
SourceRange getSourceRange() const override LLVM_READONLY;
11521152

@@ -1728,7 +1728,7 @@ class ImplicitParamDecl : public VarDecl {
17281728
static ImplicitParamDecl *Create(ASTContext &C, QualType T,
17291729
ImplicitParamKind ParamKind);
17301730

1731-
static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1731+
static ImplicitParamDecl *CreateDeserialized(ASTContext &C, DeclID ID);
17321732

17331733
ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
17341734
const IdentifierInfo *Id, QualType Type,
@@ -1782,7 +1782,7 @@ class ParmVarDecl : public VarDecl {
17821782
TypeSourceInfo *TInfo, StorageClass S,
17831783
Expr *DefArg);
17841784

1785-
static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1785+
static ParmVarDecl *CreateDeserialized(ASTContext &C, DeclID ID);
17861786

17871787
SourceRange getSourceRange() const override LLVM_READONLY;
17881788

@@ -2178,7 +2178,7 @@ class FunctionDecl : public DeclaratorDecl,
21782178
bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
21792179
Expr *TrailingRequiresClause);
21802180

2181-
static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2181+
static FunctionDecl *CreateDeserialized(ASTContext &C, DeclID ID);
21822182

21832183
DeclarationNameInfo getNameInfo() const {
21842184
return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
@@ -3136,7 +3136,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31363136
TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
31373137
InClassInitStyle InitStyle);
31383138

3139-
static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3139+
static FieldDecl *CreateDeserialized(ASTContext &C, DeclID ID);
31403140

31413141
/// Returns the index of this field within its record,
31423142
/// as appropriate for passing to ASTRecordLayout::getFieldOffset.
@@ -3311,7 +3311,7 @@ class EnumConstantDecl : public ValueDecl,
33113311
SourceLocation L, IdentifierInfo *Id,
33123312
QualType T, Expr *E,
33133313
const llvm::APSInt &V);
3314-
static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3314+
static EnumConstantDecl *CreateDeserialized(ASTContext &C, DeclID ID);
33153315

33163316
const Expr *getInitExpr() const { return (const Expr*) Init; }
33173317
Expr *getInitExpr() { return (Expr*) Init; }
@@ -3357,7 +3357,7 @@ class IndirectFieldDecl : public ValueDecl,
33573357
QualType T,
33583358
llvm::MutableArrayRef<NamedDecl *> CH);
33593359

3360-
static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3360+
static IndirectFieldDecl *CreateDeserialized(ASTContext &C, DeclID ID);
33613361

33623362
using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;
33633363

@@ -3542,7 +3542,7 @@ class TypedefDecl : public TypedefNameDecl {
35423542
static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
35433543
SourceLocation StartLoc, SourceLocation IdLoc,
35443544
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3545-
static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3545+
static TypedefDecl *CreateDeserialized(ASTContext &C, DeclID ID);
35463546

35473547
SourceRange getSourceRange() const override LLVM_READONLY;
35483548

@@ -3567,7 +3567,7 @@ class TypeAliasDecl : public TypedefNameDecl {
35673567
static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
35683568
SourceLocation StartLoc, SourceLocation IdLoc,
35693569
const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3570-
static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3570+
static TypeAliasDecl *CreateDeserialized(ASTContext &C, DeclID ID);
35713571

35723572
SourceRange getSourceRange() const override LLVM_READONLY;
35733573

@@ -3977,7 +3977,7 @@ class EnumDecl : public TagDecl {
39773977
IdentifierInfo *Id, EnumDecl *PrevDecl,
39783978
bool IsScoped, bool IsScopedUsingClassTag,
39793979
bool IsFixed);
3980-
static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3980+
static EnumDecl *CreateDeserialized(ASTContext &C, DeclID ID);
39813981

39823982
/// Overrides to provide correct range when there's an enum-base specifier
39833983
/// with forward declarations.
@@ -4182,7 +4182,7 @@ class RecordDecl : public TagDecl {
41824182
static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
41834183
SourceLocation StartLoc, SourceLocation IdLoc,
41844184
IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4185-
static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
4185+
static RecordDecl *CreateDeserialized(const ASTContext &C, DeclID ID);
41864186

41874187
RecordDecl *getPreviousDecl() {
41884188
return cast_or_null<RecordDecl>(
@@ -4433,7 +4433,7 @@ class FileScopeAsmDecl : public Decl {
44334433
StringLiteral *Str, SourceLocation AsmLoc,
44344434
SourceLocation RParenLoc);
44354435

4436-
static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4436+
static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, DeclID ID);
44374437

44384438
SourceLocation getAsmLoc() const { return getLocation(); }
44394439
SourceLocation getRParenLoc() const { return RParenLoc; }
@@ -4469,7 +4469,7 @@ class TopLevelStmtDecl : public Decl, public DeclContext {
44694469

44704470
public:
44714471
static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4472-
static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4472+
static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, DeclID ID);
44734473

44744474
SourceRange getSourceRange() const override LLVM_READONLY;
44754475
Stmt *getStmt() { return Statement; }
@@ -4563,7 +4563,7 @@ class BlockDecl : public Decl, public DeclContext {
45634563

45644564
public:
45654565
static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
4566-
static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4566+
static BlockDecl *CreateDeserialized(ASTContext &C, DeclID ID);
45674567

45684568
SourceLocation getCaretLocation() const { return getLocation(); }
45694569

@@ -4717,7 +4717,7 @@ class CapturedDecl final
47174717

47184718
static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
47194719
unsigned NumParams);
4720-
static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4720+
static CapturedDecl *CreateDeserialized(ASTContext &C, DeclID ID,
47214721
unsigned NumParams);
47224722

47234723
Stmt *getBody() const override;
@@ -4851,7 +4851,7 @@ class ImportDecl final : public Decl,
48514851
SourceLocation EndLoc);
48524852

48534853
/// Create a new, deserialized module import declaration.
4854-
static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4854+
static ImportDecl *CreateDeserialized(ASTContext &C, DeclID ID,
48554855
unsigned NumLocations);
48564856

48574857
/// Retrieve the module that was imported by the import declaration.
@@ -4892,7 +4892,7 @@ class ExportDecl final : public Decl, public DeclContext {
48924892
public:
48934893
static ExportDecl *Create(ASTContext &C, DeclContext *DC,
48944894
SourceLocation ExportLoc);
4895-
static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4895+
static ExportDecl *CreateDeserialized(ASTContext &C, DeclID ID);
48964896

48974897
SourceLocation getExportLoc() const { return getLocation(); }
48984898
SourceLocation getRBraceLoc() const { return RBraceLoc; }
@@ -4931,7 +4931,7 @@ class EmptyDecl : public Decl {
49314931
public:
49324932
static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
49334933
SourceLocation L);
4934-
static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4934+
static EmptyDecl *CreateDeserialized(ASTContext &C, DeclID ID);
49354935

49364936
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
49374937
static bool classofKind(Kind K) { return K == Empty; }
@@ -4957,7 +4957,7 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
49574957
bool CBuffer, SourceLocation KwLoc,
49584958
IdentifierInfo *ID, SourceLocation IDLoc,
49594959
SourceLocation LBrace);
4960-
static HLSLBufferDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4960+
static HLSLBufferDecl *CreateDeserialized(ASTContext &C, DeclID ID);
49614961

49624962
SourceRange getSourceRange() const override LLVM_READONLY {
49634963
return SourceRange(getLocStart(), RBraceLoc);

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ class alignas(8) Decl {
349349
LLVM_PREFERRED_TYPE(Linkage)
350350
mutable unsigned CacheValidAndLinkage : 3;
351351

352+
using DeclID = uint32_t;
353+
352354
/// Allocate memory for a deserialized declaration.
353355
///
354356
/// This routine must be used to allocate memory for any declaration that is
@@ -358,7 +360,7 @@ class alignas(8) Decl {
358360
/// \param Ctx The context in which we will allocate memory.
359361
/// \param ID The global ID of the deserialized declaration.
360362
/// \param Extra The amount of extra space to allocate after the object.
361-
void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID,
363+
void *operator new(std::size_t Size, const ASTContext &Ctx, DeclID ID,
362364
std::size_t Extra = 0);
363365

364366
/// Allocate memory for a non-deserialized declaration.

0 commit comments

Comments
 (0)