1 //===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLD_ELF_SCRIPT_LEXER_H
11 #define LLD_ELF_SCRIPT_LEXER_H
12 
13 #include "lld/Common/LLVM.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/MemoryBuffer.h"
16 #include <utility>
17 #include <vector>
18 
19 namespace lld {
20 namespace elf {
21 
22 class ScriptLexer {
23 public:
24   explicit ScriptLexer(MemoryBufferRef MB);
25 
26   void setError(const Twine &Msg);
27   void tokenize(MemoryBufferRef MB);
28   static StringRef skipSpace(StringRef S);
29   bool atEOF();
30   StringRef next();
31   StringRef peek();
32   StringRef peek2();
33   void skip();
34   bool consume(StringRef Tok);
35   void expect(StringRef Expect);
36   bool consumeLabel(StringRef Tok);
37   std::string getCurrentLocation();
38 
39   std::vector<MemoryBufferRef> MBs;
40   std::vector<StringRef> Tokens;
41   bool InExpr = false;
42   size_t Pos = 0;
43 
44 private:
45   void maybeSplitExpr();
46   StringRef getLine();
47   size_t getLineNumber();
48   size_t getColumnNumber();
49 
50   MemoryBufferRef getCurrentMB();
51 };
52 
53 } // namespace elf
54 } // namespace lld
55 
56 #endif
57