From a6141f078074409a8bd24b4808cbfce40ed27cea Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Sat, 31 May 2008 03:35:42 +0000 Subject: [PATCH] Hack RewriteObjC::RewriteObjCStringLiteral() to include the filename in the generated code (replacing any non-alphanumeric characters with "_"). This allows header files to contain ObjCStringLiterals. llvm-svn: 51811 --- clang/Driver/RewriteObjC.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clang/Driver/RewriteObjC.cpp b/clang/Driver/RewriteObjC.cpp index 6d49c7eef06c..d1c6b9710a68 100644 --- a/clang/Driver/RewriteObjC.cpp +++ b/clang/Driver/RewriteObjC.cpp @@ -1801,6 +1801,17 @@ Stmt *RewriteObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { QualType strType = getConstantStringStructType(); std::string S = "__NSConstantStringImpl_"; + + std::string tmpName = InFileName; + unsigned i; + for (i=0; i < tmpName.length(); i++) { + char c = tmpName.at(i); + // replace any non alphanumeric characters with '_'. + if (!isalpha(c) && (c < '0' || c > '9')) + tmpName[i] = '_'; + } + S += tmpName; + S += "_"; S += utostr(NumObjCStringLiterals++); Preamble += "static __NSConstantStringImpl " + S;