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