diff options
author | lh123 <1585086582@qq.com> | 2020-06-25 20:04:18 +0800 |
---|---|---|
committer | lh123 <1585086582@qq.com> | 2020-07-01 12:51:25 +0800 |
commit | 83fae3f762699655a4329fe3cf6fd3e2a2617559 (patch) | |
tree | dcdfb1153d7f331095aeabb42356f1ae080bdde0 /clang/lib/Sema/SemaCodeComplete.cpp | |
parent | ca134e4c525babf0c414c78fb53d648fbee364d8 (diff) | |
download | llvm-83fae3f762699655a4329fe3cf6fd3e2a2617559.zip llvm-83fae3f762699655a4329fe3cf6fd3e2a2617559.tar.gz llvm-83fae3f762699655a4329fe3cf6fd3e2a2617559.tar.bz2 |
[CodeComplete] Add code completion after function equals
Summary:
Provide `default` and `delete` completion after the function equals.
Reviewers: kadircet, sammccall
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82548
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 26d127e..0a8a270 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -24,11 +24,13 @@ #include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/Type.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/OperatorKinds.h" #include "clang/Basic/Specifiers.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/CodeCompleteConsumer.h" +#include "clang/Sema/DeclSpec.h" #include "clang/Sema/Designator.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Overload.h" @@ -6266,6 +6268,53 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, Results.data(), Results.size()); } +void Sema::CodeCompleteAfterFunctionEquals(Declarator &D) { + if (!LangOpts.CPlusPlus11) + return; + ResultBuilder Results(*this, CodeCompleter->getAllocator(), + CodeCompleter->getCodeCompletionTUInfo(), + CodeCompletionContext::CCC_Other); + auto ShouldAddDefault = [&D, this]() { + if (!D.isFunctionDeclarator()) + return false; + auto &Id = D.getName(); + if (Id.getKind() == UnqualifiedIdKind::IK_DestructorName) + return true; + // FIXME(liuhui): Ideally, we should check the constructor parameter list to + // verify that it is the default, copy or move constructor? + if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName && + D.getFunctionTypeInfo().NumParams <= 1) + return true; + if (Id.getKind() == UnqualifiedIdKind::IK_OperatorFunctionId) { + auto Op = Id.OperatorFunctionId.Operator; + // FIXME(liuhui): Ideally, we should check the function parameter list to + // verify that it is the copy or move assignment? + if (Op == OverloadedOperatorKind::OO_Equal) + return true; + if (LangOpts.CPlusPlus20 && + (Op == OverloadedOperatorKind::OO_EqualEqual || + Op == OverloadedOperatorKind::OO_ExclaimEqual || + Op == OverloadedOperatorKind::OO_Less || + Op == OverloadedOperatorKind::OO_LessEqual || + Op == OverloadedOperatorKind::OO_Greater || + Op == OverloadedOperatorKind::OO_GreaterEqual || + Op == OverloadedOperatorKind::OO_Spaceship)) + return true; + } + return false; + }; + + Results.EnterNewScope(); + if (ShouldAddDefault()) + Results.AddResult("default"); + // FIXME(liuhui): Ideally, we should only provide `delete` completion for the + // first function declaration. + Results.AddResult("delete"); + Results.ExitScope(); + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); +} + /// Macro that optionally prepends an "@" to the string literal passed in via /// Keyword, depending on whether NeedAt is true or false. #define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword) |