OSDN Git Service

[Bash-autocompletion] Auto complete cc1 options if -cc1 is specified
authorYuka Takahashi <yukatkh@gmail.com>
Sat, 8 Jul 2017 17:48:59 +0000 (17:48 +0000)
committerYuka Takahashi <yukatkh@gmail.com>
Sat, 8 Jul 2017 17:48:59 +0000 (17:48 +0000)
Summary:
We don't want to autocomplete flags whose Flags class has `NoDriverOption` when argv[1] is not `-cc1`.

Another idea for this implementation is to make --autocomplete a cc1
option and handle it in clang Frontend, by porting --autocomplete
handler from Driver to Frontend, so that we can handle Driver options
and CC1 options in unified manner.

Differential Revision: https://reviews.llvm.org/D34770

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307479 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Option/OptTable.h
lib/Option/OptTable.cpp

index 3e7b019..a35e182 100644 (file)
@@ -140,7 +140,8 @@ public:
   //  to start with.
   ///
   /// \return The vector of flags which start with Cur.
-  std::vector<std::string> findByPrefix(StringRef Cur) const;
+  std::vector<std::string> findByPrefix(StringRef Cur,
+                                        unsigned short DisableFlags) const;
 
   /// \brief Parse a single argument; returning the new argument and
   /// updating Index.
index a5c12ac..bcd3652 100644 (file)
@@ -225,11 +225,15 @@ OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
   return {};
 }
 
-std::vector<std::string> OptTable::findByPrefix(StringRef Cur) const {
+std::vector<std::string>
+OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector<std::string> Ret;
   for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
     if (!In.Prefixes || (!In.HelpText && !In.GroupID))
       continue;
+    if (In.Flags & DisableFlags)
+      continue;
+
     for (int I = 0; In.Prefixes[I]; I++) {
       std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
       if (StringRef(S).startswith(Cur))