capfredf updated this revision to Diff 550489.
capfredf marked 7 inline comments as done.
capfredf added a comment.

address @sammccall 's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154382/new/

https://reviews.llvm.org/D154382

Files:
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Interpreter/InterpreterCodeCompletion.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Interpreter/InterpreterCodeCompletion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Interpreter/CodeCompletionTest.cpp

Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===================================================================
--- clang/unittests/Interpreter/CodeCompletionTest.cpp
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -42,9 +42,9 @@
       Prefix, 1, Prefix.size(), MainInterp.getCompilerInstance(), Results);
 
   std::vector<std::string> Comps;
-  for (auto c : ConvertToCodeCompleteStrings(Results)) {
-    if (c.startswith(Prefix))
-      Comps.push_back(c.substr(Prefix.size()).str());
+  for (auto c : convertToCodeCompleteStrings(Results)) {
+    if (c.find(Prefix) == 0)
+      Comps.push_back(c.substr(Prefix.size()));
   }
 
   return Comps;
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===================================================================
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -543,7 +543,7 @@
     case CodeCompletionContext::CCC_PreprocessorExpression:
     case CodeCompletionContext::CCC_PreprocessorDirective:
     case CodeCompletionContext::CCC_Attribute:
-    case CodeCompletionContext::CCC_ReplTopLevel:
+    case CodeCompletionContext::CCC_TopLevelOrExpression:
     case CodeCompletionContext::CCC_TypeQualifiers: {
       //Only Clang results should be accepted, so we'll set all of the other
       //context bits to 0 (i.e. the empty set)
Index: clang/tools/clang-repl/ClangRepl.cpp
===================================================================
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -129,13 +129,14 @@
     s = Buffer.substr(space_pos + 1);
   }
 
-  for (auto c : ConvertToCodeCompleteStrings(Results)) {
-    if (c.startswith(s))
+  for (auto c : convertToCodeCompleteStrings(Results)) {
+    if (c.find(s) == 0)
       Comps.push_back(
-          llvm::LineEditor::Completion(c.substr(s.size()).str(), c.str()));
+          llvm::LineEditor::Completion(c.substr(s.size()), c));
   }
   return Comps;
 }
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -225,7 +225,7 @@
     case CodeCompletionContext::CCC_ObjCMessageReceiver:
     case CodeCompletionContext::CCC_ParenthesizedExpression:
     case CodeCompletionContext::CCC_Statement:
-    case CodeCompletionContext::CCC_ReplTopLevel:
+    case CodeCompletionContext::CCC_TopLevelOrExpression:
     case CodeCompletionContext::CCC_Recovery:
       if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl())
         if (Method->isInstanceMethod())
@@ -1851,7 +1851,7 @@
   case Sema::PCC_ObjCInstanceVariableList:
   case Sema::PCC_Expression:
   case Sema::PCC_Statement:
-  case Sema::PCC_TopLevelStmtDecl:
+  case Sema::PCC_TopLevelOrExpression:
   case Sema::PCC_ForInit:
   case Sema::PCC_Condition:
   case Sema::PCC_RecoveryInFunction:
@@ -1909,7 +1909,7 @@
   case Sema::PCC_Type:
   case Sema::PCC_ParenthesizedExpression:
   case Sema::PCC_LocalDeclarationSpecifiers:
-  case Sema::PCC_TopLevelStmtDecl:
+  case Sema::PCC_TopLevelOrExpression:
     return true;
 
   case Sema::PCC_Expression:
@@ -2222,7 +2222,7 @@
     break;
 
   case Sema::PCC_RecoveryInFunction:
-  case Sema::PCC_TopLevelStmtDecl:
+  case Sema::PCC_TopLevelOrExpression:
   case Sema::PCC_Statement: {
     if (SemaRef.getLangOpts().CPlusPlus11)
       AddUsingAliasResult(Builder, Results);
@@ -4212,8 +4212,8 @@
 
   case Sema::PCC_LocalDeclarationSpecifiers:
     return CodeCompletionContext::CCC_Type;
-  case Sema::PCC_TopLevelStmtDecl:
-    return CodeCompletionContext::CCC_ReplTopLevel;
+  case Sema::PCC_TopLevelOrExpression:
+    return CodeCompletionContext::CCC_TopLevelOrExpression;
   }
 
   llvm_unreachable("Invalid ParserCompletionContext!");
@@ -4354,7 +4354,7 @@
     break;
 
   case PCC_Statement:
-  case PCC_TopLevelStmtDecl:
+  case PCC_TopLevelOrExpression:
   case PCC_ParenthesizedExpression:
   case PCC_Expression:
   case PCC_ForInit:
@@ -4392,7 +4392,7 @@
   case PCC_ParenthesizedExpression:
   case PCC_Expression:
   case PCC_Statement:
-  case PCC_TopLevelStmtDecl:
+  case PCC_TopLevelOrExpression:
   case PCC_RecoveryInFunction:
     if (S->getFnParent())
       AddPrettyFunctionResults(getLangOpts(), Results);
Index: clang/lib/Sema/CodeCompleteConsumer.cpp
===================================================================
--- clang/lib/Sema/CodeCompleteConsumer.cpp
+++ clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -51,7 +51,7 @@
   case CCC_ParenthesizedExpression:
   case CCC_Symbol:
   case CCC_SymbolOrNewName:
-  case CCC_ReplTopLevel:
+  case CCC_TopLevelOrExpression:
     return true;
 
   case CCC_TopLevel:
@@ -170,7 +170,7 @@
     return "Recovery";
   case CCKind::CCC_ObjCClassForwardDecl:
     return "ObjCClassForwardDecl";
-  case CCKind::CCC_ReplTopLevel:
+  case CCKind::CCC_TopLevelOrExpression:
     return "ReplTopLevel";
   }
   llvm_unreachable("Invalid CodeCompletionContext::Kind!");
Index: clang/lib/Parse/Parser.cpp
===================================================================
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -928,7 +928,7 @@
     if (CurParsedObjCImpl) {
       PCC = Sema::PCC_ObjCImplementation;
     } else if (PP.isIncrementalProcessingEnabled()) {
-      PCC = Sema::PCC_TopLevelStmtDecl;
+      PCC = Sema::PCC_TopLevelOrExpression;
     } else {
       PCC = Sema::PCC_Namespace;
     };
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -6645,18 +6645,6 @@
 
   while (true) {
     if (Tok.is(tok::l_paren)) {
-      if (PP.isIncrementalProcessingEnabled() &&
-          NextToken().is(tok::code_completion)) {
-        // In clang-repl, code completion for input like `void foo(<tab>` should
-        // not trigger a parsing error. So we make the declarator malformed and
-        // exits the loop.
-        ConsumeParen();
-        cutOffParsing();
-        D.SetIdentifier(nullptr, Tok.getLocation());
-        D.setInvalidType(true);
-        break;
-      }
-
       bool IsFunctionDeclaration = D.isFunctionDeclaratorAFunctionDeclaration();
       // Enter function-declaration scope, limiting any declarators to the
       // function prototype scope, including parameter declarators.
Index: clang/lib/Interpreter/InterpreterCodeCompletion.cpp
===================================================================
--- clang/lib/Interpreter/InterpreterCodeCompletion.cpp
+++ clang/lib/Interpreter/InterpreterCodeCompletion.cpp
@@ -69,23 +69,23 @@
         Results.push_back(Result);
       }
       break;
-    default:
-      break;
     case CodeCompletionResult::RK_Keyword:
       Results.push_back(Result);
       break;
+    default:
+      break;
     }
   }
 };
 
-std::vector<llvm::StringRef> ConvertToCodeCompleteStrings(
+std::vector<std::string> convertToCodeCompleteStrings(
     const std::vector<clang::CodeCompletionResult> &Results) {
-  std::vector<llvm::StringRef> CompletionStrings;
+  std::vector<std::string> CompletionStrings;
   for (auto Res : Results) {
     switch (Res.Kind) {
     case clang::CodeCompletionResult::RK_Declaration:
       if (auto *ID = Res.Declaration->getIdentifier()) {
-        CompletionStrings.push_back(ID->getName());
+        CompletionStrings.push_back(ID->getName().str());
       }
       break;
     case clang::CodeCompletionResult::RK_Keyword:
Index: clang/lib/Frontend/ASTUnit.cpp
===================================================================
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -2007,7 +2007,7 @@
   case CodeCompletionContext::CCC_SymbolOrNewName:
   case CodeCompletionContext::CCC_ParenthesizedExpression:
   case CodeCompletionContext::CCC_ObjCInterfaceName:
-  case CodeCompletionContext::CCC_ReplTopLevel:
+  case CodeCompletionContext::CCC_TopLevelOrExpression:
       break;
 
   case CodeCompletionContext::CCC_EnumTag:
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13452,7 +13452,7 @@
     /// specifiers within a function, method, or block.
     PCC_LocalDeclarationSpecifiers,
     /// Code completion occurs at top-level in a REPL session
-    PCC_TopLevelStmtDecl,
+    PCC_TopLevelOrExpression,
   };
 
   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
Index: clang/include/clang/Sema/CodeCompleteConsumer.h
===================================================================
--- clang/include/clang/Sema/CodeCompleteConsumer.h
+++ clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -339,7 +339,7 @@
     CCC_ObjCClassForwardDecl,
 
     /// Code completion at a top level in a REPL session.
-    CCC_ReplTopLevel,
+    CCC_TopLevelOrExpression,
   };
 
   using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>;
Index: clang/include/clang/Interpreter/InterpreterCodeCompletion.h
===================================================================
--- clang/include/clang/Interpreter/InterpreterCodeCompletion.h
+++ clang/include/clang/Interpreter/InterpreterCodeCompletion.h
@@ -12,6 +12,7 @@
 
 #ifndef LLVM_CLANG_INTERPRETER_CODE_COMPLETION_H
 #define LLVM_CLANG_INTERPRETER_CODE_COMPLETION_H
+#include <string>
 #include <vector>
 
 namespace llvm {
@@ -26,7 +27,7 @@
                   unsigned Line, unsigned Col, const CompilerInstance *ParentCI,
                   std::vector<CodeCompletionResult> &CCResults);
 
-std::vector<llvm::StringRef>
-ConvertToCodeCompleteStrings(const std::vector<CodeCompletionResult> &Results);
+std::vector<std::string>
+convertToCodeCompleteStrings(const std::vector<CodeCompletionResult> &Results);
 } // namespace clang
 #endif
Index: clang/include/clang/Frontend/ASTUnit.h
===================================================================
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -888,7 +888,9 @@
   /// \param IncludeBriefComments Whether to include brief documentation within
   /// the set of code completions returned.
   ///
-  /// \param Act A SyntaxOnlyAction performs actions on the syntax.
+  /// \param Act If supplied, this argument is used to parse the input file,
+  /// allowing customized parsing by overriding SyntaxOnlyAction lifecycle
+  /// methods.
   ///
   /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
   /// OwnedBuffers parameters are all disgusting hacks. They will go away.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to