mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
Add ability to update existing variables with values read from the command line
to certain classes. This is nice because it means that in header files we can just declare a value, and still have that value be set based on a command-line argument. The difference is now that the #include of CommandLine.h does not need to go into the header file as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2708 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -176,12 +176,22 @@ public:
|
|||||||
// Boolean/flag command line option
|
// Boolean/flag command line option
|
||||||
//
|
//
|
||||||
class Flag : public Option {
|
class Flag : public Option {
|
||||||
bool Value;
|
bool &Value;
|
||||||
|
bool DValue;
|
||||||
virtual bool handleOccurance(const char *ArgName, const std::string &Arg);
|
virtual bool handleOccurance(const char *ArgName, const std::string &Arg);
|
||||||
public:
|
public:
|
||||||
inline Flag(const char *ArgStr, const char *Message, int Flags = 0,
|
inline Flag(const char *ArgStr, const char *Message, int Flags = 0,
|
||||||
bool DefaultVal = 0) : Option(ArgStr, Message, Flags),
|
bool DefaultVal = false)
|
||||||
Value(DefaultVal) {}
|
: Option(ArgStr, Message, Flags), Value(DValue) {
|
||||||
|
Value = DefaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Flag(bool &UpdateVal, const char *ArgStr, const char *Message,
|
||||||
|
int Flags = 0, bool DefaultVal = false)
|
||||||
|
: Option(ArgStr, Message, Flags), Value(UpdateVal) {
|
||||||
|
Value = DefaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
operator const bool() const { return Value; }
|
operator const bool() const { return Value; }
|
||||||
inline bool operator=(bool Val) { Value = Val; return Val; }
|
inline bool operator=(bool Val) { Value = Val; return Val; }
|
||||||
};
|
};
|
||||||
@ -278,7 +288,6 @@ public:
|
|||||||
|
|
||||||
class EnumValueBase : public EnumBase {
|
class EnumValueBase : public EnumBase {
|
||||||
protected:
|
protected:
|
||||||
int Value;
|
|
||||||
inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
|
inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
|
||||||
: EnumBase(ArgStr, Help, Flags) {}
|
: EnumBase(ArgStr, Help, Flags) {}
|
||||||
inline EnumValueBase(int Flags) : EnumBase(Flags) {}
|
inline EnumValueBase(int Flags) : EnumBase(Flags) {}
|
||||||
@ -293,6 +302,9 @@ protected:
|
|||||||
// to-be-maintained width is specified.
|
// to-be-maintained width is specified.
|
||||||
//
|
//
|
||||||
virtual void printOptionInfo(unsigned GlobalWidth) const;
|
virtual void printOptionInfo(unsigned GlobalWidth) const;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class E> // The enum we are representing
|
template <class E> // The enum we are representing
|
||||||
@ -300,17 +312,31 @@ class Enum : public EnumValueBase {
|
|||||||
virtual enum ValueExpected getValueExpectedFlagDefault() const {
|
virtual enum ValueExpected getValueExpectedFlagDefault() const {
|
||||||
return ValueRequired;
|
return ValueRequired;
|
||||||
}
|
}
|
||||||
|
E DVal;
|
||||||
|
E &Value;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) { Value = (E)Val; }
|
||||||
public:
|
public:
|
||||||
inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
|
inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
|
||||||
: EnumValueBase(ArgStr, Help, Flags) {
|
: EnumValueBase(ArgStr, Help, Flags), Value(DVal) {
|
||||||
va_list Values;
|
va_list Values;
|
||||||
va_start(Values, Help);
|
va_start(Values, Help);
|
||||||
processValues(Values);
|
processValues(Values);
|
||||||
va_end(Values);
|
va_end(Values);
|
||||||
Value = ValueMap.front().second.first; // Grab default value
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator E() const { return (E)Value; }
|
inline Enum(E &EUpdate, const char *ArgStr, int Flags, const char *Help, ...)
|
||||||
|
: EnumValueBase(ArgStr, Help, Flags), Value(EUpdate) {
|
||||||
|
va_list Values;
|
||||||
|
va_start(Values, Help);
|
||||||
|
processValues(Values);
|
||||||
|
va_end(Values);
|
||||||
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
|
}
|
||||||
|
|
||||||
|
inline operator E() const { return Value; }
|
||||||
inline E operator=(E Val) { Value = Val; return Val; }
|
inline E operator=(E Val) { Value = Val; return Val; }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -337,14 +363,27 @@ protected:
|
|||||||
|
|
||||||
template <class E> // The enum we are representing
|
template <class E> // The enum we are representing
|
||||||
class EnumFlags : public EnumFlagsBase {
|
class EnumFlags : public EnumFlagsBase {
|
||||||
|
E DVal;
|
||||||
|
E &Value;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) { Value = (E)Val; }
|
||||||
public:
|
public:
|
||||||
inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags) {
|
inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags), Value(DVal) {
|
||||||
va_list Values;
|
va_list Values;
|
||||||
va_start(Values, Flags);
|
va_start(Values, Flags);
|
||||||
processValues(Values);
|
processValues(Values);
|
||||||
va_end(Values);
|
va_end(Values);
|
||||||
registerArgs();
|
registerArgs();
|
||||||
Value = ValueMap.front().second.first; // Grab default value
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
|
}
|
||||||
|
inline EnumFlags(E &RV, int Flags, ...) : EnumFlagsBase(Flags), Value(RV) {
|
||||||
|
va_list Values;
|
||||||
|
va_start(Values, Flags);
|
||||||
|
processValues(Values);
|
||||||
|
va_end(Values);
|
||||||
|
registerArgs();
|
||||||
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator E() const { return (E)Value; }
|
inline operator E() const { return (E)Value; }
|
||||||
|
@ -176,12 +176,22 @@ public:
|
|||||||
// Boolean/flag command line option
|
// Boolean/flag command line option
|
||||||
//
|
//
|
||||||
class Flag : public Option {
|
class Flag : public Option {
|
||||||
bool Value;
|
bool &Value;
|
||||||
|
bool DValue;
|
||||||
virtual bool handleOccurance(const char *ArgName, const std::string &Arg);
|
virtual bool handleOccurance(const char *ArgName, const std::string &Arg);
|
||||||
public:
|
public:
|
||||||
inline Flag(const char *ArgStr, const char *Message, int Flags = 0,
|
inline Flag(const char *ArgStr, const char *Message, int Flags = 0,
|
||||||
bool DefaultVal = 0) : Option(ArgStr, Message, Flags),
|
bool DefaultVal = false)
|
||||||
Value(DefaultVal) {}
|
: Option(ArgStr, Message, Flags), Value(DValue) {
|
||||||
|
Value = DefaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Flag(bool &UpdateVal, const char *ArgStr, const char *Message,
|
||||||
|
int Flags = 0, bool DefaultVal = false)
|
||||||
|
: Option(ArgStr, Message, Flags), Value(UpdateVal) {
|
||||||
|
Value = DefaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
operator const bool() const { return Value; }
|
operator const bool() const { return Value; }
|
||||||
inline bool operator=(bool Val) { Value = Val; return Val; }
|
inline bool operator=(bool Val) { Value = Val; return Val; }
|
||||||
};
|
};
|
||||||
@ -278,7 +288,6 @@ public:
|
|||||||
|
|
||||||
class EnumValueBase : public EnumBase {
|
class EnumValueBase : public EnumBase {
|
||||||
protected:
|
protected:
|
||||||
int Value;
|
|
||||||
inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
|
inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
|
||||||
: EnumBase(ArgStr, Help, Flags) {}
|
: EnumBase(ArgStr, Help, Flags) {}
|
||||||
inline EnumValueBase(int Flags) : EnumBase(Flags) {}
|
inline EnumValueBase(int Flags) : EnumBase(Flags) {}
|
||||||
@ -293,6 +302,9 @@ protected:
|
|||||||
// to-be-maintained width is specified.
|
// to-be-maintained width is specified.
|
||||||
//
|
//
|
||||||
virtual void printOptionInfo(unsigned GlobalWidth) const;
|
virtual void printOptionInfo(unsigned GlobalWidth) const;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class E> // The enum we are representing
|
template <class E> // The enum we are representing
|
||||||
@ -300,17 +312,31 @@ class Enum : public EnumValueBase {
|
|||||||
virtual enum ValueExpected getValueExpectedFlagDefault() const {
|
virtual enum ValueExpected getValueExpectedFlagDefault() const {
|
||||||
return ValueRequired;
|
return ValueRequired;
|
||||||
}
|
}
|
||||||
|
E DVal;
|
||||||
|
E &Value;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) { Value = (E)Val; }
|
||||||
public:
|
public:
|
||||||
inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
|
inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
|
||||||
: EnumValueBase(ArgStr, Help, Flags) {
|
: EnumValueBase(ArgStr, Help, Flags), Value(DVal) {
|
||||||
va_list Values;
|
va_list Values;
|
||||||
va_start(Values, Help);
|
va_start(Values, Help);
|
||||||
processValues(Values);
|
processValues(Values);
|
||||||
va_end(Values);
|
va_end(Values);
|
||||||
Value = ValueMap.front().second.first; // Grab default value
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator E() const { return (E)Value; }
|
inline Enum(E &EUpdate, const char *ArgStr, int Flags, const char *Help, ...)
|
||||||
|
: EnumValueBase(ArgStr, Help, Flags), Value(EUpdate) {
|
||||||
|
va_list Values;
|
||||||
|
va_start(Values, Help);
|
||||||
|
processValues(Values);
|
||||||
|
va_end(Values);
|
||||||
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
|
}
|
||||||
|
|
||||||
|
inline operator E() const { return Value; }
|
||||||
inline E operator=(E Val) { Value = Val; return Val; }
|
inline E operator=(E Val) { Value = Val; return Val; }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -337,14 +363,27 @@ protected:
|
|||||||
|
|
||||||
template <class E> // The enum we are representing
|
template <class E> // The enum we are representing
|
||||||
class EnumFlags : public EnumFlagsBase {
|
class EnumFlags : public EnumFlagsBase {
|
||||||
|
E DVal;
|
||||||
|
E &Value;
|
||||||
|
|
||||||
|
// setValue - Subclasses override this when they need to receive a new value
|
||||||
|
virtual void setValue(int Val) { Value = (E)Val; }
|
||||||
public:
|
public:
|
||||||
inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags) {
|
inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags), Value(DVal) {
|
||||||
va_list Values;
|
va_list Values;
|
||||||
va_start(Values, Flags);
|
va_start(Values, Flags);
|
||||||
processValues(Values);
|
processValues(Values);
|
||||||
va_end(Values);
|
va_end(Values);
|
||||||
registerArgs();
|
registerArgs();
|
||||||
Value = ValueMap.front().second.first; // Grab default value
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
|
}
|
||||||
|
inline EnumFlags(E &RV, int Flags, ...) : EnumFlagsBase(Flags), Value(RV) {
|
||||||
|
va_list Values;
|
||||||
|
va_start(Values, Flags);
|
||||||
|
processValues(Values);
|
||||||
|
va_end(Values);
|
||||||
|
registerArgs();
|
||||||
|
Value = (E)ValueMap.front().second.first; // Grab default value
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator E() const { return (E)Value; }
|
inline operator E() const { return (E)Value; }
|
||||||
|
@ -346,7 +346,7 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) {
|
|||||||
return error(": unrecognized alternative '" + Arg +
|
return error(": unrecognized alternative '" + Arg +
|
||||||
"'! Alternatives are: " + Alternatives);
|
"'! Alternatives are: " + Alternatives);
|
||||||
}
|
}
|
||||||
Value = ValueMap[i].second.first;
|
setValue(ValueMap[i].second.first);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) {
|
|||||||
return error(": unrecognized alternative '" + Arg +
|
return error(": unrecognized alternative '" + Arg +
|
||||||
"'! Alternatives are: " + Alternatives);
|
"'! Alternatives are: " + Alternatives);
|
||||||
}
|
}
|
||||||
Value = ValueMap[i].second.first;
|
setValue(ValueMap[i].second.first);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user