[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-16 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308139: [Bash-autocompletion] Add support for -W 
and -Wno (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D35447?vs=106774=106805#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35447

Files:
  cfe/trunk/include/clang/Basic/DiagnosticIDs.h
  cfe/trunk/lib/Basic/DiagnosticIDs.cpp
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/autocomplete.c


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1275,6 +1275,13 @@
   // 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: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
===
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,18 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector 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: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
===
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
   class DiagnosticsEngine;
@@ -263,6 +264,13 @@
   /// 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 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: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -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


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1275,6 +1275,13 @@
   // 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: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
===
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp

[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu accepted this revision.
ruiu added a comment.

LGTM




Comment at: clang/lib/Driver/Driver.cpp:1283
+  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))
+  SuggestedCompletions.push_back(S);

nit: StringRef(S) -> S as S is already a StringRef.


https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor accepted this revision.
teemperor added a comment.
This revision is now accepted and ready to land.

I have a last request in my inline comment regarding the documentation, 
otherwise this is good to go. Nice work!




Comment at: clang/include/clang/Basic/DiagnosticIDs.h:267
 
+  /// \brief Get the string of all diagnostic flags
+  static std::vector getDiagnosticFlags();

Let's add an example to make it clear that we want to have the command line 
flags here, something like this:
```
/// \brief Get the list 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", ...}`
```


https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 106774.
yamaguchi added a comment.

Fixed indent.


https://reviews.llvm.org/D35447

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


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,13 @@
   // 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 (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,18 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector 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: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
   class DiagnosticsEngine;
@@ -263,6 +264,9 @@
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  /// \brief Get the string of all diagnostic flags
+  static std::vector 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: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,13 @@
   // 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 (StringRef(S).startswith(PassedFlags))
+  SuggestedCompletions.push_back(S);
 } else {
   // If the flag is in the form of 

[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 106764.
yamaguchi added a comment.

Add code comment.


https://reviews.llvm.org/D35447

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


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,12 @@
   // 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 (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,18 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector 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: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
   class DiagnosticsEngine;
@@ -263,6 +264,9 @@
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  /// \brief Get the string of all diagnostic flags
+  static std::vector 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: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,12 @@
   // 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 (StringRef(S).startswith(PassedFlags))
+  SuggestedCompletions.push_back(S);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we 

[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 106763.
yamaguchi added a comment.

Update diff according to Rui and teemperor's comments.


https://reviews.llvm.org/D35447

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


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // 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);
+
+  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,18 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector 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: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
   class DiagnosticsEngine;
@@ -263,6 +264,9 @@
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  /// \brief Get the string of all diagnostic flags
+  static std::vector 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: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // 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);
+
+  for (StringRef S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,18 @@
   return 

[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

@yamaguchi yes, the reason why we have to treat the `-W...` flags specially 
should be documented (as they're not in the OptTable as you said). E.g. 
something like `// We have to query the -W flags manually as they're not in the 
OptTable.` and then maybe a `TODO: Find a good way to add them to OptTable 
instead and them remove this code.`.


https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

@teemperor 
I forgot to include  in DiagnosticIDs, thanks!

What do you mean `reuse the normal flags` ?
Do you think we should define these -W in Options.td like other flags?


https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-15 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

It seems the code doesn't compile in clang because on your platform 
`std::vector` is implicitly included by some header, on clang+Arch however it 
isn`t (see the error at the end of https://teemperor.de/ccir/D35447).




Comment at: clang/lib/Driver/Driver.cpp:1279
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))

ruiu wrote:
> Let's avoid copy: std::string -> StringRef
> 
Could you document why we had to do it this way and can't reuse the normal 
flags? Maybe even add a `TODO:` because it would be nice project for someone to 
refactor this into one data structure.


https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-14 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticIDs.h:266
 
+  static std::vector getDiagnosticFlags();
+

Please write a function comment just like other member functions in this class.



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:514
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {

res -> Res
i -> I




Comment at: clang/lib/Basic/DiagnosticIDs.cpp:515
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =

`size_t` is more precise than `int`, even though sizeof(DiagGroupNames) in 
reality fits in an int.



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:516-517
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =
+std::string(StringRef(DiagGroupNames + i + 1, DiagGroupNames[i]));
+i += DiagGroupNames[i] + 1;

If you want to construct a string, you can do this

  std::string Diag(DiagGroupNames + i + 1, DiagGroupNames[i]);



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:519-522
+std::string W = "-W" + Diag;
+std::string Wno = "-Wno" + Diag;
+res.push_back(W);
+res.push_back(Wno);

I think you can remove these temporary variables:

  res.push_back("-W" + Diag);
  res.push_back("-Wno" + Diag);



Comment at: clang/lib/Driver/Driver.cpp:1279
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))

Let's avoid copy: std::string -> StringRef



https://reviews.llvm.org/D35447



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


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-14 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

`-W[tab]` will autocomplete warnings defined in this link:
https://clang.llvm.org/docs/DiagnosticsReference.html#wweak-vtables


https://reviews.llvm.org/D35447

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


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // 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);
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,21 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =
+std::string(StringRef(DiagGroupNames + i + 1, DiagGroupNames[i]));
+i += DiagGroupNames[i] + 1;
+std::string W = "-W" + Diag;
+std::string Wno = "-Wno" + Diag;
+res.push_back(W);
+res.push_back(Wno);
+  }
+
+  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: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -263,6 +263,8 @@
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  static std::vector 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: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -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
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // 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);
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(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: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,21 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] !=