summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling
Commit message (Collapse)AuthorAgeFilesLines
* [Syntax] Merge overlapping top-level macros in TokenBufferSam McCall2020-06-101-5/+29
| | | | | | | | | | | | | | | | | | | 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] Simplify TokenCollector::Builder, use captured expansion bounds. NFCSam McCall2020-06-101-158/+128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The motivation here is fixing https://bugs.llvm.org/show_bug.cgi?id=45428, see D77507. The fundamental problem is that a "top-level" expansion wasn't precisely defined. Repairing this concept means that TokenBuffer's "top-level expansion" may not correspond to a single macro expansion. Example: ``` M(2); // expands to 1+2 ``` The expansions overlap, but neither expansion alone yields all the tokens. We need a TokenBuffer::Mapping that corresponds to their union. This is fairly easy to fix in CollectPPExpansions, but the current design of TokenCollector::Builder needs a fix too as it relies on the macro's expansion range rather than the captured expansion bounds. This fix is hard to make due to the way code is reused within Builder. And honestly, I found that code pretty hard to reason about too. The new approach doesn't use the expansion range, but only the expansion location: it assumes an expansion is the contiguous set of expanded tokens with the same expansion location, which seems like a reasonable formalization of the "top-level" notion. And hopefully the control flow is easier to follow too, it's considerably shorter even with more documentation. Reviewers: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77614 (cherry picked from commit ec0b9908952a9f4a19c3eb92ba0fc01cffcb8614)
* Strip preceeding -Xclang when stripping -fcolor-diagnostics or ↵Kadir Cetinkaya2020-02-261-0/+6
| | | | | | | | | | | | | | | | | | -fdiagnostics-color Summary: Fixes https://github.com/clangd/clangd/issues/279. We were removing the color options but not the preceeding -Xclang which causes errors since the -Xclang would now apply to the next option in the list of options. Now, when removing a color option, we check if there was a preceeding -Xclang and remove it as well. Patch By @DaanDeMeyer ! Reviewers: sammccall, kadircet Reviewed By: sammccall Subscribers: ilya-biryukov, usaxena95 Differential Revision: https://reviews.llvm.org/D75019 (cherry picked from commit da236f235028c82c2f0e00eea1f6f9c689bcae4a)
* Remove trailing `;`. NFC.Michael Liao2020-01-141-1/+1
|
* [Syntax] Unset IsOriginal flag on nodes removed from the treeIlya Biryukov2020-01-141-8/+19
| | | | | | 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/+4
| | | | | This was an oversight in the original patch. Also add corresponding tests.
* [Syntax] Assert invariants on tree structure and fix a bug in mutationsIlya Biryukov2020-01-144-9/+56
| | | | | | | | Add checks for some structural invariants when building and mutating the syntax trees. Fix a bug failing the invariants after mutations: the parent of nodes added into the tree was null.
* [Syntax] Build spanning SimpleDecalration for classes, structs, etcIlya Biryukov2020-01-031-3/+7
| | | | | | | 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.
* [NFC] Fixes -Wrange-loop-analysis warningsMark de Wever2020-01-011-1/+1
| | | | | | This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71857
* Parenthesized a logical expression.Dmitri Gribenko2019-12-201-1/+1
| | | | This change fixes a warning on the ppc64be buildbot.
* Use isa instead of dyn_castDmitri Gribenko2019-12-201-1/+1
|
* [clang][Tooling] Prefer -x over -std when interpolatingKadir Cetinkaya2019-12-201-1/+2
| | | | | | | | | | | | | | | | | | | 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-9/+10
| | | | | | | | 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] Allow to mutate syntax treesIlya Biryukov2019-12-187-14/+358
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-131-1/+0
| | | | | | | | | | | | 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/Syntax] Helpers to find spelled tokens touching a location.Sam McCall2019-12-121-0/+25
| | | | | | | | | | | | 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
* [Syntax] Build nodes for simple cases of top level declarationsIlya Biryukov2019-12-122-1/+104
| | | | | | | | | | | | | | | | 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
* Revert "[clang][clang-scan-deps] Aggregate the full dependency information."Michael Spencer2019-12-113-143/+80
| | | | | | This reverts commit f978ea498309adaebab8fbf1cd6e520e7e0e11f1. It broke clang-ppc64be-linux, but not sure why yet.
* [clang][clang-scan-deps] Aggregate the full dependency information.Michael Spencer2019-12-113-80/+143
| | | | Differential Revision: https://reviews.llvm.org/D70268
* [clang][Tooling] Fix potential UB in ExpandResponseFilesCompilationDatabaseSam McCall2019-12-091-1/+3
| | | | | | | | | | | | | | | | | Summary: `vector::assign` will cause UB at here. fixes: https://github.com/clangd/clangd/issues/223 Reviewers: kadircet, sammccall, hokein Reviewed By: sammccall Subscribers: merge_guards_bot, ilya-biryukov, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71172
* Remove Expr.h include from ASTContext.h, NFCReid Kleckner2019-12-061-0/+1
| | | | | | | ASTContext.h is popular, prune its includes. Expr.h brings in Attr.h, which is also expensive. Move BlockVarCopyInit to Expr.h to accomplish this.
* Reapply "[llvm][Support] Take in CurrentDirectory as a parameter in ↵Kadir Cetinkaya2019-12-042-9/+5
| | | | | | ExpandResponseFiles" Attemps to fix windows buildbots.
* Revert "[llvm][Support] Take in CurrentDirectory as a parameter in ↵Kadir Cetinkaya2019-12-042-5/+9
| | | | | | ExpandResponseFiles" This reverts commit 75656005dbc8866e1888932a68a830b0df403560.
* [llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFilesKadir Cetinkaya2019-12-042-9/+5
| | | | | | | | | | | | | | | | | Summary: This is a follow-up to D70769 and D70222, which allows propagation of current directory down to ExpandResponseFiles for handling of relative paths. Previously clients had to mutate FS to achieve that, which is not thread-safe and can even be thread-hostile in the case of real file system. Reviewers: sammccall Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D70857
* [clang][Tooling] Add support for .rsp files in compile_commands.jsonKadir Cetinkaya2019-12-043-1/+96
| | | | | | | | | | | | | | | | | | | 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/+16
| | | | | | 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-16/+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/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-292-37/+140
| | | | | | | | | | | | | | | | | | | | 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
* [Syntax] Add a comment explaining the pointer keys in std::map<Token*, ...>. NFCIlya Biryukov2019-11-291-0/+2
|
* [Syntax] Remove unused parameter from `TreeBuilder::markChildToken`. NFCIlya Biryukov2019-11-291-20/+15
|
* clang/Modules: Rename CompilerInstance::ModuleManager, NFCDuncan P. N. Exon Smith2019-11-221-3/+2
| | | | | | | | | | | | | | | | | | | Fix the confusing naming of `CompilerInstance::ModuleManager`. This is actually an instance of `ASTReader`, which contains an instance of `ModuleManager`. I have to assume there was a point in the past where they were just one class, but it's been pretty confusing for a while. I think it's time to fix it. The new name is `TheASTReader`; the annoying `The` prefix is so that we don't shadow the `ASTReader` class. I tried out `ASTRdr` but that seemed less clear, and this choice matches `ThePCHContainerOperations` just a couple of declarations below. Also rename `CompilerInstance::getModuleManager` and `CompilerInstance::createModuleManager` to `*ASTReader`, making some cases of `getModuleManager().getModuleManager()` a little more clear. https://reviews.llvm.org/D70583
* [libTooling] Add stencil combinators for nodes that may be pointers or values.Yitzhak Mandelbaum2019-11-221-4/+36
| | | | | | | | | | | | | | | | 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
* [libTooling] Extend `buildASTFromCodeWithArgs` to take files argument.Yitzhak Mandelbaum2019-11-191-1/+7
| | | | | | | | | | | | | | | | | Summary: Adds an optional parameter to `buildASTFromCodeWithArgs` that allows the user to pass additional files that the main code needs to compile. This change makes `buildASTFromCodeWithArgs` consistent with `runToolOnCodeWithArgs`. Patch by Alexey Eremin. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70175
* [clang][Tooling] Filter flags that generate output in SyntaxOnlyAdjusterKadir Cetinkaya2019-11-131-2/+14
| | | | | | | | | | | | | | | | | | 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
* Allow additional file suffixes/extensions considered as source in main ↵mydeveloperday2019-11-121-1/+4
| | | | | | | | | | | | | | | | | | | | | include grouping Summary: By additional regex match, grouping of main include can be enabled in files that are not normally considered as a C/C++ source code. For example, this might be useful in templated code, where template implementations are being held in *Impl.hpp files. On the occassion, 'assume-filename' option description was reworded as it was misleading. It has nothing to do with `style=file` option and it does not influence sourced style filename. Reviewers: rsmith, ioeric, krasimir, sylvestre.ledru, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Patch by: furdyna Tags: #clang Differential Revision: https://reviews.llvm.org/D67750
* [libTooling] Further simplify `Stencil` type and introduce `MatchComputation`.Yitzhak Mandelbaum2019-11-112-26/+42
| | | | | | | | | | | | | | | | | | | | 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
* [clang-rename] Respect the traversal scope when traversing the entire AST.Haojian Wu2019-11-071-1/+1
| | | | | | | | | | | | | | | Summary: This should be NFC to clang-rename, by default the traversal scope is TUDecl. Traversing the TUDecl in clangd is a performance cliff, we should avoid it. Reviewers: ilya-biryukov Subscribers: kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69892
* [Syntax] Silence "unused function" warning in no-assert builds. NFCIlya Biryukov2019-11-071-0/+2
| | | | A helper `isImpicitExpr` is only used inside assert.
* [libTooling] Fix breakage from change #84922Yitzhak Mandelbaum2019-11-061-1/+1
|
* [libTooling] Simplify type structure of `Stencil`s.Yitzhak Mandelbaum2019-11-061-56/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-063-15/+391
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang][ScanDeps] Fix issue with multiple commands with the same input.Michael Spencer2019-10-311-6/+14
| | | | | | | | | | | | | | | | | | | Previously, given a CompilationDatabase with two commands for the same source file we would report that file twice with the union of the dependencies for each command both times. This was due to the way `ClangTool` runs actions given an input source file (see the comment in `DependencyScanningTool.cpp`). This commit adds a `SingleCommandCompilationDatabase` that is created with each `CompileCommand` in the original CDB, which is then used for each `ClangTool` invocation. This gives us a single run of `DependencyScanningAction` per `CompileCommand`. I looked at using `AllTUsToolExecutor` which is a parallel tool executor, but I'm not sure it's suitable for `clang-scan-deps` as it does a lot more sharing of state than `AllTUsToolExecutor` expects. Differential Revision: https://reviews.llvm.org/D69643
* [clang][ScanDeps] Fix shadowing warning.Michael Spencer2019-10-301-5/+5
|
* [clang][clang-scan-deps] Add support for extracting full module dependencies.Michael Spencer2019-10-305-21/+266
| | | | | | | | | | | This is a recommit of d8a4ef0e685c with the nondeterminism fixed. This adds experimental support for extracting a Clang module dependency graph from a compilation database. The output format is experimental and will change. It is currently a concatenation of JSON outputs for each compilation. Future patches will change this to deduplicate modules between compilations. Differential Revision: https://reviews.llvm.org/D69420
* Revert "[clang][clang-scan-deps] Add support for extracting full module ↵Michael Spencer2019-10-305-266/+21
| | | | | | | | dependencies." This reverts commit d8a4ef0e685cec1fc73d4953b48220b649d05b40. This commit broke some of the bots. I believe it's due to nondeterminism. Will fix and recommit.
* [clang][clang-scan-deps] Add support for extracting full module dependencies.Michael Spencer2019-10-305-21/+266
| | | | | | | | | This adds experimental support for extracting a Clang module dependency graph from a compilation database. The output format is experimental and will change. It is currently a concatenation of JSON outputs for each compilation. Future patches will change this to deduplicate modules between compilations. Differential Revision: https://reviews.llvm.org/D69420
* [clang][DependencyScanning] 80-col.Michael Spencer2019-10-251-3/+5
|
* [clang-rename] NFC, make getCanonicalSymbolDeclaration robust on nullptr input.Haojian Wu2019-10-251-0/+2
|
* [clang][DependencyScanning] clang-format.Michael Spencer2019-10-241-2/+3
|
OpenPOWER on IntegriCloud