[PATCH] Allow string literals as module identifiers
Richard Smith
richard at metafoo.co.uk
Wed Oct 30 16:58:32 PDT 2013
================
Comment at: docs/Modules.rst:267
@@ -266,3 +266,3 @@
*module-id*:
*identifier* ('.' *identifier*)*
----------------
Update this to say `*module-name*` not `*identifier*`.
================
Comment at: lib/Lex/Preprocessor.cpp:750-757
@@ -751,1 +749,10 @@
+ (Result.is(tok::identifier) || Result.is(tok::string_literal))) {
+ if (Result.is(tok::string_literal)) {
+ // String literals are valid module identifiers. Set token kind and
+ // identifier information appropriately.
+ StringRef WithoutQuotes(Result.getLiteralData(), Result.getLength());
+ WithoutQuotes = WithoutQuotes.substr(1, WithoutQuotes.size() - 2);
+ Result.setIdentifierInfo(&Identifiers.get(WithoutQuotes));
+ Result.setKind(tok::identifier);
+ }
ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
----------------
Daniel Jasper wrote:
> Richard Smith wrote:
> > You should check for, and reject, a ud-suffix here. Should we allow implicit string literal concatenation here?
> Same as above.
You need to check for ud-suffixes here at least. Also I don't believe that this will do the right thing for a raw string literal. Since parsing of `@import` notionally acts after phase 6 of translation, it really ought to perform string literal concatenation too.
The right way to handle this is to collect the sequence of `tok::string_literal` tokens here and pass them to a `StringLiteralParser`.
================
Comment at: test/Modules/string_names.m:6
@@ +5,3 @@
+
+ at import "my/module-a"."Sub";
+
----------------
Maybe also test that `"Sub"` and `Sub` are treated as equivalent?
http://llvm-reviews.chandlerc.com/D2024
More information about the cfe-commits
mailing list