2017-02-14 04:47:05 +00:00
|
|
|
//===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
|
2016-04-06 20:59:11 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-04-06 20:59:11 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-02-14 04:47:05 +00:00
|
|
|
#ifndef LLD_ELF_SCRIPT_LEXER_H
|
|
|
|
#define LLD_ELF_SCRIPT_LEXER_H
|
2016-04-06 20:59:11 +00:00
|
|
|
|
2017-10-02 21:00:41 +00:00
|
|
|
#include "lld/Common/LLVM.h"
|
2016-04-06 20:59:11 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-11-21 15:49:56 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2016-06-03 16:57:13 +00:00
|
|
|
#include <utility>
|
2016-04-06 21:33:18 +00:00
|
|
|
#include <vector>
|
2016-04-06 20:59:11 +00:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
|
|
|
|
2017-02-14 04:47:05 +00:00
|
|
|
class ScriptLexer {
|
2016-04-06 20:59:11 +00:00
|
|
|
public:
|
2017-02-14 04:47:05 +00:00
|
|
|
explicit ScriptLexer(MemoryBufferRef mb);
|
2016-04-06 20:59:11 +00:00
|
|
|
|
|
|
|
void setError(const Twine &msg);
|
2016-11-21 15:49:56 +00:00
|
|
|
void tokenize(MemoryBufferRef mb);
|
2020-07-22 12:48:16 +03:00
|
|
|
StringRef skipSpace(StringRef s);
|
2016-04-06 20:59:11 +00:00
|
|
|
bool atEOF();
|
|
|
|
StringRef next();
|
2017-03-09 19:23:00 +00:00
|
|
|
StringRef peek();
|
2018-08-28 08:39:21 +00:00
|
|
|
StringRef peek2();
|
2016-10-17 06:21:13 +00:00
|
|
|
void skip();
|
2016-10-17 16:01:53 +00:00
|
|
|
bool consume(StringRef tok);
|
2016-04-06 20:59:11 +00:00
|
|
|
void expect(StringRef expect);
|
2017-03-09 19:23:00 +00:00
|
|
|
bool consumeLabel(StringRef tok);
|
2016-12-01 04:36:49 +00:00
|
|
|
std::string getCurrentLocation();
|
2016-04-06 20:59:11 +00:00
|
|
|
|
2016-11-21 15:49:56 +00:00
|
|
|
std::vector<MemoryBufferRef> mbs;
|
2016-04-06 20:59:11 +00:00
|
|
|
std::vector<StringRef> tokens;
|
2017-02-15 19:58:17 +00:00
|
|
|
bool inExpr = false;
|
2016-04-06 20:59:11 +00:00
|
|
|
size_t pos = 0;
|
2016-11-21 15:49:56 +00:00
|
|
|
|
2021-06-22 15:35:23 -07:00
|
|
|
size_t lastLineNumber = 0;
|
|
|
|
size_t lastLineNumberOffset = 0;
|
|
|
|
|
2020-04-08 21:45:21 -07:00
|
|
|
protected:
|
|
|
|
MemoryBufferRef getCurrentMB();
|
|
|
|
|
2016-11-21 15:49:56 +00:00
|
|
|
private:
|
2017-02-15 19:58:17 +00:00
|
|
|
void maybeSplitExpr();
|
2016-12-01 04:36:49 +00:00
|
|
|
StringRef getLine();
|
|
|
|
size_t getLineNumber();
|
|
|
|
size_t getColumnNumber();
|
2016-04-06 20:59:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|