Abstract the details from regex.h a bit more by not allowing people to specify compil...
authorGreg Clayton <gclayton@apple.com>
Wed, 21 Jan 2015 21:51:02 +0000 (21:51 +0000)
committerGreg Clayton <gclayton@apple.com>
Wed, 21 Jan 2015 21:51:02 +0000 (21:51 +0000)
Since REG_ENHANCED is available on MacOSX, this allow the use of \d (digits) \b (word boundaries) and much more without affecting other systems.

<rdar://problem/12082562>

llvm-svn: 226704

lldb/include/lldb/Core/RegularExpression.h
lldb/include/lldb/Interpreter/OptionValueRegex.h
lldb/source/Core/RegularExpression.cpp
lldb/source/Host/common/FileSpec.cpp
lldb/source/Interpreter/CommandObjectRegexCommand.cpp
lldb/source/Interpreter/OptionValueRegex.cpp
lldb/source/Interpreter/Property.cpp
lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
lldb/source/Target/Thread.cpp

index 00d8310..a58d17b 100644 (file)
@@ -121,23 +121,6 @@ public:
     //------------------------------------------------------------------
     RegularExpression ();
 
-    //------------------------------------------------------------------
-    /// Constructor that takes a regular expression with flags.
-    ///
-    /// Constructor that compiles \a re using \a flags and stores the
-    /// resulting compiled regular expression into this object.
-    ///
-    /// @param[in] re
-    ///     A c string that represents the regular expression to
-    ///     compile.
-    ///
-    /// @param[in] flags
-    ///     Flags that are passed to the \c regcomp() function.
-    //------------------------------------------------------------------
-    explicit
-    RegularExpression (const char* re, int flags);
-
-    // This one uses flags = REG_EXTENDED.
     explicit
     RegularExpression (const char* re);
 
@@ -157,7 +140,7 @@ public:
     /// Compile a regular expression.
     ///
     /// Compile a regular expression using the supplied regular
-    /// expression text and flags. The compiled regular expression lives
+    /// expression text. The compiled regular expression lives
     /// in this object so that it can be readily used for regular
     /// expression matches. Execute() can be called after the regular
     /// expression is compiled. Any previously compiled regular
@@ -167,9 +150,6 @@ public:
     ///     A NULL terminated C string that represents the regular
     ///     expression to compile.
     ///
-    /// @param[in] flags
-    ///     Flags that are passed to the \c regcomp() function.
-    ///
     /// @return
     ///     \b true if the regular expression compiles successfully,
     ///     \b false otherwise.
@@ -177,9 +157,6 @@ public:
     bool
     Compile (const char* re);
 
-    bool
-    Compile (const char* re, int flags);
-
     //------------------------------------------------------------------
     /// Executes a regular expression.
     ///
@@ -187,8 +164,7 @@ public:
     /// expression that is already in this object against the match
     /// string \a s. If any parens are used for regular expression
     /// matches \a match_count should indicate the number of regmatch_t
-    /// values that are present in \a match_ptr. The regular expression
-    /// will be executed using the \a execute_flags
+    /// values that are present in \a match_ptr.
     ///
     /// @param[in] string
     ///     The string to match against the compile regular expression.
@@ -198,15 +174,12 @@ public:
     ///     properly initialized with the desired number of maximum
     ///     matches, or NULL if no parenthesized matching is needed.
     ///
-    /// @param[in] execute_flags
-    ///     Flags to pass to the \c regexec() function.
-    ///
     /// @return
     ///     \b true if \a string matches the compiled regular
     ///     expression, \b false otherwise.
     //------------------------------------------------------------------
     bool
-    Execute (const char* string, Match *match = NULL, int execute_flags = 0) const;
+    Execute (const char* string, Match *match = NULL) const;
 
     size_t
     GetErrorAsCString (char *err_str, size_t err_str_max_len) const;
@@ -233,12 +206,6 @@ public:
     const char*
     GetText () const;
     
-    int
-    GetCompileFlags () const
-    {
-        return m_compile_flags;
-    }
-
     //------------------------------------------------------------------
     /// Test if valid.
     ///
@@ -256,7 +223,6 @@ public:
     {
         Free();
         m_re.clear();
-        m_compile_flags = 0;
         m_comp_err = 1;
     }
     
@@ -276,7 +242,6 @@ private:
     std::string m_re;   ///< A copy of the original regular expression text
     int m_comp_err;     ///< Error code for the regular expression compilation
     regex_t m_preg;     ///< The compiled regular expression
-    int     m_compile_flags; ///< Stores the flags from the last compile.
 };
 
 } // namespace lldb_private
index bb8c458..295bb98 100644 (file)
@@ -24,9 +24,9 @@ namespace lldb_private {
 class OptionValueRegex : public OptionValue
 {
 public:
-    OptionValueRegex (const char *value = NULL, uint32_t regex_flags = 0) :
+    OptionValueRegex (const char *value = NULL) :
         OptionValue(),
-        m_regex (value, regex_flags)
+        m_regex (value)
     {
     }
 
@@ -75,10 +75,10 @@ public:
     }
     
     void
-    SetCurrentValue (const char *value, uint32_t regex_flags)
+    SetCurrentValue (const char *value)
     {
         if (value && value[0])
-            m_regex.Compile (value, regex_flags);
+            m_regex.Compile (value);
         else
             m_regex.Clear();
     }
index 54924d0..3f712e1 100644 (file)
@@ -7,36 +7,34 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <string.h>
 #include "lldb/Core/RegularExpression.h"
 #include "llvm/ADT/StringRef.h"
-#include <string.h>
+#include "lldb/Core/Error.h"
 
-using namespace lldb_private;
 
 //----------------------------------------------------------------------
-// Default constructor
+// Enable enhanced mode if it is available. This allows for things like
+// \d for digit, \s for space, and many more, but it isn't available
+// everywhere.
 //----------------------------------------------------------------------
-RegularExpression::RegularExpression() :
-    m_re(),
-    m_comp_err (1),
-    m_preg(),
-    m_compile_flags(REG_EXTENDED)
-{
-    memset(&m_preg,0,sizeof(m_preg));
-}
+#if defined(REG_ENHANCED)
+#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED|REG_EXTENDED)
+#else
+#define DEFAULT_COMPILE_FLAGS (REG_EXTENDED)
+#endif
+
+using namespace lldb_private;
 
 //----------------------------------------------------------------------
-// Constructor that compiles "re" using "flags" and stores the
-// resulting compiled regular expression into this object.
+// Default constructor
 //----------------------------------------------------------------------
-RegularExpression::RegularExpression(const char* re, int flags) :
+RegularExpression::RegularExpression() :
     m_re(),
     m_comp_err (1),
-    m_preg(),
-    m_compile_flags(flags)
+    m_preg()
 {
     memset(&m_preg,0,sizeof(m_preg));
-    Compile(re);
 }
 
 //----------------------------------------------------------------------
@@ -46,8 +44,7 @@ RegularExpression::RegularExpression(const char* re, int flags) :
 RegularExpression::RegularExpression(const char* re) :
     m_re(),
     m_comp_err (1),
-    m_preg(),
-    m_compile_flags(REG_EXTENDED)
+    m_preg()
 {
     memset(&m_preg,0,sizeof(m_preg));
     Compile(re);
@@ -56,16 +53,14 @@ RegularExpression::RegularExpression(const char* re) :
 RegularExpression::RegularExpression(const RegularExpression &rhs)
 {
     memset(&m_preg,0,sizeof(m_preg));
-    Compile(rhs.GetText(), rhs.GetCompileFlags());
+    Compile(rhs.GetText());
 }
 
 const RegularExpression &
 RegularExpression::operator= (const RegularExpression &rhs)
 {
     if (&rhs != this)
-    {
-        Compile (rhs.GetText(), rhs.GetCompileFlags());
-    }
+        Compile (rhs.GetText());
     return *this;
 }
 //----------------------------------------------------------------------
@@ -94,19 +89,12 @@ RegularExpression::~RegularExpression()
 bool
 RegularExpression::Compile(const char* re)
 {
-    return Compile (re, m_compile_flags);
-}
-
-bool
-RegularExpression::Compile(const char* re, int flags)
-{
     Free();
-    m_compile_flags = flags;
     
     if (re && re[0])
     {
         m_re = re;
-        m_comp_err = ::regcomp (&m_preg, re, flags);
+        m_comp_err = ::regcomp (&m_preg, re, DEFAULT_COMPILE_FLAGS);
     }
     else
     {
@@ -126,7 +114,7 @@ RegularExpression::Compile(const char* re, int flags)
 // will be executed using the "execute_flags".
 //---------------------------------------------------------------------
 bool
-RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
+RegularExpression::Execute (const char* s, Match *match) const
 {
     int err = 1;
     if (s != NULL && m_comp_err == 0)
@@ -137,7 +125,7 @@ RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
                              s,
                              match->GetSize(),
                              match->GetData(),
-                             execute_flags);
+                             0);
         }
         else
         {
@@ -145,7 +133,7 @@ RegularExpression::Execute(const char* s, Match *match, int execute_flags) const
                              s,
                              0,
                              NULL,
-                             execute_flags);
+                             0);
         }
     }
     
index 98b4bef..ca50aac 100644 (file)
@@ -1330,8 +1330,7 @@ FileSpec::IsSourceImplementationFile () const
     ConstString extension (GetFileNameExtension());
     if (extension)
     {
-        static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$",
-                                                      REG_EXTENDED | REG_ICASE);
+        static RegularExpression g_source_file_regex ("^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])$");
         return g_source_file_regex.Execute (extension.GetCString());
     }
     return false;
index efc7c33..bde7f58 100644 (file)
@@ -111,7 +111,7 @@ CommandObjectRegexCommand::AddRegexCommand (const char *re_cstr, const char *com
 {
     m_entries.resize(m_entries.size() + 1);
     // Only add the regular expression if it compiles
-    if (m_entries.back().regex.Compile (re_cstr, REG_EXTENDED))
+    if (m_entries.back().regex.Compile (re_cstr))
     {
         m_entries.back().command.assign (command_cstr);
         return true;
index f51cf02..fab462f 100644 (file)
@@ -62,7 +62,7 @@ OptionValueRegex::SetValueFromCString (const char *value_cstr,
 
     case eVarSetOperationReplace:
     case eVarSetOperationAssign:
-        if (m_regex.Compile (value_cstr, m_regex.GetCompileFlags()))
+        if (m_regex.Compile (value_cstr))
         {
             m_value_was_set = true;
             NotifyValueChanged();
@@ -84,5 +84,5 @@ OptionValueRegex::SetValueFromCString (const char *value_cstr,
 lldb::OptionValueSP
 OptionValueRegex::DeepCopy () const
 {
-    return OptionValueSP(new OptionValueRegex(m_regex.GetText(), m_regex.GetCompileFlags()));
+    return OptionValueSP(new OptionValueRegex(m_regex.GetText()));
 }
index 36976b8..7fcc9d2 100644 (file)
@@ -129,7 +129,7 @@ Property::Property (const PropertyDefinition &definition) :
             // "definition.default_uint_value" is used to the regular expression flags
             // "definition.default_cstr_value" the default regular expression value
             // value.
-            m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value, definition.default_uint_value));
+            m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value));
             break;
             
         case OptionValue::eTypeSInt64:
index 9af0da3..2f90122 100644 (file)
@@ -371,7 +371,7 @@ public:
                 }
             }
 
-            static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
+            static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?");
 
             RegularExpression::Match matches(3);
 
index b532d8d..d87a39e 100644 (file)
@@ -66,8 +66,8 @@ g_properties[] =
     { "step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, step-in will not stop in functions with no debug information." },
     { "step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, when step-in/step-out/step-over leave the current frame, they will continue to step out till they come to a function with "
                                                                                     "debug information.  Passing a frame argument to step-out will override this option." },
-    { "step-avoid-regexp",  OptionValue::eTypeRegex  , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
-    { "step-avoid-libraries",  OptionValue::eTypeFileSpecList  , true , REG_EXTENDED, NULL, NULL, "A list of libraries that source stepping won't stop in." },
+    { "step-avoid-regexp",  OptionValue::eTypeRegex  , true , 0, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
+    { "step-avoid-libraries",  OptionValue::eTypeFileSpecList  , true , 0, NULL, NULL, "A list of libraries that source stepping won't stop in." },
     { "trace-thread",       OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." },
     {  NULL               , OptionValue::eTypeInvalid, false, 0    , NULL, NULL, NULL  }
 };