capfredf updated this revision to Diff 539572.
capfredf marked 2 inline comments as done.
capfredf edited the summary of this revision.
capfredf added a comment.
Herald added a subscriber: arphaman.

- rename
- Do not export ReplCompletionConsumer
- remove commented code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154382

Files:
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp

Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===================================================================
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -543,6 +543,7 @@
     case CodeCompletionContext::CCC_PreprocessorExpression:
     case CodeCompletionContext::CCC_PreprocessorDirective:
     case CodeCompletionContext::CCC_Attribute:
+    case CodeCompletionContext::CCC_ReplTopLevel:
     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/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1851,7 +1851,7 @@
   case Sema::PCC_ObjCInstanceVariableList:
   case Sema::PCC_Expression:
   case Sema::PCC_Statement:
-  case Sema::PCC_ReplTopLevel:
+  case Sema::PCC_TopLevelStmtDecl:
   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_ReplTopLevel:
+  case Sema::PCC_TopLevelStmtDecl:
     return true;
 
   case Sema::PCC_Expression:
@@ -2222,7 +2222,7 @@
     break;
 
   case Sema::PCC_RecoveryInFunction:
-  case Sema::PCC_ReplTopLevel:
+  case Sema::PCC_TopLevelStmtDecl:
   case Sema::PCC_Statement: {
     if (SemaRef.getLangOpts().CPlusPlus11)
       AddUsingAliasResult(Builder, Results);
@@ -4212,7 +4212,7 @@
 
   case Sema::PCC_LocalDeclarationSpecifiers:
     return CodeCompletionContext::CCC_Type;
-  case Sema::PCC_ReplTopLevel:
+  case Sema::PCC_TopLevelStmtDecl:
     return CodeCompletionContext::CCC_ReplTopLevel;
   }
 
@@ -4354,7 +4354,7 @@
     break;
 
   case PCC_Statement:
-  case PCC_ReplTopLevel:
+  case PCC_TopLevelStmtDecl:
   case PCC_ParenthesizedExpression:
   case PCC_Expression:
   case PCC_ForInit:
@@ -4392,7 +4392,7 @@
   case PCC_ParenthesizedExpression:
   case PCC_Expression:
   case PCC_Statement:
-  case PCC_ReplTopLevel:
+  case PCC_TopLevelStmtDecl:
   case PCC_RecoveryInFunction:
     if (S->getFnParent())
       AddPrettyFunctionResults(getLangOpts(), Results);
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_ReplTopLevel;
+      PCC = Sema::PCC_TopLevelStmtDecl;
     } else {
       PCC = Sema::PCC_Namespace;
     };
Index: clang/lib/Interpreter/Interpreter.cpp
===================================================================
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -239,12 +239,11 @@
 }
 
 Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err,
-                         std::vector<CodeCompletionResult> &CompResults,
+                         CodeCompleteConsumer* CConsumer,
                          const CompilerInstance *ParentCI) {
   llvm::ErrorAsOutParameter EAO(&Err);
   auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
   TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
-  auto *CConsumer = new ReplCompletionConsumer(CompResults);
   CI->setCodeCompletionConsumer(CConsumer);
   IncrParser = std::make_unique<IncrementalParser>(
       *this, std::move(CI), *TSCtx->getContext(), Err, ParentCI);
@@ -304,7 +303,7 @@
 llvm::Expected<std::unique_ptr<Interpreter>>
 Interpreter::createForCodeCompletion(
     IncrementalCompilerBuilder &CB, const CompilerInstance *ParentCI,
-    std::vector<CodeCompletionResult> &CompResults) {
+    CodeCompleteConsumer* CConsumer) {
   auto CI = CB.CreateCpp();
   if (auto Err = CI.takeError()) {
     return std::move(Err);
@@ -315,12 +314,9 @@
   (*CI)->getLangOpts().SpellChecking = false;
   (*CI)->getLangOpts().DelayedTemplateParsing = false;
 
-  auto &FrontendOpts = (*CI)->getFrontendOpts();
-  FrontendOpts.CodeCompleteOpts = getClangCompleteOpts();
-
   llvm::Error Err = llvm::Error::success();
   auto Interp = std::unique_ptr<Interpreter>(
-      new Interpreter(std::move(*CI), Err, CompResults, ParentCI));
+      new Interpreter(std::move(*CI), Err, CConsumer, ParentCI));
 
   if (Err)
     return std::move(Err);
Index: clang/lib/Interpreter/IncrementalParser.cpp
===================================================================
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -331,11 +331,7 @@
 
   auto [FID, SrcLoc] = createSourceFile(SourceName.str(), input);
   auto FE = CI->getSourceManager().getFileEntryRefForID(FID);
-  // auto Entry = PP.getFileManager().getFile(DummyFN);
-  // if (!Entry) {
-  //   std::cout << "Entry invalid \n";
-  //   return;
-  // }
+
   if (FE) {
     PP.SetCodeCompletionPoint(*FE, Line, Col);
 
@@ -372,13 +368,12 @@
   // candidates for example
   SourceLocation NewLoc = SM.getLocForStartOfFile(SM.getMainFileID());
 
-  // Create FileID for the current buffer.
-  // FileID FID = SM.createFileID(std::move(MB), SrcMgr::C_User, /*LoadedID=*/0,
-  //                              /*LoadedOffset=*/0, NewLoc);
 
   const clang::FileEntry *FE = SM.getFileManager().getVirtualFile(
       SourceName.str(), InputSize, 0 /* mod time*/);
   SM.overrideFileContents(FE, std::move(MB));
+
+  // Create FileID for the current buffer.
   FileID FID = SM.createFileID(FE, NewLoc, SrcMgr::C_User);
   return {FID, NewLoc};
 }
Index: clang/lib/Interpreter/CodeCompletion.cpp
===================================================================
--- clang/lib/Interpreter/CodeCompletion.cpp
+++ clang/lib/Interpreter/CodeCompletion.cpp
@@ -28,6 +28,32 @@
   return Opts;
 }
 
+
+class ReplCompletionConsumer : public CodeCompleteConsumer {
+public:
+  ReplCompletionConsumer(std::vector<CodeCompletionResult> &Results)
+    : CodeCompleteConsumer(getClangCompleteOpts()),
+      CCAllocator(std::make_shared<GlobalCodeCompletionAllocator>()),
+      CCTUInfo(CCAllocator), Results(Results){};
+  void ProcessCodeCompleteResults(class Sema &S, CodeCompletionContext Context,
+                                  CodeCompletionResult *InResults,
+                                  unsigned NumResults) final;
+
+  clang::CodeCompletionAllocator &getAllocator() override {
+    return *CCAllocator;
+  }
+
+  clang::CodeCompletionTUInfo &getCodeCompletionTUInfo() override {
+    return CCTUInfo;
+  }
+
+private:
+  std::shared_ptr<GlobalCodeCompletionAllocator> CCAllocator;
+  CodeCompletionTUInfo CCTUInfo;
+  std::vector<CodeCompletionResult> &Results;
+};
+
+
 void ReplCompletionConsumer::ProcessCodeCompleteResults(
     class Sema &S, CodeCompletionContext Context,
     CodeCompletionResult *InResults, unsigned NumResults) {
@@ -68,12 +94,14 @@
   return CompletionStrings;
 }
 
+
 std::vector<llvm::LineEditor::Completion>
 ReplListCompleter::operator()(llvm::StringRef Buffer, size_t Pos) const {
   std::vector<llvm::LineEditor::Completion> Comps;
   std::vector<CodeCompletionResult> Results;
+  auto *CConsumer = new ReplCompletionConsumer(Results);
   auto Interp = Interpreter::createForCodeCompletion(
-      CB, MainInterp.getCompilerInstance(), Results);
+      CB, MainInterp.getCompilerInstance(), CConsumer);
 
   if (auto Err = Interp.takeError()) {
     // log the error and returns an empty vector;
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13321,7 +13321,7 @@
     /// specifiers within a function, method, or block.
     PCC_LocalDeclarationSpecifiers,
     /// Code completion occurs at top-level in a REPL session
-    PCC_ReplTopLevel,
+    PCC_TopLevelStmtDecl,
   };
 
   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
Index: clang/include/clang/Interpreter/Interpreter.h
===================================================================
--- clang/include/clang/Interpreter/Interpreter.h
+++ clang/include/clang/Interpreter/Interpreter.h
@@ -39,7 +39,7 @@
 class CompilerInstance;
 class IncrementalExecutor;
 class IncrementalParser;
-class ReplCompletionConsumer;
+class CodeCompleteConsumer;
 
 /// Create a pre-configured \c CompilerInstance for incremental processing.
 class IncrementalCompilerBuilder {
@@ -82,11 +82,10 @@
 
   // An optional parser for CUDA offloading
   std::unique_ptr<IncrementalParser> DeviceParser;
-  std::unique_ptr<ReplCompletionConsumer> CConsumer;
 
   Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
   Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err,
-              std::vector<CodeCompletionResult> &CompResults,
+              CodeCompleteConsumer* CConsumer,
               const CompilerInstance *ParentCI = nullptr);
 
   llvm::Error CreateExecutor();
@@ -110,7 +109,7 @@
   static llvm::Expected<std::unique_ptr<Interpreter>>
   createForCodeCompletion(IncrementalCompilerBuilder &CB,
                           const CompilerInstance *ParentCI,
-                          std::vector<CodeCompletionResult> &CompResults);
+                          CodeCompleteConsumer* CConsumer);
 
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
Index: clang/include/clang/Interpreter/CodeCompletion.h
===================================================================
--- clang/include/clang/Interpreter/CodeCompletion.h
+++ clang/include/clang/Interpreter/CodeCompletion.h
@@ -19,31 +19,6 @@
 class Interpreter;
 class IncrementalCompilerBuilder;
 
-clang::CodeCompleteOptions getClangCompleteOpts();
-
-class ReplCompletionConsumer : public CodeCompleteConsumer {
-public:
-  ReplCompletionConsumer(std::vector<CodeCompletionResult> &Results)
-      : CodeCompleteConsumer(getClangCompleteOpts()),
-        CCAllocator(std::make_shared<GlobalCodeCompletionAllocator>()),
-        CCTUInfo(CCAllocator), Results(Results){};
-  void ProcessCodeCompleteResults(class Sema &S, CodeCompletionContext Context,
-                                  CodeCompletionResult *InResults,
-                                  unsigned NumResults) final;
-
-  clang::CodeCompletionAllocator &getAllocator() override {
-    return *CCAllocator;
-  }
-
-  clang::CodeCompletionTUInfo &getCodeCompletionTUInfo() override {
-    return CCTUInfo;
-  }
-
-private:
-  std::shared_ptr<GlobalCodeCompletionAllocator> CCAllocator;
-  CodeCompletionTUInfo CCTUInfo;
-  std::vector<CodeCompletionResult> &Results;
-};
 
 struct ReplListCompleter {
   IncrementalCompilerBuilder &CB;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to