dab68c3aabcb8f0f942850cd7f49bd335e3a96a1
[oota-llvm.git] / utils / TableGen / TGLexer.h
1 //===- TGLexer.h - Lexer for TableGen Files ---------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class represents the Lexer for tablegen files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef TGLEXER_H
15 #define TGLEXER_H
16
17 #include <vector>
18 #include <string>
19 #include <iosfwd>
20
21 namespace llvm {
22 class MemoryBuffer;
23
24 class TGLexer {
25   const char *CurPtr;
26   unsigned CurLineNo;
27   MemoryBuffer *CurBuf;
28
29   /// IncludeRec / IncludeStack - This captures the current set of include
30   /// directives we are nested within.
31   struct IncludeRec {
32     MemoryBuffer *Buffer;
33     const char *CurPtr;
34     unsigned LineNo;
35     IncludeRec(MemoryBuffer *buffer, const char *curPtr, unsigned lineNo)
36       : Buffer(buffer), CurPtr(curPtr), LineNo(lineNo) {}
37   };
38   std::vector<IncludeRec> IncludeStack;
39   
40   // IncludeDirectories - This is the list of directories we should search for
41   // include files in.
42   std::vector<std::string> IncludeDirectories;
43 public:
44   TGLexer(MemoryBuffer *StartBuf);
45   ~TGLexer();
46   
47   void setIncludeDirs(const std::vector<std::string> &Dirs) {
48     IncludeDirectories = Dirs;
49   }
50   
51   int LexToken();
52
53   void PrintError(const char *Loc, const std::string &Msg) const;
54   
55   std::ostream &err() const;
56   void PrintIncludeStack(std::ostream &OS) const;
57   
58 private:
59   int ReturnError(const char *Loc, const std::string &Msg);
60   
61   int getNextChar();
62   void SkipBCPLComment();
63   bool SkipCComment();
64   int LexIdentifier();
65   bool LexInclude();
66   int LexString();
67   int LexVarName();
68   int LexNumber();
69   int LexBracket();
70   int LexExclaim();
71 };
72   
73 } // end namespace llvm
74
75 #endif