@@ -594,14 +594,21 @@ static bool isLeftBound(const char *tokBegin, const char *bufferBegin) {
594594
595595// / Is the operator ending at the given character (actually one past the end)
596596// / "right-bound"?
597- static bool isRightBound (const char *tokEnd, bool isLeftBound) {
597+ // /
598+ // / The code-completion point is considered right-bound.
599+ static bool isRightBound (const char *tokEnd, bool isLeftBound,
600+ const char *codeCompletionPtr) {
598601 switch (*tokEnd) {
599602 case ' ' : case ' \r ' : case ' \n ' : case ' \t ' : // whitespace
600603 case ' )' : case ' ]' : case ' }' : // closing delimiters
601604 case ' ,' : case ' ;' : case ' :' : // expression separators
602- case ' \0 ' : // whitespace / last char in file
603605 return false ;
604606
607+ case ' \0 ' :
608+ if (tokEnd == codeCompletionPtr) // code-completion
609+ return true ;
610+ return false ; // whitespace / last char in file
611+
605612 case ' .' :
606613 // Prefer the '^' in "x^.y" to be a postfix op, not binary, but the '^' in
607614 // "^.y" to be a prefix op, not binary.
@@ -637,7 +644,7 @@ void Lexer::lexOperatorIdentifier() {
637644 // It's binary if either both sides are bound or both sides are not bound.
638645 // Otherwise, it's postfix if left-bound and prefix if right-bound.
639646 bool leftBound = isLeftBound (TokStart, BufferStart);
640- bool rightBound = isRightBound (CurPtr, leftBound);
647+ bool rightBound = isRightBound (CurPtr, leftBound, CodeCompletionPtr );
641648
642649 // Match various reserved words.
643650 if (CurPtr-TokStart == 1 ) {
@@ -669,17 +676,16 @@ void Lexer::lexOperatorIdentifier() {
669676 const char *AfterHorzWhitespace = CurPtr;
670677 while (*AfterHorzWhitespace == ' ' || *AfterHorzWhitespace == ' \t ' )
671678 ++AfterHorzWhitespace;
672-
673- // First, when we are code completing "x.<ESC>", then make sure to return
679+
680+ // First, when we are code completing "x. <ESC>", then make sure to return
674681 // a tok::period, since that is what the user is wanting to know about.
675- // FIXME: isRightBound should consider this to be right bound.
676682 if (*AfterHorzWhitespace == ' \0 ' &&
677683 AfterHorzWhitespace == CodeCompletionPtr) {
678684 diagnose (TokStart, diag::expected_member_name);
679685 return formToken (tok::period, TokStart);
680686 }
681-
682- if (isRightBound (AfterHorzWhitespace, leftBound) &&
687+
688+ if (isRightBound (AfterHorzWhitespace, leftBound, CodeCompletionPtr ) &&
683689 // Don't consider comments to be this. A leading slash is probably
684690 // either // or /* and most likely occurs just in our testsuite for
685691 // expected-error lines.
0 commit comments