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) {} |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 30 | Data(const RCToken &Token) { |
| 31 | if (Token.kind() == RCToken::Kind::Int) |
| 32 | Int = Token.intValue(); |
| 33 | else |
| 34 | String = Token.value(); |
| 35 | } |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 36 | } Data; |
| 37 | bool IsInt; |
| 38 | |
| 39 | public: |
| 40 | IntOrString() : IntOrString(0) {} |
| 41 | IntOrString(uint32_t Value) : Data(Value), IsInt(1) {} |
| 42 | IntOrString(StringRef Value) : Data(Value), IsInt(0) {} |
| 43 | IntOrString(const RCToken &Token) |
| 44 | : Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {} |
| 45 | |
| 46 | bool equalsLower(const char *Str) { |
| 47 | return !IsInt && Data.String.equals_lower(Str); |
| 48 | } |
| 49 | |
| 50 | friend raw_ostream &operator<<(raw_ostream &, const IntOrString &); |
| 51 | }; |
| 52 | |
| 53 | // Base resource. All the resources should derive from this base. |
| 54 | class RCResource { |
| 55 | protected: |
| 56 | IntOrString ResName; |
| 57 | |
| 58 | public: |
| 59 | RCResource() = default; |
| 60 | RCResource(RCResource &&) = default; |
| 61 | void setName(const IntOrString &Name) { ResName = Name; } |
| 62 | virtual raw_ostream &log(raw_ostream &OS) const { |
| 63 | return OS << "Base statement\n"; |
| 64 | }; |
| 65 | virtual ~RCResource() {} |
| 66 | }; |
| 67 | |
| 68 | // Optional statement base. All such statements should derive from this base. |
| 69 | class OptionalStmt : public RCResource {}; |
| 70 | |
| 71 | class OptionalStmtList : public OptionalStmt { |
| 72 | std::vector<std::unique_ptr<OptionalStmt>> Statements; |
| 73 | |
| 74 | public: |
| 75 | OptionalStmtList() {} |
| 76 | virtual raw_ostream &log(raw_ostream &OS) const; |
| 77 | |
| 78 | void addStmt(std::unique_ptr<OptionalStmt> Stmt) { |
| 79 | Statements.push_back(std::move(Stmt)); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | // LANGUAGE statement. It can occur both as a top-level statement (in such |
| 84 | // a situation, it changes the default language until the end of the file) |
| 85 | // and as an optional resource statement (then it changes the language |
| 86 | // of a single resource). |
| 87 | // |
| 88 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx |
| 89 | class LanguageResource : public OptionalStmt { |
| 90 | uint32_t Lang, SubLang; |
| 91 | |
| 92 | public: |
| 93 | LanguageResource(uint32_t LangId, uint32_t SubLangId) |
| 94 | : Lang(LangId), SubLang(SubLangId) {} |
| 95 | raw_ostream &log(raw_ostream &) const override; |
| 96 | }; |
| 97 | |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 98 | // ACCELERATORS resource. Defines a named table of accelerators for the app. |
| 99 | // |
| 100 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380610(v=vs.85).aspx |
| 101 | class AcceleratorsResource : public RCResource { |
| 102 | public: |
| 103 | class Accelerator { |
| 104 | public: |
| 105 | IntOrString Event; |
| 106 | uint32_t Id; |
| 107 | uint8_t Flags; |
| 108 | |
| 109 | enum Options { |
| 110 | ASCII = (1 << 0), |
| 111 | VIRTKEY = (1 << 1), |
| 112 | NOINVERT = (1 << 2), |
| 113 | ALT = (1 << 3), |
| 114 | SHIFT = (1 << 4), |
| 115 | CONTROL = (1 << 5) |
| 116 | }; |
| 117 | |
| 118 | static constexpr size_t NumFlags = 6; |
| 119 | static StringRef OptionsStr[NumFlags]; |
| 120 | }; |
| 121 | |
| 122 | AcceleratorsResource(OptionalStmtList &&OptStmts) |
| 123 | : OptStatements(std::move(OptStmts)) {} |
| 124 | void addAccelerator(IntOrString Event, uint32_t Id, uint8_t Flags) { |
| 125 | Accelerators.push_back(Accelerator{Event, Id, Flags}); |
| 126 | } |
| 127 | raw_ostream &log(raw_ostream &) const override; |
| 128 | |
| 129 | private: |
| 130 | std::vector<Accelerator> Accelerators; |
| 131 | OptionalStmtList OptStatements; |
| 132 | }; |
| 133 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 134 | // CURSOR resource. Represents a single cursor (".cur") file. |
| 135 | // |
| 136 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx |
| 137 | class CursorResource : public RCResource { |
| 138 | StringRef CursorLoc; |
| 139 | |
| 140 | public: |
| 141 | CursorResource(StringRef Location) : CursorLoc(Location) {} |
| 142 | raw_ostream &log(raw_ostream &) const override; |
| 143 | }; |
| 144 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 145 | // ICON resource. Represents a single ".ico" file containing a group of icons. |
| 146 | // |
| 147 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx |
| 148 | class IconResource : public RCResource { |
| 149 | StringRef IconLoc; |
| 150 | |
| 151 | public: |
| 152 | IconResource(StringRef Location) : IconLoc(Location) {} |
| 153 | raw_ostream &log(raw_ostream &) const override; |
| 154 | }; |
| 155 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 156 | // HTML resource. Represents a local webpage that is to be embedded into the |
| 157 | // resulting resource file. It embeds a file only - no additional resources |
| 158 | // (images etc.) are included with this resource. |
| 159 | // |
| 160 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx |
| 161 | class HTMLResource : public RCResource { |
| 162 | StringRef HTMLLoc; |
| 163 | |
| 164 | public: |
| 165 | HTMLResource(StringRef Location) : HTMLLoc(Location) {} |
| 166 | raw_ostream &log(raw_ostream &) const override; |
| 167 | }; |
| 168 | |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 169 | // -- MENU resource and its helper classes -- |
| 170 | // This resource describes the contents of an application menu |
| 171 | // (usually located in the upper part of the dialog.) |
| 172 | // |
| 173 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381025(v=vs.85).aspx |
| 174 | |
| 175 | // Description of a single submenu item. |
| 176 | class MenuDefinition { |
| 177 | public: |
| 178 | enum Options { |
| 179 | CHECKED = (1 << 0), |
| 180 | GRAYED = (1 << 1), |
| 181 | HELP = (1 << 2), |
| 182 | INACTIVE = (1 << 3), |
| 183 | MENUBARBREAK = (1 << 4), |
| 184 | MENUBREAK = (1 << 5) |
| 185 | }; |
| 186 | |
| 187 | static constexpr size_t NumFlags = 6; |
| 188 | static StringRef OptionsStr[NumFlags]; |
| 189 | static raw_ostream &logFlags(raw_ostream &, uint8_t Flags); |
| 190 | virtual raw_ostream &log(raw_ostream &OS) const { |
| 191 | return OS << "Base menu definition\n"; |
| 192 | } |
| 193 | virtual ~MenuDefinition() {} |
| 194 | }; |
| 195 | |
| 196 | // Recursive description of a whole submenu. |
| 197 | class MenuDefinitionList : public MenuDefinition { |
| 198 | std::vector<std::unique_ptr<MenuDefinition>> Definitions; |
| 199 | |
| 200 | public: |
| 201 | void addDefinition(std::unique_ptr<MenuDefinition> Def) { |
| 202 | Definitions.push_back(std::move(Def)); |
| 203 | } |
| 204 | raw_ostream &log(raw_ostream &) const override; |
| 205 | }; |
| 206 | |
| 207 | // Separator in MENU definition (MENUITEM SEPARATOR). |
| 208 | // |
| 209 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx |
| 210 | class MenuSeparator : public MenuDefinition { |
| 211 | public: |
| 212 | raw_ostream &log(raw_ostream &) const override; |
| 213 | }; |
| 214 | |
| 215 | // MENUITEM statement definition. |
| 216 | // |
| 217 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx |
| 218 | class MenuItem : public MenuDefinition { |
| 219 | StringRef Name; |
| 220 | uint32_t Id; |
| 221 | uint8_t Flags; |
| 222 | |
| 223 | public: |
| 224 | MenuItem(StringRef Caption, uint32_t ItemId, uint8_t ItemFlags) |
| 225 | : Name(Caption), Id(ItemId), Flags(ItemFlags) {} |
| 226 | raw_ostream &log(raw_ostream &) const override; |
| 227 | }; |
| 228 | |
| 229 | // POPUP statement definition. |
| 230 | // |
| 231 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381030(v=vs.85).aspx |
| 232 | class PopupItem : public MenuDefinition { |
| 233 | StringRef Name; |
| 234 | uint8_t Flags; |
| 235 | MenuDefinitionList SubItems; |
| 236 | |
| 237 | public: |
| 238 | PopupItem(StringRef Caption, uint8_t ItemFlags, |
| 239 | MenuDefinitionList &&SubItemsList) |
| 240 | : Name(Caption), Flags(ItemFlags), SubItems(std::move(SubItemsList)) {} |
| 241 | raw_ostream &log(raw_ostream &) const override; |
| 242 | }; |
| 243 | |
| 244 | // Menu resource definition. |
| 245 | class MenuResource : public RCResource { |
| 246 | OptionalStmtList OptStatements; |
| 247 | MenuDefinitionList Elements; |
| 248 | |
| 249 | public: |
| 250 | MenuResource(OptionalStmtList &&OptStmts, MenuDefinitionList &&Items) |
| 251 | : OptStatements(std::move(OptStmts)), Elements(std::move(Items)) {} |
| 252 | raw_ostream &log(raw_ostream &) const override; |
| 253 | }; |
| 254 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 255 | // STRINGTABLE resource. Contains a list of strings, each having its unique ID. |
| 256 | // |
| 257 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx |
| 258 | class StringTableResource : public RCResource { |
| 259 | OptionalStmtList OptStatements; |
| 260 | std::vector<std::pair<uint32_t, StringRef>> Table; |
| 261 | |
| 262 | public: |
| 263 | StringTableResource(OptionalStmtList &&OptStmts) |
| 264 | : OptStatements(std::move(OptStmts)) {} |
| 265 | void addString(uint32_t ID, StringRef String) { |
| 266 | Table.emplace_back(ID, String); |
| 267 | } |
| 268 | raw_ostream &log(raw_ostream &) const override; |
| 269 | }; |
| 270 | |
| 271 | // CHARACTERISTICS optional statement. |
| 272 | // |
| 273 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx |
| 274 | class CharacteristicsStmt : public OptionalStmt { |
| 275 | uint32_t Value; |
| 276 | |
| 277 | public: |
| 278 | CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {} |
| 279 | raw_ostream &log(raw_ostream &) const override; |
| 280 | }; |
| 281 | |
| 282 | // VERSION optional statement. |
| 283 | // |
| 284 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx |
| 285 | class VersionStmt : public OptionalStmt { |
| 286 | uint32_t Value; |
| 287 | |
| 288 | public: |
| 289 | VersionStmt(uint32_t Version) : Value(Version) {} |
| 290 | raw_ostream &log(raw_ostream &) const override; |
| 291 | }; |
| 292 | |
| 293 | } // namespace rc |
| 294 | } // namespace llvm |
| 295 | |
| 296 | #endif |