aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-3/+3
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-13[clang][ExtractAPI] Add support for single symbol SGF and libclang supportDaniel Grumberg1-536/+13
This is mainly adding an entry point to `SymbolGraphSerializer` at `serializeSingleSymbolSGF` and exposing the necessary data to make this possible. Additionaly there are some changes to how symbol kinds and path components are serialized to make the usage more ergonomic in `serializeSingleSymbolSGF`. On the libclang side this introduces APIs to: - create an APISet from a TU - dispose of an APISet - query an APISet for a single symbol SGF for a given USR. - generate a single symbol SGF for a given CXCursor, this only traverses the necessary AST nodes to construct the result as oppposed as going through the entire AST. Differential Revision: https://reviews.llvm.org/D139115
2022-12-09[ExtractAPI] Use std::optional in ExtractAPIConsumer.cpp (NFC)Kazu Hirata1-3/+4
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-25[clang][ExtractAPI] Allow users to specify a list of symbols to ignoreDaniel Grumberg1-1/+16
Adds a `--extract-api-ignores=` command line option that allows users to provide a file containing a new line separated list of symbols to unconditionally ignore when extracting API information. Differential Revision: https://reviews.llvm.org/D136450
2022-10-13[clang][ExtractAPI] Ignore fully anonymous RecordDeclsDaniel Grumberg1-0/+3
ExtractAPI was emitting a separate symbol for anonymous record declaration that define the type of a member of another record declaration. Now ExtractAPI ignores these declarations and just records the existence of the actual member. Differential Revision: https://reviews.llvm.org/D135804
2022-10-05[clang][ExtractAPI] Don't print locations for anonymous tagsZixu Wang1-0/+5
ExtractAPI doesn't care about locations of anonymous TagDecls. Set the printing policy to exclude that from anonymous decl names. Differential Revision: https://reviews.llvm.org/D135295
2022-08-19[clang][ExtractAPI] Record availability information on all platformsDaniel Grumberg1-68/+27
Currently ExtractAPI only emits availability information for the current platform. This makes it easy for clients to get all availability information for a given symbol in one invocation as opposed to having to invoke clang once per-platform and then merge the symbol-graphs. Differential Revision: https://reviews.llvm.org/D130918
2022-07-22[NFC] Start saving InstantiatedFromDecl in non-template functionsErich Keane1-0/+1
In cases where a non-template function is defined inside a function template, we don't have information about the original uninstantiated version. In the case of concepts instantiation, we will need the ability to get back to the original template. This patch splits a piece of the deferred concepts instantaition patch off to accomplish the storage of this, with minor runtime overhead, and zero additional storage.
2022-07-01Revert "Re-apply "Deferred Concept Instantiation Implementation"""Erich Keane1-1/+0
This reverts commit befa8cf087dbb8159a4d9dc8fa4d6748d6d5049a. Apparently this breaks some libc++ builds with an apparent assertion, so I'm looking into that .
2022-07-01Re-apply "Deferred Concept Instantiation Implementation""Erich Keane1-0/+1
This reverts commit d4d47e574ecae562ab32f8ac7fa3f4d424bb6574. This fixes the lldb crash that was observed by ensuring that our friend-'template contains reference to' TreeTransform properly handles a TemplateDecl.
2022-06-30Revert "Deferred Concept Instantiation Implementation"Jonas Devlieghere1-1/+0
This reverts commit 2f207439521d62d9551b2884158368e8b34084e5 because it triggers an assertion when building an LLDB test program: Assertion failed: (InstantiatingSpecializations.empty() && "failed to clean up an InstantiatingTemplate?"), function ~Sema, file /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/clang/lib/Sema/Sema.cpp, line 458. More details in https://reviews.llvm.org/D126907.
2022-06-30Deferred Concept Instantiation ImplementationErich Keane1-0/+1
This is a continuation of D119544. Based on @rsmith 's feed back showing me https://eel.is/c++draft/temp#friend-9, We should properly handle friend functions now. Differential Revision: https://reviews.llvm.org/D126907
2022-06-12[clang] Use any_of and none_of (NFC)Kazu Hirata1-5/+5
2022-05-09Revert ""Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""""Erich Keane1-1/+0
This reverts commit a425cac31e2e4cee8e14b7b9a99c8ba17c1ebb52. There is another libc++ test, that this time causes us to hit an assertion. Reverting, likely for a while this time.
2022-05-09"Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""""Erich Keane1-0/+1
This includes a fix for the libc++ issue I ran across with friend declarations not properly being identified as overloads. This reverts commit 45c07db31cc76802a1a2e41bed1ce9c1b8198181.
2022-05-05[clang] Add static_cast to fix Bazel build.Adrian Kuegel1-1/+2
Differential Revision: https://reviews.llvm.org/D124995
2022-05-04Revert "Revert "[clang][extract-api] Use relative includes""Zixu Wang1-12/+178
Reapply the change after fixing sanitizer errors. The original problem was that `StringRef`s in `Matches` are pointing to temporary local `std::string`s created by `path::convert_to_slash` in the regex match call. This patch does the conversion up front in container `FilePath`. This reverts commit 2966f0fa505266735dbc8324b8821b7f0aa901ff. Differential Revision: https://reviews.llvm.org/D124964
2022-05-04Revert "[clang][extract-api] Use relative includes"Zixu Wang1-181/+12
This reverts commit 4c262fee08b5383c96857d77eefe80d61c41d2b0. Revert to fix Msan and Asan errors.
2022-05-04[clang][extract-api] Use relative includesZixu Wang1-12/+181
This patch transforms the given input headers to relative include names using header search entries and some heuritics. For example: `/Path/To/Header.h` will be included as `<Header.h>` with a search path of `-I /Path/To/`; and `/Path/To/Framework.framework/Headers/Header.h` will be included as `<Framework/Header.h>`, given a search path of `-F /Path/To`. Headermaps will also be queried in reverse to find a spelled name to include headers. Differential Revision: https://reviews.llvm.org/D123831
2022-05-02Revert "Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""Erich Keane1-1/+0
This reverts commit a97899108e495147985e5e9492e742d51d5cc97a. The patch caused some problems with the libc++ `__range_adaptor_closure` that I haven't been able to figure out the cause of, so I am reverting while I figure out whether this is a solvable problem/issue with the CFE, or libc++ depending on an older 'incorrect' behavior.
2022-05-02Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""Erich Keane1-0/+1
This reverts commit 0c31da48389754822dc3eecc4723160c295b9ab2. I've solved the issue with the PointerUnion by making the `FunctionTemplateDecl` pointer be a NamedDecl, that could be a `FunctionDecl` or `FunctionTemplateDecl` depending. This is enforced with an assert.
2022-05-02Revert "Deferred Concept Instantiation Implementation"Erich Keane1-1/+0
This reverts commit 4b6c2cd647e9e5a147954886338f97ffb6a1bcfb. The patch caused numerous ARM 32 bit build failures, since we added a 5th item to the PointerUnion, and went over the 2-bits available in the 32 bit pointers.
2022-05-02Deferred Concept Instantiation ImplementationErich Keane1-0/+1
As reported here: https://github.com/llvm/llvm-project/issues/44178 Concepts are not supposed to be instantiated until they are checked, so this patch implements that and goes through significant amounts of work to make sure we properly re-instantiate the concepts correctly. Differential Revision: https://reviews.llvm.org/D119544
2022-04-28Frontend: Delete output streams before closing CompilerInstance outputsDuncan P. N. Exon Smith1-1/+1
Delete the output streams coming from CompilerInstance::createOutputFile() and friends once writes are finished. Concretely, replacing `OS->flush()` with `OS.reset()` in: - `ExtractAPIAction::EndSourceFileAction()` - `PrecompiledPreambleAction::setEmittedPreamblePCH()` - `cc1_main()'s support for `-ftime-trace` This fixes theoretical bugs related to proxy streams, which may have cleanups to run in their destructor. For example, a proxy that CompilerInstance sometimes uses is `buffer_ostream`, which wraps a `raw_ostream` lacking pwrite support and adds it. `flush()` does not promise that output is complete; `buffer_ostream` needs to wait until the destructor to forward anything so that it can service later calls to `pwrite()`. If the destructor isn't called then the proxied stream hasn't received any content. This also protects against some logic bugs, triggering a null dereference on a later attempt to write to the stream. No tests, since in practice these particular code paths never use use `buffer_ostream`; you need to be writing a binary file to a pipe (such as stdout) to hit it, but `-extract-api` writes a text file and the other two use computed filenames that will never (in practice) be a pipe. This is effectively NFC, for now. But I have some other patches in the works that add guard rails, crashing if the stream hasn't been destructed by the time the CompilerInstance is told to keep the output file, since in most cases this is a problem. Differential Revision: https://reviews.llvm.org/D124635
2022-04-12[clang][extract-api] Add support for true anonymous enumsDaniel Grumberg1-3/+6
Anonymous enums without a typedef should have a "(anonymous)" identifier. Differential Revision: https://reviews.llvm.org/D123533
2022-04-11[clang][extract-api] Emit "functionSignature" in SGF for ObjC methods.Daniel Grumberg1-2/+2
- Split GlobalRecord into two distinct types to be able to introduce has_function_signature type trait. - Add has_function_signature type trait. - Serialize function signatures as part of serializeAPIRecord for records that are known to have a function signature. Differential Revision: https://reviews.llvm.org/D123304
2022-04-07[clang][extract-api][NFC] Use dedicated API to check for macro equalityDaniel Grumberg1-8/+9
Differential Revision: https://reviews.llvm.org/D123295
2022-04-07[clang][extract-api] Process only APIs declared in inputsDaniel Grumberg1-7/+80
We should only process APIs declared in the command line inputs to avoid drowning the ExtractAPI output with symbols the user doesn't care about. This is achieved by keeping track of the provided input files and checking that the associated Decl or Macro is declared in one of those files. Differential Revision: https://reviews.llvm.org/D123148
2022-04-06[clang][extract-api] Add Objective-C Category supportZixu Wang1-0/+33
Add (partial) support for Objective-C category records in ExtractAPI. The current ExtractAPI collects everything for an Objective-C category, but not fully serialized in the SymbolGraphSerializer. Categories extending external interfaces are disgarded during serialization, and categories extending known interfaces are merged (all members surfaced) into the interfaces. Differential Revision: https://reviews.llvm.org/D122774
2022-04-06[clang][extract-api] Add support for typedefsDaniel Grumberg1-0/+42
Typedef records consist of the symbol associated with the underlying TypedefDecl and a SymbolReference to the underlying type. Additionally typedefs for anonymous TagTypes use the typedef'd name as the symbol name in their respective records and USRs. As a result the declaration fragments for the anonymous TagType are those for the associated typedef. This means that when the user is defining a typedef to a typedef to a anonymous type, we use a reference the anonymous TagType itself and do not emit the typedef to the anonymous type in the generated symbol graph, including in the type destination of further typedef symbol records. Differential Revision: https://reviews.llvm.org/D123019
2022-04-05[clang][extract-api] Undefining macros should not result in a crashDaniel Grumberg1-0/+5
This fixes the situation where a undefining a not previously defined macro resulted in a crash. Before trying to remove a definition from PendingMacros we first check to see if the macro did indeed have a previous definition. Differential Revision: https://reviews.llvm.org/D123056
2022-03-30[clang][extract-api][NFC] Don't remap the generated input buffer in PPOptsDaniel Grumberg1-6/+2
This was triggering some build failures so removing this change for now.
2022-03-30[clang][extract-api] Add support for macrosDaniel Grumberg1-2/+79
To achieve this we hook into the preprocessor during the ExtractAPIAction and record definitions for macros that don't get undefined during preprocessing.
2022-03-30[clang][extractapi] Tie API and serialization to the FrontendActionDaniel Grumberg1-19/+28
Make the API records a property of the action instead of the ASTVisitor so that it can be accessed outside the AST visitation and push back serialization to the end of the frontend action. This will allow accessing and modifying the API records outside of the ASTVisitor, which is a prerequisite for supporting macros.
2022-03-29[clang][extract-api] Add Objective-C protocol supportZixu Wang1-0/+32
Add support for Objective-C protocol declarations in ExtractAPI. Depends on D122446 Differential Revision: https://reviews.llvm.org/D122511
2022-03-29[clang][extract-api] Add Objective-C interface supportZixu Wang1-0/+154
Add support for Objective-C interface declarations in ExtractAPI. Depends on D122495 Differential Revision: https://reviews.llvm.org/D122446
2022-03-29[clang][extract-api] Use correct language info from inputsZixu Wang1-5/+5
The current way of getting the `clang::Language` from `LangOptions` does not handle Objective-C correctly because `clang::Language::ObjC` does not correspond to any `LangStandard`. This patch passes the correct `Language` from the frontend input information. Differential Revision: https://reviews.llvm.org/D122495
2022-03-23[clang][extract-api] Enable processing of multiple headersDaniel Grumberg1-0/+32
Before actually executing the ExtractAPIAction, clear the CompilationInstance's input list and replace it with a single synthesized file that just includes (or imports in ObjC) all the inputs. Depends on D122141 Differential Revision: https://reviews.llvm.org/D122175
2022-03-23[clang][extract-api] Add struct supportZixu Wang1-0/+62
- Add `StructFieldRecord` and `StructRecord` to store API information for structs - Implement `VisitRecordDecl` in `ExtractAPIVisitor` - Implement Symbol Graph serialization for struct records. - Add test case for struct records. Depends on D121873 Differential Revision: https://reviews.llvm.org/D122202
2022-03-23[clang][extract-api] Add enum supportZixu Wang1-0/+61
Add support for enum records - Add `EnumConstantRecord` and `EnumRecord` to store API information for enums - Implement `VisitEnumDecl` in `ExtractAPIVisitor` - Implement serializatin for enum records and `MemberOf` relationship - Add test case for enum records - Few other improvements Depends on D122160 Differential Revision: https://reviews.llvm.org/D121873
2022-03-23[clang][extract-api] Suppprt for the module name property in SymbolGraphDaniel Grumberg1-5/+8
Adds `--product-name=` flag to the clang driver. This gets forwarded to cc1 only when we are performing a ExtractAPI Action. This is used to populate the `name` field of the module object in the generated SymbolGraph. Differential Revision: https://reviews.llvm.org/D122141
2022-03-22[clang][extract-api] Refactor ExtractAPI and improve docsZixu Wang1-0/+224
- The name SymbolGraph is inappropriate and confusing for the new library for clang-extract-api. Refactor and rename things to make it clear that ExtractAPI is the core functionality and SymbolGraph is one serializer for the API information. - Add documentation comments to ExtractAPI classes and methods to improve readability and clearness of the ExtractAPI work. Differential Revision: https://reviews.llvm.org/D122160