Don't generate MIN & MAX enum values if "--no-prefix" is used.

Close #3892
This commit is contained in:
BogDan Vatra 2016-06-01 10:23:44 +03:00
parent cccd7003ed
commit 3e52fecd1e
1 changed files with 13 additions and 11 deletions

View File

@ -179,17 +179,19 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
maxv = !maxv || maxv->value < ev.value ? &ev : maxv; maxv = !maxv || maxv->value < ev.value ? &ev : maxv;
anyv |= ev.value; anyv |= ev.value;
} }
assert(minv && maxv); if (parser.opts.scoped_enums || parser.opts.prefixed_enums) {
if (enum_def.attributes.Lookup("bit_flags")) { assert(minv && maxv);
if (minv->value != 0) // If the user didn't defined NONE value if (enum_def.attributes.Lookup("bit_flags")) {
code += " " + GenEnumVal(enum_def, "NONE", parser.opts) + " = 0,\n"; if (minv->value != 0) // If the user didn't defined NONE value
if (maxv->value != anyv) // If the user didn't defined ANY value code += " " + GenEnumVal(enum_def, "NONE", parser.opts) + " = 0,\n";
code += " " + GenEnumVal(enum_def, "ANY", parser.opts) + " = " + NumToString(anyv) + "\n"; if (maxv->value != anyv) // If the user didn't defined ANY value
} else { // MIN & MAX are useless for bit_flags code += " " + GenEnumVal(enum_def, "ANY", parser.opts) + " = " + NumToString(anyv) + "\n";
code += " " + GenEnumVal(enum_def, "MIN", parser.opts) + " = "; } else { // MIN & MAX are useless for bit_flags
code += GenEnumVal(enum_def, minv->name, parser.opts) + ",\n"; code += " " + GenEnumVal(enum_def, "MIN", parser.opts) + " = ";
code += " " + GenEnumVal(enum_def, "MAX", parser.opts) + " = "; code += GenEnumVal(enum_def, minv->name, parser.opts) + ",\n";
code += GenEnumVal(enum_def, maxv->name, parser.opts) + "\n"; code += " " + GenEnumVal(enum_def, "MAX", parser.opts) + " = ";
code += GenEnumVal(enum_def, maxv->name, parser.opts) + "\n";
}
} }
code += "};\n"; code += "};\n";
if (parser.opts.scoped_enums && enum_def.attributes.Lookup("bit_flags")) if (parser.opts.scoped_enums && enum_def.attributes.Lookup("bit_flags"))