forked from OSchip/llvm-project
Eliminate the (de-)serialization of code completion results, now that
libclang does not support out-of-process code completion. llvm-svn: 116253
This commit is contained in:
parent
b28ce01e34
commit
b9ab0ed33e
|
@ -267,8 +267,6 @@ def remap_file : Separate<"-remap-file">,
|
|||
HelpText<"Replace the contents of the <from> file with the contents of the <to> file">;
|
||||
def code_completion_at_EQ : Joined<"-code-completion-at=">,
|
||||
Alias<code_completion_at>;
|
||||
def no_code_completion_debug_printer : Flag<"-no-code-completion-debug-printer">,
|
||||
HelpText<"Don't use the \"debug\" code-completion print">;
|
||||
def code_completion_macros : Flag<"-code-completion-macros">,
|
||||
HelpText<"Include macros in code-completion results">;
|
||||
def code_completion_patterns : Flag<"-code-completion-patterns">,
|
||||
|
|
|
@ -548,7 +548,7 @@ public:
|
|||
static CodeCompleteConsumer *
|
||||
createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
|
||||
unsigned Line, unsigned Column,
|
||||
bool UseDebugPrinter, bool ShowMacros,
|
||||
bool ShowMacros,
|
||||
bool ShowCodePatterns, bool ShowGlobals,
|
||||
llvm::raw_ostream &OS);
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@ namespace frontend {
|
|||
/// FrontendOptions - Options for controlling the behavior of the frontend.
|
||||
class FrontendOptions {
|
||||
public:
|
||||
unsigned DebugCodeCompletionPrinter : 1; ///< Use the debug printer for code
|
||||
/// completion results.
|
||||
unsigned DisableFree : 1; ///< Disable memory freeing on exit.
|
||||
unsigned RelocatablePCH : 1; ///< When generating PCH files,
|
||||
/// instruct the AST writer to create
|
||||
|
@ -119,7 +117,6 @@ public:
|
|||
|
||||
public:
|
||||
FrontendOptions() {
|
||||
DebugCodeCompletionPrinter = 1;
|
||||
DisableFree = 0;
|
||||
ProgramAction = frontend::ParseSyntaxOnly;
|
||||
ActionName = "";
|
||||
|
|
|
@ -465,14 +465,6 @@ public:
|
|||
/// \param Result If non-NULL, points to an empty code-completion
|
||||
/// result that will be given a cloned copy of
|
||||
CodeCompletionString *Clone(CodeCompletionString *Result = 0) const;
|
||||
|
||||
/// \brief Serialize this code-completion string to the given stream.
|
||||
void Serialize(llvm::raw_ostream &OS) const;
|
||||
|
||||
/// \brief Deserialize a code-completion string from the given string.
|
||||
///
|
||||
/// \returns true if successful, false otherwise.
|
||||
bool Deserialize(const char *&Str, const char *StrEnd);
|
||||
};
|
||||
|
||||
/// \brief Captures a result of code completion.
|
||||
|
@ -797,32 +789,6 @@ public:
|
|||
unsigned NumCandidates);
|
||||
};
|
||||
|
||||
/// \brief A code-completion consumer that prints the results it receives
|
||||
/// in a format that is parsable by the CIndex library.
|
||||
class CIndexCodeCompleteConsumer : public CodeCompleteConsumer {
|
||||
/// \brief The raw output stream.
|
||||
llvm::raw_ostream &OS;
|
||||
|
||||
public:
|
||||
/// \brief Create a new CIndex code-completion consumer that prints its
|
||||
/// results to the given raw output stream in a format readable to the CIndex
|
||||
/// library.
|
||||
CIndexCodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns,
|
||||
bool IncludeGlobals, llvm::raw_ostream &OS)
|
||||
: CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals,
|
||||
true), OS(OS) {}
|
||||
|
||||
/// \brief Prints the finalized code-completion results.
|
||||
virtual void ProcessCodeCompleteResults(Sema &S,
|
||||
CodeCompletionContext Context,
|
||||
CodeCompletionResult *Results,
|
||||
unsigned NumResults);
|
||||
|
||||
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
|
||||
OverloadCandidate *Candidates,
|
||||
unsigned NumCandidates);
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
|
||||
|
|
|
@ -289,7 +289,6 @@ void CompilerInstance::createCodeCompletionConsumer() {
|
|||
CompletionConsumer.reset(
|
||||
createCodeCompletionConsumer(getPreprocessor(),
|
||||
Loc.FileName, Loc.Line, Loc.Column,
|
||||
getFrontendOpts().DebugCodeCompletionPrinter,
|
||||
getFrontendOpts().ShowMacrosInCodeCompletion,
|
||||
getFrontendOpts().ShowCodePatternsInCodeCompletion,
|
||||
getFrontendOpts().ShowGlobalSymbolsInCodeCompletion,
|
||||
|
@ -318,7 +317,6 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
|
|||
const std::string &Filename,
|
||||
unsigned Line,
|
||||
unsigned Column,
|
||||
bool UseDebugPrinter,
|
||||
bool ShowMacros,
|
||||
bool ShowCodePatterns,
|
||||
bool ShowGlobals,
|
||||
|
@ -327,11 +325,7 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
|
|||
return 0;
|
||||
|
||||
// Set up the creation routine for code-completion.
|
||||
if (UseDebugPrinter)
|
||||
return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns,
|
||||
ShowGlobals, OS);
|
||||
else
|
||||
return new CIndexCodeCompleteConsumer(ShowMacros, ShowCodePatterns,
|
||||
return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns,
|
||||
ShowGlobals, OS);
|
||||
}
|
||||
|
||||
|
|
|
@ -353,8 +353,6 @@ static const char *getActionName(frontend::ActionKind Kind) {
|
|||
|
||||
static void FrontendOptsToArgs(const FrontendOptions &Opts,
|
||||
std::vector<std::string> &Res) {
|
||||
if (!Opts.DebugCodeCompletionPrinter)
|
||||
Res.push_back("-no-code-completion-debug-printer");
|
||||
if (Opts.DisableFree)
|
||||
Res.push_back("-disable-free");
|
||||
if (Opts.RelocatablePCH)
|
||||
|
@ -1067,8 +1065,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
|||
Diags.Report(diag::err_drv_invalid_value)
|
||||
<< A->getAsString(Args) << A->getValue(Args);
|
||||
}
|
||||
Opts.DebugCodeCompletionPrinter =
|
||||
!Args.hasArg(OPT_no_code_completion_debug_printer);
|
||||
Opts.DisableFree = Args.hasArg(OPT_disable_free);
|
||||
|
||||
Opts.OutputFile = Args.getLastArgValue(OPT_o);
|
||||
|
|
|
@ -297,126 +297,6 @@ CodeCompletionString::Clone(CodeCompletionString *Result) const {
|
|||
return Result;
|
||||
}
|
||||
|
||||
static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) {
|
||||
OS.write((const char *)&Value, sizeof(unsigned));
|
||||
}
|
||||
|
||||
static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd,
|
||||
unsigned &Value) {
|
||||
if (Memory + sizeof(unsigned) > MemoryEnd)
|
||||
return true;
|
||||
|
||||
memmove(&Value, Memory, sizeof(unsigned));
|
||||
Memory += sizeof(unsigned);
|
||||
return false;
|
||||
}
|
||||
|
||||
void CodeCompletionString::Serialize(llvm::raw_ostream &OS) const {
|
||||
// Write the number of chunks.
|
||||
WriteUnsigned(OS, size());
|
||||
|
||||
for (iterator C = begin(), CEnd = end(); C != CEnd; ++C) {
|
||||
WriteUnsigned(OS, C->Kind);
|
||||
|
||||
switch (C->Kind) {
|
||||
case CK_TypedText:
|
||||
case CK_Text:
|
||||
case CK_Placeholder:
|
||||
case CK_Informative:
|
||||
case CK_ResultType:
|
||||
case CK_CurrentParameter: {
|
||||
const char *Text = C->Text;
|
||||
unsigned StrLen = strlen(Text);
|
||||
WriteUnsigned(OS, StrLen);
|
||||
OS.write(Text, StrLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case CK_Optional:
|
||||
C->Optional->Serialize(OS);
|
||||
break;
|
||||
|
||||
case CK_LeftParen:
|
||||
case CK_RightParen:
|
||||
case CK_LeftBracket:
|
||||
case CK_RightBracket:
|
||||
case CK_LeftBrace:
|
||||
case CK_RightBrace:
|
||||
case CK_LeftAngle:
|
||||
case CK_RightAngle:
|
||||
case CK_Comma:
|
||||
case CK_Colon:
|
||||
case CK_SemiColon:
|
||||
case CK_Equal:
|
||||
case CK_HorizontalSpace:
|
||||
case CK_VerticalSpace:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CodeCompletionString::Deserialize(const char *&Str, const char *StrEnd) {
|
||||
if (Str == StrEnd || *Str == 0)
|
||||
return false;
|
||||
|
||||
unsigned NumBlocks;
|
||||
if (ReadUnsigned(Str, StrEnd, NumBlocks))
|
||||
return false;
|
||||
|
||||
for (unsigned I = 0; I != NumBlocks; ++I) {
|
||||
if (Str + 1 >= StrEnd)
|
||||
break;
|
||||
|
||||
// Parse the next kind.
|
||||
unsigned KindValue;
|
||||
if (ReadUnsigned(Str, StrEnd, KindValue))
|
||||
return false;
|
||||
|
||||
switch (ChunkKind Kind = (ChunkKind)KindValue) {
|
||||
case CK_TypedText:
|
||||
case CK_Text:
|
||||
case CK_Placeholder:
|
||||
case CK_Informative:
|
||||
case CK_ResultType:
|
||||
case CK_CurrentParameter: {
|
||||
unsigned StrLen;
|
||||
if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd))
|
||||
return false;
|
||||
|
||||
AddChunk(Chunk(Kind, StringRef(Str, StrLen)));
|
||||
Str += StrLen;
|
||||
break;
|
||||
}
|
||||
|
||||
case CK_Optional: {
|
||||
std::auto_ptr<CodeCompletionString> Optional(new CodeCompletionString());
|
||||
if (Optional->Deserialize(Str, StrEnd))
|
||||
AddOptionalChunk(Optional);
|
||||
break;
|
||||
}
|
||||
|
||||
case CK_LeftParen:
|
||||
case CK_RightParen:
|
||||
case CK_LeftBracket:
|
||||
case CK_RightBracket:
|
||||
case CK_LeftBrace:
|
||||
case CK_RightBrace:
|
||||
case CK_LeftAngle:
|
||||
case CK_RightAngle:
|
||||
case CK_Comma:
|
||||
case CK_Colon:
|
||||
case CK_SemiColon:
|
||||
case CK_Equal:
|
||||
case CK_HorizontalSpace:
|
||||
case CK_VerticalSpace:
|
||||
AddChunk(Chunk(Kind));
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CodeCompletionResult::Destroy() {
|
||||
if (Kind == RK_Pattern) {
|
||||
delete Pattern;
|
||||
|
@ -636,37 +516,3 @@ bool clang::operator<(const CodeCompletionResult &X,
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
CIndexCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
|
||||
CodeCompletionContext Context,
|
||||
CodeCompletionResult *Results,
|
||||
unsigned NumResults) {
|
||||
// Print the results.
|
||||
for (unsigned I = 0; I != NumResults; ++I) {
|
||||
WriteUnsigned(OS, Results[I].CursorKind);
|
||||
WriteUnsigned(OS, Results[I].Priority);
|
||||
WriteUnsigned(OS, Results[I].Availability);
|
||||
CodeCompletionString *CCS = Results[I].CreateCodeCompletionString(SemaRef);
|
||||
assert(CCS && "No code-completion string?");
|
||||
CCS->Serialize(OS);
|
||||
delete CCS;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CIndexCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
|
||||
unsigned CurrentArg,
|
||||
OverloadCandidate *Candidates,
|
||||
unsigned NumCandidates) {
|
||||
for (unsigned I = 0; I != NumCandidates; ++I) {
|
||||
WriteUnsigned(OS, CXCursor_NotImplemented);
|
||||
WriteUnsigned(OS, /*Priority=*/I);
|
||||
WriteUnsigned(OS, /*Availability=*/CXAvailability_Available);
|
||||
CodeCompletionString *CCS
|
||||
= Candidates[I].CreateSignatureString(CurrentArg, SemaRef);
|
||||
assert(CCS && "No code-completion string?");
|
||||
CCS->Serialize(OS);
|
||||
delete CCS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue