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"
25 // The remaining content to parse and the filename.
26 StringRef s
, filename
;
27 const char *begin
= nullptr;
28 size_t lineNumber
= 1;
29 // True if the script is opened as an absolute path under the --sysroot
31 bool isUnderSysroot
= false;
34 Buffer(Ctx
&ctx
, MemoryBufferRef mb
);
37 // The current buffer and parent buffers due to INCLUDE.
39 SmallVector
<Buffer
, 0> buffers
;
41 // Used to detect INCLUDE() cycles.
42 llvm::DenseSet
<StringRef
> activeFilenames
;
46 explicit operator bool() const { return !str
.empty(); }
47 operator StringRef() const { return str
; }
50 // The token before the last next().
52 // Rules for what is a token are different when we are in an expression.
53 // curTok holds the cached return value of peek() and is invalid when the
54 // expression state changes.
56 size_t prevTokLine
= 1;
57 // The inExpr state when curTok is cached.
58 bool curTokState
= false;
62 explicit ScriptLexer(Ctx
&ctx
, MemoryBufferRef mb
);
64 void setError(const Twine
&msg
);
66 StringRef
skipSpace(StringRef s
);
71 bool consume(StringRef tok
);
72 void expect(StringRef expect
);
73 Token
till(StringRef tok
);
74 std::string
getCurrentLocation();
75 MemoryBufferRef
getCurrentMB();
77 std::vector
<MemoryBufferRef
> mbs
;
82 size_t getColumnNumber();
85 } // namespace lld::elf