summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2015-01-27 22:21:06 +0000
committerChris Bieneman <beanz@apple.com>2015-01-27 22:21:06 +0000
commit681693628770b4d69ca0ee69859ea97fd85f97e3 (patch)
tree546831cd0bcdff159e90e216b61d1186ee222765
parentbfa3f9d82ff549fda10aaaf4cb7633dcbf9dcec6 (diff)
downloadbcm5719-llvm-681693628770b4d69ca0ee69859ea97fd85f97e3.tar.gz
bcm5719-llvm-681693628770b4d69ca0ee69859ea97fd85f97e3.zip
Re-landing changes to use ArrayRef instead of SmallVectorImpl, and new API test.
This contains the changes from r227148 & r227154, and also fixes to the test case to properly clean up the stack options. llvm-svn: 227255
-rw-r--r--llvm/include/llvm/Support/CommandLine.h3
-rw-r--r--llvm/lib/Support/CommandLine.cpp3
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp31
3 files changed, 31 insertions, 6 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index e53ac06a3cd..efa17219585 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -20,6 +20,7 @@
#ifndef LLVM_SUPPORT_COMMANDLINE_H
#define LLVM_SUPPORT_COMMANDLINE_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
@@ -1938,7 +1939,7 @@ void HideUnrelatedOptions(cl::OptionCategory &Category);
/// Some tools (like clang-format) like to be able to hide all options that are
/// not specific to the tool. This function allows a tool to specify a single
/// option category to display in the -help output.
-void HideUnrelatedOptions(SmallVectorImpl<cl::OptionCategory *> &Categories);
+void HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *> Categories);
} // End namespace cl
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 4cd6f0c5f0a..35c49be02ce 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1861,8 +1861,7 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category) {
}
}
-void cl::HideUnrelatedOptions(
- SmallVectorImpl<cl::OptionCategory *> &Categories) {
+void cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *> Categories) {
auto CategoriesBegin = Categories.begin();
auto CategoriesEnd = Categories.end();
StringMap<cl::Option *> Options;
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 4fa14e252fb..f0ef020c7ba 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -231,8 +231,8 @@ TEST(CommandLineTest, AliasRequired) {
}
TEST(CommandLineTest, HideUnrelatedOptions) {
- cl::opt<int> TestOption1("test-option-1");
- cl::opt<int> TestOption2("test-option-2", cl::cat(TestCategory));
+ StackOption<int> TestOption1("hide-option-1");
+ StackOption<int> TestOption2("hide-option-2", cl::cat(TestCategory));
cl::HideUnrelatedOptions(TestCategory);
@@ -241,7 +241,32 @@ TEST(CommandLineTest, HideUnrelatedOptions) {
ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag())
<< "Hid extra option that should be visable.";
- StringMap<cl::Option*> Map;
+ StringMap<cl::Option *> Map;
+ cl::getRegisteredOptions(Map);
+ ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag())
+ << "Hid default option that should be visable.";
+}
+
+cl::OptionCategory TestCategory2("Test Options set 2", "Description");
+
+TEST(CommandLineTest, HideUnrelatedOptionsMulti) {
+ StackOption<int> TestOption1("multi-hide-option-1");
+ StackOption<int> TestOption2("multi-hide-option-2", cl::cat(TestCategory));
+ StackOption<int> TestOption3("multi-hide-option-3", cl::cat(TestCategory2));
+
+ const cl::OptionCategory *VisibleCategories[] = {&TestCategory,
+ &TestCategory2};
+
+ cl::HideUnrelatedOptions(makeArrayRef(VisibleCategories));
+
+ ASSERT_EQ(cl::ReallyHidden, TestOption1.getOptionHiddenFlag())
+ << "Failed to hide extra option.";
+ ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag())
+ << "Hid extra option that should be visable.";
+ ASSERT_EQ(cl::NotHidden, TestOption3.getOptionHiddenFlag())
+ << "Hid extra option that should be visable.";
+
+ StringMap<cl::Option *> Map;
cl::getRegisteredOptions(Map);
ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag())
<< "Hid default option that should be visable.";
OpenPOWER on IntegriCloud