[clang] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (PR #89873)
https://github.com/ChuanqiXu9 closed https://github.com/llvm/llvm-project/pull/89873 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (PR #89873)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/89873 >From d83b9cda6c7d943e90c324fa2c1c7e7ffaf88e1c Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 24 Apr 2024 13:35:01 +0800 Subject: [PATCH] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h Previously, the DeclID is defined in serialization/ASTBitCodes.h under clang::serialization namespace. However, actually the DeclID is not purely used in serialization part. The DeclID is already widely used in AST and all around the clang project via classes like `LazyPtrDecl` or calling `ExternalASTSource::getExernalDecl()`. All such uses are via the raw underlying type of `DeclID` as `uint32_t`. This is not pretty good. This patch moves the DeclID class family to a new header `AST/DeclID.h` so that the whole project can use the wrapped class `DeclID`, `GlobalDeclID` and `LocalDeclID` instead of the raw underlying type. This can improve the readability and the type safety. --- clang/include/clang/AST/ASTContext.h | 4 +- clang/include/clang/AST/DeclBase.h| 4 +- clang/include/clang/AST/DeclID.h | 177 ++ clang/include/clang/AST/DeclTemplate.h| 2 +- clang/include/clang/AST/ExternalASTSource.h | 4 +- clang/include/clang/Frontend/ASTUnit.h| 2 +- .../clang/Frontend/MultiplexConsumer.h| 2 +- .../clang/Sema/MultiplexExternalSemaSource.h | 2 +- .../include/clang/Serialization/ASTBitCodes.h | 161 +--- .../ASTDeserializationListener.h | 2 +- clang/include/clang/Serialization/ASTReader.h | 126 ++--- .../clang/Serialization/ASTRecordReader.h | 6 +- clang/include/clang/Serialization/ASTWriter.h | 22 +-- .../include/clang/Serialization/ModuleFile.h | 8 +- clang/lib/AST/ASTContext.cpp | 3 +- clang/lib/AST/Decl.cpp| 46 ++--- clang/lib/AST/DeclBase.cpp| 4 +- clang/lib/AST/DeclCXX.cpp | 63 +++ clang/lib/AST/DeclFriend.cpp | 2 +- clang/lib/AST/DeclObjC.cpp| 24 +-- clang/lib/AST/DeclOpenMP.cpp | 18 +- clang/lib/AST/DeclTemplate.cpp| 41 ++-- clang/lib/AST/ExternalASTSource.cpp | 2 +- clang/lib/Frontend/ASTUnit.cpp| 4 +- clang/lib/Frontend/FrontendAction.cpp | 6 +- clang/lib/Frontend/MultiplexConsumer.cpp | 3 +- .../lib/Sema/MultiplexExternalSemaSource.cpp | 2 +- clang/lib/Serialization/ASTReader.cpp | 16 +- clang/lib/Serialization/ASTReaderDecl.cpp | 18 +- clang/lib/Serialization/ASTWriter.cpp | 4 +- clang/lib/Serialization/ASTWriterDecl.cpp | 4 +- 31 files changed, 384 insertions(+), 398 deletions(-) create mode 100644 clang/include/clang/AST/DeclID.h diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index d5ed20ff50157d..ecec9bfcf30079 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -455,7 +455,7 @@ class ASTContext : public RefCountedBase { /// initialization of another module). struct PerModuleInitializers { llvm::SmallVector Initializers; -llvm::SmallVector LazyInitializers; +llvm::SmallVector LazyInitializers; void resolve(ASTContext ); }; @@ -1059,7 +1059,7 @@ class ASTContext : public RefCountedBase { /// or an ImportDecl nominating another module that has initializers. void addModuleInitializer(Module *M, Decl *Init); - void addLazyModuleInitializers(Module *M, ArrayRef IDs); + void addLazyModuleInitializers(Module *M, ArrayRef IDs); /// Get the initializations to perform when importing a module, if any. ArrayRef getModuleInitializers(Module *M); diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index d8cafc3d81526e..474e51c1df6d68 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -15,6 +15,7 @@ #include "clang/AST/ASTDumperUtils.h" #include "clang/AST/AttrIterator.h" +#include "clang/AST/DeclID.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/SelectorLocationsKind.h" #include "clang/Basic/IdentifierTable.h" @@ -239,9 +240,6 @@ class alignas(8) Decl { ModulePrivate }; - /// An ID number that refers to a declaration in an AST file. - using DeclID = uint32_t; - protected: /// The next declaration within the same lexical /// DeclContext. These pointers form the linked list that is diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h new file mode 100644 index 00..e2c6dd65e86bc3 --- /dev/null +++ b/clang/include/clang/AST/DeclID.h @@ -0,0 +1,177 @@ +//===--- DeclID.h - ID number for deserialized declarations *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See
[clang] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (PR #89873)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Chuanqi Xu (ChuanqiXu9) Changes Previously, the DeclID is defined in serialization/ASTBitCodes.h under clang::serialization namespace. However, actually the DeclID is not purely used in serialization part. The DeclID is already widely used in AST and all around the clang project via classes like `LazyPtrDecl` or calling `ExternalASTSource::getExernalDecl()`. All such uses are via the raw underlying type of `DeclID` as `uint32_t`. This is not pretty good. This patch moves the DeclID class family to a new header `AST/DeclID.h` so that the whole project can use the wrapped class `DeclID`, `GlobalDeclID` and `LocalDeclID` instead of the raw underlying type. This can improve the readability and the type safety. --- Patch is 93.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/89873.diff 31 Files Affected: - (modified) clang/include/clang/AST/ASTContext.h (+2-2) - (modified) clang/include/clang/AST/DeclBase.h (+1-3) - (added) clang/include/clang/AST/DeclID.h (+175) - (modified) clang/include/clang/AST/DeclTemplate.h (+1-1) - (modified) clang/include/clang/AST/ExternalASTSource.h (+2-2) - (modified) clang/include/clang/Frontend/ASTUnit.h (+1-1) - (modified) clang/include/clang/Frontend/MultiplexConsumer.h (+1-1) - (modified) clang/include/clang/Sema/MultiplexExternalSemaSource.h (+1-1) - (modified) clang/include/clang/Serialization/ASTBitCodes.h (+4-157) - (modified) clang/include/clang/Serialization/ASTDeserializationListener.h (+1-1) - (modified) clang/include/clang/Serialization/ASTReader.h (+54-72) - (modified) clang/include/clang/Serialization/ASTRecordReader.h (+2-4) - (modified) clang/include/clang/Serialization/ASTWriter.h (+10-12) - (modified) clang/include/clang/Serialization/ModuleFile.h (+4-4) - (modified) clang/lib/AST/ASTContext.cpp (+1-2) - (modified) clang/lib/AST/Decl.cpp (+23-23) - (modified) clang/lib/AST/DeclBase.cpp (+2-2) - (modified) clang/lib/AST/DeclCXX.cpp (+30-33) - (modified) clang/lib/AST/DeclFriend.cpp (+1-1) - (modified) clang/lib/AST/DeclObjC.cpp (+12-12) - (modified) clang/lib/AST/DeclOpenMP.cpp (+8-10) - (modified) clang/lib/AST/DeclTemplate.cpp (+19-22) - (modified) clang/lib/AST/ExternalASTSource.cpp (+1-1) - (modified) clang/lib/Frontend/ASTUnit.cpp (+2-2) - (modified) clang/lib/Frontend/FrontendAction.cpp (+3-3) - (modified) clang/lib/Frontend/MultiplexConsumer.cpp (+1-2) - (modified) clang/lib/Sema/MultiplexExternalSemaSource.cpp (+1-1) - (modified) clang/lib/Serialization/ASTReader.cpp (+7-9) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+8-10) - (modified) clang/lib/Serialization/ASTWriter.cpp (+2-2) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+2-2) ``diff diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index d5ed20ff50157d..ecec9bfcf30079 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -455,7 +455,7 @@ class ASTContext : public RefCountedBase { /// initialization of another module). struct PerModuleInitializers { llvm::SmallVector Initializers; -llvm::SmallVector LazyInitializers; +llvm::SmallVector LazyInitializers; void resolve(ASTContext ); }; @@ -1059,7 +1059,7 @@ class ASTContext : public RefCountedBase { /// or an ImportDecl nominating another module that has initializers. void addModuleInitializer(Module *M, Decl *Init); - void addLazyModuleInitializers(Module *M, ArrayRef IDs); + void addLazyModuleInitializers(Module *M, ArrayRef IDs); /// Get the initializations to perform when importing a module, if any. ArrayRef getModuleInitializers(Module *M); diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index d8cafc3d81526e..474e51c1df6d68 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -15,6 +15,7 @@ #include "clang/AST/ASTDumperUtils.h" #include "clang/AST/AttrIterator.h" +#include "clang/AST/DeclID.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/SelectorLocationsKind.h" #include "clang/Basic/IdentifierTable.h" @@ -239,9 +240,6 @@ class alignas(8) Decl { ModulePrivate }; - /// An ID number that refers to a declaration in an AST file. - using DeclID = uint32_t; - protected: /// The next declaration within the same lexical /// DeclContext. These pointers form the linked list that is diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h new file mode 100644 index 00..37e40e198f2776 --- /dev/null +++ b/clang/include/clang/AST/DeclID.h @@ -0,0 +1,175 @@ +//===--- DeclID.h - ID number for deserialized declarations *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +//
[clang] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (PR #89873)
https://github.com/ChuanqiXu9 ready_for_review https://github.com/llvm/llvm-project/pull/89873 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (PR #89873)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/89873 Previously, the DeclID is defined in serialization/ASTBitCodes.h under clang::serialization namespace. However, actually the DeclID is not purely used in serialization part. The DeclID is already widely used in AST and all around the clang project via classes like `LazyPtrDecl` or calling `ExternalASTSource::getExernalDecl()`. All such uses are via the raw underlying type of `DeclID` as `uint32_t`. This is not pretty good. This patch moves the DeclID class family to a new header `AST/DeclID.h` so that the whole project can use the wrapped class `DeclID`, `GlobalDeclID` and `LocalDeclID` instead of the raw underlying type. This can improve the readability and the type safety. >From 3c8e76dcf7746d7ede5434e0fbf025802590bd68 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 24 Apr 2024 13:35:01 +0800 Subject: [PATCH] [NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h Previously, the DeclID is defined in serialization/ASTBitCodes.h under clang::serialization namespace. However, actually the DeclID is not purely used in serialization part. The DeclID is already widely used in AST and all around the clang project via classes like `LazyPtrDecl` or calling `ExternalASTSource::getExernalDecl()`. All such uses are via the raw underlying type of `DeclID` as `uint32_t`. This is not pretty good. This patch moves the DeclID class family to a new header `AST/DeclID.h` so that the whole project can use the wrapped class `DeclID`, `GlobalDeclID` and `LocalDeclID` instead of the raw underlying type. This can improve the readability and the type safety. --- clang/include/clang/AST/ASTContext.h | 4 +- clang/include/clang/AST/DeclBase.h| 4 +- clang/include/clang/AST/DeclID.h | 175 ++ clang/include/clang/AST/DeclTemplate.h| 2 +- clang/include/clang/AST/ExternalASTSource.h | 4 +- clang/include/clang/Frontend/ASTUnit.h| 2 +- .../clang/Frontend/MultiplexConsumer.h| 2 +- .../clang/Sema/MultiplexExternalSemaSource.h | 2 +- .../include/clang/Serialization/ASTBitCodes.h | 161 +--- .../ASTDeserializationListener.h | 2 +- clang/include/clang/Serialization/ASTReader.h | 126 ++--- .../clang/Serialization/ASTRecordReader.h | 6 +- clang/include/clang/Serialization/ASTWriter.h | 22 +-- .../include/clang/Serialization/ModuleFile.h | 8 +- clang/lib/AST/ASTContext.cpp | 3 +- clang/lib/AST/Decl.cpp| 46 ++--- clang/lib/AST/DeclBase.cpp| 4 +- clang/lib/AST/DeclCXX.cpp | 63 +++ clang/lib/AST/DeclFriend.cpp | 2 +- clang/lib/AST/DeclObjC.cpp| 24 +-- clang/lib/AST/DeclOpenMP.cpp | 18 +- clang/lib/AST/DeclTemplate.cpp| 41 ++-- clang/lib/AST/ExternalASTSource.cpp | 2 +- clang/lib/Frontend/ASTUnit.cpp| 4 +- clang/lib/Frontend/FrontendAction.cpp | 6 +- clang/lib/Frontend/MultiplexConsumer.cpp | 3 +- .../lib/Sema/MultiplexExternalSemaSource.cpp | 2 +- clang/lib/Serialization/ASTReader.cpp | 16 +- clang/lib/Serialization/ASTReaderDecl.cpp | 18 +- clang/lib/Serialization/ASTWriter.cpp | 4 +- clang/lib/Serialization/ASTWriterDecl.cpp | 4 +- 31 files changed, 382 insertions(+), 398 deletions(-) create mode 100644 clang/include/clang/AST/DeclID.h diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index d5ed20ff50157d..ecec9bfcf30079 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -455,7 +455,7 @@ class ASTContext : public RefCountedBase { /// initialization of another module). struct PerModuleInitializers { llvm::SmallVector Initializers; -llvm::SmallVector LazyInitializers; +llvm::SmallVector LazyInitializers; void resolve(ASTContext ); }; @@ -1059,7 +1059,7 @@ class ASTContext : public RefCountedBase { /// or an ImportDecl nominating another module that has initializers. void addModuleInitializer(Module *M, Decl *Init); - void addLazyModuleInitializers(Module *M, ArrayRef IDs); + void addLazyModuleInitializers(Module *M, ArrayRef IDs); /// Get the initializations to perform when importing a module, if any. ArrayRef getModuleInitializers(Module *M); diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index d8cafc3d81526e..474e51c1df6d68 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -15,6 +15,7 @@ #include "clang/AST/ASTDumperUtils.h" #include "clang/AST/AttrIterator.h" +#include "clang/AST/DeclID.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/SelectorLocationsKind.h" #include