r174767 - Simplify logic for avoiding concatenation after numeric constants.
Jordan Rose
jordan_rose at apple.com
Fri Feb 8 14:30:31 PST 2013
Author: jrose
Date: Fri Feb 8 16:30:31 2013
New Revision: 174767
URL: http://llvm.org/viewvc/llvm-project?rev=174767&view=rev
Log:
Simplify logic for avoiding concatenation after numeric constants.
I threw in a couple of test cases for UD-suffixes -- already working, but
it wasn't immediately obvious to me.
Added:
cfe/trunk/test/Preprocessor/output_paste_avoid.cpp
- copied, changed from r174766, cfe/trunk/test/Preprocessor/output_paste_avoid.c
Removed:
cfe/trunk/test/Preprocessor/output_paste_avoid.c
Modified:
cfe/trunk/lib/Lex/TokenConcatenation.cpp
Modified: cfe/trunk/lib/Lex/TokenConcatenation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenConcatenation.cpp?rev=174767&r1=174766&r2=174767&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenConcatenation.cpp (original)
+++ cfe/trunk/lib/Lex/TokenConcatenation.cpp Fri Feb 8 16:30:31 2013
@@ -12,9 +12,9 @@
//===----------------------------------------------------------------------===//
#include "clang/Lex/TokenConcatenation.h"
+#include "clang/Basic/CharInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/ErrorHandling.h"
-#include <cctype>
using namespace clang;
@@ -240,13 +240,12 @@ bool TokenConcatenation::AvoidConcat(con
return IsIdentifierStringPrefix(PrevTok);
case tok::numeric_constant:
- return isalnum(FirstChar) || Tok.is(tok::numeric_constant) ||
- FirstChar == '+' || FirstChar == '-' || FirstChar == '.' ||
- (PP.getLangOpts().CPlusPlus11 && FirstChar == '_');
+ return isPreprocessingNumberBody(FirstChar) ||
+ FirstChar == '+' || FirstChar == '-';
case tok::period: // ..., .*, .1234
return (FirstChar == '.' && PrevPrevTok.is(tok::period)) ||
- isdigit(FirstChar) ||
- (PP.getLangOpts().CPlusPlus && FirstChar == '*');
+ isDigit(FirstChar) ||
+ (PP.getLangOpts().CPlusPlus && FirstChar == '*');
case tok::amp: // &&
return FirstChar == '&';
case tok::plus: // ++
Removed: cfe/trunk/test/Preprocessor/output_paste_avoid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/output_paste_avoid.c?rev=174766&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/output_paste_avoid.c (original)
+++ cfe/trunk/test/Preprocessor/output_paste_avoid.c (removed)
@@ -1,39 +0,0 @@
-// RUN: %clang_cc1 -E %s -o - | FileCheck -strict-whitespace %s
-
-
-#define y(a) ..a
-A: y(.)
-// This should print as ".. ." to avoid turning into ...
-// CHECK: A: .. .
-
-#define X 0 .. 1
-B: X
-// CHECK: B: 0 .. 1
-
-#define DOT .
-C: ..DOT
-// CHECK: C: .. .
-
-
-#define PLUS +
-#define EMPTY
-#define f(x) =x=
-D: +PLUS -EMPTY- PLUS+ f(=)
-// CHECK: D: + + - - + + = = =
-
-
-#define test(x) L#x
-E: test(str)
-// Should expand to L "str" not L"str"
-// CHECK: E: L "str"
-
-// Should avoid producing >>=.
-#define equal =
-F: >>equal
-// CHECK: F: >> =
-
-// Make sure we don't introduce spaces in the guid because we try to avoid
-// pasting '-' to a numeric constant.
-#define TYPEDEF(guid) typedef [uuid(guid)]
-TYPEDEF(66504301-BE0F-101A-8BBB-00AA00300CAB) long OLE_COLOR;
-// CHECK: typedef [uuid(66504301-BE0F-101A-8BBB-00AA00300CAB)] long OLE_COLOR;
Copied: cfe/trunk/test/Preprocessor/output_paste_avoid.cpp (from r174766, cfe/trunk/test/Preprocessor/output_paste_avoid.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/output_paste_avoid.cpp?p2=cfe/trunk/test/Preprocessor/output_paste_avoid.cpp&p1=cfe/trunk/test/Preprocessor/output_paste_avoid.c&r1=174766&r2=174767&rev=174767&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/output_paste_avoid.c (original)
+++ cfe/trunk/test/Preprocessor/output_paste_avoid.cpp Fri Feb 8 16:30:31 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -E %s -o - | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -E -std=c++11 %s -o - | FileCheck -strict-whitespace %s
#define y(a) ..a
@@ -37,3 +37,11 @@ F: >>equal
#define TYPEDEF(guid) typedef [uuid(guid)]
TYPEDEF(66504301-BE0F-101A-8BBB-00AA00300CAB) long OLE_COLOR;
// CHECK: typedef [uuid(66504301-BE0F-101A-8BBB-00AA00300CAB)] long OLE_COLOR;
+
+// Be careful with UD-suffixes.
+#define StrSuffix() "abc"_suffix
+#define IntSuffix() 123_suffix
+UD: StrSuffix()ident
+UD: IntSuffix()ident
+// CHECK: UD: "abc"_suffix ident
+// CHECK: UD: 123_suffix ident
More information about the cfe-commits
mailing list