[Lldb-commits] [lldb] r221640 - Cleaned up the StringLexer a little bit. It turns

Sean Callanan scallanan at apple.com
Mon Nov 10 15:20:52 PST 2014


Author: spyffe
Date: Mon Nov 10 17:20:52 2014
New Revision: 221640

URL: http://llvm.org/viewvc/llvm-project?rev=221640&view=rev
Log:
Cleaned up the StringLexer a little bit.  It turns
out we only want to roll back text that was in the
buffer to begin with, so it's not necessary to
provide a pushback stack.

I'm going to use this slightly cleaner API to perform
lookahead for the Objective-C runtime type parser.

Modified:
    lldb/trunk/include/lldb/Utility/StringLexer.h
    lldb/trunk/source/Utility/StringLexer.cpp

Modified: lldb/trunk/include/lldb/Utility/StringLexer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StringLexer.h?rev=221640&r1=221639&r2=221640&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/StringLexer.h (original)
+++ lldb/trunk/include/lldb/Utility/StringLexer.h Mon Nov 10 17:20:52 2014
@@ -27,6 +27,7 @@ public:
     
     StringLexer (const StringLexer& rhs);
     
+    // These APIs are not bounds-checked.  Use HasAtLeast() if you're not sure.
     Character
     Peek ();
     
@@ -42,8 +43,9 @@ public:
     bool
     HasAny (Character c);
     
+    // This will assert if there are less than s characters preceding the cursor.
     void
-    PutBack (Character c);
+    PutBack (Size s);
     
     StringLexer&
     operator = (const StringLexer& rhs);
@@ -51,7 +53,6 @@ public:
 private:
     std::string m_data;
     Position m_position;
-    std::list<Character> m_putback_data;
     
     void
     Consume();

Modified: lldb/trunk/source/Utility/StringLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringLexer.cpp?rev=221640&r1=221639&r2=221640&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringLexer.cpp (original)
+++ lldb/trunk/source/Utility/StringLexer.cpp Mon Nov 10 17:20:52 2014
@@ -10,28 +10,24 @@
 #include "lldb/Utility/StringLexer.h"
 
 #include <algorithm>
+#include <assert.h>
 
 using namespace lldb_utility;
 
 StringLexer::StringLexer (std::string s) :
-m_data(s),
-m_position(0),
-m_putback_data()
+    m_data(s),
+    m_position(0)
 { }
 
 StringLexer::StringLexer (const StringLexer& rhs) :
-m_data(rhs.m_data),
-m_position(rhs.m_position),
-m_putback_data(rhs.m_putback_data)
+    m_data(rhs.m_data),
+    m_position(rhs.m_position)
 { }
 
 StringLexer::Character
 StringLexer::Peek ()
 {
-    if (m_putback_data.empty())
-        return m_data[m_position];
-    else
-        return m_putback_data.front();
+    return m_data[m_position];
 }
 
 bool
@@ -57,35 +53,26 @@ StringLexer::Next ()
 bool
 StringLexer::HasAtLeast (Size s)
 {
-    auto in_m_data = m_data.size()-m_position;
-    auto in_putback = m_putback_data.size();
-    return (in_m_data + in_putback >= s);
+    return (m_data.size() - m_position) >= s;
 }
 
-
 void
-StringLexer::PutBack (Character c)
+StringLexer::PutBack (Size s)
 {
-    m_putback_data.push_back(c);
+    assert (m_position >= s);
+    m_position -= s;
 }
 
 bool
 StringLexer::HasAny (Character c)
 {
-    const auto begin(m_putback_data.begin());
-    const auto end(m_putback_data.end());
-    if (std::find(begin, end, c) != end)
-        return true;
     return m_data.find(c, m_position) != std::string::npos;
 }
 
 void
 StringLexer::Consume()
 {
-    if (m_putback_data.empty())
-        m_position++;
-    else
-        m_putback_data.pop_front();
+    m_position++;
 }
 
 StringLexer&
@@ -95,7 +82,6 @@ StringLexer::operator = (const StringLex
     {
         m_data = rhs.m_data;
         m_position = rhs.m_position;
-        m_putback_data = rhs.m_putback_data;
     }
     return *this;
 }





More information about the lldb-commits mailing list