Add continuation support for comma and backslash characters.

This commit is contained in:
Frederich Munch 2017-03-10 16:37:02 -05:00 committed by sftnight
parent 499b522de5
commit df4aea2fb0
3 changed files with 80 additions and 4 deletions

View File

@ -74,6 +74,7 @@ namespace cling {
const char* curPos = line.data();
bool multilineComment = inBlockComment();
int commentTok = multilineComment ? tok::asterik : tok::slash;
int lastKind;
if (!multilineComment && m_ParenStack.empty()) {
// Only check for 'template' if we're not already indented
@ -88,6 +89,8 @@ namespace cling {
}
do {
lastKind = int(Tok.getKind());
const char* prevStart = curPos;
MetaLexer::LexPunctuatorAndAdvance(curPos, Tok);
const int kind = (int)Tok.getKind();
@ -197,7 +200,8 @@ namespace cling {
}
} while (Tok.isNot(tok::eof));
if (!m_ParenStack.empty() && Res != kMismatch)
const bool Continue = lastKind == tok::backslash || lastKind == tok::comma;
if (Continue || (!m_ParenStack.empty() && Res != kMismatch))
Res = kIncomplete;
if (!m_Input.empty()) {

View File

@ -139,9 +139,6 @@ namespace cling {
Tok.startToken(curPos);
bool nextWasPunct = true;
while (true) {
if(*curPos == '\\')
curPos += 2;
// On comment skip until the eof token.
if (curPos[0] == '/' && curPos[1] == '/') {
while (*curPos != '\0' && *curPos != '\r' && *curPos != '\n')

View File

@ -0,0 +1,75 @@
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
// RUN: cat %s | %cling -Xclang -verify 2>&1 | FileCheck %s
// Tests continuation of a line with , or \
// Be careful saving this file: some editors strip the trailing spaces at bottom
extern "C" int printf(const char*, ...);
int Ac = 15,
Bc = 25,
Cc = 35;
Ac
// CHECK: (int) 15
Bc
// CHECK-NEXT: (int) 25
Cc
// CHECK-NEXT: (int) 35
static void InvokeTest(int A,
int B) { printf("Invoke: %d, %d\n", A, B); }
InvokeTest(Ac,
Bc);
// CHECK-NEXT: Invoke: 15, 25
int A = 10, \
B = 20, \
C = 30;
A
// CHECK-NEXT: (int) 10
B
// CHECK-NEXT: (int) 20
C
// CHECK-NEXT: (int) 30
#define CLING_MULTILINE_STRING "A" \
"B" \
" C D"
CLING_MULTILINE_STRING
// CHECK-NEXT: (const char [7]) "AB C D"
"Multinline" \
" String " \
"Constant"
"Separate"
// CHECK-NEXT: (const char [27]) "Multinline String Constant"
// CHECK-NEXT: (const char [9]) "Separate"
// Common error handling macro
#define CLING_MULTILINE_MACRO(STR) do { \
printf(STR "\n"); } while(0)
CLING_MULTILINE_MACRO("DOWHILE");
// CHECK-NEXT: DOWHILE
#define CLING_MULTILINE_TRAILING_SPACE \
"Trailing Space " \
"And A Tab" \
" End" // expected-warning@1 {{backslash and newline separated by space}} // expected-warning@2 {{backslash and newline separated by space}}
// Separation by a tab is allowed? Is that a bug in clang?
CLING_MULTILINE_TRAILING_SPACE
// CHECK-NEXT: (const char [29]) "Trailing Space And A Tab End"
.q