ResourceScriptToken.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===-- ResourceScriptToken.h -----------------------------------*- C++-*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===---------------------------------------------------------------------===//
  8. //
  9. // This declares the .rc script tokens and defines an interface for tokenizing
  10. // the input data. The list of available tokens is located at
  11. // ResourceScriptTokenList.def.
  12. //
  13. // Note that the tokenizer does not support preprocessor directives. The
  14. // preprocessor should do its work on the .rc file before running llvm-rc.
  15. //
  16. // As for now, it is possible to parse ASCII files only (the behavior on
  17. // UTF files might be undefined). However, it already consumes UTF-8 BOM, if
  18. // there is any. Thus, ASCII-compatible UTF-8 files are tokenized correctly.
  19. //
  20. // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx
  21. //
  22. //===---------------------------------------------------------------------===//
  23. #ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H
  24. #define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H
  25. #include "llvm/ADT/StringRef.h"
  26. #include "llvm/Support/Error.h"
  27. #include <cstdint>
  28. #include <map>
  29. #include <string>
  30. #include <vector>
  31. namespace llvm {
  32. // A definition of a single resource script token. Each token has its kind
  33. // (declared in ResourceScriptTokenList) and holds a value - a reference
  34. // representation of the token.
  35. // RCToken does not claim ownership on its value. A memory buffer containing
  36. // the token value should be stored in a safe place and cannot be freed
  37. // nor reallocated.
  38. class RCToken {
  39. public:
  40. enum class Kind {
  41. #define TOKEN(Name) Name,
  42. #define SHORT_TOKEN(Name, Ch) Name,
  43. #include "ResourceScriptTokenList.def"
  44. };
  45. RCToken(RCToken::Kind RCTokenKind, StringRef Value);
  46. // Get an integer value of the integer token.
  47. uint32_t intValue() const;
  48. bool isLongInt() const;
  49. StringRef value() const;
  50. Kind kind() const;
  51. // Check if a token describes a binary operator.
  52. bool isBinaryOp() const;
  53. private:
  54. Kind TokenKind;
  55. StringRef TokenValue;
  56. };
  57. // Tokenize Input.
  58. // In case no error occurred, the return value contains
  59. // tokens in order they were in the input file.
  60. // In case of any error, the return value contains
  61. // a textual representation of error.
  62. //
  63. // Tokens returned by this function hold only references to the parts
  64. // of the Input. Memory buffer containing Input cannot be freed,
  65. // modified or reallocated.
  66. Expected<std::vector<RCToken>> tokenizeRC(StringRef Input);
  67. } // namespace llvm
  68. #endif