blob: 8ff0e5bb19ccd419f1c9898315621ff3ae7b1576 [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"
18
19namespace llvm {
20namespace rc {
21
22// A class holding a name - either an integer or a reference to the string.
23class IntOrString {
24private:
25 union Data {
26 uint32_t Int;
27 StringRef String;
28 Data(uint32_t Value) : Int(Value) {}
29 Data(const StringRef Value) : String(Value) {}
30 Data(const RCToken &Token);
31 } Data;
32 bool IsInt;
33
34public:
35 IntOrString() : IntOrString(0) {}
36 IntOrString(uint32_t Value) : Data(Value), IsInt(1) {}
37 IntOrString(StringRef Value) : Data(Value), IsInt(0) {}
38 IntOrString(const RCToken &Token)
39 : Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {}
40
41 bool equalsLower(const char *Str) {
42 return !IsInt && Data.String.equals_lower(Str);
43 }
44
45 friend raw_ostream &operator<<(raw_ostream &, const IntOrString &);
46};
47
48// Base resource. All the resources should derive from this base.
49class RCResource {
50protected:
51 IntOrString ResName;
52
53public:
54 RCResource() = default;
55 RCResource(RCResource &&) = default;
56 void setName(const IntOrString &Name) { ResName = Name; }
57 virtual raw_ostream &log(raw_ostream &OS) const {
58 return OS << "Base statement\n";
59 };
60 virtual ~RCResource() {}
61};
62
63// Optional statement base. All such statements should derive from this base.
64class OptionalStmt : public RCResource {};
65
66class OptionalStmtList : public OptionalStmt {
67 std::vector<std::unique_ptr<OptionalStmt>> Statements;
68
69public:
70 OptionalStmtList() {}
71 virtual raw_ostream &log(raw_ostream &OS) const;
72
73 void addStmt(std::unique_ptr<OptionalStmt> Stmt) {
74 Statements.push_back(std::move(Stmt));
75 }
76};
77
78// LANGUAGE statement. It can occur both as a top-level statement (in such
79// a situation, it changes the default language until the end of the file)
80// and as an optional resource statement (then it changes the language
81// of a single resource).
82//
83// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx
84class LanguageResource : public OptionalStmt {
85 uint32_t Lang, SubLang;
86
87public:
88 LanguageResource(uint32_t LangId, uint32_t SubLangId)
89 : Lang(LangId), SubLang(SubLangId) {}
90 raw_ostream &log(raw_ostream &) const override;
91};
92
Marek Sokolowski72aa9372017-08-28 21:59:54 +000093// CURSOR resource. Represents a single cursor (".cur") file.
94//
95// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx
96class CursorResource : public RCResource {
97 StringRef CursorLoc;
98
99public:
100 CursorResource(StringRef Location) : CursorLoc(Location) {}
101 raw_ostream &log(raw_ostream &) const override;
102};
103
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000104// ICON resource. Represents a single ".ico" file containing a group of icons.
105//
106// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx
107class IconResource : public RCResource {
108 StringRef IconLoc;
109
110public:
111 IconResource(StringRef Location) : IconLoc(Location) {}
112 raw_ostream &log(raw_ostream &) const override;
113};
114
Marek Sokolowski72aa9372017-08-28 21:59:54 +0000115// HTML resource. Represents a local webpage that is to be embedded into the
116// resulting resource file. It embeds a file only - no additional resources
117// (images etc.) are included with this resource.
118//
119// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx
120class HTMLResource : public RCResource {
121 StringRef HTMLLoc;
122
123public:
124 HTMLResource(StringRef Location) : HTMLLoc(Location) {}
125 raw_ostream &log(raw_ostream &) const override;
126};
127
Marek Sokolowski5cd3d5c2017-08-18 18:24:17 +0000128// STRINGTABLE resource. Contains a list of strings, each having its unique ID.
129//
130// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx
131class StringTableResource : public RCResource {
132 OptionalStmtList OptStatements;
133 std::vector<std::pair<uint32_t, StringRef>> Table;
134
135public:
136 StringTableResource(OptionalStmtList &&OptStmts)
137 : OptStatements(std::move(OptStmts)) {}
138 void addString(uint32_t ID, StringRef String) {
139 Table.emplace_back(ID, String);
140 }
141 raw_ostream &log(raw_ostream &) const override;
142};
143
144// CHARACTERISTICS optional statement.
145//
146// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx
147class CharacteristicsStmt : public OptionalStmt {
148 uint32_t Value;
149
150public:
151 CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {}
152 raw_ostream &log(raw_ostream &) const override;
153};
154
155// VERSION optional statement.
156//
157// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx
158class VersionStmt : public OptionalStmt {
159 uint32_t Value;
160
161public:
162 VersionStmt(uint32_t Version) : Value(Version) {}
163 raw_ostream &log(raw_ostream &) const override;
164};
165
166} // namespace rc
167} // namespace llvm
168
169#endif