summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-15 05:14:19 +0000
committerChris Lattner <sabre@nondot.org>2008-01-15 05:14:19 +0000
commit877ca774207c0ab1275afc063cb5c94fff8f53b8 (patch)
treed956bc17740c3e33c41bc1aa4734bd26af88b712 /clang
parent352ab9b4a2a6ac23865f37ee129bfdcbab3aed07 (diff)
downloadbcm5719-llvm-877ca774207c0ab1275afc063cb5c94fff8f53b8.tar.gz
bcm5719-llvm-877ca774207c0ab1275afc063cb5c94fff8f53b8.zip
avoid token pasting between identifiers and wide strings:
abc+L"foo" -> abc L"foo", not abcL"foo" llvm-svn: 45999
Diffstat (limited to 'clang')
-rw-r--r--clang/Driver/PrintPreprocessedOutput.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/clang/Driver/PrintPreprocessedOutput.cpp b/clang/Driver/PrintPreprocessedOutput.cpp
index 7e179fecc22..efa2c006525 100644
--- a/clang/Driver/PrintPreprocessedOutput.cpp
+++ b/clang/Driver/PrintPreprocessedOutput.cpp
@@ -420,6 +420,23 @@ static void InitAvoidConcatTokenInfo() {
TokenInfo[tok::equal ] |= aci_avoid_equal; // ==
}
+static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
+ char Buffer[256];
+ if (!Tok.needsCleaning()) {
+ SourceManager &SrcMgr = PP.getSourceManager();
+ return *SrcMgr.getCharacterData(SrcMgr.getPhysicalLoc(Tok.getLocation()))
+ == 'L';
+ }
+
+ if (Tok.getLength() < 256) {
+ const char *TokPtr = Buffer;
+ PP.getSpelling(Tok, TokPtr);
+ return TokPtr[0] == 'L';
+ }
+
+ return PP.getSpelling(Tok)[0] == 'L';
+}
+
/// AvoidConcat - If printing PrevTok immediately followed by Tok would cause
/// the two individual tokens to be lexed as a single token, return true (which
/// causes a space to be printed between them). This allows the output of -E
@@ -484,21 +501,19 @@ bool PrintPPOutputPPCallbacks::AvoidConcat(const Token &PrevTok,
Tok.is(tok::wide_string_literal) /* ||
Tok.is(tok::wide_char_literal)*/)
return true;
- if (Tok.isNot(tok::char_constant))
+
+ // If this isn't identifier + string, we're done.
+ if (Tok.isNot(tok::char_constant) && Tok.isNot(tok::string_literal))
return false;
// FIXME: need a wide_char_constant!
- if (!Tok.needsCleaning()) {
- SourceManager &SrcMgr = PP.getSourceManager();
- return *SrcMgr.getCharacterData(SrcMgr.getPhysicalLoc(Tok.getLocation()))
- == 'L';
- } else if (Tok.getLength() < 256) {
- const char *TokPtr = Buffer;
- PP.getSpelling(Tok, TokPtr);
- return TokPtr[0] == 'L';
- } else {
- return PP.getSpelling(Tok)[0] == 'L';
- }
+
+ // If the string was a wide string L"foo" or wide char L'f', it would concat
+ // with the previous identifier into fooL"bar". Avoid this.
+ if (StartsWithL(Tok, PP))
+ return true;
+
+ return false;
case tok::numeric_constant:
return isalnum(FirstChar) || Tok.is(tok::numeric_constant) ||
FirstChar == '+' || FirstChar == '-' || FirstChar == '.';
OpenPOWER on IntegriCloud