diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-02-26 11:01:50 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-02-26 11:01:50 +0000 |
commit | ff2a99752f67a73e325b3e57cdafeb342b4c92ac (patch) | |
tree | c05eb1e1adc6e34d4e8d0e5564db1bffc3c51c63 /clang/lib/Sema/SemaCodeComplete.cpp | |
parent | 2ccc120d191ff1829c9c53dc367d086eaf7311db (diff) | |
download | llvm-ff2a99752f67a73e325b3e57cdafeb342b4c92ac.zip llvm-ff2a99752f67a73e325b3e57cdafeb342b4c92ac.tar.gz llvm-ff2a99752f67a73e325b3e57cdafeb342b4c92ac.tar.bz2 |
[CodeComplete] Propagate preferred type for function arguments in more cases
Summary:
See the added test for some new cases.
This change also removes special code completion calls inside the
ParseExpressionList function now that we properly propagate expected
type to the function responsible for parsing elements of the expression list
(ParseAssignmentExpression).
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: xbolva00, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D58541
llvm-svn: 354864
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index cebf97a..a727bad9 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -350,13 +350,16 @@ public: void PreferredTypeBuilder::enterReturn(Sema &S, SourceLocation Tok) { if (isa<BlockDecl>(S.CurContext)) { if (sema::BlockScopeInfo *BSI = S.getCurBlock()) { + ComputeType = nullptr; Type = BSI->ReturnType; ExpectedLoc = Tok; } } else if (const auto *Function = dyn_cast<FunctionDecl>(S.CurContext)) { + ComputeType = nullptr; Type = Function->getReturnType(); ExpectedLoc = Tok; } else if (const auto *Method = dyn_cast<ObjCMethodDecl>(S.CurContext)) { + ComputeType = nullptr; Type = Method->getReturnType(); ExpectedLoc = Tok; } @@ -364,10 +367,18 @@ void PreferredTypeBuilder::enterReturn(Sema &S, SourceLocation Tok) { void PreferredTypeBuilder::enterVariableInit(SourceLocation Tok, Decl *D) { auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D); + ComputeType = nullptr; Type = VD ? VD->getType() : QualType(); ExpectedLoc = Tok; } +void PreferredTypeBuilder::enterFunctionArgument( + SourceLocation Tok, llvm::function_ref<QualType()> ComputeType) { + this->ComputeType = ComputeType; + Type = QualType(); + ExpectedLoc = Tok; +} + void PreferredTypeBuilder::enterParenExpr(SourceLocation Tok, SourceLocation LParLoc) { // expected type for parenthesized expression does not change. @@ -480,13 +491,14 @@ static QualType getPreferredTypeOfUnaryArg(Sema &S, QualType ContextType, case tok::kw___imag: return QualType(); default: - assert(false && "unhnalded unary op"); + assert(false && "unhandled unary op"); return QualType(); } } void PreferredTypeBuilder::enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op) { + ComputeType = nullptr; Type = getPreferredTypeOfBinaryRHS(S, LHS, Op); ExpectedLoc = Tok; } @@ -495,30 +507,38 @@ void PreferredTypeBuilder::enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base) { if (!Base) return; - Type = this->get(Base->getBeginLoc()); + // Do we have expected type for Base? + if (ExpectedLoc != Base->getBeginLoc()) + return; + // Keep the expected type, only update the location. ExpectedLoc = Tok; + return; } void PreferredTypeBuilder::enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, SourceLocation OpLoc) { + ComputeType = nullptr; Type = getPreferredTypeOfUnaryArg(S, this->get(OpLoc), OpKind); ExpectedLoc = Tok; } void PreferredTypeBuilder::enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS) { + ComputeType = nullptr; Type = S.getASTContext().IntTy; ExpectedLoc = Tok; } void PreferredTypeBuilder::enterTypeCast(SourceLocation Tok, QualType CastType) { + ComputeType = nullptr; Type = !CastType.isNull() ? CastType.getCanonicalType() : QualType(); ExpectedLoc = Tok; } void PreferredTypeBuilder::enterCondition(Sema &S, SourceLocation Tok) { + ComputeType = nullptr; Type = S.getASTContext().BoolTy; ExpectedLoc = Tok; } |