2017-08-19 02:24:17 +08:00
|
|
|
//===-- ResourceScriptParser.cpp --------------------------------*- C++-*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-08-19 02:24:17 +08:00
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the parser defined in ResourceScriptParser.h.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ResourceScriptParser.h"
|
2017-10-12 04:12:09 +08:00
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Process.h"
|
2017-08-19 02:24:17 +08:00
|
|
|
|
|
|
|
// Take an expression returning llvm::Error and forward the error if it exists.
|
|
|
|
#define RETURN_IF_ERROR(Expr) \
|
|
|
|
if (auto Err = (Expr)) \
|
|
|
|
return std::move(Err);
|
|
|
|
|
|
|
|
// Take an expression returning llvm::Expected<T> and assign it to Var or
|
|
|
|
// forward the error out of the function.
|
|
|
|
#define ASSIGN_OR_RETURN(Var, Expr) \
|
|
|
|
auto Var = (Expr); \
|
|
|
|
if (!Var) \
|
|
|
|
return Var.takeError();
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace rc {
|
|
|
|
|
2017-10-10 02:50:29 +08:00
|
|
|
RCParser::ParserError::ParserError(const Twine &Expected, const LocIter CurLoc,
|
2017-08-19 02:24:17 +08:00
|
|
|
const LocIter End)
|
|
|
|
: ErrorLoc(CurLoc), FileEnd(End) {
|
|
|
|
CurMessage = "Error parsing file: expected " + Expected.str() + ", got " +
|
|
|
|
(CurLoc == End ? "<EOF>" : CurLoc->value()).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
char RCParser::ParserError::ID = 0;
|
|
|
|
|
2017-10-10 02:50:29 +08:00
|
|
|
RCParser::RCParser(std::vector<RCToken> TokenList)
|
2017-08-19 02:24:17 +08:00
|
|
|
: Tokens(std::move(TokenList)), CurLoc(Tokens.begin()), End(Tokens.end()) {}
|
|
|
|
|
|
|
|
bool RCParser::isEof() const { return CurLoc == End; }
|
|
|
|
|
|
|
|
RCParser::ParseType RCParser::parseSingleResource() {
|
|
|
|
// The first thing we read is usually a resource's name. However, in some
|
|
|
|
// cases (LANGUAGE and STRINGTABLE) the resources don't have their names
|
|
|
|
// and the first token to be read is the type.
|
|
|
|
ASSIGN_OR_RETURN(NameToken, readTypeOrName());
|
|
|
|
|
|
|
|
if (NameToken->equalsLower("LANGUAGE"))
|
|
|
|
return parseLanguageResource();
|
|
|
|
else if (NameToken->equalsLower("STRINGTABLE"))
|
|
|
|
return parseStringTableResource();
|
|
|
|
|
|
|
|
// If it's not an unnamed resource, what we've just read is a name. Now,
|
|
|
|
// read resource type;
|
|
|
|
ASSIGN_OR_RETURN(TypeToken, readTypeOrName());
|
|
|
|
|
|
|
|
ParseType Result = std::unique_ptr<RCResource>();
|
|
|
|
(void)!Result;
|
|
|
|
|
2017-08-29 06:58:31 +08:00
|
|
|
if (TypeToken->equalsLower("ACCELERATORS"))
|
|
|
|
Result = parseAcceleratorsResource();
|
2018-05-08 04:27:37 +08:00
|
|
|
else if (TypeToken->equalsLower("BITMAP"))
|
|
|
|
Result = parseBitmapResource();
|
2017-08-29 06:58:31 +08:00
|
|
|
else if (TypeToken->equalsLower("CURSOR"))
|
2017-08-29 05:59:54 +08:00
|
|
|
Result = parseCursorResource();
|
2017-08-30 00:49:59 +08:00
|
|
|
else if (TypeToken->equalsLower("DIALOG"))
|
|
|
|
Result = parseDialogResource(false);
|
|
|
|
else if (TypeToken->equalsLower("DIALOGEX"))
|
|
|
|
Result = parseDialogResource(true);
|
2017-08-29 05:59:54 +08:00
|
|
|
else if (TypeToken->equalsLower("HTML"))
|
|
|
|
Result = parseHTMLResource();
|
2018-05-08 04:27:15 +08:00
|
|
|
else if (TypeToken->equalsLower("ICON"))
|
|
|
|
Result = parseIconResource();
|
2017-08-29 07:46:30 +08:00
|
|
|
else if (TypeToken->equalsLower("MENU"))
|
|
|
|
Result = parseMenuResource();
|
2018-05-10 02:20:56 +08:00
|
|
|
else if (TypeToken->equalsLower("RCDATA"))
|
|
|
|
Result = parseUserDefinedResource(RkRcData);
|
2017-09-29 06:41:38 +08:00
|
|
|
else if (TypeToken->equalsLower("VERSIONINFO"))
|
|
|
|
Result = parseVersionInfoResource();
|
2017-08-19 02:24:17 +08:00
|
|
|
else
|
2017-09-29 08:14:18 +08:00
|
|
|
Result = parseUserDefinedResource(*TypeToken);
|
2017-08-19 02:24:17 +08:00
|
|
|
|
|
|
|
if (Result)
|
|
|
|
(*Result)->setName(*NameToken);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RCParser::isNextTokenKind(Kind TokenKind) const {
|
|
|
|
return !isEof() && look().kind() == TokenKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RCToken &RCParser::look() const {
|
|
|
|
assert(!isEof());
|
|
|
|
return *CurLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RCToken &RCParser::read() {
|
|
|
|
assert(!isEof());
|
|
|
|
return *CurLoc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCParser::consume() {
|
|
|
|
assert(!isEof());
|
|
|
|
CurLoc++;
|
|
|
|
}
|
|
|
|
|
2017-09-29 07:53:25 +08:00
|
|
|
// An integer description might consist of a single integer or
|
|
|
|
// an arithmetic expression evaluating to the integer. The expressions
|
2018-12-05 21:22:56 +08:00
|
|
|
// can contain the following tokens: <int> ( ) + - | & ~ not. Their meaning
|
|
|
|
// is the same as in C++ except for 'not' expression.
|
2017-09-29 07:53:25 +08:00
|
|
|
// The operators in the original RC implementation have the following
|
|
|
|
// precedence:
|
2018-12-05 21:22:56 +08:00
|
|
|
// 1) Unary operators (- ~ not),
|
2017-09-29 07:53:25 +08:00
|
|
|
// 2) Binary operators (+ - & |), with no precedence.
|
|
|
|
//
|
2018-12-05 21:22:56 +08:00
|
|
|
// 'not' expression is mostly useful for style values. It evaluates to 0,
|
|
|
|
// but value given to the operator is stored separately from integer value.
|
|
|
|
// It's mostly useful for control style expressions and causes bits from
|
|
|
|
// default control style to be excluded from generated style. For binary
|
|
|
|
// operators the mask from the right operand is applied to the left operand
|
|
|
|
// and masks from both operands are combined in operator result.
|
|
|
|
//
|
2017-09-29 07:53:25 +08:00
|
|
|
// The following grammar is used to parse the expressions Exp1:
|
|
|
|
// Exp1 ::= Exp2 || Exp1 + Exp2 || Exp1 - Exp2 || Exp1 | Exp2 || Exp1 & Exp2
|
2018-12-05 21:22:56 +08:00
|
|
|
// Exp2 ::= -Exp2 || ~Exp2 || not Expr2 || Int || (Exp1).
|
2017-09-29 07:53:25 +08:00
|
|
|
// (More conveniently, Exp1 is a non-empty sequence of Exp2 expressions,
|
|
|
|
// separated by binary operators.)
|
|
|
|
//
|
|
|
|
// Expressions of type Exp1 are read by parseIntExpr1(Inner) method, while Exp2
|
|
|
|
// is read by parseIntExpr2().
|
|
|
|
//
|
|
|
|
// The original Microsoft tool handles multiple unary operators incorrectly.
|
|
|
|
// For example, in 16-bit little-endian integers:
|
|
|
|
// 1 => 01 00, -1 => ff ff, --1 => ff ff, ---1 => 01 00;
|
|
|
|
// 1 => 01 00, ~1 => fe ff, ~~1 => fd ff, ~~~1 => fc ff.
|
|
|
|
// Our implementation differs from the original one and handles these
|
|
|
|
// operators correctly:
|
|
|
|
// 1 => 01 00, -1 => ff ff, --1 => 01 00, ---1 => ff ff;
|
|
|
|
// 1 => 01 00, ~1 => fe ff, ~~1 => 01 00, ~~~1 => fe ff.
|
|
|
|
|
2018-12-05 21:22:56 +08:00
|
|
|
Expected<RCInt> RCParser::readInt() {
|
|
|
|
ASSIGN_OR_RETURN(Value, parseIntExpr1());
|
|
|
|
return (*Value).getValue();
|
|
|
|
}
|
2017-09-29 07:53:25 +08:00
|
|
|
|
2018-12-05 21:22:56 +08:00
|
|
|
Expected<IntWithNotMask> RCParser::parseIntExpr1() {
|
2017-09-29 07:53:25 +08:00
|
|
|
// Exp1 ::= Exp2 || Exp1 + Exp2 || Exp1 - Exp2 || Exp1 | Exp2 || Exp1 & Exp2.
|
|
|
|
ASSIGN_OR_RETURN(FirstResult, parseIntExpr2());
|
2018-12-05 21:22:56 +08:00
|
|
|
IntWithNotMask Result = *FirstResult;
|
2017-09-29 07:53:25 +08:00
|
|
|
|
|
|
|
while (!isEof() && look().isBinaryOp()) {
|
|
|
|
auto OpToken = read();
|
|
|
|
ASSIGN_OR_RETURN(NextResult, parseIntExpr2());
|
|
|
|
|
|
|
|
switch (OpToken.kind()) {
|
|
|
|
case Kind::Plus:
|
|
|
|
Result += *NextResult;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Kind::Minus:
|
|
|
|
Result -= *NextResult;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Kind::Pipe:
|
|
|
|
Result |= *NextResult;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Kind::Amp:
|
|
|
|
Result &= *NextResult;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Already processed all binary ops.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:22:56 +08:00
|
|
|
Expected<IntWithNotMask> RCParser::parseIntExpr2() {
|
|
|
|
// Exp2 ::= -Exp2 || ~Exp2 || not Expr2 || Int || (Exp1).
|
2017-09-29 07:53:25 +08:00
|
|
|
static const char ErrorMsg[] = "'-', '~', integer or '('";
|
|
|
|
|
|
|
|
if (isEof())
|
|
|
|
return getExpectedError(ErrorMsg);
|
|
|
|
|
|
|
|
switch (look().kind()) {
|
|
|
|
case Kind::Minus: {
|
|
|
|
consume();
|
|
|
|
ASSIGN_OR_RETURN(Result, parseIntExpr2());
|
|
|
|
return -(*Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Kind::Tilde: {
|
|
|
|
consume();
|
|
|
|
ASSIGN_OR_RETURN(Result, parseIntExpr2());
|
|
|
|
return ~(*Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Kind::Int:
|
2017-10-07 05:26:06 +08:00
|
|
|
return RCInt(read());
|
2017-09-29 07:53:25 +08:00
|
|
|
|
|
|
|
case Kind::LeftParen: {
|
|
|
|
consume();
|
|
|
|
ASSIGN_OR_RETURN(Result, parseIntExpr1());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::RightParen));
|
|
|
|
return *Result;
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:22:56 +08:00
|
|
|
case Kind::Identifier: {
|
|
|
|
if (!read().value().equals_lower("not"))
|
|
|
|
return getExpectedError(ErrorMsg, true);
|
|
|
|
ASSIGN_OR_RETURN(Result, parseIntExpr2());
|
|
|
|
return IntWithNotMask(0, (*Result).getValue());
|
|
|
|
}
|
|
|
|
|
2017-09-29 07:53:25 +08:00
|
|
|
default:
|
|
|
|
return getExpectedError(ErrorMsg);
|
|
|
|
}
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expected<StringRef> RCParser::readString() {
|
|
|
|
if (!isNextTokenKind(Kind::String))
|
|
|
|
return getExpectedError("string");
|
|
|
|
return read().value();
|
|
|
|
}
|
|
|
|
|
2018-05-08 16:47:37 +08:00
|
|
|
Expected<StringRef> RCParser::readFilename() {
|
|
|
|
if (!isNextTokenKind(Kind::String) && !isNextTokenKind(Kind::Identifier))
|
|
|
|
return getExpectedError("string");
|
|
|
|
return read().value();
|
|
|
|
}
|
|
|
|
|
2017-08-19 02:24:17 +08:00
|
|
|
Expected<StringRef> RCParser::readIdentifier() {
|
|
|
|
if (!isNextTokenKind(Kind::Identifier))
|
|
|
|
return getExpectedError("identifier");
|
|
|
|
return read().value();
|
|
|
|
}
|
|
|
|
|
2017-08-29 06:58:31 +08:00
|
|
|
Expected<IntOrString> RCParser::readIntOrString() {
|
|
|
|
if (!isNextTokenKind(Kind::Int) && !isNextTokenKind(Kind::String))
|
|
|
|
return getExpectedError("int or string");
|
|
|
|
return IntOrString(read());
|
|
|
|
}
|
|
|
|
|
2017-08-19 02:24:17 +08:00
|
|
|
Expected<IntOrString> RCParser::readTypeOrName() {
|
|
|
|
// We suggest that the correct resource name or type should be either an
|
|
|
|
// identifier or an integer. The original RC tool is much more liberal.
|
|
|
|
if (!isNextTokenKind(Kind::Identifier) && !isNextTokenKind(Kind::Int))
|
|
|
|
return getExpectedError("int or identifier");
|
2017-08-29 06:58:31 +08:00
|
|
|
return IntOrString(read());
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Error RCParser::consumeType(Kind TokenKind) {
|
|
|
|
if (isNextTokenKind(TokenKind)) {
|
|
|
|
consume();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (TokenKind) {
|
|
|
|
#define TOKEN(TokenName) \
|
|
|
|
case Kind::TokenName: \
|
|
|
|
return getExpectedError(#TokenName);
|
|
|
|
#define SHORT_TOKEN(TokenName, TokenCh) \
|
|
|
|
case Kind::TokenName: \
|
|
|
|
return getExpectedError(#TokenCh);
|
2017-11-21 08:23:19 +08:00
|
|
|
#include "ResourceScriptTokenList.def"
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("All case options exhausted.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RCParser::consumeOptionalType(Kind TokenKind) {
|
|
|
|
if (isNextTokenKind(TokenKind)) {
|
|
|
|
consume();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-07 05:26:06 +08:00
|
|
|
Expected<SmallVector<RCInt, 8>> RCParser::readIntsWithCommas(size_t MinCount,
|
|
|
|
size_t MaxCount) {
|
2017-08-19 02:24:17 +08:00
|
|
|
assert(MinCount <= MaxCount);
|
|
|
|
|
2017-10-07 05:26:06 +08:00
|
|
|
SmallVector<RCInt, 8> Result;
|
2017-08-19 02:24:17 +08:00
|
|
|
|
|
|
|
auto FailureHandler =
|
2017-10-07 05:26:06 +08:00
|
|
|
[&](llvm::Error Err) -> Expected<SmallVector<RCInt, 8>> {
|
2017-08-19 02:24:17 +08:00
|
|
|
if (Result.size() < MinCount)
|
|
|
|
return std::move(Err);
|
|
|
|
consumeError(std::move(Err));
|
|
|
|
return Result;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MaxCount; ++i) {
|
|
|
|
// Try to read a comma unless we read the first token.
|
|
|
|
// Sometimes RC tool requires them and sometimes not. We decide to
|
|
|
|
// always require them.
|
|
|
|
if (i >= 1) {
|
|
|
|
if (auto CommaError = consumeType(Kind::Comma))
|
|
|
|
return FailureHandler(std::move(CommaError));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto IntResult = readInt())
|
|
|
|
Result.push_back(*IntResult);
|
|
|
|
else
|
|
|
|
return FailureHandler(IntResult.takeError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Result);
|
|
|
|
}
|
|
|
|
|
2017-09-30 01:46:32 +08:00
|
|
|
Expected<uint32_t> RCParser::parseFlags(ArrayRef<StringRef> FlagDesc,
|
|
|
|
ArrayRef<uint32_t> FlagValues) {
|
2017-08-29 06:58:31 +08:00
|
|
|
assert(!FlagDesc.empty());
|
2017-09-30 01:46:32 +08:00
|
|
|
assert(FlagDesc.size() == FlagValues.size());
|
2017-08-29 06:58:31 +08:00
|
|
|
|
|
|
|
uint32_t Result = 0;
|
|
|
|
while (isNextTokenKind(Kind::Comma)) {
|
|
|
|
consume();
|
|
|
|
ASSIGN_OR_RETURN(FlagResult, readIdentifier());
|
|
|
|
bool FoundFlag = false;
|
|
|
|
|
|
|
|
for (size_t FlagId = 0; FlagId < FlagDesc.size(); ++FlagId) {
|
|
|
|
if (!FlagResult->equals_lower(FlagDesc[FlagId]))
|
|
|
|
continue;
|
|
|
|
|
2017-09-30 01:46:32 +08:00
|
|
|
Result |= FlagValues[FlagId];
|
2017-08-29 06:58:31 +08:00
|
|
|
FoundFlag = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FoundFlag)
|
|
|
|
return getExpectedError(join(FlagDesc, "/"), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t RCParser::parseMemoryFlags(uint16_t Flags) {
|
|
|
|
while (!isEof()) {
|
|
|
|
const RCToken &Token = look();
|
|
|
|
if (Token.kind() != Kind::Identifier)
|
|
|
|
return Flags;
|
|
|
|
const StringRef Ident = Token.value();
|
|
|
|
if (Ident.equals_lower("PRELOAD"))
|
|
|
|
Flags |= MfPreload;
|
|
|
|
else if (Ident.equals_lower("LOADONCALL"))
|
|
|
|
Flags &= ~MfPreload;
|
|
|
|
else if (Ident.equals_lower("FIXED"))
|
|
|
|
Flags &= ~(MfMoveable | MfDiscardable);
|
|
|
|
else if (Ident.equals_lower("MOVEABLE"))
|
|
|
|
Flags |= MfMoveable;
|
|
|
|
else if (Ident.equals_lower("DISCARDABLE"))
|
|
|
|
Flags |= MfDiscardable | MfMoveable | MfPure;
|
|
|
|
else if (Ident.equals_lower("PURE"))
|
|
|
|
Flags |= MfPure;
|
|
|
|
else if (Ident.equals_lower("IMPURE"))
|
|
|
|
Flags &= ~(MfPure | MfDiscardable);
|
|
|
|
else if (Ident.equals_lower("SHARED"))
|
|
|
|
Flags |= MfPure;
|
|
|
|
else if (Ident.equals_lower("NONSHARED"))
|
|
|
|
Flags &= ~(MfPure | MfDiscardable);
|
|
|
|
else
|
|
|
|
return Flags;
|
|
|
|
consume();
|
|
|
|
}
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:51:20 +08:00
|
|
|
Expected<OptionalStmtList>
|
|
|
|
RCParser::parseOptionalStatements(OptStmtType StmtsType) {
|
2017-08-19 02:24:17 +08:00
|
|
|
OptionalStmtList Result;
|
|
|
|
|
|
|
|
// The last statement is always followed by the start of the block.
|
|
|
|
while (!isNextTokenKind(Kind::BlockBegin)) {
|
2017-10-07 04:51:20 +08:00
|
|
|
ASSIGN_OR_RETURN(SingleParse, parseSingleOptionalStatement(StmtsType));
|
2017-08-19 02:24:17 +08:00
|
|
|
Result.addStmt(std::move(*SingleParse));
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<std::unique_ptr<OptionalStmt>>
|
2017-10-07 04:51:20 +08:00
|
|
|
RCParser::parseSingleOptionalStatement(OptStmtType StmtsType) {
|
2017-08-19 02:24:17 +08:00
|
|
|
ASSIGN_OR_RETURN(TypeToken, readIdentifier());
|
|
|
|
if (TypeToken->equals_lower("CHARACTERISTICS"))
|
|
|
|
return parseCharacteristicsStmt();
|
2017-08-30 00:49:59 +08:00
|
|
|
if (TypeToken->equals_lower("LANGUAGE"))
|
2017-08-19 02:24:17 +08:00
|
|
|
return parseLanguageStmt();
|
2017-08-30 00:49:59 +08:00
|
|
|
if (TypeToken->equals_lower("VERSION"))
|
2017-08-19 02:24:17 +08:00
|
|
|
return parseVersionStmt();
|
2017-08-30 00:49:59 +08:00
|
|
|
|
2017-10-07 04:51:20 +08:00
|
|
|
if (StmtsType != OptStmtType::BasicStmt) {
|
2017-08-30 00:49:59 +08:00
|
|
|
if (TypeToken->equals_lower("CAPTION"))
|
|
|
|
return parseCaptionStmt();
|
2018-05-16 03:21:28 +08:00
|
|
|
if (TypeToken->equals_lower("CLASS"))
|
|
|
|
return parseClassStmt();
|
2018-11-29 20:17:39 +08:00
|
|
|
if (TypeToken->equals_lower("EXSTYLE"))
|
|
|
|
return parseExStyleStmt();
|
2017-08-30 00:49:59 +08:00
|
|
|
if (TypeToken->equals_lower("FONT"))
|
2017-10-07 04:51:20 +08:00
|
|
|
return parseFontStmt(StmtsType);
|
2017-08-30 00:49:59 +08:00
|
|
|
if (TypeToken->equals_lower("STYLE"))
|
|
|
|
return parseStyleStmt();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getExpectedError("optional statement type, BEGIN or '{'",
|
|
|
|
/* IsAlreadyRead = */ true);
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RCParser::ParseType RCParser::parseLanguageResource() {
|
|
|
|
// Read LANGUAGE as an optional statement. If it's read correctly, we can
|
|
|
|
// upcast it to RCResource.
|
|
|
|
return parseLanguageStmt();
|
|
|
|
}
|
|
|
|
|
2017-08-29 06:58:31 +08:00
|
|
|
RCParser::ParseType RCParser::parseAcceleratorsResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(AcceleratorsResource::getDefaultMemoryFlags());
|
2017-08-29 06:58:31 +08:00
|
|
|
ASSIGN_OR_RETURN(OptStatements, parseOptionalStatements());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
|
|
|
|
|
2018-05-15 14:35:29 +08:00
|
|
|
auto Accels = llvm::make_unique<AcceleratorsResource>(
|
|
|
|
std::move(*OptStatements), MemoryFlags);
|
2017-08-29 06:58:31 +08:00
|
|
|
|
|
|
|
while (!consumeOptionalType(Kind::BlockEnd)) {
|
|
|
|
ASSIGN_OR_RETURN(EventResult, readIntOrString());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
ASSIGN_OR_RETURN(IDResult, readInt());
|
2017-09-30 01:46:32 +08:00
|
|
|
ASSIGN_OR_RETURN(
|
|
|
|
FlagsResult,
|
|
|
|
parseFlags(AcceleratorsResource::Accelerator::OptionsStr,
|
|
|
|
AcceleratorsResource::Accelerator::OptionsFlags));
|
2017-08-29 06:58:31 +08:00
|
|
|
Accels->addAccelerator(*EventResult, *IDResult, *FlagsResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Accels);
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:59:54 +08:00
|
|
|
RCParser::ParseType RCParser::parseCursorResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(CursorResource::getDefaultMemoryFlags());
|
2018-05-08 16:47:37 +08:00
|
|
|
ASSIGN_OR_RETURN(Arg, readFilename());
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<CursorResource>(*Arg, MemoryFlags);
|
2017-08-29 05:59:54 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 00:49:59 +08:00
|
|
|
RCParser::ParseType RCParser::parseDialogResource(bool IsExtended) {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(DialogResource::getDefaultMemoryFlags());
|
2017-08-30 00:49:59 +08:00
|
|
|
// Dialog resources have the following format of the arguments:
|
|
|
|
// DIALOG: x, y, width, height [opt stmts...] {controls...}
|
|
|
|
// DIALOGEX: x, y, width, height [, helpID] [opt stmts...] {controls...}
|
|
|
|
// These are very similar, so we parse them together.
|
|
|
|
ASSIGN_OR_RETURN(LocResult, readIntsWithCommas(4, 4));
|
|
|
|
|
|
|
|
uint32_t HelpID = 0; // When HelpID is unset, it's assumed to be 0.
|
|
|
|
if (IsExtended && consumeOptionalType(Kind::Comma)) {
|
|
|
|
ASSIGN_OR_RETURN(HelpIDResult, readInt());
|
|
|
|
HelpID = *HelpIDResult;
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:51:20 +08:00
|
|
|
ASSIGN_OR_RETURN(OptStatements, parseOptionalStatements(
|
|
|
|
IsExtended ? OptStmtType::DialogExStmt
|
|
|
|
: OptStmtType::DialogStmt));
|
2017-08-30 00:49:59 +08:00
|
|
|
|
|
|
|
assert(isNextTokenKind(Kind::BlockBegin) &&
|
|
|
|
"parseOptionalStatements, when successful, halts on BlockBegin.");
|
|
|
|
consume();
|
|
|
|
|
2017-09-29 08:33:57 +08:00
|
|
|
auto Dialog = llvm::make_unique<DialogResource>(
|
2017-08-30 00:49:59 +08:00
|
|
|
(*LocResult)[0], (*LocResult)[1], (*LocResult)[2], (*LocResult)[3],
|
2018-05-15 14:35:29 +08:00
|
|
|
HelpID, std::move(*OptStatements), IsExtended, MemoryFlags);
|
2017-08-30 00:49:59 +08:00
|
|
|
|
|
|
|
while (!consumeOptionalType(Kind::BlockEnd)) {
|
|
|
|
ASSIGN_OR_RETURN(ControlDefResult, parseControl());
|
|
|
|
Dialog->addControl(std::move(*ControlDefResult));
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Dialog);
|
|
|
|
}
|
|
|
|
|
2017-09-29 08:14:18 +08:00
|
|
|
RCParser::ParseType RCParser::parseUserDefinedResource(IntOrString Type) {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(UserDefinedResource::getDefaultMemoryFlags());
|
2017-09-29 08:14:18 +08:00
|
|
|
if (isEof())
|
|
|
|
return getExpectedError("filename, '{' or BEGIN");
|
|
|
|
|
|
|
|
// Check if this is a file resource.
|
2018-05-08 16:47:37 +08:00
|
|
|
switch (look().kind()) {
|
|
|
|
case Kind::String:
|
|
|
|
case Kind::Identifier:
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<UserDefinedResource>(Type, read().value(),
|
|
|
|
MemoryFlags);
|
2018-05-08 16:47:37 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-09-29 08:14:18 +08:00
|
|
|
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
|
|
|
|
std::vector<IntOrString> Data;
|
|
|
|
|
|
|
|
// Consume comma before each consecutive token except the first one.
|
|
|
|
bool ConsumeComma = false;
|
|
|
|
while (!consumeOptionalType(Kind::BlockEnd)) {
|
|
|
|
if (ConsumeComma)
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
ConsumeComma = true;
|
|
|
|
|
|
|
|
ASSIGN_OR_RETURN(Item, readIntOrString());
|
|
|
|
Data.push_back(*Item);
|
|
|
|
}
|
|
|
|
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<UserDefinedResource>(Type, std::move(Data),
|
|
|
|
MemoryFlags);
|
2017-09-29 08:14:18 +08:00
|
|
|
}
|
|
|
|
|
2017-09-29 06:41:38 +08:00
|
|
|
RCParser::ParseType RCParser::parseVersionInfoResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(VersionInfoResource::getDefaultMemoryFlags());
|
2017-09-29 06:41:38 +08:00
|
|
|
ASSIGN_OR_RETURN(FixedResult, parseVersionInfoFixed());
|
|
|
|
ASSIGN_OR_RETURN(BlockResult, parseVersionInfoBlockContents(StringRef()));
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<VersionInfoResource>(
|
|
|
|
std::move(**BlockResult), std::move(*FixedResult), MemoryFlags);
|
2017-09-29 06:41:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 00:49:59 +08:00
|
|
|
Expected<Control> RCParser::parseControl() {
|
|
|
|
// Each control definition (except CONTROL) follows one of the schemes below
|
|
|
|
// depending on the control class:
|
|
|
|
// [class] text, id, x, y, width, height [, style] [, exstyle] [, helpID]
|
|
|
|
// [class] id, x, y, width, height [, style] [, exstyle] [, helpID]
|
|
|
|
// Note that control ids must be integers.
|
2017-09-30 08:38:52 +08:00
|
|
|
// Text might be either a string or an integer pointing to resource ID.
|
2017-08-30 00:49:59 +08:00
|
|
|
ASSIGN_OR_RETURN(ClassResult, readIdentifier());
|
2017-08-30 04:03:18 +08:00
|
|
|
std::string ClassUpper = ClassResult->upper();
|
2017-09-30 08:38:52 +08:00
|
|
|
auto CtlInfo = Control::SupportedCtls.find(ClassUpper);
|
|
|
|
if (CtlInfo == Control::SupportedCtls.end())
|
2017-08-30 00:49:59 +08:00
|
|
|
return getExpectedError("control type, END or '}'", true);
|
|
|
|
|
|
|
|
// Read caption if necessary.
|
2017-09-30 08:38:52 +08:00
|
|
|
IntOrString Caption{StringRef()};
|
|
|
|
if (CtlInfo->getValue().HasTitle) {
|
|
|
|
ASSIGN_OR_RETURN(CaptionResult, readIntOrString());
|
2017-08-30 00:49:59 +08:00
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
Caption = *CaptionResult;
|
|
|
|
}
|
|
|
|
|
2018-05-09 04:55:58 +08:00
|
|
|
ASSIGN_OR_RETURN(ID, readInt());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
|
|
|
|
IntOrString Class;
|
2018-12-05 21:22:56 +08:00
|
|
|
Optional<IntWithNotMask> Style;
|
2018-05-09 04:55:58 +08:00
|
|
|
if (ClassUpper == "CONTROL") {
|
|
|
|
// CONTROL text, id, class, style, x, y, width, height [, exstyle] [, helpID]
|
|
|
|
ASSIGN_OR_RETURN(ClassStr, readString());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
Class = *ClassStr;
|
2018-12-05 21:22:56 +08:00
|
|
|
ASSIGN_OR_RETURN(StyleVal, parseIntExpr1());
|
2018-05-09 04:55:58 +08:00
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
Style = *StyleVal;
|
|
|
|
} else {
|
|
|
|
Class = CtlInfo->getValue().CtlClass;
|
|
|
|
}
|
2017-08-30 00:49:59 +08:00
|
|
|
|
2018-05-09 04:55:58 +08:00
|
|
|
// x, y, width, height
|
|
|
|
ASSIGN_OR_RETURN(Args, readIntsWithCommas(4, 4));
|
|
|
|
|
|
|
|
if (ClassUpper != "CONTROL") {
|
|
|
|
if (consumeOptionalType(Kind::Comma)) {
|
2018-12-05 21:22:56 +08:00
|
|
|
ASSIGN_OR_RETURN(Val, parseIntExpr1());
|
2018-05-09 04:55:58 +08:00
|
|
|
Style = *Val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<uint32_t> ExStyle;
|
|
|
|
if (consumeOptionalType(Kind::Comma)) {
|
|
|
|
ASSIGN_OR_RETURN(Val, readInt());
|
|
|
|
ExStyle = *Val;
|
|
|
|
}
|
|
|
|
Optional<uint32_t> HelpID;
|
|
|
|
if (consumeOptionalType(Kind::Comma)) {
|
|
|
|
ASSIGN_OR_RETURN(Val, readInt());
|
|
|
|
HelpID = *Val;
|
|
|
|
}
|
2017-08-30 00:49:59 +08:00
|
|
|
|
2018-05-09 04:55:58 +08:00
|
|
|
return Control(*ClassResult, Caption, *ID, (*Args)[0], (*Args)[1],
|
|
|
|
(*Args)[2], (*Args)[3], Style, ExStyle, HelpID, Class);
|
2017-08-30 00:49:59 +08:00
|
|
|
}
|
|
|
|
|
2018-05-08 04:27:37 +08:00
|
|
|
RCParser::ParseType RCParser::parseBitmapResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(BitmapResource::getDefaultMemoryFlags());
|
2018-05-08 16:47:37 +08:00
|
|
|
ASSIGN_OR_RETURN(Arg, readFilename());
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<BitmapResource>(*Arg, MemoryFlags);
|
2018-05-08 04:27:37 +08:00
|
|
|
}
|
|
|
|
|
2017-08-19 02:24:17 +08:00
|
|
|
RCParser::ParseType RCParser::parseIconResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(IconResource::getDefaultMemoryFlags());
|
2018-05-08 16:47:37 +08:00
|
|
|
ASSIGN_OR_RETURN(Arg, readFilename());
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<IconResource>(*Arg, MemoryFlags);
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 05:59:54 +08:00
|
|
|
RCParser::ParseType RCParser::parseHTMLResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(HTMLResource::getDefaultMemoryFlags());
|
2018-05-08 16:47:37 +08:00
|
|
|
ASSIGN_OR_RETURN(Arg, readFilename());
|
2018-05-15 14:35:29 +08:00
|
|
|
return llvm::make_unique<HTMLResource>(*Arg, MemoryFlags);
|
2017-08-29 05:59:54 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 07:46:30 +08:00
|
|
|
RCParser::ParseType RCParser::parseMenuResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(MenuResource::getDefaultMemoryFlags());
|
2017-08-29 07:46:30 +08:00
|
|
|
ASSIGN_OR_RETURN(OptStatements, parseOptionalStatements());
|
|
|
|
ASSIGN_OR_RETURN(Items, parseMenuItemsList());
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<MenuResource>(std::move(*OptStatements),
|
2018-05-15 14:35:29 +08:00
|
|
|
std::move(*Items), MemoryFlags);
|
2017-08-29 07:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expected<MenuDefinitionList> RCParser::parseMenuItemsList() {
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
|
|
|
|
|
|
|
|
MenuDefinitionList List;
|
|
|
|
|
|
|
|
// Read a set of items. Each item is of one of three kinds:
|
|
|
|
// MENUITEM SEPARATOR
|
|
|
|
// MENUITEM caption:String, result:Int [, menu flags]...
|
|
|
|
// POPUP caption:String [, menu flags]... { items... }
|
|
|
|
while (!consumeOptionalType(Kind::BlockEnd)) {
|
|
|
|
ASSIGN_OR_RETURN(ItemTypeResult, readIdentifier());
|
|
|
|
|
|
|
|
bool IsMenuItem = ItemTypeResult->equals_lower("MENUITEM");
|
|
|
|
bool IsPopup = ItemTypeResult->equals_lower("POPUP");
|
|
|
|
if (!IsMenuItem && !IsPopup)
|
|
|
|
return getExpectedError("MENUITEM, POPUP, END or '}'", true);
|
|
|
|
|
|
|
|
if (IsMenuItem && isNextTokenKind(Kind::Identifier)) {
|
|
|
|
// Now, expecting SEPARATOR.
|
|
|
|
ASSIGN_OR_RETURN(SeparatorResult, readIdentifier());
|
|
|
|
if (SeparatorResult->equals_lower("SEPARATOR")) {
|
2017-09-29 08:33:57 +08:00
|
|
|
List.addDefinition(llvm::make_unique<MenuSeparator>());
|
2017-08-29 07:46:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getExpectedError("SEPARATOR or string", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a separator. Read the caption.
|
|
|
|
ASSIGN_OR_RETURN(CaptionResult, readString());
|
|
|
|
|
|
|
|
// If MENUITEM, expect also a comma and an integer.
|
|
|
|
uint32_t MenuResult = -1;
|
|
|
|
|
|
|
|
if (IsMenuItem) {
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
ASSIGN_OR_RETURN(IntResult, readInt());
|
|
|
|
MenuResult = *IntResult;
|
|
|
|
}
|
|
|
|
|
2017-09-30 01:46:32 +08:00
|
|
|
ASSIGN_OR_RETURN(FlagsResult, parseFlags(MenuDefinition::OptionsStr,
|
|
|
|
MenuDefinition::OptionsFlags));
|
2017-08-29 07:46:30 +08:00
|
|
|
|
|
|
|
if (IsPopup) {
|
|
|
|
// If POPUP, read submenu items recursively.
|
|
|
|
ASSIGN_OR_RETURN(SubMenuResult, parseMenuItemsList());
|
2017-09-29 08:33:57 +08:00
|
|
|
List.addDefinition(llvm::make_unique<PopupItem>(
|
|
|
|
*CaptionResult, *FlagsResult, std::move(*SubMenuResult)));
|
2017-08-29 07:46:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(IsMenuItem);
|
|
|
|
List.addDefinition(
|
2017-09-29 08:33:57 +08:00
|
|
|
llvm::make_unique<MenuItem>(*CaptionResult, MenuResult, *FlagsResult));
|
2017-08-29 07:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(List);
|
|
|
|
}
|
|
|
|
|
2017-08-19 02:24:17 +08:00
|
|
|
RCParser::ParseType RCParser::parseStringTableResource() {
|
2018-05-15 14:35:29 +08:00
|
|
|
uint16_t MemoryFlags =
|
|
|
|
parseMemoryFlags(StringTableResource::getDefaultMemoryFlags());
|
2017-08-19 02:24:17 +08:00
|
|
|
ASSIGN_OR_RETURN(OptStatements, parseOptionalStatements());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
|
|
|
|
|
2018-05-15 14:35:29 +08:00
|
|
|
auto Table = llvm::make_unique<StringTableResource>(std::move(*OptStatements),
|
|
|
|
MemoryFlags);
|
2017-08-19 02:24:17 +08:00
|
|
|
|
|
|
|
// Read strings until we reach the end of the block.
|
|
|
|
while (!consumeOptionalType(Kind::BlockEnd)) {
|
|
|
|
// Each definition consists of string's ID (an integer) and a string.
|
|
|
|
// Some examples in documentation suggest that there might be a comma in
|
|
|
|
// between, however we strictly adhere to the single statement definition.
|
|
|
|
ASSIGN_OR_RETURN(IDResult, readInt());
|
2018-05-08 04:27:28 +08:00
|
|
|
consumeOptionalType(Kind::Comma);
|
2017-08-19 02:24:17 +08:00
|
|
|
ASSIGN_OR_RETURN(StrResult, readString());
|
|
|
|
Table->addString(*IDResult, *StrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(Table);
|
|
|
|
}
|
|
|
|
|
2017-09-29 06:41:38 +08:00
|
|
|
Expected<std::unique_ptr<VersionInfoBlock>>
|
|
|
|
RCParser::parseVersionInfoBlockContents(StringRef BlockName) {
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
|
|
|
|
|
2017-09-29 07:12:53 +08:00
|
|
|
auto Contents = llvm::make_unique<VersionInfoBlock>(BlockName);
|
2017-09-29 06:41:38 +08:00
|
|
|
|
|
|
|
while (!isNextTokenKind(Kind::BlockEnd)) {
|
|
|
|
ASSIGN_OR_RETURN(Stmt, parseVersionInfoStmt());
|
|
|
|
Contents->addStmt(std::move(*Stmt));
|
|
|
|
}
|
|
|
|
|
|
|
|
consume(); // Consume BlockEnd.
|
|
|
|
|
|
|
|
return std::move(Contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<std::unique_ptr<VersionInfoStmt>> RCParser::parseVersionInfoStmt() {
|
|
|
|
// Expect either BLOCK or VALUE, then a name or a key (a string).
|
|
|
|
ASSIGN_OR_RETURN(TypeResult, readIdentifier());
|
|
|
|
|
|
|
|
if (TypeResult->equals_lower("BLOCK")) {
|
|
|
|
ASSIGN_OR_RETURN(NameResult, readString());
|
|
|
|
return parseVersionInfoBlockContents(*NameResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TypeResult->equals_lower("VALUE")) {
|
|
|
|
ASSIGN_OR_RETURN(KeyResult, readString());
|
2017-10-07 05:26:06 +08:00
|
|
|
// Read a non-empty list of strings and/or ints, each
|
|
|
|
// possibly preceded by a comma. Unfortunately, the tool behavior depends
|
|
|
|
// on them existing or not, so we need to memorize where we found them.
|
2017-09-29 06:41:38 +08:00
|
|
|
std::vector<IntOrString> Values;
|
2017-10-07 05:26:06 +08:00
|
|
|
std::vector<bool> PrecedingCommas;
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
while (!isNextTokenKind(Kind::Identifier) &&
|
|
|
|
!isNextTokenKind(Kind::BlockEnd)) {
|
|
|
|
// Try to eat a comma if it's not the first statement.
|
|
|
|
bool HadComma = Values.size() > 0 && consumeOptionalType(Kind::Comma);
|
2017-09-29 06:41:38 +08:00
|
|
|
ASSIGN_OR_RETURN(ValueResult, readIntOrString());
|
|
|
|
Values.push_back(*ValueResult);
|
2017-10-07 05:26:06 +08:00
|
|
|
PrecedingCommas.push_back(HadComma);
|
2017-09-29 06:41:38 +08:00
|
|
|
}
|
2017-10-07 05:26:06 +08:00
|
|
|
return llvm::make_unique<VersionInfoValue>(*KeyResult, std::move(Values),
|
|
|
|
std::move(PrecedingCommas));
|
2017-09-29 06:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return getExpectedError("BLOCK or VALUE", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<VersionInfoResource::VersionInfoFixed>
|
|
|
|
RCParser::parseVersionInfoFixed() {
|
|
|
|
using RetType = VersionInfoResource::VersionInfoFixed;
|
|
|
|
RetType Result;
|
|
|
|
|
|
|
|
// Read until the beginning of the block.
|
|
|
|
while (!isNextTokenKind(Kind::BlockBegin)) {
|
|
|
|
ASSIGN_OR_RETURN(TypeResult, readIdentifier());
|
|
|
|
auto FixedType = RetType::getFixedType(*TypeResult);
|
|
|
|
|
|
|
|
if (!RetType::isTypeSupported(FixedType))
|
|
|
|
return getExpectedError("fixed VERSIONINFO statement type", true);
|
|
|
|
if (Result.IsTypePresent[FixedType])
|
|
|
|
return getExpectedError("yet unread fixed VERSIONINFO statement type",
|
|
|
|
true);
|
|
|
|
|
|
|
|
// VERSION variations take multiple integers.
|
|
|
|
size_t NumInts = RetType::isVersionType(FixedType) ? 4 : 1;
|
|
|
|
ASSIGN_OR_RETURN(ArgsResult, readIntsWithCommas(NumInts, NumInts));
|
2017-10-07 05:26:06 +08:00
|
|
|
SmallVector<uint32_t, 4> ArgInts(ArgsResult->begin(), ArgsResult->end());
|
|
|
|
Result.setValue(FixedType, ArgInts);
|
2017-09-29 06:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-08-19 02:24:17 +08:00
|
|
|
RCParser::ParseOptionType RCParser::parseLanguageStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Args, readIntsWithCommas(/* min = */ 2, /* max = */ 2));
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<LanguageResource>((*Args)[0], (*Args)[1]);
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RCParser::ParseOptionType RCParser::parseCharacteristicsStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readInt());
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<CharacteristicsStmt>(*Arg);
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RCParser::ParseOptionType RCParser::parseVersionStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readInt());
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<VersionStmt>(*Arg);
|
2017-08-19 02:24:17 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 00:49:59 +08:00
|
|
|
RCParser::ParseOptionType RCParser::parseCaptionStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readString());
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<CaptionStmt>(*Arg);
|
2017-08-30 00:49:59 +08:00
|
|
|
}
|
|
|
|
|
2018-05-16 03:21:28 +08:00
|
|
|
RCParser::ParseOptionType RCParser::parseClassStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readIntOrString());
|
|
|
|
return llvm::make_unique<ClassStmt>(*Arg);
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:51:20 +08:00
|
|
|
RCParser::ParseOptionType RCParser::parseFontStmt(OptStmtType DialogType) {
|
|
|
|
assert(DialogType != OptStmtType::BasicStmt);
|
|
|
|
|
2017-08-30 00:49:59 +08:00
|
|
|
ASSIGN_OR_RETURN(SizeResult, readInt());
|
|
|
|
RETURN_IF_ERROR(consumeType(Kind::Comma));
|
|
|
|
ASSIGN_OR_RETURN(NameResult, readString());
|
2017-10-07 04:51:20 +08:00
|
|
|
|
|
|
|
// Default values for the optional arguments.
|
|
|
|
uint32_t FontWeight = 0;
|
|
|
|
bool FontItalic = false;
|
|
|
|
uint32_t FontCharset = 1;
|
|
|
|
if (DialogType == OptStmtType::DialogExStmt) {
|
|
|
|
if (consumeOptionalType(Kind::Comma)) {
|
|
|
|
ASSIGN_OR_RETURN(Args, readIntsWithCommas(/* min = */ 0, /* max = */ 3));
|
|
|
|
if (Args->size() >= 1)
|
|
|
|
FontWeight = (*Args)[0];
|
|
|
|
if (Args->size() >= 2)
|
|
|
|
FontItalic = (*Args)[1] != 0;
|
|
|
|
if (Args->size() >= 3)
|
|
|
|
FontCharset = (*Args)[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return llvm::make_unique<FontStmt>(*SizeResult, *NameResult, FontWeight,
|
|
|
|
FontItalic, FontCharset);
|
2017-08-30 00:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RCParser::ParseOptionType RCParser::parseStyleStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readInt());
|
2017-09-29 08:33:57 +08:00
|
|
|
return llvm::make_unique<StyleStmt>(*Arg);
|
2017-08-30 00:49:59 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 20:17:39 +08:00
|
|
|
RCParser::ParseOptionType RCParser::parseExStyleStmt() {
|
|
|
|
ASSIGN_OR_RETURN(Arg, readInt());
|
|
|
|
return llvm::make_unique<ExStyleStmt>(*Arg);
|
|
|
|
}
|
|
|
|
|
2017-10-10 02:50:29 +08:00
|
|
|
Error RCParser::getExpectedError(const Twine &Message, bool IsAlreadyRead) {
|
2017-08-19 02:24:17 +08:00
|
|
|
return make_error<ParserError>(
|
|
|
|
Message, IsAlreadyRead ? std::prev(CurLoc) : CurLoc, End);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace rc
|
|
|
|
} // namespace llvm
|