blob: 517b81a49612815e2bb38a337a437aa2e4be6b7c [file] [log] [blame]
Chris Lattnera8058742007-11-18 02:57:27 +00001//===- 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
21namespace llvm {
22class MemoryBuffer;
23
24class 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
44 std::string TheError;
45public:
46 TGLexer(MemoryBuffer *StartBuf);
47 ~TGLexer();
48
49 void setIncludeDirs(const std::vector<std::string> &Dirs) {
50 IncludeDirectories = Dirs;
51 }
52
53 int LexToken();
54
55 const std::string getError() const { return TheError; }
56
57 std::ostream &err();
58 void PrintIncludeStack(std::ostream &OS);
59private:
60 int getNextChar();
61 void SkipBCPLComment();
62 bool SkipCComment();
63 int LexIdentifier();
64 bool LexInclude();
65 int LexString();
66 int LexVarName();
67 int LexNumber();
68 int LexBracket();
69 int LexExclaim();
70};
71
72} // end namespace llvm
73
74#endif