[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

Erick Velez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 16 16:47:13 PDT 2023


evelez7 added a comment.

We didn't handle inheriting from a template parameter, but now we do by serializing the relationship. The parameter does not produce a target USR so it falls back to its name.



================
Comment at: clang/include/clang/ExtractAPI/DeclarationFragments.h:191
 
+class Template {
+  struct TemplateParameter {
----------------
dang wrote:
> This is really a model type and should live either in it's own file or in API.h
Moved to API.h


================
Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:754
+      Fragments.append(TemplateParam->getTypeConstraint()
+                           ->getNamedConcept()
+                           ->getName()
----------------
dang wrote:
> is this clang-format formatted?
Yes.


================
Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:784
+        dyn_cast<TemplateTypeParmDecl>(TemplateParameters[i]);
+    if (TypeParameter.compare("type-parameter-" +
+                              std::to_string(Parameter->getDepth()) + "-" +
----------------
dang wrote:
> Kinda sad we have to do this. I guess there is no easy way to change the AST to support this?
I've just realized that we could just take the the template parameter and insert it arbitrarily but it could easily be the incorrect partial specialization. We'd still need to determine which argument corresponds to the template param.

One optimization is to check if there is only one new param in a partial specialization so that a var template's type is automatically known if it is the new template param, i.e. template<typename T> T x<T, int>

The unfortunate reality is that template parameters are actual Decls (TemplateTypeParmDecl, which do hold the generic's correct name), and TemplateArguments are not. Calling TemplateArgument.getAsDecl() or getAsTemplate always result in assertion errors (when the arg is a template param) since there are no analogous structures. There'd have to be a TemplateTypeArgDecl.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157076/new/

https://reviews.llvm.org/D157076



More information about the cfe-commits mailing list