[cfe-commits] r38708 - in /cfe/cfe/trunk: Driver/PrintPreprocessedOutput.cpp Lex/Lexer.cpp Lex/Preprocessor.cpp include/clang/Lex/Lexer.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:59 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:59 2007
New Revision: 38708
URL: http://llvm.org/viewvc/llvm-project?rev=38708&view=rev
Log:
Change Lexer::Stringify to not add ""'s around the string.
Modified:
cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp
cfe/cfe/trunk/Lex/Lexer.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/Lexer.h
Modified: cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=38708&r1=38707&r2=38708&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp Wed Jul 11 11:23:59 2007
@@ -171,7 +171,7 @@
}
EModeCurLine = SourceMgr.getLineNumber(Loc);
- EModeCurFilename = Lexer::Stringify(SourceMgr.getSourceName(Loc));
+ EModeCurFilename = '"' + Lexer::Stringify(SourceMgr.getSourceName(Loc)) + '"';
EmodeFileType = FileType;
if (EmodeEmittedTokensOnThisLine) {
Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38708&r1=38707&r2=38708&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:59 2007
@@ -69,17 +69,16 @@
/// 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;
}
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38708&r1=38707&r2=38708&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:59 2007
@@ -837,7 +837,7 @@
// 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()));
Modified: cfe/cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Lexer.h?rev=38708&r1=38707&r2=38708&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:23:59 2007
@@ -168,9 +168,10 @@
/// 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.
More information about the cfe-commits
mailing list