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 39 StringRef AcceleratorsResource::Accelerator::OptionsStr 40 [AcceleratorsResource::Accelerator::NumFlags] = { 41 "ASCII", "VIRTKEY", "NOINVERT", "ALT", "SHIFT", "CONTROL"}; 42 43 uint32_t AcceleratorsResource::Accelerator::OptionsFlags 44 [AcceleratorsResource::Accelerator::NumFlags] = {ASCII, VIRTKEY, NOINVERT, 45 ALT, SHIFT, CONTROL}; 46 47 raw_ostream &AcceleratorsResource::log(raw_ostream &OS) const { 48 OS << "Accelerators (" << ResName << "): \n"; 49 OptStatements->log(OS); 50 for (const auto &Acc : Accelerators) { 51 OS << " Accelerator: " << Acc.Event << " " << Acc.Id; 52 for (size_t i = 0; i < Accelerator::NumFlags; ++i) 53 if (Acc.Flags & Accelerator::OptionsFlags[i]) 54 OS << " " << Accelerator::OptionsStr[i]; 55 OS << "\n"; 56 } 57 return OS; 58 } 59 60 raw_ostream &CursorResource::log(raw_ostream &OS) const { 61 return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n"; 62 } 63 64 raw_ostream &IconResource::log(raw_ostream &OS) const { 65 return OS << "Icon (" << ResName << "): " << IconLoc << "\n"; 66 } 67 68 raw_ostream &HTMLResource::log(raw_ostream &OS) const { 69 return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n"; 70 } 71 72 StringRef MenuDefinition::OptionsStr[MenuDefinition::NumFlags] = { 73 "CHECKED", "GRAYED", "HELP", "INACTIVE", "MENUBARBREAK", "MENUBREAK"}; 74 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) { 79 for (size_t i = 0; i < NumFlags; ++i) 80 if (Flags & OptionsFlags[i]) 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"; 111 OptStatements->log(OS); 112 return Elements.log(OS); 113 } 114 115 raw_ostream &StringTableResource::log(raw_ostream &OS) const { 116 OS << "StringTable:\n"; 117 OptStatements->log(OS); 118 for (const auto &String : Table) 119 OS << " " << String.first << " => " << String.second << "\n"; 120 return OS; 121 } 122 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 }; 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"; 149 OptStatements->log(OS); 150 for (auto &Ctl : Controls) 151 Ctl.log(OS); 152 return OS; 153 } 154 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 size_t NumValues = Values.size(); 165 for (size_t Id = 0; Id < NumValues; ++Id) { 166 if (Id > 0 && HasPrecedingComma[Id]) 167 OS << ","; 168 OS << " " << Values[Id]; 169 } 170 return OS << "\n"; 171 } 172 173 using VersionInfoFixed = VersionInfoResource::VersionInfoFixed; 174 using VersionInfoFixedType = VersionInfoFixed::VersionInfoFixedType; 175 176 const StringRef 177 VersionInfoFixed::FixedFieldsNames[VersionInfoFixed::FtNumTypes] = { 178 "", "FILEVERSION", "PRODUCTVERSION", "FILEFLAGSMASK", 179 "FILEFLAGS", "FILEOS", "FILETYPE", "FILESUBTYPE"}; 180 181 const StringMap<VersionInfoFixedType> VersionInfoFixed::FixedFieldsInfoMap = { 182 {FixedFieldsNames[FtFileVersion], FtFileVersion}, 183 {FixedFieldsNames[FtProductVersion], FtProductVersion}, 184 {FixedFieldsNames[FtFileFlagsMask], FtFileFlagsMask}, 185 {FixedFieldsNames[FtFileFlags], FtFileFlags}, 186 {FixedFieldsNames[FtFileOS], FtFileOS}, 187 {FixedFieldsNames[FtFileType], FtFileType}, 188 {FixedFieldsNames[FtFileSubtype], FtFileSubtype}}; 189 190 VersionInfoFixedType VersionInfoFixed::getFixedType(StringRef Type) { 191 auto UpperType = Type.upper(); 192 auto Iter = FixedFieldsInfoMap.find(UpperType); 193 if (Iter != FixedFieldsInfoMap.end()) 194 return Iter->getValue(); 195 return FtUnknown; 196 } 197 198 bool VersionInfoFixed::isTypeSupported(VersionInfoFixedType Type) { 199 return FtUnknown < Type && Type < FtNumTypes; 200 } 201 202 bool VersionInfoFixed::isVersionType(VersionInfoFixedType Type) { 203 switch (Type) { 204 case FtFileVersion: 205 case FtProductVersion: 206 return true; 207 208 default: 209 return false; 210 } 211 } 212 213 raw_ostream &VersionInfoFixed::log(raw_ostream &OS) const { 214 for (int Type = FtUnknown; Type < FtNumTypes; ++Type) { 215 if (!isTypeSupported((VersionInfoFixedType)Type)) 216 continue; 217 OS << " Fixed: " << FixedFieldsNames[Type] << ":"; 218 for (uint32_t Val : FixedInfo[Type]) 219 OS << " " << Val; 220 OS << "\n"; 221 } 222 return OS; 223 } 224 225 raw_ostream &VersionInfoResource::log(raw_ostream &OS) const { 226 OS << "VersionInfo (" << ResName << "):\n"; 227 FixedData.log(OS); 228 return MainBlock.log(OS); 229 } 230 231 raw_ostream &UserDefinedResource::log(raw_ostream &OS) const { 232 OS << "User-defined (type: " << Type << ", name: " << ResName << "): "; 233 if (IsFileResource) 234 return OS << FileLoc << "\n"; 235 OS << "data = "; 236 for (auto &Item : Contents) 237 OS << Item << " "; 238 return OS << "\n"; 239 } 240 241 raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const { 242 return OS << "Characteristics: " << Value << "\n"; 243 } 244 245 raw_ostream &VersionStmt::log(raw_ostream &OS) const { 246 return OS << "Version: " << Value << "\n"; 247 } 248 249 raw_ostream &CaptionStmt::log(raw_ostream &OS) const { 250 return OS << "Caption: " << Value << "\n"; 251 } 252 253 raw_ostream &FontStmt::log(raw_ostream &OS) const { 254 OS << "Font: size = " << Size << ", face = " << Name 255 << ", weight = " << Weight; 256 if (Italic) 257 OS << ", italic"; 258 return OS << ", charset = " << Charset << "\n"; 259 } 260 261 raw_ostream &StyleStmt::log(raw_ostream &OS) const { 262 return OS << "Style: " << Value << "\n"; 263 } 264 265 } // namespace rc 266 } // namespace llvm 267