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">,
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);
/// 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
public:
FrontendOptions() {
- DebugCodeCompletionPrinter = 1;
DisableFree = 0;
ProgramAction = frontend::ParseSyntaxOnly;
ActionName = "";
/// \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.
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
CompletionConsumer.reset(
createCodeCompletionConsumer(getPreprocessor(),
Loc.FileName, Loc.Line, Loc.Column,
- getFrontendOpts().DebugCodeCompletionPrinter,
getFrontendOpts().ShowMacrosInCodeCompletion,
getFrontendOpts().ShowCodePatternsInCodeCompletion,
getFrontendOpts().ShowGlobalSymbolsInCodeCompletion,
const std::string &Filename,
unsigned Line,
unsigned Column,
- bool UseDebugPrinter,
bool ShowMacros,
bool ShowCodePatterns,
bool ShowGlobals,
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);
}
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)
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);
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;
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;
- }
-}