blob: 90fe0ac34651645ba45940452e38b1a0d8b1da38 [file] [log] [blame]
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +00001//===-- ResourceScriptStmt.h ------------------------------------*- C++-*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===---------------------------------------------------------------------===//
9//
10// This lists all the resource and statement types occurring in RC scripts.
11//
12//===---------------------------------------------------------------------===//
13
14#ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
15#define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
16
17#include "ResourceScriptToken.h"
Marek Sokolowski8f193432017-09-29 17:14:09 +000018#include "ResourceVisitor.h"
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +000019
Marek Sokolowski4ac54d92017-08-29 16:49:59 +000020#include "llvm/ADT/StringSet.h"
21
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +000022namespace llvm {
23namespace rc {
24
25// A class holding a name - either an integer or a reference to the string.
26class IntOrString {
27private:
28 union Data {
29 uint32_t Int;
30 StringRef String;
31 Data(uint32_t Value) : Int(Value) {}
32 Data(const StringRef Value) : String(Value) {}
Marek Sokolowski7f110522017-08-28 22:58:31 +000033 Data(const RCToken &Token) {
34 if (Token.kind() == RCToken::Kind::Int)
35 Int = Token.intValue();
36 else
37 String = Token.value();
38 }
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +000039 } Data;
40 bool IsInt;
41
42public:
43 IntOrString() : IntOrString(0) {}
44 IntOrString(uint32_t Value) : Data(Value), IsInt(1) {}
45 IntOrString(StringRef Value) : Data(Value), IsInt(0) {}
46 IntOrString(const RCToken &Token)
47 : Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {}
48
49 bool equalsLower(const char *Str) {
50 return !IsInt && Data.String.equals_lower(Str);
51 }
52
Marek Sokolowski8f193432017-09-29 17:14:09 +000053 bool isInt() const { return IsInt; }
54
55 uint32_t getInt() const {
56 assert(IsInt);
57 return Data.Int;
58 }
59
60 const StringRef &getString() const {
61 assert(!IsInt);
62 return Data.String;
63 }
64
65 operator Twine() const {
66 return isInt() ? Twine(getInt()) : Twine(getString());
67 }
68
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +000069 friend raw_ostream &operator<<(raw_ostream &, const IntOrString &);
70};
71
Marek Sokolowski8f193432017-09-29 17:14:09 +000072enum ResourceKind {
73 // These resource kinds have corresponding .res resource type IDs
74 // (TYPE in RESOURCEHEADER structure). The numeric value assigned to each
75 // kind is equal to this type ID.
76 RkNull = 0,
77 RkMenu = 4,
78 RkDialog = 5,
79 RkAccelerators = 9,
80 RkVersionInfo = 16,
81 RkHTML = 23,
82
83 // These kinds don't have assigned type IDs (they might be the resources
84 // of invalid kind, expand to many resource structures in .res files,
85 // or have variable type ID). In order to avoid ID clashes with IDs above,
86 // we assign the kinds the values 256 and larger.
87 RkInvalid = 256,
88 RkBase,
89 RkCursor,
90 RkIcon,
91 RkUser
92};
93
94// Non-zero memory flags.
95// Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648027(v=vs.85).aspx
96enum MemoryFlags {
97 MfMoveable = 0x10,
98 MfPure = 0x20,
99 MfPreload = 0x40,
100 MfDiscardable = 0x1000
101};
102
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000103// Base resource. All the resources should derive from this base.
104class RCResource {
Marek Sokolowski8f193432017-09-29 17:14:09 +0000105public:
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000106 IntOrString ResName;
107
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000108 RCResource() = default;
109 RCResource(RCResource &&) = default;
110 void setName(const IntOrString &Name) { ResName = Name; }
111 virtual raw_ostream &log(raw_ostream &OS) const {
112 return OS << "Base statement\n";
113 };
114 virtual ~RCResource() {}
Marek Sokolowski8f193432017-09-29 17:14:09 +0000115
116 virtual Error visit(Visitor *) const {
117 llvm_unreachable("This is unable to call methods from Visitor base");
118 }
119
120 // By default, memory flags are DISCARDABLE | PURE | MOVEABLE.
121 virtual uint16_t getMemoryFlags() const {
122 return MfDiscardable | MfPure | MfMoveable;
123 }
124 virtual ResourceKind getKind() const { return RkBase; }
125 static bool classof(const RCResource *Res) { return true; }
126
127 virtual IntOrString getResourceType() const {
128 llvm_unreachable("This cannot be called on objects without types.");
129 }
130 virtual Twine getResourceTypeName() const {
131 llvm_unreachable("This cannot be called on objects without types.");
132 };
133};
134
135// An empty resource. It has no content, type 0, ID 0 and all of its
136// characteristics are equal to 0.
137class NullResource : public RCResource {
138public:
139 raw_ostream &log(raw_ostream &OS) const override {
140 return OS << "Null resource\n";
141 }
142 Error visit(Visitor *V) const override { return V->visitNullResource(this); }
143 IntOrString getResourceType() const override { return 0; }
144 Twine getResourceTypeName() const override { return "(NULL)"; }
145 uint16_t getMemoryFlags() const override { return 0; }
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000146};
147
148// Optional statement base. All such statements should derive from this base.
149class OptionalStmt : public RCResource {};
150
151class OptionalStmtList : public OptionalStmt {
152 std::vector<std::unique_ptr<OptionalStmt>> Statements;
153
154public:
155 OptionalStmtList() {}
156 virtual raw_ostream &log(raw_ostream &OS) const;
157
158 void addStmt(std::unique_ptr<OptionalStmt> Stmt) {
159 Statements.push_back(std::move(Stmt));
160 }
161};
162
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000163class OptStatementsRCResource : public RCResource {
164public:
165 std::unique_ptr<OptionalStmtList> OptStatements;
166
167 OptStatementsRCResource(OptionalStmtList &&Stmts)
168 : OptStatements(llvm::make_unique<OptionalStmtList>(std::move(Stmts))) {}
169};
170
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000171// LANGUAGE statement. It can occur both as a top-level statement (in such
172// a situation, it changes the default language until the end of the file)
173// and as an optional resource statement (then it changes the language
174// of a single resource).
175//
176// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx
177class LanguageResource : public OptionalStmt {
Marek Sokolowski8f193432017-09-29 17:14:09 +0000178public:
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000179 uint32_t Lang, SubLang;
180
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000181 LanguageResource(uint32_t LangId, uint32_t SubLangId)
182 : Lang(LangId), SubLang(SubLangId) {}
183 raw_ostream &log(raw_ostream &) const override;
Marek Sokolowski8f193432017-09-29 17:14:09 +0000184
185 // This is not a regular top-level statement; when it occurs, it just
186 // modifies the language context.
187 Error visit(Visitor *V) const override { return V->visitLanguageStmt(this); }
188 Twine getResourceTypeName() const override { return "LANGUAGE"; }
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000189};
190
Marek Sokolowski7f110522017-08-28 22:58:31 +0000191// ACCELERATORS resource. Defines a named table of accelerators for the app.
192//
193// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380610(v=vs.85).aspx
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000194class AcceleratorsResource : public OptStatementsRCResource {
Marek Sokolowski7f110522017-08-28 22:58:31 +0000195public:
196 class Accelerator {
197 public:
198 IntOrString Event;
199 uint32_t Id;
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000200 uint16_t Flags;
Marek Sokolowski7f110522017-08-28 22:58:31 +0000201
202 enum Options {
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000203 // This is actually 0x0000 (accelerator is assumed to be ASCII if it's
204 // not VIRTKEY). However, rc.exe behavior is different in situations
205 // "only ASCII defined" and "neither ASCII nor VIRTKEY defined".
206 // Therefore, we include ASCII as another flag. This must be zeroed
207 // when serialized.
208 ASCII = 0x8000,
209 VIRTKEY = 0x0001,
210 NOINVERT = 0x0002,
211 ALT = 0x0010,
212 SHIFT = 0x0004,
213 CONTROL = 0x0008
Marek Sokolowski7f110522017-08-28 22:58:31 +0000214 };
215
216 static constexpr size_t NumFlags = 6;
217 static StringRef OptionsStr[NumFlags];
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000218 static uint32_t OptionsFlags[NumFlags];
Marek Sokolowski7f110522017-08-28 22:58:31 +0000219 };
220
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000221 using OptStatementsRCResource::OptStatementsRCResource;
222 void addAccelerator(IntOrString Event, uint32_t Id, uint16_t Flags) {
Marek Sokolowski7f110522017-08-28 22:58:31 +0000223 Accelerators.push_back(Accelerator{Event, Id, Flags});
224 }
225 raw_ostream &log(raw_ostream &) const override;
226
227private:
228 std::vector<Accelerator> Accelerators;
Marek Sokolowski7f110522017-08-28 22:58:31 +0000229};
230
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000231// CURSOR resource. Represents a single cursor (".cur") file.
232//
233// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx
234class CursorResource : public RCResource {
235 StringRef CursorLoc;
236
237public:
238 CursorResource(StringRef Location) : CursorLoc(Location) {}
239 raw_ostream &log(raw_ostream &) const override;
240};
241
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000242// ICON resource. Represents a single ".ico" file containing a group of icons.
243//
244// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx
245class IconResource : public RCResource {
246 StringRef IconLoc;
247
248public:
249 IconResource(StringRef Location) : IconLoc(Location) {}
250 raw_ostream &log(raw_ostream &) const override;
251};
252
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000253// HTML resource. Represents a local webpage that is to be embedded into the
254// resulting resource file. It embeds a file only - no additional resources
255// (images etc.) are included with this resource.
256//
257// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx
258class HTMLResource : public RCResource {
Marek Sokolowski8f193432017-09-29 17:14:09 +0000259public:
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000260 StringRef HTMLLoc;
261
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000262 HTMLResource(StringRef Location) : HTMLLoc(Location) {}
263 raw_ostream &log(raw_ostream &) const override;
Marek Sokolowski8f193432017-09-29 17:14:09 +0000264
265 Error visit(Visitor *V) const override { return V->visitHTMLResource(this); }
266
267 // Curiously, file resources don't have DISCARDABLE flag set.
268 uint16_t getMemoryFlags() const override { return MfPure | MfMoveable; }
269 IntOrString getResourceType() const override { return RkHTML; }
270 Twine getResourceTypeName() const override { return "HTML"; }
271 ResourceKind getKind() const override { return RkHTML; }
272 static bool classof(const RCResource *Res) {
273 return Res->getKind() == RkHTML;
274 }
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000275};
276
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000277// -- MENU resource and its helper classes --
278// This resource describes the contents of an application menu
279// (usually located in the upper part of the dialog.)
280//
281// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381025(v=vs.85).aspx
282
283// Description of a single submenu item.
284class MenuDefinition {
285public:
286 enum Options {
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000287 CHECKED = 0x0008,
288 GRAYED = 0x0001,
289 HELP = 0x4000,
290 INACTIVE = 0x0002,
291 MENUBARBREAK = 0x0020,
292 MENUBREAK = 0x0040
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000293 };
294
295 static constexpr size_t NumFlags = 6;
296 static StringRef OptionsStr[NumFlags];
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000297 static uint32_t OptionsFlags[NumFlags];
298 static raw_ostream &logFlags(raw_ostream &, uint16_t Flags);
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000299 virtual raw_ostream &log(raw_ostream &OS) const {
300 return OS << "Base menu definition\n";
301 }
302 virtual ~MenuDefinition() {}
303};
304
305// Recursive description of a whole submenu.
306class MenuDefinitionList : public MenuDefinition {
307 std::vector<std::unique_ptr<MenuDefinition>> Definitions;
308
309public:
310 void addDefinition(std::unique_ptr<MenuDefinition> Def) {
311 Definitions.push_back(std::move(Def));
312 }
313 raw_ostream &log(raw_ostream &) const override;
314};
315
316// Separator in MENU definition (MENUITEM SEPARATOR).
317//
318// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
319class MenuSeparator : public MenuDefinition {
320public:
321 raw_ostream &log(raw_ostream &) const override;
322};
323
324// MENUITEM statement definition.
325//
326// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
327class MenuItem : public MenuDefinition {
328 StringRef Name;
329 uint32_t Id;
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000330 uint16_t Flags;
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000331
332public:
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000333 MenuItem(StringRef Caption, uint32_t ItemId, uint16_t ItemFlags)
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000334 : Name(Caption), Id(ItemId), Flags(ItemFlags) {}
335 raw_ostream &log(raw_ostream &) const override;
336};
337
338// POPUP statement definition.
339//
340// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381030(v=vs.85).aspx
341class PopupItem : public MenuDefinition {
342 StringRef Name;
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000343 uint16_t Flags;
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000344 MenuDefinitionList SubItems;
345
346public:
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000347 PopupItem(StringRef Caption, uint16_t ItemFlags,
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000348 MenuDefinitionList &&SubItemsList)
349 : Name(Caption), Flags(ItemFlags), SubItems(std::move(SubItemsList)) {}
350 raw_ostream &log(raw_ostream &) const override;
351};
352
353// Menu resource definition.
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000354class MenuResource : public OptStatementsRCResource {
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000355 MenuDefinitionList Elements;
356
357public:
358 MenuResource(OptionalStmtList &&OptStmts, MenuDefinitionList &&Items)
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000359 : OptStatementsRCResource(std::move(OptStmts)),
360 Elements(std::move(Items)) {}
Marek Sokolowski99ecb0e2017-08-28 23:46:30 +0000361 raw_ostream &log(raw_ostream &) const override;
362};
363
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000364// STRINGTABLE resource. Contains a list of strings, each having its unique ID.
365//
366// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000367class StringTableResource : public OptStatementsRCResource {
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000368 std::vector<std::pair<uint32_t, StringRef>> Table;
369
370public:
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000371 using OptStatementsRCResource::OptStatementsRCResource;
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000372 void addString(uint32_t ID, StringRef String) {
373 Table.emplace_back(ID, String);
374 }
375 raw_ostream &log(raw_ostream &) const override;
376};
377
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000378// -- DIALOG(EX) resource and its helper classes --
379//
380// This resource describes dialog boxes and controls residing inside them.
381//
382// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381003(v=vs.85).aspx
383// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381002(v=vs.85).aspx
384
385// Single control definition.
386class Control {
387 StringRef Type, Title;
388 uint32_t ID, X, Y, Width, Height;
389 Optional<uint32_t> Style, ExtStyle, HelpID;
390
391public:
392 Control(StringRef CtlType, StringRef CtlTitle, uint32_t CtlID, uint32_t PosX,
393 uint32_t PosY, uint32_t ItemWidth, uint32_t ItemHeight,
394 Optional<uint32_t> ItemStyle, Optional<uint32_t> ExtItemStyle,
395 Optional<uint32_t> CtlHelpID)
396 : Type(CtlType), Title(CtlTitle), ID(CtlID), X(PosX), Y(PosY),
397 Width(ItemWidth), Height(ItemHeight), Style(ItemStyle),
398 ExtStyle(ExtItemStyle), HelpID(CtlHelpID) {}
399
400 static const StringSet<> SupportedCtls;
401 static const StringSet<> CtlsWithTitle;
402
403 raw_ostream &log(raw_ostream &) const;
404};
405
406// Single dialog definition. We don't create distinct classes for DIALOG and
407// DIALOGEX because of their being too similar to each other. We only have a
408// flag determining the type of the dialog box.
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000409class DialogResource : public OptStatementsRCResource {
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000410 uint32_t X, Y, Width, Height, HelpID;
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000411 std::vector<Control> Controls;
412 bool IsExtended;
413
414public:
415 DialogResource(uint32_t PosX, uint32_t PosY, uint32_t DlgWidth,
416 uint32_t DlgHeight, uint32_t DlgHelpID,
417 OptionalStmtList &&OptStmts, bool IsDialogEx)
Marek Sokolowskic75a0872017-09-29 17:46:32 +0000418 : OptStatementsRCResource(std::move(OptStmts)), X(PosX), Y(PosY),
419 Width(DlgWidth), Height(DlgHeight), HelpID(DlgHelpID),
420 IsExtended(IsDialogEx) {}
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000421
422 void addControl(Control &&Ctl) { Controls.push_back(std::move(Ctl)); }
423
424 raw_ostream &log(raw_ostream &) const override;
425};
426
Marek Sokolowskib5f39a02017-09-29 00:14:18 +0000427// User-defined resource. It is either:
428// * a link to the file, e.g. NAME TYPE "filename",
429// * or contains a list of integers and strings, e.g. NAME TYPE {1, "a", 2}.
430class UserDefinedResource : public RCResource {
431 IntOrString Type;
432 StringRef FileLoc;
433 std::vector<IntOrString> Contents;
434 bool IsFileResource;
435
436public:
437 UserDefinedResource(IntOrString ResourceType, StringRef FileLocation)
438 : Type(ResourceType), FileLoc(FileLocation), IsFileResource(true) {}
439 UserDefinedResource(IntOrString ResourceType, std::vector<IntOrString> &&Data)
440 : Type(ResourceType), Contents(std::move(Data)), IsFileResource(false) {}
441
442 raw_ostream &log(raw_ostream &) const override;
443};
444
Marek Sokolowskifb74cb12017-09-28 22:41:38 +0000445// -- VERSIONINFO resource and its helper classes --
446//
447// This resource lists the version information on the executable/library.
448// The declaration consists of the following items:
449// * A number of fixed optional version statements (e.g. FILEVERSION, FILEOS)
450// * BEGIN
451// * A number of BLOCK and/or VALUE statements. BLOCK recursively defines
452// another block of version information, whereas VALUE defines a
453// key -> value correspondence. There might be more than one value
454// corresponding to the single key.
455// * END
456//
457// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx
458
459// A single VERSIONINFO statement;
460class VersionInfoStmt {
461public:
462 virtual raw_ostream &log(raw_ostream &OS) const { return OS << "VI stmt\n"; }
463 virtual ~VersionInfoStmt() {}
464};
465
466// BLOCK definition; also the main VERSIONINFO declaration is considered a
467// BLOCK, although it has no name.
468// The correct top-level blocks are "VarFileInfo" and "StringFileInfo". We don't
469// care about them at the parsing phase.
470class VersionInfoBlock : public VersionInfoStmt {
471 std::vector<std::unique_ptr<VersionInfoStmt>> Stmts;
472 StringRef Name;
473
474public:
475 VersionInfoBlock(StringRef BlockName) : Name(BlockName) {}
476 void addStmt(std::unique_ptr<VersionInfoStmt> Stmt) {
477 Stmts.push_back(std::move(Stmt));
478 }
479 raw_ostream &log(raw_ostream &) const override;
480};
481
482class VersionInfoValue : public VersionInfoStmt {
483 StringRef Key;
484 std::vector<IntOrString> Values;
485
486public:
487 VersionInfoValue(StringRef InfoKey, std::vector<IntOrString> &&Vals)
488 : Key(InfoKey), Values(std::move(Vals)) {}
489 raw_ostream &log(raw_ostream &) const override;
490};
491
492class VersionInfoResource : public RCResource {
493public:
494 // A class listing fixed VERSIONINFO statements (occuring before main BEGIN).
495 // If any of these is not specified, it is assumed by the original tool to
496 // be equal to 0.
497 class VersionInfoFixed {
498 public:
499 enum VersionInfoFixedType {
500 FtUnknown,
501 FtFileVersion,
502 FtProductVersion,
503 FtFileFlagsMask,
504 FtFileFlags,
505 FtFileOS,
506 FtFileType,
507 FtFileSubtype,
508 FtNumTypes
509 };
510
511 private:
512 static const StringMap<VersionInfoFixedType> FixedFieldsInfoMap;
513 static const StringRef FixedFieldsNames[FtNumTypes];
514
515 public:
516 SmallVector<uint32_t, 4> FixedInfo[FtNumTypes];
517 SmallVector<bool, FtNumTypes> IsTypePresent;
518
519 static VersionInfoFixedType getFixedType(StringRef Type);
520 static bool isTypeSupported(VersionInfoFixedType Type);
521 static bool isVersionType(VersionInfoFixedType Type);
522
523 VersionInfoFixed() : IsTypePresent(FtNumTypes, false) {}
524
525 void setValue(VersionInfoFixedType Type, ArrayRef<uint32_t> Value) {
526 FixedInfo[Type] = SmallVector<uint32_t, 4>(Value.begin(), Value.end());
527 IsTypePresent[Type] = true;
528 }
529
530 raw_ostream &log(raw_ostream &) const;
531 };
532
533private:
534 VersionInfoBlock MainBlock;
535 VersionInfoFixed FixedData;
536
537public:
538 VersionInfoResource(VersionInfoBlock &&TopLevelBlock,
539 VersionInfoFixed &&FixedInfo)
540 : MainBlock(std::move(TopLevelBlock)), FixedData(std::move(FixedInfo)) {}
541
542 raw_ostream &log(raw_ostream &) const override;
543};
544
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000545// CHARACTERISTICS optional statement.
546//
547// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx
548class CharacteristicsStmt : public OptionalStmt {
549 uint32_t Value;
550
551public:
552 CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {}
553 raw_ostream &log(raw_ostream &) const override;
554};
555
556// VERSION optional statement.
557//
558// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx
559class VersionStmt : public OptionalStmt {
560 uint32_t Value;
561
562public:
563 VersionStmt(uint32_t Version) : Value(Version) {}
564 raw_ostream &log(raw_ostream &) const override;
565};
566
Marek Sokolowski4ac54d92017-08-29 16:49:59 +0000567// CAPTION optional statement.
568//
569// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380778(v=vs.85).aspx
570class CaptionStmt : public OptionalStmt {
571 StringRef Value;
572
573public:
574 CaptionStmt(StringRef Caption) : Value(Caption) {}
575 raw_ostream &log(raw_ostream &) const override;
576};
577
578// FONT optional statement.
579// Note that the documentation is inaccurate: it expects five arguments to be
580// given, however the example provides only two. In fact, the original tool
581// expects two arguments - point size and name of the typeface.
582//
583// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381013(v=vs.85).aspx
584class FontStmt : public OptionalStmt {
585 uint32_t Size;
586 StringRef Typeface;
587
588public:
589 FontStmt(uint32_t FontSize, StringRef FontName)
590 : Size(FontSize), Typeface(FontName) {}
591 raw_ostream &log(raw_ostream &) const override;
592};
593
594// STYLE optional statement.
595//
596// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381051(v=vs.85).aspx
597class StyleStmt : public OptionalStmt {
598 uint32_t Value;
599
600public:
601 StyleStmt(uint32_t Style) : Value(Style) {}
602 raw_ostream &log(raw_ostream &) const override;
603};
604
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000605} // namespace rc
606} // namespace llvm
607
608#endif