Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 1 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | // See https://llvm.org/LICENSE.txt for license information. |
| 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 5 | // |
| 6 | //===---------------------------------------------------------------------===// |
| 7 | // |
| 8 | // This implements methods defined in ResourceScriptStmt.h. |
| 9 | // |
| 10 | // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx |
| 11 | // |
| 12 | //===---------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ResourceScriptStmt.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | namespace rc { |
| 18 | |
| 19 | raw_ostream &operator<<(raw_ostream &OS, const IntOrString &Item) { |
| 20 | if (Item.IsInt) |
| 21 | return OS << Item.Data.Int; |
| 22 | else |
| 23 | return OS << Item.Data.String; |
| 24 | } |
| 25 | |
| 26 | raw_ostream &OptionalStmtList::log(raw_ostream &OS) const { |
| 27 | for (const auto &Stmt : Statements) { |
| 28 | OS << " Option: "; |
| 29 | Stmt->log(OS); |
| 30 | } |
| 31 | return OS; |
| 32 | } |
| 33 | |
| 34 | raw_ostream &LanguageResource::log(raw_ostream &OS) const { |
| 35 | return OS << "Language: " << Lang << ", Sublanguage: " << SubLang << "\n"; |
| 36 | } |
| 37 | |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 38 | StringRef AcceleratorsResource::Accelerator::OptionsStr |
| 39 | [AcceleratorsResource::Accelerator::NumFlags] = { |
| 40 | "ASCII", "VIRTKEY", "NOINVERT", "ALT", "SHIFT", "CONTROL"}; |
| 41 | |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 42 | uint32_t AcceleratorsResource::Accelerator::OptionsFlags |
| 43 | [AcceleratorsResource::Accelerator::NumFlags] = {ASCII, VIRTKEY, NOINVERT, |
| 44 | ALT, SHIFT, CONTROL}; |
| 45 | |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 46 | raw_ostream &AcceleratorsResource::log(raw_ostream &OS) const { |
| 47 | OS << "Accelerators (" << ResName << "): \n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 48 | OptStatements->log(OS); |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 49 | for (const auto &Acc : Accelerators) { |
| 50 | OS << " Accelerator: " << Acc.Event << " " << Acc.Id; |
| 51 | for (size_t i = 0; i < Accelerator::NumFlags; ++i) |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 52 | if (Acc.Flags & Accelerator::OptionsFlags[i]) |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 53 | OS << " " << Accelerator::OptionsStr[i]; |
| 54 | OS << "\n"; |
| 55 | } |
| 56 | return OS; |
| 57 | } |
| 58 | |
Martin Storsjo | 577b981 | 2018-05-07 20:27:37 +0000 | [diff] [blame] | 59 | raw_ostream &BitmapResource::log(raw_ostream &OS) const { |
| 60 | return OS << "Bitmap (" << ResName << "): " << BitmapLoc << "\n"; |
| 61 | } |
| 62 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 63 | raw_ostream &CursorResource::log(raw_ostream &OS) const { |
| 64 | return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n"; |
| 65 | } |
| 66 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 67 | raw_ostream &IconResource::log(raw_ostream &OS) const { |
| 68 | return OS << "Icon (" << ResName << "): " << IconLoc << "\n"; |
| 69 | } |
| 70 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 71 | raw_ostream &HTMLResource::log(raw_ostream &OS) const { |
| 72 | return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n"; |
| 73 | } |
| 74 | |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 75 | StringRef MenuDefinition::OptionsStr[MenuDefinition::NumFlags] = { |
| 76 | "CHECKED", "GRAYED", "HELP", "INACTIVE", "MENUBARBREAK", "MENUBREAK"}; |
| 77 | |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 78 | uint32_t MenuDefinition::OptionsFlags[MenuDefinition::NumFlags] = { |
| 79 | CHECKED, GRAYED, HELP, INACTIVE, MENUBARBREAK, MENUBREAK}; |
| 80 | |
| 81 | raw_ostream &MenuDefinition::logFlags(raw_ostream &OS, uint16_t Flags) { |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 82 | for (size_t i = 0; i < NumFlags; ++i) |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 83 | if (Flags & OptionsFlags[i]) |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 84 | OS << " " << OptionsStr[i]; |
| 85 | return OS; |
| 86 | } |
| 87 | |
| 88 | raw_ostream &MenuDefinitionList::log(raw_ostream &OS) const { |
| 89 | OS << " Menu list starts\n"; |
| 90 | for (auto &Item : Definitions) |
| 91 | Item->log(OS); |
| 92 | return OS << " Menu list ends\n"; |
| 93 | } |
| 94 | |
| 95 | raw_ostream &MenuItem::log(raw_ostream &OS) const { |
| 96 | OS << " MenuItem (" << Name << "), ID = " << Id; |
| 97 | logFlags(OS, Flags); |
| 98 | return OS << "\n"; |
| 99 | } |
| 100 | |
| 101 | raw_ostream &MenuSeparator::log(raw_ostream &OS) const { |
| 102 | return OS << " Menu separator\n"; |
| 103 | } |
| 104 | |
| 105 | raw_ostream &PopupItem::log(raw_ostream &OS) const { |
| 106 | OS << " Popup (" << Name << ")"; |
| 107 | logFlags(OS, Flags); |
| 108 | OS << ":\n"; |
| 109 | return SubItems.log(OS); |
| 110 | } |
| 111 | |
| 112 | raw_ostream &MenuResource::log(raw_ostream &OS) const { |
| 113 | OS << "Menu (" << ResName << "):\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 114 | OptStatements->log(OS); |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 115 | return Elements.log(OS); |
| 116 | } |
| 117 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 118 | raw_ostream &StringTableResource::log(raw_ostream &OS) const { |
| 119 | OS << "StringTable:\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 120 | OptStatements->log(OS); |
Martin Storsjö | b989fcb | 2020-08-04 10:24:32 +0300 | [diff] [blame] | 121 | for (const auto &String : Table) { |
| 122 | OS << " " << String.first << " =>"; |
| 123 | for (const auto &S : String.second) |
| 124 | OS << " " << S; |
| 125 | OS << "\n"; |
| 126 | } |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 127 | return OS; |
| 128 | } |
| 129 | |
Marek Sokolowski | 7f7745c | 2017-09-30 00:38:52 +0000 | [diff] [blame] | 130 | const StringMap<Control::CtlInfo> Control::SupportedCtls = { |
| 131 | {"LTEXT", CtlInfo{0x50020000, ClsStatic, true}}, |
| 132 | {"CTEXT", CtlInfo{0x50020001, ClsStatic, true}}, |
| 133 | {"RTEXT", CtlInfo{0x50020002, ClsStatic, true}}, |
Martin Storsjo | 818bd56 | 2018-05-08 20:55:58 +0000 | [diff] [blame] | 134 | {"ICON", CtlInfo{0x50000003, ClsStatic, true}}, |
Marek Sokolowski | 7f7745c | 2017-09-30 00:38:52 +0000 | [diff] [blame] | 135 | {"PUSHBUTTON", CtlInfo{0x50010000, ClsButton, true}}, |
| 136 | {"DEFPUSHBUTTON", CtlInfo{0x50010001, ClsButton, true}}, |
Martin Storsjo | 818bd56 | 2018-05-08 20:55:58 +0000 | [diff] [blame] | 137 | {"AUTO3STATE", CtlInfo{0x50010006, ClsButton, true}}, |
| 138 | {"AUTOCHECKBOX", CtlInfo{0x50010003, ClsButton, true}}, |
| 139 | {"AUTORADIOBUTTON", CtlInfo{0x50000009, ClsButton, true}}, |
| 140 | {"CHECKBOX", CtlInfo{0x50010002, ClsButton, true}}, |
| 141 | {"GROUPBOX", CtlInfo{0x50000007, ClsButton, true}}, |
| 142 | {"RADIOBUTTON", CtlInfo{0x50000004, ClsButton, true}}, |
| 143 | {"STATE3", CtlInfo{0x50010005, ClsButton, true}}, |
| 144 | {"PUSHBOX", CtlInfo{0x5001000A, ClsButton, true}}, |
Marek Sokolowski | 7f7745c | 2017-09-30 00:38:52 +0000 | [diff] [blame] | 145 | {"EDITTEXT", CtlInfo{0x50810000, ClsEdit, false}}, |
Martin Storsjo | 818bd56 | 2018-05-08 20:55:58 +0000 | [diff] [blame] | 146 | {"COMBOBOX", CtlInfo{0x50000000, ClsComboBox, false}}, |
| 147 | {"LISTBOX", CtlInfo{0x50800001, ClsListBox, false}}, |
| 148 | {"SCROLLBAR", CtlInfo{0x50000000, ClsScrollBar, false}}, |
| 149 | {"CONTROL", CtlInfo{0x50000000, 0, true}}, |
Marek Sokolowski | 7f7745c | 2017-09-30 00:38:52 +0000 | [diff] [blame] | 150 | }; |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 151 | |
| 152 | raw_ostream &Control::log(raw_ostream &OS) const { |
| 153 | OS << " Control (" << ID << "): " << Type << ", title: " << Title |
| 154 | << ", loc: (" << X << ", " << Y << "), size: [" << Width << ", " << Height |
| 155 | << "]"; |
| 156 | if (Style) |
Martin Storsjo | d0afe72 | 2018-12-05 13:22:56 +0000 | [diff] [blame] | 157 | OS << ", style: " << (*Style).getValue(); |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 158 | if (ExtStyle) |
| 159 | OS << ", ext. style: " << *ExtStyle; |
| 160 | if (HelpID) |
| 161 | OS << ", help ID: " << *HelpID; |
| 162 | return OS << "\n"; |
| 163 | } |
| 164 | |
| 165 | raw_ostream &DialogResource::log(raw_ostream &OS) const { |
| 166 | OS << "Dialog" << (IsExtended ? "Ex" : "") << " (" << ResName << "): loc: (" |
| 167 | << X << ", " << Y << "), size: [" << Width << ", " << Height |
| 168 | << "], help ID: " << HelpID << "\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 169 | OptStatements->log(OS); |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 170 | for (auto &Ctl : Controls) |
| 171 | Ctl.log(OS); |
| 172 | return OS; |
| 173 | } |
| 174 | |
Marek Sokolowski | fb74cb1 | 2017-09-28 22:41:38 +0000 | [diff] [blame] | 175 | raw_ostream &VersionInfoBlock::log(raw_ostream &OS) const { |
| 176 | OS << " Start of block (name: " << Name << ")\n"; |
| 177 | for (auto &Stmt : Stmts) |
| 178 | Stmt->log(OS); |
| 179 | return OS << " End of block\n"; |
| 180 | } |
| 181 | |
| 182 | raw_ostream &VersionInfoValue::log(raw_ostream &OS) const { |
| 183 | OS << " " << Key << " =>"; |
Zachary Turner | 07bc04f | 2017-10-06 21:26:06 +0000 | [diff] [blame] | 184 | size_t NumValues = Values.size(); |
| 185 | for (size_t Id = 0; Id < NumValues; ++Id) { |
| 186 | if (Id > 0 && HasPrecedingComma[Id]) |
| 187 | OS << ","; |
| 188 | OS << " " << Values[Id]; |
| 189 | } |
Marek Sokolowski | fb74cb1 | 2017-09-28 22:41:38 +0000 | [diff] [blame] | 190 | return OS << "\n"; |
| 191 | } |
| 192 | |
| 193 | using VersionInfoFixed = VersionInfoResource::VersionInfoFixed; |
| 194 | using VersionInfoFixedType = VersionInfoFixed::VersionInfoFixedType; |
| 195 | |
| 196 | const StringRef |
| 197 | VersionInfoFixed::FixedFieldsNames[VersionInfoFixed::FtNumTypes] = { |
| 198 | "", "FILEVERSION", "PRODUCTVERSION", "FILEFLAGSMASK", |
| 199 | "FILEFLAGS", "FILEOS", "FILETYPE", "FILESUBTYPE"}; |
| 200 | |
| 201 | const StringMap<VersionInfoFixedType> VersionInfoFixed::FixedFieldsInfoMap = { |
| 202 | {FixedFieldsNames[FtFileVersion], FtFileVersion}, |
| 203 | {FixedFieldsNames[FtProductVersion], FtProductVersion}, |
| 204 | {FixedFieldsNames[FtFileFlagsMask], FtFileFlagsMask}, |
| 205 | {FixedFieldsNames[FtFileFlags], FtFileFlags}, |
| 206 | {FixedFieldsNames[FtFileOS], FtFileOS}, |
| 207 | {FixedFieldsNames[FtFileType], FtFileType}, |
| 208 | {FixedFieldsNames[FtFileSubtype], FtFileSubtype}}; |
| 209 | |
| 210 | VersionInfoFixedType VersionInfoFixed::getFixedType(StringRef Type) { |
| 211 | auto UpperType = Type.upper(); |
| 212 | auto Iter = FixedFieldsInfoMap.find(UpperType); |
| 213 | if (Iter != FixedFieldsInfoMap.end()) |
| 214 | return Iter->getValue(); |
| 215 | return FtUnknown; |
| 216 | } |
| 217 | |
| 218 | bool VersionInfoFixed::isTypeSupported(VersionInfoFixedType Type) { |
| 219 | return FtUnknown < Type && Type < FtNumTypes; |
| 220 | } |
| 221 | |
| 222 | bool VersionInfoFixed::isVersionType(VersionInfoFixedType Type) { |
| 223 | switch (Type) { |
| 224 | case FtFileVersion: |
| 225 | case FtProductVersion: |
| 226 | return true; |
| 227 | |
| 228 | default: |
| 229 | return false; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | raw_ostream &VersionInfoFixed::log(raw_ostream &OS) const { |
| 234 | for (int Type = FtUnknown; Type < FtNumTypes; ++Type) { |
| 235 | if (!isTypeSupported((VersionInfoFixedType)Type)) |
| 236 | continue; |
| 237 | OS << " Fixed: " << FixedFieldsNames[Type] << ":"; |
| 238 | for (uint32_t Val : FixedInfo[Type]) |
| 239 | OS << " " << Val; |
| 240 | OS << "\n"; |
| 241 | } |
| 242 | return OS; |
| 243 | } |
| 244 | |
| 245 | raw_ostream &VersionInfoResource::log(raw_ostream &OS) const { |
| 246 | OS << "VersionInfo (" << ResName << "):\n"; |
| 247 | FixedData.log(OS); |
| 248 | return MainBlock.log(OS); |
| 249 | } |
| 250 | |
Marek Sokolowski | b5f39a0 | 2017-09-29 00:14:18 +0000 | [diff] [blame] | 251 | raw_ostream &UserDefinedResource::log(raw_ostream &OS) const { |
| 252 | OS << "User-defined (type: " << Type << ", name: " << ResName << "): "; |
| 253 | if (IsFileResource) |
| 254 | return OS << FileLoc << "\n"; |
| 255 | OS << "data = "; |
| 256 | for (auto &Item : Contents) |
| 257 | OS << Item << " "; |
| 258 | return OS << "\n"; |
| 259 | } |
| 260 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 261 | raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const { |
| 262 | return OS << "Characteristics: " << Value << "\n"; |
| 263 | } |
| 264 | |
| 265 | raw_ostream &VersionStmt::log(raw_ostream &OS) const { |
| 266 | return OS << "Version: " << Value << "\n"; |
| 267 | } |
| 268 | |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 269 | raw_ostream &CaptionStmt::log(raw_ostream &OS) const { |
| 270 | return OS << "Caption: " << Value << "\n"; |
| 271 | } |
| 272 | |
Martin Storsjo | e241ce6 | 2018-05-15 19:21:28 +0000 | [diff] [blame] | 273 | raw_ostream &ClassStmt::log(raw_ostream &OS) const { |
| 274 | return OS << "Class: " << Value << "\n"; |
| 275 | } |
| 276 | |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 277 | raw_ostream &FontStmt::log(raw_ostream &OS) const { |
Zachary Turner | 420090a | 2017-10-06 20:51:20 +0000 | [diff] [blame] | 278 | OS << "Font: size = " << Size << ", face = " << Name |
| 279 | << ", weight = " << Weight; |
| 280 | if (Italic) |
| 281 | OS << ", italic"; |
| 282 | return OS << ", charset = " << Charset << "\n"; |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | raw_ostream &StyleStmt::log(raw_ostream &OS) const { |
| 286 | return OS << "Style: " << Value << "\n"; |
| 287 | } |
| 288 | |
Martin Storsjo | a876b5c | 2018-11-29 12:17:39 +0000 | [diff] [blame] | 289 | raw_ostream &ExStyleStmt::log(raw_ostream &OS) const { |
| 290 | return OS << "ExStyle: " << Value << "\n"; |
| 291 | } |
| 292 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 293 | } // namespace rc |
| 294 | } // namespace llvm |