summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-rc
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-rc')
-rw-r--r--llvm/tools/llvm-rc/ResourceScriptParser.cpp27
-rw-r--r--llvm/tools/llvm-rc/ResourceScriptParser.h1
-rw-r--r--llvm/tools/llvm-rc/ResourceScriptStmt.cpp10
-rw-r--r--llvm/tools/llvm-rc/ResourceScriptStmt.h18
4 files changed, 55 insertions, 1 deletions
diff --git a/llvm/tools/llvm-rc/ResourceScriptParser.cpp b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
index ee7de6b937a..211d9e7e954 100644
--- a/llvm/tools/llvm-rc/ResourceScriptParser.cpp
+++ b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
@@ -80,7 +80,7 @@ RCParser::ParseType RCParser::parseSingleResource() {
else if (TypeToken->equalsLower("VERSIONINFO"))
Result = parseVersionInfoResource();
else
- return getExpectedError("resource type", /* IsAlreadyRead = */ true);
+ Result = parseUserDefinedResource(*TypeToken);
if (Result)
(*Result)->setName(*NameToken);
@@ -416,6 +416,31 @@ RCParser::ParseType RCParser::parseDialogResource(bool IsExtended) {
return std::move(Dialog);
}
+RCParser::ParseType RCParser::parseUserDefinedResource(IntOrString Type) {
+ if (isEof())
+ return getExpectedError("filename, '{' or BEGIN");
+
+ // Check if this is a file resource.
+ if (look().kind() == Kind::String)
+ return make_unique<UserDefinedResource>(Type, read().value());
+
+ 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);
+ }
+
+ return make_unique<UserDefinedResource>(Type, std::move(Data));
+}
+
RCParser::ParseType RCParser::parseVersionInfoResource() {
ASSIGN_OR_RETURN(FixedResult, parseVersionInfoFixed());
ASSIGN_OR_RETURN(BlockResult, parseVersionInfoBlockContents(StringRef()));
diff --git a/llvm/tools/llvm-rc/ResourceScriptParser.h b/llvm/tools/llvm-rc/ResourceScriptParser.h
index 56042f79d5f..7509b8e9066 100644
--- a/llvm/tools/llvm-rc/ResourceScriptParser.h
+++ b/llvm/tools/llvm-rc/ResourceScriptParser.h
@@ -139,6 +139,7 @@ private:
ParseType parseHTMLResource();
ParseType parseMenuResource();
ParseType parseStringTableResource();
+ ParseType parseUserDefinedResource(IntOrString Type);
ParseType parseVersionInfoResource();
// Helper DIALOG parser - a single control.
diff --git a/llvm/tools/llvm-rc/ResourceScriptStmt.cpp b/llvm/tools/llvm-rc/ResourceScriptStmt.cpp
index eb123e543f0..792ac40e55d 100644
--- a/llvm/tools/llvm-rc/ResourceScriptStmt.cpp
+++ b/llvm/tools/llvm-rc/ResourceScriptStmt.cpp
@@ -214,6 +214,16 @@ raw_ostream &VersionInfoResource::log(raw_ostream &OS) const {
return MainBlock.log(OS);
}
+raw_ostream &UserDefinedResource::log(raw_ostream &OS) const {
+ OS << "User-defined (type: " << Type << ", name: " << ResName << "): ";
+ if (IsFileResource)
+ return OS << FileLoc << "\n";
+ OS << "data = ";
+ for (auto &Item : Contents)
+ OS << Item << " ";
+ return OS << "\n";
+}
+
raw_ostream &CharacteristicsStmt::log(raw_ostream &OS) const {
return OS << "Characteristics: " << Value << "\n";
}
diff --git a/llvm/tools/llvm-rc/ResourceScriptStmt.h b/llvm/tools/llvm-rc/ResourceScriptStmt.h
index b090be4b700..95890fe6669 100644
--- a/llvm/tools/llvm-rc/ResourceScriptStmt.h
+++ b/llvm/tools/llvm-rc/ResourceScriptStmt.h
@@ -319,6 +319,24 @@ public:
raw_ostream &log(raw_ostream &) const override;
};
+// User-defined resource. It is either:
+// * a link to the file, e.g. NAME TYPE "filename",
+// * or contains a list of integers and strings, e.g. NAME TYPE {1, "a", 2}.
+class UserDefinedResource : public RCResource {
+ IntOrString Type;
+ StringRef FileLoc;
+ std::vector<IntOrString> Contents;
+ bool IsFileResource;
+
+public:
+ UserDefinedResource(IntOrString ResourceType, StringRef FileLocation)
+ : Type(ResourceType), FileLoc(FileLocation), IsFileResource(true) {}
+ UserDefinedResource(IntOrString ResourceType, std::vector<IntOrString> &&Data)
+ : Type(ResourceType), Contents(std::move(Data)), IsFileResource(false) {}
+
+ raw_ostream &log(raw_ostream &) const override;
+};
+
// -- VERSIONINFO resource and its helper classes --
//
// This resource lists the version information on the executable/library.
OpenPOWER on IntegriCloud