[PATCH] Allow string literals as module identifiers

Daniel Jasper djasper at google.com
Thu Oct 31 06:11:21 PDT 2013

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);
+    }
Richard Smith wrote:
> 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`.
Done. However, I have failed to add a test for user-defined and raw string literals as the "@import" statement doesn't seem to work in C++ mode (error: "expected unqualified-id") and ObjC doesn't have those.

Comment at: test/Modules/string_names.m:6
@@ +5,3 @@
+ at import "my/module-a"."Sub";
Richard Smith wrote:
> Maybe also test that `"Sub"` and `Sub` are treated as equivalent?
Done (I think).


More information about the cfe-commits mailing list