Skip to content

Commit 31d597d

Browse files
committed
[clang-doc] Reorder struct fields to have less padding
1 parent d055754 commit 31d597d

File tree

2 files changed

+68
-62
lines changed

2 files changed

+68
-62
lines changed

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
400400
BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
401401
bool IsVirtual, AccessSpecifier Access,
402402
bool IsParent)
403-
: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
403+
: RecordInfo(USR, Name, Path), Access(Access), IsVirtual(IsVirtual),
404404
IsParent(IsParent) {}
405405

406406
llvm::SmallString<16> Info::extractName() const {

clang-tools-extra/clang-doc/Representation.h

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
#include "clang/AST/Type.h"
1818
#include "clang/Basic/Diagnostic.h"
1919
#include "clang/Basic/Specifiers.h"
20-
#include "clang/Tooling/StandaloneExecution.h"
21-
#include "llvm/ADT/APSInt.h"
20+
#include "clang/Tooling/Execution.h"
2221
#include "llvm/ADT/SmallVector.h"
23-
#include "llvm/ADT/StringExtras.h"
2422
#include <array>
2523
#include <optional>
2624
#include <string>
@@ -88,29 +86,29 @@ struct CommentInfo {
8886
// the vector.
8987
bool operator<(const CommentInfo &Other) const;
9088

91-
CommentKind Kind = CommentKind::
92-
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
93-
// TextComment, InlineCommandComment, HTMLStartTagComment,
94-
// HTMLEndTagComment, BlockCommandComment,
95-
// ParamCommandComment, TParamCommandComment,
96-
// VerbatimBlockComment, VerbatimBlockLineComment,
97-
// VerbatimLineComment).
98-
SmallString<64> Text; // Text of the comment.
99-
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
89+
std::vector<std::unique_ptr<CommentInfo>>
90+
Children; // List of child comments for this CommentInfo.
10091
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
92+
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
10193
SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
10294
SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
103-
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
104-
bool Explicit = false; // Indicates if the direction of a param is explicit
105-
// (for (T)ParamCommand).
95+
SmallString<64> Text; // Text of the comment.
10696
llvm::SmallVector<SmallString<16>, 4>
10797
AttrKeys; // List of attribute keys (for HTML).
10898
llvm::SmallVector<SmallString<16>, 4>
10999
AttrValues; // List of attribute values for each key (for HTML).
110100
llvm::SmallVector<SmallString<16>, 4>
111101
Args; // List of arguments to commands (for InlineCommand).
112-
std::vector<std::unique_ptr<CommentInfo>>
113-
Children; // List of child comments for this CommentInfo.
102+
CommentKind Kind = CommentKind::
103+
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
104+
// TextComment, InlineCommandComment, HTMLStartTagComment,
105+
// HTMLEndTagComment, BlockCommandComment,
106+
// ParamCommandComment, TParamCommandComment,
107+
// VerbatimBlockComment, VerbatimBlockLineComment,
108+
// VerbatimLineComment).
109+
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
110+
bool Explicit = false; // Indicates if the direction of a param is explicit
111+
// (for (T)ParamCommand).
114112
};
115113

116114
struct Reference {
@@ -121,13 +119,13 @@ struct Reference {
121119
// "GlobalNamespace" as the name, but an empty QualName).
122120
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
123121
InfoType IT = InfoType::IT_default)
124-
: USR(USR), Name(Name), QualName(Name), RefType(IT) {}
122+
: USR(USR), RefType(IT), Name(Name), QualName(Name) {}
125123
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
126124
StringRef Path = StringRef())
127-
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
125+
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path) {}
128126
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
129127
StringRef Path, SmallString<16> DocumentationFileName)
130-
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
128+
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path),
131129
DocumentationFileName(DocumentationFileName) {}
132130

133131
bool operator==(const Reference &Other) const {
@@ -147,6 +145,10 @@ struct Reference {
147145

148146
SymbolID USR = SymbolID(); // Unique identifier for referenced decl
149147

148+
InfoType RefType = InfoType::IT_default; // Indicates the type of this
149+
// Reference (namespace, record,
150+
// function, enum, default).
151+
150152
// Name of type (possibly unresolved). Not including namespaces or template
151153
// parameters (so for a std::vector<int> this would be "vector"). See also
152154
// QualName.
@@ -157,9 +159,6 @@ struct Reference {
157159
// Name.
158160
SmallString<16> QualName;
159161

160-
InfoType RefType = InfoType::IT_default; // Indicates the type of this
161-
// Reference (namespace, record,
162-
// function, enum, default).
163162
// Path of directory where the clang-doc generated file will be saved
164163
// (possibly unresolved)
165164
llvm::SmallString<128> Path;
@@ -279,21 +278,21 @@ struct MemberTypeInfo : public FieldTypeInfo {
279278
Other.Description);
280279
}
281280

281+
std::vector<CommentInfo> Description;
282+
282283
// Access level associated with this info (public, protected, private, none).
283284
// AS_public is set as default because the bitcode writer requires the enum
284285
// with value 0 to be used as the default.
285286
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
286287
AccessSpecifier Access = AccessSpecifier::AS_public;
287-
288-
std::vector<CommentInfo> Description; // Comment description of this field.
289288
bool IsStatic = false;
290289
};
291290

292291
struct Location {
293292
Location(int StartLineNumber = 0, int EndLineNumber = 0,
294293
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
295-
: StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
296-
Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
294+
: Filename(Filename), StartLineNumber(StartLineNumber),
295+
EndLineNumber(EndLineNumber), IsFileInRootDir(IsFileInRootDir) {}
297296

298297
bool operator==(const Location &Other) const {
299298
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
@@ -311,40 +310,24 @@ struct Location {
311310
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
312311
}
313312

314-
int StartLineNumber = 0; // Line number of this Location.
313+
SmallString<32> Filename;
314+
int StartLineNumber = 0;
315315
int EndLineNumber = 0;
316-
SmallString<32> Filename; // File for this Location.
317-
bool IsFileInRootDir = false; // Indicates if file is inside root directory
316+
bool IsFileInRootDir = false;
318317
};
319318

320319
/// A base struct for Infos.
321320
struct Info {
322321
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(),
323322
StringRef Name = StringRef(), StringRef Path = StringRef())
324-
: USR(USR), IT(IT), Name(Name), Path(Path) {}
323+
: Path(Path), Name(Name), USR(USR), IT(IT) {}
325324

326325
Info(const Info &Other) = delete;
327326
Info(Info &&Other) = default;
328-
329327
virtual ~Info() = default;
330328

331329
Info &operator=(Info &&Other) = default;
332330

333-
SymbolID USR =
334-
SymbolID(); // Unique identifier for the decl described by this Info.
335-
InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
336-
SmallString<16> Name; // Unqualified name of the decl.
337-
llvm::SmallVector<Reference, 4>
338-
Namespace; // List of parent namespaces for this decl.
339-
std::vector<CommentInfo> Description; // Comment description of this decl.
340-
llvm::SmallString<128> Path; // Path of directory where the clang-doc
341-
// generated file will be saved
342-
343-
// The name used for the file that this info is documented in.
344-
// In the JSON generator, infos are documented in files with mangled names.
345-
// Thus, we keep track of the physical filename for linking purposes.
346-
SmallString<16> DocumentationFileName;
347-
348331
void mergeBase(Info &&I);
349332
bool mergeable(const Info &Other);
350333

@@ -355,6 +338,29 @@ struct Info {
355338

356339
/// Returns the basename that should be used for this Info.
357340
llvm::SmallString<16> getFileBaseName() const;
341+
342+
// Path of directory where the clang-doc generated file will be saved.
343+
llvm::SmallString<128> Path;
344+
345+
// Unqualified name of the decl.
346+
SmallString<16> Name;
347+
348+
// The name used for the file that this info is documented in.
349+
// In the JSON generator, infos are documented in files with mangled names.
350+
// Thus, we keep track of the physical filename for linking purposes.
351+
SmallString<16> DocumentationFileName;
352+
353+
// List of parent namespaces for this decl.
354+
llvm::SmallVector<Reference, 4> Namespace;
355+
356+
// Unique identifier for the decl described by this Info.
357+
SymbolID USR = SymbolID();
358+
359+
// InfoType of this particular Info.
360+
InfoType IT = InfoType::IT_default;
361+
362+
// Comment description of this decl.
363+
std::vector<CommentInfo> Description;
358364
};
359365

360366
// Info for namespaces.
@@ -428,21 +434,21 @@ struct FunctionInfo : public SymbolInfo {
428434

429435
void merge(FunctionInfo &&I);
430436

431-
bool IsMethod = false; // Indicates whether this function is a class method.
432-
Reference Parent; // Reference to the parent class decl for this method.
433-
TypeInfo ReturnType; // Info about the return type of this function.
434-
llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
437+
Reference Parent;
438+
TypeInfo ReturnType;
439+
llvm::SmallVector<FieldTypeInfo, 4> Params;
440+
SmallString<256> Prototype;
441+
442+
// When present, this function is a template or specialization.
443+
std::optional<TemplateInfo> Template;
444+
435445
// Access level for this method (public, private, protected, none).
436446
// AS_public is set as default because the bitcode writer requires the enum
437447
// with value 0 to be used as the default.
438448
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
439449
AccessSpecifier Access = AccessSpecifier::AS_public;
440450

441-
// Function Prototype
442-
SmallString<256> Prototype;
443-
444-
// When present, this function is a template or specialization.
445-
std::optional<TemplateInfo> Template;
451+
bool IsMethod = false;
446452
};
447453

448454
// TODO: Expand to allow for documenting templating, inheritance access,
@@ -457,15 +463,15 @@ struct RecordInfo : public SymbolInfo {
457463
// Type of this record (struct, class, union, interface).
458464
TagTypeKind TagType = TagTypeKind::Struct;
459465

460-
// When present, this record is a template or specialization.
461-
std::optional<TemplateInfo> Template;
462-
463466
// Indicates if the record was declared using a typedef. Things like anonymous
464467
// structs in a typedef:
465468
// typedef struct { ... } foo_t;
466469
// are converted into records with the typedef as the Name + this flag set.
467470
bool IsTypeDef = false;
468471

472+
// When present, this record is a template or specialization.
473+
std::optional<TemplateInfo> Template;
474+
469475
llvm::SmallVector<MemberTypeInfo, 4>
470476
Members; // List of info about record members.
471477
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
@@ -510,11 +516,11 @@ struct BaseRecordInfo : public RecordInfo {
510516
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
511517
AccessSpecifier Access, bool IsParent);
512518

513-
// Indicates if base corresponds to a virtual inheritance
514-
bool IsVirtual = false;
515519
// Access level associated with this inherited info (public, protected,
516520
// private).
517521
AccessSpecifier Access = AccessSpecifier::AS_public;
522+
// Indicates if base corresponds to a virtual inheritance
523+
bool IsVirtual = false;
518524
bool IsParent = false; // Indicates if this base is a direct parent
519525
};
520526

0 commit comments

Comments
 (0)