Option: Propagate flags from groups to options in each group
authorReid Kleckner <reid@kleckner.net>
Sat, 12 Jul 2014 00:18:58 +0000 (00:18 +0000)
committerReid Kleckner <reid@kleckner.net>
Sat, 12 Jul 2014 00:18:58 +0000 (00:18 +0000)
This should make it easy to set a flag for a whole group of clang driver
options.

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

include/llvm/Option/OptParser.td
utils/TableGen/OptParserEmitter.cpp

index 963389f0bc6fdc86e35d5c93d2c522d8d7e5f00f..dbf240d748051ca4c69df15acdf4d09ad4647180 100644 (file)
@@ -75,6 +75,7 @@ class OptionGroup<string name> {
   string Name = name;
   string HelpText = ?;
   OptionGroup Group = ?;
+  list<OptionFlag> Flags = [];
 }
 
 // Define the option class.
index c5fd7eecbfefdc5ff53efb4e37bced51fcd5d922..9262d7c8a02c66b38c71eb5a984d3baf497f378a 100644 (file)
@@ -221,9 +221,11 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
 
     // The containing option group (if any).
     OS << ", ";
-    if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
+    const ListInit *GroupFlags = nullptr;
+    if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
+      GroupFlags = DI->getDef()->getValueAsListInit("Flags");
       OS << getOptionName(*DI->getDef());
-    else
+    else
       OS << "INVALID";
 
     // The option alias (if any).
@@ -249,17 +251,19 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
     }
 
     // The option flags.
+    OS << ", ";
+    int NumFlags = 0;
     const ListInit *LI = R.getValueAsListInit("Flags");
-    if (LI->empty()) {
-      OS << ", 0";
-    } else {
-      OS << ", ";
-      for (unsigned i = 0, e = LI->size(); i != e; ++i) {
-        if (i)
-          OS << " | ";
-        OS << cast<DefInit>(LI->getElement(i))->getDef()->getName();
-      }
+    for (Init *I : *LI)
+      OS << (NumFlags++ ? " | " : "")
+         << cast<DefInit>(I)->getDef()->getName();
+    if (GroupFlags) {
+      for (Init *I : *GroupFlags)
+        OS << (NumFlags++ ? " | " : "")
+           << cast<DefInit>(I)->getDef()->getName();
     }
+    if (NumFlags == 0)
+      OS << '0';
 
     // The option parameter field.
     OS << ", " << R.getValueAsInt("NumArgs");