mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:51:50 +00:00
8db11b79ac
Add vm support for setting flags through vm service (UI coming soon). e.g. http://127.0.0.1:8181/#/flags/set?name=some_flag&value=100 -- I reworked the Flags class to use a growing array rather than a linked list to store flags. This means that we don't need to go through the hassle of building an array and sorting every time that we print/printjson. R=johnmccutchan@google.com Review URL: https://codereview.chromium.org//299143007 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36712 260f80e4-7a28-3924-810f-c04153c831b5
108 lines
3.1 KiB
C++
108 lines
3.1 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef VM_FLAGS_H_
|
|
#define VM_FLAGS_H_
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/globals.h"
|
|
|
|
typedef const char* charp;
|
|
|
|
#define DECLARE_FLAG(type, name) \
|
|
extern type FLAG_##name
|
|
|
|
#define DEFINE_FLAG(type, name, default_value, comment) \
|
|
type FLAG_##name = Flags::Register_##type(&FLAG_##name, \
|
|
#name, \
|
|
default_value, \
|
|
comment)
|
|
|
|
#define DEFINE_FLAG_HANDLER(handler, name, comment) \
|
|
bool DUMMY_##name = Flags::Register_func(handler, #name, comment)
|
|
|
|
|
|
#if defined(DEBUG)
|
|
#define DECLARE_DEBUG_FLAG(type, name) DECLARE_FLAG(type, name)
|
|
#define DEFINE_DEBUG_FLAG(type, name, default_value, comment) \
|
|
DEFINE_FLAG(type, name, default_value, comment)
|
|
#else
|
|
#define DECLARE_DEBUG_FLAG(type, name)
|
|
#define DEFINE_DEBUG_FLAG(type, name, default_value, comment)
|
|
#endif
|
|
|
|
namespace dart {
|
|
|
|
typedef void (*FlagHandler)(bool value);
|
|
|
|
// Forward declarations.
|
|
class Flag;
|
|
class JSONArray;
|
|
class JSONStream;
|
|
|
|
class Flags {
|
|
public:
|
|
static bool Register_bool(bool* addr,
|
|
const char* name,
|
|
bool default_value,
|
|
const char* comment);
|
|
|
|
static int Register_int(int* addr,
|
|
const char* name,
|
|
int default_value,
|
|
const char* comment);
|
|
|
|
static const char* Register_charp(charp* addr,
|
|
const char* name,
|
|
const char* default_value,
|
|
const char* comment);
|
|
|
|
static bool Register_func(FlagHandler handler,
|
|
const char* name,
|
|
const char* comment);
|
|
|
|
static bool ProcessCommandLineFlags(int argc, const char** argv);
|
|
|
|
static Flag* Lookup(const char* name);
|
|
|
|
static bool IsSet(const char* name);
|
|
|
|
static bool Initialized() { return initialized_; }
|
|
|
|
static void PrintJSON(JSONStream* js);
|
|
|
|
static bool SetFlag(const char* name,
|
|
const char* value,
|
|
const char** error);
|
|
|
|
private:
|
|
static Flag** flags_;
|
|
static intptr_t capacity_;
|
|
static intptr_t num_flags_;
|
|
|
|
static bool initialized_;
|
|
|
|
static void AddFlag(Flag* flag);
|
|
|
|
static bool SetFlagFromString(Flag* flag, const char* argument);
|
|
|
|
static void Parse(const char* option);
|
|
|
|
static int CompareFlagNames(const void* left, const void* right);
|
|
|
|
static void PrintFlags();
|
|
|
|
static void PrintFlagToJSONArray(JSONArray* jsarr, const Flag* flag);
|
|
|
|
// Testing needs direct access to private methods.
|
|
friend void Dart_TestParseFlags();
|
|
|
|
DISALLOW_ALLOCATION();
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Flags);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // VM_FLAGS_H_
|