annotate tools/llvm-rc/ResourceScriptStmt.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- ResourceScriptStmt.h ------------------------------------*- C++-*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //===---------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 // This lists all the resource and statement types occurring in RC scripts.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //===---------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTSTMT_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "ResourceScriptToken.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "ResourceVisitor.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/ADT/StringSet.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 namespace rc {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 // Integer wrapper that also holds information whether the user declared
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 // the integer to be long (by appending L to the end of the integer) or not.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 // It allows to be implicitly cast from and to uint32_t in order
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 // to be compatible with the parts of code that don't care about the integers
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 // being marked long.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 class RCInt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 uint32_t Val;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 bool Long;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 RCInt(const RCToken &Token)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 : Val(Token.intValue()), Long(Token.isLongInt()) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 RCInt(uint32_t Value) : Val(Value), Long(false) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 RCInt(uint32_t Value, bool IsLong) : Val(Value), Long(IsLong) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 operator uint32_t() const { return Val; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 bool isLong() const { return Long; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 RCInt &operator+=(const RCInt &Rhs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 std::tie(Val, Long) = std::make_pair(Val + Rhs.Val, Long | Rhs.Long);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 return *this;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 RCInt &operator-=(const RCInt &Rhs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 std::tie(Val, Long) = std::make_pair(Val - Rhs.Val, Long | Rhs.Long);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 return *this;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 RCInt &operator|=(const RCInt &Rhs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 std::tie(Val, Long) = std::make_pair(Val | Rhs.Val, Long | Rhs.Long);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 return *this;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 RCInt &operator&=(const RCInt &Rhs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 std::tie(Val, Long) = std::make_pair(Val & Rhs.Val, Long | Rhs.Long);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 return *this;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 RCInt operator-() const { return {-Val, Long}; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 RCInt operator~() const { return {~Val, Long}; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 friend raw_ostream &operator<<(raw_ostream &OS, const RCInt &Int) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 return OS << Int.Val << (Int.Long ? "L" : "");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
69 class IntWithNotMask {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
70 private:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
71 RCInt Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
72 int32_t NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
73
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
74 public:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
75 IntWithNotMask() : IntWithNotMask(RCInt(0)) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
76 IntWithNotMask(RCInt Value, int32_t NotMask = 0) : Value(Value), NotMask(NotMask) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
77
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
78 RCInt getValue() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
79 return Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
80 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
81
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
82 uint32_t getNotMask() const {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
83 return NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
84 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
85
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
86 IntWithNotMask &operator+=(const IntWithNotMask &Rhs) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
87 Value &= ~Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
88 Value += Rhs.Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
89 NotMask |= Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
90 return *this;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
91 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
92
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
93 IntWithNotMask &operator-=(const IntWithNotMask &Rhs) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
94 Value &= ~Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
95 Value -= Rhs.Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
96 NotMask |= Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
97 return *this;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
98 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
99
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
100 IntWithNotMask &operator|=(const IntWithNotMask &Rhs) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
101 Value &= ~Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
102 Value |= Rhs.Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
103 NotMask |= Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
104 return *this;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
105 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
106
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
107 IntWithNotMask &operator&=(const IntWithNotMask &Rhs) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
108 Value &= ~Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
109 Value &= Rhs.Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
110 NotMask |= Rhs.NotMask;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
111 return *this;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
112 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
113
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
114 IntWithNotMask operator-() const { return {-Value, NotMask}; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
115 IntWithNotMask operator~() const { return {~Value, 0}; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
116
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
117 friend raw_ostream &operator<<(raw_ostream &OS, const IntWithNotMask &Int) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
118 return OS << Int.Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
119 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
120 };
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
121
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 // A class holding a name - either an integer or a reference to the string.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 class IntOrString {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 union Data {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 RCInt Int;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 StringRef String;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 Data(RCInt Value) : Int(Value) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 Data(const StringRef Value) : String(Value) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 Data(const RCToken &Token) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 if (Token.kind() == RCToken::Kind::Int)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 Int = RCInt(Token);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 else
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 String = Token.value();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 } Data;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 bool IsInt;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 IntOrString() : IntOrString(RCInt(0)) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 IntOrString(uint32_t Value) : Data(Value), IsInt(1) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 IntOrString(RCInt Value) : Data(Value), IsInt(1) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 IntOrString(StringRef Value) : Data(Value), IsInt(0) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 IntOrString(const RCToken &Token)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 : Data(Token), IsInt(Token.kind() == RCToken::Kind::Int) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 bool equalsLower(const char *Str) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 return !IsInt && Data.String.equals_lower(Str);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 bool isInt() const { return IsInt; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 RCInt getInt() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 assert(IsInt);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 return Data.Int;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 const StringRef &getString() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 assert(!IsInt);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 return Data.String;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 operator Twine() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 return isInt() ? Twine(getInt()) : Twine(getString());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 friend raw_ostream &operator<<(raw_ostream &, const IntOrString &);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 enum ResourceKind {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 // These resource kinds have corresponding .res resource type IDs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 // (TYPE in RESOURCEHEADER structure). The numeric value assigned to each
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 // kind is equal to this type ID.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 RkNull = 0,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 RkSingleCursor = 1,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
176 RkBitmap = 2,
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 RkSingleIcon = 3,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 RkMenu = 4,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179 RkDialog = 5,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 RkStringTableBundle = 6,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 RkAccelerators = 9,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
182 RkRcData = 10,
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 RkCursorGroup = 12,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 RkIconGroup = 14,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185 RkVersionInfo = 16,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186 RkHTML = 23,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 // These kinds don't have assigned type IDs (they might be the resources
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189 // of invalid kind, expand to many resource structures in .res files,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 // or have variable type ID). In order to avoid ID clashes with IDs above,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 // we assign the kinds the values 256 and larger.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 RkInvalid = 256,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193 RkBase,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 RkCursor,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 RkIcon,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 RkStringTable,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197 RkUser,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 RkSingleCursorOrIconRes,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 RkCursorOrIconGroupRes,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202 // Non-zero memory flags.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648027(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 enum MemoryFlags {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205 MfMoveable = 0x10,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 MfPure = 0x20,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207 MfPreload = 0x40,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 MfDiscardable = 0x1000
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 // Base resource. All the resources should derive from this base.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 class RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 IntOrString ResName;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
215 uint16_t MemoryFlags = getDefaultMemoryFlags();
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 void setName(const IntOrString &Name) { ResName = Name; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 virtual raw_ostream &log(raw_ostream &OS) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 return OS << "Base statement\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 };
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
220 RCResource() {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
221 RCResource(uint16_t Flags) : MemoryFlags(Flags) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 virtual ~RCResource() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 virtual Error visit(Visitor *) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225 llvm_unreachable("This is unable to call methods from Visitor base");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228 // Apply the statements attached to this resource. Generic resources
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229 // don't have any.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230 virtual Error applyStmts(Visitor *) const { return Error::success(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232 // By default, memory flags are DISCARDABLE | PURE | MOVEABLE.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
233 static uint16_t getDefaultMemoryFlags() {
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234 return MfDiscardable | MfPure | MfMoveable;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
236
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237 virtual ResourceKind getKind() const { return RkBase; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238 static bool classof(const RCResource *Res) { return true; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 virtual IntOrString getResourceType() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241 llvm_unreachable("This cannot be called on objects without types.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243 virtual Twine getResourceTypeName() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244 llvm_unreachable("This cannot be called on objects without types.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
248 // An empty resource. It has no content, type 0, ID 0 and all of its
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
249 // characteristics are equal to 0.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
250 class NullResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
251 public:
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
252 NullResource() : RCResource(0) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
253 raw_ostream &log(raw_ostream &OS) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
254 return OS << "Null resource\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
255 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
256 Error visit(Visitor *V) const override { return V->visitNullResource(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
257 IntOrString getResourceType() const override { return 0; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
258 Twine getResourceTypeName() const override { return "(NULL)"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
259 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
260
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
261 // Optional statement base. All such statements should derive from this base.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
262 class OptionalStmt : public RCResource {};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
263
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
264 class OptionalStmtList : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
265 std::vector<std::unique_ptr<OptionalStmt>> Statements;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
266
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
267 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
268 OptionalStmtList() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
269 raw_ostream &log(raw_ostream &OS) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
270
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
271 void addStmt(std::unique_ptr<OptionalStmt> Stmt) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
272 Statements.push_back(std::move(Stmt));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
273 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
274
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
275 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
276 for (auto &StmtPtr : Statements)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
277 if (auto Err = StmtPtr->visit(V))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
278 return Err;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
279 return Error::success();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
280 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
281 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
282
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
283 class OptStatementsRCResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
284 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
285 std::unique_ptr<OptionalStmtList> OptStatements;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
286
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
287 OptStatementsRCResource(OptionalStmtList &&Stmts,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
288 uint16_t Flags = RCResource::getDefaultMemoryFlags())
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
289 : RCResource(Flags),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
290 OptStatements(llvm::make_unique<OptionalStmtList>(std::move(Stmts))) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
291
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
292 virtual Error applyStmts(Visitor *V) const { return OptStatements->visit(V); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
293 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
294
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
295 // LANGUAGE statement. It can occur both as a top-level statement (in such
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
296 // a situation, it changes the default language until the end of the file)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
297 // and as an optional resource statement (then it changes the language
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
298 // of a single resource).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
299 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
300 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381019(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
301 class LanguageResource : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
302 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
303 uint32_t Lang, SubLang;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
304
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
305 LanguageResource(uint32_t LangId, uint32_t SubLangId)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
306 : Lang(LangId), SubLang(SubLangId) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
307 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
308
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
309 // This is not a regular top-level statement; when it occurs, it just
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
310 // modifies the language context.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
311 Error visit(Visitor *V) const override { return V->visitLanguageStmt(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
312 Twine getResourceTypeName() const override { return "LANGUAGE"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
313 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
314
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
315 // ACCELERATORS resource. Defines a named table of accelerators for the app.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
316 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
317 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380610(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
318 class AcceleratorsResource : public OptStatementsRCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
319 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
320 class Accelerator {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
321 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
322 IntOrString Event;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
323 uint32_t Id;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
324 uint16_t Flags;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
325
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
326 enum Options {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
327 // This is actually 0x0000 (accelerator is assumed to be ASCII if it's
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
328 // not VIRTKEY). However, rc.exe behavior is different in situations
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
329 // "only ASCII defined" and "neither ASCII nor VIRTKEY defined".
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
330 // Therefore, we include ASCII as another flag. This must be zeroed
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
331 // when serialized.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
332 ASCII = 0x8000,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
333 VIRTKEY = 0x0001,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
334 NOINVERT = 0x0002,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
335 ALT = 0x0010,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
336 SHIFT = 0x0004,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
337 CONTROL = 0x0008
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
338 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
339
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
340 static constexpr size_t NumFlags = 6;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
341 static StringRef OptionsStr[NumFlags];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
342 static uint32_t OptionsFlags[NumFlags];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
343 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
344
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
345 AcceleratorsResource(OptionalStmtList &&List, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
346 : OptStatementsRCResource(std::move(List), Flags) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
347
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
348 std::vector<Accelerator> Accelerators;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
349
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
350 void addAccelerator(IntOrString Event, uint32_t Id, uint16_t Flags) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
351 Accelerators.push_back(Accelerator{Event, Id, Flags});
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
352 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
353 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
354
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
355 IntOrString getResourceType() const override { return RkAccelerators; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
356 static uint16_t getDefaultMemoryFlags() { return MfPure | MfMoveable; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
357 Twine getResourceTypeName() const override { return "ACCELERATORS"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
358
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
359 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
360 return V->visitAcceleratorsResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
361 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
362 ResourceKind getKind() const override { return RkAccelerators; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
363 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
364 return Res->getKind() == RkAccelerators;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
365 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
366 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
367
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
368 // BITMAP resource. Represents a bitmap (".bmp") file.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
369 //
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
370 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380680(v=vs.85).aspx
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
371 class BitmapResource : public RCResource {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
372 public:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
373 StringRef BitmapLoc;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
374
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
375 BitmapResource(StringRef Location, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
376 : RCResource(Flags), BitmapLoc(Location) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
377 raw_ostream &log(raw_ostream &) const override;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
378
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
379 IntOrString getResourceType() const override { return RkBitmap; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
380 static uint16_t getDefaultMemoryFlags() { return MfPure | MfMoveable; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
381
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
382 Twine getResourceTypeName() const override { return "BITMAP"; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
383 Error visit(Visitor *V) const override {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
384 return V->visitBitmapResource(this);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
385 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
386 ResourceKind getKind() const override { return RkBitmap; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
387 static bool classof(const RCResource *Res) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
388 return Res->getKind() == RkBitmap;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
389 }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
390 };
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
391
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
392 // CURSOR resource. Represents a single cursor (".cur") file.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
393 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
394 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
395 class CursorResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
396 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
397 StringRef CursorLoc;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
398
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
399 CursorResource(StringRef Location, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
400 : RCResource(Flags), CursorLoc(Location) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
401 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
402
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
403 Twine getResourceTypeName() const override { return "CURSOR"; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
404 static uint16_t getDefaultMemoryFlags() { return MfDiscardable | MfMoveable; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
405 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
406 return V->visitCursorResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
407 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
408 ResourceKind getKind() const override { return RkCursor; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
409 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
410 return Res->getKind() == RkCursor;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
411 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
412 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
413
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
414 // ICON resource. Represents a single ".ico" file containing a group of icons.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
415 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
416 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
417 class IconResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
418 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
419 StringRef IconLoc;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
420
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
421 IconResource(StringRef Location, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
422 : RCResource(Flags), IconLoc(Location) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
423 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
424
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
425 Twine getResourceTypeName() const override { return "ICON"; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
426 static uint16_t getDefaultMemoryFlags() { return MfDiscardable | MfMoveable; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
427 Error visit(Visitor *V) const override { return V->visitIconResource(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
428 ResourceKind getKind() const override { return RkIcon; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
429 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
430 return Res->getKind() == RkIcon;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
431 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
432 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
433
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
434 // HTML resource. Represents a local webpage that is to be embedded into the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
435 // resulting resource file. It embeds a file only - no additional resources
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
436 // (images etc.) are included with this resource.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
437 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
438 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
439 class HTMLResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
440 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
441 StringRef HTMLLoc;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
442
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
443 HTMLResource(StringRef Location, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
444 : RCResource(Flags), HTMLLoc(Location) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
445 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
446
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
447 Error visit(Visitor *V) const override { return V->visitHTMLResource(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
448
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
449 // Curiously, file resources don't have DISCARDABLE flag set.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
450 static uint16_t getDefaultMemoryFlags() { return MfPure | MfMoveable; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
451 IntOrString getResourceType() const override { return RkHTML; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
452 Twine getResourceTypeName() const override { return "HTML"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
453 ResourceKind getKind() const override { return RkHTML; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
454 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
455 return Res->getKind() == RkHTML;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
456 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
457 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
458
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
459 // -- MENU resource and its helper classes --
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
460 // This resource describes the contents of an application menu
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
461 // (usually located in the upper part of the dialog.)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
462 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
463 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381025(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
464
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
465 // Description of a single submenu item.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
466 class MenuDefinition {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
467 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
468 enum Options {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
469 CHECKED = 0x0008,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
470 GRAYED = 0x0001,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
471 HELP = 0x4000,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
472 INACTIVE = 0x0002,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
473 MENUBARBREAK = 0x0020,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
474 MENUBREAK = 0x0040
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
475 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
476
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
477 enum MenuDefKind { MkBase, MkSeparator, MkMenuItem, MkPopup };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
478
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
479 static constexpr size_t NumFlags = 6;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
480 static StringRef OptionsStr[NumFlags];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
481 static uint32_t OptionsFlags[NumFlags];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
482 static raw_ostream &logFlags(raw_ostream &, uint16_t Flags);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
483 virtual raw_ostream &log(raw_ostream &OS) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
484 return OS << "Base menu definition\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
485 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
486 virtual ~MenuDefinition() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
487
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
488 virtual uint16_t getResFlags() const { return 0; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
489 virtual MenuDefKind getKind() const { return MkBase; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
490 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
491
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
492 // Recursive description of a whole submenu.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
493 class MenuDefinitionList : public MenuDefinition {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
494 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
495 std::vector<std::unique_ptr<MenuDefinition>> Definitions;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
496
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
497 void addDefinition(std::unique_ptr<MenuDefinition> Def) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
498 Definitions.push_back(std::move(Def));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
499 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
500 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
501 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
502
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
503 // Separator in MENU definition (MENUITEM SEPARATOR).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
504 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
505 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
506 class MenuSeparator : public MenuDefinition {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
507 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
508 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
509
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
510 MenuDefKind getKind() const override { return MkSeparator; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
511 static bool classof(const MenuDefinition *D) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
512 return D->getKind() == MkSeparator;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
513 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
514 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
515
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
516 // MENUITEM statement definition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
517 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
518 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
519 class MenuItem : public MenuDefinition {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
520 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
521 StringRef Name;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
522 uint32_t Id;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
523 uint16_t Flags;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
524
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
525 MenuItem(StringRef Caption, uint32_t ItemId, uint16_t ItemFlags)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
526 : Name(Caption), Id(ItemId), Flags(ItemFlags) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
527 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
528
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
529 uint16_t getResFlags() const override { return Flags; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
530 MenuDefKind getKind() const override { return MkMenuItem; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
531 static bool classof(const MenuDefinition *D) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
532 return D->getKind() == MkMenuItem;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
533 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
534 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
535
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
536 // POPUP statement definition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
537 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
538 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381030(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
539 class PopupItem : public MenuDefinition {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
540 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
541 StringRef Name;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
542 uint16_t Flags;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
543 MenuDefinitionList SubItems;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
544
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
545 PopupItem(StringRef Caption, uint16_t ItemFlags,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
546 MenuDefinitionList &&SubItemsList)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
547 : Name(Caption), Flags(ItemFlags), SubItems(std::move(SubItemsList)) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
548 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
549
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
550 // This has an additional (0x10) flag. It doesn't match with documented
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
551 // 0x01 flag, though.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
552 uint16_t getResFlags() const override { return Flags | 0x10; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
553 MenuDefKind getKind() const override { return MkPopup; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
554 static bool classof(const MenuDefinition *D) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
555 return D->getKind() == MkPopup;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
556 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
557 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
558
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
559 // Menu resource definition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
560 class MenuResource : public OptStatementsRCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
561 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
562 MenuDefinitionList Elements;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
563
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
564 MenuResource(OptionalStmtList &&OptStmts, MenuDefinitionList &&Items,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
565 uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
566 : OptStatementsRCResource(std::move(OptStmts), Flags),
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
567 Elements(std::move(Items)) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
568 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
569
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
570 IntOrString getResourceType() const override { return RkMenu; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
571 Twine getResourceTypeName() const override { return "MENU"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
572 Error visit(Visitor *V) const override { return V->visitMenuResource(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
573 ResourceKind getKind() const override { return RkMenu; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
574 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
575 return Res->getKind() == RkMenu;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
576 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
577 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
578
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
579 // STRINGTABLE resource. Contains a list of strings, each having its unique ID.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
580 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
581 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
582 class StringTableResource : public OptStatementsRCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
583 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
584 std::vector<std::pair<uint32_t, StringRef>> Table;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
585
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
586 StringTableResource(OptionalStmtList &&List, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
587 : OptStatementsRCResource(std::move(List), Flags) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
588 void addString(uint32_t ID, StringRef String) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
589 Table.emplace_back(ID, String);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
590 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
591 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
592 Twine getResourceTypeName() const override { return "STRINGTABLE"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
593 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
594 return V->visitStringTableResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
595 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
596 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
597
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
598 // -- DIALOG(EX) resource and its helper classes --
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
599 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
600 // This resource describes dialog boxes and controls residing inside them.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
601 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
602 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381003(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
603 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381002(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
604
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
605 // Single control definition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
606 class Control {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
607 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
608 StringRef Type;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
609 IntOrString Title;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
610 uint32_t ID, X, Y, Width, Height;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
611 Optional<IntWithNotMask> Style;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
612 Optional<uint32_t> ExtStyle, HelpID;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
613 IntOrString Class;
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
614
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
615 // Control classes as described in DLGITEMTEMPLATEEX documentation.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
616 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
617 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms645389.aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
618 enum CtlClasses {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
619 ClsButton = 0x80,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
620 ClsEdit = 0x81,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
621 ClsStatic = 0x82,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
622 ClsListBox = 0x83,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
623 ClsScrollBar = 0x84,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
624 ClsComboBox = 0x85
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
625 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
626
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
627 // Simple information about a single control type.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
628 struct CtlInfo {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
629 uint32_t Style;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
630 uint16_t CtlClass;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
631 bool HasTitle;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
632 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
633
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
634 Control(StringRef CtlType, IntOrString CtlTitle, uint32_t CtlID,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
635 uint32_t PosX, uint32_t PosY, uint32_t ItemWidth, uint32_t ItemHeight,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
636 Optional<IntWithNotMask> ItemStyle, Optional<uint32_t> ExtItemStyle,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
637 Optional<uint32_t> CtlHelpID, IntOrString CtlClass)
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
638 : Type(CtlType), Title(CtlTitle), ID(CtlID), X(PosX), Y(PosY),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
639 Width(ItemWidth), Height(ItemHeight), Style(ItemStyle),
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
640 ExtStyle(ExtItemStyle), HelpID(CtlHelpID), Class(CtlClass) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
641
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
642 static const StringMap<CtlInfo> SupportedCtls;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
643
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
644 raw_ostream &log(raw_ostream &) const;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
645 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
646
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
647 // Single dialog definition. We don't create distinct classes for DIALOG and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
648 // DIALOGEX because of their being too similar to each other. We only have a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
649 // flag determining the type of the dialog box.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
650 class DialogResource : public OptStatementsRCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
651 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
652 uint32_t X, Y, Width, Height, HelpID;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
653 std::vector<Control> Controls;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
654 bool IsExtended;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
655
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
656 DialogResource(uint32_t PosX, uint32_t PosY, uint32_t DlgWidth,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
657 uint32_t DlgHeight, uint32_t DlgHelpID,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
658 OptionalStmtList &&OptStmts, bool IsDialogEx, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
659 : OptStatementsRCResource(std::move(OptStmts), Flags), X(PosX), Y(PosY),
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
660 Width(DlgWidth), Height(DlgHeight), HelpID(DlgHelpID),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
661 IsExtended(IsDialogEx) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
662
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
663 void addControl(Control &&Ctl) { Controls.push_back(std::move(Ctl)); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
664
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
665 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
666
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
667 // It was a weird design decision to assign the same resource type number
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
668 // both for DIALOG and DIALOGEX (and the same structure version number).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
669 // It makes it possible for DIALOG to be mistaken for DIALOGEX.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
670 IntOrString getResourceType() const override { return RkDialog; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
671 Twine getResourceTypeName() const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
672 return "DIALOG" + Twine(IsExtended ? "EX" : "");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
673 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
674 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
675 return V->visitDialogResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
676 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
677 ResourceKind getKind() const override { return RkDialog; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
678 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
679 return Res->getKind() == RkDialog;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
680 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
681 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
682
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
683 // User-defined resource. It is either:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
684 // * a link to the file, e.g. NAME TYPE "filename",
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
685 // * or contains a list of integers and strings, e.g. NAME TYPE {1, "a", 2}.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
686 class UserDefinedResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
687 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
688 IntOrString Type;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
689 StringRef FileLoc;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
690 std::vector<IntOrString> Contents;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
691 bool IsFileResource;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
692
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
693 UserDefinedResource(IntOrString ResourceType, StringRef FileLocation,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
694 uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
695 : RCResource(Flags), Type(ResourceType), FileLoc(FileLocation),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
696 IsFileResource(true) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
697 UserDefinedResource(IntOrString ResourceType, std::vector<IntOrString> &&Data,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
698 uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
699 : RCResource(Flags), Type(ResourceType), Contents(std::move(Data)),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
700 IsFileResource(false) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
701
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
702 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
703 IntOrString getResourceType() const override { return Type; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
704 Twine getResourceTypeName() const override { return Type; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
705 static uint16_t getDefaultMemoryFlags() { return MfPure | MfMoveable; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
706
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
707 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
708 return V->visitUserDefinedResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
709 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
710 ResourceKind getKind() const override { return RkUser; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
711 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
712 return Res->getKind() == RkUser;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
713 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
714 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
715
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
716 // -- VERSIONINFO resource and its helper classes --
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
717 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
718 // This resource lists the version information on the executable/library.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
719 // The declaration consists of the following items:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
720 // * A number of fixed optional version statements (e.g. FILEVERSION, FILEOS)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
721 // * BEGIN
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
722 // * A number of BLOCK and/or VALUE statements. BLOCK recursively defines
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
723 // another block of version information, whereas VALUE defines a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
724 // key -> value correspondence. There might be more than one value
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
725 // corresponding to the single key.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
726 // * END
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
727 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
728 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
729
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
730 // A single VERSIONINFO statement;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
731 class VersionInfoStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
732 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
733 enum StmtKind { StBase = 0, StBlock = 1, StValue = 2 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
734
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
735 virtual raw_ostream &log(raw_ostream &OS) const { return OS << "VI stmt\n"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
736 virtual ~VersionInfoStmt() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
737
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
738 virtual StmtKind getKind() const { return StBase; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
739 static bool classof(const VersionInfoStmt *S) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
740 return S->getKind() == StBase;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
741 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
742 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
743
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
744 // BLOCK definition; also the main VERSIONINFO declaration is considered a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
745 // BLOCK, although it has no name.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
746 // The correct top-level blocks are "VarFileInfo" and "StringFileInfo". We don't
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
747 // care about them at the parsing phase.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
748 class VersionInfoBlock : public VersionInfoStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
749 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
750 std::vector<std::unique_ptr<VersionInfoStmt>> Stmts;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
751 StringRef Name;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
752
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
753 VersionInfoBlock(StringRef BlockName) : Name(BlockName) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
754 void addStmt(std::unique_ptr<VersionInfoStmt> Stmt) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
755 Stmts.push_back(std::move(Stmt));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
756 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
757 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
758
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
759 StmtKind getKind() const override { return StBlock; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
760 static bool classof(const VersionInfoStmt *S) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
761 return S->getKind() == StBlock;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
762 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
763 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
764
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
765 class VersionInfoValue : public VersionInfoStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
766 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
767 StringRef Key;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
768 std::vector<IntOrString> Values;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
769 std::vector<bool> HasPrecedingComma;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
770
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
771 VersionInfoValue(StringRef InfoKey, std::vector<IntOrString> &&Vals,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
772 std::vector<bool> &&CommasBeforeVals)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
773 : Key(InfoKey), Values(std::move(Vals)),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
774 HasPrecedingComma(std::move(CommasBeforeVals)) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
775 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
776
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
777 StmtKind getKind() const override { return StValue; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
778 static bool classof(const VersionInfoStmt *S) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
779 return S->getKind() == StValue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
780 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
781 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
782
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
783 class VersionInfoResource : public RCResource {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
784 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
785 // A class listing fixed VERSIONINFO statements (occuring before main BEGIN).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
786 // If any of these is not specified, it is assumed by the original tool to
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
787 // be equal to 0.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
788 class VersionInfoFixed {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
789 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
790 enum VersionInfoFixedType {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
791 FtUnknown,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
792 FtFileVersion,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
793 FtProductVersion,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
794 FtFileFlagsMask,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
795 FtFileFlags,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
796 FtFileOS,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
797 FtFileType,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
798 FtFileSubtype,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
799 FtNumTypes
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
800 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
801
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
802 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
803 static const StringMap<VersionInfoFixedType> FixedFieldsInfoMap;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
804 static const StringRef FixedFieldsNames[FtNumTypes];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
805
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
806 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
807 SmallVector<uint32_t, 4> FixedInfo[FtNumTypes];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
808 SmallVector<bool, FtNumTypes> IsTypePresent;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
809
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
810 static VersionInfoFixedType getFixedType(StringRef Type);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
811 static bool isTypeSupported(VersionInfoFixedType Type);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
812 static bool isVersionType(VersionInfoFixedType Type);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
813
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
814 VersionInfoFixed() : IsTypePresent(FtNumTypes, false) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
815
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
816 void setValue(VersionInfoFixedType Type, ArrayRef<uint32_t> Value) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
817 FixedInfo[Type] = SmallVector<uint32_t, 4>(Value.begin(), Value.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
818 IsTypePresent[Type] = true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
819 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
820
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
821 raw_ostream &log(raw_ostream &) const;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
822 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
823
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
824 VersionInfoBlock MainBlock;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
825 VersionInfoFixed FixedData;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
826
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
827 VersionInfoResource(VersionInfoBlock &&TopLevelBlock,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
828 VersionInfoFixed &&FixedInfo, uint16_t Flags)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
829 : RCResource(Flags), MainBlock(std::move(TopLevelBlock)),
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
830 FixedData(std::move(FixedInfo)) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
831
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
832 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
833 IntOrString getResourceType() const override { return RkVersionInfo; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
834 static uint16_t getDefaultMemoryFlags() { return MfMoveable | MfPure; }
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
835 Twine getResourceTypeName() const override { return "VERSIONINFO"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
836 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
837 return V->visitVersionInfoResource(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
838 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
839 ResourceKind getKind() const override { return RkVersionInfo; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
840 static bool classof(const RCResource *Res) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
841 return Res->getKind() == RkVersionInfo;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
842 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
843 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
844
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
845 // CHARACTERISTICS optional statement.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
846 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
847 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380872(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
848 class CharacteristicsStmt : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
849 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
850 uint32_t Value;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
851
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
852 CharacteristicsStmt(uint32_t Characteristic) : Value(Characteristic) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
853 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
854
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
855 Twine getResourceTypeName() const override { return "CHARACTERISTICS"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
856 Error visit(Visitor *V) const override {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
857 return V->visitCharacteristicsStmt(this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
858 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
859 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
860
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
861 // VERSION optional statement.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
862 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
863 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381059(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
864 class VersionStmt : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
865 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
866 uint32_t Value;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
867
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
868 VersionStmt(uint32_t Version) : Value(Version) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
869 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
870
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
871 Twine getResourceTypeName() const override { return "VERSION"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
872 Error visit(Visitor *V) const override { return V->visitVersionStmt(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
873 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
874
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
875 // CAPTION optional statement.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
876 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
877 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380778(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
878 class CaptionStmt : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
879 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
880 StringRef Value;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
881
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
882 CaptionStmt(StringRef Caption) : Value(Caption) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
883 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
884 Twine getResourceTypeName() const override { return "CAPTION"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
885 Error visit(Visitor *V) const override { return V->visitCaptionStmt(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
886 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
887
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
888 // FONT optional statement.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
889 // Note that the documentation is inaccurate: it expects five arguments to be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
890 // given, however the example provides only two. In fact, the original tool
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
891 // expects two arguments - point size and name of the typeface.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
892 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
893 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381013(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
894 class FontStmt : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
895 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
896 uint32_t Size, Weight, Charset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
897 StringRef Name;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
898 bool Italic;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
899
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
900 FontStmt(uint32_t FontSize, StringRef FontName, uint32_t FontWeight,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
901 bool FontItalic, uint32_t FontCharset)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
902 : Size(FontSize), Weight(FontWeight), Charset(FontCharset),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
903 Name(FontName), Italic(FontItalic) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
904 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
905 Twine getResourceTypeName() const override { return "FONT"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
906 Error visit(Visitor *V) const override { return V->visitFontStmt(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
907 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
908
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
909 // STYLE optional statement.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
910 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
911 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381051(v=vs.85).aspx
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
912 class StyleStmt : public OptionalStmt {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
913 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
914 uint32_t Value;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
915
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
916 StyleStmt(uint32_t Style) : Value(Style) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
917 raw_ostream &log(raw_ostream &) const override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
918 Twine getResourceTypeName() const override { return "STYLE"; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
919 Error visit(Visitor *V) const override { return V->visitStyleStmt(this); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
920 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
921
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
922 // EXSTYLE optional statement.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
923 //
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
924 // Ref: docs.microsoft.com/en-us/windows/desktop/menurc/exstyle-statement
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
925 class ExStyleStmt : public OptionalStmt {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
926 public:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
927 uint32_t Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
928
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
929 ExStyleStmt(uint32_t ExStyle) : Value(ExStyle) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
930 raw_ostream &log(raw_ostream &) const override;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
931 Twine getResourceTypeName() const override { return "EXSTYLE"; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
932 Error visit(Visitor *V) const override { return V->visitExStyleStmt(this); }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
933 };
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
934
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
935 // CLASS optional statement.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
936 //
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
937 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380883(v=vs.85).aspx
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
938 class ClassStmt : public OptionalStmt {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
939 public:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
940 IntOrString Value;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
941
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
942 ClassStmt(IntOrString Class) : Value(Class) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
943 raw_ostream &log(raw_ostream &) const override;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
944 Twine getResourceTypeName() const override { return "CLASS"; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
945 Error visit(Visitor *V) const override { return V->visitClassStmt(this); }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
946 };
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
947
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
948 } // namespace rc
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
949 } // namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
950
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
951 #endif