]> granicus.if.org Git - clang/commitdiff
[Bash-autocompletion] Add support for -W<warning> and -Wno<warning>
authorYuka Takahashi <yukatkh@gmail.com>
Sun, 16 Jul 2017 15:07:20 +0000 (15:07 +0000)
committerYuka Takahashi <yukatkh@gmail.com>
Sun, 16 Jul 2017 15:07:20 +0000 (15:07 +0000)
Summary:
`-W[tab]` will autocomplete warnings defined in this link:
https://clang.llvm.org/docs/DiagnosticsReference.html#wweak-vtables

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

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

include/clang/Basic/DiagnosticIDs.h
lib/Basic/DiagnosticIDs.cpp
lib/Driver/Driver.cpp
test/Driver/autocomplete.c

index 479d1978c62d8c762708f7cd8799c9099c260220..cdd358542a0d3d331ae3bb1b7a7202f7d2911d40 100644 (file)
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include <vector>
 
 namespace clang {
   class DiagnosticsEngine;
@@ -263,6 +264,13 @@ public:
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  /// \brief Get the string of all diagnostic flags.
+  ///
+  /// \returns A list of all diagnostics flags as they would be written in a
+  /// command line invocation including their `no-` variants. For example:
+  /// `{"-Wempty-body", "-Wno-empty-body", ...}`
+  static std::vector<std::string> getDiagnosticFlags();
+
   /// \brief Get the set of all diagnostic IDs in the group with the given name.
   ///
   /// \param[out] Diags - On return, the diagnostics in the group.
index ce493c1e5caba8e5aadeab3d8cf76454d796d7eb..932b3f1934cc4af80acd0483b0fab68626c7f05c 100644 (file)
@@ -510,6 +510,18 @@ StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
   return StringRef();
 }
 
+std::vector<std::string> DiagnosticIDs::getDiagnosticFlags() {
+  std::vector<std::string> Res;
+  for (size_t I = 1; DiagGroupNames[I] != '\0';) {
+    std::string Diag(DiagGroupNames + I + 1, DiagGroupNames[I]);
+    I += DiagGroupNames[I] + 1;
+    Res.push_back("-W" + Diag);
+    Res.push_back("-Wno" + Diag);
+  }
+
+  return Res;
+}
+
 /// Return \c true if any diagnostics were found in this group, even if they
 /// were filtered out due to having the wrong flavor.
 static bool getDiagnosticsInGroup(diag::Flavor Flavor,
index 42478013ccecd76b5c8dc511e6385eca63c3e17b..1d35d6e78cca5e3bcdf9991f094ba8a3dd04eecf 100644 (file)
@@ -1275,6 +1275,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
       // we were requested to print out all option names that start with "-foo".
       // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
       SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+      // We have to query the -W flags manually as they're not in the OptTable.
+      // TODO: Find a good way to add them to OptTable instead and them remove
+      // this code.
+      for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+        if (S.startswith(PassedFlags))
+          SuggestedCompletions.push_back(S);
     } else {
       // If the flag is in the form of "--autocomplete=foo,bar", we were
       // requested to print out all option values for "-foo" that start with
index e9e2e992bae9ee4fce9793369372ba8999c5bb8c..dec48bfb35967d987836f36e0650a53b2a6da28d 100644 (file)
@@ -40,3 +40,7 @@
 // MRELOCMODEL_CLANG-NOT: -mrelocation-model
 // RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
 // MRELOCMODEL_CC1: -mrelocation-model
+// RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
+// WARNING: -Wmacro-redefined -Wmain -Wmain-return-type -Wmalformed-warning-check -Wmany-braces-around-scalar-init -Wmax-unsigned-zero
+// RUN: %clang --autocomplete=-Wnoinvalid-pp- | FileCheck %s -check-prefix=NOWARNING
+// NOWARNING: -Wnoinvalid-pp-token