1 //===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLD_ELF_SCRIPT_LEXER_H
10 #define LLD_ELF_SCRIPT_LEXER_H
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/MemoryBufferRef.h"
24 // The remaining content to parse and the filename.
25 StringRef s
, filename
;
26 const char *begin
= nullptr;
27 size_t lineNumber
= 1;
28 // True if the script is opened as an absolute path under the --sysroot
30 bool isUnderSysroot
= false;
33 Buffer(MemoryBufferRef mb
);
35 // The current buffer and parent buffers due to INCLUDE.
37 SmallVector
<Buffer
, 0> buffers
;
39 // Used to detect INCLUDE() cycles.
40 llvm::DenseSet
<StringRef
> activeFilenames
;
44 explicit operator bool() const { return !str
.empty(); }
45 operator StringRef() const { return str
; }
48 // The token before the last next().
50 // Rules for what is a token are different when we are in an expression.
51 // curTok holds the cached return value of peek() and is invalid when the
52 // expression state changes.
54 size_t prevTokLine
= 1;
55 // The inExpr state when curTok is cached.
56 bool curTokState
= false;
60 explicit ScriptLexer(MemoryBufferRef mb
);
62 void setError(const Twine
&msg
);
64 StringRef
skipSpace(StringRef s
);
69 bool consume(StringRef tok
);
70 void expect(StringRef expect
);
71 Token
till(StringRef tok
);
72 std::string
getCurrentLocation();
73 MemoryBufferRef
getCurrentMB();
75 std::vector
<MemoryBufferRef
> mbs
;
80 size_t getColumnNumber();
83 } // namespace lld::elf