1 //===-- OptionValue.h --------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_OptionValue_h_ 11 #define liblldb_OptionValue_h_ 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project includes 17 #include "lldb/lldb-defines.h" 18 #include "lldb/Core/ConstString.h" 19 #include "lldb/Core/Error.h" 20 21 namespace lldb_private { 22 23 //--------------------------------------------------------------------- 24 // OptionValue 25 //--------------------------------------------------------------------- 26 class OptionValue 27 { 28 public: 29 typedef enum { 30 eTypeInvalid = 0, 31 eTypeArch, 32 eTypeArgs, 33 eTypeArray, 34 eTypeBoolean, 35 eTypeDictionary, 36 eTypeEnum, 37 eTypeFileSpec, 38 eTypeFileSpecList, 39 eTypeFormat, 40 eTypePathMap, 41 eTypeProperties, 42 eTypeRegex, 43 eTypeSInt64, 44 eTypeString, 45 eTypeUInt64, 46 eTypeUUID 47 } Type; 48 49 enum { 50 eDumpOptionName = (1u << 0), 51 eDumpOptionType = (1u << 1), 52 eDumpOptionValue = (1u << 2), 53 eDumpOptionDescription = (1u << 3), 54 eDumpOptionRaw = (1u << 4), 55 eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue), 56 eDumpGroupHelp = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription) 57 }; 58 59 OptionValue()60 OptionValue () : 61 m_value_was_set (false) 62 { 63 } 64 OptionValue(const OptionValue & rhs)65 OptionValue (const OptionValue &rhs) : 66 m_value_was_set (rhs.m_value_was_set) 67 { 68 } 69 ~OptionValue()70 virtual ~OptionValue () 71 { 72 } 73 //----------------------------------------------------------------- 74 // Subclasses should override these functions 75 //----------------------------------------------------------------- 76 virtual Type 77 GetType () const = 0; 78 79 // If this value is always hidden, the avoid showing any info on this 80 // value, just show the info for the child values. 81 virtual bool ValueIsTransparent()82 ValueIsTransparent () const 83 { 84 return GetType() == eTypeProperties; 85 } 86 87 virtual const char * GetTypeAsCString()88 GetTypeAsCString () const 89 { 90 return GetBuiltinTypeAsCString(GetType()); 91 } 92 93 94 static const char * 95 GetBuiltinTypeAsCString (Type t); 96 97 virtual void 98 DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0; 99 100 virtual Error 101 SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign); 102 103 virtual bool 104 Clear () = 0; 105 106 virtual lldb::OptionValueSP 107 DeepCopy () const = 0; 108 109 virtual size_t 110 AutoComplete (CommandInterpreter &interpreter, 111 const char *s, 112 int match_start_point, 113 int max_return_elements, 114 bool &word_complete, 115 StringList &matches); 116 117 //----------------------------------------------------------------- 118 // Subclasses can override these functions 119 //----------------------------------------------------------------- 120 virtual lldb::OptionValueSP GetSubValue(const ExecutionContext * exe_ctx,const char * name,bool will_modify,Error & error)121 GetSubValue (const ExecutionContext *exe_ctx, 122 const char *name, 123 bool will_modify, 124 Error &error) const 125 { 126 error.SetErrorStringWithFormat("'%s' is not a value subvalue", name); 127 return lldb::OptionValueSP(); 128 } 129 130 virtual Error 131 SetSubValue (const ExecutionContext *exe_ctx, 132 VarSetOperationType op, 133 const char *name, 134 const char *value); 135 136 virtual bool IsAggregateValue()137 IsAggregateValue () const 138 { 139 return false; 140 } 141 142 virtual ConstString GetName()143 GetName() const 144 { 145 return ConstString(); 146 } 147 148 virtual bool 149 DumpQualifiedName (Stream &strm) const; 150 //----------------------------------------------------------------- 151 // Subclasses should NOT override these functions as they use the 152 // above functions to implement functionality 153 //----------------------------------------------------------------- 154 uint32_t GetTypeAsMask()155 GetTypeAsMask () 156 { 157 return 1u << GetType(); 158 } 159 160 static uint32_t ConvertTypeToMask(OptionValue::Type type)161 ConvertTypeToMask (OptionValue::Type type) 162 { 163 return 1u << type; 164 } 165 166 static OptionValue::Type ConvertTypeMaskToType(uint32_t type_mask)167 ConvertTypeMaskToType (uint32_t type_mask) 168 { 169 // If only one bit is set, then return an appropriate enumeration 170 switch (type_mask) 171 { 172 case 1u << eTypeArch: return eTypeArch; 173 case 1u << eTypeArgs: return eTypeArgs; 174 case 1u << eTypeArray: return eTypeArray; 175 case 1u << eTypeBoolean: return eTypeBoolean; 176 case 1u << eTypeDictionary: return eTypeDictionary; 177 case 1u << eTypeEnum: return eTypeEnum; 178 case 1u << eTypeFileSpec: return eTypeFileSpec; 179 case 1u << eTypeFileSpecList: return eTypeFileSpecList; 180 case 1u << eTypeFormat: return eTypeFormat; 181 case 1u << eTypePathMap: return eTypePathMap; 182 case 1u << eTypeProperties: return eTypeProperties; 183 case 1u << eTypeRegex: return eTypeRegex; 184 case 1u << eTypeSInt64: return eTypeSInt64; 185 case 1u << eTypeString: return eTypeString; 186 case 1u << eTypeUInt64: return eTypeUInt64; 187 case 1u << eTypeUUID: return eTypeUUID; 188 } 189 // Else return invalid 190 return eTypeInvalid; 191 } 192 193 static lldb::OptionValueSP 194 CreateValueFromCStringForTypeMask (const char *value_cstr, 195 uint32_t type_mask, 196 Error &error); 197 198 // Get this value as a uint64_t value if it is encoded as a boolean, 199 // uint64_t or int64_t. Other types will cause "fail_value" to be 200 // returned 201 uint64_t 202 GetUInt64Value (uint64_t fail_value, bool *success_ptr); 203 204 OptionValueArch * 205 GetAsArch (); 206 207 const OptionValueArch * 208 GetAsArch () const; 209 210 OptionValueArray * 211 GetAsArray (); 212 213 const OptionValueArray * 214 GetAsArray () const; 215 216 OptionValueArgs * 217 GetAsArgs (); 218 219 const OptionValueArgs * 220 GetAsArgs () const; 221 222 OptionValueBoolean * 223 GetAsBoolean (); 224 225 const OptionValueBoolean * 226 GetAsBoolean () const; 227 228 OptionValueDictionary * 229 GetAsDictionary (); 230 231 const OptionValueDictionary * 232 GetAsDictionary () const; 233 234 OptionValueEnumeration * 235 GetAsEnumeration (); 236 237 const OptionValueEnumeration * 238 GetAsEnumeration () const; 239 240 OptionValueFileSpec * 241 GetAsFileSpec (); 242 243 const OptionValueFileSpec * 244 GetAsFileSpec () const; 245 246 OptionValueFileSpecList * 247 GetAsFileSpecList (); 248 249 const OptionValueFileSpecList * 250 GetAsFileSpecList () const; 251 252 OptionValueFormat * 253 GetAsFormat (); 254 255 const OptionValueFormat * 256 GetAsFormat () const; 257 258 OptionValuePathMappings * 259 GetAsPathMappings (); 260 261 const OptionValuePathMappings * 262 GetAsPathMappings () const; 263 264 OptionValueProperties * 265 GetAsProperties (); 266 267 const OptionValueProperties * 268 GetAsProperties () const; 269 270 OptionValueRegex * 271 GetAsRegex (); 272 273 const OptionValueRegex * 274 GetAsRegex () const; 275 276 OptionValueSInt64 * 277 GetAsSInt64 (); 278 279 const OptionValueSInt64 * 280 GetAsSInt64 () const; 281 282 OptionValueString * 283 GetAsString (); 284 285 const OptionValueString * 286 GetAsString () const; 287 288 OptionValueUInt64 * 289 GetAsUInt64 (); 290 291 const OptionValueUInt64 * 292 GetAsUInt64 () const; 293 294 OptionValueUUID * 295 GetAsUUID (); 296 297 const OptionValueUUID * 298 GetAsUUID () const; 299 300 bool 301 GetBooleanValue (bool fail_value = false) const; 302 303 bool 304 SetBooleanValue (bool new_value); 305 306 int64_t 307 GetEnumerationValue (int64_t fail_value = -1) const; 308 309 bool 310 SetEnumerationValue (int64_t value); 311 312 FileSpec 313 GetFileSpecValue () const; 314 315 bool 316 SetFileSpecValue (const FileSpec &file_spec); 317 318 FileSpecList 319 GetFileSpecListValue () const; 320 321 lldb::Format 322 GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const; 323 324 bool 325 SetFormatValue (lldb::Format new_value); 326 327 const RegularExpression * 328 GetRegexValue () const; 329 330 int64_t 331 GetSInt64Value (int64_t fail_value = 0) const; 332 333 bool 334 SetSInt64Value (int64_t new_value); 335 336 const char * 337 GetStringValue (const char *fail_value = NULL) const; 338 339 bool 340 SetStringValue (const char *new_value); 341 342 uint64_t 343 GetUInt64Value (uint64_t fail_value = 0) const; 344 345 bool 346 SetUInt64Value (uint64_t new_value); 347 348 UUID 349 GetUUIDValue () const; 350 351 bool 352 SetUUIDValue (const UUID &uuid); 353 354 bool OptionWasSet()355 OptionWasSet () const 356 { 357 return m_value_was_set; 358 } 359 360 void SetOptionWasSet()361 SetOptionWasSet () 362 { 363 m_value_was_set = true; 364 } 365 366 void SetParent(const lldb::OptionValueSP & parent_sp)367 SetParent (const lldb::OptionValueSP &parent_sp) 368 { 369 m_parent_wp = parent_sp; 370 } 371 protected: 372 lldb::OptionValueWP m_parent_wp; 373 bool m_value_was_set; // This can be used to see if a value has been set 374 // by a call to SetValueFromCString(). It is often 375 // handy to know if an option value was set from 376 // the command line or as a setting, versus if we 377 // just have the default value that was already 378 // populated in the option value. 379 380 }; 381 382 } // namespace lldb_private 383 384 #endif // liblldb_OptionValue_h_ 385