[llvm-rc] Add support for the optional CLASS statement for dialogs

Differential Revision: https://reviews.llvm.org/D46875

llvm-svn: 332386
This commit is contained in:
Martin Storsjo 2018-05-15 19:21:28 +00:00
parent 041e33a699
commit 059282774a
9 changed files with 71 additions and 3 deletions

View File

@ -51,3 +51,6 @@ CAPTION "CAPTION" STYLE 0 {}
26 DIALOGEX 1, 2, 3, 4, 5 {}
27 DIALOGEX 5, 5, 5, 5 CLASS "Foobar" {}
28 DIALOG 5, 5, 5, 5 CLASS 42 {}

View File

@ -550,6 +550,35 @@
; HEADERS-NEXT: 0010: 00000100 02000300 04000000 00000000 |................|
; HEADERS-NEXT: )
; HEADERS-DAG: Resource type (int): 5
; HEADERS-NEXT: Resource name (int): 27
; HEADERS-NEXT: Data version: 0
; HEADERS-NEXT: Memory flags: 0x1030
; HEADERS-NEXT: Language ID: 1033
; HEADERS-NEXT: Version (major): 0
; HEADERS-NEXT: Version (minor): 0
; HEADERS-NEXT: Characteristics: 0
; HEADERS-NEXT: Data size: 44
; HEADERS-NEXT: Data: (
; HEADERS-NEXT: 0000: 0100FFFF 00000000 00000000 00008880 |................|
; HEADERS-NEXT: 0010: 00000500 05000500 05000000 46006F00 |............F.o.|
; HEADERS-NEXT: 0020: 6F006200 61007200 00000000 |o.b.a.r.....|
; HEADERS-NEXT: )
; HEADERS-DAG: Resource type (int): 5
; HEADERS-NEXT: Resource name (int): 28
; HEADERS-NEXT: Data version: 0
; HEADERS-NEXT: Memory flags: 0x1030
; HEADERS-NEXT: Language ID: 1033
; HEADERS-NEXT: Version (major): 0
; HEADERS-NEXT: Version (minor): 0
; HEADERS-NEXT: Characteristics: 0
; HEADERS-NEXT: Data size: 26
; HEADERS-NEXT: Data: (
; HEADERS-NEXT: 0000: 00008880 00000000 00000500 05000500 |................|
; HEADERS-NEXT: 0010: 05000000 FFFF2A00 0000 |......*...|
; HEADERS-NEXT: )
; RUN: not llvm-rc /FO %t %p/Inputs/tag-dialog-large-coord.rc 2>&1 | FileCheck %s --check-prefix COORD1

View File

@ -458,6 +458,11 @@ Error ResourceFileWriter::visitCaptionStmt(const CaptionStmt *Stmt) {
return Error::success();
}
Error ResourceFileWriter::visitClassStmt(const ClassStmt *Stmt) {
ObjectData.Class = Stmt->Value;
return Error::success();
}
Error ResourceFileWriter::visitHTMLResource(const RCResource *Res) {
return writeResource(Res, &ResourceFileWriter::writeHTMLBody);
}
@ -1120,8 +1125,8 @@ Error ResourceFileWriter::writeDialogBody(const RCResource *Base) {
// think there is no menu attached to the dialog.
writeInt<uint16_t>(0);
// Window CLASS field. Not kept here.
writeInt<uint16_t>(0);
// Window CLASS field.
RETURN_IF_ERROR(writeIntOrString(ObjectData.Class));
// Window title or a single word equal to 0.
RETURN_IF_ERROR(writeCString(ObjectData.Caption));

View File

@ -62,6 +62,7 @@ public:
Error visitCaptionStmt(const CaptionStmt *) override;
Error visitCharacteristicsStmt(const CharacteristicsStmt *) override;
Error visitClassStmt(const ClassStmt *) override;
Error visitFontStmt(const FontStmt *) override;
Error visitLanguageStmt(const LanguageResource *) override;
Error visitStyleStmt(const StyleStmt *) override;
@ -88,8 +89,11 @@ public:
uint32_t Charset;
};
Optional<FontInfo> Font;
IntOrString Class;
ObjectInfo() : LanguageInfo(0), Characteristics(0), VersionInfo(0) {}
ObjectInfo()
: LanguageInfo(0), Characteristics(0), VersionInfo(0),
Class(StringRef()) {}
} ObjectData;
struct StringTableInfo {

View File

@ -386,6 +386,8 @@ RCParser::parseSingleOptionalStatement(OptStmtType StmtsType) {
if (StmtsType != OptStmtType::BasicStmt) {
if (TypeToken->equals_lower("CAPTION"))
return parseCaptionStmt();
if (TypeToken->equals_lower("CLASS"))
return parseClassStmt();
if (TypeToken->equals_lower("FONT"))
return parseFontStmt(StmtsType);
if (TypeToken->equals_lower("STYLE"))
@ -779,6 +781,11 @@ RCParser::ParseOptionType RCParser::parseCaptionStmt() {
return llvm::make_unique<CaptionStmt>(*Arg);
}
RCParser::ParseOptionType RCParser::parseClassStmt() {
ASSIGN_OR_RETURN(Arg, readIntOrString());
return llvm::make_unique<ClassStmt>(*Arg);
}
RCParser::ParseOptionType RCParser::parseFontStmt(OptStmtType DialogType) {
assert(DialogType != OptStmtType::BasicStmt);

View File

@ -171,6 +171,7 @@ private:
ParseOptionType parseCharacteristicsStmt();
ParseOptionType parseVersionStmt();
ParseOptionType parseCaptionStmt();
ParseOptionType parseClassStmt();
ParseOptionType parseFontStmt(OptStmtType DialogType);
ParseOptionType parseStyleStmt();

View File

@ -267,6 +267,10 @@ raw_ostream &CaptionStmt::log(raw_ostream &OS) const {
return OS << "Caption: " << Value << "\n";
}
raw_ostream &ClassStmt::log(raw_ostream &OS) const {
return OS << "Class: " << Value << "\n";
}
raw_ostream &FontStmt::log(raw_ostream &OS) const {
OS << "Font: size = " << Size << ", face = " << Name
<< ", weight = " << Weight;

View File

@ -866,6 +866,19 @@ public:
Error visit(Visitor *V) const override { return V->visitStyleStmt(this); }
};
// CLASS optional statement.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380883(v=vs.85).aspx
class ClassStmt : public OptionalStmt {
public:
IntOrString Value;
ClassStmt(IntOrString Class) : Value(Class) {}
raw_ostream &log(raw_ostream &) const override;
Twine getResourceTypeName() const override { return "CLASS"; }
Error visit(Visitor *V) const override { return V->visitClassStmt(this); }
};
} // namespace rc
} // namespace llvm

View File

@ -22,6 +22,7 @@ namespace rc {
class RCResource;
class CaptionStmt;
class ClassStmt;
class CharacteristicsStmt;
class FontStmt;
class LanguageResource;
@ -43,6 +44,7 @@ public:
virtual Error visitVersionInfoResource(const RCResource *) = 0;
virtual Error visitCaptionStmt(const CaptionStmt *) = 0;
virtual Error visitClassStmt(const ClassStmt *) = 0;
virtual Error visitCharacteristicsStmt(const CharacteristicsStmt *) = 0;
virtual Error visitFontStmt(const FontStmt *) = 0;
virtual Error visitLanguageStmt(const LanguageResource *) = 0;