summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling
Commit message (Collapse)AuthorAgeFilesLines
* [Syntax] Merge overlapping top-level macros in TokenBufferSam McCall2020-06-101-4/+21
| | | | | | | | | | | | | | | | | | | Summary: Our previous definition of "top-level" was too informal, and didn't allow for overlapping macros that each directly produce expanded tokens. See D77507 for previous discussion. Fixes http://bugs.llvm.org/show_bug.cgi?id=45428 Reviewers: kadircet, vabridgers Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77615 (cherry picked from commit d66afd6dde542dc373f87e07fe764c071fe20d76)
* [Syntax] Unset IsOriginal flag on nodes removed from the treeIlya Biryukov2020-01-141-0/+3
| | | | | | And add a corresponding test. Only nodes inside the TranslationUnit subtree can be marked as original, computeReplacements() relies on this.
* [Syntax] Mark synthesized nodes as modifiableIlya Biryukov2020-01-141-0/+18
| | | | | This was an oversight in the original patch. Also add corresponding tests.
* [Syntax] Build spanning SimpleDecalration for classes, structs, etcIlya Biryukov2020-01-031-18/+63
| | | | | | | When they are free-standing, e.g. `struct X;` or `struct X {};`. Although this complicates the common case (of free-standing class declarations), this ensures the less common case (e.g. `struct X {} a;`) are handled uniformly and produce similar syntax trees.
* Fix crash in getFullyQualifiedName for inline namespaceAlexey Bader2019-12-281-0/+11
| | | | | | | | | | | | | | Summary: The ICE happens when the most outer namespace is an inline namespace. Reviewers: bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ebevhan, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71962
* [clang][Tooling] Prefer -x over -std when interpolatingKadir Cetinkaya2019-12-201-0/+4
| | | | | | | | | | | | | | | | | | | Summary: Currently interpolation logic prefers -std over -x. But the latter is a more strong signal, so this patch inverts the order and only makes use of -std if -x didn't exist. Fixes https://github.com/clangd/clangd/issues/185 Thanks @sammccall for tracking this down! Reviewers: sammccall Subscribers: ilya-biryukov, usaxena95, cfe-commits, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D71727
* [Syntax] Use a hash table to search for tokens by their locationIlya Biryukov2019-12-181-0/+40
| | | | | | | | This is both more efficient and avoids corner cases in `SourceManager::isBeforeInTranslationUnit`. The change is trivial and clearly a performance improvement on the hot path of building the syntax tree, so sending without review.
* [Syntax] Uppercase the first letter of the test name. NFCIlya Biryukov2019-12-181-1/+1
| | | | To match naming style of other tests.
* [Syntax] Allow to mutate syntax treesIlya Biryukov2019-12-182-5/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds facilities to mutate the syntax trees and produce corresponding text replacements. The public interface of the syntax library now includes facilities to: 1. perform type-safe modifications of syntax trees, 2. compute textual replacements to apply the modifications, 3. create syntax trees not backed by the source code. For each of the three, we only add a few example transformations in this patch to illustrate the idea, support for more kinds of nodes and transformations will be done in follow-up patches. The high-level mutation operations are implemented on top of operations that allow to arbitrarily change the trees. They are considered to be implementation details and are not available to the users of the library. Reviewers: sammccall, gribozavr2 Reviewed By: gribozavr2 Subscribers: merge_guards_bot, mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64573
* [Tooling/Syntax] Helpers to find spelled tokens touching a location.Sam McCall2019-12-121-0/+41
| | | | | | | | | | | | Summary: Useful when positions are used to target nodes, with before/after ambiguity. Reviewers: ilya-biryukov, kbobyrev Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71356
* [Tooling] Move raw string literal out of a macro call. NFCIlya Biryukov2019-12-121-4/+7
| | | | Should fix buildbots with some older gcc versions.
* [Syntax] Build nodes for simple cases of top level declarationsIlya Biryukov2019-12-121-1/+184
| | | | | | | | | | | | | | | | Summary: More complicated nodes (e.g. template declarations) will be implemented in the follow-up patches. Reviewers: gribozavr2 Reviewed By: gribozavr2 Subscribers: merge_guards_bot, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70856
* Reland "[AST] Traverse the class type loc inside the member type loc.""Haojian Wu2019-12-092-0/+56
| | | | | | | | | | | | Summary: added a unittest which causes "TL.getClassTInfo" is null. Reviewers: ilya-biryukov Subscribers: mgorny, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71186
* Revert "[AST] Traverse the class type loc inside the member type loc."Sterling Augustine2019-12-052-48/+0
| | | | | | | This reverts commit 7f93cb62280a73e3e899d49c45be8bfbac634b7d. The assertion at RecursiveASTVisitor.h:1169 fails when passed a TypeLocNode. Not sure if the correct fix is to use getTypeLocClass or something else.
* [Syntax] Show input code on tests failures. NFCIlya Biryukov2019-12-051-0/+2
|
* [AST] Traverse the class type loc inside the member type loc.Haojian Wu2019-12-052-0/+48
| | | | | | | | | | | | | | | Summary: We are missing this currently. This would fix https://github.com/clangd/clangd/issues/216. Reviewers: ilya-biryukov Subscribers: mgorny, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70849
* [clang][Tooling] Add support for .rsp files in compile_commands.jsonKadir Cetinkaya2019-12-041-0/+30
| | | | | | | | | | | | | | | | | | | Summary: Add support for .rsp files. Fixes https://github.com/clangd/clangd/issues/81 Patch By: liu hui(@lh123) Reviewers: sammccall, ilya-biryukov, hokein, kadircet Reviewed By: kadircet Subscribers: merge_guards_bot, mgorny, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D70222
* Reland [clangd] Rethink how SelectionTree deals with macros and #includes.Sam McCall2019-12-031-0/+15
| | | | | | This reverts commit 905b002c139f039a32ab9bf1fad63d745d12423f. Avoid tricky (and invalid) comparator for std::set.
* Revert "[clangd] Rethink how SelectionTree deals with macros and #includes."Sam McCall2019-11-291-15/+0
| | | | | | | | This reverts commit 19daa21f841ad45290c923689ee3d25198651a4c. It causes a bunch of failures on a bot that I've been unable to reproduce so far: http://45.33.8.238/mac/3308/step_7.txt
* [clangd] Rethink how SelectionTree deals with macros and #includes.Sam McCall2019-11-291-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The exclusive-claim model is successful at resolving conflicts over tokens between parent/child or siblings. However claims at the spelled-token level do the wrong thing for macro expansions, where siblings can be equally associated with the macro invocation. Moreover, any model that only uses the endpoints in a range can fail when a macro invocation occurs inside the node. To address this, we use the existing TokenBuffer in more depth. Claims are expressed in terms of expanded tokens, so there is no need to worry about macros, includes etc. Once we know which expanded tokens were claimed, they are mapped onto spelled tokens for hit-testing. This mapping is fairly flexible, currently the handling of macros is pretty simple (map macro args onto spellings, other macro expansions onto the macro name token). This mapping is in principle token-by-token for correctness (though there's some batching for performance). The aggregation of the selection enum is now more principled as we need to be able to aggregate several hit-test results together. For simplicity i removed the ability to determine selectedness of TUDecl. (That was originally implemented in 90a5bf92ff97b1, but doesn't seem to be very important or worth the complexity any longer). The expandedTokens(SourceLocation) helper could be added locally, but seems to make sense on TokenBuffer. Fixes https://github.com/clangd/clangd/issues/202 Fixes https://github.com/clangd/clangd/issues/126 Reviewers: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits, ilya-biryukov Tags: #clang Differential Revision: https://reviews.llvm.org/D70512
* [Syntax] Build SimpleDeclaration node that groups multiple declaratorsIlya Biryukov2019-11-291-25/+93
| | | | | | | | | | | | | | | | | | | | Summary: Also remove the temporary TopLevelDeclaration node and add UnknownDeclaration to represent other unknown nodes. See the follow-up change for building more top-level declarations. Adding declarators is also pretty involved and will be done in another follow-up patch. Reviewers: gribozavr2 Reviewed By: gribozavr2 Subscribers: merge_guards_bot, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70787
* [libTooling] Add stencil combinators for nodes that may be pointers or values.Yitzhak Mandelbaum2019-11-221-0/+40
| | | | | | | | | | | | | | | | Summary: Adds combinators `maybeDeref` and `maybeAddressOf` to provide a uniform way to handle nodes which may be bound to either a pointer or a value (most often in the context of member expressions). Such polymorphism is already supported by `access`; these combinators extend it to more general uses. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70554
* [clang][Tooling] Filter flags that generate output in SyntaxOnlyAdjusterKadir Cetinkaya2019-11-131-0/+34
| | | | | | | | | | | | | | | | | | Summary: Flags that generate output could result in failures when creating syntax only actions. This patch introduces initial logic for filtering out those. The first such flag is "save-temps", which saves intermediate files(bitcode, assembly, etc.) into a specified directory. Fixes https://github.com/clangd/clangd/issues/191 Reviewers: hokein Subscribers: ilya-biryukov, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70173
* [libTooling] Further simplify `Stencil` type and introduce `MatchComputation`.Yitzhak Mandelbaum2019-11-112-27/+9
| | | | | | | | | | | | | | | | | | | | Summary: This revision introduces a new interface `MatchComputation` which generalizes the `Stencil` interface and replaces the `std::function` interface of `MatchConsumer`. With this revision, `Stencil` (as an abstraction) becomes just one collection of implementations of `MatchComputation<std::string>`. Correspondingly, we remove the `Stencil` class entirely in favor of a simple type alias, deprecate `MatchConsumer` and change all functions that accepted `MatchConsumer<std::string>` to use `MatchComputation<std::string>` instead. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69802
* [libTooling] Fix breakage from change #84922Yitzhak Mandelbaum2019-11-061-1/+4
|
* [libTooling] Small changes in Transformer API.Yitzhak Mandelbaum2019-11-061-36/+37
| | | | | | | | | | | | | | | | | Summary: * Rename `transformer::change` to `transformer::changeTo`, make `change` forward to `changeTo` and mark it deprecated. * Mark `transformer::text` and `transformer::selection` deprecated and migrate references to them in tests. Reviewers: ilya-biryukov Subscribers: gribozavr, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69896
* [libTooling] Simplify type structure of `Stencil`s.Yitzhak Mandelbaum2019-11-061-56/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently, stencils are defined as a sequence of `StencilParts`. This differentiation adds an unneeded layer of complexity to the definition of Stencils. This change significantly simplifies the type structure: a stencil is now conceptually any object implementing `StencilInterface` and `Stencil` is just a thin wrapper for pointers to this interface. To account for the sequencing that was supported by the old `Stencil` type, we introduce a sequencing class that implements `StencilInterface`. That is, sequences are just another kind of Stencil and no longer have any special status. Corresponding to this change in the type structure, we change the way `cat` is used (and defined). `cat` bundles multiple features: it builds a stencil from a sequence of subcomponents and admits multiple different types for its arguments, while coercing them into the right type. Previously, `cat` was also used to coerce a single `StencilPart` into a `Stencil`. With that distinction gone, many uses of `cat` (e.g. in the tests) are unnecessary and have, therefore, been removed. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69613
* [Syntax] Add nodes for most common statementsIlya Biryukov2019-11-061-8/+305
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Most of the statements mirror the ones provided by clang AST. Major differences are: - expressions are wrapped into 'ExpressionStatement' instead of being a subclass of statement, - semicolons are always consumed by the leaf expressions (return, expression satement, etc), - some clang statements are not handled yet, we wrap those into an UnknownStatement class, which is not present in clang. We also define an 'Expression' and 'UnknownExpression' classes in order to produce 'ExpressionStatement' where needed. The actual implementation of expressions is not yet ready, it will follow later. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63835
* [libTooling] Fix r374962: add more Transformer forwarding decls.Yitzhak Mandelbaum2019-10-161-1/+0
| | | | | | | | | | | | | | | | | | Summary: The move to a new, single namespace in r374962 left out some type definitions from the old namespace and resulted in one naming conflict (`text`). This revision adds aliases for those definitions and removes one of the `text` functions from the new namespace. Reviewers: alexfh Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69036 llvm-svn: 375003
* [libTooling] Put all Transformer declarations in a single namespace.Yitzhak Mandelbaum2019-10-163-20/+12
| | | | | | | | | | | | | | | | Summary: This revision introduces a new namespace, `clang::transformer`, to hold the declarations for the Transformer library. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68876 llvm-svn: 374962
* [libTooling] Change Stencil equality to use `toString()`Yitzhak Mandelbaum2019-10-111-33/+11
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Removes the `isEqual` method from StencilPartInterface and modifies equality to use the string representation returned by the `toString` method for comparison. This means the `run` and `selection` stencils return true by default, and clients should be cautious in relying on equality operator for comparison of stencils containing parts generated by these functions. It also means we no longer need the custom RTTI support (typeId() and down_cast()), so it has been removed. Patch by Harshal T. Lehri. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68825 llvm-svn: 374552
* [libTooling] Move Transformer files to their own directory/library.Yitzhak Mandelbaum2019-10-106-6/+7
| | | | | | | | | | | | | | | | | | | Summary: The Transformer library has been growing inside of lib/Tooling/Refactoring. However, it's not really related to anything else in that directory. This revision moves all Transformer-related files into their own include & lib directories. A followup revision will (temporarily) add forwarding headers to help any users migrate their code to the new location. Reviewers: gribozavr Subscribers: mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68637 llvm-svn: 374271
* [libTooling][NFC] Fix build break in r373916.Yitzhak Mandelbaum2019-10-071-14/+22
| | | | | | r373916 used raw strings inside macro calls, which breaks some builds. llvm-svn: 373928
* [libTooling] Add `toString` method to the Stencil classYitzhak Mandelbaum2019-10-071-0/+55
| | | | | | | | | | | | | | | | | Summary: `toString` generates a string representation of the stencil. Patch by Harshal T. Lehri. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68574 llvm-svn: 373916
* [libTooling] Add various Stencil combinators for expressions.Yitzhak Mandelbaum2019-10-031-1/+65
| | | | | | | | | | | | | | | | | | | Summary: This revision adds three new Stencil combinators: * `expression`, which idiomatically constructs the source for an expression, including wrapping the expression's source in parentheses if needed. * `deref`, which constructs an idiomatic dereferencing expression. * `addressOf`, which constructs an idiomatic address-taking expression. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68315 llvm-svn: 373593
* [libTooling] Transformer: refine `SourceLocation` specified as anchor of ↵Yitzhak Mandelbaum2019-09-271-0/+51
| | | | | | | | | | | | | | | | | | | | | | | changes. Summary: Every change triggered by a rewrite rule is anchored at a particular location in the source code. This patch refines how that location is chosen and defines it as an explicit function so it can be shared by other Transformer implementations. This patch was inspired by a bug found by a clang tidy, wherein two changes were anchored at the same location (the expansion loc of the macro) resulting in the discarding of the second change. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66652 llvm-svn: 373093
* [libTooling] Add `run` combinator to Stencils.Yitzhak Mandelbaum2019-09-261-0/+18
| | | | | | | | | | | | | | | | Summary: This revision adds `run`, a StencilPart that runs a user-defined function that computes a result over `MatchFinder::MatchResult`. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67969 llvm-svn: 372936
* [libTooling][NFC] Switch StencilTest.cpp to use EXPECT_THAT_EXPECTEDYitzhak Mandelbaum2019-09-251-21/+4
| | | | | | | | | | | | | | | | Summary: Currently, some tests use homegrown matchers to handle `llvm::Expected` values. This revision standardizes on EXPECT_THAT_EXPECTED and `HasValue`. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67973 llvm-svn: 372918
* [libTooling] Add `access` and `ifBound` combinators to Stencil library.Yitzhak Mandelbaum2019-09-231-8/+111
| | | | | | | | | | | | | | | | | | | | Summary: This revision add the `access` and `ifBound` combinators to the Stencil library: * `access` -- constructs an idiomatic expression for accessing a member (a `MemberExpr`). * `ifBound` -- chooses between two `StencilParts` based on the whether an id is bound in the match (corresponds to the combinator of the same name in RangeSelector). Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67633 llvm-svn: 372605
* [libTooling] Introduce new library of source-code builders.Yitzhak Mandelbaum2019-09-232-0/+231
| | | | | | | | | | | | | | | | | Summary: Introduces facilities for easily building source-code strings, including idiomatic use of parentheses and the address-of, dereference and member-access operators (dot and arrow) and queries about need for parentheses. Reviewers: gribozavr Subscribers: mgorny, cfe-commits, ilya-biryukov Tags: #clang Differential Revision: https://reviews.llvm.org/D67632 llvm-svn: 372595
* [libTooling] Add `ifBound`, `elseBranch` RangeSelector combinators.Yitzhak Mandelbaum2019-09-201-0/+54
| | | | | | | | | | | | | | | | | | Summary: Adds two new combinators and corresponding tests to the RangeSelector library. * `ifBound` -- conditional evaluation of range-selectors, based on whether a given node id is bound in the match. * `elseBranch` -- selects the source range of the else and its statement. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67621 llvm-svn: 372410
* [Tooling] Migrated APIs that take ownership of objects to unique_ptrDmitri Gribenko2019-08-304-52/+54
| | | | | | | | | | Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66960 llvm-svn: 370451
* Changed FrontendActionFactory::create to return a std::unique_ptrDmitri Gribenko2019-08-291-1/+3
| | | | | | | | | | Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66947 llvm-svn: 370379
* Use FileEntryRef for PPCallbacks::HasIncludeAlex Lorenz2019-08-271-0/+35
| | | | | | | | This fixes the issue where a filename dependendency was missing if the file that was referenced with __has_include() was accessed through a symlink in an earlier run, if the file manager was reused between runs. llvm-svn: 370081
* Use FileEntryRef for PPCallbacks::FileSkippedAlex Lorenz2019-08-271-1/+41
| | | | | | | | This fixes the issue where a filename dependendency was missing if the file that was skipped was included through a symlink in an earlier run, if the file manager was reused between runs. llvm-svn: 369998
* Remove unused variables.Benjamin Kramer2019-08-261-2/+0
| | | | llvm-svn: 369965
* Re-enable DependencyScannerTest on windows with the right fixesAlex Lorenz2019-08-241-13/+16
| | | | | | It should now pass. llvm-svn: 369832
* Disable the ScanDepsReuseFilemanager test on WindowsAlex Lorenz2019-08-221-0/+4
| | | | | | | Right now it fails. I'm going to investigate it and fix it in follow-up commits. llvm-svn: 369688
* Introduce FileEntryRef and use it when handling includes to report correct ↵Alex Lorenz2019-08-222-0/+119
| | | | | | | | | | | | | | | | | | | | | | | dependencies when the FileManager is reused across invocations This commit introduces a parallel API to FileManager's getFile: getFileEntryRef, which returns a reference to the FileEntry, and the name that was used to access the file. In the case of a VFS with 'use-external-names', the FileEntyRef contains the external name of the file, not the filename that was used to access it. The new API is adopted only in the HeaderSearch and Preprocessor for include file lookup, so that the accessed path can be propagated to SourceManager's FileInfo. SourceManager's FileInfo now can report this accessed path, using the new getName method. This API is then adopted in the dependency collector, which now correctly reports dependencies when a file is included both using a symlink and a real path in the case when the FileManager is reused across multiple Preprocessor invocations. Note that this patch does not fix all dependency collector issues, as the same problem is still present in other cases when dependencies are obtained using FileSkipped, InclusionDirective, and HasInclude. This will be fixed in follow-up commits. Differential Revision: https://reviews.llvm.org/D65907 llvm-svn: 369680
* [Syntax] Added function to get macro expansion tokens to TokenBuffer.Johan Vikstrom2019-08-201-0/+23
| | | | | | | | | | | | | | | | Summary: Returns the first token in every mapping where the token is an identifier. This API is required to be able to highlight macro expansions in clangd. Reviewers: hokein, ilya-biryukov Subscribers: kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66470 llvm-svn: 369385
OpenPOWER on IntegriCloud