Skip to content

Commit a76e68c

Browse files
committed
[CodeComplete] Member completion for concept-constrained types.
Summary: The basic idea is to walk through the concept definition, looking for t.foo() where t has the constrained type. In this patch: - nested types are recognized and offered after :: - variable/function members are recognized and offered after the correct dot/arrow/colon trigger - member functions are recognized (anything directly called). parameter types are presumed to be the argument types. parameters are unnamed. - result types are available when a requirement has a type constraint. These are printed as constraints, except same_as<T> which prints as T. Not in this patch: - support for merging/overloading when two locations describe the same member. The last one wins, for any given name. This is probably important... - support for nested template members (T::x<int>) - support for completing members of (instantiations of) template template parameters Reviewers: nridge, saar.raz Subscribers: mgrang, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73649
1 parent 41c135d commit a76e68c

File tree

4 files changed

+490
-37
lines changed

4 files changed

+490
-37
lines changed

clang/include/clang/Sema/Scope.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ class Scope {
320320

321321
/// isDeclScope - Return true if this is the scope that the specified decl is
322322
/// declared in.
323-
bool isDeclScope(Decl *D) {
324-
return DeclsInScope.count(D) != 0;
325-
}
323+
bool isDeclScope(const Decl *D) const { return DeclsInScope.count(D) != 0; }
326324

327325
DeclContext *getEntity() const { return Entity; }
328326
void setEntity(DeclContext *E) { Entity = E; }

clang/lib/Sema/CodeCompleteConsumer.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -570,29 +570,10 @@ void PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(
570570
if (const char *BriefComment = CCS->getBriefComment())
571571
OS << " : " << BriefComment;
572572
}
573-
for (const FixItHint &FixIt : Results[I].FixIts) {
574-
const SourceLocation BLoc = FixIt.RemoveRange.getBegin();
575-
const SourceLocation ELoc = FixIt.RemoveRange.getEnd();
576-
577-
SourceManager &SM = SemaRef.SourceMgr;
578-
std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(BLoc);
579-
std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(ELoc);
580-
// Adjust for token ranges.
581-
if (FixIt.RemoveRange.isTokenRange())
582-
EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, SemaRef.LangOpts);
583-
584-
OS << " (requires fix-it:"
585-
<< " {" << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
586-
<< SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
587-
<< SM.getLineNumber(EInfo.first, EInfo.second) << ':'
588-
<< SM.getColumnNumber(EInfo.first, EInfo.second) << "}"
589-
<< " to \"" << FixIt.CodeToInsert << "\")";
590-
}
591-
OS << '\n';
592573
break;
593574

594575
case CodeCompletionResult::RK_Keyword:
595-
OS << Results[I].Keyword << '\n';
576+
OS << Results[I].Keyword;
596577
break;
597578

598579
case CodeCompletionResult::RK_Macro:
@@ -602,13 +583,31 @@ void PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(
602583
includeBriefComments())) {
603584
OS << " : " << CCS->getAsString();
604585
}
605-
OS << '\n';
606586
break;
607587

608588
case CodeCompletionResult::RK_Pattern:
609-
OS << "Pattern : " << Results[I].Pattern->getAsString() << '\n';
589+
OS << "Pattern : " << Results[I].Pattern->getAsString();
610590
break;
611591
}
592+
for (const FixItHint &FixIt : Results[I].FixIts) {
593+
const SourceLocation BLoc = FixIt.RemoveRange.getBegin();
594+
const SourceLocation ELoc = FixIt.RemoveRange.getEnd();
595+
596+
SourceManager &SM = SemaRef.SourceMgr;
597+
std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(BLoc);
598+
std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(ELoc);
599+
// Adjust for token ranges.
600+
if (FixIt.RemoveRange.isTokenRange())
601+
EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, SemaRef.LangOpts);
602+
603+
OS << " (requires fix-it:"
604+
<< " {" << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
605+
<< SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
606+
<< SM.getLineNumber(EInfo.first, EInfo.second) << ':'
607+
<< SM.getColumnNumber(EInfo.first, EInfo.second) << "}"
608+
<< " to \"" << FixIt.CodeToInsert << "\")";
609+
}
610+
OS << '\n';
612611
}
613612
}
614613

0 commit comments

Comments
 (0)