summaryrefslogtreecommitdiff
path: root/utils/TableGen/TGLexer.h
blob: dab68c3aabcb8f0f942850cd7f49bd335e3a96a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//===- TGLexer.h - Lexer for TableGen Files ---------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class represents the Lexer for tablegen files.
//
//===----------------------------------------------------------------------===//

#ifndef TGLEXER_H
#define TGLEXER_H

#include <vector>
#include <string>
#include <iosfwd>

namespace llvm {
class MemoryBuffer;

class TGLexer {
  const char *CurPtr;
  unsigned CurLineNo;
  MemoryBuffer *CurBuf;

  /// 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;
  
  // IncludeDirectories - This is the list of directories we should search for
  // include files in.
  std::vector<std::string> IncludeDirectories;
public:
  TGLexer(MemoryBuffer *StartBuf);
  ~TGLexer();
  
  void setIncludeDirs(const std::vector<std::string> &Dirs) {
    IncludeDirectories = Dirs;
  }
  
  int LexToken();

  void PrintError(const char *Loc, const std::string &Msg) const;
  
  std::ostream &err() const;
  void PrintIncludeStack(std::ostream &OS) const;
  
private:
  int ReturnError(const char *Loc, const std::string &Msg);
  
  int getNextChar();
  void SkipBCPLComment();
  bool SkipCComment();
  int LexIdentifier();
  bool LexInclude();
  int LexString();
  int LexVarName();
  int LexNumber();
  int LexBracket();
  int LexExclaim();
};
  
} // end namespace llvm

#endif