aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI
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 Izvekov2-53/+59
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-06-20[ExtractAPI] Include +/- symbols for ObjC methods (#145035)Prajwal Nadig1-0/+16
ObjC methods include a +/- prefix to indicate if they are a class or instance method. This information is valuable, and must be included in the navigator generated by ExtractAPI. rdar://150870936
2025-06-15[clang] Remove unused includes (NFC) (#144285)Kazu Hirata2-3/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-12[NFC] Optimize file kind determination (#139492)Serge Pavlov1-2/+1
There are checks in clang codebase that determine the type of source file, associated with a given location - specifically, if it is an ordonary file or comes from sources like command-line options or a built-in definitions. These checks often rely on calls to `getPresumedLoc`, which is relatively expensive. In certain cases, these checks are combined, leading to repeated calculations of the costly function negatively affecting compile time. This change tries to optimize such checks. It must fix compile time regression introduced in https://github.com/llvm/llvm-project/pull/137306/. --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
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-12-16[ExtractAPI] reorder the module names in extension symbol graph file names ↵QuietMisdreavus1-3/+2
(#119925) Resolves rdar://140298287 ExtractAPI's support for printing Objective-C category extensions from other modules emits symbol graphs with an `ExtendedModule@HostModule.symbols.json`. However, this is backwards from existing symbol graph practices, causing issues when these symbol graphs are consumed alongside symbol graphs generated with other tools like Swift. This PR flips the naming scheme to be in line with existing symbol graph tooling.
2024-10-28Remove support for RenderScript (#112916)Aaron Ballman1-1/+0
See https://discourse.llvm.org/t/rfc-deprecate-and-eventually-remove-renderscript-support/81284 for the RFC
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-25[clang] Make deprecations of some `FileManager` APIs formal (#110014)Jan Svoboda1-2/+2
Some `FileManager` APIs still return `{File,Directory}Entry` instead of the preferred `{File,Directory}EntryRef`. These are documented to be deprecated, but don't have the attribute that warns on their usage. This PR marks them as such with `LLVM_DEPRECATED()` and replaces their usage with the recommended counterparts. NFCI.
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-09-03[clang][ExtractAPI] Remove erroneous module name check in MacroCallbacks ↵Daniel Grumberg1-1/+1
(#107059) rdar://135044923
2024-08-29[clang][ExtractAPI] Fix iteration order of TopLevelRecords (#106411)Daniel Grumberg1-2/+4
Fixes #106355
2024-08-27[clang][ExtractAPI] Fix quirks in interaction with submodules (#105868)Daniel Grumberg3-59/+39
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-08-20Reenable anon structs (#104922)Daniel Grumberg2-10/+51
Add back missing includes and revert revert "[clang][ExtractAPI] Stop dropping fields of nested anonymous record types when they aren't attached to variable declaration (#104600)"
2024-08-19Revert "[clang][ExtractAPI] Stop dropping fields of nested anonymous record ↵Daniel Grumberg2-51/+10
types when they aren't attached to variable declaration (#104600)" This reverts commit c60da1a271a6bb271e7703b2f7c71fbece67ab78.
2024-08-19[clang][ExtractAPI] Stop dropping fields of nested anonymous record types ↵Daniel Grumberg2-10/+51
when they aren't attached to variable declaration (#104600) - Introduce primitives for removing records from `APISet` and managing the record chain of `RecordContext` - Detect nested anonymous record types and remove them from the `APISet` after they have been fully traversed and transfer ownership of child records to the parent context (if any)
2024-08-15[clang][ExtractAPI] Emit environment component of target triple in SGF (#103273)Daniel Grumberg1-0/+4
rdar://133533830
2024-08-15[clang][ExtractAPI] Compute inherited availability information (#103040)Daniel Grumberg1-14/+17
Additionally this computes availability information for all platforms ahead of possibly introducing a flag to enable this behavior. rdar://123513706
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-06-06[clang][NFC] fix name lookup for llvm::json::Value in SymbolGraphSerializer ↵Yuxuan Chen1-3/+2
(#94511) This code uses namespaces `llvm` and `llvm::json`. However, we have both `llvm::Value` and `llvm::json::Value`. Whenever any of the headers declare or include `llvm::Value`, the lookup becomes ambiguous. Fixing this by qualifying the `Value` type.
2024-06-03[clang][Modules] Remove unnecessary includes of `Module.h` (#93417)David Stone1-1/+0
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-20[clang][ExtractAPI] Remove symbols defined in categories to external types ↵Daniel Grumberg1-2/+9
unless requested (#92522) rdar://128259890
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-05-13[clang][ExtractAPI] Distinguish between record kind for display and for RTTI ↵Daniel Grumberg1-3/+3
(#91466) rdar://127732562
2024-04-24[clang][ExtractAPI] Fix handling of anonymous TagDecls (#87772)Daniel Grumberg3-4/+43
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-23[clang][ExtractAPI] Serialize platform specific unavailable attribute in ↵Daniel Grumberg1-13/+15
symbol graphs (#89277) rdar://125622225
2024-04-03Reenable external categories (#87357)Daniel Grumberg5-1140/+536
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 Grumberg5-536/+1140
(#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 Grumberg5-1140/+536
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-03-21[CIR][Basic][NFC] Add the CIR language to the Language enumNathan Lanza1-0/+1
Add the CIR language to the Language enum and the standard usages of it. commit-id:fd12b2c2 Reviewers: bcardosolopes, AaronBallman, erichkeane Reviewed By: AaronBallman, bcardosolopes Pull Request: https://github.com/llvm/llvm-project/pull/86072
2024-02-20[clang][InstallAPI] Add input file support to library (#81701)Cyndy Ishida2-4/+4
This patch adds support for expected InstallAPI inputs. InstallAPI accepts a well defined filelist of headers and how those headers represent a single library. InstallAPI captures header files to determine linkable symbols to then compare against what was compiled in a binary dylib and generate TBD files.
2024-02-15[clang] Move `AvailabilityInfo` into AST library (#81897)Cyndy Ishida2-36/+0
Previously this class was only used by ExtractAPI, but it will soon also be needed by InstallAPI. This patch should not change availability behavior but just centralizes the information next to what already is captured about availability for AST traversal.
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 Grumberg3-27/+35
Ensure that we generate correct symbol kinds and declaration fragments for unions in C and Objective-C parsing modes. rdar://120544091
2024-01-19[clang][ExtractAPI] Record availability information only for the target ↵Sofía Rodríguez3-128/+106
platform (#76823) Currently, ExtractAPI provides availability information for all platforms within a given domain. With this change, we narrow down the output to include availability details only for the specified target platform, so users can generate the symbol graph with only the availability information they need, omitting information of the other platforms. This change reverts the functionality introduced in [`57c9780`](https://github.com/llvm/llvm-project/commit/57c9780). rdar://120419037
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata2-3/+3
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-07[clang][ExtractAPI] Allow serialization for ObjC++ headers (#74733)Daniel Grumberg1-1/+2
rdar://79874441