summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-12-07 09:27:33 +0000
committerDouglas Gregor <dgregor@apple.com>2009-12-07 09:27:33 +0000
commitf48706c787843768430a89edaba489f2a4ac2d15 (patch)
tree4322e8d91688dcf76fccfc9c80b57d526ccd1ca6 /clang/lib
parent175447f743490a34d3dcfe6ad630a38fceaa8c4d (diff)
downloadbcm5719-llvm-f48706c787843768430a89edaba489f2a4ac2d15.tar.gz
bcm5719-llvm-f48706c787843768430a89edaba489f2a4ac2d15.zip
Code completion for Objective-C @ directives
llvm-svn: 90756
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Parse/ParseObjc.cpp16
-rw-r--r--clang/lib/Sema/Sema.h2
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp88
3 files changed, 105 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 8525c49d726..f1832e5707f 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -30,6 +30,11 @@ using namespace clang;
Parser::DeclPtrTy Parser::ParseObjCAtDirectives() {
SourceLocation AtLoc = ConsumeToken(); // the "@"
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, false);
+ ConsumeToken();
+ }
+
switch (Tok.getObjCKeywordID()) {
case tok::objc_class:
return ParseObjCAtClassDeclaration(AtLoc);
@@ -345,6 +350,12 @@ void Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
// Otherwise, we have an @ directive, eat the @.
SourceLocation AtLoc = ConsumeToken(); // the "@"
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
+ ConsumeToken();
+ break;
+ }
+
tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
if (DirectiveKind == tok::objc_end) { // @end -> terminate list
@@ -401,7 +412,10 @@ void Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
// We break out of the big loop in two cases: when we see @end or when we see
// EOF. In the former case, eat the @end. In the later case, emit an error.
- if (Tok.isObjCAtKeyword(tok::objc_end))
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteObjCAtDirective(CurScope, ObjCImpDecl, true);
+ ConsumeToken();
+ } else if (Tok.isObjCAtKeyword(tok::objc_end))
ConsumeToken(); // the "end" identifier
else
Diag(Tok, diag::err_objc_missing_end);
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index edb4528f7e6..806f1e94d3a 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -3778,6 +3778,8 @@ public:
virtual void CodeCompleteNamespaceAliasDecl(Scope *S);
virtual void CodeCompleteOperatorName(Scope *S);
+ virtual void CodeCompleteObjCAtDirective(Scope *S, DeclPtrTy ObjCImpDecl,
+ bool InInterface);
virtual void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
virtual void CodeCompleteObjCPropertyGetter(Scope *S, DeclPtrTy ClassDecl,
DeclPtrTy *Methods,
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 5f9bba0f8c8..5e231a54d1a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1847,6 +1847,94 @@ void Sema::CodeCompleteOperatorName(Scope *S) {
HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
}
+void Sema::CodeCompleteObjCAtDirective(Scope *S, DeclPtrTy ObjCImpDecl,
+ bool InInterface) {
+ typedef CodeCompleteConsumer::Result Result;
+ ResultBuilder Results(*this);
+ Results.EnterNewScope();
+ if (ObjCImpDecl) {
+ // Since we have an implementation, we can end it.
+ Results.MaybeAddResult(Result("end", 0));
+
+ CodeCompletionString *Pattern = 0;
+ Decl *ImpDecl = ObjCImpDecl.getAs<Decl>();
+ if (isa<ObjCImplementationDecl>(ImpDecl) ||
+ isa<ObjCCategoryImplDecl>(ImpDecl)) {
+ // @dynamic
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("dynamic");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("property");
+ Results.MaybeAddResult(Result(Pattern, 0));
+
+ // @synthesize
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("synthesize");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("property");
+ Results.MaybeAddResult(Result(Pattern, 0));
+ }
+ } else if (InInterface) {
+ // Since we have an interface or protocol, we can end it.
+ Results.MaybeAddResult(Result("end", 0));
+
+ if (LangOpts.ObjC2) {
+ // @property
+ Results.MaybeAddResult(Result("property", 0));
+ }
+
+ // @required
+ Results.MaybeAddResult(Result("required", 0));
+
+ // @optional
+ Results.MaybeAddResult(Result("optional", 0));
+ } else {
+ CodeCompletionString *Pattern = 0;
+
+ // @class name ;
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("class");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("identifier");
+ Pattern->AddTextChunk(";"); // add ';' chunk
+ Results.MaybeAddResult(Result(Pattern, 0));
+
+ // @interface name
+ // FIXME: Could introduce the whole pattern, including superclasses and
+ // such.
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("interface");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("class");
+ Results.MaybeAddResult(Result(Pattern, 0));
+
+ // @protocol name
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("protocol");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("protocol");
+ Results.MaybeAddResult(Result(Pattern, 0));
+
+ // @implementation name
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("implementation");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("class");
+ Results.MaybeAddResult(Result(Pattern, 0));
+
+ // @compatibility_alias name
+ Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk("compatibility_alias");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("alias");
+ Pattern->AddTextChunk(" ");
+ Pattern->AddPlaceholderChunk("class");
+ Results.MaybeAddResult(Result(Pattern, 0));
+ }
+ Results.ExitScope();
+ HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
+}
+
/// \brief Determine whether the addition of the given flag to an Objective-C
/// property's attributes will cause a conflict.
static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) {
OpenPOWER on IntegriCloud