1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
//===-- ResourceScriptStmt.h ------------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===---------------------------------------------------------------------===//
//
// This lists all the resource and statement types occurring in RC scripts.
//
//===---------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
#define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
#include "ResourceScriptToken.h"
namespace llvm {
namespace rc {
// A class holding a name - either an integer or a reference to the string.
class IntOrString {
private:
union Data {
uint32_t Int;
StringRef String;
Data(uint32_t Value) : Int(Value) {}
Data(const StringRef Value) : String(Value) {}
Data(const RCToken &Token) {
if (Token.kind() == RCToken::Kind::Int)
Int = Token.intValue();
else
String = Token.value();
}
} Data;
bool IsInt;
public:
IntOrString() : IntOrString(0) {}
IntOrString(uint32_t Value) : Data(Value), IsInt(1) {}
IntOrString(StringRef Value) : Data(Value), IsInt(0) {}
IntOrString(const RCToken &Token)
: Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {}
bool equalsLower(const char *Str) {
return !IsInt && Data.String.equals_lower(Str);
}
friend raw_ostream &operator<<(raw_ostream &, const IntOrString &);
};
// Base resource. All the resources should derive from this base.
class RCResource {
protected:
IntOrString ResName;
public:
RCResource() = default;
RCResource(RCResource &&) = default;
void setName(const IntOrString &Name) { ResName = Name; }
virtual raw_ostream &log(raw_ostream &OS) const {
return OS << "Base statement\n";
};
virtual ~RCResource() {}
};
// Optional statement base. All such statements should derive from this base.
class OptionalStmt : public RCResource {};
class OptionalStmtList : public OptionalStmt {
std::vector<std::unique_ptr<OptionalStmt>> Statements;
public:
OptionalStmtList() {}
virtual raw_ostream &log(raw_ostream &OS) const;
void addStmt(std::unique_ptr<OptionalStmt> Stmt) {
Statements.push_back(std::move(Stmt));
}
};
// LANGUAGE statement. It can occur both as a top-level statement (in such
// a situation, it changes the default language until the end of the file)
// and as an optional resource statement (then it changes the language
// of a single resource).
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx
class LanguageResource : public OptionalStmt {
uint32_t Lang, SubLang;
public:
LanguageResource(uint32_t LangId, uint32_t SubLangId)
: Lang(LangId), SubLang(SubLangId) {}
raw_ostream &log(raw_ostream &) const override;
};
// ACCELERATORS resource. Defines a named table of accelerators for the app.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380610(v=vs.85).aspx
class AcceleratorsResource : public RCResource {
public:
class Accelerator {
public:
IntOrString Event;
uint32_t Id;
uint8_t Flags;
enum Options {
ASCII = (1 << 0),
VIRTKEY = (1 << 1),
NOINVERT = (1 << 2),
ALT = (1 << 3),
SHIFT = (1 << 4),
CONTROL = (1 << 5)
};
static constexpr size_t NumFlags = 6;
static StringRef OptionsStr[NumFlags];
};
AcceleratorsResource(OptionalStmtList &&OptStmts)
: OptStatements(std::move(OptStmts)) {}
void addAccelerator(IntOrString Event, uint32_t Id, uint8_t Flags) {
Accelerators.push_back(Accelerator{Event, Id, Flags});
}
raw_ostream &log(raw_ostream &) const override;
private:
std::vector<Accelerator> Accelerators;
OptionalStmtList OptStatements;
};
// CURSOR resource. Represents a single cursor (".cur") file.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx
class CursorResource : public RCResource {
StringRef CursorLoc;
public:
CursorResource(StringRef Location) : CursorLoc(Location) {}
raw_ostream &log(raw_ostream &) const override;
};
// ICON resource. Represents a single ".ico" file containing a group of icons.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx
class IconResource : public RCResource {
StringRef IconLoc;
public:
IconResource(StringRef Location) : IconLoc(Location) {}
raw_ostream &log(raw_ostream &) const override;
};
// HTML resource. Represents a local webpage that is to be embedded into the
// resulting resource file. It embeds a file only - no additional resources
// (images etc.) are included with this resource.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx
class HTMLResource : public RCResource {
StringRef HTMLLoc;
public:
HTMLResource(StringRef Location) : HTMLLoc(Location) {}
raw_ostream &log(raw_ostream &) const override;
};
// -- MENU resource and its helper classes --
// This resource describes the contents of an application menu
// (usually located in the upper part of the dialog.)
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381025(v=vs.85).aspx
// Description of a single submenu item.
class MenuDefinition {
public:
enum Options {
CHECKED = (1 << 0),
GRAYED = (1 << 1),
HELP = (1 << 2),
INACTIVE = (1 << 3),
MENUBARBREAK = (1 << 4),
MENUBREAK = (1 << 5)
};
static constexpr size_t NumFlags = 6;
static StringRef OptionsStr[NumFlags];
static raw_ostream &logFlags(raw_ostream &, uint8_t Flags);
virtual raw_ostream &log(raw_ostream &OS) const {
return OS << "Base menu definition\n";
}
virtual ~MenuDefinition() {}
};
// Recursive description of a whole submenu.
class MenuDefinitionList : public MenuDefinition {
std::vector<std::unique_ptr<MenuDefinition>> Definitions;
public:
void addDefinition(std::unique_ptr<MenuDefinition> Def) {
Definitions.push_back(std::move(Def));
}
raw_ostream &log(raw_ostream &) const override;
};
// Separator in MENU definition (MENUITEM SEPARATOR).
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
class MenuSeparator : public MenuDefinition {
public:
raw_ostream &log(raw_ostream &) const override;
};
// MENUITEM statement definition.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
class MenuItem : public MenuDefinition {
StringRef Name;
uint32_t Id;
uint8_t Flags;
public:
MenuItem(StringRef Caption, uint32_t ItemId, uint8_t ItemFlags)
: Name(Caption), Id(ItemId), Flags(ItemFlags) {}
raw_ostream &log(raw_ostream &) const override;
};
// POPUP statement definition.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381030(v=vs.85).aspx
class PopupItem : public MenuDefinition {
StringRef Name;
uint8_t Flags;
MenuDefinitionList SubItems;
public:
PopupItem(StringRef Caption, uint8_t ItemFlags,
MenuDefinitionList &&SubItemsList)
: Name(Caption), Flags(ItemFlags), SubItems(std::move(SubItemsList)) {}
raw_ostream &log(raw_ostream &) const override;
};
// Menu resource definition.
class MenuResource : public RCResource {
OptionalStmtList OptStatements;
MenuDefinitionList Elements;
public:
MenuResource(OptionalStmtList &&OptStmts, MenuDefinitionList &&Items)
: OptStatements(std::move(OptStmts)), Elements(std::move(Items)) {}
raw_ostream &log(raw_ostream &) const override;
};
// STRINGTABLE resource. Contains a list of strings, each having its unique ID.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx
class StringTableResource : public RCResource {
OptionalStmtList OptStatements;
std::vector<std::pair<uint32_t, StringRef>> Table;
public:
StringTableResource(OptionalStmtList &&OptStmts)
: OptStatements(std::move(OptStmts)) {}
void addString(uint32_t ID, StringRef String) {
Table.emplace_back(ID, String);
}
raw_ostream &log(raw_ostream &) const override;
};
// CHARACTERISTICS optional statement.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx
class CharacteristicsStmt : public OptionalStmt {
uint32_t Value;
public:
CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {}
raw_ostream &log(raw_ostream &) const override;
};
// VERSION optional statement.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx
class VersionStmt : public OptionalStmt {
uint32_t Value;
public:
VersionStmt(uint32_t Version) : Value(Version) {}
raw_ostream &log(raw_ostream &) const override;
};
} // namespace rc
} // namespace llvm
#endif
|