Home | History | Annotate | Download | only in Interpreter
      1 //===-- OptionValueRegex.cpp ------------------------------------*- 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 #include "lldb/Interpreter/OptionValueRegex.h"
     11 
     12 // C Includes
     13 // C++ Includes
     14 // Other libraries and framework includes
     15 // Project includes
     16 #include "lldb/Core/Stream.h"
     17 
     18 using namespace lldb;
     19 using namespace lldb_private;
     20 
     21 void
     22 OptionValueRegex::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
     23 {
     24     if (dump_mask & eDumpOptionType)
     25         strm.Printf ("(%s)", GetTypeAsCString ());
     26     if (dump_mask & eDumpOptionValue)
     27     {
     28         if (dump_mask & eDumpOptionType)
     29             strm.PutCString (" = ");
     30         if (m_regex.IsValid())
     31         {
     32             const char *regex_text = m_regex.GetText();
     33             if (regex_text && regex_text[0])
     34                 strm.Printf ("%s", regex_text);
     35         }
     36         else
     37         {
     38 
     39         }
     40     }
     41 }
     42 
     43 Error
     44 OptionValueRegex::SetValueFromCString (const char *value_cstr,
     45                                         VarSetOperationType op)
     46 {
     47     Error error;
     48     switch (op)
     49     {
     50     case eVarSetOperationInvalid:
     51     case eVarSetOperationInsertBefore:
     52     case eVarSetOperationInsertAfter:
     53     case eVarSetOperationRemove:
     54     case eVarSetOperationAppend:
     55         error = OptionValue::SetValueFromCString (value_cstr, op);
     56         break;
     57 
     58     case eVarSetOperationClear:
     59         Clear();
     60         break;
     61 
     62     case eVarSetOperationReplace:
     63     case eVarSetOperationAssign:
     64         if (m_regex.Compile (value_cstr, m_regex.GetCompileFlags()))
     65         {
     66             m_value_was_set = true;
     67         }
     68         else
     69         {
     70             char regex_error[1024];
     71             if (m_regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
     72                 error.SetErrorString (regex_error);
     73             else
     74                 error.SetErrorStringWithFormat ("regex error %u", m_regex.GetErrorCode());
     75         }
     76         break;
     77     }
     78     return error;
     79 }
     80 
     81 
     82 lldb::OptionValueSP
     83 OptionValueRegex::DeepCopy () const
     84 {
     85     return OptionValueSP(new OptionValueRegex(m_regex.GetText(), m_regex.GetCompileFlags()));
     86 }
     87