blob: eb123e543f0de029292f986a413975571fbbc096 [file] [log] [blame]
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +00001//
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
17namespace llvm {
18namespace rc {
19
20raw_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
27raw_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
35raw_ostream &LanguageResource::log(raw_ostream &OS) const {
36 return OS << "Language: " << Lang << ", Sublanguage: " << SubLang << "\n";
37}
38
Marek Sokolowski7f110522017-08-28 22:58:31 +000039StringRef AcceleratorsResource::Accelerator::OptionsStr
40 [AcceleratorsResource::Accelerator::NumFlags] = {
41 "ASCII", "VIRTKEY", "NOINVERT", "ALT", "SHIFT", "CONTROL"};
42
43raw_ostream &AcceleratorsResource::log(raw_ostream &OS) const {
44 OS << "Accelerators (" << ResName << "): \n";
45 OptStatements.log(OS);
46 for (const auto &Acc : Accelerators) {
47 OS << " Accelerator: " << Acc.Event << " " << Acc.Id;
48 for (size_t i = 0; i < Accelerator::NumFlags; ++i)
49 if (Acc.Flags & (1U << i))
50 OS << " " << Accelerator::OptionsStr[i];
51 OS << "\n";
52 }
53 return OS;
54}
55
Marek Sokolowski72aa9372017-08-28 21:59:54 +000056raw_ostream &CursorResource::log(raw_ostream &OS) const {
57 return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n";
58}
59
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +000060raw_ostream &IconResource::log(raw_ostream &OS) const {
61 return OS << "Icon (" << ResName << "): " << IconLoc << "\n";
62}
63
Marek Sokolowski72aa9372017-08-28 21:59:54 +000064raw_ostream &HTMLResource::log(raw_ostream &OS) const {
65 return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n";
66}
67
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +000068StringRef MenuDefinition::OptionsStr[MenuDefinition::NumFlags] = {
69 "CHECKED", "GRAYED", "HELP", "INACTIVE", "MENUBARBREAK", "MENUBREAK"};
70
71raw_ostream &MenuDefinition::logFlags(raw_ostream &OS, uint8_t Flags) {
72 for (size_t i = 0; i < NumFlags; ++i)
73 if (Flags & (1U << i))
74 OS << " " << OptionsStr[i];
75 return OS;
76}
77
78raw_ostream &MenuDefinitionList::log(raw_ostream &OS) const {
79 OS << " Menu list starts\n";
80 for (auto &Item : Definitions)
81 Item->log(OS);
82 return OS << " Menu list ends\n";
83}
84
85raw_ostream &MenuItem::log(raw_ostream &OS) const {
86 OS << " MenuItem (" << Name << "), ID = " << Id;
87 logFlags(OS, Flags);
88 return OS << "\n";
89}
90
91raw_ostream &MenuSeparator::log(raw_ostream &OS) const {
92 return OS << " Menu separator\n";
93}
94
95raw_ostream &PopupItem::log(raw_ostream &OS) const {
96 OS << " Popup (" << Name << ")";
97 logFlags(OS, Flags);
98 OS << ":\n";
99 return SubItems.log(OS);
100}
101
102raw_ostream &MenuResource::log(raw_ostream &OS) const {
103 OS << "Menu (" << ResName << "):\n";
104 OptStatements.log(OS);
105 return Elements.log(OS);
106}
107
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000108raw_ostream &StringTableResource::log(raw_ostream &OS) const {
109 OS << "StringTable:\n";
110 OptStatements.log(OS);
111 for (const auto &String : Table)
112 OS << " " << String.first << " => " << String.second << "\n";
113 return OS;
114}
115
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000116const StringSet<> Control::SupportedCtls = {
117 "LTEXT", "RTEXT", "CTEXT", "PUSHBUTTON", "DEFPUSHBUTTON", "EDITTEXT"};
118
119const StringSet<> Control::CtlsWithTitle = {"LTEXT", "RTEXT", "CTEXT",
120 "PUSHBUTTON", "DEFPUSHBUTTON"};
121
122raw_ostream &Control::log(raw_ostream &OS) const {
123 OS << " Control (" << ID << "): " << Type << ", title: " << Title
124 << ", loc: (" << X << ", " << Y << "), size: [" << Width << ", " << Height
125 << "]";
126 if (Style)
127 OS << ", style: " << *Style;
128 if (ExtStyle)
129 OS << ", ext. style: " << *ExtStyle;
130 if (HelpID)
131 OS << ", help ID: " << *HelpID;
132 return OS << "\n";
133}
134
135raw_ostream &DialogResource::log(raw_ostream &OS) const {
136 OS << "Dialog" << (IsExtended ? "Ex" : "") << " (" << ResName << "): loc: ("
137 << X << ", " << Y << "), size: [" << Width << ", " << Height
138 << "], help ID: " << HelpID << "\n";
139 OptStatements.log(OS);
140 for (auto &Ctl : Controls)
141 Ctl.log(OS);
142 return OS;
143}
144
Marek Sokolowskifb74cb12017-09-28 22:41:38 +0000145raw_ostream &VersionInfoBlock::log(raw_ostream &OS) const {
146 OS << " Start of block (name: " << Name << ")\n";
147 for (auto &Stmt : Stmts)
148 Stmt->log(OS);
149 return OS << " End of block\n";
150}
151
152raw_ostream &VersionInfoValue::log(raw_ostream &OS) const {
153 OS << " " << Key << " =>";
154 for (auto &Value : Values)
155 OS << " " << Value;
156 return OS << "\n";
157}
158
159using VersionInfoFixed = VersionInfoResource::VersionInfoFixed;
160using VersionInfoFixedType = VersionInfoFixed::VersionInfoFixedType;
161
162const StringRef
163 VersionInfoFixed::FixedFieldsNames[VersionInfoFixed::FtNumTypes] = {
164 "", "FILEVERSION", "PRODUCTVERSION", "FILEFLAGSMASK",
165 "FILEFLAGS", "FILEOS", "FILETYPE", "FILESUBTYPE"};
166
167const StringMap<VersionInfoFixedType> VersionInfoFixed::FixedFieldsInfoMap = {
168 {FixedFieldsNames[FtFileVersion], FtFileVersion},
169 {FixedFieldsNames[FtProductVersion], FtProductVersion},
170 {FixedFieldsNames[FtFileFlagsMask], FtFileFlagsMask},
171 {FixedFieldsNames[FtFileFlags], FtFileFlags},
172 {FixedFieldsNames[FtFileOS], FtFileOS},
173 {FixedFieldsNames[FtFileType], FtFileType},
174 {FixedFieldsNames[FtFileSubtype], FtFileSubtype}};
175
176VersionInfoFixedType VersionInfoFixed::getFixedType(StringRef Type) {
177 auto UpperType = Type.upper();
178 auto Iter = FixedFieldsInfoMap.find(UpperType);
179 if (Iter != FixedFieldsInfoMap.end())
180 return Iter->getValue();
181 return FtUnknown;
182}
183
184bool VersionInfoFixed::isTypeSupported(VersionInfoFixedType Type) {
185 return FtUnknown < Type && Type < FtNumTypes;
186}
187
188bool VersionInfoFixed::isVersionType(VersionInfoFixedType Type) {
189 switch (Type) {
190 case FtFileVersion:
191 case FtProductVersion:
192 return true;
193
194 default:
195 return false;
196 }
197}
198
199raw_ostream &VersionInfoFixed::log(raw_ostream &OS) const {
200 for (int Type = FtUnknown; Type < FtNumTypes; ++Type) {
201 if (!isTypeSupported((VersionInfoFixedType)Type))
202 continue;
203 OS << " Fixed: " << FixedFieldsNames[Type] << ":";
204 for (uint32_t Val : FixedInfo[Type])
205 OS << " " << Val;
206 OS << "\n";
207 }
208 return OS;
209}
210
211raw_ostream &VersionInfoResource::log(raw_ostream &OS) const {
212 OS << "VersionInfo (" << ResName << "):\n";
213 FixedData.log(OS);
214 return MainBlock.log(OS);
215}
216
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000217raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const {
218 return OS << "Characteristics: " << Value << "\n";
219}
220
221raw_ostream &VersionStmt::log(raw_ostream &OS) const {
222 return OS << "Version: " << Value << "\n";
223}
224
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000225raw_ostream &CaptionStmt::log(raw_ostream &OS) const {
226 return OS << "Caption: " << Value << "\n";
227}
228
229raw_ostream &FontStmt::log(raw_ostream &OS) const {
230 return OS << "Font: size = " << Size << ", face = " << Typeface << "\n";
231}
232
233raw_ostream &StyleStmt::log(raw_ostream &OS) const {
234 return OS << "Style: " << Value << "\n";
235}
236
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000237} // namespace rc
238} // namespace llvm