void MaybeAddConstructorResults(Result R);
public:
- explicit ResultBuilder(Sema &SemaRef, LookupFilter Filter = 0)
+ explicit ResultBuilder(Sema &SemaRef,
+ const CodeCompletionContext &CompletionContext,
+ LookupFilter Filter = 0)
: SemaRef(SemaRef), Filter(Filter), AllowNestedNameSpecifiers(false),
HasObjectTypeQualifiers(false),
- CompletionContext(CodeCompletionContext::CCC_Other) { }
+ CompletionContext(CompletionContext) { }
/// \brief Whether we should include code patterns in the completion
/// results.
return CompletionContext;
}
- /// \brief Set the code-completion context.
- void setCompletionContext(const CodeCompletionContext &CompletionContext) {
- this->CompletionContext = CompletionContext;
- }
-
/// \brief Specify whether nested-name-specifiers are allowed.
void allowNestedNameSpecifiers(bool Allow = true) {
AllowNestedNameSpecifiers = Allow;
bool IsObjCIvar(NamedDecl *ND) const;
bool IsObjCMessageReceiver(NamedDecl *ND) const;
bool IsObjCCollection(NamedDecl *ND) const;
+ bool IsImpossibleToSatisfy(NamedDecl *ND) const;
//@}
};
}
if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
((isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) &&
Filter != &ResultBuilder::IsNamespace &&
- Filter != &ResultBuilder::IsNamespaceOrAlias))
+ Filter != &ResultBuilder::IsNamespaceOrAlias &&
+ Filter != 0))
AsNestedNameSpecifier = true;
// Filter out any unwanted results.
(SemaRef.getLangOptions().CPlusPlus && T->isRecordType());
}
+bool ResultBuilder::IsImpossibleToSatisfy(NamedDecl *ND) const {
+ return false;
+}
+
/// \rief Determines whether the given declaration is an Objective-C
/// instance variable.
bool ResultBuilder::IsObjCIvar(NamedDecl *ND) const {
case Sema::PCC_Template:
case Sema::PCC_MemberTemplate:
+ if (S.CurContext->isFileContext())
+ return CodeCompletionContext::CCC_TopLevel;
+ else if (S.CurContext->isRecord())
+ return CodeCompletionContext::CCC_ClassStructUnion;
+ else
+ return CodeCompletionContext::CCC_Other;
+
case Sema::PCC_RecoveryInFunction:
- return CodeCompletionContext::CCC_Other;
+ return CodeCompletionContext::CCC_Recovery;
case Sema::PCC_Expression:
case Sema::PCC_ForInit:
void Sema::CodeCompleteOrdinaryName(Scope *S,
ParserCompletionContext CompletionContext) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
- Results.setCompletionContext(mapCodeCompletionContext(*this,
- CompletionContext));
+ ResultBuilder Results(*this,
+ mapCodeCompletionContext(*this, CompletionContext));
Results.EnterNewScope();
// Determine how to filter results, e.g., so that the names of
bool AllowNonIdentifiers,
bool AllowNestedNameSpecifiers) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this,
+ AllowNestedNameSpecifiers
+ ? CodeCompletionContext::CCC_PotentiallyQualifiedName
+ : CodeCompletionContext::CCC_Name);
Results.EnterNewScope();
// Type qualifiers can come after names.
// Add nested-name-specifiers.
if (AllowNestedNameSpecifiers) {
Results.allowNestedNameSpecifiers();
+ Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
CodeCompletionDeclConsumer Consumer(Results, CurContext);
LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
CodeCompleter->includeGlobals());
+ Results.setFilter(0);
}
}
Results.ExitScope();
// Note that we intentionally suppress macro results here, since we do not
// encourage using macros to produce the names of entities.
- HandleCodeCompleteResults(this, CodeCompleter,
- AllowNestedNameSpecifiers
- ? CodeCompletionContext::CCC_PotentiallyQualifiedName
- : CodeCompletionContext::CCC_Name,
+ HandleCodeCompleteResults(this, CodeCompleter,
+ Results.getCompletionContext(),
Results.data(), Results.size());
}
void Sema::CodeCompleteExpression(Scope *S,
const CodeCompleteExpressionData &Data) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
-
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Expression);
if (Data.ObjCCollection)
Results.setFilter(&ResultBuilder::IsObjCCollection);
else if (Data.IntegralConstantExpression)
return;
}
- ResultBuilder Results(*this, &ResultBuilder::IsMember);
+ ResultBuilder Results(*this,
+ CodeCompletionContext(CodeCompletionContext::CCC_MemberAccess,
+ BaseType),
+ &ResultBuilder::IsMember);
Results.EnterNewScope();
if (const RecordType *Record = BaseType->getAs<RecordType>()) {
// Indicate that we are performing a member access, and the cv-qualifiers
// Hand off the results found for code completion.
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext(CodeCompletionContext::CCC_MemberAccess,
- BaseType),
+ Results.getCompletionContext(),
Results.data(),Results.size());
}
return;
}
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, ContextKind);
CodeCompletionDeclConsumer Consumer(Results, CurContext);
// First pass: look for tags.
LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer);
}
- HandleCodeCompleteResults(this, CodeCompleter, ContextKind,
+ HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(),Results.size());
}
void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_TypeQualifiers);
Results.EnterNewScope();
if (!(DS.getTypeQualifiers() & DeclSpec::TQ_const))
Results.AddResult("const");
Results.AddResult("restrict");
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_TypeQualifiers,
+ Results.getCompletionContext(),
Results.data(), Results.size());
}
}
// Add any enumerators that have not yet been mentioned.
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Expression);
Results.EnterNewScope();
for (EnumDecl::enumerator_iterator E = Enum->enumerator_begin(),
EEnd = Enum->enumerator_end();
if (!isDependentScopeSpecifier(SS) && RequireCompleteDeclContext(SS, Ctx))
return;
- ResultBuilder Results(*this);
-
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Name);
Results.EnterNewScope();
+
// The "template" keyword can follow "::" in the grammar, but only
// put it into the grammar if the nested-name-specifier is dependent.
NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep();
if (!CodeCompleter)
return;
- ResultBuilder Results(*this, &ResultBuilder::IsNestedNameSpecifier);
+ ResultBuilder Results(*this,
+ CodeCompletionContext::CCC_PotentiallyQualifiedName,
+ &ResultBuilder::IsNestedNameSpecifier);
Results.EnterNewScope();
// If we aren't in class scope, we could see the "namespace" keyword.
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Other,
+ CodeCompletionContext::CCC_PotentiallyQualifiedName,
Results.data(),Results.size());
}
// After "using namespace", we expect to see a namespace name or namespace
// alias.
- ResultBuilder Results(*this, &ResultBuilder::IsNamespaceOrAlias);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Namespace,
+ &ResultBuilder::IsNamespaceOrAlias);
Results.EnterNewScope();
CodeCompletionDeclConsumer Consumer(Results, CurContext);
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
if (!CodeCompleter)
return;
- ResultBuilder Results(*this, &ResultBuilder::IsNamespace);
DeclContext *Ctx = (DeclContext *)S->getEntity();
if (!S->getParent())
Ctx = Context.getTranslationUnitDecl();
- if (Ctx && Ctx->isFileContext()) {
+ bool SuppressedGlobalResults
+ = Ctx && !CodeCompleter->includeGlobals() && isa<TranslationUnitDecl>(Ctx);
+
+ ResultBuilder Results(*this,
+ SuppressedGlobalResults
+ ? CodeCompletionContext::CCC_Namespace
+ : CodeCompletionContext::CCC_Other,
+ &ResultBuilder::IsNamespace);
+
+ if (Ctx && Ctx->isFileContext() && !SuppressedGlobalResults) {
// We only want to see those namespaces that have already been defined
// within this scope, because its likely that the user is creating an
// extended namespace declaration. Keep track of the most recent
}
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Other,
+ Results.getCompletionContext(),
Results.data(),Results.size());
}
return;
// After "namespace", we expect to see a namespace or alias.
- ResultBuilder Results(*this, &ResultBuilder::IsNamespaceOrAlias);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Namespace,
+ &ResultBuilder::IsNamespaceOrAlias);
CodeCompletionDeclConsumer Consumer(Results, CurContext);
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
CodeCompleter->includeGlobals());
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Namespace,
+ Results.getCompletionContext(),
Results.data(),Results.size());
}
return;
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this, &ResultBuilder::IsType);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Type,
+ &ResultBuilder::IsType);
Results.EnterNewScope();
// Add the names of overloadable operators.
if (!Constructor)
return;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this,
+ CodeCompletionContext::CCC_PotentiallyQualifiedName);
Results.EnterNewScope();
// Fill in any already-initialized fields or base classes.
}
Results.ExitScope();
- HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Name,
+ HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(), Results.size());
}
void Sema::CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
bool InInterface) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
if (ObjCImpDecl)
AddObjCImplementationResults(getLangOptions(), Results, false);
}
void Sema::CodeCompleteObjCAtVisibility(Scope *S) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
AddObjCVisibilityResults(getLangOptions(), Results, false);
Results.ExitScope();
}
void Sema::CodeCompleteObjCAtStatement(Scope *S) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
AddObjCStatementResults(Results, false);
AddObjCExpressionResults(Results, false);
}
void Sema::CodeCompleteObjCAtExpression(Scope *S) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
AddObjCExpressionResults(Results, false);
Results.ExitScope();
unsigned Attributes = ODS.getPropertyAttributes();
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_readonly))
Results.AddResult(CodeCompletionResult("readonly"));
}
// Find all of the potential getters.
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// FIXME: We need to do this because Objective-C methods don't get
}
// Find all of the potential getters.
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// FIXME: We need to do this because Objective-C methods don't get
void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Type);
Results.EnterNewScope();
// Add context-sensitive, Objective-C parameter-passing keywords.
void Sema::CodeCompleteObjCMessageReceiver(Scope *S) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCMessageReceiver,
+ &ResultBuilder::IsObjCMessageReceiver);
- // Find anything that looks like it could be a message receiver.
- Results.setFilter(&ResultBuilder::IsObjCMessageReceiver);
- Results.setCompletionContext(CodeCompletionContext::CCC_ObjCMessageReceiver);
-
CodeCompletionDeclConsumer Consumer(Results, CurContext);
Results.EnterNewScope();
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
unsigned NumSelIdents,
bool AtArgumentExpression,
bool IsSuper) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
AddClassMessageCompletions(*this, S, Receiver, SelIdents, NumSelIdents,
AtArgumentExpression, IsSuper, Results);
QualType ReceiverType = RecExpr? RecExpr->getType() : Context.getObjCIdType();
// Build the set of methods we can see.
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// If this is a send-to-super, try to add the special "super" send
}
}
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_SelectorName);
Results.EnterNewScope();
for (GlobalMethodPool::iterator M = MethodPool.begin(),
MEnd = MethodPool.end();
void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
unsigned NumProtocols) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
Results.EnterNewScope();
// Tell the result set to ignore all of the protocols we have
}
void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
Results.EnterNewScope();
// Add all protocols.
}
void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// Add all classes.
false, Results);
Results.ExitScope();
+ // FIXME: Add a special context for this, use cached global completion
+ // results.
HandleCodeCompleteResults(this, CodeCompleter,
CodeCompletionContext::CCC_Other,
Results.data(),Results.size());
void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
SourceLocation ClassNameLoc) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// Make sure that we ignore the class we're currently defining.
false, Results);
Results.ExitScope();
+ // FIXME: Add a special context for this, use cached global completion
+ // results.
HandleCodeCompleteResults(this, CodeCompleter,
CodeCompletionContext::CCC_Other,
Results.data(),Results.size());
}
void Sema::CodeCompleteObjCImplementationDecl(Scope *S) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
// Add all unimplemented classes.
true, Results);
Results.ExitScope();
+ // FIXME: Add a special context for this, use cached global completion
+ // results.
HandleCodeCompleteResults(this, CodeCompleter,
CodeCompletionContext::CCC_Other,
Results.data(),Results.size());
SourceLocation ClassNameLoc) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
// Ignore any categories we find that have already been implemented by this
// interface.
if (!Class)
return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc);
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
// Add all of the categories that have have corresponding interface
// declarations in this class and any of its superclasses, except for
void Sema::CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
// Figure out where this @synthesize lives.
ObjCContainerDecl *Container
IdentifierInfo *PropertyName,
Decl *ObjCImpDecl) {
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
// Figure out where this @synthesize lives.
ObjCContainerDecl *Container
// Add declarations or definitions for each of the known methods.
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
PrintingPolicy Policy(Context.PrintingPolicy);
Policy.AnonymousTagLocations = false;
// Build the set of methods we can see.
typedef CodeCompletionResult Result;
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
if (ReturnTy)
Results.setPreferredType(GetTypeFromParser(ReturnTy).getNonReferenceType());
}
void Sema::CodeCompletePreprocessorDirective(bool InConditional) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this,
+ CodeCompletionContext::CCC_PreprocessorDirective);
Results.EnterNewScope();
// #if <condition>
}
void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this,
+ IsDefinition? CodeCompletionContext::CCC_MacroName
+ : CodeCompletionContext::CCC_MacroNameUse);
if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) {
// Add just the names of macros, not their arguments.
Results.EnterNewScope();
// FIXME: Can we detect when the user just wrote an include guard above?
}
- HandleCodeCompleteResults(this, CodeCompleter,
- IsDefinition? CodeCompletionContext::CCC_MacroName
- : CodeCompletionContext::CCC_MacroNameUse,
+ HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
Results.data(), Results.size());
}
void Sema::CodeCompletePreprocessorExpression() {
- ResultBuilder Results(*this);
+ ResultBuilder Results(*this,
+ CodeCompletionContext::CCC_PreprocessorExpression);
if (!CodeCompleter || CodeCompleter->includeMacros())
AddMacroResults(PP, Results);
void Sema::GatherGlobalCodeCompletions(
llvm::SmallVectorImpl<CodeCompletionResult> &Results) {
- ResultBuilder Builder(*this);
+ ResultBuilder Builder(*this, CodeCompletionContext::CCC_Recovery);
if (!CodeCompleter || CodeCompleter->includeGlobals()) {
CodeCompletionDeclConsumer Consumer(Builder,