Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 1 | //===-- ResourceScriptToken.h -----------------------------------*- C++-*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===---------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This declares the .rc script tokens and defines an interface for tokenizing |
| 11 | // the input data. The list of available tokens is located at |
David Blaikie | bb5acf9 | 2017-11-21 00:23:19 +0000 | [diff] [blame] | 12 | // ResourceScriptTokenList.def. |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 13 | // |
Martin Storsjo | 9affe20 | 2018-05-08 12:33:54 +0000 | [diff] [blame] | 14 | // Note that the tokenizer does not support preprocessor directives. The |
| 15 | // preprocessor should do its work on the .rc file before running llvm-rc. |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 16 | // |
| 17 | // As for now, it is possible to parse ASCII files only (the behavior on |
| 18 | // UTF files might be undefined). However, it already consumes UTF-8 BOM, if |
| 19 | // there is any. Thus, ASCII-compatible UTF-8 files are tokenized correctly. |
| 20 | // |
| 21 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx |
| 22 | // |
| 23 | //===---------------------------------------------------------------------===// |
| 24 | |
| 25 | #ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H |
| 26 | #define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H |
| 27 | |
| 28 | #include "llvm/ADT/StringRef.h" |
| 29 | #include "llvm/Support/Error.h" |
| 30 | |
| 31 | #include <cstdint> |
| 32 | #include <map> |
| 33 | #include <string> |
| 34 | #include <vector> |
| 35 | |
| 36 | namespace llvm { |
| 37 | |
| 38 | // A definition of a single resource script token. Each token has its kind |
| 39 | // (declared in ResourceScriptTokenList) and holds a value - a reference |
| 40 | // representation of the token. |
| 41 | // RCToken does not claim ownership on its value. A memory buffer containing |
| 42 | // the token value should be stored in a safe place and cannot be freed |
| 43 | // nor reallocated. |
| 44 | class RCToken { |
| 45 | public: |
| 46 | enum class Kind { |
| 47 | #define TOKEN(Name) Name, |
| 48 | #define SHORT_TOKEN(Name, Ch) Name, |
David Blaikie | bb5acf9 | 2017-11-21 00:23:19 +0000 | [diff] [blame] | 49 | #include "ResourceScriptTokenList.def" |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | RCToken(RCToken::Kind RCTokenKind, StringRef Value); |
| 53 | |
| 54 | // Get an integer value of the integer token. |
| 55 | uint32_t intValue() const; |
Zachary Turner | 93bb30d | 2017-10-06 21:26:06 +0000 | [diff] [blame] | 56 | bool isLongInt() const; |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 57 | |
| 58 | StringRef value() const; |
| 59 | Kind kind() const; |
| 60 | |
Marek Sokolowski | 5906648 | 2017-09-28 23:53:25 +0000 | [diff] [blame] | 61 | // Check if a token describes a binary operator. |
| 62 | bool isBinaryOp() const; |
| 63 | |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 64 | private: |
| 65 | Kind TokenKind; |
| 66 | StringRef TokenValue; |
| 67 | }; |
| 68 | |
| 69 | // Tokenize Input. |
Malcolm Parsons | 5fc9628 | 2018-01-24 10:33:39 +0000 | [diff] [blame] | 70 | // In case no error occurred, the return value contains |
Marek Sokolowski | 6c9cbed | 2017-08-10 16:21:44 +0000 | [diff] [blame] | 71 | // tokens in order they were in the input file. |
| 72 | // In case of any error, the return value contains |
| 73 | // a textual representation of error. |
| 74 | // |
| 75 | // Tokens returned by this function hold only references to the parts |
| 76 | // of the Input. Memory buffer containing Input cannot be freed, |
| 77 | // modified or reallocated. |
| 78 | Expected<std::vector<RCToken>> tokenizeRC(StringRef Input); |
| 79 | |
| 80 | } // namespace llvm |
| 81 | |
| 82 | #endif |