aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-03-01[ASTMatcher] Add coroutineBodyStmt matcherChris Cotter1-1/+2
The coroutineBodyStmt matcher matches CoroutineBodyStmt AST nodes. Differential Revision: https://reviews.llvm.org/D140794
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #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
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-15/+13
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
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with 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-07-12[clang, clang-tools-extra] Use has_value instead of hasValue (NFC)Kazu Hirata1-4/+4
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-4/+4
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-4/+4
2022-06-25[clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)Kazu Hirata1-9/+9
2021-02-07Add code complete support for mapAnyOfStephen Kelly1-0/+23
2021-02-07Add clang-query support for mapAnyOfStephen Kelly1-2/+28
Differential Revision: https://reviews.llvm.org/D94880
2020-09-23Improve dynamic AST matching diagnostics for conversion errorsAaron Ballman1-4/+2
Currently, when marshaling a dynamic AST matchers, we check for the type and value validity of matcher arguments at the same time for some matchers. For instance, when marshaling hasAttr("foo"), the argument is first type checked to ensure it's a string and then checked to see if that string can locate an attribute with that name. Similar happens for other enumeration conversions like cast kinds or unary operator kinds. If the type is correct but the value cannot be looked up, we make a best-effort attempt to find a nearby name that the user might have meant, but if one cannot be found, we throw our hands up and claim the types don't match. This has an unfortunate behavior that when the user enters something of the correct type but a best guess cannot be located, you get confusing error messages like: Incorrect type for arg 1. (Expected = string) != (Actual = String). This patch splits the argument check into two parts: if the types don't match, give a type diagnostic. If the type matches but the value cannot be converted, give a best guess diagnostic or a value could not be located diagnostic. This addresses PR47057.
2020-07-02[ASTMatchers] Enhanced support for matchers taking Regex argumentsNathan James1-0/+29
Added new Macros `AST(_POLYMORPHIC)_MATCHER_REGEX(_OVERLOAD)` that define a matchers that take a regular expression string and optionally regular expression flags. This lets users match against nodes while ignoring the case without having to manually use `[Aa]` or `[A-Fa-f]` in their regex. The other point this addresses is in the current state, matchers that use regular expressions have to compile them for each node they try to match on, Now the regular expression is compiled once when you define the matcher and used for every node that it tries to match against. If there is an error while compiling the regular expression an error will be logged to stderr showing the bad regex string and the reason it couldn't be compiled. The old behaviour of this was down to the Matcher implementation and some would assert, whereas others just would never match. Support for this has been added to the documentation script as well. Support for this has been added to dynamic matchers ensuring functionality is the same between the 2 use cases. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D82706
2020-05-23Add some explicit use of TK_AsIsStephen Kelly1-1/+1
2020-04-09[ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchersNathan James1-0/+9
Summary: Requires hasCastKind arguments to have `CK_` prefixed to bring it in line with the documentation and other matchers that take enumerations. Reviewers: klimek, aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77503
2020-04-09[ASTMatchers] Add support for dynamic matching of ofKind narrowing matcherNathan James1-0/+8
Summary: Adds support for using the ofKind in clang-query and other dynamic matcher use cases Reviewers: klimek, aaron.ballman, jdoerfert Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77791
2020-04-06[ASTMatchers] Matchers that take enumerations args provide hints with ↵Nathan James1-0/+14
invalid arguments Summary: This adds support for giving hints when using dynamic matchers with enum args. Take this query, I couldn't figure out why the matcher wasn't working: (Turns out it needed to be "IntegralToBoolean", but thats another bug itself) ``` clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean")) 1:1: Error parsing argument 1 for matcher implicitCastExpr. 1:18: Error building matcher hasCastKind. 1:30: Incorrect type for arg 1. (Expected = string) != (Actual = String) ``` With this patch the new behaviour looks like this: ``` clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean")) 1:1: Error parsing argument 1 for matcher implicitCastExpr. 1:18: Error building matcher hasCastKind. 1:30: Unknown value 'CK_IntegralToBoolean' for arg 1; did you mean 'IntegralToBoolean' ``` There are no test cases for this yet as there simply isn't any infrastructure for testing errors reported when parsing args that I can see. Reviewers: klimek, jdoerfert, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, dexonsmith, mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77499
2020-01-29One more batch of things found by g++ 6Benjamin Kramer1-1/+1
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+3
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-05[ParserTest] Move raw string literal out of macroDavid Green1-3/+3
Some combinations of gcc and ccache do not deal well with raw strings in macros. Moving the string out to attempt to fix the bots.
2019-12-27Allow newlines in AST Matchers in clang-query filesStephen Kelly1-23/+142
Reviewers: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71842
2019-12-26Revert "Allow newlines in AST Matchers in clang-query files" + 1Evgenii Stepanov1-142/+23
Revert "Fix -Wunused-lambda-capture warnings." This reverts commit 2369560f4a7720b19edfbf9de14ef061307ff773. This reverts commit 522ee29a4fb3814db604b585c8637247477ec057. clang/lib/ASTMatchers/Dynamic/Parser.cpp:610:13: warning: implicit conversion turns string literal into bool: 'const char [35]' to 'bool' [-Wstring-conversion] assert(!"Newline should never be found here");
2019-12-26Allow newlines in AST Matchers in clang-query filesStephen Kelly1-23/+142
Reviewers: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71842
2019-12-26Revert "Allow newlines in AST Matchers in clang-query files"Stephen Kelly1-142/+23
This reverts commit 6a3ecf4dc7ec299394e71b3124df2b3a34ed4ac3.
2019-12-26Allow newlines in AST Matchers in clang-query filesStephen Kelly1-23/+142
Reviewers: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71842
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-4/+4
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-10-03Revert "[ASTMatchers] Fix DynamicASTMatchersTests again"Fangrui Song1-0/+1
This reverts commit 8a6631a983ec9c1d22cc77c5f55a524a651740f0. The last fix seems good in Debug mode. llvm-svn: 343738
2018-10-03[ASTMatchers] Fix DynamicASTMatchersTests againFangrui Song1-1/+0
llvm-svn: 343722
2018-10-03[test] Fix -Wunused-variable in rC343665Fangrui Song1-1/+1
llvm-svn: 343721
2018-10-03Allow comments with '#' in dynamic AST MatchersStephen Kelly1-2/+17
Summary: This is necessary for clang-query to be able to handle comments. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52751 llvm-svn: 343665
2018-08-30Allow binding to NamedValue resulting from let expressionStephen Kelly1-0/+38
Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51259 llvm-svn: 341142
2018-03-29[ASTMatchers] Introduce a matcher for matching any given Objective-C selectorGeorge Karpenkov1-0/+11
Incudes a tiny related refactoring. Differential Revision: https://reviews.llvm.org/D44858 llvm-svn: 328747
2018-03-29[ASTMatchers] Extend hasParameter and hasAnyParameter matches to handle ↵George Karpenkov1-7/+8
Objective-C methods Differential Revision: https://reviews.llvm.org/D44707 llvm-svn: 328746
2017-07-14Use EXPECT_TRUE rather than EXPECT_EQ(true, ...) to clean up the code and ↵Eric Christopher1-2/+2
silence a null conversion warning. llvm-svn: 307989
2017-06-08[ASTMatchers] Add support for floatLiteralsPeter Wu1-2/+17
Summary: Needed to support something like "floatLiteral(equals(1.0))". The parser for floating point numbers is kept simple, so instead of ".1" you have to use "0.1". Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33135 llvm-svn: 305021
2017-06-08[ASTMatchers] Add support for boolean literalsPeter Wu1-0/+9
Summary: Recognize boolean literals for future extensions ("equals(true)"). Note that a specific VariantValue constructor is added to resolve ambiguity (like "Value = 5") between unsigned and bool. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33093 llvm-svn: 305020
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+0
Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
2016-04-14Reorder ASTNodeKind::AllKindInfo to match NodeKindId.Alexander Kornienko1-1/+1
Summary: AllKindInfo is being indexed by NodeKindId, so the order must match. Extended ASTTypeTraits tests to cover this. Reviewers: sbenza Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19059 llvm-svn: 266268
2016-01-20Add AST matcher support for FunctionDecls with the hasBody matcher.Aaron Ballman1-1/+1
Patch by Aleksei Sidorin. llvm-svn: 258322
2015-10-23[AST] Re-add TypeLocs and NestedNameSpecifierLocs to the ParentMap.Benjamin Kramer1-2/+4
This relands r250831 after some fixes to shrink the ParentMap overall with one addtional tweak: nodes with pointer identity (e.g. Decl* and friends) can be store more efficiently so I put them in a separate map. All other nodes (so far only TypeLoc and NNSLoc) go in a different map keyed on DynTypedNode. This further uglifies the code but significantly reduces memory overhead. Overall this change still make ParentMap significantly larger but it's nowhere as bad as before. I see about 25 MB over baseline (pre-r251008) on X86ISelLowering.cpp. If this becomes an issue we could consider splitting the maps further as DynTypedNode is still larger (32 bytes) than a single TypeLoc (16 bytes) but I didn't want to introduce even more complexity now. Differential Revision: http://reviews.llvm.org/D14011 llvm-svn: 251101
2015-10-21Revert "[AST] Put TypeLocs and NestedNameSpecifierLocs into the ParentMap."Benjamin Kramer1-2/+1
Putting DynTypedNode in the ParentMap bloats its memory foot print. Before the void* key had 8 bytes, now we're at 40 bytes per key which can mean multiple gigabytes increase for large ASTs and this count doesn't even include all the added TypeLoc nodes. Revert until I come up with a better data structure. This reverts commit r250831. llvm-svn: 250889
2015-10-20[AST] Put TypeLocs and NestedNameSpecifierLocs into the ParentMap.Benjamin Kramer1-1/+2
Firstly this changes the type of parent map to be keyed on DynTypedNode to simplify the following changes. This comes with a DenseMapInfo for DynTypedNode, which is a bit incomplete still and will probably only work for parentmap right now. Then the RecursiveASTVisitor in ASTContext is updated and finally ASTMatchers hasParent and hasAncestor learn about the new functionality. Now ParentMap is only missing TemplateArgumentLocs and CXXCtorInitializers. Differential Revision: http://reviews.llvm.org/D13897 llvm-svn: 250831
2015-10-20Roll-back r250822.Angel Garcia Gomez1-1/+1
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-1/+1
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-10-04Pass SourceRange by value in a test I missed in r249259.Craig Topper1-2/+2
llvm-svn: 249260
2015-09-17Rename AST node matchers to match the AST node names directly. Part of this ↵Aaron Ballman1-2/+2
rename also splits recordDecl() (which used to match CXXRecordDecl) into recordDecl() (that matches RecordDecl) and cxxRecordDecl (that matches CXXRecordDecl). Also adds isStruct(), isUnion(), and isClass() narrowing matchers for RecordDecl objects. llvm-svn: 247885
2015-07-06Replace some const std::string & with llvm::StringRef or std::stringYaron Keren1-1/+1
and std::move to avoid implicit std::string construction. Patch by Eugene Kosov. llvm-svn: 241433
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko1-3/+4
Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
2014-10-09Special case 0 and 1 matcher in makeAllOfComposite().Samuel Benzaquen1-1/+4
Summary: Remove unnecessary wrapping for the 0 and 1 matcher cases of makeAllOfComposite(). We don't need a variadic wrapper for those cases. Refactor TrueMatcher to take advandage of the new conversions between DynTypedMatcher and Matcher<T>. Also, make it a singleton. This change improves our clang-tidy related benchmarks by ~12%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5675 llvm-svn: 219431
2014-10-01Refactor Matcher<T> and DynTypedMatcher to reduce overhead of casts.Samuel Benzaquen1-4/+8
Summary: This change introduces DynMatcherInterface and changes the internal representation of DynTypedMatcher and Matcher<T> to use a generic interface instead. It removes unnecessary indirections and virtual function calls when converting matchers by implicit and dynamic casts. DynTypedMatcher now remembers the stricter type in the chain of casts and checks it before calling into DynMatcherInterface. This change improves our clang-tidy related benchmark by ~14%. Also, it opens the door for more optimizations of this kind that are coming in future changes. As a side effect of removing these template instantiations, it also speeds up compilation of Dynamic/Registry.cpp by ~17% and reduces the number of symbols generated by ~30%. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5542 llvm-svn: 218769