[cfe-commits] r38624 - in /cfe/cfe/trunk: 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:18 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:18 2007
New Revision: 38624
URL: http://llvm.org/viewvc/llvm-project?rev=38624&view=rev
Log:
Refactor some code into a new Lexer::Stringify method.
Modified:
cfe/cfe/trunk/Lex/Lexer.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/Lexer.h
Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38624&r1=38623&r2=38624&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:18 2007
@@ -59,9 +59,21 @@
ParsingFilename = false;
}
-//===----------------------------------------------------------------------===//
-// LexerToken implementation.
-//===----------------------------------------------------------------------===//
+/// 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 Result = Str;
+ for (unsigned i = 0, e = Result.size(); i != e; ++i) {
+ if (Result[i] == '\\' || Result[i] == '"') {
+ Result.insert(Result.begin()+i, '\\');
+ ++i; ++e;
+ }
+ }
+
+ // Add quotes.
+ return '"' + Result + '"';
+}
+
//===----------------------------------------------------------------------===//
// Character information.
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38624&r1=38623&r2=38624&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:18 2007
@@ -624,14 +624,7 @@
// Escape this filename. Turn '\' -> '\\' '"' -> '\"'
std::string FN = SourceMgr.getSourceName(Loc);
- for (unsigned i = 0, e = FN.size(); i != e; ++i)
- if (FN[i] == '\\' || FN[i] == '"') {
- FN.insert(FN.begin()+i, '\\');
- ++i; ++e;
- }
-
- // Add quotes.
- FN = '"' + FN + '"';
+ FN = Lexer::Stringify(FN);
Tok.SetKind(tok::string_literal);
Tok.SetLength(FN.size());
Tok.SetLocation(ScratchBuf->getToken(&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=38624&r1=38623&r2=38624&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:23:18 2007
@@ -121,6 +121,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);
+
//===--------------------------------------------------------------------===//
// Internal implementation interfaces.
private:
More information about the cfe-commits
mailing list