blob: dab68c3aabcb8f0f942850cd7f49bd335e3a96a1 [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;
Chris Lattnera8058742007-11-18 02:57:27 +000043public:
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
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000053 void PrintError(const char *Loc, const std::string &Msg) const;
Chris Lattnera8058742007-11-18 02:57:27 +000054
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000055 std::ostream &err() const;
56 void PrintIncludeStack(std::ostream &OS) const;
57
Chris Lattnera8058742007-11-18 02:57:27 +000058private:
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000059 int ReturnError(const char *Loc, const std::string &Msg);
60
Chris Lattnera8058742007-11-18 02:57:27 +000061 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