================ @@ -56,26 +63,146 @@ class ReplCompletionConsumer : public CodeCompleteConsumer { std::shared_ptr<GlobalCodeCompletionAllocator> CCAllocator; CodeCompletionTUInfo CCTUInfo; std::vector<std::string> &Results; + ReplCodeCompleter &CC; +}; + +// The class CompletionContextHandler contains four interfaces, each of +// which handles one type of completion result. +// Its substract classes are used to create concrete handlers based on +// CodeCompletionContext. +class CompletionContextHandler { +protected: + CodeCompletionContext CCC; + std::vector<std::string> &Results; + +private: + Sema &S; + +public: + CompletionContextHandler(Sema &S, CodeCompletionContext CCC, + std::vector<std::string> &Results) + : CCC(CCC), Results(Results), S(S) {} + + // converts a Declaration completion result to a completion string, and then + // stores it in Results. + virtual void handleDeclaration(const CodeCompletionResult &Result) { + auto PreferredType = CCC.getPreferredType(); + if (PreferredType.isNull()) { + Results.push_back(Result.Declaration->getName().str()); + return; + } + + if (auto *VD = dyn_cast<VarDecl>(Result.Declaration)) { + auto ArgumentType = VD->getType(); + if (PreferredType->isReferenceType()) { + QualType RT = PreferredType->castAs<ReferenceType>()->getPointeeType(); + Sema::ReferenceConversions RefConv; + Sema::ReferenceCompareResult RefRelationship = + S.CompareReferenceRelationship(SourceLocation(), RT, ArgumentType, + &RefConv); + switch (RefRelationship) { + case Sema::Ref_Compatible: + case Sema::Ref_Related: + Results.push_back(VD->getName().str()); + break; + case Sema::Ref_Incompatible: + break; + } + } else if (S.Context.hasSameType(ArgumentType, PreferredType)) { + Results.push_back(VD->getName().str()); + } + } + } + + // converts a Keyword completion result to a completion string, and then + // stores it in Results. ---------------- vgvassilev wrote:
```suggestion /// Converts a Keyword completion result to a completion string, and then /// stores it in Results. ``` https://github.com/llvm/llvm-project/pull/67349 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits