diff options
| author | Greg Clayton <gclayton@apple.com> | 2015-01-21 21:51:02 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2015-01-21 21:51:02 +0000 |
| commit | 7bd4c60043d995d21ced0cdf0d6c67b8ce015177 (patch) | |
| tree | e2e9bfedae8ba337cf29e02a96c89c6cd7453b57 /lldb/source | |
| parent | 24a777238ee9849a05dcb2aa230ad92cb2287e22 (diff) | |
| download | bcm5719-llvm-7bd4c60043d995d21ced0cdf0d6c67b8ce015177.tar.gz bcm5719-llvm-7bd4c60043d995d21ced0cdf0d6c67b8ce015177.zip | |
Abstract the details from regex.h a bit more by not allowing people to specify compile and execute flags for regular expressions. Also enable better regular expressions if they are available by check if the REG_ENHANCED is available and using it if it is.
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
Diffstat (limited to 'lldb/source')
| -rw-r--r-- | lldb/source/Core/RegularExpression.cpp | 56 | ||||
| -rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 3 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandObjectRegexCommand.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Interpreter/OptionValueRegex.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Interpreter/Property.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Target/Thread.cpp | 4 |
7 files changed, 30 insertions, 43 deletions
diff --git a/lldb/source/Core/RegularExpression.cpp b/lldb/source/Core/RegularExpression.cpp index 54924d06953..3f712e1b2da 100644 --- a/lldb/source/Core/RegularExpression.cpp +++ b/lldb/source/Core/RegularExpression.cpp @@ -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); } } diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 98b4beffe28..ca50aac9d6e 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -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; diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index efc7c33fa8f..bde7f58b4cb 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -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; diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp index f51cf02edf5..fab462f0e70 100644 --- a/lldb/source/Interpreter/OptionValueRegex.cpp +++ b/lldb/source/Interpreter/OptionValueRegex.cpp @@ -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())); } diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index 36976b889da..7fcc9d2d96e 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/lldb/source/Interpreter/Property.cpp @@ -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: diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp index 9af0da3fe86..2f9012222c0 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -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); diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index b532d8d71c8..d87a39ed430 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -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 } }; |

