summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-04-18 14:40:46 +0000
committerDouglas Gregor <dgregor@apple.com>2011-04-18 14:40:46 +0000
commit6c7a9eec42033931a9ed09b92561c39c0abbd59e (patch)
tree7e32bfcf04071e6da03211c7b7ffffecfe639c95 /clang/lib/Sema/SemaCodeComplete.cpp
parent566ae67ef8e2cae37893b3ff7572649da03f42d9 (diff)
downloadbcm5719-llvm-6c7a9eec42033931a9ed09b92561c39c0abbd59e.tar.gz
bcm5719-llvm-6c7a9eec42033931a9ed09b92561c39c0abbd59e.zip
When providing code completions of ivar names for a property
implementation such as @synthesize Prop1 = Give priority to ivars whose type matches or closely matches the property type (as we do for several other kinds of results). Additionally, if there is an ivar with the same name as the property, or differs only due to a _ prefix or suffix, give that ivar a priority bump. Finally, verify that this search is properly returning ivars within class extensions and implementations (<rdar://problem/8488854>). llvm-svn: 129699
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index fa76db4c638..cc8726de9df 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5370,6 +5370,19 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
Class = cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl()
->getClassInterface();
+ // Determine the type of the property we're synthesizing.
+ QualType PropertyType = Context.getObjCIdType();
+ if (Class) {
+ if (ObjCPropertyDecl *Property
+ = Class->FindPropertyDeclaration(PropertyName)) {
+ PropertyType
+ = Property->getType().getNonReferenceType().getUnqualifiedType();
+
+ // Give preference to ivars
+ Results.setPreferredType(PropertyType);
+ }
+ }
+
// Add all of the instance variables in this class and its superclasses.
Results.EnterNewScope();
bool SawSimilarlyNamedIvar = false;
@@ -5379,39 +5392,38 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
std::string NameWithSuffix = PropertyName->getName().str();
NameWithSuffix += '_';
for(; Class; Class = Class->getSuperClass()) {
- // FIXME: We could screen the type of each ivar for compatibility with
- // the property, but is that being too paternal?
for (ObjCIvarDecl *Ivar = Class->all_declared_ivar_begin(); Ivar;
Ivar = Ivar->getNextIvar()) {
+ Results.AddResult(Result(Ivar, 0), CurContext, 0, false);
+
// Determine whether we've seen an ivar with a name similar to the
// property.
- if (!SawSimilarlyNamedIvar &&
- (PropertyName->getName() == Ivar->getName() ||
+ if ((PropertyName == Ivar->getIdentifier() ||
NameWithPrefix == Ivar->getName() ||
- NameWithSuffix == Ivar->getName()))
+ NameWithSuffix == Ivar->getName())) {
SawSimilarlyNamedIvar = true;
-
- Results.AddResult(Result(Ivar, 0), CurContext, 0, false);
+
+ // Reduce the priority of this result by one, to give it a slight
+ // advantage over other results whose names don't match so closely.
+ if (Results.size() &&
+ Results.data()[Results.size() - 1].Kind
+ == CodeCompletionResult::RK_Declaration &&
+ Results.data()[Results.size() - 1].Declaration == Ivar)
+ Results.data()[Results.size() - 1].Priority--;
+ }
}
}
if (!SawSimilarlyNamedIvar) {
// Create ivar result _propName, that the user can use to synthesize
- // an ivar of the appropriate type.
- QualType T = Context.getObjCIdType();
-
- if (Class) {
- if (ObjCPropertyDecl *Property
- = Class->FindPropertyDeclaration(PropertyName))
- T = Property->getType().getNonReferenceType().getUnqualifiedType();
- }
-
- unsigned Priority = CCP_MemberDeclaration;
+ // an ivar of the appropriate type.
+ unsigned Priority = CCP_MemberDeclaration + 1;
typedef CodeCompletionResult Result;
CodeCompletionAllocator &Allocator = Results.getAllocator();
CodeCompletionBuilder Builder(Allocator, Priority,CXAvailability_Available);
- Builder.AddResultTypeChunk(GetCompletionTypeString(T, Context, Allocator));
+ Builder.AddResultTypeChunk(GetCompletionTypeString(PropertyType, Context,
+ Allocator));
Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix));
Results.AddResult(Result(Builder.TakeString(), Priority,
CXCursor_ObjCIvarDecl));
OpenPOWER on IntegriCloud