The linker script lexer is context-sensitive. In the regular context, arithmetic operator characters are regular characters, but in the expression context, they are independent tokens. This afects how the lexer tokenizes "3*4", for example. (This kind of expression is real; the Linux kernel uses it.) This patch defines function `maybeSplitExpr`. This function splits the current token into multiple expression tokens if the lexer is in the expression context. Differential Revision: https://reviews.llvm.org/D29963 llvm-svn: 295225
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
//===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Linker
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_ELF_SCRIPT_LEXER_H
|
|
#define LLD_ELF_SCRIPT_LEXER_H
|
|
|
|
#include "lld/Core/LLVM.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace lld {
|
|
namespace elf {
|
|
|
|
class ScriptLexer {
|
|
public:
|
|
explicit ScriptLexer(MemoryBufferRef MB);
|
|
|
|
void setError(const Twine &Msg);
|
|
void tokenize(MemoryBufferRef MB);
|
|
static StringRef skipSpace(StringRef S);
|
|
bool atEOF();
|
|
StringRef next();
|
|
StringRef peek(unsigned N = 0);
|
|
void skip();
|
|
bool consume(StringRef Tok);
|
|
void expect(StringRef Expect);
|
|
std::string getCurrentLocation();
|
|
|
|
std::vector<MemoryBufferRef> MBs;
|
|
std::vector<StringRef> Tokens;
|
|
bool InExpr = false;
|
|
size_t Pos = 0;
|
|
bool Error = false;
|
|
|
|
private:
|
|
void maybeSplitExpr();
|
|
StringRef getLine();
|
|
size_t getLineNumber();
|
|
size_t getColumnNumber();
|
|
|
|
MemoryBufferRef getCurrentMB();
|
|
};
|
|
|
|
} // namespace elf
|
|
} // namespace lld
|
|
|
|
#endif
|