blob: ef786b6f28bcb58741f616daa4a479a60e94021c [file] [log] [blame]
Chris Lattner53e7a272007-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 Lattner8e769982007-11-19 07:43:52 +000043 const char *TokStart;
Chris Lattner53e7a272007-11-18 02:57:27 +000044public:
45 TGLexer(MemoryBuffer *StartBuf);
46 ~TGLexer();
47
48 void setIncludeDirs(const std::vector<std::string> &Dirs) {
49 IncludeDirectories = Dirs;
50 }
51
52 int LexToken();
53
Chris Lattner8e769982007-11-19 07:43:52 +000054 typedef const char* LocationTy;
55 LocationTy getTokenStart() const { return TokStart; }
56
57 void PrintError(LocationTy Loc, const std::string &Msg) const;
Chris Lattner53e7a272007-11-18 02:57:27 +000058
Chris Lattnerce975c92007-11-19 07:38:58 +000059 std::ostream &err() const;
60 void PrintIncludeStack(std::ostream &OS) const;
61
Chris Lattner53e7a272007-11-18 02:57:27 +000062private:
Chris Lattnerce975c92007-11-19 07:38:58 +000063 int ReturnError(const char *Loc, const std::string &Msg);
64
Chris Lattner53e7a272007-11-18 02:57:27 +000065 int getNextChar();
66 void SkipBCPLComment();
67 bool SkipCComment();
68 int LexIdentifier();
69 bool LexInclude();
70 int LexString();
71 int LexVarName();
72 int LexNumber();
73 int LexBracket();
74 int LexExclaim();
75};
76
77} // end namespace llvm
78
79#endif