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 12 // ResourceScriptTokenList.h. 13 // 14 // Note that the tokenizer does not support comments or preprocessor 15 // directives. The preprocessor should do its work on the .rc file before 16 // running llvm-rc. 17 // 18 // As for now, it is possible to parse ASCII files only (the behavior on 19 // UTF files might be undefined). However, it already consumes UTF-8 BOM, if 20 // there is any. Thus, ASCII-compatible UTF-8 files are tokenized correctly. 21 // 22 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx 23 // 24 //===---------------------------------------------------------------------===// 25 26 #ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H 27 #define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H 28 29 #include "llvm/ADT/StringRef.h" 30 #include "llvm/Support/Error.h" 31 32 #include <cstdint> 33 #include <map> 34 #include <string> 35 #include <vector> 36 37 namespace llvm { 38 39 // A definition of a single resource script token. Each token has its kind 40 // (declared in ResourceScriptTokenList) and holds a value - a reference 41 // representation of the token. 42 // RCToken does not claim ownership on its value. A memory buffer containing 43 // the token value should be stored in a safe place and cannot be freed 44 // nor reallocated. 45 class RCToken { 46 public: 47 enum class Kind { 48 #define TOKEN(Name) Name, 49 #define SHORT_TOKEN(Name, Ch) Name, 50 #include "ResourceScriptTokenList.h" 51 #undef TOKEN 52 #undef SHORT_TOKEN 53 }; 54 55 RCToken(RCToken::Kind RCTokenKind, StringRef Value); 56 57 // Get an integer value of the integer token. 58 uint32_t intValue() const; 59 bool isLongInt() const; 60 61 StringRef value() const; 62 Kind kind() const; 63 64 // Check if a token describes a binary operator. 65 bool isBinaryOp() const; 66 67 private: 68 Kind TokenKind; 69 StringRef TokenValue; 70 }; 71 72 // Tokenize Input. 73 // In case no error occured, the return value contains 74 // tokens in order they were in the input file. 75 // In case of any error, the return value contains 76 // a textual representation of error. 77 // 78 // Tokens returned by this function hold only references to the parts 79 // of the Input. Memory buffer containing Input cannot be freed, 80 // modified or reallocated. 81 Expected<std::vector<RCToken>> tokenizeRC(StringRef Input); 82 83 } // namespace llvm 84 85 #endif 86