[Lldb-commits] [lldb] r215133 - Add a StringLexer utility class that can be used when you have string data that needs to be parsed - I don't think such a general purpose facility is part of LLVM, and I am going to need this, so just add it to lldb_utility
Enrico Granata
egranata at apple.com
Thu Aug 7 12:22:15 PDT 2014
Author: enrico
Date: Thu Aug 7 14:22:14 2014
New Revision: 215133
URL: http://llvm.org/viewvc/llvm-project?rev=215133&view=rev
Log:
Add a StringLexer utility class that can be used when you have string data that needs to be parsed - I don't think such a general purpose facility is part of LLVM, and I am going to need this, so just add it to lldb_utility
Added:
lldb/trunk/include/lldb/Utility/StringLexer.h
lldb/trunk/source/Utility/StringLexer.cpp
Modified:
lldb/trunk/lldb.xcodeproj/project.pbxproj
Added: lldb/trunk/include/lldb/Utility/StringLexer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StringLexer.h?rev=215133&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Utility/StringLexer.h (added)
+++ lldb/trunk/include/lldb/Utility/StringLexer.h Thu Aug 7 14:22:14 2014
@@ -0,0 +1,62 @@
+//===--------------------- StringLexer.h -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef utility_StringLexer_h_
+#define utility_StringLexer_h_
+
+#include <string>
+#include <list>
+
+namespace lldb_utility {
+
+class StringLexer
+{
+public:
+ typedef std::string::size_type Position;
+ typedef std::string::size_type Size;
+
+ typedef std::string::value_type Character;
+
+ StringLexer (std::string s);
+
+ StringLexer (const StringLexer& rhs);
+
+ Character
+ Peek ();
+
+ bool
+ NextIf (Character c);
+
+ Character
+ Next ();
+
+ bool
+ HasAtLeast (Size s);
+
+ bool
+ HasAny (Character c);
+
+ void
+ PutBack (Character c);
+
+ StringLexer&
+ operator = (const StringLexer& rhs);
+
+private:
+ std::string m_data;
+ Position m_position;
+ std::list<Character> m_putback_data;
+
+ void
+ Consume();
+};
+
+} // namespace lldb_private
+
+#endif // #ifndef utility_StringLexer_h_
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=215133&r1=215132&r2=215133&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Aug 7 14:22:14 2014
@@ -617,6 +617,7 @@
941BCC8014E48C4000BB969C /* SBTypeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568714E355F2003A195C /* SBTypeFormat.h */; settings = {ATTRIBUTES = (Public, ); }; };
941BCC8114E48C4000BB969C /* SBTypeSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568814E355F2003A195C /* SBTypeSummary.h */; settings = {ATTRIBUTES = (Public, ); }; };
941BCC8214E48C4000BB969C /* SBTypeSynthetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568914E355F2003A195C /* SBTypeSynthetic.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 94380B8219940B0A00BFE4A8 /* StringLexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */; };
944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */; };
944372DD171F6B4300E57C32 /* RegisterContextDummy.h in Headers */ = {isa = PBXBuildFile; fileRef = 944372DB171F6B4300E57C32 /* RegisterContextDummy.h */; };
9443B122140C18C40013457C /* SBData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };
@@ -1841,6 +1842,8 @@
94094C68163B6CCC0083A547 /* ValueObjectCast.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValueObjectCast.h; path = include/lldb/Core/ValueObjectCast.h; sourceTree = "<group>"; };
94094C69163B6CD90083A547 /* ValueObjectCast.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ValueObjectCast.cpp; path = source/Core/ValueObjectCast.cpp; sourceTree = "<group>"; };
94145430175D7FDE00284436 /* lldb-versioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "lldb-versioning.h"; path = "include/lldb/lldb-versioning.h"; sourceTree = "<group>"; };
+ 94380B8019940B0300BFE4A8 /* StringLexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StringLexer.h; path = include/lldb/Utility/StringLexer.h; sourceTree = "<group>"; };
+ 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringLexer.cpp; path = source/Utility/StringLexer.cpp; sourceTree = "<group>"; };
944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterContextDummy.cpp; path = Utility/RegisterContextDummy.cpp; sourceTree = "<group>"; };
944372DB171F6B4300E57C32 /* RegisterContextDummy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterContextDummy.h; path = Utility/RegisterContextDummy.h; sourceTree = "<group>"; };
9443B120140C18A90013457C /* SBData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path = include/lldb/API/SBData.h; sourceTree = "<group>"; };
@@ -2821,6 +2824,8 @@
2660D9F611922A1300958FBD /* StringExtractor.cpp */,
2676A094119C93C8008A98EF /* StringExtractorGDBRemote.h */,
2676A093119C93C8008A98EF /* StringExtractorGDBRemote.cpp */,
+ 94380B8019940B0300BFE4A8 /* StringLexer.h */,
+ 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */,
26D1804616CEE12C00EDFB5B /* TimeSpecTimeout.h */,
26D1804016CEDF0700EDFB5B /* TimeSpecTimeout.cpp */,
94EBAC8313D9EE26009BA64E /* PythonPointer.h */,
@@ -4851,6 +4856,7 @@
268900C113353E5F00698AC0 /* DWARFDebugPubnames.cpp in Sources */,
268900C213353E5F00698AC0 /* DWARFDebugPubnamesSet.cpp in Sources */,
268900C313353E5F00698AC0 /* DWARFDebugRanges.cpp in Sources */,
+ 94380B8219940B0A00BFE4A8 /* StringLexer.cpp in Sources */,
268900C413353E5F00698AC0 /* DWARFDefines.cpp in Sources */,
94D0B10C16D5535900EA9C70 /* LibCxx.cpp in Sources */,
268900C513353E5F00698AC0 /* DWARFDIECollection.cpp in Sources */,
Added: lldb/trunk/source/Utility/StringLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringLexer.cpp?rev=215133&view=auto
==============================================================================
--- lldb/trunk/source/Utility/StringLexer.cpp (added)
+++ lldb/trunk/source/Utility/StringLexer.cpp Thu Aug 7 14:22:14 2014
@@ -0,0 +1,93 @@
+//===--------------------- StringLexer.cpp -----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Utility/StringLexer.h"
+
+using namespace lldb_utility;
+
+StringLexer::StringLexer (std::string s) :
+m_data(s),
+m_position(0),
+m_putback_data()
+{ }
+
+StringLexer::StringLexer (const StringLexer& rhs) :
+m_data(rhs.m_data),
+m_position(rhs.m_position),
+m_putback_data(rhs.m_putback_data)
+{ }
+
+StringLexer::Character
+StringLexer::Peek ()
+{
+ if (m_putback_data.empty())
+ return m_data[m_position];
+ else
+ return m_putback_data.front();
+}
+
+bool
+StringLexer::NextIf (Character c)
+{
+ auto val = Peek();
+ if (val == c)
+ {
+ Next();
+ return true;
+ }
+ return false;
+}
+
+StringLexer::Character
+StringLexer::Next ()
+{
+ auto val = Peek();
+ Consume();
+ return val;
+}
+
+bool
+StringLexer::HasAtLeast (Size s)
+{
+ return m_data.size()-m_position >= s;
+}
+
+
+void
+StringLexer::PutBack (Character c)
+{
+ m_putback_data.push_back(c);
+}
+
+bool
+StringLexer::HasAny (Character c)
+{
+ 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();
+}
+
+StringLexer&
+StringLexer::operator = (const StringLexer& rhs)
+{
+ if (this != &rhs)
+ {
+ 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