]> granicus.if.org Git - llvm/commitdiff
[llvm-rc] Add ICON and HTML parsing ability (parser, pt 2/8).
authorMarek Sokolowski <mnbvmar@gmail.com>
Mon, 28 Aug 2017 21:59:54 +0000 (21:59 +0000)
committerMarek Sokolowski <mnbvmar@gmail.com>
Mon, 28 Aug 2017 21:59:54 +0000 (21:59 +0000)
This extends the current llvm-rc parser by ICON and HTML resources.
Moreover, some tests have been slightly rewritten.

Thanks for Nico Weber for his original work in this area.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311939 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-rc/Inputs/parser-correct-everything.rc
test/tools/llvm-rc/Inputs/parser-html-bad-string.rc [new file with mode: 0644]
test/tools/llvm-rc/Inputs/parser-html-extra-comma.rc [new file with mode: 0644]
test/tools/llvm-rc/parser.test
tools/llvm-rc/ResourceScriptParser.cpp
tools/llvm-rc/ResourceScriptParser.h
tools/llvm-rc/ResourceScriptStmt.cpp
tools/llvm-rc/ResourceScriptStmt.h

index 6337a369fe642dbd3bef42a15417c3645a56f8b5..37fc1cfe22c23237ca14596434b13db0f669b49a 100644 (file)
@@ -13,3 +13,6 @@ VERSION 14
   2 "world"
 }
 STRINGTABLE BEGIN END
+
+500 HTML "index.html"
+Name Cursor "hello.ico"
diff --git a/test/tools/llvm-rc/Inputs/parser-html-bad-string.rc b/test/tools/llvm-rc/Inputs/parser-html-bad-string.rc
new file mode 100644 (file)
index 0000000..5edab85
--- /dev/null
@@ -0,0 +1 @@
+200 HTML ThisPassesInTheOriginalToolButDocSaysItShouldBeQuoted
diff --git a/test/tools/llvm-rc/Inputs/parser-html-extra-comma.rc b/test/tools/llvm-rc/Inputs/parser-html-extra-comma.rc
new file mode 100644 (file)
index 0000000..e80c52c
--- /dev/null
@@ -0,0 +1 @@
+1 HTML, "index.html"
index 40b66da88fbd983f3c5f85624d37feaa97a1cb53..9b990a3c54317ff41da6b4e5472f7985356525df 100644 (file)
 ; PGOOD-NEXT:    1 => "hello"
 ; PGOOD-NEXT:    2 => "world"
 ; PGOOD-NEXT:  StringTable:
+; PGOOD-NEXT:  HTML (500): "index.html"
+; PGOOD-NEXT:  Cursor (Name): "hello.ico"
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-stringtable-no-string.rc 2> %t2
-; RUN: FileCheck %s --check-prefix PSTRINGTABLE1 --input-file %t2
+; RUN: not llvm-rc /V %p/Inputs/parser-stringtable-no-string.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE1
 
 ; PSTRINGTABLE1:  llvm-rc: Error parsing file: expected string, got }
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-stringtable-weird-option.rc 2> %t3
-; RUN: FileCheck %s --check-prefix PSTRINGTABLE2 --input-file %t3
+; RUN: not llvm-rc /V %p/Inputs/parser-stringtable-weird-option.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE2
 
 ; PSTRINGTABLE2:  llvm-rc: Error parsing file: expected optional statement type, BEGIN or '{', got NONSENSETYPE
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-eof.rc 2> %t4
-; RUN: FileCheck %s --check-prefix PEOF --input-file %t4
+; RUN: not llvm-rc /V %p/Inputs/parser-eof.rc 2>&1 | FileCheck %s --check-prefix PEOF
 
 ; PEOF:  llvm-rc: Error parsing file: expected integer, got <EOF>
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-no-characteristics-arg.rc 2> %t5
-; RUN: FileCheck %s --check-prefix PCHARACTERISTICS1 --input-file %t5
+; RUN: not llvm-rc /V %p/Inputs/parser-no-characteristics-arg.rc 2>&1 | FileCheck %s --check-prefix PCHARACTERISTICS1
 
 ; PCHARACTERISTICS1:  llvm-rc: Error parsing file: expected integer, got BEGIN
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-token.rc 2> %t6
-; RUN: FileCheck %s --check-prefix PNONSENSE1 --input-file %t6
+; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-token.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE1
 
 ; PNONSENSE1:  llvm-rc: Error parsing file: expected int or identifier, got &
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-type.rc 2> %t7
-; RUN: FileCheck %s --check-prefix PNONSENSE2 --input-file %t7
+; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-type.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE2
 
 ; PNONSENSE2:  llvm-rc: Error parsing file: expected resource type, got WORLD
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-type-eof.rc 2> %t8
-; RUN: FileCheck %s --check-prefix PNONSENSE3 --input-file %t8
+; RUN: not llvm-rc /V %p/Inputs/parser-nonsense-type-eof.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE3
 
 ; PNONSENSE3:  llvm-rc: Error parsing file: expected int or identifier, got <EOF>
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-language-no-comma.rc 2> %t9
-; RUN: FileCheck %s --check-prefix PLANGUAGE1 --input-file %t9
+; RUN: not llvm-rc /V %p/Inputs/parser-language-no-comma.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE1
 
 ; PLANGUAGE1:  llvm-rc: Error parsing file: expected ',', got 7
 
 
-; RUN: not llvm-rc /V %p/Inputs/parser-language-too-many-commas.rc 2> %t10
-; RUN: FileCheck %s --check-prefix PLANGUAGE2 --input-file %t10
+; RUN: not llvm-rc /V %p/Inputs/parser-language-too-many-commas.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE2
 
 ; PLANGUAGE2:  llvm-rc: Error parsing file: expected integer, got ,
+
+
+; RUN: not llvm-rc /V %p/Inputs/parser-html-bad-string.rc 2>&1 | FileCheck %s --check-prefix PHTML1
+
+; PHTML1:  llvm-rc: Error parsing file: expected string, got ThisPassesInTheOriginalToolButDocSaysItShouldBeQuoted
+
+
+; RUN: not llvm-rc /V %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2
+
+; PHTML2:  llvm-rc: Error parsing file: expected string, got ,
index 1e9bd467c25e4191c3c8a2cef847e603c163d48f..e4c0f2a7f7ca640169c3cebf25e659d34bfaab7d 100644 (file)
@@ -63,8 +63,12 @@ RCParser::ParseType RCParser::parseSingleResource() {
   ParseType Result = std::unique_ptr<RCResource>();
   (void)!Result;
 
-  if (TypeToken->equalsLower("ICON"))
+  if (TypeToken->equalsLower("CURSOR"))
+    Result = parseCursorResource();
+  else if (TypeToken->equalsLower("ICON"))
     Result = parseIconResource();
+  else if (TypeToken->equalsLower("HTML"))
+    Result = parseHTMLResource();
   else
     return getExpectedError("resource type", /* IsAlreadyRead = */ true);
 
@@ -219,11 +223,21 @@ RCParser::ParseType RCParser::parseLanguageResource() {
   return parseLanguageStmt();
 }
 
+RCParser::ParseType RCParser::parseCursorResource() {
+  ASSIGN_OR_RETURN(Arg, readString());
+  return make_unique<CursorResource>(*Arg);
+}
+
 RCParser::ParseType RCParser::parseIconResource() {
   ASSIGN_OR_RETURN(Arg, readString());
   return make_unique<IconResource>(*Arg);
 }
 
+RCParser::ParseType RCParser::parseHTMLResource() {
+  ASSIGN_OR_RETURN(Arg, readString());
+  return make_unique<HTMLResource>(*Arg);
+}
+
 RCParser::ParseType RCParser::parseStringTableResource() {
   ASSIGN_OR_RETURN(OptStatements, parseOptionalStatements());
   RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
index 017e22f273d798756a178d960793717631295a45..b217a73ae765f2b258aa74d974c2da02145e5ad7 100644 (file)
@@ -118,7 +118,9 @@ private:
 
   // Top-level resource parsers.
   ParseType parseLanguageResource();
+  ParseType parseCursorResource();
   ParseType parseIconResource();
+  ParseType parseHTMLResource();
   ParseType parseStringTableResource();
 
   // Optional statement parsers.
index af62e532225d3e7e7f29ead9337ff8aaf29f985a..f008641ff76b7219498c390ff3387b51253f7a9b 100644 (file)
@@ -36,10 +36,18 @@ raw_ostream &LanguageResource::log(raw_ostream &OS) const {
   return OS << "Language: " << Lang << ", Sublanguage: " << SubLang << "\n";
 }
 
+raw_ostream &CursorResource::log(raw_ostream &OS) const {
+  return OS << "Cursor (" << ResName << "): " << CursorLoc << "\n";
+}
+
 raw_ostream &IconResource::log(raw_ostream &OS) const {
   return OS << "Icon (" << ResName << "): " << IconLoc << "\n";
 }
 
+raw_ostream &HTMLResource::log(raw_ostream &OS) const {
+  return OS << "HTML (" << ResName << "): " << HTMLLoc << "\n";
+}
+
 raw_ostream &StringTableResource::log(raw_ostream &OS) const {
   OS << "StringTable:\n";
   OptStatements.log(OS);
index 3ee0962cfeddf763e5ff516cce84cee77aa21d56..8ff0e5bb19ccd419f1c9898315621ff3ae7b1576 100644 (file)
@@ -90,6 +90,17 @@ public:
   raw_ostream &log(raw_ostream &) const override;
 };
 
+// CURSOR resource. Represents a single cursor (".cur") file.
+//
+// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380920(v=vs.85).aspx
+class CursorResource : public RCResource {
+  StringRef CursorLoc;
+
+public:
+  CursorResource(StringRef Location) : CursorLoc(Location) {}
+  raw_ostream &log(raw_ostream &) const override;
+};
+
 // ICON resource. Represents a single ".ico" file containing a group of icons.
 //
 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381018(v=vs.85).aspx
@@ -101,6 +112,19 @@ public:
   raw_ostream &log(raw_ostream &) const override;
 };
 
+// HTML resource. Represents a local webpage that is to be embedded into the
+// resulting resource file. It embeds a file only - no additional resources
+// (images etc.) are included with this resource.
+//
+// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa966018(v=vs.85).aspx
+class HTMLResource : public RCResource {
+  StringRef HTMLLoc;
+
+public:
+  HTMLResource(StringRef Location) : HTMLLoc(Location) {}
+  raw_ostream &log(raw_ostream &) const override;
+};
+
 // STRINGTABLE resource. Contains a list of strings, each having its unique ID.
 //
 // Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx