mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-17 00:10:28 +00:00
Removed a couple of static helpers in the data formatters, replaced with new general logic in StringLexer
llvm-svn: 222058
This commit is contained in:
parent
603d316517
commit
e65a28f36f
@ -39,6 +39,8 @@
|
||||
#include "lldb/Target/StackFrame.h"
|
||||
#include "lldb/Target/TargetList.h"
|
||||
|
||||
#include "lldb/Utility/StringLexer.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
// this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization
|
||||
@ -59,18 +61,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
static inline bool
|
||||
IsWhitespace (char c)
|
||||
{
|
||||
return ( (c == ' ') || (c == '\t') || (c == '\v') || (c == '\f') );
|
||||
}
|
||||
|
||||
static inline bool
|
||||
HasPrefix (const char* str1, const char* str2)
|
||||
{
|
||||
return ( ::strstr(str1, str2) == str1 );
|
||||
}
|
||||
|
||||
// if the user tries to add formatters for, say, "struct Foo"
|
||||
// those will not match any type because of the way we strip qualifiers from typenames
|
||||
// this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
|
||||
@ -78,32 +68,23 @@ HasPrefix (const char* str1, const char* str2)
|
||||
static inline ConstString
|
||||
GetValidTypeName_Impl (const ConstString& type)
|
||||
{
|
||||
int strip_len = 0;
|
||||
|
||||
if ((bool)type == false)
|
||||
if (type.IsEmpty())
|
||||
return type;
|
||||
|
||||
const char* type_cstr = type.AsCString();
|
||||
std::string type_cstr(type.AsCString());
|
||||
lldb_utility::StringLexer type_lexer(type_cstr);
|
||||
|
||||
if ( HasPrefix(type_cstr, "class ") )
|
||||
strip_len = 6;
|
||||
else if ( HasPrefix(type_cstr, "enum ") )
|
||||
strip_len = 5;
|
||||
else if ( HasPrefix(type_cstr, "struct ") )
|
||||
strip_len = 7;
|
||||
else if ( HasPrefix(type_cstr, "union ") )
|
||||
strip_len = 6;
|
||||
type_lexer.AdvanceIf("class ");
|
||||
type_lexer.AdvanceIf("enum ");
|
||||
type_lexer.AdvanceIf("struct ");
|
||||
type_lexer.AdvanceIf("union ");
|
||||
|
||||
if (strip_len == 0)
|
||||
return type;
|
||||
|
||||
type_cstr += strip_len;
|
||||
while (IsWhitespace(*type_cstr) && ++type_cstr)
|
||||
while (type_lexer.NextIf({' ','\t','\v','\f'}).first)
|
||||
;
|
||||
|
||||
return ConstString(type_cstr);
|
||||
return ConstString(type_lexer.GetUnlexed());
|
||||
}
|
||||
|
||||
|
||||
template<typename KeyType, typename ValueType>
|
||||
class FormattersContainer;
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
#ifndef utility_StringLexer_h_
|
||||
#define utility_StringLexer_h_
|
||||
|
||||
#include <string>
|
||||
#include <initializer_list>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace lldb_utility {
|
||||
|
||||
@ -34,6 +35,12 @@ public:
|
||||
bool
|
||||
NextIf (Character c);
|
||||
|
||||
std::pair<bool, Character>
|
||||
NextIf (std::initializer_list<Character> cs);
|
||||
|
||||
bool
|
||||
AdvanceIf (const std::string& token);
|
||||
|
||||
Character
|
||||
Next ();
|
||||
|
||||
@ -43,6 +50,9 @@ public:
|
||||
bool
|
||||
HasAny (Character c);
|
||||
|
||||
std::string
|
||||
GetUnlexed ();
|
||||
|
||||
// This will assert if there are less than s characters preceding the cursor.
|
||||
void
|
||||
PutBack (Size s);
|
||||
|
@ -42,6 +42,42 @@ StringLexer::NextIf (Character c)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::pair<bool, StringLexer::Character>
|
||||
StringLexer::NextIf (std::initializer_list<Character> cs)
|
||||
{
|
||||
auto val = Peek();
|
||||
for (auto c : cs)
|
||||
{
|
||||
if (val == c)
|
||||
{
|
||||
Next();
|
||||
return {true,c};
|
||||
}
|
||||
}
|
||||
return {false,0};
|
||||
}
|
||||
|
||||
bool
|
||||
StringLexer::AdvanceIf (const std::string& token)
|
||||
{
|
||||
auto pos = m_position;
|
||||
bool matches = true;
|
||||
for (auto c : token)
|
||||
{
|
||||
if (!NextIf(c))
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matches)
|
||||
{
|
||||
m_position = pos;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StringLexer::Character
|
||||
StringLexer::Next ()
|
||||
{
|
||||
@ -69,6 +105,12 @@ StringLexer::HasAny (Character c)
|
||||
return m_data.find(c, m_position) != std::string::npos;
|
||||
}
|
||||
|
||||
std::string
|
||||
StringLexer::GetUnlexed ()
|
||||
{
|
||||
return std::string(m_data, m_position);
|
||||
}
|
||||
|
||||
void
|
||||
StringLexer::Consume()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user