Skip to content

Conversation

@ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Dec 1, 2025

No description provided.

Copy link
Contributor Author

ilovepi commented Dec 1, 2025

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/170222.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Representation.cpp (+1-1)
  • (modified) clang-tools-extra/clang-doc/Representation.h (+67-61)
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
 };
 

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

🐧 Linux x64 Test Results

  • 3053 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

@ilovepi ilovepi force-pushed the users/ilovepi/cd-struct-fields branch from 31d597d to ddbd817 Compare December 1, 2025 23:29
@ilovepi ilovepi force-pushed the users/ilovepi/cd-statics branch from d055754 to 69bec00 Compare December 1, 2025 23:29
@ilovepi ilovepi force-pushed the users/ilovepi/cd-struct-fields branch from ddbd817 to bc90314 Compare December 3, 2025 22:09
@ilovepi ilovepi force-pushed the users/ilovepi/cd-statics branch from 69bec00 to 05abefd Compare December 3, 2025 22:09
@ilovepi ilovepi force-pushed the users/ilovepi/cd-statics branch from 05abefd to 3faef54 Compare December 4, 2025 23:38
@ilovepi ilovepi force-pushed the users/ilovepi/cd-struct-fields branch from bc90314 to 3d5418a Compare December 4, 2025 23:38
Base automatically changed from users/ilovepi/cd-statics to main December 4, 2025 23:45
@ilovepi ilovepi merged commit a2032f5 into main Dec 5, 2025
11 of 16 checks passed
@ilovepi ilovepi deleted the users/ilovepi/cd-struct-fields branch December 5, 2025 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants