aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/DeclarationFragments.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)Matheus Izvekov1-1/+1
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`, as a redirection to `TypeBase.h`, and redirects most users to include the former instead. This is a preparatory patch for being able to provide inline definitions for `Type` methods which would otherwise cause a circular dependency with `Decl{,CXX}.h`. Doing these operations into their own NFC patch helps the git rename detection logic work, preserving the history. This patch makes clang just a little slower to build (~0.17%), just because it makes more code indirectly include `DeclCXX.h`.
2025-08-27[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)Matheus Izvekov1-1/+1
This is a preparatory patch, to be able to provide inline definitions for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also depends on `Type.h`, this would not be possible without some reorganizing. Splitting this rename into its own patch allows git to track this as a rename, and preserve all git history, and not force any code reformatting. A later NFC patch will reintroduce `Type.h` as redirection to `TypeBase.h`, rewriting most places back to directly including `Type.h` instead of `TypeBase.h`, leaving only a handful of places where this is necessary. Then yet a later patch will exploit this by making more stuff inline.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-52/+58
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-07-18[Clang][AST][NFC] Introduce `NamespaceBaseDecl` (#149123)Yanzuo Liu1-12/+3
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and `NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit. Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-07-07[ExtractAPI] Include tilde in destructor name (#146001)Prajwal Nadig1-3/+8
The subheading for a destructor contained only the identifier. The tilde must also be included as it is necessary to differentiate the destructor from any constructors present. rdar://129587608
2025-06-30[ExtractAPI] Format pointer types correctly (#146182)Prajwal Nadig1-11/+18
Pointer types in function signatures must place the asterisk before the identifier without a space in between. This patch removes the space and also ensures that pointers to pointers are formatted correctly. rdar://131780418 rdar://154533037
2025-06-23[ExtractAPI] Include `virtual` keyword for methods (#145412)Prajwal Nadig1-0/+3
This information was being left out of the symbol graph. rdar://131780883
2025-04-01[clang] improved preservation of template keyword (#133610)Matheus Izvekov1-7/+0
2025-03-26[clang][ExtractAPI] fix a couple crashes when used via libclang (#132297)QuietMisdreavus1-1/+5
This PR fixes two crashes in ExtractAPI that occur when decls are requested via libclang: - A null-dereference would sometimes happen in `DeclarationFragmentsBuilder::getFragmentsForClassTemplateSpecialization` when the template being processed was loaded indirectly via a typedef, with parameters filled in. The first commit loads the template parameter locations ahead of time to perform a null check before dereferencing. - An assertion (or another null-dereference) was happening in `CXXRecordDecl::bases` when processing a forward-declaration (i.e. a record without a definition). The second commit guards the use of `bases` in `ExtractAPIVisitorBase::getBases` by first checking that the decl in question has a complete definition. The added test `extract-api-cursor-cpp` adds tests for these two scenarios to protect against the crash in the future. Fixes rdar://140592475, fixes rdar://123430367
2024-10-02[clang][ExtractAPI] Generate subheading for typedef'd anonymous types (#110689)Daniel Grumberg1-0/+3
When an anonymous type has a typedef we normally use the typedef's name in places where we expect a named identifier in the symbol graph. This extends this logic to apply to subheadings. rdar://136690614
2024-09-19[clang] Tidy uses of raw_string_ostream (NFC)Youngsuk Kim1-1/+0
As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b13610a5226b84889b923bae884ba395ad084d for further reference ) * Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-09-05[clang][ExtractAPI] Handle AttributedType fragments transparently (#107262)Daniel Grumberg1-0/+13
rdar://131958623
2024-08-27[clang][ExtractAPI] Fix quirks in interaction with submodules (#105868)Daniel Grumberg1-3/+1
Extension SGFs require the module system to be enabled in order to discover which module defines the extended external type. This patch ensures the following: - Associate symbols with their top level module name, and that only top level modules are considered as modules for emitting extension SGFs. - Ensure we don't drop macro definitions that came from a submodule. To this end look at all defined macros in `PPCalbacks::EndOfMainFile` instead of relying on `PPCallbacks::MacroDefined` being called to detect a macro definition.
2024-07-16[clang][ExtractAPI][NFC] Remove some nullptr dereference problems (#98914)Daniel Grumberg1-2/+6
A places try to get a NamedDecl's name using getName when it isn't a simple identifier, migrate these areas to getNameAsString. rdar://125315602
2024-05-24[clang][ExtractAPI] Ensure TemplateArgumentLocations are only accessed if ↵Daniel Grumberg1-11/+21
available (#93205)
2024-05-22[clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (#92852)Matheus Izvekov1-2/+3
This is an enabler for https://github.com/llvm/llvm-project/pull/92855 This allows an NTTP default argument to be set as an arbitrary TemplateArgument, not just an expression. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This allows NTTP default arguments to be other kinds of arguments, like packs, integral constants, and such.
2024-05-21[clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (#92854)Matheus Izvekov1-4/+4
This is an enabler for a future patch. This allows an type-parameter default argument to be set as an arbitrary TemplateArgument, not just a type. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This will be used in a later patch which synthesizes template parameter lists with arbitrary default arguments taken from template specializations. There are a few places we used SubsType, because we only had a type, now we use SubstTemplateArgument. SubstTemplateArgument was missing arguments for setting Instantiation location and entity names. Adding those is needed so we don't regress in diagnostics.
2024-05-17[clang][ExtractAPI] Correctly generate declaration fragments for non-type ↵Daniel Grumberg1-37/+189
template parameters (#91958) Previously we only generated declaration fragments for template type parameters/arguments, this adds supports for most other possible template parameters/arguments. rdar://127732598
2024-04-24[clang][ExtractAPI] Fix handling of anonymous TagDecls (#87772)Daniel Grumberg1-4/+13
This changes the handling of anonymous TagDecls to the following rules: - If the TagDecl is embedded in the declaration for some VarDecl (this is the only possibility for RecordDecls), then pretend the child decls belong to the VarDecl - If it's an EnumDecl proceed as we did previously, i.e., embed it in the enclosing DeclContext. Additionally this fixes a few issues with declaration fragments not consistently including "{ ... }" for anonymous TagDecls. To make testing these additions easier this patch fixes some text declaration fragments merging issues and updates tests accordingly. rdar://121436298
2024-04-03Reenable external categories (#87357)Daniel Grumberg1-25/+46
Reenables b31414bf4f9898f7817a9fcf8a91f62ec26f3eaf. Also adds a new warning for missing `--symbol-graph-dir` arg when `--emit-extension-symbol-graphs` is provided. This also reverts the commit that removed.
2024-04-02[clang][ExtractAPI] improve template argument name deduction (#77716)Erick Velez1-41/+10
The names of template arguments in partial specializations or parameters used as types might be mangled according to index and depth. Instead of looping through parameter lists to find matches like we do now, they can be deduced via their QualTypes or as written from the AST.
2024-04-02Revert "[clang][ExtractAPI] Add ability to create multiple symbol graphs ↵Daniel Grumberg1-46/+25
(#86676)" This failed the test suite due to missing DiagGroup for a new warning. This reverts commit b31414bf4f9898f7817a9fcf8a91f62ec26f3eaf.
2024-04-02[clang][ExtractAPI] Add ability to create multiple symbol graphs (#86676)Daniel Grumberg1-25/+46
This extends ExtractAPI to take into account symbols defined in categories to types defined in an external module. This introduces 2 new command line flags, `--symbol-graph-dir=DIR` and `--emit-extension-symbol-graphs`, when used together this generates additional symbol graph files at `DIR/ExtendedModule@ProductName.symbols.json` for each external module that is extended in this way. Additionally this makes some cleanups to tests to make them more resilient and cleans up the `APISet` data structure.
2024-01-28[ExtractAPI] Use StringRef::starts_with (NFC)Kazu Hirata1-8/+8
2024-01-22[clang][ExtractAPI] Ensure typedef to pointer types are preserved (#78584)Daniel Grumberg1-40/+40
When generating declaration fragments for types that use typedefs to pointer types ensure that we keep the user-defined typedef form instead of desugaring the typedef. rdar://102137655
2024-01-22[clang][ExtractAPI] Add support C unions in non C++ parsing mode (#77451)Daniel Grumberg1-3/+6
Ensure that we generate correct symbol kinds and declaration fragments for unions in C and Objective-C parsing modes. rdar://120544091
2023-11-28[clang][ExtractAPI] Add support for blocks in declaration fragments (#73369)Daniel Grumberg1-28/+148
Ensure that block types get represented correctly in declaration fragments, as block parameter names are important for documentation clients we need a separate system from getFragmentsForType in order to have access to full ParmVarDecls for the parameters. rdar://118257401
2023-10-31[clang][NFC] Refactor ElaboratedTypeKeywordVlad Serebrennikov1-1/+1
This patch moves ElaboratedTypeKeyword before `Type` definition so that the enum is complete where bit-field for it is declared. It also converts it to scoped enum and removes `ETK_` prefix.
2023-10-31[clang][NFC] Refactor `ArrayType::ArraySizeModifier`Vlad Serebrennikov1-3/+3
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-08-25[NFC][Clang] Fix static analyzer concernElizabeth Andrews1-2/+2
Fix a few static analyzer concerns about dereferencing null value. Differential Revision: https://reviews.llvm.org/D158671
2023-08-22[clang][ExtractAPI] Fix bool spelling coming from the macro definition.Erick Velez1-0/+3
getFragmentsForType resulted in a bool typeIdentifier fragment to be spelled "_Bool". This fixes the spelling to be "bool" and checks it in C and C++. Reviewed By: dang Differential Revision: https://reviews.llvm.org/D158474
2023-08-22[clang][ExtractAPI] Add support for namespacesErick Velez1-0/+10
Serialize namespaces, nested namespaces, and class relationships inside them. Depends on D157076 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D158239
2023-08-21[clang][ExtractAPI] Add support for C++ member templatesErick Velez1-0/+5
Visit and serialize C++ fields by checking if a var template's context is a CXXRecordDecl in VisitVarTemplateDecl. Depends on D158027 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D158029
2023-08-18[clang][ExtractAPI] Add support for C++ global function templatesErick Velez1-5/+65
Add records, serialization for global function templates and their specializations Depends on D157350 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D157579
2023-08-18[clang][ExtractAPI] Add support for C++ variable templatesErick Velez1-0/+71
Serialize global C++ variable templates and specializations. Depends on D157076 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D157350
2023-08-18[clang][ExtractAPI] Add support for C++ class templates and conceptsErick Velez1-0/+168
Add has_template template, DeclarationFragmentBuilder functions, and tests for class templates, specializations/partial specs, and concepts. Depends on D157007 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D157076
2023-08-04[clang][ExtractAPI] Add support for C++ classes with fixErick Velez1-22/+235
Reintroduce D153557 with fix for use-after-free from f4de606ef271 and minor changes. Reviewed By: dang Differential Revision: https://reviews.llvm.org/D157007
2023-08-02Revert "[clang][ExtractAPI] Add support for C++ classes"Erick Velez1-236/+21
This reverts commit 8b76b44e46ac5b4efbf8cb3702f09d353af2a112.
2023-08-02fix use-after-free introduced in 8b76b44e46acAugie Fackler1-2/+2
ASan catches this easily enough.
2023-08-02[clang][ExtractAPI] Add support for C++ classesErick Velez1-21/+236
Add ExtractAPI support C++ classes, fields, methods, and various qualifiers and specifiers Differential Revision: https://reviews.llvm.org/D153557
2023-07-31[clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSONErick Velez1-2/+4
Differential Revision: https://reviews.llvm.org/D154038
2023-05-04[clang][ExtractAPI] Add semicolon to function declaration fragmentsNagaChaitanya Vellanki1-1/+1
Add missing semicolon at the end of function declarations to fragments Reviewed By: dang Differential Revision: https://reviews.llvm.org/D149737
2023-04-04[ExtractAPI] Remove extra attributes in property declaration fragmentsUsman Akinyemi1-1/+1
Use `getPropertyAttributesAsWritten` instead of `getPropertyAttributes` to get property attributes actually specified in the source code. Resolves issue #61478. https://reviews.llvm.org/D146759 Reviewed By: zixuw, dang Differential Revision: https://reviews.llvm.org/D146759
2023-03-30[clang][ExtractAPI] Remove extra pointer indirection from declaration ↵NagaChaitanya Vellanki1-5/+17
fragments for Obj-C lightweight generics on id Fixes https://github.com/llvm/llvm-project/issues/61479 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D146866
2023-03-30[clang][ExtractAPI] Reland ExtractAPI for libclang improvementsDaniel Grumberg1-1/+1
This relands the changes that were originally introduced by: - https://reviews.llvm.org/D146656 - https://reviews.llvm.org/D147138 This also fixes the leak that led to these changes being reverted Differential Revision: https://reviews.llvm.org/D147234
2023-03-29Revert "Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656""Mitch Phillips1-1/+1
This reverts commit 79116475124112051625b1a0665e35c861bb13fd. Broke the ASan bots. See more information in https://reviews.llvm.org/rG79116475124112051625b1a0665e35c861bb13fd
2023-03-29Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656"Daniel Grumberg1-1/+1
This reverts commit 158a431227a876306fe5838936413dd51588d0c6.
2023-03-27Revert ExtractAPI from https://reviews.llvm.org/D146656Daniel Grumberg1-1/+1
2023-03-27[clang][ExtractAPI] Refactor ExtractAPIVisitor to make it more extensibleDaniel Grumberg1-1/+1
Use CRTP to enable creating statically dispatched subclasses of ExtractAPIVisitor. This enables adding extension points and customising the behavior more easily. This is used in CXExtractAPI.cpp to create a specialized visitor for Libclang as well as streamlining the batch implementation in ExtractAPIConsumer.cpp
2023-03-23[clang][ExtractAPI]Fix Declaration fragments for instancetype in the type ↵NagaChaitanya Vellanki1-9/+13
position degrade to id Fixes https://github.com/llvm/llvm-project/issues/61481 Reviewed By: dang Differential Revision: https://reviews.llvm.org/D146671