Marek Sokolowski | 5cd3d5c | 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 | 7f11052 | 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 | c75a087 | 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 | 7f11052 | 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 | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 49 | OptStatements->log(OS); |
Marek Sokolowski | 7f11052 | 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 | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 53 | if (Acc.Flags & Accelerator::OptionsFlags[i]) |
Marek Sokolowski | 7f11052 | 2017-08-28 22:58:31 +0000 | [diff] [blame] | 54 | OS << " " << Accelerator::OptionsStr[i]; |
| 55 | OS << "\n"; |
| 56 | } |
| 57 | return OS; |
| 58 | } |
| 59 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 60 | raw_ostream &CursorResource::log(raw_ostream &OS) const { |
| 61 | return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n"; |
| 62 | } |
| 63 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 64 | raw_ostream &IconResource::log(raw_ostream &OS) const { |
| 65 | return OS << "Icon (" << ResName << "): " << IconLoc << "\n"; |
| 66 | } |
| 67 | |
Marek Sokolowski | 72aa937 | 2017-08-28 21:59:54 +0000 | [diff] [blame] | 68 | raw_ostream &HTMLResource::log(raw_ostream &OS) const { |
| 69 | return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n"; |
| 70 | } |
| 71 | |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 72 | StringRef MenuDefinition::OptionsStr[MenuDefinition::NumFlags] = { |
| 73 | "CHECKED", "GRAYED", "HELP", "INACTIVE", "MENUBARBREAK", "MENUBREAK"}; |
| 74 | |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 75 | uint32_t MenuDefinition::OptionsFlags[MenuDefinition::NumFlags] = { |
| 76 | CHECKED, GRAYED, HELP, INACTIVE, MENUBARBREAK, MENUBREAK}; |
| 77 | |
| 78 | raw_ostream &MenuDefinition::logFlags(raw_ostream &OS, uint16_t Flags) { |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 79 | for (size_t i = 0; i < NumFlags; ++i) |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 80 | if (Flags & OptionsFlags[i]) |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 81 | OS << " " << OptionsStr[i]; |
| 82 | return OS; |
| 83 | } |
| 84 | |
| 85 | raw_ostream &MenuDefinitionList::log(raw_ostream &OS) const { |
| 86 | OS << " Menu list starts\n"; |
| 87 | for (auto &Item : Definitions) |
| 88 | Item->log(OS); |
| 89 | return OS << " Menu list ends\n"; |
| 90 | } |
| 91 | |
| 92 | raw_ostream &MenuItem::log(raw_ostream &OS) const { |
| 93 | OS << " MenuItem (" << Name << "), ID = " << Id; |
| 94 | logFlags(OS, Flags); |
| 95 | return OS << "\n"; |
| 96 | } |
| 97 | |
| 98 | raw_ostream &MenuSeparator::log(raw_ostream &OS) const { |
| 99 | return OS << " Menu separator\n"; |
| 100 | } |
| 101 | |
| 102 | raw_ostream &PopupItem::log(raw_ostream &OS) const { |
| 103 | OS << " Popup (" << Name << ")"; |
| 104 | logFlags(OS, Flags); |
| 105 | OS << ":\n"; |
| 106 | return SubItems.log(OS); |
| 107 | } |
| 108 | |
| 109 | raw_ostream &MenuResource::log(raw_ostream &OS) const { |
| 110 | OS << "Menu (" << ResName << "):\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 111 | OptStatements->log(OS); |
Marek Sokolowski | 99ecb0e | 2017-08-28 23:46:30 +0000 | [diff] [blame] | 112 | return Elements.log(OS); |
| 113 | } |
| 114 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 115 | raw_ostream &StringTableResource::log(raw_ostream &OS) const { |
| 116 | OS << "StringTable:\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 117 | OptStatements->log(OS); |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 118 | for (const auto &String : Table) |
| 119 | OS << " " << String.first << " => " << String.second << "\n"; |
| 120 | return OS; |
| 121 | } |
| 122 | |
Marek Sokolowski | 7f7745c | 2017-09-30 00:38:52 +0000 | [diff] [blame^] | 123 | const StringMap<Control::CtlInfo> Control::SupportedCtls = { |
| 124 | {"LTEXT", CtlInfo{0x50020000, ClsStatic, true}}, |
| 125 | {"CTEXT", CtlInfo{0x50020001, ClsStatic, true}}, |
| 126 | {"RTEXT", CtlInfo{0x50020002, ClsStatic, true}}, |
| 127 | {"PUSHBUTTON", CtlInfo{0x50010000, ClsButton, true}}, |
| 128 | {"DEFPUSHBUTTON", CtlInfo{0x50010001, ClsButton, true}}, |
| 129 | {"EDITTEXT", CtlInfo{0x50810000, ClsEdit, false}}, |
| 130 | }; |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 131 | |
| 132 | raw_ostream &Control::log(raw_ostream &OS) const { |
| 133 | OS << " Control (" << ID << "): " << Type << ", title: " << Title |
| 134 | << ", loc: (" << X << ", " << Y << "), size: [" << Width << ", " << Height |
| 135 | << "]"; |
| 136 | if (Style) |
| 137 | OS << ", style: " << *Style; |
| 138 | if (ExtStyle) |
| 139 | OS << ", ext. style: " << *ExtStyle; |
| 140 | if (HelpID) |
| 141 | OS << ", help ID: " << *HelpID; |
| 142 | return OS << "\n"; |
| 143 | } |
| 144 | |
| 145 | raw_ostream &DialogResource::log(raw_ostream &OS) const { |
| 146 | OS << "Dialog" << (IsExtended ? "Ex" : "") << " (" << ResName << "): loc: (" |
| 147 | << X << ", " << Y << "), size: [" << Width << ", " << Height |
| 148 | << "], help ID: " << HelpID << "\n"; |
Marek Sokolowski | c75a087 | 2017-09-29 17:46:32 +0000 | [diff] [blame] | 149 | OptStatements->log(OS); |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 150 | for (auto &Ctl : Controls) |
| 151 | Ctl.log(OS); |
| 152 | return OS; |
| 153 | } |
| 154 | |
Marek Sokolowski | fb74cb1 | 2017-09-28 22:41:38 +0000 | [diff] [blame] | 155 | raw_ostream &VersionInfoBlock::log(raw_ostream &OS) const { |
| 156 | OS << " Start of block (name: " << Name << ")\n"; |
| 157 | for (auto &Stmt : Stmts) |
| 158 | Stmt->log(OS); |
| 159 | return OS << " End of block\n"; |
| 160 | } |
| 161 | |
| 162 | raw_ostream &VersionInfoValue::log(raw_ostream &OS) const { |
| 163 | OS << " " << Key << " =>"; |
| 164 | for (auto &Value : Values) |
| 165 | OS << " " << Value; |
| 166 | return OS << "\n"; |
| 167 | } |
| 168 | |
| 169 | using VersionInfoFixed = VersionInfoResource::VersionInfoFixed; |
| 170 | using VersionInfoFixedType = VersionInfoFixed::VersionInfoFixedType; |
| 171 | |
| 172 | const StringRef |
| 173 | VersionInfoFixed::FixedFieldsNames[VersionInfoFixed::FtNumTypes] = { |
| 174 | "", "FILEVERSION", "PRODUCTVERSION", "FILEFLAGSMASK", |
| 175 | "FILEFLAGS", "FILEOS", "FILETYPE", "FILESUBTYPE"}; |
| 176 | |
| 177 | const StringMap<VersionInfoFixedType> VersionInfoFixed::FixedFieldsInfoMap = { |
| 178 | {FixedFieldsNames[FtFileVersion], FtFileVersion}, |
| 179 | {FixedFieldsNames[FtProductVersion], FtProductVersion}, |
| 180 | {FixedFieldsNames[FtFileFlagsMask], FtFileFlagsMask}, |
| 181 | {FixedFieldsNames[FtFileFlags], FtFileFlags}, |
| 182 | {FixedFieldsNames[FtFileOS], FtFileOS}, |
| 183 | {FixedFieldsNames[FtFileType], FtFileType}, |
| 184 | {FixedFieldsNames[FtFileSubtype], FtFileSubtype}}; |
| 185 | |
| 186 | VersionInfoFixedType VersionInfoFixed::getFixedType(StringRef Type) { |
| 187 | auto UpperType = Type.upper(); |
| 188 | auto Iter = FixedFieldsInfoMap.find(UpperType); |
| 189 | if (Iter != FixedFieldsInfoMap.end()) |
| 190 | return Iter->getValue(); |
| 191 | return FtUnknown; |
| 192 | } |
| 193 | |
| 194 | bool VersionInfoFixed::isTypeSupported(VersionInfoFixedType Type) { |
| 195 | return FtUnknown < Type && Type < FtNumTypes; |
| 196 | } |
| 197 | |
| 198 | bool VersionInfoFixed::isVersionType(VersionInfoFixedType Type) { |
| 199 | switch (Type) { |
| 200 | case FtFileVersion: |
| 201 | case FtProductVersion: |
| 202 | return true; |
| 203 | |
| 204 | default: |
| 205 | return false; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | raw_ostream &VersionInfoFixed::log(raw_ostream &OS) const { |
| 210 | for (int Type = FtUnknown; Type < FtNumTypes; ++Type) { |
| 211 | if (!isTypeSupported((VersionInfoFixedType)Type)) |
| 212 | continue; |
| 213 | OS << " Fixed: " << FixedFieldsNames[Type] << ":"; |
| 214 | for (uint32_t Val : FixedInfo[Type]) |
| 215 | OS << " " << Val; |
| 216 | OS << "\n"; |
| 217 | } |
| 218 | return OS; |
| 219 | } |
| 220 | |
| 221 | raw_ostream &VersionInfoResource::log(raw_ostream &OS) const { |
| 222 | OS << "VersionInfo (" << ResName << "):\n"; |
| 223 | FixedData.log(OS); |
| 224 | return MainBlock.log(OS); |
| 225 | } |
| 226 | |
Marek Sokolowski | b5f39a0 | 2017-09-29 00:14:18 +0000 | [diff] [blame] | 227 | raw_ostream &UserDefinedResource::log(raw_ostream &OS) const { |
| 228 | OS << "User-defined (type: " << Type << ", name: " << ResName << "): "; |
| 229 | if (IsFileResource) |
| 230 | return OS << FileLoc << "\n"; |
| 231 | OS << "data = "; |
| 232 | for (auto &Item : Contents) |
| 233 | OS << Item << " "; |
| 234 | return OS << "\n"; |
| 235 | } |
| 236 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 237 | raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const { |
| 238 | return OS << "Characteristics: " << Value << "\n"; |
| 239 | } |
| 240 | |
| 241 | raw_ostream &VersionStmt::log(raw_ostream &OS) const { |
| 242 | return OS << "Version: " << Value << "\n"; |
| 243 | } |
| 244 | |
Marek Sokolowski | 4ac54d9 | 2017-08-29 16:49:59 +0000 | [diff] [blame] | 245 | raw_ostream &CaptionStmt::log(raw_ostream &OS) const { |
| 246 | return OS << "Caption: " << Value << "\n"; |
| 247 | } |
| 248 | |
| 249 | raw_ostream &FontStmt::log(raw_ostream &OS) const { |
| 250 | return OS << "Font: size = " << Size << ", face = " << Typeface << "\n"; |
| 251 | } |
| 252 | |
| 253 | raw_ostream &StyleStmt::log(raw_ostream &OS) const { |
| 254 | return OS << "Style: " << Value << "\n"; |
| 255 | } |
| 256 | |
Marek Sokolowski | 5cd3d5c | 2017-08-18 18:24:17 +0000 | [diff] [blame] | 257 | } // namespace rc |
| 258 | } // namespace llvm |