[llvm] r331747 - [llvm-rc] Don't strictly require quotes around external file names
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 01:47:38 PDT 2018
Author: mstorsjo
Date: Tue May 8 01:47:37 2018
New Revision: 331747
URL: http://llvm.org/viewvc/llvm-project?rev=331747&view=rev
Log:
[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
Added:
llvm/trunk/test/tools/llvm-rc/Inputs/include-noquotes.rc
llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp
- copied, changed from r331746, llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp
Removed:
llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp
Modified:
llvm/trunk/test/tools/llvm-rc/Inputs/deep-include.rc
llvm/trunk/test/tools/llvm-rc/include-paths.test
llvm/trunk/test/tools/llvm-rc/parser.test
llvm/trunk/tools/llvm-rc/ResourceScriptParser.cpp
llvm/trunk/tools/llvm-rc/ResourceScriptParser.h
llvm/trunk/tools/llvm-rc/ResourceScriptToken.cpp
Modified: llvm/trunk/test/tools/llvm-rc/Inputs/deep-include.rc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/Inputs/deep-include.rc?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/Inputs/deep-include.rc (original)
+++ llvm/trunk/test/tools/llvm-rc/Inputs/deep-include.rc Tue May 8 01:47:37 2018
@@ -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"
Added: llvm/trunk/test/tools/llvm-rc/Inputs/include-noquotes.rc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/Inputs/include-noquotes.rc?rev=331747&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/Inputs/include-noquotes.rc (added)
+++ llvm/trunk/test/tools/llvm-rc/Inputs/include-noquotes.rc Tue May 8 01:47:37 2018
@@ -0,0 +1,3 @@
+// Test including filenames without quotes.
+// In this form, the path can't include dashes.
+foo BITMAP ./nested/nested_bitmap.bmp
Removed: llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp?rev=331746&view=auto
==============================================================================
Binary file - no diff available.
Copied: llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp (from r331746, llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp?p2=llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested_bitmap.bmp&p1=llvm/trunk/test/tools/llvm-rc/Inputs/nested/nested-bitmap.bmp&r1=331746&r2=331747&rev=331747&view=diff
==============================================================================
Binary files - no diff available.
Modified: llvm/trunk/test/tools/llvm-rc/include-paths.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/include-paths.test?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/include-paths.test (original)
+++ llvm/trunk/test/tools/llvm-rc/include-paths.test Tue May 8 01:47:37 2018
@@ -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 24
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
Modified: llvm/trunk/test/tools/llvm-rc/parser.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/parser.test?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/parser.test (original)
+++ llvm/trunk/test/tools/llvm-rc/parser.test Tue May 8 01:47:37 2018
@@ -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 ,
Modified: llvm/trunk/tools/llvm-rc/ResourceScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/ResourceScriptParser.cpp?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rc/ResourceScriptParser.cpp (original)
+++ llvm/trunk/tools/llvm-rc/ResourceScriptParser.cpp Tue May 8 01:47:37 2018
@@ -214,6 +214,12 @@ Expected<StringRef> RCParser::readString
return read().value();
}
+Expected<StringRef> RCParser::readFilename() {
+ if (!isNextTokenKind(Kind::String) && !isNextTokenKind(Kind::Identifier))
+ return getExpectedError("string");
+ return read().value();
+}
+
Expected<StringRef> RCParser::readIdentifier() {
if (!isNextTokenKind(Kind::Identifier))
return getExpectedError("identifier");
@@ -385,7 +391,7 @@ RCParser::ParseType RCParser::parseAccel
}
RCParser::ParseType RCParser::parseCursorResource() {
- ASSIGN_OR_RETURN(Arg, readString());
+ ASSIGN_OR_RETURN(Arg, readFilename());
return llvm::make_unique<CursorResource>(*Arg);
}
@@ -427,8 +433,13 @@ RCParser::ParseType RCParser::parseUserD
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<UserDefinedResource>(Type, read().value());
+ default:
+ break;
+ }
RETURN_IF_ERROR(consumeType(Kind::BlockBegin));
std::vector<IntOrString> Data;
@@ -487,17 +498,17 @@ Expected<Control> RCParser::parseControl
}
RCParser::ParseType RCParser::parseBitmapResource() {
- ASSIGN_OR_RETURN(Arg, readString());
+ ASSIGN_OR_RETURN(Arg, readFilename());
return llvm::make_unique<BitmapResource>(*Arg);
}
RCParser::ParseType RCParser::parseIconResource() {
- ASSIGN_OR_RETURN(Arg, readString());
+ ASSIGN_OR_RETURN(Arg, readFilename());
return llvm::make_unique<IconResource>(*Arg);
}
RCParser::ParseType RCParser::parseHTMLResource() {
- ASSIGN_OR_RETURN(Arg, readString());
+ ASSIGN_OR_RETURN(Arg, readFilename());
return llvm::make_unique<HTMLResource>(*Arg);
}
Modified: llvm/trunk/tools/llvm-rc/ResourceScriptParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/ResourceScriptParser.h?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rc/ResourceScriptParser.h (original)
+++ llvm/trunk/tools/llvm-rc/ResourceScriptParser.h Tue May 8 01:47:37 2018
@@ -84,6 +84,7 @@ private:
Expected<RCInt> readInt(); // Parse an integer.
Expected<StringRef> readString(); // Parse a string.
Expected<StringRef> readIdentifier(); // Parse an identifier.
+ Expected<StringRef> readFilename(); // Parse a filename.
Expected<IntOrString> readIntOrString(); // Parse an integer or a string.
Expected<IntOrString> readTypeOrName(); // Parse an integer or an identifier.
Modified: llvm/trunk/tools/llvm-rc/ResourceScriptToken.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/ResourceScriptToken.cpp?rev=331747&r1=331746&r2=331747&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rc/ResourceScriptToken.cpp (original)
+++ llvm/trunk/tools/llvm-rc/ResourceScriptToken.cpp Tue May 8 01:47:37 2018
@@ -281,13 +281,14 @@ bool Tokenizer::canStartIdentifier() con
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 {
More information about the llvm-commits
mailing list