xref: /freebsd/contrib/llvm-project/lld/ELF/ScriptLexer.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 //===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_ELF_SCRIPT_LEXER_H
10 #define LLD_ELF_SCRIPT_LEXER_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/MemoryBuffer.h"
15 #include <utility>
16 #include <vector>
17 
18 namespace lld {
19 namespace elf {
20 
21 class ScriptLexer {
22 public:
23   explicit ScriptLexer(MemoryBufferRef mb);
24 
25   void setError(const Twine &msg);
26   void tokenize(MemoryBufferRef mb);
27   static StringRef skipSpace(StringRef s);
28   bool atEOF();
29   StringRef next();
30   StringRef peek();
31   StringRef peek2();
32   void skip();
33   bool consume(StringRef tok);
34   void expect(StringRef expect);
35   bool consumeLabel(StringRef tok);
36   std::string getCurrentLocation();
37 
38   std::vector<MemoryBufferRef> mbs;
39   std::vector<StringRef> tokens;
40   bool inExpr = false;
41   size_t pos = 0;
42 
43 protected:
44   MemoryBufferRef getCurrentMB();
45 
46 private:
47   void maybeSplitExpr();
48   StringRef getLine();
49   size_t getLineNumber();
50   size_t getColumnNumber();
51 };
52 
53 } // namespace elf
54 } // namespace lld
55 
56 #endif
57