xref: /freebsd/contrib/llvm-project/lld/ELF/ScriptLexer.h (revision f126d349810fdb512c0b01e101342d430b947488)
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   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   size_t lastLineNumber = 0;
44   size_t lastLineNumberOffset = 0;
45 
46 protected:
47   MemoryBufferRef getCurrentMB();
48 
49 private:
50   void maybeSplitExpr();
51   StringRef getLine();
52   size_t getLineNumber();
53   size_t getColumnNumber();
54 };
55 
56 } // namespace elf
57 } // namespace lld
58 
59 #endif
60