sammccall created this revision. sammccall added a reviewer: hokein. Herald added subscribers: usaxena95, kadircet, arphaman. sammccall requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
The AST doesn't track their locations, and the default behavior of attributing them to the lexically-enclosing node is sloppy and often inaccurate. Also add a couple of passing test cases for declarators that weren't obvious. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117185 Files: clang-tools-extra/clangd/Selection.cpp clang-tools-extra/clangd/unittests/SelectionTests.cpp Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -331,9 +331,15 @@ {"int (*getFunc([[do^uble]]))(int);", "BuiltinTypeLoc"}, + // Member pointers and pack expansion use declarator syntax, but are + // restricted so they don't need special casing. + {"class X{}; [[int X::^*]]y[10];", "MemberPointerTypeLoc"}, + {"template<typename ...T> void foo([[T*^...]]x);", + "PackExpansionTypeLoc"}, + // FIXME: the AST has no location info for qualifiers. {"const [[a^uto]] x = 42;", "AutoTypeLoc"}, - {"[[co^nst auto x = 42]];", "VarDecl"}, + {"[[co^nst auto x = 42]];", nullptr}, {"^", nullptr}, {"void foo() { [[foo^^]] (); }", "DeclRefExpr"}, Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -188,8 +188,11 @@ // As well as comments, don't count semicolons as real tokens. // They're not properly claimed as expr-statement is missing from the AST. +// Similarly, we don't have locations for cvr-qualifiers. bool shouldIgnore(const syntax::Token &Tok) { - return Tok.kind() == tok::comment || Tok.kind() == tok::semi; + return Tok.kind() == tok::comment || Tok.kind() == tok::semi || + Tok.kind() == tok::kw_const || Tok.kind() == tok::kw_volatile || + Tok.kind() == tok::kw_restrict; } // Determine whether 'Target' is the first expansion of the macro
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -331,9 +331,15 @@ {"int (*getFunc([[do^uble]]))(int);", "BuiltinTypeLoc"}, + // Member pointers and pack expansion use declarator syntax, but are + // restricted so they don't need special casing. + {"class X{}; [[int X::^*]]y[10];", "MemberPointerTypeLoc"}, + {"template<typename ...T> void foo([[T*^...]]x);", + "PackExpansionTypeLoc"}, + // FIXME: the AST has no location info for qualifiers. {"const [[a^uto]] x = 42;", "AutoTypeLoc"}, - {"[[co^nst auto x = 42]];", "VarDecl"}, + {"[[co^nst auto x = 42]];", nullptr}, {"^", nullptr}, {"void foo() { [[foo^^]] (); }", "DeclRefExpr"}, Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -188,8 +188,11 @@ // As well as comments, don't count semicolons as real tokens. // They're not properly claimed as expr-statement is missing from the AST. +// Similarly, we don't have locations for cvr-qualifiers. bool shouldIgnore(const syntax::Token &Tok) { - return Tok.kind() == tok::comment || Tok.kind() == tok::semi; + return Tok.kind() == tok::comment || Tok.kind() == tok::semi || + Tok.kind() == tok::kw_const || Tok.kind() == tok::kw_volatile || + Tok.kind() == tok::kw_restrict; } // Determine whether 'Target' is the first expansion of the macro
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits