diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/clang-c/Index.h | 25 | ||||
-rw-r--r-- | include/clang/AST/RawCommentList.h | 6 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 2 | ||||
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 15 | ||||
-rw-r--r-- | include/clang/Frontend/CompilerInstance.h | 3 | ||||
-rw-r--r-- | include/clang/Frontend/FrontendOptions.h | 14 | ||||
-rw-r--r-- | include/clang/Sema/CodeCompleteConsumer.h | 71 | ||||
-rw-r--r-- | include/clang/Sema/CodeCompleteOptions.h | 37 |
8 files changed, 125 insertions, 48 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index fd048775d3..b34918fb6f 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -1058,7 +1058,14 @@ enum CXTranslationUnit_Flags { * This option can be used to search for declarations/definitions while * ignoring the usages. */ - CXTranslationUnit_SkipFunctionBodies = 0x40 + CXTranslationUnit_SkipFunctionBodies = 0x40, + + /** + * \brief Used to indicate that brief documentation comments should be + * included into the set of code completions returned from this translation + * unit. + */ + CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80 }; /** @@ -3786,6 +3793,14 @@ clang_getCompletionAnnotation(CXCompletionString completion_string, CINDEX_LINKAGE CXString clang_getCompletionParent(CXCompletionString completion_string, enum CXCursorKind *kind); + +/** + * \brief Retrieve the brief documentation comment attached to the declaration + * that corresponds to the given completion string. + */ +CINDEX_LINKAGE CXString +clang_getCompletionBriefComment(CXCompletionString completion_string); + /** * \brief Retrieve a completion string for an arbitrary declaration or macro * definition cursor. @@ -3836,7 +3851,13 @@ enum CXCodeComplete_Flags { * \brief Whether to include code patterns for language constructs * within the set of code completions, e.g., for loops. */ - CXCodeComplete_IncludeCodePatterns = 0x02 + CXCodeComplete_IncludeCodePatterns = 0x02, + + /** + * \brief Whether to include brief documentation within the set of code + * completions returned. + */ + CXCodeComplete_IncludeBriefComments = 0x04 }; /** diff --git a/include/clang/AST/RawCommentList.h b/include/clang/AST/RawCommentList.h index 73816b7b0b..dc8bbad1d5 100644 --- a/include/clang/AST/RawCommentList.h +++ b/include/clang/AST/RawCommentList.h @@ -92,7 +92,7 @@ public: unsigned getBeginLine(const SourceManager &SM) const; unsigned getEndLine(const SourceManager &SM) const; - StringRef getBriefText(const ASTContext &Context) const { + const char *getBriefText(const ASTContext &Context) const { if (BriefTextValid) return BriefText; @@ -103,7 +103,7 @@ private: SourceRange Range; mutable StringRef RawText; - mutable StringRef BriefText; + mutable const char *BriefText; mutable bool RawTextValid : 1; ///< True if RawText is valid mutable bool BriefTextValid : 1; ///< True if BriefText is valid @@ -129,7 +129,7 @@ private: StringRef getRawTextSlow(const SourceManager &SourceMgr) const; - StringRef extractBriefText(const ASTContext &Context) const; + const char *extractBriefText(const ASTContext &Context) const; friend class ASTReader; }; diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index da22046f36..436aed4ae2 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -269,6 +269,8 @@ def code_completion_patterns : Flag<"-code-completion-patterns">, HelpText<"Include code patterns in code-completion results">; def no_code_completion_globals : Flag<"-no-code-completion-globals">, HelpText<"Do not include global declarations in code-completion results.">; +def code_completion_brief_comments : Flag<"-code-completion-brief-comments">, + HelpText<"Include brief documentation comments in code-completion results.">; def disable_free : Flag<"-disable-free">, HelpText<"Disable freeing of memory on exit">; def load : Separate<"-load">, MetaVarName<"<dsopath>">, diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index c22a18bd1c..cc503bc4eb 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -248,7 +248,11 @@ private: std::vector<serialization::DeclID> TopLevelDeclsInPreamble; /// \brief Whether we should be caching code-completion results. - bool ShouldCacheCodeCompletionResults; + bool ShouldCacheCodeCompletionResults : 1; + + /// \brief Whether to include brief documentation within the set of code + /// completions cached. + bool IncludeBriefCommentsInCodeCompletion : 1; /// \brief The language options used when we load an AST file. LangOptions ASTFileLangOpts; @@ -681,6 +685,7 @@ public: bool CaptureDiagnostics = false, bool PrecompilePreamble = false, bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false, OwningPtr<ASTUnit> *ErrAST = 0); /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a @@ -700,7 +705,8 @@ public: bool CaptureDiagnostics = false, bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete, - bool CacheCodeCompletionResults = false); + bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false); /// LoadFromCommandLine - Create an ASTUnit from a vector of command line /// arguments, which must specify exactly one source file. @@ -732,6 +738,7 @@ public: bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete, bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false, bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false, OwningPtr<ASTUnit> *ErrAST = 0); @@ -759,11 +766,15 @@ public: /// \param IncludeCodePatterns Whether to include code patterns (such as a /// for loop) in the code-completion results. /// + /// \param IncludeBriefComments Whether to include brief documentation within + /// the set of code completions returned. + /// /// 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, RemappedFile *RemappedFiles, unsigned NumRemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, + bool IncludeBriefComments, CodeCompleteConsumer &Consumer, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 1bb76952d5..b28e1031b8 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -560,8 +560,7 @@ public: static CodeCompleteConsumer * createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename, unsigned Line, unsigned Column, - bool ShowMacros, - bool ShowCodePatterns, bool ShowGlobals, + const CodeCompleteOptions &Opts, raw_ostream &OS); /// \brief Create the Sema object to be used for parsing. diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 48cd317fb3..22cce9cc37 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H #include "clang/Frontend/CommandLineSourceLoc.h" +#include "clang/Sema/CodeCompleteOptions.h" #include "llvm/ADT/StringRef.h" #include <string> #include <vector> @@ -84,7 +85,7 @@ struct FrontendInputFile { FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) : File(File.str()), Kind(Kind), IsSystem(IsSystem) { } }; - + /// FrontendOptions - Options for controlling the behavior of the frontend. class FrontendOptions { public: @@ -93,12 +94,6 @@ public: /// instruct the AST writer to create /// relocatable PCH files. unsigned ShowHelp : 1; ///< Show the -help text. - unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion - /// results. - unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code - /// completion results. - unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in - /// code completion results. unsigned ShowStats : 1; ///< Show frontend performance /// metrics and statistics. unsigned ShowTimers : 1; ///< Show timers for individual @@ -116,6 +111,8 @@ public: /// not need them (e.g. with code /// completion). + CodeCompleteOptions CodeCompleteOpts; + enum { ARCMT_None, ARCMT_Check, @@ -183,9 +180,6 @@ public: ActionName = ""; RelocatablePCH = 0; ShowHelp = 0; - ShowMacrosInCodeCompletion = 0; - ShowCodePatternsInCodeCompletion = 0; - ShowGlobalSymbolsInCodeCompletion = 1; ShowStats = 0; ShowTimers = 0; ShowVersion = 0; diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index f7c7586065..d43aaafb29 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -15,6 +15,7 @@ #include "clang/AST/Type.h" #include "clang/AST/CanonicalType.h" +#include "clang/Sema/CodeCompleteOptions.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" @@ -444,6 +445,10 @@ private: /// \brief The name of the parent context. StringRef ParentName; + + /// \brief A brief documentation comment attached to the declaration of + /// entity being completed by this result. + const char *BriefComment; CodeCompletionString(const CodeCompletionString &); // DO NOT IMPLEMENT CodeCompletionString &operator=(const CodeCompletionString &); // DITTO @@ -451,7 +456,8 @@ private: CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, unsigned Priority, CXAvailabilityKind Availability, const char **Annotations, unsigned NumAnnotations, - CXCursorKind ParentKind, StringRef ParentName); + CXCursorKind ParentKind, StringRef ParentName, + const char *BriefComment); ~CodeCompletionString() { } friend class CodeCompletionBuilder; @@ -493,6 +499,10 @@ public: StringRef getParentContextName() const { return ParentName; } + + const char *getBriefComment() const { + return BriefComment; + } /// \brief Retrieve a string representation of the code completion string, /// which is mainly useful for debugging. @@ -569,6 +579,7 @@ private: CXAvailabilityKind Availability; CXCursorKind ParentKind; StringRef ParentName; + const char *BriefComment; /// \brief The chunks stored in this string. SmallVector<Chunk, 4> Chunks; @@ -580,14 +591,14 @@ public: CodeCompletionTUInfo &CCTUInfo) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(0), Availability(CXAvailability_Available), - ParentKind(CXCursor_NotImplemented) { } + ParentKind(CXCursor_NotImplemented), BriefComment(NULL) { } CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority), Availability(Availability), - ParentKind(CXCursor_NotImplemented) { } + ParentKind(CXCursor_NotImplemented), BriefComment(NULL) { } /// \brief Retrieve the allocator into which the code completion /// strings should be allocated. @@ -628,6 +639,8 @@ public: /// \brief Add the parent context information to this code completion. void addParentContext(DeclContext *DC); + + void addBriefComment(StringRef Comment); CXCursorKind getParentKind() const { return ParentKind; } StringRef getParentName() const { return ParentName; } @@ -780,11 +793,13 @@ public: /// string itself. CodeCompletionString *CreateCodeCompletionString(Sema &S, CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo); + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments); CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, Preprocessor &PP, CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo); + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments); /// \brief Determine a base priority for the given declaration. static unsigned getPriorityFromDecl(NamedDecl *ND); @@ -818,16 +833,7 @@ raw_ostream &operator<<(raw_ostream &OS, /// information. class CodeCompleteConsumer { protected: - /// \brief Whether to include macros in the code-completion results. - bool IncludeMacros; - - /// \brief Whether to include code patterns (such as for loops) within - /// the completion results. - bool IncludeCodePatterns; - - /// \brief Whether to include global (top-level) declarations and names in - /// the completion results. - bool IncludeGlobals; + const CodeCompleteOptions CodeCompleteOpts; /// \brief Whether the output format for the code-completion consumer is /// binary. @@ -900,22 +906,31 @@ public: CodeCompletionTUInfo &CCTUInfo) const; }; - CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false), - IncludeGlobals(true), OutputIsBinary(false) { } - - CodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns, - bool IncludeGlobals, bool OutputIsBinary) - : IncludeMacros(IncludeMacros), IncludeCodePatterns(IncludeCodePatterns), - IncludeGlobals(IncludeGlobals), OutputIsBinary(OutputIsBinary) { } + CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, + bool OutputIsBinary) + : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) + { } /// \brief Whether the code-completion consumer wants to see macros. - bool includeMacros() const { return IncludeMacros; } + bool includeMacros() const { + return CodeCompleteOpts.IncludeMacros; + } /// \brief Whether the code-completion consumer wants to see code patterns. - bool includeCodePatterns() const { return IncludeCodePatterns; } + bool includeCodePatterns() const { + return CodeCompleteOpts.IncludeCodePatterns; + } /// \brief Whether to include global (top-level) declaration results. - bool includeGlobals() const { return IncludeGlobals; } + bool includeGlobals() const { + return CodeCompleteOpts.IncludeGlobals; + } + + /// \brief Whether to include brief documentation comments within the set of + /// code completions returned. + bool includeBriefComments() const { + return CodeCompleteOpts.IncludeBriefComments; + } /// \brief Determine whether the output of this consumer is binary. bool isOutputBinary() const { return OutputIsBinary; } @@ -962,11 +977,9 @@ class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { public: /// \brief Create a new printing code-completion consumer that prints its /// results to the given raw output stream. - PrintingCodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns, - bool IncludeGlobals, + PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, raw_ostream &OS) - : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals, - false), OS(OS), + : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS), CCTUInfo(new GlobalCodeCompletionAllocator) {} /// \brief Prints the finalized code-completion results. diff --git a/include/clang/Sema/CodeCompleteOptions.h b/include/clang/Sema/CodeCompleteOptions.h new file mode 100644 index 0000000000..30712dbad1 --- /dev/null +++ b/include/clang/Sema/CodeCompleteOptions.h @@ -0,0 +1,37 @@ +//===---- CodeCompleteOptions.h - Code Completion Options -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SEMA_CODECOMPLETEOPTIONS_H +#define LLVM_CLANG_SEMA_CODECOMPLETEOPTIONS_H + +/// Options controlling the behavior of code completion. +class CodeCompleteOptions { +public: + ///< Show macros in code completion results. + unsigned IncludeMacros : 1; + + ///< Show code patterns in code completion results. + unsigned IncludeCodePatterns : 1; + + ///< Show top-level decls in code completion results. + unsigned IncludeGlobals : 1; + + ///< Show brief documentation comments in code completion results. + unsigned IncludeBriefComments : 1; + + CodeCompleteOptions() : + IncludeMacros(0), + IncludeCodePatterns(0), + IncludeGlobals(1), + IncludeBriefComments(0) + { } +}; + +#endif + |