aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-18 22:27:02 +0000
committerChris Lattner <sabre@nondot.org>2009-04-18 22:27:02 +0000
commit033749571f8d4c804eeb357c70b06424aa24503b (patch)
tree3f1355bb33e3617817ce858fc89b0c63aedbac5a
parent24f0e48c0aa62f2268e061aad70f9b19a59e7b52 (diff)
add a new Lexer::SkipEscapedNewLines method.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69483 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/Lexer.h4
-rw-r--r--lib/Lex/Lexer.cpp23
2 files changed, 27 insertions, 0 deletions
diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h
index 8d0576e4f9..3a73147152 100644
--- a/include/clang/Lex/Lexer.h
+++ b/include/clang/Lex/Lexer.h
@@ -342,6 +342,10 @@ public:
/// to this function.
static unsigned getEscapedNewLineSize(const char *P);
+ /// SkipEscapedNewLines - If P points to an escaped newline (or a series of
+ /// them), skip over them and return the first non-escaped-newline found,
+ /// otherwise return P.
+ static const char *SkipEscapedNewLines(const char *P);
private:
/// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index b9aa0178c6..4d6450b914 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -422,6 +422,29 @@ unsigned Lexer::getEscapedNewLineSize(const char *Ptr) {
return 0;
}
+/// SkipEscapedNewLines - If P points to an escaped newline (or a series of
+/// them), skip over them and return the first non-escaped-newline found,
+/// otherwise return P.
+const char *Lexer::SkipEscapedNewLines(const char *P) {
+ while (1) {
+ const char *AfterEscape;
+ if (*P == '\\') {
+ AfterEscape = P+1;
+ } else if (*P == '?') {
+ // If not a trigraph for escape, bail out.
+ if (P[1] != '?' || P[2] != '/')
+ return P;
+ AfterEscape = P+3;
+ } else {
+ return P;
+ }
+
+ unsigned NewLineSize = Lexer::getEscapedNewLineSize(AfterEscape);
+ if (NewLineSize == 0) return P;
+ P = AfterEscape+NewLineSize;
+ }
+}
+
/// getCharAndSizeSlow - Peek a single 'character' from the specified buffer,
/// get its size, and return it. This is tricky in several cases: