From b587f9662a7b6f00f9ce48ddf2dea1a4fb18a6db Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 29 Apr 2009 23:26:16 +0000 Subject: [PATCH] Add support for a character after a command line option. Like '-Os'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70437 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 23 +++++++++++++++++++++++ lib/Support/CommandLine.cpp | 3 +++ 2 files changed, 26 insertions(+) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 1b625588d28..fa3b8701d34 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -679,6 +679,28 @@ public: EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); +//-------------------------------------------------- +// parser +// +template<> +class parser : public basic_parser { +public: + // parse - Return true on error. + bool parse(Option &, const char *, const std::string &Arg, + char &Value) { + Value = Arg[0]; + return false; + } + + // getValueName - Overload in subclass to provide a better default value. + virtual const char *getValueName() const { return "char"; } + + // An out-of-line virtual method to provide a 'home' for this class. + virtual void anchor(); +}; + +EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); + //===----------------------------------------------------------------------===// // applicator class - This class is used because we must use partial // specialization to handle literal string arguments specially (const char* does @@ -923,6 +945,7 @@ public: EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); +EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); //===----------------------------------------------------------------------===// diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index e4f65ba1de9..4922560200a 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -45,10 +45,12 @@ TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); +TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class opt); TEMPLATE_INSTANTIATION(class opt); TEMPLATE_INSTANTIATION(class opt); +TEMPLATE_INSTANTIATION(class opt); TEMPLATE_INSTANTIATION(class opt); void Option::anchor() {} @@ -60,6 +62,7 @@ void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} +void parser::anchor() {} //===----------------------------------------------------------------------===// -- 2.34.1