//===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class implements a command line argument processor that is useful when
// creating a tool. It provides a simple, minimalistic interface that is easily
// extensible and supports nonlocal (library) command line options.
//
// Note that rather than trying to figure out what this code does, you should
// read the library documentation located in docs/CommandLine.html or looks at
// the many example usages in tools/*/*.cpp
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_COMMANDLINE_H
#define LLVM_SUPPORT_COMMANDLINE_H
#include "llvm/Support/type_traits.h"
#include <string>
#include <vector>
#include <utility>
#include <cstdarg>
#include <cassert>
namespace llvm {
/// cl Namespace - This namespace contains all of the command line option
/// processing machinery. It is intentionally a short name to make qualified
/// usage concise.
namespace cl {
//===----------------------------------------------------------------------===//
// ParseCommandLineOptions - Command line option processing entry point.
//
void ParseCommandLineOptions(int &argc, char **argv,
const char *Overview = 0);
//===----------------------------------------------------------------------===//
// ParseEnvironmentOptions - Environment variable option processing alternate
// entry point.
//
void ParseEnvironmentOptions(const char *progName, const char *envvar,
const char *Overview = 0);
//===----------------------------------------------------------------------===//
// Flags permitted to be passed to command line arguments
//
enum NumOccurrences { // Flags for the number of occurrences allowed
Optional = 0x01, // Zero or One occurrence
ZeroOrMore = 0x02, // Zero or more occurrences allowed
Required = 0x03, // One occurrence required
OneOrMore = 0x04, // One or more occurrences required
// ConsumeAfter - Indicates that this option is fed anything that follows the
// last positional argument required by the application (it is an error if
// there are zero positional arguments, and a ConsumeAfter option is used).
// Thus, for example, all arguments to LLI are processed until a filename is
// found. Once a filename is found, all of the succeeding arguments are
// passed, unprocessed, to the ConsumeAfter option.
//
ConsumeAfter = 0x05,
OccurrencesMask = 0x07,
};
enum ValueExpected { // Is a value required for the option?
ValueOptional = 0x08, // The value can appear... or not
ValueRequired = 0x10, // The value is required to appear!
ValueDisallowed = 0x18, // A value may not be specified (for flags)
ValueMask = 0x18,
};
enum OptionHidden { // Control whether -help shows this option
NotHidden = 0x20, // Option included in --help & --help-hidden
Hidden = 0x40, // -help doesn't, but --help-hidden does
ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
HiddenMask = 0x60,
};
// Formatting flags - This controls special features that the option might have
// that cause it to be parsed differently...
//
// Prefix - This option allows arguments that are otherwise unrecognized to be
// matched by options that are a prefix of the actual value. This is useful for
// cases like a linker, where options are typically of the form '-lfoo' or
// '-L../../include' where -l or -L are the actual flags. When prefix is
// enabled, and used, the value for the flag comes from the suffix of the
// argument.
//
// Grouping - With this option enabled, multiple letter options are allowed to
// bunch together with only a single hyphen for the whole group. This allows
// emulation of the behavior that ls uses for example: ls -la === ls -l -a
//
enum FormattingFlags {
NormalFormatting = 0x000, // Nothing special
Positional = 0x080, // Is a positional argument, no '-' required
Prefix = 0x100, // Can this option directly prefix its value?
Grouping = 0x180, // Can this option group with other options?
FormattingMask = 0x180, // Union of the above flags.
};
enum MiscFlags { // Miscellaneous flags to adjust argument
CommaSeparated = 0x200, // Should this cl::list split between commas?
PositionalEatsArgs = 0x400, // Should this positional cl::list eat -args?
MiscMask = 0x600, // U