aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-24 19:08:16 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-24 19:08:16 +0000
commitf44e854ed1e3aa86d2ed6d615ccd109d50ddcff9 (patch)
treeb3fd57ca42856df16b30ce95b7030b5a4e10123c /include/clang
parentcdaa6a8fed16d8bd3987fb4f3304dfb4e52876c3 (diff)
Introduce basic code-completion support for preprocessor directives,
e.g., after a "#" we'll suggest #if, #ifdef, etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111943 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Lex/CodeCompletionHandler.h42
-rw-r--r--include/clang/Lex/Preprocessor.h14
-rw-r--r--include/clang/Parse/Parser.h8
-rw-r--r--include/clang/Sema/Action.h10
-rw-r--r--include/clang/Sema/Sema.h2
5 files changed, 75 insertions, 1 deletions
diff --git a/include/clang/Lex/CodeCompletionHandler.h b/include/clang/Lex/CodeCompletionHandler.h
new file mode 100644
index 0000000000..4cc3b12d47
--- /dev/null
+++ b/include/clang/Lex/CodeCompletionHandler.h
@@ -0,0 +1,42 @@
+//===--- CodeCompletionHandler.h - Preprocessor code completion -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the CodeCompletionHandler interface, which provides
+// code-completion callbacks for the preprocessor.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
+#define LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
+
+namespace clang {
+
+/// \brief Callback handler that receives notifications when performing code
+/// completion within the preprocessor.
+class CodeCompletionHandler {
+public:
+ virtual ~CodeCompletionHandler();
+
+ /// \brief Callback invoked when performing code completion for a preprocessor
+ /// directive.
+ ///
+ /// This callback will be invoked when the preprocessor processes a '#' at the
+ /// start of a line, followed by the code-completion token.
+ ///
+ /// \param InConditional Whether we're inside a preprocessor conditional
+ /// already.
+ virtual void CodeCompleteDirective(bool InConditional) { }
+
+ /// \brief Callback invoked when performing code completion within a block of
+ /// code that was excluded due to preprocessor conditionals.
+ virtual void CodeCompleteInConditionalExclusion() { }
+};
+
+}
+
+#endif // LLVM_CLANG_LEX_CODECOMPLETIONHANDLER_H
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 8bf0df3d02..712feaa425 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -42,6 +42,7 @@ class CommentHandler;
class ScratchBuffer;
class TargetInfo;
class PPCallbacks;
+class CodeCompletionHandler;
class DirectoryLookup;
class PreprocessingRecord;
@@ -131,6 +132,9 @@ class Preprocessor {
/// with this preprocessor.
std::vector<CommentHandler *> CommentHandlers;
+ /// \brief The code-completion handler.
+ CodeCompletionHandler *CodeComplete;
+
/// \brief The file that we're performing code-completion for, if any.
const FileEntry *CodeCompletionFile;
@@ -373,6 +377,16 @@ public:
/// It is an error to remove a handler that has not been registered.
void RemoveCommentHandler(CommentHandler *Handler);
+ /// \brief Set the code completion handler to the given object.
+ void setCodeCompletionHandler(CodeCompletionHandler &Handler) {
+ CodeComplete = &Handler;
+ }
+
+ /// \brief Clear out the code completion handler.
+ void clearCodeCompletionHandler() {
+ CodeComplete = 0;
+ }
+
/// \brief Retrieve the preprocessing record, or NULL if there is no
/// preprocessing record.
PreprocessingRecord *getPreprocessingRecord() const { return Record; }
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index ceaeb34ee5..83b42fd172 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -16,6 +16,7 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/CodeCompletionHandler.h"
#include "clang/Sema/Action.h"
#include "clang/Sema/DeclSpec.h"
#include "llvm/ADT/OwningPtr.h"
@@ -70,7 +71,7 @@ namespace prec {
/// parsing units of the grammar, productions are invoked to handle whatever has
/// been read.
///
-class Parser {
+class Parser : public CodeCompletionHandler {
friend class PragmaUnusedHandler;
friend class ColonProtectionRAIIObject;
friend class ParenBraceBracketBalancer;
@@ -1529,6 +1530,11 @@ private:
//===--------------------------------------------------------------------===//
// GNU G++: Type Traits [Type-Traits.html in the GCC manual]
ExprResult ParseUnaryTypeTrait();
+
+ //===--------------------------------------------------------------------===//
+ // Preprocessor code-completion pass-through
+ virtual void CodeCompleteDirective(bool InConditional);
+ virtual void CodeCompleteInConditionalExclusion();
};
} // end namespace clang
diff --git a/include/clang/Sema/Action.h b/include/clang/Sema/Action.h
index 1d3d460b41..d407037515 100644
--- a/include/clang/Sema/Action.h
+++ b/include/clang/Sema/Action.h
@@ -3205,6 +3205,16 @@ public:
IdentifierInfo **SelIdents,
unsigned NumSelIdents) { }
+ /// \brief Code completion for a preprocessor directive.
+ ///
+ /// \brief S The scope in which the preprocessor directive is being parsed.
+ /// \brief InConditional Whether we're inside a preprocessor conditional.
+ virtual void CodeCompletePreprocessorDirective(Scope *S, bool InConditional) {
+ }
+
+ /// \brief Code completion while in an area of the translation unit that was
+ /// excluded due to preprocessor conditionals.
+ virtual void CodeCompleteInPreprocessorConditionalExclusion(Scope *S) { }
//@}
};
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 3991bce7e1..b4449ff45c 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -4690,6 +4690,8 @@ public:
ParsedType ReturnType,
IdentifierInfo **SelIdents,
unsigned NumSelIdents);
+ virtual void CodeCompletePreprocessorDirective(Scope *S, bool InConditional);
+ virtual void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
void GatherGlobalCodeCompletions(
llvm::SmallVectorImpl<CodeCompleteConsumer::Result> &Results);
//@}