Changeset View
Changeset View
Standalone View
Standalone View
llvm/tools/llvm-rc/ResourceScriptParser.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | RCParser::ParseType RCParser::parseSingleResource() { | ||||
else if (TypeToken->equalsLower("DIALOGEX")) | else if (TypeToken->equalsLower("DIALOGEX")) | ||||
Result = parseDialogResource(true); | Result = parseDialogResource(true); | ||||
else if (TypeToken->equalsLower("ICON")) | else if (TypeToken->equalsLower("ICON")) | ||||
Result = parseIconResource(); | Result = parseIconResource(); | ||||
else if (TypeToken->equalsLower("HTML")) | else if (TypeToken->equalsLower("HTML")) | ||||
Result = parseHTMLResource(); | Result = parseHTMLResource(); | ||||
else if (TypeToken->equalsLower("MENU")) | else if (TypeToken->equalsLower("MENU")) | ||||
Result = parseMenuResource(); | Result = parseMenuResource(); | ||||
else if (TypeToken->equalsLower("VERSIONINFO")) | |||||
Result = parseVersionInfoResource(); | |||||
else | else | ||||
return getExpectedError("resource type", /* IsAlreadyRead = */ true); | return getExpectedError("resource type", /* IsAlreadyRead = */ true); | ||||
if (Result) | if (Result) | ||||
(*Result)->setName(*NameToken); | (*Result)->setName(*NameToken); | ||||
return Result; | return Result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | RCParser::ParseType RCParser::parseDialogResource(bool IsExtended) { | ||||
while (!consumeOptionalType(Kind::BlockEnd)) { | while (!consumeOptionalType(Kind::BlockEnd)) { | ||||
ASSIGN_OR_RETURN(ControlDefResult, parseControl()); | ASSIGN_OR_RETURN(ControlDefResult, parseControl()); | ||||
Dialog->addControl(std::move(*ControlDefResult)); | Dialog->addControl(std::move(*ControlDefResult)); | ||||
} | } | ||||
return std::move(Dialog); | return std::move(Dialog); | ||||
} | } | ||||
RCParser::ParseType RCParser::parseVersionInfoResource() { | |||||
ASSIGN_OR_RETURN(FixedResult, parseVersionInfoFixed()); | |||||
ASSIGN_OR_RETURN(BlockResult, parseVersionInfoBlockContents(StringRef())); | |||||
return make_unique<VersionInfoResource>(std::move(**BlockResult), | |||||
std::move(*FixedResult)); | |||||
} | |||||
Expected<Control> RCParser::parseControl() { | Expected<Control> RCParser::parseControl() { | ||||
// Each control definition (except CONTROL) follows one of the schemes below | // Each control definition (except CONTROL) follows one of the schemes below | ||||
// depending on the control class: | // depending on the control class: | ||||
// [class] text, id, x, y, width, height [, style] [, exstyle] [, helpID] | // [class] text, id, x, y, width, height [, style] [, exstyle] [, helpID] | ||||
// [class] id, x, y, width, height [, style] [, exstyle] [, helpID] | // [class] id, x, y, width, height [, style] [, exstyle] [, helpID] | ||||
// Note that control ids must be integers. | // Note that control ids must be integers. | ||||
ASSIGN_OR_RETURN(ClassResult, readIdentifier()); | ASSIGN_OR_RETURN(ClassResult, readIdentifier()); | ||||
std::string ClassUpper = ClassResult->upper(); | std::string ClassUpper = ClassResult->upper(); | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | while (!consumeOptionalType(Kind::BlockEnd)) { | ||||
ASSIGN_OR_RETURN(IDResult, readInt()); | ASSIGN_OR_RETURN(IDResult, readInt()); | ||||
ASSIGN_OR_RETURN(StrResult, readString()); | ASSIGN_OR_RETURN(StrResult, readString()); | ||||
Table->addString(*IDResult, *StrResult); | Table->addString(*IDResult, *StrResult); | ||||
} | } | ||||
return std::move(Table); | return std::move(Table); | ||||
} | } | ||||
Expected<std::unique_ptr<VersionInfoBlock>> | |||||
RCParser::parseVersionInfoBlockContents(StringRef BlockName) { | |||||
RETURN_IF_ERROR(consumeType(Kind::BlockBegin)); | |||||
auto Contents = make_unique<VersionInfoBlock>(BlockName); | |||||
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); | |||||
} | |||||
ecbeckmann: No else after return. | |||||
if (TypeResult->equals_lower("VALUE")) { | |||||
ASSIGN_OR_RETURN(KeyResult, readString()); | |||||
// Read a (possibly empty) list of strings and/or ints, each preceded by | |||||
// a comma. | |||||
std::vector<IntOrString> Values; | |||||
while (consumeOptionalType(Kind::Comma)) { | |||||
ASSIGN_OR_RETURN(ValueResult, readIntOrString()); | |||||
Values.push_back(*ValueResult); | |||||
} | |||||
return make_unique<VersionInfoValue>(*KeyResult, std::move(Values)); | |||||
ditto ecbeckmann: ditto | |||||
} | |||||
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); | |||||
Can you make a RetType::isTypeSupported() function and just call it? zturner: Can you make a `RetType::isTypeSupported()` function and just call it? | |||||
if (Result.IsTypePresent[FixedType]) | |||||
return getExpectedError("yet unread fixed VERSIONINFO statement type", | |||||
use early continue pattern, remove else clause ecbeckmann: use early continue pattern, remove else clause | |||||
true); | |||||
// VERSION variations take multiple integers. | |||||
size_t NumInts = RetType::isVersionType(FixedType) ? 4 : 1; | |||||
ASSIGN_OR_RETURN(ArgsResult, readIntsWithCommas(NumInts, NumInts)); | |||||
Result.setValue(FixedType, *ArgsResult); | |||||
} | |||||
return Result; | |||||
} | |||||
RCParser::ParseOptionType RCParser::parseLanguageStmt() { | RCParser::ParseOptionType RCParser::parseLanguageStmt() { | ||||
ASSIGN_OR_RETURN(Args, readIntsWithCommas(/* min = */ 2, /* max = */ 2)); | ASSIGN_OR_RETURN(Args, readIntsWithCommas(/* min = */ 2, /* max = */ 2)); | ||||
return make_unique<LanguageResource>((*Args)[0], (*Args)[1]); | return make_unique<LanguageResource>((*Args)[0], (*Args)[1]); | ||||
} | } | ||||
RCParser::ParseOptionType RCParser::parseCharacteristicsStmt() { | RCParser::ParseOptionType RCParser::parseCharacteristicsStmt() { | ||||
ASSIGN_OR_RETURN(Arg, readInt()); | ASSIGN_OR_RETURN(Arg, readInt()); | ||||
return make_unique<CharacteristicsStmt>(*Arg); | return make_unique<CharacteristicsStmt>(*Arg); | ||||
Show All 31 Lines |
No else after return.