5#ifndef RUNTIME_BIN_OPTIONS_H_
6#define RUNTIME_BIN_OPTIONS_H_
45 DISALLOW_ALLOCATION();
53 return cb_(option, vm_options);
60#define DEFINE_CB_OPTION(callback) \
61 static CallbackOptionProcessor option_##callback(&callback);
63#define DEFINE_STRING_OPTION_CB(name, callback) \
64 class OptionProcessor_##name : public OptionProcessor { \
66 virtual bool Process(const char* option, CommandLineOptions* vm_options) { \
68 OptionProcessor::ProcessOption(option, "--" #name "="); \
69 if (value == nullptr) { \
72 if (*value == '\0') { \
73 Syslog::PrintErr("Empty value for option " #name "\n"); \
80 static OptionProcessor_##name option_##name;
82#define DEFINE_STRING_OPTION(name, variable) \
83 DEFINE_STRING_OPTION_CB(name, { variable = value; })
85#define DEFINE_ENUM_OPTION(name, enum_name, variable) \
86 DEFINE_STRING_OPTION_CB(name, { \
87 const char* const* kNames = k##enum_name##Names; \
88 for (intptr_t i = 0; kNames[i] != nullptr; i++) { \
89 if (strcmp(value, kNames[i]) == 0) { \
90 variable = static_cast<enum_name>(i); \
95 "Unrecognized value for " #name ": '%s'\nValid values are: ", value); \
96 for (intptr_t i = 0; kNames[i] != nullptr; i++) { \
97 Syslog::PrintErr("%s%s", i > 0 ? ", " : "", kNames[i]); \
99 Syslog::PrintErr("\n"); \
102#define DEFINE_BOOL_OPTION_CB(name, callback) \
103 class OptionProcessor_##name : public OptionProcessor { \
105 virtual bool Process(const char* option, CommandLineOptions* vm_options) { \
106 const char* value = OptionProcessor::ProcessOption(option, "--" #name); \
107 if (value == nullptr) { \
110 if (*value == '=') { \
111 Syslog::PrintErr("Non-empty value for option " #name "\n"); \
114 if (*value != '\0') { \
117 callback(vm_options); \
121 static OptionProcessor_##name option_##name;
123#define DEFINE_BOOL_OPTION(name, variable) \
124 class OptionProcessor_##name : public OptionProcessor { \
126 virtual bool Process(const char* option, CommandLineOptions* vm_options) { \
127 const char* value = OptionProcessor::ProcessOption(option, "--" #name); \
128 if (value == nullptr) { \
131 if (*value == '=') { \
132 Syslog::PrintErr("Non-empty value for option " #name "\n"); \
135 if (*value != '\0') { \
142 static OptionProcessor_##name option_##name;
144#define DEFINE_BOOL_OPTION_SHORT(short_name, long_name, variable) \
145 class OptionProcessor_##long_name : public OptionProcessor { \
147 virtual bool Process(const char* option, CommandLineOptions* vm_options) { \
148 const char* value = \
149 OptionProcessor::ProcessOption(option, "-" #short_name); \
150 if (value == nullptr) { \
151 value = OptionProcessor::ProcessOption(option, "--" #long_name); \
153 if (value == nullptr) { \
156 if (*value == '=') { \
157 Syslog::PrintErr("Non-empty value for option " #long_name "\n"); \
160 if (*value != '\0') { \
167 static OptionProcessor_##long_name option_##long_name;
CallbackOptionProcessor(OptionProcessorCallback cb)
virtual bool Process(const char *option, CommandLineOptions *vm_options)
static bool TryProcess(const char *option, CommandLineOptions *options)
static bool IsValidShortFlag(const char *name)
static const char * ProcessOption(const char *option, const char *name)
static bool ProcessEnvironmentOption(const char *arg, CommandLineOptions *vm_options, dart::SimpleHashMap **environment)
virtual bool Process(const char *option, CommandLineOptions *options)=0
virtual ~OptionProcessor()
static bool IsValidFlag(const char *name)
bool(* OptionProcessorCallback)(const char *arg, CommandLineOptions *vm_options)
static dart::SimpleHashMap * environment