Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame^] | 1 | //===-- ResourceScriptStmt.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 lists all the resource and statement types occurring in RC scripts. |
| 11 | // |
| 12 | //===---------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H |
| 15 | #define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H |
| 16 | |
| 17 | #include "ResourceScriptToken.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | namespace rc { |
| 21 | |
| 22 | // A class holding a name - either an integer or a reference to the string. |
| 23 | class IntOrString { |
| 24 | private: |
| 25 | union Data { |
| 26 | uint32_t Int; |
| 27 | StringRef String; |
| 28 | Data(uint32_t Value) : Int(Value) {} |
| 29 | Data(const StringRef Value) : String(Value) {} |
| 30 | Data(const RCToken &Token); |
| 31 | } Data; |
| 32 | bool IsInt; |
| 33 | |
| 34 | public: |
| 35 | IntOrString() : IntOrString(0) {} |
| 36 | IntOrString(uint32_t Value) : Data(Value), IsInt(1) {} |
| 37 | IntOrString(StringRef Value) : Data(Value), IsInt(0) {} |
| 38 | IntOrString(const RCToken &Token) |
| 39 | : Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {} |
| 40 | |
| 41 | bool equalsLower(const char *Str) { |
| 42 | return !IsInt && Data.String.equals_lower(Str); |
| 43 | } |
| 44 | |
| 45 | friend raw_ostream &operator<<(raw_ostream &, const IntOrString &); |
| 46 | }; |
| 47 | |
| 48 | // Base resource. All the resources should derive from this base. |
| 49 | class RCResource { |
| 50 | protected: |
| 51 | IntOrString ResName; |
| 52 | |
| 53 | public: |
| 54 | RCResource() = default; |
| 55 | RCResource(RCResource &&) = default; |
| 56 | void setName(const IntOrString &Name) { ResName = Name; } |
| 57 | virtual raw_ostream &log(raw_ostream &OS) const { |
| 58 | return OS << "Base statement\n"; |
| 59 | }; |
| 60 | virtual ~RCResource() {} |
| 61 | }; |
| 62 | |
| 63 | // Optional statement base. All such statements should derive from this base. |
| 64 | class OptionalStmt : public RCResource {}; |
| 65 | |
| 66 | class OptionalStmtList : public OptionalStmt { |
| 67 | std::vector<std::unique_ptr<OptionalStmt>> Statements; |
| 68 | |
| 69 | public: |
| 70 | OptionalStmtList() {} |
| 71 | virtual raw_ostream &log(raw_ostream &OS) const; |
| 72 | |
| 73 | void addStmt(std::unique_ptr<OptionalStmt> Stmt) { |
| 74 | Statements.push_back(std::move(Stmt)); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | // LANGUAGE statement. It can occur both as a top-level statement (in such |
| 79 | // a situation, it changes the default language until the end of the file) |
| 80 | // and as an optional resource statement (then it changes the language |
| 81 | // of a single resource). |
| 82 | // |
| 83 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx |
| 84 | class LanguageResource : public OptionalStmt { |
| 85 | uint32_t Lang, SubLang; |
| 86 | |
| 87 | public: |
| 88 | LanguageResource(uint32_t LangId, uint32_t SubLangId) |
| 89 | : Lang(LangId), SubLang(SubLangId) {} |
| 90 | raw_ostream &log(raw_ostream &) const override; |
| 91 | }; |
| 92 | |
| 93 | // ICON resource. Represents a single ".ico" file containing a group of icons. |
| 94 | // |
| 95 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx |
| 96 | class IconResource : public RCResource { |
| 97 | StringRef IconLoc; |
| 98 | |
| 99 | public: |
| 100 | IconResource(StringRef Location) : IconLoc(Location) {} |
| 101 | raw_ostream &log(raw_ostream &) const override; |
| 102 | }; |
| 103 | |
| 104 | // STRINGTABLE resource. Contains a list of strings, each having its unique ID. |
| 105 | // |
| 106 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx |
| 107 | class StringTableResource : public RCResource { |
| 108 | OptionalStmtList OptStatements; |
| 109 | std::vector<std::pair<uint32_t, StringRef>> Table; |
| 110 | |
| 111 | public: |
| 112 | StringTableResource(OptionalStmtList &&OptStmts) |
| 113 | : OptStatements(std::move(OptStmts)) {} |
| 114 | void addString(uint32_t ID, StringRef String) { |
| 115 | Table.emplace_back(ID, String); |
| 116 | } |
| 117 | raw_ostream &log(raw_ostream &) const override; |
| 118 | }; |
| 119 | |
| 120 | // CHARACTERISTICS optional statement. |
| 121 | // |
| 122 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx |
| 123 | class CharacteristicsStmt : public OptionalStmt { |
| 124 | uint32_t Value; |
| 125 | |
| 126 | public: |
| 127 | CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {} |
| 128 | raw_ostream &log(raw_ostream &) const override; |
| 129 | }; |
| 130 | |
| 131 | // VERSION optional statement. |
| 132 | // |
| 133 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx |
| 134 | class VersionStmt : public OptionalStmt { |
| 135 | uint32_t Value; |
| 136 | |
| 137 | public: |
| 138 | VersionStmt(uint32_t Version) : Value(Version) {} |
| 139 | raw_ostream &log(raw_ostream &) const override; |
| 140 | }; |
| 141 | |
| 142 | } // namespace rc |
| 143 | } // namespace llvm |
| 144 | |
| 145 | #endif |