From 75f6bb88efd5de8663dd38b12d08bf89c1ec39c4 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Tue, 8 May 2018 08:47:37 +0000 Subject: [PATCH] [llvm-rc] Don't strictly require quotes around external file names Regardless of what docs may say, existing resource files in the wild can use this syntax. Rename a file used in an existing test, to make it usable for unquoted paths. Differential Revision: https://reviews.llvm.org/D46511 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331747 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-rc/Inputs/deep-include.rc | 2 +- test/tools/llvm-rc/Inputs/include-noquotes.rc | 3 +++ .../{nested-bitmap.bmp => nested_bitmap.bmp} | Bin test/tools/llvm-rc/include-paths.test | 7 ++++++- test/tools/llvm-rc/parser.test | 5 ----- tools/llvm-rc/ResourceScriptParser.cpp | 21 ++++++++++++++++----- tools/llvm-rc/ResourceScriptParser.h | 1 + tools/llvm-rc/ResourceScriptToken.cpp | 5 +++-- 8 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 test/tools/llvm-rc/Inputs/include-noquotes.rc rename test/tools/llvm-rc/Inputs/nested/{nested-bitmap.bmp => nested_bitmap.bmp} (100%) diff --git a/test/tools/llvm-rc/Inputs/deep-include.rc b/test/tools/llvm-rc/Inputs/deep-include.rc index b28fa8f243a..5097a90f960 100644 --- a/test/tools/llvm-rc/Inputs/deep-include.rc +++ b/test/tools/llvm-rc/Inputs/deep-include.rc @@ -1,3 +1,3 @@ // Whether this is found depends on whether the /I flag searches within the // "nested" subdirectory -foo BITMAP "nested-bitmap.bmp" \ No newline at end of file +foo BITMAP "nested_bitmap.bmp" diff --git a/test/tools/llvm-rc/Inputs/include-noquotes.rc b/test/tools/llvm-rc/Inputs/include-noquotes.rc new file mode 100644 index 00000000000..11c971f32b3 --- /dev/null +++ b/test/tools/llvm-rc/Inputs/include-noquotes.rc @@ -0,0 +1,3 @@ +// Test including filenames without quotes. +// In this form, the path can't include dashes. +foo BITMAP ./nested/nested_bitmap.bmp diff --git a/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp b/test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp similarity index 100% rename from test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp rename to test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp diff --git a/test/tools/llvm-rc/include-paths.test b/test/tools/llvm-rc/include-paths.test index f24cc449504..e6c52b12d6d 100644 --- a/test/tools/llvm-rc/include-paths.test +++ b/test/tools/llvm-rc/include-paths.test @@ -3,6 +3,11 @@ ; RUN: llvm-rc /FO %t.include.res %p/Inputs/include.rc ; RUN: llvm-readobj %t.include.res | FileCheck --check-prefix=FOUND %s +; Try including files without quotes. +; RUN: rm -f %t.noquotes.res +; RUN: llvm-rc /FO %t.noquotes.res %p/Inputs/include-noquotes.rc +; RUN: llvm-readobj %t.noquotes.res | FileCheck --check-prefix=FOUND %s + ; Should find the bitmap if the folder is explicitly specified. ; RUN: rm -f %t.nested-include.res ; RUN: llvm-rc /FO %t.nested-include.res /I %p/Inputs/nested %p/Inputs/deep-include.rc @@ -41,4 +46,4 @@ FOUND-NEXT: 0050: FFFFFF0E C9FF0000 241CEDFF FFFF0000 |........$.......| FOUND-NEXT: ) MISSING: llvm-rc: Error in BITMAP statement (ID foo): -MISSING-NEXT: error : file not found : nested-bitmap.bmp +MISSING-NEXT: error : file not found : nested_bitmap.bmp diff --git a/test/tools/llvm-rc/parser.test b/test/tools/llvm-rc/parser.test index 112e4859a9b..66ed7386e82 100644 --- a/test/tools/llvm-rc/parser.test +++ b/test/tools/llvm-rc/parser.test @@ -145,11 +145,6 @@ ; PLANGUAGE2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got , -; RUN: not llvm-rc /dry-run /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 /dry-run /V %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2 ; PHTML2: llvm-rc: Error parsing file: expected string, got , diff --git a/tools/llvm-rc/ResourceScriptParser.cpp b/tools/llvm-rc/ResourceScriptParser.cpp index ffa18bdf198..7123df9029a 100644 --- a/tools/llvm-rc/ResourceScriptParser.cpp +++ b/tools/llvm-rc/ResourceScriptParser.cpp @@ -214,6 +214,12 @@ Expected RCParser::readString() { return read().value(); } +Expected RCParser::readFilename() { + if (!isNextTokenKind(Kind::String) && !isNextTokenKind(Kind::Identifier)) + return getExpectedError("string"); + return read().value(); +} + Expected RCParser::readIdentifier() { if (!isNextTokenKind(Kind::Identifier)) return getExpectedError("identifier"); @@ -385,7 +391,7 @@ RCParser::ParseType RCParser::parseAcceleratorsResource() { } RCParser::ParseType RCParser::parseCursorResource() { - ASSIGN_OR_RETURN(Arg, readString()); + ASSIGN_OR_RETURN(Arg, readFilename()); return llvm::make_unique(*Arg); } @@ -427,8 +433,13 @@ RCParser::ParseType RCParser::parseUserDefinedResource(IntOrString Type) { return getExpectedError("filename, '{' or BEGIN"); // Check if this is a file resource. - if (look().kind() == Kind::String) + switch (look().kind()) { + case Kind::String: + case Kind::Identifier: return llvm::make_unique(Type, read().value()); + default: + break; + } RETURN_IF_ERROR(consumeType(Kind::BlockBegin)); std::vector Data; @@ -487,17 +498,17 @@ Expected RCParser::parseControl() { } RCParser::ParseType RCParser::parseBitmapResource() { - ASSIGN_OR_RETURN(Arg, readString()); + ASSIGN_OR_RETURN(Arg, readFilename()); return llvm::make_unique(*Arg); } RCParser::ParseType RCParser::parseIconResource() { - ASSIGN_OR_RETURN(Arg, readString()); + ASSIGN_OR_RETURN(Arg, readFilename()); return llvm::make_unique(*Arg); } RCParser::ParseType RCParser::parseHTMLResource() { - ASSIGN_OR_RETURN(Arg, readString()); + ASSIGN_OR_RETURN(Arg, readFilename()); return llvm::make_unique(*Arg); } diff --git a/tools/llvm-rc/ResourceScriptParser.h b/tools/llvm-rc/ResourceScriptParser.h index e22619a5834..639ef63863c 100644 --- a/tools/llvm-rc/ResourceScriptParser.h +++ b/tools/llvm-rc/ResourceScriptParser.h @@ -84,6 +84,7 @@ private: Expected readInt(); // Parse an integer. Expected readString(); // Parse a string. Expected readIdentifier(); // Parse an identifier. + Expected readFilename(); // Parse a filename. Expected readIntOrString(); // Parse an integer or a string. Expected readTypeOrName(); // Parse an integer or an identifier. diff --git a/tools/llvm-rc/ResourceScriptToken.cpp b/tools/llvm-rc/ResourceScriptToken.cpp index 7bbf0d16f04..fc0a0e91845 100644 --- a/tools/llvm-rc/ResourceScriptToken.cpp +++ b/tools/llvm-rc/ResourceScriptToken.cpp @@ -281,13 +281,14 @@ bool Tokenizer::canStartIdentifier() const { assert(!streamEof()); const char CurChar = Data[Pos]; - return std::isalpha(CurChar) || CurChar == '_'; + return std::isalpha(CurChar) || CurChar == '_' || CurChar == '.'; } bool Tokenizer::canContinueIdentifier() const { assert(!streamEof()); const char CurChar = Data[Pos]; - return std::isalnum(CurChar) || CurChar == '_'; + return std::isalnum(CurChar) || CurChar == '_' || CurChar == '.' || + CurChar == '/' || CurChar == '\\'; } bool Tokenizer::canStartInt() const { -- 2.11.4.GIT