-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-doc] Reorder struct fields to have less padding #170222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Member
|
@llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) ChangesFull diff: https://github.com/llvm/llvm-project/pull/170222.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 073ed83fff6d7..4cc94fa167545 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -400,7 +400,7 @@ BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
bool IsVirtual, AccessSpecifier Access,
bool IsParent)
- : RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
+ : RecordInfo(USR, Name, Path), Access(Access), IsVirtual(IsVirtual),
IsParent(IsParent) {}
llvm::SmallString<16> Info::extractName() const {
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index a13beab0b0c3a..a3e779aa39bc4 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -17,10 +17,8 @@
#include "clang/AST/Type.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/Specifiers.h"
-#include "clang/Tooling/StandaloneExecution.h"
-#include "llvm/ADT/APSInt.h"
+#include "clang/Tooling/Execution.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
#include <array>
#include <optional>
#include <string>
@@ -88,29 +86,29 @@ struct CommentInfo {
// the vector.
bool operator<(const CommentInfo &Other) const;
- CommentKind Kind = CommentKind::
- CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
- // TextComment, InlineCommandComment, HTMLStartTagComment,
- // HTMLEndTagComment, BlockCommandComment,
- // ParamCommandComment, TParamCommandComment,
- // VerbatimBlockComment, VerbatimBlockLineComment,
- // VerbatimLineComment).
- SmallString<64> Text; // Text of the comment.
- SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
+ std::vector<std::unique_ptr<CommentInfo>>
+ Children; // List of child comments for this CommentInfo.
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
+ SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
- bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
- bool Explicit = false; // Indicates if the direction of a param is explicit
- // (for (T)ParamCommand).
+ SmallString<64> Text; // Text of the comment.
llvm::SmallVector<SmallString<16>, 4>
AttrKeys; // List of attribute keys (for HTML).
llvm::SmallVector<SmallString<16>, 4>
AttrValues; // List of attribute values for each key (for HTML).
llvm::SmallVector<SmallString<16>, 4>
Args; // List of arguments to commands (for InlineCommand).
- std::vector<std::unique_ptr<CommentInfo>>
- Children; // List of child comments for this CommentInfo.
+ CommentKind Kind = CommentKind::
+ CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
+ // TextComment, InlineCommandComment, HTMLStartTagComment,
+ // HTMLEndTagComment, BlockCommandComment,
+ // ParamCommandComment, TParamCommandComment,
+ // VerbatimBlockComment, VerbatimBlockLineComment,
+ // VerbatimLineComment).
+ bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
+ bool Explicit = false; // Indicates if the direction of a param is explicit
+ // (for (T)ParamCommand).
};
struct Reference {
@@ -121,13 +119,13 @@ struct Reference {
// "GlobalNamespace" as the name, but an empty QualName).
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
InfoType IT = InfoType::IT_default)
- : USR(USR), Name(Name), QualName(Name), RefType(IT) {}
+ : USR(USR), RefType(IT), Name(Name), QualName(Name) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path = StringRef())
- : USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
+ : USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path, SmallString<16> DocumentationFileName)
- : USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
+ : USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path),
DocumentationFileName(DocumentationFileName) {}
bool operator==(const Reference &Other) const {
@@ -147,6 +145,10 @@ struct Reference {
SymbolID USR = SymbolID(); // Unique identifier for referenced decl
+ InfoType RefType = InfoType::IT_default; // Indicates the type of this
+ // Reference (namespace, record,
+ // function, enum, default).
+
// Name of type (possibly unresolved). Not including namespaces or template
// parameters (so for a std::vector<int> this would be "vector"). See also
// QualName.
@@ -157,9 +159,6 @@ struct Reference {
// Name.
SmallString<16> QualName;
- InfoType RefType = InfoType::IT_default; // Indicates the type of this
- // Reference (namespace, record,
- // function, enum, default).
// Path of directory where the clang-doc generated file will be saved
// (possibly unresolved)
llvm::SmallString<128> Path;
@@ -279,21 +278,21 @@ struct MemberTypeInfo : public FieldTypeInfo {
Other.Description);
}
+ std::vector<CommentInfo> Description;
+
// Access level associated with this info (public, protected, private, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;
-
- std::vector<CommentInfo> Description; // Comment description of this field.
bool IsStatic = false;
};
struct Location {
Location(int StartLineNumber = 0, int EndLineNumber = 0,
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
- : StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
- Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
+ : Filename(Filename), StartLineNumber(StartLineNumber),
+ EndLineNumber(EndLineNumber), IsFileInRootDir(IsFileInRootDir) {}
bool operator==(const Location &Other) const {
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
@@ -311,40 +310,24 @@ struct Location {
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
}
- int StartLineNumber = 0; // Line number of this Location.
+ SmallString<32> Filename;
+ int StartLineNumber = 0;
int EndLineNumber = 0;
- SmallString<32> Filename; // File for this Location.
- bool IsFileInRootDir = false; // Indicates if file is inside root directory
+ bool IsFileInRootDir = false;
};
/// A base struct for Infos.
struct Info {
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(),
StringRef Name = StringRef(), StringRef Path = StringRef())
- : USR(USR), IT(IT), Name(Name), Path(Path) {}
+ : Path(Path), Name(Name), USR(USR), IT(IT) {}
Info(const Info &Other) = delete;
Info(Info &&Other) = default;
-
virtual ~Info() = default;
Info &operator=(Info &&Other) = default;
- SymbolID USR =
- SymbolID(); // Unique identifier for the decl described by this Info.
- InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
- SmallString<16> Name; // Unqualified name of the decl.
- llvm::SmallVector<Reference, 4>
- Namespace; // List of parent namespaces for this decl.
- std::vector<CommentInfo> Description; // Comment description of this decl.
- llvm::SmallString<128> Path; // Path of directory where the clang-doc
- // generated file will be saved
-
- // The name used for the file that this info is documented in.
- // In the JSON generator, infos are documented in files with mangled names.
- // Thus, we keep track of the physical filename for linking purposes.
- SmallString<16> DocumentationFileName;
-
void mergeBase(Info &&I);
bool mergeable(const Info &Other);
@@ -355,6 +338,29 @@ struct Info {
/// Returns the basename that should be used for this Info.
llvm::SmallString<16> getFileBaseName() const;
+
+ // Path of directory where the clang-doc generated file will be saved.
+ llvm::SmallString<128> Path;
+
+ // Unqualified name of the decl.
+ SmallString<16> Name;
+
+ // The name used for the file that this info is documented in.
+ // In the JSON generator, infos are documented in files with mangled names.
+ // Thus, we keep track of the physical filename for linking purposes.
+ SmallString<16> DocumentationFileName;
+
+ // List of parent namespaces for this decl.
+ llvm::SmallVector<Reference, 4> Namespace;
+
+ // Unique identifier for the decl described by this Info.
+ SymbolID USR = SymbolID();
+
+ // InfoType of this particular Info.
+ InfoType IT = InfoType::IT_default;
+
+ // Comment description of this decl.
+ std::vector<CommentInfo> Description;
};
// Info for namespaces.
@@ -428,21 +434,21 @@ struct FunctionInfo : public SymbolInfo {
void merge(FunctionInfo &&I);
- bool IsMethod = false; // Indicates whether this function is a class method.
- Reference Parent; // Reference to the parent class decl for this method.
- TypeInfo ReturnType; // Info about the return type of this function.
- llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
+ Reference Parent;
+ TypeInfo ReturnType;
+ llvm::SmallVector<FieldTypeInfo, 4> Params;
+ SmallString<256> Prototype;
+
+ // When present, this function is a template or specialization.
+ std::optional<TemplateInfo> Template;
+
// Access level for this method (public, private, protected, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;
- // Function Prototype
- SmallString<256> Prototype;
-
- // When present, this function is a template or specialization.
- std::optional<TemplateInfo> Template;
+ bool IsMethod = false;
};
// TODO: Expand to allow for documenting templating, inheritance access,
@@ -457,15 +463,15 @@ struct RecordInfo : public SymbolInfo {
// Type of this record (struct, class, union, interface).
TagTypeKind TagType = TagTypeKind::Struct;
- // When present, this record is a template or specialization.
- std::optional<TemplateInfo> Template;
-
// Indicates if the record was declared using a typedef. Things like anonymous
// structs in a typedef:
// typedef struct { ... } foo_t;
// are converted into records with the typedef as the Name + this flag set.
bool IsTypeDef = false;
+ // When present, this record is a template or specialization.
+ std::optional<TemplateInfo> Template;
+
llvm::SmallVector<MemberTypeInfo, 4>
Members; // List of info about record members.
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
@@ -510,11 +516,11 @@ struct BaseRecordInfo : public RecordInfo {
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
AccessSpecifier Access, bool IsParent);
- // Indicates if base corresponds to a virtual inheritance
- bool IsVirtual = false;
// Access level associated with this inherited info (public, protected,
// private).
AccessSpecifier Access = AccessSpecifier::AS_public;
+ // Indicates if base corresponds to a virtual inheritance
+ bool IsVirtual = false;
bool IsParent = false; // Indicates if this base is a direct parent
};
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
31d597d to
ddbd817
Compare
d055754 to
69bec00
Compare
ddbd817 to
bc90314
Compare
69bec00 to
05abefd
Compare
petrhosek
approved these changes
Dec 4, 2025
evelez7
approved these changes
Dec 4, 2025
05abefd to
3faef54
Compare
bc90314 to
3d5418a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

No description provided.