• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_FLAGS_FLAGS_H_
6 #define V8_FLAGS_FLAGS_H_
7 
8 #include "src/common/globals.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // Declare all of our flags.
14 #define FLAG_MODE_DECLARE
15 #include "src/flags/flag-definitions.h"
16 
17 // The global list of all flags.
18 class V8_EXPORT_PRIVATE FlagList {
19  public:
20   class HelpOptions {
21    public:
22     enum ExitBehavior : bool { kExit = true, kDontExit = false };
23 
24     explicit HelpOptions(ExitBehavior exit_behavior = kExit,
25                          const char* usage = nullptr)
exit_behavior_(exit_behavior)26         : exit_behavior_(exit_behavior), usage_(usage) {}
27 
ShouldExit()28     bool ShouldExit() { return exit_behavior_ == kExit; }
HasUsage()29     bool HasUsage() { return usage_ != nullptr; }
usage()30     const char* usage() { return usage_; }
31 
32    private:
33     ExitBehavior exit_behavior_;
34     const char* usage_;
35   };
36 
37   // Set the flag values by parsing the command line. If remove_flags is
38   // set, the recognized flags and associated values are removed from (argc,
39   // argv) and only unknown arguments remain. Returns 0 if no error occurred.
40   // Otherwise, returns the argv index > 0 for the argument where an error
41   // occurred. In that case, (argc, argv) will remain unchanged independent of
42   // the remove_flags value, and no assumptions about flag settings should be
43   // made. If exit_behavior is set to Exit and --help has been specified on the
44   // command line, then the usage string will be printed, if it was specified,
45   // followed by the help flag and then the process will exit. Otherwise the
46   // flag help will be displayed but execution will continue.
47   //
48   // The following syntax for flags is accepted (both '-' and '--' are ok):
49   //
50   //   --flag        (bool flags only)
51   //   --no-flag     (bool flags only)
52   //   --flag=value  (non-bool flags only, no spaces around '=')
53   //   --flag value  (non-bool flags only)
54   //   --            (capture all remaining args in JavaScript)
55   static int SetFlagsFromCommandLine(
56       int* argc, char** argv, bool remove_flags,
57       FlagList::HelpOptions help_options = FlagList::HelpOptions());
58 
59   // Set the flag values by parsing the string str. Splits string into argc
60   // substrings argv[], each of which consisting of non-white-space chars,
61   // and then calls SetFlagsFromCommandLine() and returns its result.
62   static int SetFlagsFromString(const char* str, size_t len);
63 
64   // Reset all flags to their default value.
65   static void ResetAllFlags();
66 
67   // Print help to stdout with flags, types, and default values.
68   static void PrintHelp();
69 
70   static void PrintValues();
71 
72   // Set flags as consequence of being implied by another flag.
73   static void EnforceFlagImplications();
74 
75   // Hash of flags (to quickly determine mismatching flag expectations).
76   // This hash is calculated during V8::Initialize and cached.
77   static uint32_t Hash();
78 };
79 
80 }  // namespace internal
81 }  // namespace v8
82 
83 #endif  // V8_FLAGS_FLAGS_H_
84