[PATCH] D128611: [libc++] Implement `std::ranges::merge`

2022-06-27 Thread Hui via Phabricator via cfe-commits
huixie90 updated this revision to Diff 440493.
huixie90 added a comment.
Herald added subscribers: cfe-commits, llvm-commits, libc-commits, 
openmp-commits, lldb-commits, Sanitizers, steakhal, nlopes, mtrofin, jsji, 
Enna1, bzcheeseman, kosarev, jsilvanus, mattd, gchakrabarti, ThomasRaoux, 
pmatos, asb, pcwang-thead, yota9, ayermolo, awarzynski, arjunp, sdasgup3, 
luke957, asavonic, carlosgalvezp, jeroen.dobbelaere, Groverkss, wenzhicui, 
wrengr, armkevincheng, ormris, foad, jsmolens, eric-k256, dcaballe, ChuanqiXu, 
cota, mravishankar, teijeong, frasercrmck, rdzhabarov, ecnelises, tatianashp, 
wenlei, mehdi_amini, okura, jdoerfert, bmahjour, msifontes, sstefan1, jurahul, 
kuter, Kayjukh, grosul1, martong, Joonsoo, stephenneuendorffer, kerbowa, 
liufengdb, aartbik, mgester, arpith-jacob, csigg, nicolasvasilache, 
antiagainst, shauheen, rriddle, luismarques, apazos, sameer.abuasal, usaxena95, 
pengfei, s.egerton, Jim, asbirlea, mstorsjo, miyuki, kadircet, jocewei, 
rupprecht, PkmX, arphaman, george.burgess.iv, the_o, brucehoult, MartinMosbeck, 
rogfer01, steven_wu, mgrang, edward-jones, zzheng, MaskRay, jrtc27, gbedwell, 
delcypher, niosHD, sabuasal, simoncook, haicheng, johnrusso, rbar, javed.absar, 
fedor.sergeev, kbarton, aheejin, hiraditya, jgravelle-google, arichardson, 
sbc100, nhaehnle, jvesely, nemanjai, emaste, dylanmckay, jyknight, dschuff, 
arsenm, qcolombet, MatzeB, jholewinski.
Herald added a reviewer: deadalnix.
Herald added a reviewer: bollu.
Herald added a reviewer: andreadb.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jhenderson.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: nicolasvasilache.
Herald added a reviewer: rriddle.
Herald added a reviewer: antiagainst.
Herald added a reviewer: aartbik.
Herald added a reviewer: MaskRay.
Herald added a reviewer: sscalpone.
Herald added a reviewer: jpienaar.
Herald added a reviewer: ftynse.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: aartbik.
Herald added a reviewer: aartbik.
Herald added a reviewer: awarzynski.
Herald added a reviewer: sjarus.
Herald added a reviewer: clementval.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a reviewer: paulkirth.
Herald added projects: clang, Sanitizers, LLDB, OpenMP, libc-project, 
libunwind, MLIR, LLVM, lld-macho, clang-tools-extra, Flang.
Herald added a reviewer: libunwind.
Herald added a reviewer: lld-macho.

reorder includes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128611/new/

https://reviews.llvm.org/D128611

Files:
  bolt/README.md
  bolt/docs/OptimizingClang.md
  bolt/include/bolt/Passes/SplitFunctions.h
  bolt/lib/Core/BinaryFunctionProfile.cpp
  bolt/lib/Core/DebugData.cpp
  bolt/lib/Passes/IndirectCallPromotion.cpp
  bolt/lib/Passes/LongJmp.cpp
  bolt/lib/Passes/SplitFunctions.cpp
  bolt/lib/Rewrite/DWARFRewriter.cpp
  bolt/test/X86/Inputs/dwarf5-call-pc-helper.s
  bolt/test/X86/Inputs/dwarf5-call-pc-main.s
  bolt/test/X86/Inputs/dwarf5-return-pc-helper.s
  bolt/test/X86/Inputs/dwarf5-return-pc-main.s
  bolt/test/X86/bug-reorder-bb-jrcxz.s
  bolt/test/X86/dwarf5-call-pc.test
  bolt/test/X86/dwarf5-return-pc.test
  bolt/test/X86/jump-table-icp.test
  bolt/test/X86/shared_object_entry.s
  bolt/test/X86/unreachable.test
  bolt/test/runtime/X86/exceptions-instrumentation.test
  bolt/test/runtime/X86/pie-exceptions-split.test
  bolt/test/runtime/meta-merge-fdata.test
  clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/FeatureModule.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/LSPClient.cpp
  clang-tools-extra/clangd/unittests/Matchers.h
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/

[PATCH] D145183: [libc++] Implement `stop_token`

2023-05-22 Thread Hui via Phabricator via cfe-commits
huixie90 updated this revision to Diff 524387.
huixie90 added a comment.
Herald added subscribers: cfe-commits, llvm-commits, lldb-commits, Sanitizers, 
TinaAMD, hoy, bviyer, wlei, jplehr, mgehre-amd, luke, hanchung, jsetoain, 
Moerafaat, zero9178, pcwang-thead, anlunx, Enna1, bzcheeseman, mattd, 
gchakrabarti, ThomasRaoux, awarzynski, sdasgup3, wenzhicui, wrengr, snehasish, 
armkevincheng, ormris, foad, jsmolens, sjarus, eric-k256, cota, mravishankar, 
teijeong, frasercrmck, rdzhabarov, tatianashp, wenlei, mehdi_amini, okura, 
jdoerfert, msifontes, sstefan1, jurahul, kuter, Kayjukh, vkmr, grosul1, 
jvesely, Joonsoo, stephenneuendorffer, kerbowa, liufengdb, aartbik, mgester, 
arpith-jacob, csigg, nicolasvasilache, antiagainst, shauheen, rriddle, 
luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, asbirlea, 
kadircet, jocewei, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, 
steven_wu, mgrang, edward-jones, zzheng, MaskRay, jrtc27, gbedwell, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, fedor.sergeev, hiraditya, nemanjai, 
arsenm, jholewinski.
Herald added a reviewer: andreadb.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: nicolasvasilache.
Herald added a reviewer: herhut.
Herald added a reviewer: rriddle.
Herald added a reviewer: aartbik.
Herald added a reviewer: sscalpone.
Herald added a reviewer: ftynse.
Herald added a reviewer: aartbik.
Herald added a reviewer: clementval.
Herald added a reviewer: ThomasRaoux.
Herald added a reviewer: NoQ.
Herald added a reviewer: dcaballe.
Herald added a reviewer: ftynse.
Herald added a reviewer: dcaballe.
Herald added a reviewer: kiranchandramohan.
Herald added projects: clang, Sanitizers, LLDB, MLIR, LLVM, clang-tools-extra, 
Flang.

- [libc++] Implement `stop_token`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145183/new/

https://reviews.llvm.org/D145183

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/docs/ControlFlowIntegrity.rst
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/RISCVVTypes.def
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Basic/riscv_vector_common.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vget_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vloxseg2ei32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlseg2e32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlseg2e32ff_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlsseg2e32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vluxseg2ei32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vset_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsoxseg2ei32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsseg2e32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vssseg2e32_tuple.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsuxseg2ei32_tuple.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vget-index-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vset-index-out-of-range.c
  clang/test/CodeGen/assignment-tracking/flag.cpp
  clang/test/CodeGen/ubsan-function.c
  clang/test/PCH/asm-label.cpp
  clang/test/Sema/flexible-array-in-union.c
  clang/test/Sema/riscv-types.c
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive

[PATCH] D64970: Handle windows line endings in QueryDriver

2019-07-18 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, arphaman, jkorous, ilya-biryukov.
Herald added a project: clang.

The previous patch did not fix the end mark. D64789 

fixes second case of https://github.com/clangd/clangd/issues/93


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D64970

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; 
});
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; });
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64970: Handle windows line endings in QueryDriver

2019-07-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 210735.
lh123 added a comment.

update test.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64970/new/

https://reviews.llvm.org/D64970

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> 
%t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; 
});
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; });
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64970: Handle windows line endings in QueryDriver

2019-07-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 210737.
lh123 added a comment.

update diff context.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64970/new/

https://reviews.llvm.org/D64970

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> 
%t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; 
});
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; });
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64970: [clangd] Handle windows line endings in QueryDriver

2019-07-18 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D64970#1592881 , @kadircet wrote:

> LGTM thanks!
>
> Do you have commit access?


I don't have permission to commit.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64970/new/

https://reviews.llvm.org/D64970



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82373: [CodeComplete] Tweak code completion for `typename`

2020-06-23 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
Herald added subscribers: cfe-commits, usaxena95, ilya-biryukov.
Herald added a project: clang.
lh123 retitled this revision from "[CodeComplete] Tweak code completion for 
"typename" to "[CodeComplete] Tweak code completion for `typename`".

Currently, clangd always completes `typename` as `typename qualifier::name`, I 
think in this completion in the `template <>` is not appropriate. So I tweak it 
to `typename identifier`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82373

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -54,7 +54,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -97,7 +97,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
@@ -134,7 +134,7 @@
   // CHECK-CC3-NEXT: COMPLETION: struct
   // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC3-NEXT: COMPLETION: union
@@ -176,7 +176,7 @@
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#bool#]true
   // CHECK-CC4-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC4-NEXT: COMPLETION: union
@@ -227,7 +227,7 @@
   // CHECK-NO-RTTI: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-NO-RTTI-NOT: typeid
-  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -57,7 +57,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -107,7 +107,7 @@
   // CHECK-CC2-NEXT: COMPLETION: thread_local
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#identifier#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
@@ -150,7 +150,7 @@
   // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC3-NEXT: COMPLETION: thread_local
   // CHECK-CC3-NEXT: COMPLETION: Pattern

[PATCH] D82373: [CodeComplete] Tweak code completion for `typename`

2020-06-24 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 272994.
lh123 edited the summary of this revision.
lh123 added a comment.

address comment.
Also tweak  code completion behavior  for `using`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82373/new/

https://reviews.llvm.org/D82373

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -54,7 +54,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -97,12 +97,12 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#name#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
   // CHECK-CC2-NEXT: COMPLETION: volatile
@@ -134,12 +134,12 @@
   // CHECK-CC3-NEXT: COMPLETION: struct
   // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
-  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#name#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -176,7 +176,7 @@
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#bool#]true
   // CHECK-CC4-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC4-NEXT: COMPLETION: union
@@ -227,7 +227,7 @@
   // CHECK-NO-RTTI: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-NO-RTTI-NOT: typeid
-  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#name#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -57,7 +57,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -107,12 +107,12 @@
   // CHECK-CC2-NEXT: COMPLETION: thread_local
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#name#>

[PATCH] D82373: [CodeComplete] Tweak code completion for `typename`

2020-06-24 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

If this patch looks good, please land it for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82373/new/

https://reviews.llvm.org/D82373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82373: [CodeComplete] Tweak code completion for `typename` and `using`.

2020-06-24 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:2058
   Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
-  Builder.AddPlaceholderChunk("qualifier");
-  Builder.AddTextChunk("::");

kadircet wrote:
> unfortunately the reasoning above doesn't apply here, as a using declaration 
> *must* have a nested-name-specifier. e.g. `using X;` is not allowed. so 
> please revert this (and following on `using typename` it requires a 
> nested-name-specifier too)
Yes, you are right. but I think complete `using` as `using qualifier::name` is 
not useful when user want input something like `using A = B`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82373/new/

https://reviews.llvm.org/D82373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82373: [CodeComplete] Tweak code completion for `typename` and `using`.

2020-06-24 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:2058
   Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
-  Builder.AddPlaceholderChunk("qualifier");
-  Builder.AddTextChunk("::");

lh123 wrote:
> kadircet wrote:
> > unfortunately the reasoning above doesn't apply here, as a using 
> > declaration *must* have a nested-name-specifier. e.g. `using X;` is not 
> > allowed. so please revert this (and following on `using typename` it 
> > requires a nested-name-specifier too)
> Yes, you are right. but I think complete `using` as `using qualifier::name` 
> is not useful when user want input something like `using A = B`.
I think we just need revert change for `using typename qualifier::name`. WDYT.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82373/new/

https://reviews.llvm.org/D82373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82373: [CodeComplete] Tweak code completion for `typename`.

2020-06-24 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273074.
lh123 retitled this revision from "[CodeComplete] Tweak code completion for 
`typename` and `using`." to "[CodeComplete] Tweak code completion for 
`typename`.".
lh123 added a comment.

Address comment.
I will add `using $alias$ = $type$;` in a separate patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82373/new/

https://reviews.llvm.org/D82373

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -54,7 +54,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -97,7 +97,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
@@ -134,7 +134,7 @@
   // CHECK-CC3-NEXT: COMPLETION: struct
   // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC3-NEXT: COMPLETION: union
@@ -176,7 +176,7 @@
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#bool#]true
   // CHECK-CC4-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC4-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC4-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC4-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC4-NEXT: COMPLETION: union
@@ -227,7 +227,7 @@
   // CHECK-NO-RTTI: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-NO-RTTI-NOT: typeid
-  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-NO-RTTI: COMPLETION: Pattern : typename <#name#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -57,7 +57,7 @@
   // CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
-  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
@@ -107,7 +107,7 @@
   // CHECK-CC2-NEXT: COMPLETION: thread_local
   // CHECK-CC2-NEXT: COMPLETION: TYPEDEF : TYPEDEF
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : typename <#name#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof <#expression#>
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
@@ -150,7 +150,7 @@
   // CHECK-CC3-NEXT: COMPLETION: Pattern : template<<#parameters#>>
   // CHECK-CC3-NEXT: COMPLETION: thread_local
   // CHECK-CC3-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>;
-  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : typename <#name#>
   //

[PATCH] D82535: [CodeComplete] Add code completion for using alias.

2020-06-25 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added a reviewer: kadircet.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
lh123 added a parent revision: D82373: [CodeComplete] Tweak code completion for 
`typename`..

Add code completion for using alias.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82535

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -59,6 +59,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -102,6 +103,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
+  // CHECK-CC2-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
@@ -140,6 +142,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC3-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -232,6 +235,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -62,6 +62,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -112,6 +113,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
@@ -156,6 +158,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -264,6 +267,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1816,6 +1816,19 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+// using name = type
+static void AddUsingAliasResult(ResultBuilder &Results) {
+  CodeCompletionBuilder Builder(Results.getAllocator(),
+Results.getCodeCompletionTUInfo());
+  Builder.AddTypedTextChunk("using");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("name");
+  Builder.AddChunk(CodeCompletionString::CK_Equal);
+  Builder.AddPlaceholderChunk("type");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+}

[PATCH] D82535: [CodeComplete] Add code completion for using alias.

2020-06-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273287.
lh123 added a comment.

format code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82535/new/

https://reviews.llvm.org/D82535

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -59,6 +59,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -102,6 +103,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
+  // CHECK-CC2-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
@@ -140,6 +142,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC3-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -232,6 +235,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -62,6 +62,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -112,6 +113,7 @@
   // CHECK-CC2-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
@@ -156,6 +158,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -264,6 +267,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1816,6 +1816,19 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+// using name = type
+static void AddUsingAliasResult(ResultBuilder &Results) {
+  CodeCompletionBuilder Builder(Results.getAllocator(),
+Results.getCodeCompletionTUInfo());
+  Builder.AddTypedTextChunk("using");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("name");
+  Builder.AddChunk(CodeCompletionString::CK_Equal);
+  Builder.AddPlaceholderChunk("type");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+}
+
 static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
const LangOptions

[PATCH] D82535: [CodeComplete] Add code completion for using alias.

2020-06-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273321.
lh123 marked 3 inline comments as done.
lh123 added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82535/new/

https://reviews.llvm.org/D82535

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -59,6 +59,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -103,6 +104,7 @@
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC2-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
   // CHECK-CC2-NEXT: COMPLETION: volatile
@@ -140,6 +142,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC3-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -232,6 +235,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -62,6 +62,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -113,6 +114,7 @@
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
   // CHECK-CC2-NEXT: COMPLETION: volatile
@@ -156,6 +158,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -264,6 +267,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1816,6 +1816,18 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+// using name = type
+static void AddUsingAliasResult(CodeCompletionBuilder &Builder,
+ResultBuilder &Results) {
+  Builder.AddTypedTextChunk("using");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("name");
+  Builder.AddChunk(CodeCompletionString::CK_Equal);
+  Builder.AddPlaceholderChunk("type");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+}
+
 static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
const LangOptions &LangOpts) {
   switch (CCC) {
@@ -2059,6 +2071,9 @@

[PATCH] D82548: [CodeComplete] add code completion for `delete` and `default` specifier.

2020-06-25 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added a reviewer: kadircet.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
lh123 added a parent revision: D82535: [CodeComplete] Add code completion for 
using alias..

add code completion for `delete` and `default` specifier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/delete-default-specifier.cpp

Index: clang/test/CodeCompletion/delete-default-specifier.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/delete-default-specifier.cpp
@@ -0,0 +1,24 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+  A(const A &);
+};
+
+A::A(const A &) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:9:19 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: COMPLETION: default
+// CHECK-CC2-NEXT: COMPLETION: delete
+
+struct B {
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:15:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: COMPLETION: default
+  // CHECK-CC3-NEXT: COMPLETION: delete
+};
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:21:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: COMPLETION: default
+// CHECK-CC4-NEXT: COMPLETION: delete
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -6261,6 +6261,25 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteFunctionDeleteAndDefaultSpecifier() {
+  if (!LangOpts.CPlusPlus11) {
+return;
+  }
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  Results.EnterNewScope();
+  // FIXME(liuhui): Ideally, we should only provide `default` completion for
+  // special functions.
+  Results.AddResult("default");
+  // FIXME(liuhui): Ideally, we should only provide `delete` completion for the
+  // first function declaration.
+  Results.AddResult("delete");
+  Results.ExitScope();
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
+}
+
 /// Macro that optionally prepends an "@" to the string literal passed in via
 /// Keyword, depending on whether NeedAt is true or false.
 #define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2714,6 +2714,11 @@
   DefinitionKind = FDK_Defaulted;
 else if (KW.is(tok::kw_delete))
   DefinitionKind = FDK_Deleted;
+else if (KW.is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefaultSpecifier();
+  cutOffParsing();
+  return nullptr;
+}
   }
 }
 DeclaratorInfo.setFunctionDefinitionKind(DefinitionKind);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2046,46 +2046,52 @@
   }
 
   // Check to see if we have a function *definition* which must have a body.
-  if (D.isFunctionDeclarator() &&
-  // Look at the next token to make sure that this isn't a function
-  // declaration.  We have to check this because __attribute__ might be the
-  // start of a function definition in GCC-extended K&R C.
-  !isDeclarationAfterDeclarator()) {
-
-// Function definitions are only allowed at file scope and in C++ classes.
-// The C++ inline method definition case is handled elsewhere, so we only
-// need to handle the file scope definition case.
-if (Context == DeclaratorContext::FileContext) {
-  if (isStartOfFunctionDefinition(D)) {
-if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-  Diag(Tok, diag::err_function_declared_typedef);
-
-  // Recover by treating the 'typedef' as spurious.
-  DS.ClearStorageClassSpecs();
-}
+  if (D.isFunctionDeclarator()) {
+if (Tok.is(tok::equal) && NextToken().is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefa

[PATCH] D82535: [CodeComplete] Add code completion for using alias.

2020-06-26 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273631.
lh123 added a comment.

Rebase to head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82535/new/

https://reviews.llvm.org/D82535

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ordinary-name-cxx11.cpp
  clang/test/CodeCompletion/ordinary-name.cpp

Index: clang/test/CodeCompletion/ordinary-name.cpp
===
--- clang/test/CodeCompletion/ordinary-name.cpp
+++ clang/test/CodeCompletion/ordinary-name.cpp
@@ -59,6 +59,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -103,6 +104,7 @@
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC2-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
   // CHECK-CC2-NEXT: COMPLETION: volatile
@@ -140,6 +142,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC3-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -232,6 +235,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NOT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/test/CodeCompletion/ordinary-name-cxx11.cpp
===
--- clang/test/CodeCompletion/ordinary-name-cxx11.cpp
+++ clang/test/CodeCompletion/ordinary-name-cxx11.cpp
@@ -62,6 +62,7 @@
   // CHECK-CC1-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-CC1-NEXT: COMPLETION: union
   // CHECK-CC1-NEXT: COMPLETION: unsigned
+  // CHECK-CC1-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC1-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC1-NEXT: COMPLETION: void
   // CHECK-CC1-NEXT: COMPLETION: volatile
@@ -113,6 +114,7 @@
   // CHECK-CC2-NEXT: COMPLETION: union
   // CHECK-CC2-NEXT: COMPLETION: unsigned
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>;
+  // CHECK-CC2-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC2-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-CC2-NEXT: COMPLETION: void
   // CHECK-CC2-NEXT: COMPLETION: volatile
@@ -156,6 +158,7 @@
   // CHECK-CC3-NEXT: COMPLETION: union
   // CHECK-CC3-NEXT: COMPLETION: unsigned
   // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#qualifier#>::<#name#>
+  // CHECK-CC3-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-CC3-NEXT: COMPLETION: virtual
   // CHECK-CC3-NEXT: COMPLETION: void
   // CHECK-CC3-NEXT: COMPLETION: volatile
@@ -264,6 +267,7 @@
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : typeof(<#type#>)
   // CHECK-NO-RTTI-NEXT: COMPLETION: union
   // CHECK-NO-RTTI-NEXT: COMPLETION: unsigned
+  // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using <#name#> = <#type#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : using namespace <#identifier#>;
   // CHECK-NO-RTTI-NEXT: COMPLETION: void
   // CHECK-NO-RTTI-NEXT: COMPLETION: volatile
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1816,6 +1816,18 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+// using name = type
+static void AddUsingAliasResult(CodeCompletionBuilder &Builder,
+ResultBuilder &Results) {
+  Builder.AddTypedTextChunk("using");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("name");
+  Builder.AddChunk(CodeCompletionString::CK_Equal);
+  Builder.AddPlaceholderChunk("type");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+}
+
 static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
const LangOptions &LangOpts) {
   switch (CCC) {
@@ -2059,6 +2071,9 @@
   Builder.AddChunk(CodeCompletionSt

[PATCH] D82714: [clangd] Remove redundant `findRefs` calls. NFC.

2020-06-29 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273928.
lh123 added a comment.

Rebase to head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82714/new/

https://reviews.llvm.org/D82714

Files:
  clang-tools-extra/clangd/XRefs.cpp


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82714: [clangd] Remove redundant `findRefs` calls. NFC.

2020-06-29 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.
lh123 updated this revision to Diff 273928.
lh123 added a comment.

Rebase to head.


Remove redundant `findRefs` calls.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82714

Files:
  clang-tools-extra/clangd/XRefs.cpp


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-29 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273925.
lh123 edited the summary of this revision.
lh123 added a comment.

Rebase to head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/delete-default-specifier.cpp

Index: clang/test/CodeCompletion/delete-default-specifier.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/delete-default-specifier.cpp
@@ -0,0 +1,24 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+  A(const A &);
+};
+
+A::A(const A &) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:9:19 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: COMPLETION: default
+// CHECK-CC2-NEXT: COMPLETION: delete
+
+struct B {
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:15:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: COMPLETION: default
+  // CHECK-CC3-NEXT: COMPLETION: delete
+};
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:21:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: COMPLETION: default
+// CHECK-CC4-NEXT: COMPLETION: delete
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -6261,6 +6261,25 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteFunctionDeleteAndDefaultSpecifier() {
+  if (!LangOpts.CPlusPlus11) {
+return;
+  }
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  Results.EnterNewScope();
+  // FIXME(liuhui): Ideally, we should only provide `default` completion for
+  // special functions.
+  Results.AddResult("default");
+  // FIXME(liuhui): Ideally, we should only provide `delete` completion for the
+  // first function declaration.
+  Results.AddResult("delete");
+  Results.ExitScope();
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
+}
+
 /// Macro that optionally prepends an "@" to the string literal passed in via
 /// Keyword, depending on whether NeedAt is true or false.
 #define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2713,6 +2713,11 @@
   DefinitionKind = FDK_Defaulted;
 else if (KW.is(tok::kw_delete))
   DefinitionKind = FDK_Deleted;
+else if (KW.is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefaultSpecifier();
+  cutOffParsing();
+  return nullptr;
+}
   }
 }
 DeclaratorInfo.setFunctionDefinitionKind(DefinitionKind);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1898,46 +1898,52 @@
   }
 
   // Check to see if we have a function *definition* which must have a body.
-  if (D.isFunctionDeclarator() &&
-  // Look at the next token to make sure that this isn't a function
-  // declaration.  We have to check this because __attribute__ might be the
-  // start of a function definition in GCC-extended K&R C.
-  !isDeclarationAfterDeclarator()) {
-
-// Function definitions are only allowed at file scope and in C++ classes.
-// The C++ inline method definition case is handled elsewhere, so we only
-// need to handle the file scope definition case.
-if (Context == DeclaratorContext::FileContext) {
-  if (isStartOfFunctionDefinition(D)) {
-if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-  Diag(Tok, diag::err_function_declared_typedef);
-
-  // Recover by treating the 'typedef' as spurious.
-  DS.ClearStorageClassSpecs();
-}
+  if (D.isFunctionDeclarator()) {
+if (Tok.is(tok::equal) && NextToken().is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefaultSpecifier();
+  cutOffParsing();
+  return nullptr;
+}
+// Look at the nex

[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-29 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 273942.
lh123 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/delete-default-specifier.cpp

Index: clang/test/CodeCompletion/delete-default-specifier.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/delete-default-specifier.cpp
@@ -0,0 +1,24 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+  A(const A &);
+};
+
+A::A(const A &) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:9:19 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: COMPLETION: default
+// CHECK-CC2-NEXT: COMPLETION: delete
+
+struct B {
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:15:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: COMPLETION: default
+  // CHECK-CC3-NEXT: COMPLETION: delete
+};
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:21:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: COMPLETION: default
+// CHECK-CC4-NEXT: COMPLETION: delete
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -6261,6 +6261,25 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteFunctionDeleteAndDefaultSpecifier() {
+  if (!LangOpts.CPlusPlus11) {
+return;
+  }
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  Results.EnterNewScope();
+  // FIXME(liuhui): Ideally, we should only provide `default` completion for
+  // special functions.
+  Results.AddResult("default");
+  // FIXME(liuhui): Ideally, we should only provide `delete` completion for the
+  // first function declaration.
+  Results.AddResult("delete");
+  Results.ExitScope();
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
+}
+
 /// Macro that optionally prepends an "@" to the string literal passed in via
 /// Keyword, depending on whether NeedAt is true or false.
 #define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2713,6 +2713,11 @@
   DefinitionKind = FDK_Defaulted;
 else if (KW.is(tok::kw_delete))
   DefinitionKind = FDK_Deleted;
+else if (KW.is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefaultSpecifier();
+  cutOffParsing();
+  return nullptr;
+}
   }
 }
 DeclaratorInfo.setFunctionDefinitionKind(DefinitionKind);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1898,46 +1898,52 @@
   }
 
   // Check to see if we have a function *definition* which must have a body.
-  if (D.isFunctionDeclarator() &&
-  // Look at the next token to make sure that this isn't a function
-  // declaration.  We have to check this because __attribute__ might be the
-  // start of a function definition in GCC-extended K&R C.
-  !isDeclarationAfterDeclarator()) {
-
-// Function definitions are only allowed at file scope and in C++ classes.
-// The C++ inline method definition case is handled elsewhere, so we only
-// need to handle the file scope definition case.
-if (Context == DeclaratorContext::FileContext) {
-  if (isStartOfFunctionDefinition(D)) {
-if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-  Diag(Tok, diag::err_function_declared_typedef);
-
-  // Recover by treating the 'typedef' as spurious.
-  DS.ClearStorageClassSpecs();
-}
+  if (D.isFunctionDeclarator()) {
+if (Tok.is(tok::equal) && NextToken().is(tok::code_completion)) {
+  Actions.CodeCompleteFunctionDeleteAndDefaultSpecifier();
+  cutOffParsing();
+  return nullptr;
+}
+// Look at the next token to make sure that this isn't a function
+   

[PATCH] D82714: [clangd] Remove redundant `findRefs` calls. NFC.

2020-06-30 Thread liu hui via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84ced55d9b7b: [clangd] Remove redundant `findRefs` calls. 
NFC. (authored by lh123).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82714/new/

https://reviews.llvm.org/D82714

Files:
  clang-tools-extra/clangd/XRefs.cpp


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))


Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -993,7 +993,6 @@
   DeclRelation::TemplatePattern | DeclRelation::Alias;
   auto Decls = targetDecl(N->ASTNode, Relations);
   if (!Decls.empty()) {
-auto Refs = findRefs({Decls.begin(), Decls.end()}, AST);
 // FIXME: we may get multiple DocumentHighlights with the same location
 // and different kinds, deduplicate them.
 for (const auto &Ref : findRefs({Decls.begin(), Decls.end()}, AST))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-30 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 274491.
lh123 added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/after-function-equals.cpp

Index: clang/test/CodeCompletion/after-function-equals.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/after-function-equals.cpp
@@ -0,0 +1,47 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+
+  A(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:7:18 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // CHECK-CC2: COMPLETION: default
+  // CHECK-CC2-NEXT: COMPLETION: delete
+
+  A(const A &, int) = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:12:23 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3-NOT: COMPLETION: default
+  // CHECK-CC3: COMPLETION: delete
+
+  A(A &&);
+
+  A &operator=(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:19:29 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: COMPLETION: default
+  // CHECK-CC4-NEXT: COMPLETION: delete
+
+  bool operator==(const A &) const = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: COMPLETION: default
+  // CHECK-CC5: COMPLETION: delete
+
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++20 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+  // CHECK-CC6: COMPLETION: default
+  // CHECK-CC6-NEXT: COMPLETION: delete
+
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:33:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+  // CHECK-CC7-NOT: COMPLETION: default
+  // CHECK-CC7: COMPLETION: delete
+};
+
+A::A(A &&) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:39:14 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+// CHECK-CC8: COMPLETION: default
+// CHECK-CC8-NEXT: COMPLETION: delete
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:44:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
+// CHECK-CC9-NOT: COMPLETION: default
+// CHECK-CC9: COMPLETION: delete
\ No newline at end of file
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -24,11 +24,13 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Overload.h"
@@ -6261,6 +6263,50 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteAfterFunctionEquals(Declarator &D) {
+  if (!LangOpts.CPlusPlus11)
+return;
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  auto ShouldAddDefault = [&D, this]() {
+if (!D.isFunctionDeclarator())
+  return false;
+auto &Id = D.getName();
+if (Id.getKind() == UnqualifiedIdKind::IK_DestructorName)
+  return true;
+// FIXME(liuhui): Ideally, we should check the ctor parameter list to
+// verify whether it is a copy ctor or a move ctor.
+if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName &&
+D.getFunctionTypeInfo().NumParams <= 1)
+  return true;
+if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) {
+  auto Op = Id.OperatorFunctionId.Operator;
+  if (Op == OverloadedOperatorKind::OO_Equal)
+return true;
+  if (LangOpts.CPlusPlus20 &&
+  (Op == OverloadedOperatorKind::OO_EqualEqual ||
+   Op == OverloadedOperatorKind::OO_Less ||
+   Op == OverloadedOperatorKind::OO_LessEqual ||
+   Op == OverloadedOperatorKind::OO_Greater ||
+  

[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-30 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 274496.
lh123 added a comment.

Add the missing `operator!=`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/after-function-equals.cpp

Index: clang/test/CodeCompletion/after-function-equals.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/after-function-equals.cpp
@@ -0,0 +1,47 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+
+  A(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:7:18 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // CHECK-CC2: COMPLETION: default
+  // CHECK-CC2-NEXT: COMPLETION: delete
+
+  A(const A &, int) = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:12:23 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3-NOT: COMPLETION: default
+  // CHECK-CC3: COMPLETION: delete
+
+  A(A &&);
+
+  A &operator=(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:19:29 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: COMPLETION: default
+  // CHECK-CC4-NEXT: COMPLETION: delete
+
+  bool operator==(const A &) const = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: COMPLETION: default
+  // CHECK-CC5: COMPLETION: delete
+
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++20 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+  // CHECK-CC6: COMPLETION: default
+  // CHECK-CC6-NEXT: COMPLETION: delete
+
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:33:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+  // CHECK-CC7-NOT: COMPLETION: default
+  // CHECK-CC7: COMPLETION: delete
+};
+
+A::A(A &&) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:39:14 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+// CHECK-CC8: COMPLETION: default
+// CHECK-CC8-NEXT: COMPLETION: delete
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:44:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
+// CHECK-CC9-NOT: COMPLETION: default
+// CHECK-CC9: COMPLETION: delete
\ No newline at end of file
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -24,11 +24,13 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Overload.h"
@@ -6261,6 +6263,51 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteAfterFunctionEquals(Declarator &D) {
+  if (!LangOpts.CPlusPlus11)
+return;
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  auto ShouldAddDefault = [&D, this]() {
+if (!D.isFunctionDeclarator())
+  return false;
+auto &Id = D.getName();
+if (Id.getKind() == UnqualifiedIdKind::IK_DestructorName)
+  return true;
+// FIXME(liuhui): Ideally, we should check the ctor parameter list to
+// verify whether it is a copy ctor or a move ctor.
+if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName &&
+D.getFunctionTypeInfo().NumParams <= 1)
+  return true;
+if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) {
+  auto Op = Id.OperatorFunctionId.Operator;
+  if (Op == OverloadedOperatorKind::OO_Equal)
+return true;
+  if (LangOpts.CPlusPlus20 &&
+  (Op == OverloadedOperatorKind::OO_EqualEqual ||
+   Op == OverloadedOperatorKind::OO_ExclaimEqual ||
+   Op == OverloadedOperatorKind::OO_Less ||
+   Op == OverloadedOperatorKind::OO_LessEqu

[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-30 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D82548#2124546 , @MaskRay wrote:

> Hi, your git commit contains extra Phabricator tags. You can drop 
> `Reviewers:` `Subscribers:` `Tags:` and the text `Summary:` from the git 
> commit with the following script:
>
>   arcfilter () {
>   arc amend
>   git log -1 --pretty=%B | awk '/Reviewers:|Subscribers:/{p=1} 
> /Reviewed By:|Differential Revision:/{p=0} !p && !/^Summary:$/ 
> {sub(/^Summary: /,"");print}' | git commit --amend --date=now -F -
>   }
>   
>
> `Reviewed By: ` is considered important by some people. Please keep the tag. 
> (`--date=now` is my personal preference (author dates are usually not useful. 
> Using committer dates can make log almost monotonic in time))
>
> `https://reviews.llvm.org/D80978` contains a git pre-push hook to automate 
> this.


Thanks, should I revert it and recommit it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82548: [CodeComplete] Add code completion for `delete` and `default` specifier.

2020-06-30 Thread liu hui via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83fae3f76269: [CodeComplete] Add code completion after 
function equals (authored by lh123).

Changed prior to commit:
  https://reviews.llvm.org/D82548?vs=274496&id=274685#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82548/new/

https://reviews.llvm.org/D82548

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/after-function-equals.cpp

Index: clang/test/CodeCompletion/after-function-equals.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/after-function-equals.cpp
@@ -0,0 +1,47 @@
+struct A {
+  A() = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:2:9 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: default
+  // CHECK-CC1-NEXT: COMPLETION: delete
+
+  A(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:7:18 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // CHECK-CC2: COMPLETION: default
+  // CHECK-CC2-NEXT: COMPLETION: delete
+
+  A(const A &, int) = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:12:23 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3-NOT: COMPLETION: default
+  // CHECK-CC3: COMPLETION: delete
+
+  A(A &&);
+
+  A &operator=(const A &) = default;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:19:29 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: COMPLETION: default
+  // CHECK-CC4-NEXT: COMPLETION: delete
+
+  bool operator==(const A &) const = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: COMPLETION: default
+  // CHECK-CC5: COMPLETION: delete
+
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:24:38 -std=gnu++20 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+  // CHECK-CC6: COMPLETION: default
+  // CHECK-CC6-NEXT: COMPLETION: delete
+
+  void test() = delete;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:33:17 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+  // CHECK-CC7-NOT: COMPLETION: default
+  // CHECK-CC7: COMPLETION: delete
+};
+
+A::A(A &&) = default;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:39:14 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+// CHECK-CC8: COMPLETION: default
+// CHECK-CC8-NEXT: COMPLETION: delete
+
+void test() = delete;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:44:15 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
+// CHECK-CC9-NOT: COMPLETION: default
+// CHECK-CC9: COMPLETION: delete
\ No newline at end of file
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -24,11 +24,13 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Designator.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Overload.h"
@@ -6266,6 +6268,53 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteAfterFunctionEquals(Declarator &D) {
+  if (!LangOpts.CPlusPlus11)
+return;
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_Other);
+  auto ShouldAddDefault = [&D, this]() {
+if (!D.isFunctionDeclarator())
+  return false;
+auto &Id = D.getName();
+if (Id.getKind() == UnqualifiedIdKind::IK_DestructorName)
+  return true;
+// FIXME(liuhui): Ideally, we should check the constructor parameter list to
+// verify that it is the default, copy or move constructor?
+if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName &&
+D.getFunctionTypeInfo().NumParams <= 1)
+  return true;
+if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) {
+  auto Op = Id.OperatorFunctionId.Operator;
+  // FIXME(liuhui): Ideally, we should check the function parameter list to
+  // verify that it is the copy or move assignment?
+  if

[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D72498#1814008 , @sammccall wrote:

> I think i'm also comfortable with marking the linked bug as wontfix.


The previous example is just minimal repo.

  template  
  auto sum(T1 &t1, T2 &t2) ->decltype(t1 + t2))
  {  
return t1 + t2;  
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72498/new/

https://reviews.llvm.org/D72498



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

> what do you think about unwrapping decltype only when it's a return value 
> (optional: of a function whose leading return type is auto) to narrowly catch 
> this idiom?

I think it's worth fixing in the declarations too.

  int &bar(int a, int b);
  
  template 
  auto call(Func &&func, Args &&... args)
  -> decltype(func(std::forward(args)...));
  
  template  void useRes(T &&t);
  
  void foo() {
// Under c++11 we don't have decltype(auto), using auto here will lose
// reference.
decltype(call(bar, 5, 6)) res = call(bar, 5, 6);
if (res) {
  // long code to process res
  useRes(res); // User wants to know the type of res here.
} else {
  // long code to process res
  useRes(res);
}
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72498/new/

https://reviews.llvm.org/D72498



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-11 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D72498#1813902 , @ilya-biryukov 
wrote:

> Could it be the case that we want to show the canonical types (i.e. without 
> all syntax sugar)?
>  Maybe we want both the normal type and the canonical type?


+1,I think it would be helpful to show the canonical type in this case.

  int main() {
  std::vector a;
  a.front(); // hover on front
  }

hover over the `front` , you'll see "instance-method `front` → 
`std::vector >::reference`".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72498/new/

https://reviews.llvm.org/D72498



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72500: [clangd] Show hower info for expressions

2020-01-11 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D72500#1813975 , @sammccall wrote:

> I think we should avoid triggering for literals. Maybe some exceptions, but a 
> hover saying that 0 is an int with value 0 seems silly.


Yes, hovering over `IntegerLiteral/FloatingLiteral` may be useless, but I think 
it's useful when hovering over `StringLiteral/UserDefinedLiteral`.

+ hovering over "hello" show `char [6]`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72500/new/

https://reviews.llvm.org/D72500



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-13 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D72498#1816339 , @sammccall wrote:

> In D72498#1816244 , @ilya-biryukov 
> wrote:
>
> > In D72498#1815500 , @lh123 wrote:
> >
> > > - hover over the `front` , you'll see "instance-method `front` → 
> > > `std::vector >::reference`".
> > > - hover over the `push_back`, you'll see "`std::vector > > std::allocator >::value_type && __x`".
> >
> >
> > These look terrible and are the great examples where showing canonical 
> > types results in better output than canonical types.
> >  I wonder why we add `std::vector>::` in the 
> > first place, I believe the standard library uses `value_type` in the 
> > declaration. Showing `value_type` is not great, but at least that doesn't 
> > uglify what was written in the code in the first place.
> >  FWIW, I think the perfect output in those cases would be `int (aka 
> > value_type)`
>
>
> Indeed. Another illustrative example, the return type of 
> `vector::at()` - we'd probably want `int64&` here, rather than 
> `vector<...>::reference` or `unsigned long long`/`unsigned long` depending on 
> platform.


Currently, I think that in most cases, showing both expanded (canonical) and 
spelled types is sufficient.

> This has been used in ycmd for ~4 years without complaint. 
> https://github.com/clangd/clangd/issues/58#issuecomment-507800970




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72498/new/

https://reviews.llvm.org/D72498



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72623: [clangd] Rearrange type, returntype and parameters in hover card

2020-01-14 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

I think the character "🡺" should be avoided, as it may not display properly in 
some environments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72623/new/

https://reviews.llvm.org/D72623



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-24 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: kadircet, sammccall.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Add canonical type to hover when the canonical type and the pretty-printed type 
are not the same.

  c++
  template
  struct TestHover {
using Type = T;
  };
  
  int main() {
TestHover::Type a;
  }

---

**variable a**

Type: TestHover::Type (aka 'int')


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -46,7 +46,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -63,7 +65,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Field
@@ -82,6 +86,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -101,6 +106,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -119,6 +125,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.CanonicalType = "int";
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -138,6 +145,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
  HI.Type = "int";
+ HI.CanonicalType = "int";
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -154,6 +162,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -180,6 +189,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
  HI.Type = "Foo";
+ HI.CanonicalType = "Foo";
}},
   // Implicit template instantiation
   {R"cpp(
@@ -212,11 +222,16 @@
 class Foo {})cpp";
  HI.TemplateParameters = {
  {std::string("template  class"),
+  std::string("template  class"),
   std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {std::string("typename"), std::string("typename"), llvm::None,
+  std::string("char")},
+ {std::string("int"), std::string("int"), llvm::None,
+  std::string("0")},
+ {std::string("bool"), std::string("bool"), std::string("Q"),
+  std::string("false")},
+ {std::string("class..."), std::string("class..."),
+  std::string("Ts"), llvm::None},
  };
}},
   // Function template
@@ -238,7 +253,9 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "template <> void foo>()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Function decl
@@ -256,10 +273,13 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "Foo foo(int, bool T = false)";
  HI.ReturnType = "Foo";
+ HI.CanonicalReturnType = "Foo";
  HI.Type = "Foo (int, bool)";
+ HI.CanonicalType = "Foo (int, bool)";
  HI.Parameters = {
- {std::string("int"), llvm::None, llvm::None},
- {std::string("bool"), std::string("T"), std::string("false")},
+ {std::string("int"), std::string("int"), llvm::None, llvm::None},
+ 

[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-24 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389452.
lh123 added a comment.

add testcase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -46,7 +46,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -63,7 +65,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Field
@@ -82,6 +86,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -101,6 +106,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -119,6 +125,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.CanonicalType = "int";
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -138,6 +145,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
  HI.Type = "int";
+ HI.CanonicalType = "int";
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -154,6 +162,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -180,6 +189,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
  HI.Type = "Foo";
+ HI.CanonicalType = "Foo";
}},
   // Implicit template instantiation
   {R"cpp(
@@ -212,11 +222,16 @@
 class Foo {})cpp";
  HI.TemplateParameters = {
  {std::string("template  class"),
+  std::string("template  class"),
   std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {std::string("typename"), std::string("typename"), llvm::None,
+  std::string("char")},
+ {std::string("int"), std::string("int"), llvm::None,
+  std::string("0")},
+ {std::string("bool"), std::string("bool"), std::string("Q"),
+  std::string("false")},
+ {std::string("class..."), std::string("class..."),
+  std::string("Ts"), llvm::None},
  };
}},
   // Function template
@@ -238,7 +253,9 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "template <> void foo>()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Function decl
@@ -256,10 +273,13 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "Foo foo(int, bool T = false)";
  HI.ReturnType = "Foo";
+ HI.CanonicalReturnType = "Foo";
  HI.Type = "Foo (int, bool)";
+ HI.CanonicalType = "Foo (int, bool)";
  HI.Parameters = {
- {std::string("int"), llvm::None, llvm::None},
- {std::string("bool"), std::string("T"), std::string("false")},
+ {std::string("int"), std::string("int"), llvm::None, llvm::None},
+ {std::string("bool"), std::string("bool"), std::string("T"),
+  std::string("false")},
  };
}},
   // Pointers to lambdas
@@ -277,10 +297,14 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "auto *c = &b";
  HI.Type = "(lambda) **";
+ HI.CanonicalType = "(lambda) **";
  HI.ReturnType = "bool";

[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-24 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389638.
lh123 added a comment.

format code and add testcase for template.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -46,7 +46,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -63,7 +65,9 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Field
@@ -82,6 +86,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -101,6 +106,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -119,6 +125,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
  HI.Type = "int";
+ HI.CanonicalType = "int";
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -138,6 +145,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
  HI.Type = "int";
+ HI.CanonicalType = "int";
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -154,6 +162,7 @@
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
  HI.Type = "char";
+ HI.CanonicalType = "char";
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -180,6 +189,7 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
  HI.Type = "Foo";
+ HI.CanonicalType = "Foo";
}},
   // Implicit template instantiation
   {R"cpp(
@@ -212,11 +222,16 @@
 class Foo {})cpp";
  HI.TemplateParameters = {
  {std::string("template  class"),
+  std::string("template  class"),
   std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {std::string("typename"), std::string("typename"), llvm::None,
+  std::string("char")},
+ {std::string("int"), std::string("int"), llvm::None,
+  std::string("0")},
+ {std::string("bool"), std::string("bool"), std::string("Q"),
+  std::string("false")},
+ {std::string("class..."), std::string("class..."),
+  std::string("Ts"), llvm::None},
  };
}},
   // Function template
@@ -238,7 +253,9 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "template <> void foo>()";
  HI.ReturnType = "void";
+ HI.CanonicalReturnType = "void";
  HI.Type = "void ()";
+ HI.CanonicalType = "void ()";
  HI.Parameters.emplace();
}},
   // Function decl
@@ -256,10 +273,13 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Definition = "Foo foo(int, bool T = false)";
  HI.ReturnType = "Foo";
+ HI.CanonicalReturnType = "Foo";
  HI.Type = "Foo (int, bool)";
+ HI.CanonicalType = "Foo (int, bool)";
  HI.Parameters = {
- {std::string("int"), llvm::None, llvm::None},
- {std::string("bool"), std::string("T"), std::string("false")},
+ {std::string("int"), std::string("int"), llvm::None, llvm::None},
+ {std::string("bool"), std::string("bool"), std::string("T"),
+  std::string("false")},
  };
}},
   // Pointers to lambdas
@@ -277,10 +297,14 @@
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "auto *c = &b";
  HI.Type = "(lambda) **";
+ HI.CanonicalType = "(lambda) **";
   

[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-24 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

Related discussions: D72498 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389909.
lh123 added a comment.
Herald added a project: clang.

address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::string("template  class"), llvm::

[PATCH] D114522: [clangd] Add canonical type to hover

2021-11-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389911.
lh123 added a comment.

fix some bug.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::string("template  class"), llvm::None}},
+  std::string

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389915.
lh123 retitled this revision from "[clangd] Add canonical type to hover" to 
"[clangd] Add desugared type to hover".
lh123 edited the summary of this revision.
lh123 added a comment.

1. rename `CanType` to `DesugaredTy`.
2. fix some bug in compare `PrintedType`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
-   

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389921.
lh123 added a comment.

handle `TypeAliasTemplateDecl`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::string("template  class"), llvm::None}},
+   

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-25 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389924.
lh123 added a comment.

rename `TTP` to `TAT`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::string("template  class"), llvm::None}},
+  st

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389931.
lh123 added a comment.
Herald added a reviewer: gkistanova.

Move some `desugared type` to `Definition`.


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::s

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:691
   } else {
 HI.Definition = printType(QT, PP);
 

sammccall wrote:
> This seems like a pretty important case to handle.
> A wrinkle is that this gets treated as C++ code (e.g. client-side syntax 
> highlighted).
> 
> So we might need something like
> 
> ```
> int64_t
> // aka
> long long
> ```
> 
> or
> ```
> int64_t
> // aka: long long
> ```
It seems we can't do this, vscode always display
```
int64_t
// aka: long long
```
as
```
int64_t
// aka: long long
```

So I change it to `int64_t // aka: long long`


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:166
+if (ShouldAKA)
+  AKA = Result + DesugaredTy.getAsString(PP);
+  }

It seems we lost `namespace qualifiers`.
It always display `std::string` as `basic_string`


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:166
+if (ShouldAKA)
+  AKA = Result + DesugaredTy.getAsString(PP);
+  }

lh123 wrote:
> It seems we lost `namespace qualifiers`.
> It always display `std::string` as `basic_string`
Should we set `FullyQualifiedName` printing policy  for `DesugaredTy`.


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:166
+if (ShouldAKA)
+  AKA = Result + DesugaredTy.getAsString(PP);
+  }

lh123 wrote:
> lh123 wrote:
> > It seems we lost `namespace qualifiers`.
> > It always display `std::string` as `basic_string`
> Should we set `FullyQualifiedName` printing policy  for `DesugaredTy`.
Sometimes we need to distinguish certain types with the same name based on the 
`fully qualified name`.
eg.
```
namespace custom {
template  struct vector {};
} // namespace custom

void code() {
  custom::vector a;
  std::vector b;
}
```
Currently, both `a` and `b` show `vector`.


Repository:
  rZORG LLVM Github Zorg

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114621: [clangd] Show parameters for construct.

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Show parameters for construct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114621

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2683,6 +2683,32 @@
   },
   {
   [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
+  },
+  {
+  [](HoverInfo &HI) {
 HI.Kind = index::SymbolKind::Union;
 HI.AccessSpecifier = "private";
 HI.Name = "foo";
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,21 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
-  }
-}
   } else if (Type) {
 Output.addParagraph().appendText("Type: ").appendCode(*Type);
   }
 
+  if (Parameters && !Parameters->empty()) {
+Output.addParagraph().appendText("Parameters: ");
+markup::BulletList &L = Output.addBulletList();
+for (const auto &Param : *Parameters) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+  OS << Param;
+  L.addItem().addParagraph().appendCode(std::move(OS.str()));
+}
+  }
+
   if (Value) {
 markup::Paragraph &P = Output.addParagraph();
 P.appendText("Value = ");


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2683,6 +2683,32 @@
   },
   {
   [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
+  },
+  {
+  [](HoverInfo &HI) {
 HI.Kind = index::SymbolKind::Union;
 HI.AccessSpecifier = "private";
 HI.Name = "foo";
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,21 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
-  }
-}
   } else if (Type) {
 Output.addParagraph().appendT

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 389968.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,7 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
Index: clang/include/clang/AST/ASTDiagnostic.h
===
--- clang/include/clang/AST/ASTDiagnostic.h
+++ clang/include/clang/AST/ASTDiagnostic.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
 
+#include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticAST.h"
 
@@ -31,6 +32,10 @@
   SmallVectorImpl &Output,
   void *Cookie,
   ArrayRef QualTypeVals);
+
+  /// Returns a desugared version of the QualType, and marks ShouldAKA as true
+  /// whenever we remove significant sugar from the type.
+  QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA);
 }  // end namespace clang
 
 #endif
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -45,8 +45,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -62,8 +62,8 @@
  HI.Kind = index::SymbolKind::Function;
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
- HI.ReturnType = "void";
- HI.Type = "void ()";
+ HI.ReturnType = {"void", llvm::None};
+ HI.Type = {"void ()", llvm::None};
  HI.Parameters.emplace();
}},
   // Field
@@ -81,7 +81,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.Padding = 7;
@@ -100,7 +100,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Size = 1;
  HI.Padding = 15;
  HI.AccessSpecifier = "public";
@@ -118,7 +118,7 @@
  HI.Name = "x";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "int x : 1";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -137,7 +137,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "int bar";
- HI.Type = "int";
+ HI.Type = {"int", llvm::None};
}},
   // Anon namespace and local scope.
   {R"cpp(
@@ -153,7 +153,7 @@
  HI.Name = "bar";
  HI.Kind = index::SymbolKind::Field;
  HI.Definition = "char bar";
- HI.Type = "char";
+ HI.Type = {"char", llvm::None};
  HI.Offset = 0;
  HI.Size = 1;
  HI.AccessSpecifier = "public";
@@ -179,7 +179,7 @@
  HI.Name = "foo";
  HI.Kind = index::SymbolKind::Variable;
  HI.Definition = "Foo foo = Foo(5)";
- HI.Type = "Foo";
+ HI.Type = {"Foo", llvm::None};
}},
   // Implicit template instantiation
   {R"cpp(
@@ -211,12 +211,19 @@
   bool Q = false, class... Ts>
 class Foo {})cpp";
  HI.TemplateParameters = {
- {std::string("template  class"),
-  std::string("C"), llvm::None},
- {std::string("typename"), llvm::None, std::string("char")},
- {std::string("int"), llvm::None, std::string("0")},
- {std::string("bool"), std::string("Q"), std::string("false")},
- {std::string("class..."), std::string("Ts"), llvm::None},
+ {{{std::string("template  class"), llvm::None}},
+  std::string("C"),
+  llvm::None},
+   

[PATCH] D114621: [clangd] Show parameters for construct.

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390143.
lh123 added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114621/new/

https://reviews.llvm.org/D114621

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2680,6 +2680,32 @@
 
 // In cls
 protected: int method())",
+  },
+  {
+  [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
   },
   {
   [](HoverInfo &HI) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1051,27 +1051,29 @@
   Output.addRuler();
   // Print Types on their own lines to reduce chances of getting line-wrapped 
by
   // editor, as they might be long.
-  if (ReturnType) {
+  if (ReturnType)
 // For functions we display signature in a list form, e.g.:
 // → `x`
 // Parameters:
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
-  }
+
+  if (Parameters && !Parameters->empty()) {
+Output.addParagraph().appendText("Parameters: ");
+markup::BulletList &L = Output.addBulletList();
+for (const auto &Param : *Parameters) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+  OS << Param;
+  L.addItem().addParagraph().appendCode(std::move(OS.str()));
 }
-  } else if (Type) {
-Output.addParagraph().appendText("Type: ").appendCode(*Type);
   }
 
+  if (Type && !ReturnType && !Parameters)
+// Don't print Type after Parameters or ReturnType
+Output.addParagraph().appendText("Type: ").appendCode(*Type);
+
   if (Value) {
 markup::Paragraph &P = Output.addParagraph();
 P.appendText("Value = ");


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2680,6 +2680,32 @@
 
 // In cls
 protected: int method())",
+  },
+  {
+  [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
   },
   {
   [](HoverInfo &HI) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1051,27 +1051,29 @@
   Output.addRuler();
   // Print Types on their own lines to reduce chances of getting line-wrapped by
   // editor, as they might be long.
-  if (ReturnType) {
+  if (ReturnType)
 // For functions we display signature in a list form, e.g.:
 // → `x`
 // Parameters:
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->e

[PATCH] D114621: [clangd] Show parameters for construct.

2021-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:1065
 
+  if (Parameters && !Parameters->empty()) {
+Output.addParagraph().appendText("Parameters: ");

kadircet wrote:
> it's a subtle invariant that we only have parameters for functions (which has 
> a return type) or constructor/destructor/conversion-operators (which doesn't 
> have either a type or a return type).
> 
> I think we should assert on `Type` not being present here, as otherwise we 
> would probably duplicate parameters in both places. can you also add a 
> condition around `!Type` and have a comment saying ` // Don't print 
> parameters after Type, as they're likely to be mentioned there.`
We cannot assert here because the `function type` has both `ReturnType`, 
`Type`, and `Parameters`. I think we only need to not print `Type` when 
`ReturnType` or `Parameters` are present.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114621/new/

https://reviews.llvm.org/D114621

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390149.
lh123 marked 13 inline comments as done.
lh123 added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesu

[PATCH] D114665: [clangd] Add a way to enable a.k.a print through config

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Currently, a.k.a printing is closed by default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114665

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
 
 #include "AST.h"
 #include "Annotations.h"
+#include "Config.h"
 #include "Hover.h"
 #include "TestIndex.h"
 #include "TestTU.h"
@@ -2510,7 +2511,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
-
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
 ASSERT_TRUE(H);
 HoverInfo Expected;
@@ -2873,6 +2876,9 @@
   for (const auto &C : Cases) {
 HoverInfo HI;
 C.Builder(HI);
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
   }
 }
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
+
+TEST(ParseYAML, AKAPrint) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Hover:
+  AKAPrint: True
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
 
 #include "AST.h"
 #include "CodeCompletionStrings.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -666,7 +667,9 @@
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << PType.Type;
-  if (PType.AKA)
+
+  const Config &Cfg = Config::current();
+  if (PType.AKA && Cfg.Hover.AKAPrint)
 OS << " // aka: " << *PType.AKA;
   OS.flush();
   return Result;
@@ -1240,7 +1243,9 @@
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
   const HoverInfo::PrintedType &T) {
   OS << T.Type;
-  if (T.AKA)
+  
+  const Config &Cfg = Config::current();
+  if (T.AKA && Cfg.Hover.AKAPrint)
 OS << " (aka " << *T.AKA << ")";
   return OS;
 }
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
 Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -204,6 +205,19 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::HoverBlock &F, Node &N) {
+DictParser Dict("Hover", this);
+Dict.handle("AKAPrint", [&](Node &N) {
+  if (auto Value = scalarValue(N, "AKAPrint")) {
+if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+  F.AKAPrint = *AKAPrint;
+else
+  warning("AKAPrint should be a boolean", N);
+  }
+});
+Dict.parse(N);
+  }
+
   // Helper for parsing mapping nodes (dictionaries).
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
 llvm::Optional> AllScopes;
   };
   CompletionBlock Completion;
+
+  /// Describes hove

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390153.
lh123 added a comment.

format code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesugarStr =
 CompareDesugar.getAsString(

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390154.
lh123 added a comment.

format again.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesugarStr =
 CompareDesugar.getAsString

[PATCH] D114665: [clangd] Make a.k.a printing configurable.

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390158.
lh123 retitled this revision from "[clangd] Add a way to enable a.k.a print 
through config" to "[clangd] Make a.k.a printing configurable.".
lh123 added a comment.

fix testcase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114665/new/

https://reviews.llvm.org/D114665

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
 
 #include "AST.h"
 #include "Annotations.h"
+#include "Config.h"
 #include "Hover.h"
 #include "TestIndex.h"
 #include "TestTU.h"
@@ -979,6 +980,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 ASSERT_TRUE(H);
@@ -2510,7 +2514,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
-
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
 ASSERT_TRUE(H);
 HoverInfo Expected;
@@ -2873,6 +2879,9 @@
   for (const auto &C : Cases) {
 HoverInfo HI;
 C.Builder(HI);
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
   }
 }
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
+
+TEST(ParseYAML, AKAPrint) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Hover:
+  AKAPrint: True
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
 
 #include "AST.h"
 #include "CodeCompletionStrings.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -159,7 +160,9 @@
   }
   QT.print(OS, PP);
   OS.flush();
-  if (!QT.isNull()) {
+
+  const Config &Cfg = Config::current();
+  if (!QT.isNull() && Cfg.Hover.AKAPrint) {
 bool ShouldAKA = false;
 QualType DesugaredTy = clang::desugarForDiagnostic(ASTCtx, QT, ShouldAKA);
 if (ShouldAKA)
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
 Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -204,6 +205,19 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::HoverBlock &F, Node &N) {
+DictParser Dict("Hover", this);
+Dict.handle("AKAPrint", [&](Node &N) {
+  if (auto Value = scalarValue(N, "AKAPrint")) {
+if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+  F.AKAPrint = *AKAPrint;
+else
+  warning("AKAPrint should be a boolean", N);
+  }
+});
+Dict.parse(N);
+  }
+
   // Helper for parsing mapping nodes (dictionaries).
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
 llvm::Optional>

[PATCH] D114621: [clangd] Show parameters for construct.

2021-12-02 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 391537.
lh123 marked 3 inline comments as done.
lh123 added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114621/new/

https://reviews.llvm.org/D114621

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2683,6 +2683,32 @@
   },
   {
   [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
+  },
+  {
+  [](HoverInfo &HI) {
 HI.Kind = index::SymbolKind::Union;
 HI.AccessSpecifier = "private";
 HI.Name = "foo";
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,24 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
-  }
+  }
+
+  if (Parameters && !Parameters->empty()) {
+Output.addParagraph().appendText("Parameters: ");
+markup::BulletList &L = Output.addBulletList();
+for (const auto &Param : *Parameters) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+  OS << Param;
+  L.addItem().addParagraph().appendCode(std::move(OS.str()));
 }
-  } else if (Type) {
-Output.addParagraph().appendText("Type: ").appendCode(*Type);
   }
 
+  // Don't print Type after Parameters or ReturnType as this will just 
duplicate
+  // the information
+  if (Type && !ReturnType && !Parameters)
+Output.addParagraph().appendText("Type: ").appendCode(*Type);
+
   if (Value) {
 markup::Paragraph &P = Output.addParagraph();
 P.appendText("Value = ");


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2683,6 +2683,32 @@
   },
   {
   [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
+  },
+  {
+  [](HoverInfo &HI) {
 HI.Kind = index::SymbolKind::Union;
 HI.AccessSpecifier = "private";
 HI.Name = "foo";
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,24 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().a

[PATCH] D114621: [clangd] Show parameters for construct.

2021-12-02 Thread liu hui via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7bb785cc339b: [clangd] Show parameters for construct. 
(authored by lh123).

Changed prior to commit:
  https://reviews.llvm.org/D114621?vs=391537&id=391542#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114621/new/

https://reviews.llvm.org/D114621

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2680,6 +2680,32 @@
 
 // In cls
 protected: int method())",
+  },
+  {
+  [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
   },
   {
   [](HoverInfo &HI) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,24 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
-  }
+  }
+
+  if (Parameters && !Parameters->empty()) {
+Output.addParagraph().appendText("Parameters: ");
+markup::BulletList &L = Output.addBulletList();
+for (const auto &Param : *Parameters) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+  OS << Param;
+  L.addItem().addParagraph().appendCode(std::move(OS.str()));
 }
-  } else if (Type) {
-Output.addParagraph().appendText("Type: ").appendCode(*Type);
   }
 
+  // Don't print Type after Parameters or ReturnType as this will just 
duplicate
+  // the information
+  if (Type && !ReturnType && !Parameters)
+Output.addParagraph().appendText("Type: ").appendCode(*Type);
+
   if (Value) {
 markup::Paragraph &P = Output.addParagraph();
 P.appendText("Value = ");


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2680,6 +2680,32 @@
 
 // In cls
 protected: int method())",
+  },
+  {
+  [](HoverInfo &HI) {
+HI.Definition = "cls(int a, int b = 5)";
+HI.AccessSpecifier = "public";
+HI.Kind = index::SymbolKind::Constructor;
+HI.NamespaceScope = "";
+HI.LocalScope = "cls";
+HI.Name = "cls";
+HI.Parameters.emplace();
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "a";
+HI.Parameters->emplace_back();
+HI.Parameters->back().Type = "int";
+HI.Parameters->back().Name = "b";
+HI.Parameters->back().Default = "5";
+  },
+  R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
   },
   {
   [](HoverInfo &HI) {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,24 @@
 // - `bool param1`
 // - `int param2 = 5`
 Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-if (Parameters && !Parameters->empty()) {
-  Output.addParagraph().appendText("Parameters: ");
-  markup::BulletList &L = Output.addBulletList();
-  for (const auto &Param : *Parameters) {
-std::string Buffer;
-llvm::raw_string_ostream OS(Buffer);
-OS << Param;
-L.addItem().addParagraph().appendCode(std::move(OS.str()));
- 

[PATCH] D114522: [clangd] Add desugared type to hover

2021-12-02 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 391545.
lh123 added a comment.

rebase to head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114522/new/

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesugarStr =
 CompareDesugar.getAsStri

[PATCH] D114665: [clangd] Make a.k.a printing configurable.

2021-12-02 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 391546.
lh123 added a comment.

rebase to head.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114665/new/

https://reviews.llvm.org/D114665

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
 
 #include "AST.h"
 #include "Annotations.h"
+#include "Config.h"
 #include "Hover.h"
 #include "TestIndex.h"
 #include "TestTU.h"
@@ -979,6 +980,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 ASSERT_TRUE(H);
@@ -2510,7 +2514,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
-
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
 ASSERT_TRUE(H);
 HoverInfo Expected;
@@ -2899,6 +2905,9 @@
   for (const auto &C : Cases) {
 HoverInfo HI;
 C.Builder(HI);
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
   }
 }
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
+
+TEST(ParseYAML, AKAPrint) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Hover:
+  AKAPrint: True
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
 
 #include "AST.h"
 #include "CodeCompletionStrings.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -159,7 +160,9 @@
   }
   QT.print(OS, PP);
   OS.flush();
-  if (!QT.isNull()) {
+
+  const Config &Cfg = Config::current();
+  if (!QT.isNull() && Cfg.Hover.AKAPrint) {
 bool ShouldAKA = false;
 QualType DesugaredTy = clang::desugarForDiagnostic(ASTCtx, QT, ShouldAKA);
 if (ShouldAKA)
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
 Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -204,6 +205,19 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::HoverBlock &F, Node &N) {
+DictParser Dict("Hover", this);
+Dict.handle("AKAPrint", [&](Node &N) {
+  if (auto Value = scalarValue(N, "AKAPrint")) {
+if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+  F.AKAPrint = *AKAPrint;
+else
+  warning("AKAPrint should be a boolean", N);
+  }
+});
+Dict.parse(N);
+  }
+
   // Helper for parsing mapping nodes (dictionaries).
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
 llvm::Optional> AllScopes;
   };
   CompletionBlock Completion;
+
+  /// Describes hover preferences.
+  struct HoverBlock {
+/// Whether hover show a.

[PATCH] D115107: [clang][clangd] Desugar array type.

2021-12-04 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
lh123 added projects: clang, clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Desugar array type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115107

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/test/Misc/diag-aka-types.cpp

Index: clang/test/Misc/diag-aka-types.cpp
===
--- clang/test/Misc/diag-aka-types.cpp
+++ clang/test/Misc/diag-aka-types.cpp
@@ -62,3 +62,9 @@
 void (&f3)(decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'void (decltype(1 + 2))' (aka 'void (int)') cannot bind to a temporary of type 'int'}}
 decltype(1+2) (&f4)(double, decltype(1 + 2)) = 0; // expected-error{{non-const lvalue reference to type 'decltype(1 + 2) (double, decltype(1 + 2))' (aka 'int (double, int)') cannot bind to a temporary of type 'int'}}
 auto (&f5)() -> decltype(1+2) = 0; // expected-error{{non-const lvalue reference to type 'auto () -> decltype(1 + 2)' (aka 'auto () -> int') cannot bind to a temporary of type 'int'}}
+
+using C = decltype(1+2);;
+C a6[10];
+extern C a8[];
+int a9 = a6; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[10]' (aka 'int[10]')}}
+int a10 = a8; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'C[]' (aka 'int[]')}}
Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -131,6 +131,38 @@
   }
 }
 
+if (const auto *CAT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, CAT->getElementType(), ShouldAKA);
+  QT = Context.getConstantArrayType(
+  ElementTy, CAT->getSize(), CAT->getSizeExpr(), CAT->getSizeModifier(),
+  CAT->getIndexTypeCVRQualifiers());
+  break;
+}
+if (const auto *VAT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, VAT->getElementType(), ShouldAKA);
+  QT = Context.getVariableArrayType(
+  ElementTy, VAT->getSizeExpr(), VAT->getSizeModifier(),
+  VAT->getIndexTypeCVRQualifiers(), VAT->getBracketsRange());
+  break;
+}
+if (const auto *DSAT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, DSAT->getElementType(), ShouldAKA);
+  QT = Context.getDependentSizedArrayType(
+  ElementTy, DSAT->getSizeExpr(), DSAT->getSizeModifier(),
+  DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange());
+  break;
+}
+if (const auto *IAT = dyn_cast(Ty)) {
+  QualType ElementTy =
+  desugarForDiagnostic(Context, IAT->getElementType(), ShouldAKA);
+  QT = Context.getIncompleteArrayType(ElementTy, IAT->getSizeModifier(),
+  IAT->getIndexTypeCVRQualifiers());
+  break;
+}
+
 // Don't desugar magic Objective-C types.
 if (QualType(Ty,0) == Context.getObjCIdType() ||
 QualType(Ty,0) == Context.getObjCClassType() ||
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -969,6 +969,52 @@
  HI.Definition = "template  using AA = A";
  HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), llvm::None}};
+   }},
+  {// Constant array
+   R"cpp(
+  using m_int = int;
+
+  m_int ^[[arr]][10];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "m_int arr[10]";
+ HI.Type = {"m_int[10]", "int[10]"};
+   }},
+  {// Incomplete array
+   R"cpp(
+  using m_int = int;
+
+  extern m_int ^[[arr]][];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Definition = "extern m_int arr[]";
+ HI.Type = {"m_int[]", "int[]"};
+   }},
+  {// Dependent size array
+   R"cpp(
+  using m_int = int;
+
+  template
+  struct Test {
+m_int ^[[arr]][Size];
+  };
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Test::";
+ HI.AccessSpecifier = "public";
+ HI.Kind = index::SymbolKind::Field;
+   

[PATCH] D115108: [clangd] Print type for VarTemplateDecl in hover.

2021-12-04 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: kadircet, sammccall.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Print type for `VarTemplateDecl` in hover.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115108

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -901,6 +901,35 @@
  HI.Kind = index::SymbolKind::Unknown;
  HI.Type = "int[10]";
  HI.Value = "{1}";
+   }},
+  {// Var template decl
+   R"cpp(
+  using m_int = int;
+
+  template  m_int ^[[arr]][Size];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "m_int[Size]";
+ HI.NamespaceScope = "";
+ HI.Definition = "template  m_int arr[Size]";
+ HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
+   }},
+  {// Var template decl specialization
+   R"cpp(
+  using m_int = int;
+
+  template  m_int arr[Size];
+
+  template <> m_int ^[[arr]]<4>[4];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr<4>";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "m_int[4]";
+ HI.NamespaceScope = "";
+ HI.Definition = "m_int arr[4]";
}}};
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -594,6 +594,8 @@
 HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = printType(TTP, PP);
+  else if (const auto *VT = dyn_cast(D))
+HI.Type = printType(VT->getTemplatedDecl()->getType(), PP);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -901,6 +901,35 @@
  HI.Kind = index::SymbolKind::Unknown;
  HI.Type = "int[10]";
  HI.Value = "{1}";
+   }},
+  {// Var template decl
+   R"cpp(
+  using m_int = int;
+
+  template  m_int ^[[arr]][Size];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "m_int[Size]";
+ HI.NamespaceScope = "";
+ HI.Definition = "template  m_int arr[Size]";
+ HI.TemplateParameters = {{{"int"}, {"Size"}, llvm::None}};
+   }},
+  {// Var template decl specialization
+   R"cpp(
+  using m_int = int;
+
+  template  m_int arr[Size];
+
+  template <> m_int ^[[arr]]<4>[4];
+ )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "arr<4>";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "m_int[4]";
+ HI.NamespaceScope = "";
+ HI.Definition = "m_int arr[4]";
}}};
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -594,6 +594,8 @@
 HI.Type = TTP->wasDeclaredWithTypename() ? "typename" : "class";
   else if (const auto *TTP = dyn_cast(D))
 HI.Type = printType(TTP, PP);
+  else if (const auto *VT = dyn_cast(D))
+HI.Type = printType(VT->getTemplatedDecl()->getType(), PP);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69928: [clangd] Set RetainCommentsFromSystemHeaders to true

2019-11-06 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, ilya-biryukov.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

clangd should retain comments from system headers.

fixes https://github.com/clangd/clangd/issues/96

note: I don't know much about how to write unit tests, but it works fine on my 
computer.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D69928

Files:
  clang-tools-extra/trunk/clangd/Compiler.cpp
  clang-tools-extra/trunk/clangd/index/IndexAction.cpp


Index: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
===
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp
@@ -160,6 +160,7 @@
   bool BeginInvocation(CompilerInstance &CI) override {
 // We want all comments, not just the doxygen ones.
 CI.getLangOpts().CommentOpts.ParseAllComments = true;
+CI.getLangOpts().RetainCommentsFromSystemHeaders = true;
 // Index the whole file even if there are warnings and -Werror is set.
 // Avoids some analyses too. Set in two places as we're late to the party.
 CI.getDiagnosticOpts().IgnoreWarnings = true;
Index: clang-tools-extra/trunk/clangd/Compiler.cpp
===
--- clang-tools-extra/trunk/clangd/Compiler.cpp
+++ clang-tools-extra/trunk/clangd/Compiler.cpp
@@ -63,6 +63,7 @@
   // createInvocationFromCommandLine sets DisableFree.
   CI->getFrontendOpts().DisableFree = false;
   CI->getLangOpts()->CommentOpts.ParseAllComments = true;
+  CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;
   return CI;
 }
 


Index: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
===
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp
@@ -160,6 +160,7 @@
   bool BeginInvocation(CompilerInstance &CI) override {
 // We want all comments, not just the doxygen ones.
 CI.getLangOpts().CommentOpts.ParseAllComments = true;
+CI.getLangOpts().RetainCommentsFromSystemHeaders = true;
 // Index the whole file even if there are warnings and -Werror is set.
 // Avoids some analyses too. Set in two places as we're late to the party.
 CI.getDiagnosticOpts().IgnoreWarnings = true;
Index: clang-tools-extra/trunk/clangd/Compiler.cpp
===
--- clang-tools-extra/trunk/clangd/Compiler.cpp
+++ clang-tools-extra/trunk/clangd/Compiler.cpp
@@ -63,6 +63,7 @@
   // createInvocationFromCommandLine sets DisableFree.
   CI->getFrontendOpts().DisableFree = false;
   CI->getLangOpts()->CommentOpts.ParseAllComments = true;
+  CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;
   return CI;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69928: [clangd] Set RetainCommentsFromSystemHeaders to true

2019-11-07 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D69928#1736569 , @ilya-biryukov 
wrote:

> LGTM, thanks!
>  Do you need someone to land this?


Yes, I can‘t commit it.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69928/new/

https://reviews.llvm.org/D69928



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, ilya-biryukov, hokein.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

vscode always escapes the colon on the file uri, which causes the semantic 
highlighting fails on windows.

fixes: https://github.com/clangd/clangd/issues/176


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D69996

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/package.json
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -116,9 +116,9 @@
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
 (editors: vscode.TextEditor[]) =>
 editors.forEach((e) => this.highlighter.applyHighlights(
-e.document.uri.toString();
+e.document.uri.toString(true);
 this.subscriptions.push(vscode.workspace.onDidCloseTextDocument(
-(doc) => 
this.highlighter.removeFileHighlightings(doc.uri.toString(;
+(doc) => 
this.highlighter.removeFileHighlightings(doc.uri.toString(true;
   }
 
   handleNotification(params: SemanticHighlightingParams) {
@@ -224,7 +224,8 @@
 // TextEditorDecorationType is used per scope.
 const ranges = this.getDecorationRanges(fileUri);
 vscode.window.visibleTextEditors.forEach((e) => {
-  if (e.document.uri.toString() !== fileUri)
+  // Pass true to prevent escaped colon
+  if (e.document.uri.toString(true) !== fileUri)
 return;
   this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i]));
 });
@@ -239,8 +240,8 @@
 
   // Gets the uris as strings for the currently visible text editors.
   protected getVisibleTextEditorUris(): string[] {
-return vscode.window.visibleTextEditors.map((e) =>
-e.document.uri.toString());
+return vscode.window.visibleTextEditors.map(
+(e) => e.document.uri.toString(true));
   }
 
   // Returns the ranges that should be used when decorating. Index i in the
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -116,9 +116,9 @@
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
 (editors: vscode.TextEditor[]) =>
 editors.forEach((e) => this.highlighter.applyHighlights(
-e.document.uri.toString();
+e.document.uri.toString(true);
 this.subscriptions.push(vscode.workspace.onDidCloseTextDocument(
-(doc) => this.highlighter.removeFileHighlightings(doc.uri.toString(;
+(doc) => this.highlighter.removeFileHighlightings(doc.uri.toString(true;
   }
 
   handleNotification(params: SemanticHighlightingParams) {
@@ -224,7 +224,8 @@
 // TextEditorDecorationType is used per scope.
 const ranges = this.getDecorationRanges(fileUri);
 vscode.window.visibleTextEditors.forEach((e) => {
-  if (e.document.uri.toString() !== fileUri)
+  // Pass true to prevent escaped colon
+  if (e.document.uri.toString(true) !== fileUri)
 return;
   this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i]));
 });
@@ -239,8 +240,8 @@
 
   // Gets the uris as strings for the currently visible text editors.
   protected getVisibleTextEditorUris(): string[] {
-return vscode.window.visibleTextEditors.map((e) =>
-e.document.uri.toString());
+return vscode.window.visibleTextEditors.map(
+(e) => e.document.uri.toString(true));
   }
 
   // Returns the ranges that should be used when decorating. Index i in the
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===

[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 planned changes to this revision.
lh123 added a comment.

it will cause whitspace escaped problem.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 228393.
lh123 added a comment.

update diff


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/1.patch
  clang-tools-extra/clangd/clients/clangd-vscode/package.json
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 228397.
lh123 added a comment.

Remove irrelevant files from the patch


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/package.json
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 228405.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/package.json
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -124,7 +124,8 @@
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
Index: clang-tools-extra/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/clangd/clients/clangd-vscode/package.json
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.18",
+"version": "0.0.19",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 228421.
lh123 added a comment.

address comment


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996

Files:
  package.json
  src/semantic-highlighting.ts

Index: src/semantic-highlighting.ts
===
--- src/semantic-highlighting.ts
+++ src/semantic-highlighting.ts
@@ -114,17 +114,17 @@
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
-(editors: vscode.TextEditor[]) =>
-editors.forEach((e) => this.highlighter.applyHighlights(
-e.document.uri.toString();
+(editors: vscode.TextEditor[]) => editors.forEach(
+(e) => this.highlighter.applyHighlights(e.document.uri;
 this.subscriptions.push(vscode.workspace.onDidCloseTextDocument(
-(doc) => this.highlighter.removeFileHighlightings(doc.uri.toString(;
+(doc) => this.highlighter.removeFileHighlightings(doc.uri)));
   }
 
   handleNotification(params: SemanticHighlightingParams) {
 const lines: SemanticHighlightingLine[] = params.lines.map(
 (line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
-this.highlighter.highlight(params.textDocument.uri, lines);
+this.highlighter.highlight(vscode.Uri.parse(params.textDocument.uri),
+   lines);
   }
   // Disposes of all disposable resources used by this object.
   public dispose() {
@@ -199,19 +199,21 @@
   // Adds incremental highlightings to the current highlightings for the file
   // with fileUri. Also applies the highlightings to any associated
   // TextEditor(s).
-  public highlight(fileUri: string,
+  public highlight(fileUri: vscode.Uri,
highlightingLines: SemanticHighlightingLine[]) {
-if (!this.files.has(fileUri)) {
-  this.files.set(fileUri, new Map());
+const fileUriStr = fileUri.toString();
+if (!this.files.has(fileUriStr)) {
+  this.files.set(fileUriStr, new Map());
 }
-const fileHighlightings = this.files.get(fileUri);
+const fileHighlightings = this.files.get(fileUriStr);
 highlightingLines.forEach((line) => fileHighlightings.set(line.line, line));
 this.applyHighlights(fileUri);
   }
 
   // Applies all the highlightings currently stored for a file with fileUri.
-  public applyHighlights(fileUri: string) {
-if (!this.files.has(fileUri))
+  public applyHighlights(fileUri: vscode.Uri) {
+const fileUriStr = fileUri.toString();
+if (!this.files.has(fileUriStr))
   // There are no highlightings for this file, must return early or will get
   // out of bounds when applying the decorations below.
   return;
@@ -224,7 +226,7 @@
 // TextEditorDecorationType is used per scope.
 const ranges = this.getDecorationRanges(fileUri);
 vscode.window.visibleTextEditors.forEach((e) => {
-  if (e.document.uri.toString() !== fileUri)
+  if (e.document.uri.toString() !== fileUriStr)
 return;
   this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i]));
 });
@@ -232,27 +234,27 @@
 
   // Called when a text document is closed. Removes any highlighting entries for
   // the text document that was closed.
-  public removeFileHighlightings(fileUri: string) {
+  public removeFileHighlightings(fileUri: vscode.Uri) {
 // If there exists no entry the call to delete just returns false.
-this.files.delete(fileUri);
+this.files.delete(fileUri.toString());
   }
 
   // Gets the uris as strings for the currently visible text editors.
-  protected getVisibleTextEditorUris(): string[] {
-return vscode.window.visibleTextEditors.map((e) =>
-e.document.uri.toString());
+  protected getVisibleTextEditorUris(): vscode.Uri[] {
+return vscode.window.visibleTextEditors.map((e) => e.document.uri);
   }
 
   // Returns the ranges that should be used when decorating. Index i in the
   // range array has the decoration type at index i of this.decorationTypes.
-  protected getDecorationRanges(fileUri: string): vscode.Range[][] {
-if (!this.files.has(fileUri))
+  protected getDecorationRanges(fileUri: vscode.Uri): vscode.Range[][] {
+const fileUriStr = fileUri.toString();
+if (!this.files.has(fileUriStr))
   // this.files should always have an entry for fileUri if we are here. But
   // if there isn't one we don't want to crash the extension. This is also
   // useful for tests.
   return [];
 const lines: SemanticHighlightingLine[] =
-Array.from(this.files.get(fileUri).values());
+Array.from(this.files.get(fileUriStr).values());
 const decorations: vscode.Range[][] = this.decorationTypes.map(() => []);
 lines.forEach((line) => {
   line.tokens.forEach((token) => {
In

[PATCH] D69996: [clangd] Fixed colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 marked 2 inline comments as done.
lh123 added inline comments.



Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:128
+this.highlighter.highlight(
+vscode.Uri.parse(params.textDocument.uri).toString(), lines);
   }

ilya-biryukov wrote:
> Could we accept a `URI` in the `highlight` (and similar function in 
> highlighting) instead and compare the URIs instead of strings in the 
> `Highlighter.applyHighlightings`?
> 
> i.e. in code:
> ```
>  fileUri : string;
>  if (e.document.uri.toString() !== fileUri) 
>return;
> ```
> Could instead be:
> ```
>  fileUri : Uri;
>  if (e.document.uri.toString() !== fileUri.toString()) 
>return;
> ```
> 
> 
> This should normalize accordingly and is generally safer and more readable 
> than passing around strings.
Yes, you are right, I will refactor it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69996: [clangd] Fixes colon escaping on Windows

2019-11-08 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

Thanks for your reminder, I have sent an email to apply for commit access, but 
I don't know how long it will take.

> Should I land this patch for you?

Yes, you can land this patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70078: [clangd] fixes semantic highlighting test

2019-11-11 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: ilya-biryukov, hokein, sammccall.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

fixes https://github.com/clangd/clangd/issues/176


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70078

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
  
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts

Index: clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -84,19 +84,24 @@
   return scopeRanges;
 };
 
+const fileUri1 = vscode.Uri.parse('file:///file1');
+const fileUri2 = vscode.Uri.parse('file:///file2');
+const fileUri1Str = fileUri1.toString();
+const fileUri2Str = fileUri2.toString();
+
 class MockHighlighter extends semanticHighlighting.Highlighter {
   applicationUriHistory: string[] = [];
   // Override to make the highlighting calls accessible to the test. Also
   // makes the test not depend on visible text editors.
-  applyHighlights(fileUri: string) {
-this.applicationUriHistory.push(fileUri);
+  applyHighlights(fileUri: vscode.Uri) {
+this.applicationUriHistory.push(fileUri.toString());
   }
   // Override to make it accessible from the test.
-  getDecorationRanges(fileUri: string) {
+  getDecorationRanges(fileUri: vscode.Uri) {
 return super.getDecorationRanges(fileUri);
   }
   // Override to make tests not depend on visible text editors.
-  getVisibleTextEditorUris() { return [ 'file1', 'file2' ]; }
+  getVisibleTextEditorUris() { return [ fileUri1, fileUri2 ]; }
 }
 const highlighter = new MockHighlighter(scopeTable);
 const tm = new semanticHighlighting.ThemeRuleMatcher([
@@ -104,11 +109,11 @@
   {scope : 'entity.type', foreground : '2'},
 ]);
 // Recolorizes when initialized.
-highlighter.highlight('file1', []);
-assert.deepEqual(highlighter.applicationUriHistory, [ 'file1' ]);
+highlighter.highlight(fileUri1, []);
+assert.deepEqual(highlighter.applicationUriHistory, [ fileUri1Str ]);
 highlighter.initialize(tm);
 assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2' ]);
+ [ fileUri1Str, fileUri1Str, fileUri2Str ]);
 // Groups decorations into the scopes used.
 let highlightingsInLine: semanticHighlighting.SemanticHighlightingLine[] = [
   {
@@ -128,10 +133,10 @@
   },
 ];
 
-highlighter.highlight('file1', highlightingsInLine);
+highlighter.highlight(fileUri1, highlightingsInLine);
 assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1' ]);
-assert.deepEqual(highlighter.getDecorationRanges('file1'),
+ [ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str ]);
+assert.deepEqual(highlighter.getDecorationRanges(fileUri1),
  createHighlightingScopeRanges(highlightingsInLine));
 // Keeps state separate between files.
 const highlightingsInLine1:
@@ -141,26 +146,29 @@
 {character : 2, length : 1, scopeIndex : 0},
   ]
 };
-highlighter.highlight('file2', [ highlightingsInLine1 ]);
-assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1', 'file2' ]);
-assert.deepEqual(highlighter.getDecorationRanges('file2'),
+highlighter.highlight(fileUri2, [ highlightingsInLine1 ]);
+assert.deepEqual(
+highlighter.applicationUriHistory,
+[ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str ]);
+assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
  createHighlightingScopeRanges([ highlightingsInLine1 ]));
 // Does full colorizations.
-highlighter.highlight('file1', [ highlightingsInLine1 ]);
-assert.deepEqual(highlighter.applicationUriHistory,
- [ 'file1', 'file1', 'file2', 'file1', 'file2', 'file1' ]);
+highlighter.highlight(fileUri1, [ highlightingsInLine1 ]);
+assert.deepEqual(highlighter.applicationUriHistory, [
+  fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str,
+  fileUri1Str
+]);
 // After the incremental update to line 1, the old highlightings at line 1
 // will no longer exist in the array.
 assert.deepEqual(
-highlighter.getDecorationRanges('file1'),
+highlighter.getDecorationRanges(fileUri1),
 createHighlightingScopeRanges(
 [ highlightingsInLine1, ...highlightingsInLine.slice(1) ]

[PATCH] D69996: [clangd] Fixes colon escaping on Windows

2019-11-11 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D69996#1740412 , @hokein wrote:

> I believe this patch fixes the issue,  but we need to update the file 
> `test/semantic-highlighting.test.ts`), the test "Colorizer groups decorations 
> correctly" is diverged from the actual code, although it is still passed 
> (both `string` and `vscode.Uri` have the `toString` method unfortunately).
>
> @lh123  do you mind doing that?


Sorry, I forgot to update the test case, I have submitted a new patch. D70078 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69996/new/

https://reviews.llvm.org/D69996



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70164: [JSONCompilationDatabase] Fix backslash escaping on Windows

2019-11-12 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, ilya-biryukov, hokein.
Herald added subscribers: cfe-commits, usaxena95, mstorsjo, kadircet.
Herald added a project: clang.

We should always use `TokenizeWindowsCommandLine` on Windows.

When compiling clangd with `MinGW-W64`, `Triple.getEnvironment` will return 
`EnvironmentType::GNU`.

fixes https://github.com/clangd/clangd/issues/92.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70164

Files:
  clang/lib/Tooling/JSONCompilationDatabase.cpp


Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -137,11 +137,7 @@
 Syntax = JSONCommandLineSyntax::Gnu;
 llvm::Triple Triple(llvm::sys::getProcessTriple());
 if (Triple.getOS() == llvm::Triple::OSType::Win32) {
-  // Assume Windows command line parsing on Win32 unless the triple
-  // explicitly tells us otherwise.
-  if (!Triple.hasEnvironment() ||
-  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
-Syntax = JSONCommandLineSyntax::Windows;
+  Syntax = JSONCommandLineSyntax::Windows;
 }
   }
 


Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -137,11 +137,7 @@
 Syntax = JSONCommandLineSyntax::Gnu;
 llvm::Triple Triple(llvm::sys::getProcessTriple());
 if (Triple.getOS() == llvm::Triple::OSType::Win32) {
-  // Assume Windows command line parsing on Win32 unless the triple
-  // explicitly tells us otherwise.
-  if (!Triple.hasEnvironment() ||
-  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
-Syntax = JSONCommandLineSyntax::Windows;
+  Syntax = JSONCommandLineSyntax::Windows;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70164: [Tooling][JSONCompilationDatabase] Fix backslash escaping on Windows

2019-11-13 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Tooling/JSONCompilationDatabase.cpp:153
   assert(Syntax == JSONCommandLineSyntax::Gnu);
   CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();

I think we can use `TokenizeGNUCommandLine` instead of 
`CommandLineArgumentParser`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70164/new/

https://reviews.llvm.org/D70164



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-13 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, ilya-biryukov, hokein.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

Add support for .rsp files in compile_commands.json.

expand response file in `OverlayCDB`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70222

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -17,8 +17,15 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 #include 
 #include 
@@ -27,6 +34,123 @@
 namespace clangd {
 namespace {
 
+// It is called byte order marker but the UTF-8 BOM is actually not affected
+// by the host system's endianness.
+static bool hasUTF8ByteOrderMark(ArrayRef S) {
+  return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' && S[2] == '\xbf');
+}
+
+static bool expandResponseFile(llvm::StringRef FName, llvm::StringSaver &Saver,
+   llvm::cl::TokenizerCallback Tokenizer,
+
+   SmallVectorImpl &NewArgv) {
+  llvm::ErrorOr> MemBufOrErr =
+  llvm::MemoryBuffer::getFile(FName);
+  if (!MemBufOrErr)
+return false;
+  llvm::MemoryBuffer &MemBuf = *MemBufOrErr.get();
+  StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
+
+  // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
+  ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
+  std::string UTF8Buf;
+  if (llvm::hasUTF16ByteOrderMark(BufRef)) {
+if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
+  return false;
+Str = StringRef(UTF8Buf);
+  }
+  // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
+  // these bytes before parsing.
+  // Reference: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
+  else if (hasUTF8ByteOrderMark(BufRef))
+Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
+  // Tokenize the contents into NewArgv.
+  Tokenizer(Str, Saver, NewArgv, false);
+  return true;
+}
+
+static bool expandResponseFiles(tooling::CompileCommand &Cmd,
+llvm::cl::TokenizerCallback Tokenizer) {
+  bool AllExpanded = true;
+  struct ResponseFileRecord {
+llvm::StringRef File;
+size_t End;
+  };
+  std::vector &Argv = Cmd.CommandLine;
+  // To detect recursive response files, we maintain a stack of files and the
+  // position of the last argument in the file. This position is updated
+  // dynamically as we recursively expand files.
+  SmallVector FileStack;
+
+  // Push a dummy entry that represents the initial command line, removing
+  // the need to check for an empty list.
+  FileStack.push_back({"", Argv.size()});
+
+  // Don't cache Argv.size() because it can change.
+  for (unsigned I = 0; I != Argv.size();) {
+while (I == FileStack.back().End) {
+  // Passing the end of a file's argument list, so we can remove it from the
+  // stack.
+  FileStack.pop_back();
+}
+
+std::string &Arg = Argv[I];
+
+if (Arg[0] != '@') {
+  ++I;
+  continue;
+}
+SmallString<128> ResponseFile;
+if (llvm::sys::path::is_relative(&Arg[1])) {
+  llvm::sys::path::append(ResponseFile, Cmd.Directory, &Arg[1]);
+}
+auto IsEquivalent = [ResponseFile](const ResponseFileRecord &RFile) {
+  return llvm::sys::fs::equivalent(RFile.File, ResponseFile);
+};
+
+// Check for recursive response files.
+if (std::any_of(FileStack.begin() + 1, FileStack.end(), IsEquivalent)) {
+  // This file is recursive, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+// Replace this response file argument with the tokenization of its
+// contents.  Nested response files are expanded in subsequent iterations.
+SmallVector ExpandedArgv;
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSaver Saver(Alloc);
+llvm::SmallVector T;
+if (!expandResponseFile(ResponseFile, Saver, Tokenizer, ExpandedArgv)) {
+  // We couldn't read this file, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+for (ResponseFileRecord &Record : FileStack) {
+  // Increase the end of all active records by the number of newly expanded
+  // arguments, minus the

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-14 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

I don't know much about how to write unit tests, but it works fine on my 
computer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70359: [clangd] Show values of more expressions on hover

2019-11-17 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:423
+  //  - certain expressions (sizeof etc)
+  //  - built-in types
 }

I think we should also support hover on literal.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70359/new/

https://reviews.llvm.org/D70359



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 229758.
lh123 added a comment.

update diff


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -17,8 +17,10 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 #include 
 #include 
@@ -27,6 +29,124 @@
 namespace clangd {
 namespace {
 
+bool expandResponseFile(llvm::StringRef FName, llvm::StringSaver &Saver,
+llvm::cl::TokenizerCallback Tokenizer,
+SmallVectorImpl &NewArgv) {
+  llvm::ErrorOr> MemBufOrErr =
+  llvm::MemoryBuffer::getFile(FName);
+  if (!MemBufOrErr)
+return false;
+  llvm::MemoryBuffer &MemBuf = *MemBufOrErr.get();
+  StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
+
+  // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
+  ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
+  std::string UTF8Buf;
+  // It is called byte order marker but the UTF-8 BOM is actually not affected
+  // by the host system's endianness.
+  auto HasUtF8ByteOrderMark = [](ArrayRef S) {
+return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' &&
+S[2] == '\xbf');
+  };
+  if (llvm::hasUTF16ByteOrderMark(BufRef)) {
+if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
+  return false;
+Str = StringRef(UTF8Buf);
+  }
+  // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
+  // these bytes before parsing.
+  // Reference: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
+  else if (HasUtF8ByteOrderMark(BufRef))
+Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
+  // Tokenize the contents into NewArgv.
+  Tokenizer(Str, Saver, NewArgv, false);
+  return true;
+}
+
+bool expandResponseFiles(tooling::CompileCommand &Cmd,
+ llvm::cl::TokenizerCallback Tokenizer) {
+  bool AllExpanded = true;
+  struct ResponseFileRecord {
+llvm::StringRef File;
+size_t End;
+  };
+  std::vector &Argv = Cmd.CommandLine;
+  // To detect recursive response files, we maintain a stack of files and the
+  // position of the last argument in the file. This position is updated
+  // dynamically as we recursively expand files.
+  SmallVector FileStack;
+
+  // Push a dummy entry that represents the initial command line, removing
+  // the need to check for an empty list.
+  FileStack.push_back({"", Argv.size()});
+
+  // Don't cache Argv.size() because it can change.
+  for (unsigned I = 0; I != Argv.size();) {
+while (I == FileStack.back().End) {
+  // Passing the end of a file's argument list, so we can remove it from the
+  // stack.
+  FileStack.pop_back();
+}
+
+std::string &Arg = Argv[I];
+
+if (Arg[0] != '@') {
+  ++I;
+  continue;
+}
+SmallString<128> ResponseFile;
+if (llvm::sys::path::is_relative(&Arg[1])) {
+  llvm::sys::path::append(ResponseFile, Cmd.Directory, &Arg[1]);
+}
+llvm::sys::path::remove_dots(ResponseFile);
+
+auto IsEquivalent = [ResponseFile](const ResponseFileRecord &RFile) {
+  return llvm::sys::fs::equivalent(RFile.File, ResponseFile);
+};
+
+// Check for recursive response files.
+if (std::any_of(FileStack.begin() + 1, FileStack.end(), IsEquivalent)) {
+  // This file is recursive, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+// Replace this response file argument with the tokenization of its
+// contents.  Nested response files are expanded in subsequent iterations.
+SmallVector ExpandedArgv;
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSaver Saver(Alloc);
+llvm::SmallVector T;
+if (!expandResponseFile(ResponseFile, Saver, Tokenizer, ExpandedArgv)) {
+  // We couldn't read this file, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+for (ResponseFileRecord &Record : FileStack) {
+  // Increase the end of all active records by the number of newly expanded
+  // arguments, minus the response file itself.
+  Record.End += ExpandedArgv.size() - 1;
+}
+
+FileStack.push_back({ResponseFile, I + ExpandedArgv.size()});
+Argv.erase(Argv.begin() + I);
+Argv.insert(Argv.begin() + I, ExpandedArgv.begin(), ExpandedArgv.end());
+  }
+
+  // If successful, the top of the file stack will mark the end of the Argv
+  // stream. A failure her

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 229759.
lh123 added a comment.

format patch


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -17,8 +17,10 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 #include 
 #include 
@@ -27,6 +29,124 @@
 namespace clangd {
 namespace {
 
+bool expandResponseFile(llvm::StringRef FName, llvm::StringSaver &Saver,
+llvm::cl::TokenizerCallback Tokenizer,
+SmallVectorImpl &NewArgv) {
+  llvm::ErrorOr> MemBufOrErr =
+  llvm::MemoryBuffer::getFile(FName);
+  if (!MemBufOrErr)
+return false;
+  llvm::MemoryBuffer &MemBuf = *MemBufOrErr.get();
+  StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
+
+  // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
+  ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
+  std::string UTF8Buf;
+  // It is called byte order marker but the UTF-8 BOM is actually not affected
+  // by the host system's endianness.
+  auto HasUtF8ByteOrderMark = [](ArrayRef S) {
+return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' &&
+S[2] == '\xbf');
+  };
+  if (llvm::hasUTF16ByteOrderMark(BufRef)) {
+if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
+  return false;
+Str = StringRef(UTF8Buf);
+  }
+  // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
+  // these bytes before parsing.
+  // Reference: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
+  else if (HasUtF8ByteOrderMark(BufRef))
+Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
+  // Tokenize the contents into NewArgv.
+  Tokenizer(Str, Saver, NewArgv, false);
+  return true;
+}
+
+bool expandResponseFiles(tooling::CompileCommand &Cmd,
+ llvm::cl::TokenizerCallback Tokenizer) {
+  bool AllExpanded = true;
+  struct ResponseFileRecord {
+llvm::StringRef File;
+size_t End;
+  };
+  std::vector &Argv = Cmd.CommandLine;
+  // To detect recursive response files, we maintain a stack of files and the
+  // position of the last argument in the file. This position is updated
+  // dynamically as we recursively expand files.
+  SmallVector FileStack;
+
+  // Push a dummy entry that represents the initial command line, removing
+  // the need to check for an empty list.
+  FileStack.push_back({"", Argv.size()});
+
+  // Don't cache Argv.size() because it can change.
+  for (unsigned I = 0; I != Argv.size();) {
+while (I == FileStack.back().End) {
+  // Passing the end of a file's argument list, so we can remove it from the
+  // stack.
+  FileStack.pop_back();
+}
+
+std::string &Arg = Argv[I];
+
+if (Arg[0] != '@') {
+  ++I;
+  continue;
+}
+SmallString<128> ResponseFile;
+if (llvm::sys::path::is_relative(&Arg[1])) {
+  llvm::sys::path::append(ResponseFile, Cmd.Directory, &Arg[1]);
+}
+llvm::sys::path::remove_dots(ResponseFile);
+
+auto IsEquivalent = [ResponseFile](const ResponseFileRecord &RFile) {
+  return llvm::sys::fs::equivalent(RFile.File, ResponseFile);
+};
+
+// Check for recursive response files.
+if (std::any_of(FileStack.begin() + 1, FileStack.end(), IsEquivalent)) {
+  // This file is recursive, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+// Replace this response file argument with the tokenization of its
+// contents.  Nested response files are expanded in subsequent iterations.
+SmallVector ExpandedArgv;
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSaver Saver(Alloc);
+llvm::SmallVector T;
+if (!expandResponseFile(ResponseFile, Saver, Tokenizer, ExpandedArgv)) {
+  // We couldn't read this file, so we leave it in the argument stream and
+  // move on.
+  AllExpanded = false;
+  ++I;
+  continue;
+}
+
+for (ResponseFileRecord &Record : FileStack) {
+  // Increase the end of all active records by the number of newly expanded
+  // arguments, minus the response file itself.
+  Record.End += ExpandedArgv.size() - 1;
+}
+
+FileStack.push_back({ResponseFile, I + ExpandedArgv.size()});
+Argv.erase(Argv.begin() + I);
+Argv.insert(Argv.begin() + I, ExpandedArgv.begin(), ExpandedArgv.end());
+  }
+
+  // If successful, the top of the file stack will mark the end of the Argv
+  // stream. A failure he

[PATCH] D70359: [clangd] Show values of more expressions on hover

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:423
+  //  - certain expressions (sizeof etc)
+  //  - built-in types
 }

sammccall wrote:
> lh123 wrote:
> > I think we should also support hover on literal.
> sure - can you explain what you'd like to see/when you'd expect it to be 
> useful?
such as:
1. Hovering on "abc" shows char[4], we can get the length information of the 
string.
2. Get actual type for user-defined literal types.
```c++
struct foo {};
struct foo {};

foo operator""_foo(unsigned long long v) { return {}; }

int main() {
1_foo;
}

```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70359/new/

https://reviews.llvm.org/D70359



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70359: [clangd] Show values of more expressions on hover

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:423
+  //  - certain expressions (sizeof etc)
+  //  - built-in types
 }

lh123 wrote:
> sammccall wrote:
> > lh123 wrote:
> > > I think we should also support hover on literal.
> > sure - can you explain what you'd like to see/when you'd expect it to be 
> > useful?
> such as:
> 1. Hovering on "abc" shows char[4], we can get the length information of the 
> string.
> 2. Get actual type for user-defined literal types.
> ```c++
> struct foo {};
> struct foo {};
> 
> foo operator""_foo(unsigned long long v) { return {}; }
> 
> int main() {
> 1_foo;
> }
> 
> ```
> 
```
struct foo {};

foo operator""_foo(unsigned long long v) { return {}; }

int main() {
1_foo;
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70359/new/

https://reviews.llvm.org/D70359



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D70222#1749533 , @kadircet wrote:

> Thanks for taking a look into this, the `rsp files` issue has came up before 
> in the past but there wasn't enough investment to implement it.
>
> Haven't checked the implementation in detail yet, I believe the layering 
> should be different;
>
> This is a common problem for all of the clang-related tools, as they all 
> share the same "compilation database" abstraction layer, therefore it would 
> be better to implement this at that layer so that other tools (e.g, 
> clang-tidy) can also benefit from this.
>  You can find the related code in 
> `clang/include/clang/Tooling/CompilationDatabase.h` and 
> `clang/lib/Tooling/CompilationDatabase.cpp`.
>
> Also compilation databases has been historically neglecting `Virtual File 
> System` abstractions, it is hard to change it now. But would be great if you 
> could try to keep that in mind while performing reads.
>
> So would you mind making such changes ?




In D70222#1749533 , @kadircet wrote:

> Thanks for taking a look into this, the `rsp files` issue has came up before 
> in the past but there wasn't enough investment to implement it.
>
> Haven't checked the implementation in detail yet, I believe the layering 
> should be different;
>
> This is a common problem for all of the clang-related tools, as they all 
> share the same "compilation database" abstraction layer, therefore it would 
> be better to implement this at that layer so that other tools (e.g, 
> clang-tidy) can also benefit from this.
>  You can find the related code in 
> `clang/include/clang/Tooling/CompilationDatabase.h` and 
> `clang/lib/Tooling/CompilationDatabase.cpp`.
>
> Also compilation databases has been historically neglecting `Virtual File 
> System` abstractions, it is hard to change it now. But would be great if you 
> could try to keep that in mind while performing reads.
>
> So would you mind making such changes ?


Ok, I will look into this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 229807.
lh123 added a comment.

Move the implementation to `JSONCompilationDatabase`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/lib/Tooling/JSONCompilationDatabase.cpp

Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -49,9 +50,9 @@
 /// Assumes \-escaping for quoted arguments (see the documentation of
 /// unescapeCommandLine(...)).
 class CommandLineArgumentParser {
- public:
+public:
   CommandLineArgumentParser(StringRef CommandLine)
-  : Input(CommandLine), Position(Input.begin()-1) {}
+  : Input(CommandLine), Position(Input.begin() - 1) {}
 
   std::vector parse() {
 bool HasMoreInput = true;
@@ -63,46 +64,56 @@
 return CommandLine;
   }
 
- private:
+private:
   // All private methods return true if there is more input available.
 
   bool parseStringInto(std::string &String) {
 do {
   if (*Position == '"') {
-if (!parseDoubleQuotedStringInto(String)) return false;
+if (!parseDoubleQuotedStringInto(String))
+  return false;
   } else if (*Position == '\'') {
-if (!parseSingleQuotedStringInto(String)) return false;
+if (!parseSingleQuotedStringInto(String))
+  return false;
   } else {
-if (!parseFreeStringInto(String)) return false;
+if (!parseFreeStringInto(String))
+  return false;
   }
 } while (*Position != ' ');
 return true;
   }
 
   bool parseDoubleQuotedStringInto(std::string &String) {
-if (!next()) return false;
+if (!next())
+  return false;
 while (*Position != '"') {
-  if (!skipEscapeCharacter()) return false;
+  if (!skipEscapeCharacter())
+return false;
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 }
 return next();
   }
 
   bool parseSingleQuotedStringInto(std::string &String) {
-if (!next()) return false;
+if (!next())
+  return false;
 while (*Position != '\'') {
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 }
 return next();
   }
 
   bool parseFreeStringInto(std::string &String) {
 do {
-  if (!skipEscapeCharacter()) return false;
+  if (!skipEscapeCharacter())
+return false;
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 } while (*Position != ' ' && *Position != '"' && *Position != '\'');
 return true;
   }
@@ -116,7 +127,8 @@
 
   bool nextNonWhitespace() {
 do {
-  if (!next()) return false;
+  if (!next())
+return false;
 } while (*Position == ' ');
 return true;
   }
@@ -158,6 +170,124 @@
   return parser.parse();
 }
 
+bool expandResponseFile(llvm::StringRef FName, llvm::StringSaver &Saver,
+llvm::cl::TokenizerCallback Tokenizer,
+SmallVectorImpl &NewArgv) {
+  llvm::ErrorOr> MemBufOrErr =
+  llvm::MemoryBuffer::getFile(FName);
+  if (!MemBufOrErr)
+return false;
+  llvm::MemoryBuffer &MemBuf = *MemBufOrErr.get();
+  StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
+
+  // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
+  ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
+  std::string UTF8Buf;
+  // It is called byte order marker but the UTF-8 BOM is actually not affected
+  // by the host system's endianness.
+  auto HasUtF8ByteOrderMark = [](ArrayRef S) {
+return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' &&
+S[2] == '\xbf');
+  };
+  if (llvm::hasUTF16ByteOrderMark(BufRef)) {
+if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
+  return false;
+Str = StringRef(UTF8Buf);
+  }
+  // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
+  // these bytes before parsing.
+  // Reference: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
+  else if (HasUtF8ByteOrderMark(BufRef))
+Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
+  // Tokenize the contents into NewArgv.
+  Tokenizer(Str, Saver, NewArgv, false);
+  return true;
+}
+
+bool expandResponseFiles(tooling::CompileCommand &Cmd,
+ llvm::cl::TokenizerCallback Tokenizer) {
+  bool AllExpanded = true;
+  struct ResponseFileRecord {
+llvm::StringRef File;
+size_t End;
+  };
+  std::vector &Argv = Cmd.CommandLine;
+  // To detect recursive res

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-18 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 229812.
lh123 added a comment.

Respect `JSONCommandLineSyntax`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/lib/Tooling/JSONCompilationDatabase.cpp

Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -49,9 +50,9 @@
 /// Assumes \-escaping for quoted arguments (see the documentation of
 /// unescapeCommandLine(...)).
 class CommandLineArgumentParser {
- public:
+public:
   CommandLineArgumentParser(StringRef CommandLine)
-  : Input(CommandLine), Position(Input.begin()-1) {}
+  : Input(CommandLine), Position(Input.begin() - 1) {}
 
   std::vector parse() {
 bool HasMoreInput = true;
@@ -63,46 +64,56 @@
 return CommandLine;
   }
 
- private:
+private:
   // All private methods return true if there is more input available.
 
   bool parseStringInto(std::string &String) {
 do {
   if (*Position == '"') {
-if (!parseDoubleQuotedStringInto(String)) return false;
+if (!parseDoubleQuotedStringInto(String))
+  return false;
   } else if (*Position == '\'') {
-if (!parseSingleQuotedStringInto(String)) return false;
+if (!parseSingleQuotedStringInto(String))
+  return false;
   } else {
-if (!parseFreeStringInto(String)) return false;
+if (!parseFreeStringInto(String))
+  return false;
   }
 } while (*Position != ' ');
 return true;
   }
 
   bool parseDoubleQuotedStringInto(std::string &String) {
-if (!next()) return false;
+if (!next())
+  return false;
 while (*Position != '"') {
-  if (!skipEscapeCharacter()) return false;
+  if (!skipEscapeCharacter())
+return false;
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 }
 return next();
   }
 
   bool parseSingleQuotedStringInto(std::string &String) {
-if (!next()) return false;
+if (!next())
+  return false;
 while (*Position != '\'') {
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 }
 return next();
   }
 
   bool parseFreeStringInto(std::string &String) {
 do {
-  if (!skipEscapeCharacter()) return false;
+  if (!skipEscapeCharacter())
+return false;
   String.push_back(*Position);
-  if (!next()) return false;
+  if (!next())
+return false;
 } while (*Position != ' ' && *Position != '"' && *Position != '\'');
 return true;
   }
@@ -116,7 +127,8 @@
 
   bool nextNonWhitespace() {
 do {
-  if (!next()) return false;
+  if (!next())
+return false;
 } while (*Position == ' ');
 return true;
   }
@@ -158,6 +170,124 @@
   return parser.parse();
 }
 
+bool expandResponseFile(llvm::StringRef FName, llvm::StringSaver &Saver,
+llvm::cl::TokenizerCallback Tokenizer,
+SmallVectorImpl &NewArgv) {
+  llvm::ErrorOr> MemBufOrErr =
+  llvm::MemoryBuffer::getFile(FName);
+  if (!MemBufOrErr)
+return false;
+  llvm::MemoryBuffer &MemBuf = *MemBufOrErr.get();
+  StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
+
+  // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
+  ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
+  std::string UTF8Buf;
+  // It is called byte order marker but the UTF-8 BOM is actually not affected
+  // by the host system's endianness.
+  auto HasUtF8ByteOrderMark = [](ArrayRef S) {
+return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' &&
+S[2] == '\xbf');
+  };
+  if (llvm::hasUTF16ByteOrderMark(BufRef)) {
+if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
+  return false;
+Str = StringRef(UTF8Buf);
+  }
+  // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
+  // these bytes before parsing.
+  // Reference: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
+  else if (HasUtF8ByteOrderMark(BufRef))
+Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
+  // Tokenize the contents into NewArgv.
+  Tokenizer(Str, Saver, NewArgv, false);
+  return true;
+}
+
+bool expandResponseFiles(tooling::CompileCommand &Cmd,
+ llvm::cl::TokenizerCallback Tokenizer) {
+  bool AllExpanded = true;
+  struct ResponseFileRecord {
+llvm::StringRef File;
+size_t End;
+  };
+  std::vector &Argv = Cmd.CommandLine;
+  // To detect recursive response files, we mainta

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-19 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 230031.
lh123 edited the summary of this revision.
lh123 added a comment.

Address comment


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,98 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+TEST(ExpandResponseFileTest, JSONCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> FooFileName;
+  llvm::sys::path::append(FooFileName, TestDir, "foo.rsp");
+  std::ofstream FooFile(FooFileName.c_str());
+  FooFile << "-DFOO @bar.rsp";
+  FooFile.close();
+
+  SmallString<128> BarFileName;
+  llvm::sys::path::append(BarFileName, TestDir, "bar.rsp");
+  std::ofstream BarFile(BarFileName.c_str());
+  BarFile << "-DBAR";
+  BarFile.close();
+
+  SmallString<128> CompileCommandsFileName;
+  llvm::sys::path::append(CompileCommandsFileName, TestDir,
+  "compile_commands.json");
+  std::ofstream CompileCommandsFile(CompileCommandsFileName.c_str());
+  // clang-format off
+  CompileCommandsFile << ("[{\"directory\": \"" + TestDir + "\","
+  "\"command\": \"clang @foo.rsp\","
+  "\"file\": \"" + TestMainFileName + "\"}]").str();
+  // clang-format on
+  CompileCommandsFile.close();
+  std::string ErrorMessage;
+  auto JsonDatabase =
+  JSONCompilationDatabase::loadFromDirectory(TestDir, ErrorMessage);
+
+  EXPECT_TRUE(JsonDatabase);
+  auto FoundCommand = JsonDatabase->getCompileCommands(TestMainFileName);
+
+  EXPECT_TRUE(FoundCommand.size() == 1u) << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Directory, TestDir) << ErrorMessage;
+  EXPECT_THAT(FoundCommand[0].CommandLine,
+  ElementsAre("clang", "-DFOO", "-DBAR"))
+  << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Filename, TestMainFileName) << ErrorMessage;
+
+  llvm::sys::fs::remove(BarFileName);
+  llvm::sys::fs::remove(FooFileName);
+  llvm::sys::fs::remove(TestDir);
+}
+
+TEST(ExpandResponseFileTest, FixedCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> FooFileName;
+  llvm::sys::path::append(FooFileName, TestDir, "foo.rsp");
+  std::ofstream FooFile(FooFileName.c_str());
+  FooFile << "-DFOO @bar.rsp";
+  FooFile.close();
+
+  SmallString<128> BarFileName;
+  llvm::sys::path::append(BarFileName, TestDir, "bar.rsp");
+  std::ofstream BarFile(BarFileName.c_str());
+  BarFile << "-DBAR";
+  BarFile.close();
+
+  SmallString<128> FixedCompilationFileName;
+  llvm::sys::path::append(FixedCompilationFileName, TestDir,
+  "compile_flags.txt");
+  std::ofstream CompileCommandsFile(FixedCompilationFileName.c_str());
+  CompileCommandsFile << "@foo.rsp";
+  CompileCommandsFile.close();
+  std::string ErrorMessage;
+  auto FixedDatabase =
+  FixedCompilationDatabase::loadFromDirectory(TestDir, ErrorMessage);
+
+  EXPECT_TRUE(FixedDatabase);
+  auto FoundCommand = FixedDatabase->getCompileCommands(TestMainFileName);
+
+  EXPECT_TRUE(FoundCommand.size() == 1u) << ErrorMessage;
+  EXPECT_THAT(FoundCommand[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "-DFOO", "-DBAR",
+  EndsWith("main.cpp")))
+  << ErrorMessage;
+
+  llvm::sys::fs::remove(BarFileName);
+  llvm::sys::fs::remove(FooFileName);
+  llvm::sys::fs::remove(TestDir);
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -313,16 +313,28 @@
 void JSONCompilationDatabase::getCommands(
 ArrayRef CommandsRef,
 std::vector &Commands) const {
+  auto GetTokenizer = [](JSONCommandLineSyntax Syntax) {
+if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+  Syntax = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+  

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-19 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 230033.
lh123 added a comment.

fix typo in function document.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,98 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+TEST(ExpandResponseFileTest, JSONCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> FooFileName;
+  llvm::sys::path::append(FooFileName, TestDir, "foo.rsp");
+  std::ofstream FooFile(FooFileName.c_str());
+  FooFile << "-DFOO @bar.rsp";
+  FooFile.close();
+
+  SmallString<128> BarFileName;
+  llvm::sys::path::append(BarFileName, TestDir, "bar.rsp");
+  std::ofstream BarFile(BarFileName.c_str());
+  BarFile << "-DBAR";
+  BarFile.close();
+
+  SmallString<128> CompileCommandsFileName;
+  llvm::sys::path::append(CompileCommandsFileName, TestDir,
+  "compile_commands.json");
+  std::ofstream CompileCommandsFile(CompileCommandsFileName.c_str());
+  // clang-format off
+  CompileCommandsFile << ("[{\"directory\": \"" + TestDir + "\","
+  "\"command\": \"clang @foo.rsp\","
+  "\"file\": \"" + TestMainFileName + "\"}]").str();
+  // clang-format on
+  CompileCommandsFile.close();
+  std::string ErrorMessage;
+  auto JsonDatabase =
+  JSONCompilationDatabase::loadFromDirectory(TestDir, ErrorMessage);
+
+  EXPECT_TRUE(JsonDatabase);
+  auto FoundCommand = JsonDatabase->getCompileCommands(TestMainFileName);
+
+  EXPECT_TRUE(FoundCommand.size() == 1u) << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Directory, TestDir) << ErrorMessage;
+  EXPECT_THAT(FoundCommand[0].CommandLine,
+  ElementsAre("clang", "-DFOO", "-DBAR"))
+  << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Filename, TestMainFileName) << ErrorMessage;
+
+  llvm::sys::fs::remove(BarFileName);
+  llvm::sys::fs::remove(FooFileName);
+  llvm::sys::fs::remove(TestDir);
+}
+
+TEST(ExpandResponseFileTest, FixedCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> FooFileName;
+  llvm::sys::path::append(FooFileName, TestDir, "foo.rsp");
+  std::ofstream FooFile(FooFileName.c_str());
+  FooFile << "-DFOO @bar.rsp";
+  FooFile.close();
+
+  SmallString<128> BarFileName;
+  llvm::sys::path::append(BarFileName, TestDir, "bar.rsp");
+  std::ofstream BarFile(BarFileName.c_str());
+  BarFile << "-DBAR";
+  BarFile.close();
+
+  SmallString<128> FixedCompilationFileName;
+  llvm::sys::path::append(FixedCompilationFileName, TestDir,
+  "compile_flags.txt");
+  std::ofstream CompileCommandsFile(FixedCompilationFileName.c_str());
+  CompileCommandsFile << "@foo.rsp";
+  CompileCommandsFile.close();
+  std::string ErrorMessage;
+  auto FixedDatabase =
+  FixedCompilationDatabase::loadFromDirectory(TestDir, ErrorMessage);
+
+  EXPECT_TRUE(FixedDatabase);
+  auto FoundCommand = FixedDatabase->getCompileCommands(TestMainFileName);
+
+  EXPECT_TRUE(FoundCommand.size() == 1u) << ErrorMessage;
+  EXPECT_THAT(FoundCommand[0].CommandLine,
+  ElementsAre(EndsWith("clang-tool"), "-DFOO", "-DBAR",
+  EndsWith("main.cpp")))
+  << ErrorMessage;
+
+  llvm::sys::fs::remove(BarFileName);
+  llvm::sys::fs::remove(FooFileName);
+  llvm::sys::fs::remove(TestDir);
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -313,16 +313,28 @@
 void JSONCompilationDatabase::getCommands(
 ArrayRef CommandsRef,
 std::vector &Commands) const {
+  auto GetTokenizer = [](JSONCommandLineSyntax Syntax) {
+if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+  Syntax = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+   ? JSONCommandLineSyntax::Wi

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-19 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 230060.
lh123 added a comment.

fixes some  bug and add more test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,132 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+TEST(ExpandResponseFileTest, JSONCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC =
+  llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> InnerDir;
+  llvm::sys::path::append(InnerDir, TestDir, "inner");
+  EC = llvm::sys::fs::create_directory(InnerDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> RspFileName1;
+  llvm::sys::path::append(RspFileName1, InnerDir, "rsp1.rsp");
+  std::ofstream RspFile1(RspFileName1.c_str());
+  RspFile1 << "-Dflag1";
+  RspFile1.close();
+
+  SmallString<128> RspFileName2;
+  llvm::sys::path::append(RspFileName2, TestDir, "rsp2.rsp");
+  std::ofstream RspFile2(RspFileName2.c_str());
+  RspFile2 << "-Dflag2 @rsp3.rsp";
+  RspFile2.close();
+
+  SmallString<128> RspFileName3;
+  llvm::sys::path::append(RspFileName3, TestDir, "rsp3.rsp");
+  std::ofstream RspFile3(RspFileName3.c_str());
+  RspFile3 << "-Dflag3";
+  RspFile3.close();
+
+  SmallString<128> RspFileName4;
+  llvm::sys::path::append(RspFileName4, TestDir, "rsp4.rsp");
+  std::ofstream RspFile4(RspFileName4.c_str());
+  RspFile4 << "-Dflag4 @rsp4.rsp";
+  RspFile4.close();
+
+  SmallString<128> RspFileName5;
+  llvm::sys::path::append(RspFileName5, InnerDir, "rsp5.rsp");
+  std::ofstream RspFile5(RspFileName5.c_str());
+  RspFile5 << "-Dflag5 @inner/rsp1.rsp";
+  RspFile5.close();
+
+  SmallString<128> CompileCommandsFileName;
+  llvm::sys::path::append(CompileCommandsFileName, TestDir,
+  "compile_commands.json");
+  std::ofstream CompileCommandsFile(CompileCommandsFileName.c_str());
+  // clang-format off
+  CompileCommandsFile
+  << ("[{\"directory\": \"" + TestDir + "\","
+  "\"command\": \"clang @inner/rsp1.rsp @rsp2.rsp @rsp4.rsp "
+  "@" + RspFileName1 + " @inner/rsp5.rsp @rsp6.rsp\","
+  "\"file\": \"" + TestMainFileName + "\"}]").str();
+  // clang-format on
+  CompileCommandsFile.close();
+
+  std::string ErrorMessage;
+  auto JsonDatabase =
+  JSONCompilationDatabase::loadFromDirectory(TestDir, ErrorMessage);
+
+  EXPECT_TRUE(JsonDatabase);
+  auto FoundCommand = JsonDatabase->getCompileCommands(TestMainFileName);
+
+  EXPECT_TRUE(FoundCommand.size() == 1u) << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Directory, TestDir) << ErrorMessage;
+  EXPECT_THAT(FoundCommand[0].CommandLine,
+  ElementsAre("clang", "-Dflag1", "-Dflag2", "-Dflag3", "-Dflag4",
+  "@rsp4.rsp", "-Dflag1", "-Dflag5", "-Dflag1",
+  "@rsp6.rsp"))
+  << ErrorMessage;
+  EXPECT_EQ(FoundCommand[0].Filename, TestMainFileName) << ErrorMessage;
+
+  llvm::sys::fs::remove(RspFileName5);
+  llvm::sys::fs::remove(RspFileName4);
+  llvm::sys::fs::remove(RspFileName3);
+  llvm::sys::fs::remove(RspFileName2);
+  llvm::sys::fs::remove(RspFileName1);
+  llvm::sys::fs::remove(InnerDir);
+  llvm::sys::fs::remove(TestDir);
+}
+
+TEST(ExpandResponseFileTest, FixedCompilationDatabase) {
+  SmallString<128> TestDir;
+  std::error_code EC =
+  llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+  EXPECT_TRUE(!EC);
+
+  SmallString<128> TestMainFileName;
+  llvm::sys::path::append(TestMainFileName, TestDir, "main.cpp");
+
+  SmallString<128> RspFileName1;
+  llvm::sys::path::append(RspFileName1, TestDir, "rsp1.rsp");
+  std::ofstream RspFile1(RspFileName1.c_str());
+  RspFile1 << "-Dflag1 @rsp2.rsp";
+  RspFile1.close();
+
+  SmallString<128> RspFileName2;
+  llvm::sys::path::append(RspFileName2, TestDir, "rsp2.rsp");
+  std::ofstream RspFile2(RspFileName2.c_str());
+  RspFile2 << "-Dflag2";
+  RspFile2.close();
+
+  SmallString<128> FixedCompilationFileName;
+  llvm::sys::path::append(FixedCompilationFileName, TestDir,
+  "compile_flags.txt");
+  std::ofstream CompileCommandsFile(FixedCompilationFileName.c_str());
+  CompileCommandsFile << "@rsp1.rsp";
+  CompileCommandsFile.close();
+  std::string ErrorMessage;
+  auto FixedDatabase =
+

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-23 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 230752.
lh123 added a comment.
Herald added a subscriber: mgorny.

Address comment


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,76 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+class ExpandResponseFilesTest : public MemDBTest {
+protected:
+  void SetUp() override {
+InnerDir = path(StringRef("inner"));
+std::error_code EC = llvm::sys::fs::create_directory(InnerDir);
+EXPECT_TRUE(!EC);
+
+llvm::sys::path::append(RspFileName1, InnerDir, "rsp1.rsp");
+std::ofstream RspFile1(RspFileName1.c_str());
+RspFile1 << "-Dflag1";
+RspFile1.close();
+
+RspFileName2 = path(StringRef("rsp2.rsp"));
+std::ofstream RspFile2(RspFileName2.c_str());
+RspFile2 << "-Dflag2 @rsp3.rsp";
+RspFile2.close();
+
+RspFileName3 = path(StringRef("rsp3.rsp"));
+std::ofstream RspFile3(RspFileName3.c_str());
+RspFile3 << "-Dflag3";
+RspFile3.close();
+
+RspFileName4 = path(StringRef("rsp4.rsp"));
+std::ofstream  RspFile4(RspFileName4.c_str());
+RspFile4 << "-Dflag4 @rsp4.rsp";
+RspFile4.close();
+
+llvm::sys::path::append(RspFileName5, InnerDir, "rsp5.rsp");
+std::ofstream RspFile5(RspFileName5.c_str());
+RspFile5 << "-Dflag5 @inner/rsp1.rsp";
+RspFile5.close();
+  }
+
+  void TearDown() override {
+llvm::sys::fs::remove(RspFileName5);
+llvm::sys::fs::remove(RspFileName4);
+llvm::sys::fs::remove(RspFileName3);
+llvm::sys::fs::remove(RspFileName2);
+llvm::sys::fs::remove(RspFileName1);
+llvm::sys::fs::remove(InnerDir);
+  }
+
+  std::string getCommand(llvm::StringRef F) {
+auto Results = expandResponseFiles(std::make_unique(Entries))
+   ->getCompileCommands(path(F));
+if (Results.empty()) {
+  return "none";
+}
+return llvm::join(Results[0].CommandLine, " ");
+  }
+
+  SmallString<128> InnerDir;
+  SmallString<128> RspFileName1;
+  SmallString<128> RspFileName2;
+  SmallString<128> RspFileName3;
+  SmallString<128> RspFileName4;
+  SmallString<128> RspFileName5;
+};
+
+TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
+  // clang-format off
+  add("foo.cpp", "clang",
+  ("@inner/rsp1.rsp @rsp2.rsp @rsp4.rsp "
+"@" + RspFileName1 + " @inner/rsp5.rsp @rsp6.rsp")
+  .str());
+  // clang-format on
+  EXPECT_THAT(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag1 -Dflag2 "
+ "-Dflag3 -Dflag4 @rsp4.rsp -Dflag1 "
+ "-Dflag5 -Dflag1 @rsp6.rsp");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -167,8 +167,8 @@
 llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
 auto Base = JSONCompilationDatabase::loadFromFile(
 JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
-return Base ? inferTargetAndDriverMode(
-  inferMissingCompileCommands(std::move(Base)))
+return Base ? expandResponseFiles(inferTargetAndDriverMode(
+  inferMissingCompileCommands(std::move(Base
 : nullptr;
   }
 };
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- /dev/null
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -0,0 +1,192 @@
+//===- ExpandResponseFileCompilationDataBase.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Pat

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-23 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 230756.
lh123 added a comment.

Expand response files before `inferMissingCompileCommands` and 
`inferTargetAndDriverMode`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,76 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+class ExpandResponseFilesTest : public MemDBTest {
+protected:
+  void SetUp() override {
+InnerDir = path(StringRef("inner"));
+std::error_code EC = llvm::sys::fs::create_directory(InnerDir);
+EXPECT_TRUE(!EC);
+
+llvm::sys::path::append(RspFileName1, InnerDir, "rsp1.rsp");
+std::ofstream RspFile1(RspFileName1.c_str());
+RspFile1 << "-Dflag1";
+RspFile1.close();
+
+RspFileName2 = path(StringRef("rsp2.rsp"));
+std::ofstream RspFile2(RspFileName2.c_str());
+RspFile2 << "-Dflag2 @rsp3.rsp";
+RspFile2.close();
+
+RspFileName3 = path(StringRef("rsp3.rsp"));
+std::ofstream RspFile3(RspFileName3.c_str());
+RspFile3 << "-Dflag3";
+RspFile3.close();
+
+RspFileName4 = path(StringRef("rsp4.rsp"));
+std::ofstream  RspFile4(RspFileName4.c_str());
+RspFile4 << "-Dflag4 @rsp4.rsp";
+RspFile4.close();
+
+llvm::sys::path::append(RspFileName5, InnerDir, "rsp5.rsp");
+std::ofstream RspFile5(RspFileName5.c_str());
+RspFile5 << "-Dflag5 @inner/rsp1.rsp";
+RspFile5.close();
+  }
+
+  void TearDown() override {
+llvm::sys::fs::remove(RspFileName5);
+llvm::sys::fs::remove(RspFileName4);
+llvm::sys::fs::remove(RspFileName3);
+llvm::sys::fs::remove(RspFileName2);
+llvm::sys::fs::remove(RspFileName1);
+llvm::sys::fs::remove(InnerDir);
+  }
+
+  std::string getCommand(llvm::StringRef F) {
+auto Results = expandResponseFiles(std::make_unique(Entries))
+   ->getCompileCommands(path(F));
+if (Results.empty()) {
+  return "none";
+}
+return llvm::join(Results[0].CommandLine, " ");
+  }
+
+  SmallString<128> InnerDir;
+  SmallString<128> RspFileName1;
+  SmallString<128> RspFileName2;
+  SmallString<128> RspFileName3;
+  SmallString<128> RspFileName4;
+  SmallString<128> RspFileName5;
+};
+
+TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
+  // clang-format off
+  add("foo.cpp", "clang",
+  ("@inner/rsp1.rsp @rsp2.rsp @rsp4.rsp "
+"@" + RspFileName1 + " @inner/rsp5.rsp @rsp6.rsp")
+  .str());
+  // clang-format on
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag1 -Dflag2 "
+   "-Dflag3 -Dflag4 @rsp4.rsp -Dflag1 "
+   "-Dflag5 -Dflag1 @rsp6.rsp");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -167,8 +167,8 @@
 llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
 auto Base = JSONCompilationDatabase::loadFromFile(
 JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
-return Base ? inferTargetAndDriverMode(
-  inferMissingCompileCommands(std::move(Base)))
+return Base ? inferTargetAndDriverMode(inferMissingCompileCommands(
+  expandResponseFiles(std::move(Base
 : nullptr;
   }
 };
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- /dev/null
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -0,0 +1,192 @@
+//===- ExpandResponseFileCompilationDataBase.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuf

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp:167
+for (auto &Cmd : Cmds) {
+  expandResponseFiles(Cmd, Tokenizer);
+}

kadircet wrote:
> so it looks like we already have `ExpandResponseFiles` exposed in 
> `llvm/include/llvm/Support/CommandLine.h` could you make use of it in here 
> instead of re-implementing it again?
> 
> I see that it has a different signature, but we can do the conversion back 
> and forth in here, going from `std::string` to `char*` is cheap anyways, 
> coming back is expensive though, and we can limit that to iff we have seen an 
> argument starting with an `@`. So this would be something like:
> 
> ```
> llvm::SmallVector Argvs;
> Argvs.reserve(Cmd.CommandLine.size());
> bool SeenRSPFile = false;
> for(auto &Argv : Cmd.CommandLine) {
>   Argvs.push_back(Argv.c_str());
>   SeenRSPFile |= Argv.front() == '@';
> }
> if(!SeenRSPFile)
>   continue;
> 
> // call ExpandResponseFiles with Argvs, convert back to vector 
> and assign to Cmd.CommandLine
> ```
I think it's not easy to reuse `ExpandResponseFiles` without changing code 
because it uses llvm::sys::fs::current_path to resolve relative paths.

In fact, most of the code here is copied from `CommandLine`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Tooling/CompilationDatabase.cpp:402
 llvm::sys::path::append(DatabasePath, "compile_flags.txt");
-return FixedCompilationDatabase::loadFromFile(DatabasePath, ErrorMessage);
+auto Base =
+FixedCompilationDatabase::loadFromFile(DatabasePath, ErrorMessage);

kadircet wrote:
> is it really common for rsp files to show up in fixed compilation databases? 
> since compile_flags.txt itself is also a file doesn't make much sense to 
> refer to another one. as it can also contain text of arbitrary length.
Yes, rsp files usually only appear on the command line.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 231051.
lh123 added a comment.

address comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -859,5 +860,76 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+class ExpandResponseFilesTest : public MemDBTest {
+protected:
+  void SetUp() override {
+InnerDir = path(StringRef("inner"));
+std::error_code EC = llvm::sys::fs::create_directory(InnerDir);
+EXPECT_TRUE(!EC);
+
+llvm::sys::path::append(RspFileName1, InnerDir, "rsp1.rsp");
+std::ofstream RspFile1(RspFileName1.c_str());
+RspFile1 << "-Dflag1";
+RspFile1.close();
+
+RspFileName2 = path(StringRef("rsp2.rsp"));
+std::ofstream RspFile2(RspFileName2.c_str());
+RspFile2 << "-Dflag2 @rsp3.rsp";
+RspFile2.close();
+
+RspFileName3 = path(StringRef("rsp3.rsp"));
+std::ofstream RspFile3(RspFileName3.c_str());
+RspFile3 << "-Dflag3";
+RspFile3.close();
+
+RspFileName4 = path(StringRef("rsp4.rsp"));
+std::ofstream  RspFile4(RspFileName4.c_str());
+RspFile4 << "-Dflag4 @rsp4.rsp";
+RspFile4.close();
+
+llvm::sys::path::append(RspFileName5, InnerDir, "rsp5.rsp");
+std::ofstream RspFile5(RspFileName5.c_str());
+RspFile5 << "-Dflag5 @inner/rsp1.rsp";
+RspFile5.close();
+  }
+
+  void TearDown() override {
+llvm::sys::fs::remove(RspFileName5);
+llvm::sys::fs::remove(RspFileName4);
+llvm::sys::fs::remove(RspFileName3);
+llvm::sys::fs::remove(RspFileName2);
+llvm::sys::fs::remove(RspFileName1);
+llvm::sys::fs::remove(InnerDir);
+  }
+
+  std::string getCommand(llvm::StringRef F) {
+auto Results = expandResponseFiles(std::make_unique(Entries))
+   ->getCompileCommands(path(F));
+if (Results.empty()) {
+  return "none";
+}
+return llvm::join(Results[0].CommandLine, " ");
+  }
+
+  SmallString<128> InnerDir;
+  SmallString<128> RspFileName1;
+  SmallString<128> RspFileName2;
+  SmallString<128> RspFileName3;
+  SmallString<128> RspFileName4;
+  SmallString<128> RspFileName5;
+};
+
+TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
+  // clang-format off
+  add("foo.cpp", "clang",
+  ("@inner/rsp1.rsp @rsp2.rsp @rsp4.rsp "
+"@" + RspFileName1 + " @inner/rsp5.rsp @rsp6.rsp")
+  .str());
+  // clang-format on
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag1 -Dflag2 "
+   "-Dflag3 -Dflag4 @rsp4.rsp -Dflag1 "
+   "-Dflag5 -Dflag1 @rsp6.rsp");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -167,8 +167,8 @@
 llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
 auto Base = JSONCompilationDatabase::loadFromFile(
 JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
-return Base ? inferTargetAndDriverMode(
-  inferMissingCompileCommands(std::move(Base)))
+return Base ? inferTargetAndDriverMode(inferMissingCompileCommands(
+  expandResponseFiles(std::move(Base
 : nullptr;
   }
 };
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- /dev/null
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -0,0 +1,191 @@
+//===- ExpandResponseFileCompilationDataBase.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
+
+namespace clang {
+namespace tooling 

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp:167
+for (auto &Cmd : Cmds) {
+  expandResponseFiles(Cmd, Tokenizer);
+}

lh123 wrote:
> kadircet wrote:
> > so it looks like we already have `ExpandResponseFiles` exposed in 
> > `llvm/include/llvm/Support/CommandLine.h` could you make use of it in here 
> > instead of re-implementing it again?
> > 
> > I see that it has a different signature, but we can do the conversion back 
> > and forth in here, going from `std::string` to `char*` is cheap anyways, 
> > coming back is expensive though, and we can limit that to iff we have seen 
> > an argument starting with an `@`. So this would be something like:
> > 
> > ```
> > llvm::SmallVector Argvs;
> > Argvs.reserve(Cmd.CommandLine.size());
> > bool SeenRSPFile = false;
> > for(auto &Argv : Cmd.CommandLine) {
> >   Argvs.push_back(Argv.c_str());
> >   SeenRSPFile |= Argv.front() == '@';
> > }
> > if(!SeenRSPFile)
> >   continue;
> > 
> > // call ExpandResponseFiles with Argvs, convert back to vector 
> > and assign to Cmd.CommandLine
> > ```
> I think it's not easy to reuse `ExpandResponseFiles` without changing code 
> because it uses llvm::sys::fs::current_path to resolve relative paths.
> 
> In fact, most of the code here is copied from `CommandLine`
But we can reuse `static bool ExpandResponseFile(StringRef FName, StringSaver 
&Saver, TokenizerCallback Tokenizer, SmallVectorImpl &NewArgv, 
bool MarkEOLs, bool RelativeNames)` if we expose it in `CommandLine.h`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-26 Thread liu hui via Phabricator via cfe-commits
lh123 marked an inline comment as done.
lh123 added inline comments.



Comment at: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp:167
+for (auto &Cmd : Cmds) {
+  expandResponseFiles(Cmd, Tokenizer);
+}

lh123 wrote:
> lh123 wrote:
> > kadircet wrote:
> > > so it looks like we already have `ExpandResponseFiles` exposed in 
> > > `llvm/include/llvm/Support/CommandLine.h` could you make use of it in 
> > > here instead of re-implementing it again?
> > > 
> > > I see that it has a different signature, but we can do the conversion 
> > > back and forth in here, going from `std::string` to `char*` is cheap 
> > > anyways, coming back is expensive though, and we can limit that to iff we 
> > > have seen an argument starting with an `@`. So this would be something 
> > > like:
> > > 
> > > ```
> > > llvm::SmallVector Argvs;
> > > Argvs.reserve(Cmd.CommandLine.size());
> > > bool SeenRSPFile = false;
> > > for(auto &Argv : Cmd.CommandLine) {
> > >   Argvs.push_back(Argv.c_str());
> > >   SeenRSPFile |= Argv.front() == '@';
> > > }
> > > if(!SeenRSPFile)
> > >   continue;
> > > 
> > > // call ExpandResponseFiles with Argvs, convert back to 
> > > vector and assign to Cmd.CommandLine
> > > ```
> > I think it's not easy to reuse `ExpandResponseFiles` without changing code 
> > because it uses llvm::sys::fs::current_path to resolve relative paths.
> > 
> > In fact, most of the code here is copied from `CommandLine`
> But we can reuse `static bool ExpandResponseFile(StringRef FName, StringSaver 
> &Saver, TokenizerCallback Tokenizer, SmallVectorImpl &NewArgv, 
> bool MarkEOLs, bool RelativeNames)` if we expose it in `CommandLine.h`
`static bool ExpandResponseFile(StringRef FName, StringSaver &Saver, 
TokenizerCallback Tokenizer, SmallVectorImpl &NewArgv, bool 
MarkEOLs, bool RelativeNames)` also seems to use `llvm::sys::fs::current_path` 
to resolve relative paths.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added a reviewer: kadircet.
Herald added subscribers: llvm-commits, cfe-commits, seiya, rupprecht, MaskRay, 
jakehehrlich, aheejin, hiraditya, arichardson, sbc100, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added projects: clang, LLVM.

add vfs support for `ExpandResponseFiles`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70769

Files:
  clang/tools/driver/driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/DriverUtils.cpp
  lld/MinGW/Driver.cpp
  lld/tools/lld/lld.cpp
  lld/wasm/Driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -830,7 +830,8 @@
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
   bool Res = llvm::cl::ExpandResponseFiles(
-Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true);
+  Saver, llvm::cl::TokenizeGNUCommandLine, *llvm::vfs::getRealFileSystem(),
+  Argv, false, true);
   EXPECT_TRUE(Res);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "test/test");
@@ -905,7 +906,8 @@
 #else
   cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine;
 #endif
-  bool Res = cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false);
+  bool Res = cl::ExpandResponseFiles(
+  Saver, Tokenizer, *llvm::vfs::getRealFileSystem(), Argv, false, false);
   EXPECT_FALSE(Res);
 
   EXPECT_EQ(Argv.size(), 9U);
@@ -943,7 +945,8 @@
 
   BumpPtrAllocator A;
   StringSaver Saver(A);
-  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+ *llvm::vfs::getRealFileSystem(), Argv,
  false, false);
   EXPECT_FALSE(Res);
 
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -338,7 +338,7 @@
   Triple(sys::getProcessTriple()).isOSWindows()
   ? cl::TokenizeWindowsCommandLine
   : cl::TokenizeGNUCommandLine,
-  NewArgv);
+  *llvm::vfs::getRealFileSystem(), NewArgv);
 
   auto Args = makeArrayRef(NewArgv).drop_front();
   Expected DriverConfig =
Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -1096,7 +1096,8 @@
 static int ar_main(int argc, char **argv) {
   SmallVector Argv(argv, argv + argc);
   StringSaver Saver(Alloc);
-  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+  *llvm::vfs::getRealFileSystem(), Argv);
   for (size_t i = 1; i < Argv.size(); ++i) {
 StringRef Arg = Argv[i];
 const char *match = nullptr;
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -267,7 +267,8 @@
 
   // Parse command line arguments.
   SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end());
-  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine,
+  *llvm::vfs::getRealFileSystem(), NewArgs);
   ArgsArr = NewArgs;
 
   LibOptTable Table;
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -1045,10 +1045,11 @@
 
 static bool ExpandResponseFile(StringRef FName, StringSaver &Saver,
TokenizerCallback Tokenizer,
+   llvm::vfs::FileSystem &FS,
SmallVectorImpl &NewArgv,
bool MarkEOLs, bool RelativeNames) {
   ErrorOr> MemBufOrErr =
-  MemoryBuffer::getFile(FName);
+  FS.getBufferForFile(FName);
   if (!MemBufOrErr)
 return false;
   MemoryBuffer &MemBuf = *MemBufOrErr.get();
@@ -1068,6 +1069,9 @@
   else if (hasUTF8ByteOrderMark(BufRef))
 Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
 
+  llvm::ErrorOr CurrDir = FS.getCurrentWorkingDirectory();
+  if (!CurrDir)
+return fa

[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D70769#1761394 , @jhenderson wrote:

> Are there any instances where we DON'T want to get the real file system? If 
> not, could the `*llvm::vfs::getRealFileSystem()` call be put inside 
> `cl::ExpandResponseFiles`?


This patch is part of D70222 .
 This is for using InMemoryFileSystem in unit tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70769/new/

https://reviews.llvm.org/D70769



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 231213.
lh123 added a comment.

Address comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70769/new/

https://reviews.llvm.org/D70769

Files:
  clang/tools/driver/driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/DriverUtils.cpp
  lld/MinGW/Driver.cpp
  lld/tools/lld/lld.cpp
  lld/wasm/Driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -830,7 +831,8 @@
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
   bool Res = llvm::cl::ExpandResponseFiles(
-Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true);
+  Saver, llvm::cl::TokenizeGNUCommandLine, *llvm::vfs::getRealFileSystem(),
+  Argv, false, true);
   EXPECT_TRUE(Res);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "test/test");
@@ -905,7 +907,8 @@
 #else
   cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine;
 #endif
-  bool Res = cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false);
+  bool Res = cl::ExpandResponseFiles(
+  Saver, Tokenizer, *llvm::vfs::getRealFileSystem(), Argv, false, false);
   EXPECT_FALSE(Res);
 
   EXPECT_EQ(Argv.size(), 9U);
@@ -943,7 +946,8 @@
 
   BumpPtrAllocator A;
   StringSaver Saver(A);
-  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+ *llvm::vfs::getRealFileSystem(), Argv,
  false, false);
   EXPECT_FALSE(Res);
 
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -338,7 +339,7 @@
   Triple(sys::getProcessTriple()).isOSWindows()
   ? cl::TokenizeWindowsCommandLine
   : cl::TokenizeGNUCommandLine,
-  NewArgv);
+  *llvm::vfs::getRealFileSystem(), NewArgv);
 
   auto Args = makeArrayRef(NewArgv).drop_front();
   Expected DriverConfig =
Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
@@ -1096,7 +1097,8 @@
 static int ar_main(int argc, char **argv) {
   SmallVector Argv(argv, argv + argc);
   StringSaver Saver(Alloc);
-  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+  *llvm::vfs::getRealFileSystem(), Argv);
   for (size_t i = 1; i < Argv.size(); ++i) {
 StringRef Arg = Argv[i];
 const char *match = nullptr;
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
@@ -267,7 +268,8 @@
 
   // Parse command line arguments.
   SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end());
-  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine,
+  *llvm::vfs::getRealFileSystem(), NewArgs);
   ArgsArr = NewArgs;
 
   LibOptTable Table;
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Supp

[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 231215.
lh123 added a comment.

address comments and delete unused code.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70769/new/

https://reviews.llvm.org/D70769

Files:
  clang/tools/driver/driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/DriverUtils.cpp
  lld/MinGW/Driver.cpp
  lld/tools/lld/lld.cpp
  lld/wasm/Driver.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -830,7 +831,8 @@
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
   bool Res = llvm::cl::ExpandResponseFiles(
-Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true);
+  Saver, llvm::cl::TokenizeGNUCommandLine, *llvm::vfs::getRealFileSystem(),
+  Argv, false, true);
   EXPECT_TRUE(Res);
   EXPECT_EQ(Argv.size(), 13U);
   EXPECT_STREQ(Argv[0], "test/test");
@@ -905,7 +907,8 @@
 #else
   cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine;
 #endif
-  bool Res = cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false);
+  bool Res = cl::ExpandResponseFiles(
+  Saver, Tokenizer, *llvm::vfs::getRealFileSystem(), Argv, false, false);
   EXPECT_FALSE(Res);
 
   EXPECT_EQ(Argv.size(), 9U);
@@ -943,7 +946,8 @@
 
   BumpPtrAllocator A;
   StringSaver Saver(A);
-  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
+  bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+ *llvm::vfs::getRealFileSystem(), Argv,
  false, false);
   EXPECT_FALSE(Res);
 
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -338,7 +339,7 @@
   Triple(sys::getProcessTriple()).isOSWindows()
   ? cl::TokenizeWindowsCommandLine
   : cl::TokenizeGNUCommandLine,
-  NewArgv);
+  *llvm::vfs::getRealFileSystem(), NewArgv);
 
   auto Args = makeArrayRef(NewArgv).drop_front();
   Expected DriverConfig =
Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
@@ -1096,7 +1097,8 @@
 static int ar_main(int argc, char **argv) {
   SmallVector Argv(argv, argv + argc);
   StringSaver Saver(Alloc);
-  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine,
+  *llvm::vfs::getRealFileSystem(), Argv);
   for (size_t i = 1; i < Argv.size(); ++i) {
 StringRef Arg = Argv[i];
 const char *match = nullptr;
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
@@ -267,7 +268,8 @@
 
   // Parse command line arguments.
   SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end());
-  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine,
+  *llvm::vfs::getRealFileSystem(), NewArgs);
   ArgsArr = NewArgs;
 
   LibOptTable Table;
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -37,6 +37,7

[PATCH] D70222: [clangd] Add support for .rsp files in compile_commands.json

2019-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 231217.
lh123 set the repository for this revision to rG LLVM Github Monorepo.
lh123 added a comment.

rebase to D70769 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70222/new/

https://reviews.llvm.org/D70222

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -859,5 +859,64 @@
 "clang++ --driver-mode=g++ bar.cpp -D bar.cpp");
 }
 
+class ExpandResponseFilesTest : public MemDBTest {
+protected:
+  void SetUp() override {
+FS = new llvm::vfs::InMemoryFileSystem;
+
+InnerDir = path(StringRef("inner"));
+
+llvm::sys::path::append(RspFileName1, InnerDir, "rsp1.rsp");
+addFile(RspFileName1, "-Dflag1");
+
+RspFileName2 = path(StringRef("rsp2.rsp"));
+addFile(RspFileName2, "-Dflag2 @rsp3.rsp");
+
+RspFileName3 = path(StringRef("rsp3.rsp"));
+addFile(RspFileName3, "-Dflag3");
+
+RspFileName4 = path(StringRef("rsp4.rsp"));
+addFile(RspFileName4, "-Dflag4 @rsp4.rsp");
+
+llvm::sys::path::append(RspFileName5, InnerDir, "rsp5.rsp");
+addFile(RspFileName5, "-Dflag5 @inner/rsp1.rsp");
+  }
+
+  void addFile(StringRef File, StringRef Context) {
+ASSERT_TRUE(FS->addFile(File, 0, llvm::MemoryBuffer::getMemBufferCopy(Context)));
+  }
+
+  std::string getCommand(llvm::StringRef F) {
+auto Results = expandResponseFiles(std::make_unique(Entries),
+   FS)
+   ->getCompileCommands(path(F));
+if (Results.empty()) {
+  return "none";
+}
+return llvm::join(Results[0].CommandLine, " ");
+  }
+
+  SmallString<128> InnerDir;
+  SmallString<128> RspFileName1;
+  SmallString<128> RspFileName2;
+  SmallString<128> RspFileName3;
+  SmallString<128> RspFileName4;
+  SmallString<128> RspFileName5;
+  llvm::IntrusiveRefCntPtr FS;
+
+};
+
+TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
+  // clang-format off
+  add("foo.cpp", "clang",
+  ("@inner/rsp1.rsp @rsp2.rsp @rsp4.rsp "
+"@" + RspFileName1 + " @inner/rsp5.rsp @rsp6.rsp")
+  .str());
+  // clang-format on
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag1 -Dflag2 "
+   "-Dflag3 -Dflag4 @rsp4.rsp -Dflag1 "
+   "-Dflag5 -Dflag1 @rsp6.rsp");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -168,7 +168,8 @@
 auto Base = JSONCompilationDatabase::loadFromFile(
 JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
 return Base ? inferTargetAndDriverMode(
-  inferMissingCompileCommands(std::move(Base)))
+  inferMissingCompileCommands(expandResponseFiles(
+  std::move(Base), llvm::vfs::getRealFileSystem(
 : nullptr;
   }
 };
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- /dev/null
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -0,0 +1,92 @@
+//===- ExpandResponseFileCompilationDataBase.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
+
+namespace clang {
+namespace tooling {
+namespace {
+
+class ExpandResponseFilesDatabase : public CompilationDatabase {
+public:
+  ExpandResponseFilesDatabase(
+  std::unique_ptr Base,
+  llvm::cl::TokenizerCallback Tokenizer,
+  llvm::IntrusiveRefCntPtr FS)
+  : Base(std::move(Base)), Tokenizer(Tokenizer), FS(FS) {
+assert(this->Base != nullptr);
+assert(this->Tokenizer != nullptr);
+assert(this->FS != nullptr);
+  }
+
+  std::vector getAllFiles() const override {
+return Base->getAllFiles();

  1   2   >