Adhemerval Zanella | e77b5bf | 2016-04-06 20:59:11 +0000 | [diff] [blame] | 1 | //===- ScriptParser.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_PARSER_H |
| 11 | #define LLD_ELF_SCRIPT_PARSER_H |
| 12 | |
| 13 | #include "lld/Core/LLVM.h" |
| 14 | #include "llvm/ADT/StringRef.h" |
Benjamin Kramer | bd52120 | 2016-06-03 16:57:13 +0000 | [diff] [blame] | 15 | #include <utility> |
Adhemerval Zanella | b92a34e | 2016-04-06 21:33:18 +0000 | [diff] [blame] | 16 | #include <vector> |
Adhemerval Zanella | e77b5bf | 2016-04-06 20:59:11 +0000 | [diff] [blame] | 17 | |
| 18 | namespace lld { |
| 19 | namespace elf { |
| 20 | |
| 21 | class ScriptParserBase { |
| 22 | public: |
Rui Ueyama | 1470366 | 2016-05-16 21:06:31 +0000 | [diff] [blame] | 23 | explicit ScriptParserBase(StringRef S) : Input(S), Tokens(tokenize(S)) {} |
Adhemerval Zanella | e77b5bf | 2016-04-06 20:59:11 +0000 | [diff] [blame] | 24 | |
| 25 | protected: |
| 26 | void setError(const Twine &Msg); |
| 27 | static std::vector<StringRef> tokenize(StringRef S); |
| 28 | static StringRef skipSpace(StringRef S); |
| 29 | bool atEOF(); |
| 30 | StringRef next(); |
| 31 | StringRef peek(); |
Justin Bogner | 5424e7c | 2016-10-17 06:21:13 +0000 | [diff] [blame] | 32 | void skip(); |
Adhemerval Zanella | e77b5bf | 2016-04-06 20:59:11 +0000 | [diff] [blame] | 33 | bool skip(StringRef Tok); |
| 34 | void expect(StringRef Expect); |
| 35 | |
| 36 | size_t getPos(); |
| 37 | void printErrorPos(); |
| 38 | |
Adhemerval Zanella | e77b5bf | 2016-04-06 20:59:11 +0000 | [diff] [blame] | 39 | StringRef Input; |
| 40 | std::vector<StringRef> Tokens; |
| 41 | size_t Pos = 0; |
| 42 | bool Error = false; |
| 43 | }; |
| 44 | |
| 45 | } // namespace elf |
| 46 | } // namespace lld |
| 47 | |
| 48 | #endif |