From: Douglas Gregor Date: Mon, 11 Oct 2010 22:12:15 +0000 (+0000) Subject: Eliminate the (de-)serialization of code completion results, now that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9f4f620daf073805b89e893afcdc5eb7a9bdc50;p=clang Eliminate the (de-)serialization of code completion results, now that libclang does not support out-of-process code completion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116253 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index aad7d95ad2..f08b801542 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -267,8 +267,6 @@ def remap_file : Separate<"-remap-file">, HelpText<"Replace the contents of the file with the contents of the file">; def code_completion_at_EQ : Joined<"-code-completion-at=">, Alias; -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">, diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 410129ab7a..e5121e1bf9 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -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); diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 4c16d084fc..b68e9913a6 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -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 = ""; diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index d607ab149b..c32007115e 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -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 diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 44e5fd2215..2777e4dae4 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -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); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b4bb61327f..e3ba54cd39 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -353,8 +353,6 @@ static const char *getActionName(frontend::ActionKind Kind) { static void FrontendOptsToArgs(const FrontendOptions &Opts, std::vector &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); diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 5c95324f4e..ee6fb3bf0e 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -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 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; - } -}