Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
dart::bin::OptionProcessor Class Referenceabstract

#include <options.h>

Inheritance diagram for dart::bin::OptionProcessor:
dart::bin::CallbackOptionProcessor

Public Member Functions

 OptionProcessor ()
 
virtual ~OptionProcessor ()
 
virtual bool Process (const char *option, CommandLineOptions *options)=0
 

Static Public Member Functions

static bool IsValidFlag (const char *name)
 
static bool IsValidShortFlag (const char *name)
 
static bool TryProcess (const char *option, CommandLineOptions *options)
 
static const char * ProcessOption (const char *option, const char *name)
 
static bool ProcessEnvironmentOption (const char *arg, CommandLineOptions *vm_options, dart::SimpleHashMap **environment)
 

Detailed Description

Definition at line 19 of file options.h.

Constructor & Destructor Documentation

◆ OptionProcessor()

dart::bin::OptionProcessor::OptionProcessor ( )
inline

Definition at line 21 of file options.h.

21: next_(first_) { first_ = this; }

◆ ~OptionProcessor()

virtual dart::bin::OptionProcessor::~OptionProcessor ( )
inlinevirtual

Definition at line 23 of file options.h.

23{}

Member Function Documentation

◆ IsValidFlag()

bool dart::bin::OptionProcessor::IsValidFlag ( const char *  name)
static

Definition at line 12 of file options.cc.

12 {
13 return name[0] == '-' && name[1] == '-' && name[2] != '\0';
14}
const char *const name

◆ IsValidShortFlag()

bool dart::bin::OptionProcessor::IsValidShortFlag ( const char *  name)
static

Definition at line 16 of file options.cc.

16 {
17 return name[0] == '-' && name[1] != '\0';
18}

◆ Process()

virtual bool dart::bin::OptionProcessor::Process ( const char *  option,
CommandLineOptions options 
)
pure virtual

◆ ProcessEnvironmentOption()

bool dart::bin::OptionProcessor::ProcessEnvironmentOption ( const char *  arg,
CommandLineOptions vm_options,
dart::SimpleHashMap **  environment 
)
static

Definition at line 54 of file options.cc.

57 {
58 ASSERT(arg != nullptr);
59 ASSERT(environment != nullptr);
60 const char* kShortPrefix = "-D";
61 const char* kLongPrefix = "--define=";
62 const int kShortPrefixLen = strlen(kShortPrefix);
63 const int kLongPrefixLen = strlen(kLongPrefix);
64 const bool is_short_form = IsPrefix(kShortPrefix, kShortPrefixLen, arg);
65 const bool is_long_form = IsPrefix(kLongPrefix, kLongPrefixLen, arg);
66 if (is_short_form) {
67 arg = arg + kShortPrefixLen;
68 } else if (is_long_form) {
69 arg = arg + kLongPrefixLen;
70 } else {
71 return false;
72 }
73 if (*arg == '\0') {
74 return true;
75 }
76 if (*environment == nullptr) {
77 *environment = new SimpleHashMap(&SimpleHashMap::SameStringValue, 4);
78 }
79 // Split the name=value part of the -Dname=value argument.
80 char* name;
81 char* value = nullptr;
82 const char* equals_pos = strchr(arg, '=');
83 if (equals_pos == nullptr) {
84 // No equal sign (name without value) currently not supported.
85 if (is_short_form) {
86 Syslog::PrintErr("No value given to -D option\n");
87 } else {
88 Syslog::PrintErr("No value given to --define option\n");
89 }
90 return true;
91 }
92 int name_len = equals_pos - arg;
93 if (name_len == 0) {
94 if (is_short_form) {
95 Syslog::PrintErr("No name given to -D option\n");
96 } else {
97 Syslog::PrintErr("No name given to --define option\n");
98 }
99 return true;
100 }
101 // Split name=value into name and value.
102 name = reinterpret_cast<char*>(malloc(name_len + 1));
103 strncpy(name, arg, name_len);
104 name[name_len] = '\0';
105 value = Utils::StrDup(equals_pos + 1);
106 SimpleHashMap::Entry* entry =
107 (*environment)
110 ASSERT(entry != nullptr); // Lookup adds an entry if key not found.
111 if (entry->value != nullptr) {
112 free(name);
113 free(entry->value);
114 }
115 entry->value = value;
116 return true;
117}
static bool SameStringValue(void *key1, void *key2)
Definition: hashmap.h:41
static uint32_t StringHash(const char *key)
Definition: hashmap.h:26
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
#define ASSERT(E)
uint8_t value
static void * GetHashmapKeyFromString(char *key)
Definition: dartutils.h:38
static bool IsPrefix(const char *prefix, size_t prefix_len, const char *str)
Definition: options.cc:44
static dart::SimpleHashMap * environment
Definition: gen_snapshot.cc:59
void * malloc(size_t size)
Definition: allocation.cc:19

◆ ProcessOption()

const char * dart::bin::OptionProcessor::ProcessOption ( const char *  option,
const char *  name 
)
static

Definition at line 20 of file options.cc.

21 {
22 const intptr_t length = strlen(name);
23 for (intptr_t i = 0; i < length; i++) {
24 if (option[i] != name[i]) {
25 if ((name[i] == '_') && (option[i] == '-')) {
26 continue;
27 }
28 return nullptr;
29 }
30 }
31 return option + length;
32}
size_t length

◆ TryProcess()

bool dart::bin::OptionProcessor::TryProcess ( const char *  option,
CommandLineOptions options 
)
static

Definition at line 34 of file options.cc.

35 {
36 for (OptionProcessor* p = first_; p != nullptr; p = p->next_) {
37 if (p->Process(option, vm_options)) {
38 return true;
39 }
40 }
41 return false;
42}

The documentation for this class was generated from the following files: