1 //===- ScriptLexer.h --------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLD_ELF_SCRIPT_LEXER_H 11 #define LLD_ELF_SCRIPT_LEXER_H 12 13 #include "lld/Common/LLVM.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Support/MemoryBuffer.h" 16 #include <utility> 17 #include <vector> 18 19 namespace lld { 20 namespace elf { 21 22 class ScriptLexer { 23 public: 24 explicit ScriptLexer(MemoryBufferRef MB); 25 26 void setError(const Twine &Msg); 27 void tokenize(MemoryBufferRef MB); 28 static StringRef skipSpace(StringRef S); 29 bool atEOF(); 30 StringRef next(); 31 StringRef peek(); 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 private: 44 void maybeSplitExpr(); 45 StringRef getLine(); 46 size_t getLineNumber(); 47 size_t getColumnNumber(); 48 49 MemoryBufferRef getCurrentMB(); 50 }; 51 52 } // namespace elf 53 } // namespace lld 54 55 #endif 56