diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Driver/PrintPreprocessedOutput.cpp | 2 | ||||
| -rw-r--r-- | clang/Lex/Lexer.cpp | 9 | ||||
| -rw-r--r-- | clang/Lex/Preprocessor.cpp | 2 | ||||
| -rw-r--r-- | clang/include/clang/Lex/Lexer.h | 7 |
4 files changed, 10 insertions, 10 deletions
diff --git a/clang/Driver/PrintPreprocessedOutput.cpp b/clang/Driver/PrintPreprocessedOutput.cpp index fcdbd20c965..526447b94f4 100644 --- a/clang/Driver/PrintPreprocessedOutput.cpp +++ b/clang/Driver/PrintPreprocessedOutput.cpp @@ -171,7 +171,7 @@ static void HandleFileChange(SourceLocation Loc, } EModeCurLine = SourceMgr.getLineNumber(Loc); - EModeCurFilename = Lexer::Stringify(SourceMgr.getSourceName(Loc)); + EModeCurFilename = '"' + Lexer::Stringify(SourceMgr.getSourceName(Loc)) + '"'; EmodeFileType = FileType; if (EmodeEmittedTokensOnThisLine) { diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index cc45e1224a6..1344cfe7c8d 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -69,17 +69,16 @@ Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp, /// Stringify - Convert the specified string into a C string, with surrounding /// ""'s, and with escaped \ and " characters. -std::string Lexer::Stringify(const std::string &Str) { +std::string Lexer::Stringify(const std::string &Str, bool Charify) { std::string Result = Str; + char Quote = Charify ? '\'' : '"'; for (unsigned i = 0, e = Result.size(); i != e; ++i) { - if (Result[i] == '\\' || Result[i] == '"') { + if (Result[i] == '\\' || Result[i] == Quote) { Result.insert(Result.begin()+i, '\\'); ++i; ++e; } } - - // Add quotes. - return '"' + Result + '"'; + return Result; } diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index ce4a7ffb8cf..8002702638d 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -837,7 +837,7 @@ void Preprocessor::ExpandBuiltinMacro(LexerToken &Tok) { // Escape this filename. Turn '\' -> '\\' '"' -> '\"' std::string FN = SourceMgr.getSourceName(Loc); - FN = Lexer::Stringify(FN); + FN = '"' + Lexer::Stringify(FN) + '"'; Tok.SetKind(tok::string_literal); Tok.SetLength(FN.size()); Tok.SetLocation(CreateString(&FN[0], FN.size(), Tok.getLocation())); diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h index 6de701c02a2..86548d6d4c2 100644 --- a/clang/include/clang/Lex/Lexer.h +++ b/clang/include/clang/Lex/Lexer.h @@ -168,9 +168,10 @@ public: /// offset in the current file. SourceLocation getSourceLocation(const char *Loc) const; - /// Stringify - Convert the specified string into a C string, with surrounding - /// ""'s, and with escaped \ and " characters. - static std::string Stringify(const std::string &Str); + /// Stringify - Convert the specified string into a C string by escaping '\' + /// and " characters. This does not add surrounding ""'s to the string. + /// If Charify is true, this escapes the ' character instead of ". + static std::string Stringify(const std::string &Str, bool Charify = false); //===--------------------------------------------------------------------===// // Internal implementation interfaces. |

