فهرست منبع

[Bash-autocompletion] Add support for static analyzer flags

Summary:
This is a patch for clang autocomplete feature.

It will collect values which -analyzer-checker takes, which is defined in
clang/StaticAnalyzer/Checkers/Checkers.inc, dynamically.
First, from ValuesCode class in Options.td, TableGen will generate C++
code in Options.inc. Options.inc will be included in DriverOptions.cpp, and
calls OptTable's addValues function. addValues function will add second
argument to Option's Values class. Values contains string like "foo,bar,.."
which is handed to Values class
in OptTable.

Reviewers: v.g.vassilev, teemperor, ruiu

Subscribers: hiraditya, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311552 91177308-0d34-0410-b5e6-96231b3b80d8
Yuka Takahashi 8 سال پیش
والد
کامیت
ecfb2759da
3فایلهای تغییر یافته به همراه25 افزوده شده و 2 حذف شده
  1. 13 1
      include/clang/Driver/CC1Options.td
  2. 10 1
      lib/Driver/DriverOptions.cpp
  3. 2 0
      test/Driver/autocomplete.c

+ 13 - 1
include/clang/Driver/CC1Options.td

@@ -99,7 +99,19 @@ def analyzer_stats : Flag<["-"], "analyzer-stats">,
   HelpText<"Print internal analyzer statistics.">;
   HelpText<"Print internal analyzer statistics.">;
 
 
 def analyzer_checker : Separate<["-"], "analyzer-checker">,
 def analyzer_checker : Separate<["-"], "analyzer-checker">,
-  HelpText<"Choose analyzer checkers to enable">;
+  HelpText<"Choose analyzer checkers to enable">,
+  ValuesCode<[{
+    const char *Values =
+    #define GET_CHECKERS
+    #define CHECKER(FULLNAME, CLASS, DESCFILE, HT, G, H)  FULLNAME ","
+    #include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+    #undef GET_CHECKERS
+    #define GET_PACKAGES
+    #define PACKAGE(FULLNAME, G, D)  FULLNAME ","
+    #include "clang/StaticAnalyzer/Checkers/Checkers.inc"
+    #undef GET_PACKAGES
+    ;
+  }]>;
 def analyzer_checker_EQ : Joined<["-"], "analyzer-checker=">,
 def analyzer_checker_EQ : Joined<["-"], "analyzer-checker=">,
   Alias<analyzer_checker>;
   Alias<analyzer_checker>;
 
 

+ 10 - 1
lib/Driver/DriverOptions.cpp

@@ -11,6 +11,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Option/Option.h"
+#include <cassert>
 
 
 using namespace clang::driver;
 using namespace clang::driver;
 using namespace clang::driver::options;
 using namespace clang::driver::options;
@@ -40,5 +41,13 @@ public:
 }
 }
 
 
 std::unique_ptr<OptTable> clang::driver::createDriverOptTable() {
 std::unique_ptr<OptTable> clang::driver::createDriverOptTable() {
-  return llvm::make_unique<DriverOptTable>();
+  auto Result = llvm::make_unique<DriverOptTable>();
+  // Options.inc is included in DriverOptions.cpp, and calls OptTable's
+  // addValues function.
+  // Opt is a variable used in the code fragment in Options.inc.
+  OptTable &Opt = *Result;
+#define OPTTABLE_ARG_INIT
+#include "clang/Driver/Options.inc"
+#undef OPTTABLE_ARG_INIT
+  return std::move(Result);
 }
 }

+ 2 - 0
test/Driver/autocomplete.c

@@ -93,3 +93,5 @@
 // WARNING-NEXT: -Wmax-unsigned-zero
 // WARNING-NEXT: -Wmax-unsigned-zero
 // RUN: %clang --autocomplete=-Wno-invalid-pp- | FileCheck %s -check-prefix=NOWARNING
 // RUN: %clang --autocomplete=-Wno-invalid-pp- | FileCheck %s -check-prefix=NOWARNING
 // NOWARNING: -Wno-invalid-pp-token
 // NOWARNING: -Wno-invalid-pp-token
+// RUN: %clang --autocomplete=-analyzer-checker, | FileCheck %s -check-prefix=ANALYZER
+// ANALYZER: unix.Malloc