[cfe-commits] r145439 - /cfe/trunk/lib/Lex/ModuleMap.cpp
Benjamin Kramer
benny.kra at googlemail.com
Tue Nov 29 23:01:21 PST 2011
On 30.11.2011, at 02:00, Douglas Gregor <dgregor at apple.com> wrote:
>
>
> Sent from my iPhone
>
> On Nov 29, 2011, at 2:57 PM, Chris Lattner <clattner at apple.com> wrote:
>
>> On Nov 29, 2011, at 2:27 PM, Douglas Gregor wrote:
>>> URL: http://llvm.org/viewvc/llvm-project?rev=145439&view=rev
>>> Log:
>>> Escape strings when printing module maps, for silly operating systems
>>> that use \ as a separator.
>>>
>>> +static void printEscapedString(llvm::raw_ostream &OS, StringRef String) {
>>
>> This looks familiar, should it become a method on StringRef or something?
>
> I couldn't decide where up put it <g>. I'll move it into StringRef.
raw_ostream::write_escaped does the same thing.
-Ben
>
>> -Chris
>>
>>> + for (StringRef::iterator I = String.begin(), E = String.end(); I != E; ++I) {
>>> + unsigned char Char = *I;
>>> +
>>> + switch (Char) {
>>> + default:
>>> + if (isprint(Char))
>>> + OS << (char)Char;
>>> + else // Output anything hard as an octal escape.
>>> + OS << '\\'
>>> + << (char)('0'+ ((Char >> 6) & 7))
>>> + << (char)('0'+ ((Char >> 3) & 7))
>>> + << (char)('0'+ ((Char >> 0) & 7));
>>> + break;
>>> + // Handle some common non-printable cases to make dumps prettier.
>>> + case '\\': OS << "\\\\"; break;
>>> + case '"': OS << "\\\""; break;
>>> + case '\n': OS << "\\n"; break;
>>> + case '\t': OS << "\\t"; break;
>>> + case '\a': OS << "\\a"; break;
>>> + case '\b': OS << "\\b"; break;
>>> + }
>>> + }
>>> +}
>>> +
>>> void ModuleMap::Module::print(llvm::raw_ostream &OS, unsigned Indent) const {
>>> indent(OS, Indent);
>>> if (IsFramework)
>>> @@ -82,12 +107,16 @@
>>>
>>> if (UmbrellaHeader) {
>>> indent(OS, Indent + 2);
>>> - OS << "umbrella \"" << UmbrellaHeader->getName() << "\"\n";
>>> + OS << "umbrella \"";
>>> + printEscapedString(OS, UmbrellaHeader->getName());
>>> + OS << "\"\n";
>>> }
>>>
>>> for (unsigned I = 0, N = Headers.size(); I != N; ++I) {
>>> indent(OS, Indent + 2);
>>> - OS << "header \"" << Headers[I]->getName() << "\"\n";
>>> + OS << "header \"";
>>> + printEscapedString(OS, Headers[I]->getName());
>>> + OS << "\"\n";
>>> }
>>>
>>> for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(),
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list