14DEFINE_FLAG(
bool, print_flags,
false,
"Print flags as they are being parsed.");
16 ignore_unrecognized_flags,
18 "Ignore unrecognized flags.");
20#define PRODUCT_FLAG_MACRO(name, type, default_value, comment) \
22 Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
25#define DEBUG_FLAG_MACRO(name, type, default_value, comment) \
27 Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
29#define DEBUG_FLAG_MACRO(name, type, default_value, comment)
32#if defined(PRODUCT) && defined(DART_PRECOMPILED_RUNTIME)
34#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment)
36#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
37 default_value, comment)
41#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment)
43#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
44 default_value, comment)
46#elif defined(DART_PRECOMPILED_RUNTIME)
47#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
49 Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
51#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
52 default_value, comment)
55#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment) \
57 Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
58#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, \
59 default_value, comment) \
61 Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
70#undef PRODUCT_FLAG_MACRO
71#undef RELEASE_FLAG_MACRO
72#undef PRECOMPILE_FLAG_MACRO
73#undef DEBUG_FLAG_MACRO
75#if defined(DART_PRECOMPILER)
76#if defined(TARGET_USES_THREAD_SANITIZER)
77constexpr bool kDefaultTargetThreadSanitizer =
true;
79constexpr bool kDefaultTargetThreadSanitizer =
false;
82 target_thread_sanitizer,
83 kDefaultTargetThreadSanitizer,
84 "Generate Dart code compatible with Thread Sanitizer");
85#if defined(TARGET_USES_MEMORY_SANITIZER)
86constexpr bool kDefaultTargetMemorySanitizer =
true;
88constexpr bool kDefaultTargetMemorySanitizer =
false;
91 target_memory_sanitizer,
92 kDefaultTargetMemorySanitizer,
93 "Generate Dart code compatible with Memory Sanitizer");
96bool Flags::initialized_ =
false;
99Flag** Flags::flags_ =
nullptr;
100intptr_t Flags::capacity_ = 0;
101intptr_t Flags::num_flags_ = 0;
190 for (intptr_t
i = 0;
i < num_flags_;
i++) {
192 if (strcmp(
flag->name_,
name) == 0) {
202 (
flag->bool_ptr_ !=
nullptr) && (*
flag->bool_ptr_ ==
true);
207 initialized_ =
false;
210void Flags::AddFlag(Flag*
flag) {
212 if (num_flags_ == capacity_) {
213 if (flags_ ==
nullptr) {
215 flags_ =
new Flag*[capacity_];
217 intptr_t new_capacity = capacity_ * 2;
218 Flag** new_flags =
new Flag*[new_capacity];
219 for (intptr_t
i = 0;
i < num_flags_;
i++) {
220 new_flags[
i] = flags_[
i];
224 capacity_ = new_capacity;
227 flags_[num_flags_++] =
flag;
233 const char* comment) {
235 if (
flag !=
nullptr) {
237 return default_value;
241 return default_value;
247 const char* comment) {
253 return default_value;
258 uint64_t default_value,
259 const char* comment) {
265 return default_value;
270 const char* default_value,
271 const char* comment) {
275 return default_value;
280 const char* comment) {
282 Flag*
flag =
new Flag(
name, comment, handler);
289 const char* comment) {
291 Flag*
flag =
new Flag(
name, comment, handler);
297 intptr_t
len = strlen(
s);
298 for (intptr_t
i = 0;
i <
len;
i++) {
305bool Flags::SetFlagFromString(Flag*
flag,
const char* argument) {
307 switch (
flag->type_) {
309 if (strcmp(argument,
"true") == 0) {
310 *
flag->bool_ptr_ =
true;
311 }
else if (strcmp(argument,
"false") == 0) {
312 *
flag->bool_ptr_ =
false;
319 flag->string_value_.reset(argument ==
nullptr ?
nullptr
321 *
flag->charp_ptr_ =
flag->string_value_.get();
325 char* endptr =
nullptr;
326 const intptr_t
len = strlen(argument);
328 if ((
len > 2) && (argument[0] ==
'0') && (argument[1] ==
'x')) {
331 int val = strtol(argument, &endptr,
base);
332 if (endptr == argument +
len) {
333 *
flag->int_ptr_ = val;
340 char* endptr =
nullptr;
341 const intptr_t
len = strlen(argument);
343 if ((
len > 2) && (argument[0] ==
'0') && (argument[1] ==
'x')) {
346 int64_t val = strtoll(argument, &endptr,
base);
347 if (endptr == argument +
len) {
348 *
flag->uint64_ptr_ =
static_cast<uint64_t
>(val);
355 if (strcmp(argument,
"true") == 0) {
356 (
flag->flag_handler_)(
true);
357 }
else if (strcmp(argument,
"false") == 0) {
358 (
flag->flag_handler_)(
false);
367 (
flag->option_handler_)(argument);
375 flag->changed_ =
true;
379void Flags::Parse(
const char* option) {
381 const char*
equals = option;
386 const char* argument =
nullptr;
392 const char*
const kNo1Prefix =
"no_";
393 const char*
const kNo2Prefix =
"no-";
394 const intptr_t kNo1PrefixLen = strlen(kNo1Prefix);
395 const intptr_t kNo2PrefixLen = strlen(kNo2Prefix);
396 if (strncmp(option, kNo1Prefix, kNo1PrefixLen) == 0) {
397 option += kNo1PrefixLen;
399 }
else if (strncmp(option, kNo2Prefix, kNo2PrefixLen) == 0) {
400 option += kNo2PrefixLen;
411 intptr_t name_len =
equals - option;
412 char*
name =
new char[name_len + 1];
413 strncpy(
name, option, name_len);
414 name[name_len] =
'\0';
418 if (
flag ==
nullptr) {
420 char* new_flag =
new char[name_len + 1];
421 strncpy(new_flag, option, name_len);
422 new_flag[name_len] =
'\0';
428 if (!
flag->IsUnrecognized()) {
429 if (!SetFlagFromString(
flag, argument)) {
430 OS::PrintErr(
"Ignoring flag: %s is an invalid value for flag %s\n",
441 intptr_t prefix_length) {
442 intptr_t name_length = strlen(
name);
443 return ((name_length > prefix_length) &&
447int Flags::CompareFlagNames(
const void* left,
const void* right) {
448 const Flag* left_flag = *
reinterpret_cast<const Flag* const*
>(left);
449 const Flag* right_flag = *
reinterpret_cast<const Flag* const*
>(right);
450 return strcmp(left_flag->name_, right_flag->name_);
454 const char** vm_flags) {
459 qsort(flags_, num_flags_,
sizeof flags_[0], CompareFlagNames);
461 const char*
const kPrefix =
"--";
462 const intptr_t kPrefixLen = strlen(kPrefix);
465 while ((
i < number_of_vm_flags) &&
467 const char* option = vm_flags[
i] + kPrefixLen;
472 if (!FLAG_ignore_unrecognized_flags) {
473 int unrecognized_count = 0;
474 TextBuffer
error(64);
475 for (intptr_t j = 0; j < num_flags_; j++) {
476 Flag*
flag = flags_[j];
477 if (
flag->IsUnrecognized()) {
478 if (unrecognized_count == 0) {
479 error.Printf(
"Unrecognized flags: %s",
flag->name_);
483 unrecognized_count++;
486 if (unrecognized_count > 0) {
487 return error.Steal();
490 if (FLAG_print_flags) {
500 if (
flag ==
nullptr) {
501 *
error =
"Cannot set flag: flag not found";
505 *
error =
"Cannot set flag: invalid value";
511void Flags::PrintFlags() {
513 for (intptr_t
i = 0;
i < num_flags_; ++
i) {
519void Flags::PrintFlagToJSONArray(JSONArray* jsarr,
const Flag*
flag) {
520 if (
flag->IsUnrecognized()) {
523 JSONObject jsflag(jsarr);
524 jsflag.AddProperty(
"name",
flag->name_);
525 jsflag.AddProperty(
"comment",
flag->comment_);
526 jsflag.AddProperty(
"modified",
flag->changed_);
527 switch (
flag->type_) {
529 jsflag.AddProperty(
"_flagType",
"Bool");
530 jsflag.AddProperty(
"valueAsString",
531 (*
flag->bool_ptr_ ?
"true" :
"false"));
535 jsflag.AddProperty(
"_flagType",
"Int");
536 jsflag.AddPropertyF(
"valueAsString",
"%d", *
flag->int_ptr_);
540 jsflag.AddProperty(
"_flagType",
"UInt64");
541 jsflag.AddPropertyF(
"valueAsString",
"%" Pu64, *
flag->uint64_ptr_);
545 jsflag.AddProperty(
"_flagType",
"String");
546 if (
flag->charp_ptr_ !=
nullptr) {
547 jsflag.AddPropertyF(
"valueAsString",
"%s", *
flag->charp_ptr_);
554 jsflag.AddProperty(
"_flagType",
"Bool");
555 const char*
value =
flag->string_value_.get();
556 jsflag.AddProperty(
"valueAsString",
value ==
nullptr ?
"false" :
value);
560 jsflag.AddProperty(
"_flagType",
"String");
561 if (
flag->string_value_ !=
nullptr) {
562 jsflag.AddProperty(
"valueAsString",
flag->string_value_.get());
575 JSONObject jsobj(
js);
576 jsobj.AddProperty(
"type",
"FlagList");
577 JSONArray jsarr(&jsobj,
"flags");
578 for (intptr_t
i = 0;
i < num_flags_; ++
i) {
579 PrintFlagToJSONArray(&jsarr, flags_[
i]);
bool equals(SkDrawable *a, SkDrawable *b)
FlagHandler flag_handler_
CStringUniquePtr string_value_
Flag(const char *name, const char *comment, OptionHandler handler)
Flag(const char *name, const char *comment, void *addr, FlagType type)
OptionHandler option_handler_
bool IsUnrecognized() const
Flag(const char *name, const char *comment, FlagHandler handler)
static bool IsSet(const char *name)
static char * ProcessCommandLineFlags(int argc, const char **argv)
static uint64_t Register_uint64_t(uint64_t *addr, const char *name, uint64_t default_value, const char *comment)
static bool Register_bool(bool *addr, const char *name, bool default_value, const char *comment)
static const char * Register_charp(charp *addr, const char *name, const char *default_value, const char *comment)
static bool SetFlag(const char *name, const char *value, const char **error)
static bool RegisterFlagHandler(FlagHandler handler, const char *name, const char *comment)
static int Register_int(int *addr, const char *name, int default_value, const char *comment)
static bool RegisterOptionHandler(OptionHandler handler, const char *name, const char *comment)
static void PrintJSON(JSONStream *js)
static Flag * Lookup(const char *name)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
FlutterSemanticsFlag flag
const uint8_t uint32_t uint32_t GError ** error
#define DEBUG_FLAG_MACRO(name, type, default_value, comment)
#define PRECOMPILE_FLAG_MACRO(name, pre_value, product_value, type, default_value, comment)
#define RELEASE_FLAG_MACRO(name, product_value, type, default_value, comment)
#define PRODUCT_FLAG_MACRO(name, type, default_value, comment)
void(* FlagHandler)(bool value)
void(* OptionHandler)(const char *value)
FLAG_LIST(PRODUCT_FLAG_MACRO, RELEASE_FLAG_MACRO, PRECOMPILE_FLAG_MACRO, DEBUG_FLAG_MACRO) const expr bool FLAG_target_thread_sanitizer
static void Normalize(char *s)
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")
static bool IsValidFlag(const char *name, const char *prefix, intptr_t prefix_length)