| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flags.h" | 5 #include "vm/flags.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 DEFINE_FLAG(bool, print_flags, false, "Print flags as they are being parsed."); | 12 DEFINE_FLAG(bool, print_flags, false, "Print flags as they are being parsed."); |
| 13 DEFINE_FLAG(bool, ignore_unrecognized_flags, false, | 13 DEFINE_FLAG(bool, ignore_unrecognized_flags, false, |
| 14 "Ignore unrecognized flags."); | 14 "Ignore unrecognized flags."); |
| 15 | 15 |
| 16 // List of registered flags. | 16 // List of registered flags. |
| 17 Flag* Flags::flags_ = NULL; | 17 Flag* Flags::flags_ = NULL; |
| 18 | 18 |
| 19 bool Flags::initialized_ = false; |
| 20 |
| 19 class Flag { | 21 class Flag { |
| 20 public: | 22 public: |
| 21 enum Type { | 23 enum Type { |
| 22 kBoolean, | 24 kBoolean, |
| 23 kInteger, | 25 kInteger, |
| 24 kString, | 26 kString, |
| 25 kNumFlagTypes | 27 kNumFlagTypes |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 Flag(const char* name, const char* comment, void* addr, Type type) | 30 Flag(const char* name, const char* comment, void* addr, Type type) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 220 |
| 219 static bool IsValidFlag(const char* name, | 221 static bool IsValidFlag(const char* name, |
| 220 const char* prefix, | 222 const char* prefix, |
| 221 intptr_t prefix_length) { | 223 intptr_t prefix_length) { |
| 222 intptr_t name_length = strlen(name); | 224 intptr_t name_length = strlen(name); |
| 223 return ((name_length > prefix_length) && | 225 return ((name_length > prefix_length) && |
| 224 (strncmp(name, prefix, prefix_length) == 0)); | 226 (strncmp(name, prefix, prefix_length) == 0)); |
| 225 } | 227 } |
| 226 | 228 |
| 227 | 229 |
| 228 void Flags::ProcessCommandLineFlags(int number_of_vm_flags, | 230 bool Flags::ProcessCommandLineFlags(int number_of_vm_flags, |
| 229 const char** vm_flags) { | 231 const char** vm_flags) { |
| 232 if (initialized_) { |
| 233 return false; |
| 234 } |
| 235 |
| 236 initialized_ = true; |
| 237 |
| 230 const char* kPrefix = "--"; | 238 const char* kPrefix = "--"; |
| 231 const intptr_t kPrefixLen = strlen(kPrefix); | 239 const intptr_t kPrefixLen = strlen(kPrefix); |
| 232 | 240 |
| 233 int i = 0; | 241 int i = 0; |
| 234 while ((i < number_of_vm_flags) && | 242 while ((i < number_of_vm_flags) && |
| 235 IsValidFlag(vm_flags[i], kPrefix, kPrefixLen)) { | 243 IsValidFlag(vm_flags[i], kPrefix, kPrefixLen)) { |
| 236 const char* option = vm_flags[i] + kPrefixLen; | 244 const char* option = vm_flags[i] + kPrefixLen; |
| 237 Parse(option); | 245 Parse(option); |
| 238 i++; | 246 i++; |
| 239 } | 247 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 258 } | 266 } |
| 259 } | 267 } |
| 260 if (FLAG_print_flags) { | 268 if (FLAG_print_flags) { |
| 261 OS::Print("Flag settings:\n"); | 269 OS::Print("Flag settings:\n"); |
| 262 Flag* flag = Flags::flags_; | 270 Flag* flag = Flags::flags_; |
| 263 while (flag != NULL) { | 271 while (flag != NULL) { |
| 264 flag->Print(); | 272 flag->Print(); |
| 265 flag = flag->next_; | 273 flag = flag->next_; |
| 266 } | 274 } |
| 267 } | 275 } |
| 276 |
| 277 return true; |
| 268 } | 278 } |
| 269 | 279 |
| 270 } // namespace dart | 280 } // namespace dart |
| OLD | NEW |