mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Add an 'init' option property.
Makes possible to provide default values for options defined in plugins (same as cl::init). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74905 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cbc360d567
commit
8fe4447a0f
@ -39,6 +39,7 @@ def prefix_list_option;
|
||||
def extern;
|
||||
def help;
|
||||
def hidden;
|
||||
def init;
|
||||
def multi_val;
|
||||
def one_or_more;
|
||||
def really_hidden;
|
||||
@ -51,6 +52,10 @@ def empty;
|
||||
// The 'case' construct.
|
||||
def case;
|
||||
|
||||
// Boolean constants.
|
||||
def true;
|
||||
def false;
|
||||
|
||||
// Boolean operators.
|
||||
def and;
|
||||
def or;
|
||||
|
@ -187,11 +187,12 @@ struct OptionDescription {
|
||||
unsigned Flags;
|
||||
std::string Help;
|
||||
unsigned MultiVal;
|
||||
Init* InitVal;
|
||||
|
||||
OptionDescription(OptionType::OptionType t = OptionType::Switch,
|
||||
const std::string& n = "",
|
||||
const std::string& h = DefaultHelpString)
|
||||
: Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1)
|
||||
: Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1), InitVal(0)
|
||||
{}
|
||||
|
||||
/// GenTypeDeclaration - Returns the C++ variable type of this
|
||||
@ -447,6 +448,7 @@ public:
|
||||
AddHandler("extern", &CollectOptionProperties::onExtern);
|
||||
AddHandler("help", &CollectOptionProperties::onHelp);
|
||||
AddHandler("hidden", &CollectOptionProperties::onHidden);
|
||||
AddHandler("init", &CollectOptionProperties::onInit);
|
||||
AddHandler("multi_val", &CollectOptionProperties::onMultiVal);
|
||||
AddHandler("one_or_more", &CollectOptionProperties::onOneOrMore);
|
||||
AddHandler("really_hidden", &CollectOptionProperties::onReallyHidden);
|
||||
@ -490,6 +492,20 @@ private:
|
||||
optDesc_.setRequired();
|
||||
}
|
||||
|
||||
void onInit (const DagInit* d) {
|
||||
checkNumberOfArguments(d, 1);
|
||||
Init* i = d->getArg(0);
|
||||
const std::string& str = i->getAsString();
|
||||
|
||||
bool correct = optDesc_.isParameter() && dynamic_cast<StringInit*>(i);
|
||||
correct |= (optDesc_.isSwitch() && (str == "true" || str == "false"));
|
||||
|
||||
if (!correct)
|
||||
throw std::string("Incorrect usage of the 'init' option property!");
|
||||
|
||||
optDesc_.InitVal = i;
|
||||
}
|
||||
|
||||
void onOneOrMore (const DagInit* d) {
|
||||
checkNumberOfArguments(d, 0);
|
||||
if (optDesc_.isRequired() || optDesc_.isZeroOrOne())
|
||||
@ -1716,7 +1732,12 @@ void EmitOptionDefinitions (const OptionDescriptions& descs,
|
||||
}
|
||||
|
||||
if (val.MultiVal > 1)
|
||||
O << ", cl::multi_val(" << val.MultiVal << ")";
|
||||
O << ", cl::multi_val(" << val.MultiVal << ')';
|
||||
|
||||
if (val.InitVal) {
|
||||
const std::string& str = val.InitVal->getAsString();
|
||||
O << ", cl::init(" << str << ')';
|
||||
}
|
||||
|
||||
if (!val.Help.empty())
|
||||
O << ", cl::desc(\"" << val.Help << "\")";
|
||||
|
Loading…
x
Reference in New Issue
Block a user