Skip to content

Commit

Permalink
Revert "Reland "[clang-repl] support code completion at a REPL.""
Browse files Browse the repository at this point in the history
This reverts commit 5ab25a4 due to forgotten
files.
  • Loading branch information
vgvassilev committed Aug 28, 2023
1 parent cd591e0 commit 752f87c
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 127 deletions.
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) {
case CodeCompletionContext::CCC_Symbol:
case CodeCompletionContext::CCC_SymbolOrNewName:
case CodeCompletionContext::CCC_ObjCClassForwardDecl:
case CodeCompletionContext::CCC_TopLevelOrExpression:
return true;
case CodeCompletionContext::CCC_OtherWithMacros:
case CodeCompletionContext::CCC_DotMemberAccess:
Expand Down
8 changes: 1 addition & 7 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Preprocessor;
class PreprocessorOptions;
class Sema;
class TargetInfo;
class SyntaxOnlyAction;

/// \brief Enumerates the available scopes for skipping function bodies.
enum class SkipFunctionBodiesScope { None, Preamble, PreambleAndMainFile };
Expand Down Expand Up @@ -888,10 +887,6 @@ class ASTUnit {
/// \param IncludeBriefComments Whether to include brief documentation within
/// the set of code completions returned.
///
/// \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.
void CodeComplete(StringRef File, unsigned Line, unsigned Column,
Expand All @@ -902,8 +897,7 @@ class ASTUnit {
DiagnosticsEngine &Diag, LangOptions &LangOpts,
SourceManager &SourceMgr, FileManager &FileMgr,
SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
std::unique_ptr<SyntaxOnlyAction> Act = nullptr);
SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);

/// Save this translation unit to a file with the given name.
///
Expand Down
7 changes: 1 addition & 6 deletions clang/include/clang/Sema/CodeCompleteConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,7 @@ class CodeCompletionContext {
CCC_Recovery,

/// Code completion in a @class forward declaration.
CCC_ObjCClassForwardDecl,

/// Code completion at a top level, i.e. in a namespace or global scope,
/// but also in expression statements. This is because REPL inputs can be
/// declarations or expression statements.
CCC_TopLevelOrExpression,
CCC_ObjCClassForwardDecl
};

using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>;
Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13456,9 +13456,7 @@ class Sema final {
PCC_ParenthesizedExpression,
/// Code completion occurs within a sequence of declaration
/// specifiers within a function, method, or block.
PCC_LocalDeclarationSpecifiers,
/// Code completion occurs at top-level in a REPL session
PCC_TopLevelOrExpression,
PCC_LocalDeclarationSpecifiers
};

void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
Expand Down
11 changes: 4 additions & 7 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2008,8 +2008,7 @@ static void CalculateHiddenNames(const CodeCompletionContext &Context,
case CodeCompletionContext::CCC_SymbolOrNewName:
case CodeCompletionContext::CCC_ParenthesizedExpression:
case CodeCompletionContext::CCC_ObjCInterfaceName:
case CodeCompletionContext::CCC_TopLevelOrExpression:
break;
break;

case CodeCompletionContext::CCC_EnumTag:
case CodeCompletionContext::CCC_UnionTag:
Expand Down Expand Up @@ -2168,8 +2167,7 @@ void ASTUnit::CodeComplete(
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr,
FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers,
std::unique_ptr<SyntaxOnlyAction> Act) {
SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers) {
if (!Invocation)
return;

Expand Down Expand Up @@ -2306,9 +2304,8 @@ void ASTUnit::CodeComplete(
if (!Clang->getLangOpts().Modules)
PreprocessorOpts.DetailedRecord = false;

if (!Act)
Act.reset(new SyntaxOnlyAction);

std::unique_ptr<SyntaxOnlyAction> Act;
Act.reset(new SyntaxOnlyAction);
if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
if (llvm::Error Err = Act->Execute()) {
consumeError(std::move(Err)); // FIXME this drops errors on the floor.
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(LLVM_LINK_COMPONENTS

add_clang_library(clangInterpreter
DeviceOffload.cpp
CodeCompletion.cpp
IncrementalExecutor.cpp
IncrementalParser.cpp
Interpreter.cpp
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

#include "IncrementalParser.h"

#include "clang/AST/DeclContextInternals.h"
#include "clang/CodeGen/BackendUtil.h"
#include "clang/CodeGen/CodeGenAction.h"
Expand Down Expand Up @@ -158,11 +157,16 @@ class IncrementalAction : public WrapperFrontendAction {
TranslationUnitKind getTranslationUnitKind() override {
return TU_Incremental;
}

void ExecuteAction() override {
CompilerInstance &CI = getCompilerInstance();
assert(CI.hasPreprocessor() && "No PP!");

// FIXME: Move the truncation aspect of this into Sema, we delayed this till
// here so the source manager would be initialized.
if (hasCodeCompletionSupport() &&
!CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
CI.createCodeCompletionConsumer();

// Use a code completion consumer?
CodeCompleteConsumer *CompletionConsumer = nullptr;
if (CI.hasCodeCompletionConsumer())
Expand Down Expand Up @@ -394,4 +398,5 @@ llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const {
assert(CG);
return CG->GetMangledName(GD);
}

} // end namespace clang
4 changes: 2 additions & 2 deletions clang/lib/Interpreter/IncrementalParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
#define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H

#include "clang/AST/GlobalDecl.h"
#include "clang/Interpreter/PartialTranslationUnit.h"

#include "clang/AST/GlobalDecl.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
Expand All @@ -24,7 +24,7 @@
#include <memory>
namespace llvm {
class LLVMContext;
} // namespace llvm
}

namespace clang {
class ASTConsumer;
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
//
//===----------------------------------------------------------------------===//

#include "clang/Interpreter/Interpreter.h"

#include "DeviceOffload.h"
#include "IncrementalExecutor.h"
#include "IncrementalParser.h"
#include "InterpreterUtils.h"

#include "InterpreterUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/TypeVisitor.h"
Expand All @@ -31,7 +33,6 @@
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Interpreter/Interpreter.h"
#include "clang/Interpreter/Value.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/Lookup.h"
Expand Down Expand Up @@ -126,6 +127,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {

Clang->getFrontendOpts().DisableFree = false;
Clang->getCodeGenOpts().DisableFree = false;

return std::move(Clang);
}

Expand Down Expand Up @@ -274,7 +276,6 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
if (Err)
return std::move(Err);

auto PTU = Interp->Parse(Runtimes);
if (!PTU)
return PTU.takeError();
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "clang/Basic/Attributes.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Parse/Parser.h"
#include "clang/Parse/RAIIObjectsForParser.h"
Expand Down
13 changes: 3 additions & 10 deletions clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,9 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
/*IsInstanceMethod=*/std::nullopt,
/*ReturnType=*/nullptr);
}

Sema::ParserCompletionContext PCC;
if (CurParsedObjCImpl) {
PCC = Sema::PCC_ObjCImplementation;
} else if (PP.isIncrementalProcessingEnabled()) {
PCC = Sema::PCC_TopLevelOrExpression;
} else {
PCC = Sema::PCC_Namespace;
};
Actions.CodeCompleteOrdinaryName(getCurScope(), PCC);
Actions.CodeCompleteOrdinaryName(
getCurScope(),
CurParsedObjCImpl ? Sema::PCC_ObjCImplementation : Sema::PCC_Namespace);
return nullptr;
case tok::kw_import: {
Sema::ModuleImportState IS = Sema::ModuleImportState::NotACXX20Module;
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Sema/CodeCompleteConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ bool CodeCompletionContext::wantConstructorResults() const {
case CCC_ParenthesizedExpression:
case CCC_Symbol:
case CCC_SymbolOrNewName:
case CCC_TopLevelOrExpression:
return true;

case CCC_TopLevel:
Expand Down Expand Up @@ -170,8 +169,6 @@ StringRef clang::getCompletionKindString(CodeCompletionContext::Kind Kind) {
return "Recovery";
case CCKind::CCC_ObjCClassForwardDecl:
return "ObjCClassForwardDecl";
case CCKind::CCC_TopLevelOrExpression:
return "ReplTopLevel";
}
llvm_unreachable("Invalid CodeCompletionContext::Kind!");
}
Expand Down
8 changes: 0 additions & 8 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class ResultBuilder {
case CodeCompletionContext::CCC_ObjCMessageReceiver:
case CodeCompletionContext::CCC_ParenthesizedExpression:
case CodeCompletionContext::CCC_Statement:
case CodeCompletionContext::CCC_TopLevelOrExpression:
case CodeCompletionContext::CCC_Recovery:
if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl())
if (Method->isInstanceMethod())
Expand Down Expand Up @@ -1851,7 +1850,6 @@ static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC,
case Sema::PCC_ObjCInstanceVariableList:
case Sema::PCC_Expression:
case Sema::PCC_Statement:
case Sema::PCC_TopLevelOrExpression:
case Sema::PCC_ForInit:
case Sema::PCC_Condition:
case Sema::PCC_RecoveryInFunction:
Expand Down Expand Up @@ -1909,7 +1907,6 @@ static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
case Sema::PCC_Type:
case Sema::PCC_ParenthesizedExpression:
case Sema::PCC_LocalDeclarationSpecifiers:
case Sema::PCC_TopLevelOrExpression:
return true;

case Sema::PCC_Expression:
Expand Down Expand Up @@ -2222,7 +2219,6 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S,
break;

case Sema::PCC_RecoveryInFunction:
case Sema::PCC_TopLevelOrExpression:
case Sema::PCC_Statement: {
if (SemaRef.getLangOpts().CPlusPlus11)
AddUsingAliasResult(Builder, Results);
Expand Down Expand Up @@ -4212,8 +4208,6 @@ mapCodeCompletionContext(Sema &S, Sema::ParserCompletionContext PCC) {

case Sema::PCC_LocalDeclarationSpecifiers:
return CodeCompletionContext::CCC_Type;
case Sema::PCC_TopLevelOrExpression:
return CodeCompletionContext::CCC_TopLevelOrExpression;
}

llvm_unreachable("Invalid ParserCompletionContext!");
Expand Down Expand Up @@ -4354,7 +4348,6 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
break;

case PCC_Statement:
case PCC_TopLevelOrExpression:
case PCC_ParenthesizedExpression:
case PCC_Expression:
case PCC_ForInit:
Expand Down Expand Up @@ -4392,7 +4385,6 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
case PCC_ParenthesizedExpression:
case PCC_Expression:
case PCC_Statement:
case PCC_TopLevelOrExpression:
case PCC_RecoveryInFunction:
if (S->getFnParent())
AddPrettyFunctionResults(getLangOpts(), Results);
Expand Down

0 comments on commit 752f87c

Please sign in to comment.