OSDN Git Service

[llvm-rc] Implement the BITMAP resource type
[android-x86/external-llvm.git] / tools / llvm-rc / ResourceScriptStmt.cpp
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 &BitmapResource::log(raw_ostream &OS) const {
61   return OS << "Bitmap (" << ResName << "): " << BitmapLoc << "\n";
62 }
63
64 raw_ostream &CursorResource::log(raw_ostream &OS) const {
65   return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n";
66 }
67
68 raw_ostream &IconResource::log(raw_ostream &OS) const {
69   return OS << "Icon (" << ResName << "): " << IconLoc << "\n";
70 }
71
72 raw_ostream &HTMLResource::log(raw_ostream &OS) const {
73   return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n";
74 }
75
76 StringRef MenuDefinition::OptionsStr[MenuDefinition::NumFlags] = {
77     "CHECKED", "GRAYED", "HELP", "INACTIVE", "MENUBARBREAK", "MENUBREAK"};
78
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) {
83   for (size_t i = 0; i < NumFlags; ++i)
84     if (Flags & OptionsFlags[i])
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";
115   OptStatements->log(OS);
116   return Elements.log(OS);
117 }
118
119 raw_ostream &StringTableResource::log(raw_ostream &OS) const {
120   OS << "StringTable:\n";
121   OptStatements->log(OS);
122   for (const auto &String : Table)
123     OS << "  " << String.first << " => " << String.second << "\n";
124   return OS;
125 }
126
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}},
131     {"PUSHBUTTON", CtlInfo{0x50010000, ClsButton, true}},
132     {"DEFPUSHBUTTON", CtlInfo{0x50010001, ClsButton, true}},
133     {"EDITTEXT", CtlInfo{0x50810000, ClsEdit, false}},
134 };
135
136 raw_ostream &Control::log(raw_ostream &OS) const {
137   OS << "  Control (" << ID << "): " << Type << ", title: " << Title
138      << ", loc: (" << X << ", " << Y << "), size: [" << Width << ", " << Height
139      << "]";
140   if (Style)
141     OS << ", style: " << *Style;
142   if (ExtStyle)
143     OS << ", ext. style: " << *ExtStyle;
144   if (HelpID)
145     OS << ", help ID: " << *HelpID;
146   return OS << "\n";
147 }
148
149 raw_ostream &DialogResource::log(raw_ostream &OS) const {
150   OS << "Dialog" << (IsExtended ? "Ex" : "") << " (" << ResName << "): loc: ("
151      << X << ", " << Y << "), size: [" << Width << ", " << Height
152      << "], help ID: " << HelpID << "\n";
153   OptStatements->log(OS);
154   for (auto &Ctl : Controls)
155     Ctl.log(OS);
156   return OS;
157 }
158
159 raw_ostream &VersionInfoBlock::log(raw_ostream &OS) const {
160   OS << "  Start of block (name: " << Name << ")\n";
161   for (auto &Stmt : Stmts)
162     Stmt->log(OS);
163   return OS << "  End of block\n";
164 }
165
166 raw_ostream &VersionInfoValue::log(raw_ostream &OS) const {
167   OS << "  " << Key << " =>";
168   size_t NumValues = Values.size();
169   for (size_t Id = 0; Id < NumValues; ++Id) {
170     if (Id > 0 && HasPrecedingComma[Id])
171       OS << ",";
172     OS << " " << Values[Id];
173   }
174   return OS << "\n";
175 }
176
177 using VersionInfoFixed = VersionInfoResource::VersionInfoFixed;
178 using VersionInfoFixedType = VersionInfoFixed::VersionInfoFixedType;
179
180 const StringRef
181     VersionInfoFixed::FixedFieldsNames[VersionInfoFixed::FtNumTypes] = {
182         "",          "FILEVERSION", "PRODUCTVERSION", "FILEFLAGSMASK",
183         "FILEFLAGS", "FILEOS",      "FILETYPE",       "FILESUBTYPE"};
184
185 const StringMap<VersionInfoFixedType> VersionInfoFixed::FixedFieldsInfoMap = {
186     {FixedFieldsNames[FtFileVersion], FtFileVersion},
187     {FixedFieldsNames[FtProductVersion], FtProductVersion},
188     {FixedFieldsNames[FtFileFlagsMask], FtFileFlagsMask},
189     {FixedFieldsNames[FtFileFlags], FtFileFlags},
190     {FixedFieldsNames[FtFileOS], FtFileOS},
191     {FixedFieldsNames[FtFileType], FtFileType},
192     {FixedFieldsNames[FtFileSubtype], FtFileSubtype}};
193
194 VersionInfoFixedType VersionInfoFixed::getFixedType(StringRef Type) {
195   auto UpperType = Type.upper();
196   auto Iter = FixedFieldsInfoMap.find(UpperType);
197   if (Iter != FixedFieldsInfoMap.end())
198     return Iter->getValue();
199   return FtUnknown;
200 }
201
202 bool VersionInfoFixed::isTypeSupported(VersionInfoFixedType Type) {
203   return FtUnknown < Type && Type < FtNumTypes;
204 }
205
206 bool VersionInfoFixed::isVersionType(VersionInfoFixedType Type) {
207   switch (Type) {
208   case FtFileVersion:
209   case FtProductVersion:
210     return true;
211
212   default:
213     return false;
214   }
215 }
216
217 raw_ostream &VersionInfoFixed::log(raw_ostream &OS) const {
218   for (int Type = FtUnknown; Type < FtNumTypes; ++Type) {
219     if (!isTypeSupported((VersionInfoFixedType)Type))
220       continue;
221     OS << "  Fixed: " << FixedFieldsNames[Type] << ":";
222     for (uint32_t Val : FixedInfo[Type])
223       OS << " " << Val;
224     OS << "\n";
225   }
226   return OS;
227 }
228
229 raw_ostream &VersionInfoResource::log(raw_ostream &OS) const {
230   OS << "VersionInfo (" << ResName << "):\n";
231   FixedData.log(OS);
232   return MainBlock.log(OS);
233 }
234
235 raw_ostream &UserDefinedResource::log(raw_ostream &OS) const {
236   OS << "User-defined (type: " << Type << ", name: " << ResName << "): ";
237   if (IsFileResource)
238     return OS << FileLoc << "\n";
239   OS << "data = ";
240   for (auto &Item : Contents)
241     OS << Item << " ";
242   return OS << "\n";
243 }
244
245 raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const {
246   return OS << "Characteristics: " << Value << "\n";
247 }
248
249 raw_ostream &VersionStmt::log(raw_ostream &OS) const {
250   return OS << "Version: " << Value << "\n";
251 }
252
253 raw_ostream &CaptionStmt::log(raw_ostream &OS) const {
254   return OS << "Caption: " << Value << "\n";
255 }
256
257 raw_ostream &FontStmt::log(raw_ostream &OS) const {
258   OS << "Font: size = " << Size << ", face = " << Name
259      << ", weight = " << Weight;
260   if (Italic)
261     OS << ", italic";
262   return OS << ", charset = " << Charset << "\n";
263 }
264
265 raw_ostream &StyleStmt::log(raw_ostream &OS) const {
266   return OS << "Style: " << Value << "\n";
267 }
268
269 } // namespace rc
270 } // namespace llvm