Skip to content

[clang-doc] Track if a type is a template or builtin #138067

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 1 commit into from
May 28, 2025

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented May 1, 2025

Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou [email protected]

@ilovepi ilovepi requested a review from PeterChou1 May 1, 2025 00:59
@ilovepi ilovepi marked this pull request as ready for review May 1, 2025 00:59
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

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

Author: Paul Kirth (ilovepi)

Changes

Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou <[email protected]>


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Representation.h (+3)
  • (modified) clang-tools-extra/clang-doc/Serialize.cpp (+12-5)
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 89e264f541a76..4d34109c399da 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -163,6 +163,9 @@ struct TypeInfo {
   bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
 
   Reference Type; // Referenced type in this info.
+
+  bool IsTemplate = false;
+  bool IsBuiltIn = false;
 };
 
 // Represents one template parameter.
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 21cf44c1ccd35..c6ca43d148440 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -424,9 +424,12 @@ static RecordDecl *getRecordDeclForType(const QualType &T) {
 static TypeInfo getTypeInfoForType(const QualType &T,
                                    const PrintingPolicy &Policy) {
   const TagDecl *TD = getTagDeclForType(T);
-  if (!TD)
-    return TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
-
+  if (!TD) {
+    TypeInfo TI = TypeInfo(Reference(SymbolID(), T.getAsString(Policy)));
+    TI.IsBuiltIn = T->isBuiltinType();
+    TI.IsTemplate = T->isTemplateTypeParmType();
+    return TI;
+  }
   InfoType IT;
   if (isa<EnumDecl>(TD)) {
     IT = InfoType::IT_enum;
@@ -435,8 +438,12 @@ static TypeInfo getTypeInfoForType(const QualType &T,
   } else {
     IT = InfoType::IT_default;
   }
-  return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
-                            T.getAsString(Policy), getInfoRelativePath(TD)));
+  Reference R = Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
+                          T.getAsString(Policy), getInfoRelativePath(TD));
+  TypeInfo TI = TypeInfo(R);
+  TI.IsBuiltIn = T->isBuiltinType();
+  TI.IsTemplate = T->isTemplateTypeParmType();
+  return TI;
 }
 
 static bool isPublic(const clang::AccessSpecifier AS,

Copy link
Contributor Author

ilovepi commented May 1, 2025

@PeterChou1 can you provide some context about how you originally expected these fields to be used/consumed? Here we bake them into the representation and serialize them, but I don't see any handling of them in the original patch. How should they be used by the different backends?

@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from e04a368 to f70cfdf Compare May 6, 2025 21:33
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 952c914 to 4851a86 Compare May 6, 2025 21:33
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from f70cfdf to d18b211 Compare May 6, 2025 22:51
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 4851a86 to 5ebecc6 Compare May 6, 2025 22:51
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from d18b211 to 622f2ef Compare May 7, 2025 01:59
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch 2 times, most recently from 41c2767 to f5b3853 Compare May 7, 2025 02:54
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from 622f2ef to c7955f5 Compare May 7, 2025 02:54
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from f5b3853 to a30feee Compare May 7, 2025 03:23
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from c7955f5 to b5a3bc4 Compare May 7, 2025 03:23
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from a30feee to fe2cad2 Compare May 7, 2025 03:25
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch 2 times, most recently from 3107a2f to 657483d Compare May 7, 2025 03:26
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from 434ddec to d829981 Compare May 17, 2025 00:35
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 1a0c8b9 to 429d1ea Compare May 17, 2025 00:35
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from d829981 to ec5d920 Compare May 17, 2025 05:42
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch 2 times, most recently from 79d6630 to 90657f6 Compare May 20, 2025 18:26
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from ec5d920 to 049c4ae Compare May 20, 2025 18:26
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 90657f6 to a3420f9 Compare May 20, 2025 21:05
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch 2 times, most recently from 5475c90 to e94b231 Compare May 22, 2025 21:18
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from a3420f9 to 4679534 Compare May 22, 2025 21:18
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from e94b231 to 47a8fc0 Compare May 22, 2025 21:23
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 4679534 to 57cfbd4 Compare May 22, 2025 21:24
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from 47a8fc0 to 5dd55e8 Compare May 23, 2025 21:58
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 57cfbd4 to fae895b Compare May 23, 2025 21:58
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from 5dd55e8 to 3ddddd4 Compare May 23, 2025 23:01
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from fae895b to 73cdd50 Compare May 23, 2025 23:02
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from 3ddddd4 to fb5adf7 Compare May 27, 2025 22:22
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from 73cdd50 to bb3d1b0 Compare May 27, 2025 22:22
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from fb5adf7 to bfd1d03 Compare May 27, 2025 22:46
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch 2 times, most recently from b6c17fe to f8eff8a Compare May 27, 2025 22:49
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from bfd1d03 to dc1b8f6 Compare May 27, 2025 22:49
Copy link
Contributor Author

ilovepi commented May 28, 2025

Merge activity

  • May 28, 5:18 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 28, 5:26 AM UTC: Graphite rebased this pull request as part of a merge.
  • May 28, 5:28 AM UTC: @ilovepi merged this pull request with Graphite.

@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-mustache-clang-doc-tool branch from dc1b8f6 to d8ddebc Compare May 28, 2025 05:23
Base automatically changed from users/ilovepi/clang-doc-mustache-clang-doc-tool to main May 28, 2025 05:25
Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou <[email protected]>
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-builtin-template branch from f8eff8a to 96de320 Compare May 28, 2025 05:25
@ilovepi ilovepi merged commit 1ad5783 into main May 28, 2025
6 of 10 checks passed
@ilovepi ilovepi deleted the users/ilovepi/clang-doc-builtin-template branch May 28, 2025 05:28
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.

3 participants