[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

Daniel Grumberg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 24 03:38:19 PDT 2023


dang added inline comments.


================
Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:342
+  // Add the notion of typedef for tag type (struct or enum) of the same name.
+  if (const ElaboratedType *ET =
+          dyn_cast<ElaboratedType>(Decl->getUnderlyingType())) {
----------------
This doesn't quite produce the output we want, this would generate `typedef struct Foo;` instead of the expected `typedef struct Foo { ... } Bar;` where Foo is the name of the struct and Bar is the name of the typedef. This should be easy enough to fix.


================
Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:347
+        if (TagTy->getDecl()->isStruct()) {
+          for (const auto &Struct : API.getStructs()) {
+            if (Decl->getName() == Struct.second.get()->Name) {
----------------
What happens if the visitation hasn't already encountered the definition of the struct? We wouldn't find it in the the APISet and this doesn't work. The approach I would suggest here is to generate the fragments for the underlying Decl directly. For example what happens for the following code:

```c
struct Foo;
typedef struct Foo TypedefedFoo;
struct Foo {
    int bar;
};
```


================
Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:349-354
+              Struct.second.get()
+                  ->Declaration
+                  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
+                  .appendFront("typedef",
+                               DeclarationFragments::FragmentKind::Keyword, "",
+                               nullptr);
----------------
This logic is very similar to the one below we could use the same code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385



More information about the cfe-commits mailing list