use escape string.
[oota-llvm.git] / utils / TableGen / TGLexer.h
index 2c5a852fcd48af0cdb0ef7ed5a5efe48525d5926..245dd4146158d3af683cb8c20bb0c8ad795afde9 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef TGLEXER_H
 #define TGLEXER_H
 
+#include "llvm/Support/DataTypes.h"
 #include <vector>
 #include <string>
 #include <iosfwd>
@@ -21,6 +22,8 @@
 
 namespace llvm {
 class MemoryBuffer;
+class TGSourceMgr;
+class TGLoc;
   
 namespace tgtok {
   enum TokKind {
@@ -54,33 +57,27 @@ namespace tgtok {
 
 /// TGLexer - TableGen Lexer class.
 class TGLexer {
+  TGSourceMgr &SrcMgr;
+  
   const char *CurPtr;
-  unsigned CurLineNo;
-  MemoryBuffer *CurBuf;
+  const MemoryBuffer *CurBuf;
 
   // Information about the current token.
   const char *TokStart;
   tgtok::TokKind CurCode;
   std::string CurStrVal;  // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
   int64_t CurIntVal;      // This is valid for INTVAL.
-  
-  /// IncludeRec / IncludeStack - This captures the current set of include
-  /// directives we are nested within.
-  struct IncludeRec {
-    MemoryBuffer *Buffer;
-    const char *CurPtr;
-    unsigned LineNo;
-    IncludeRec(MemoryBuffer *buffer, const char *curPtr, unsigned lineNo)
-      : Buffer(buffer), CurPtr(curPtr), LineNo(lineNo) {}
-  };
-  std::vector<IncludeRec> IncludeStack;
+
+  /// CurBuffer - This is the current buffer index we're lexing from as managed
+  /// by the SourceMgr object.
+  int CurBuffer;
   
   // IncludeDirectories - This is the list of directories we should search for
   // include files in.
   std::vector<std::string> IncludeDirectories;
 public:
-  TGLexer(MemoryBuffer *StartBuf);
-  ~TGLexer();
+  TGLexer(TGSourceMgr &SrcMgr);
+  ~TGLexer() {}
   
   void setIncludeDirs(const std::vector<std::string> &Dirs) {
     IncludeDirectories = Dirs;
@@ -103,12 +100,10 @@ public:
     return CurIntVal;
   }
 
-  typedef const char* LocTy;
-  LocTy getLoc() const { return TokStart; }
+  TGLoc getLoc() const;
 
-  void PrintError(LocTy Loc, const std::string &Msg) const;
-  
-  void PrintIncludeStack(std::ostream &OS) const;
+  void PrintError(const char *Loc, const std::string &Msg) const;
+  void PrintError(TGLoc Loc, const std::string &Msg) const;
   
 private:
   /// LexToken - Read the next token and return its code.