|
@@ -350,13 +350,16 @@ public:
|
|
void PreferredTypeBuilder::enterReturn(Sema &S, SourceLocation Tok) {
|
|
void PreferredTypeBuilder::enterReturn(Sema &S, SourceLocation Tok) {
|
|
if (isa<BlockDecl>(S.CurContext)) {
|
|
if (isa<BlockDecl>(S.CurContext)) {
|
|
if (sema::BlockScopeInfo *BSI = S.getCurBlock()) {
|
|
if (sema::BlockScopeInfo *BSI = S.getCurBlock()) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = BSI->ReturnType;
|
|
Type = BSI->ReturnType;
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
} else if (const auto *Function = dyn_cast<FunctionDecl>(S.CurContext)) {
|
|
} else if (const auto *Function = dyn_cast<FunctionDecl>(S.CurContext)) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = Function->getReturnType();
|
|
Type = Function->getReturnType();
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
} else if (const auto *Method = dyn_cast<ObjCMethodDecl>(S.CurContext)) {
|
|
} else if (const auto *Method = dyn_cast<ObjCMethodDecl>(S.CurContext)) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = Method->getReturnType();
|
|
Type = Method->getReturnType();
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
@@ -364,10 +367,18 @@ void PreferredTypeBuilder::enterReturn(Sema &S, SourceLocation Tok) {
|
|
|
|
|
|
void PreferredTypeBuilder::enterVariableInit(SourceLocation Tok, Decl *D) {
|
|
void PreferredTypeBuilder::enterVariableInit(SourceLocation Tok, Decl *D) {
|
|
auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
|
|
auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = VD ? VD->getType() : QualType();
|
|
Type = VD ? VD->getType() : QualType();
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void PreferredTypeBuilder::enterFunctionArgument(
|
|
|
|
+ SourceLocation Tok, llvm::function_ref<QualType()> ComputeType) {
|
|
|
|
+ this->ComputeType = ComputeType;
|
|
|
|
+ Type = QualType();
|
|
|
|
+ ExpectedLoc = Tok;
|
|
|
|
+}
|
|
|
|
+
|
|
void PreferredTypeBuilder::enterParenExpr(SourceLocation Tok,
|
|
void PreferredTypeBuilder::enterParenExpr(SourceLocation Tok,
|
|
SourceLocation LParLoc) {
|
|
SourceLocation LParLoc) {
|
|
// expected type for parenthesized expression does not change.
|
|
// expected type for parenthesized expression does not change.
|
|
@@ -480,13 +491,14 @@ static QualType getPreferredTypeOfUnaryArg(Sema &S, QualType ContextType,
|
|
case tok::kw___imag:
|
|
case tok::kw___imag:
|
|
return QualType();
|
|
return QualType();
|
|
default:
|
|
default:
|
|
- assert(false && "unhnalded unary op");
|
|
|
|
|
|
+ assert(false && "unhandled unary op");
|
|
return QualType();
|
|
return QualType();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void PreferredTypeBuilder::enterBinary(Sema &S, SourceLocation Tok, Expr *LHS,
|
|
void PreferredTypeBuilder::enterBinary(Sema &S, SourceLocation Tok, Expr *LHS,
|
|
tok::TokenKind Op) {
|
|
tok::TokenKind Op) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = getPreferredTypeOfBinaryRHS(S, LHS, Op);
|
|
Type = getPreferredTypeOfBinaryRHS(S, LHS, Op);
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
@@ -495,30 +507,38 @@ void PreferredTypeBuilder::enterMemAccess(Sema &S, SourceLocation Tok,
|
|
Expr *Base) {
|
|
Expr *Base) {
|
|
if (!Base)
|
|
if (!Base)
|
|
return;
|
|
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;
|
|
ExpectedLoc = Tok;
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
void PreferredTypeBuilder::enterUnary(Sema &S, SourceLocation Tok,
|
|
void PreferredTypeBuilder::enterUnary(Sema &S, SourceLocation Tok,
|
|
tok::TokenKind OpKind,
|
|
tok::TokenKind OpKind,
|
|
SourceLocation OpLoc) {
|
|
SourceLocation OpLoc) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = getPreferredTypeOfUnaryArg(S, this->get(OpLoc), OpKind);
|
|
Type = getPreferredTypeOfUnaryArg(S, this->get(OpLoc), OpKind);
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
|
|
|
|
void PreferredTypeBuilder::enterSubscript(Sema &S, SourceLocation Tok,
|
|
void PreferredTypeBuilder::enterSubscript(Sema &S, SourceLocation Tok,
|
|
Expr *LHS) {
|
|
Expr *LHS) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = S.getASTContext().IntTy;
|
|
Type = S.getASTContext().IntTy;
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
|
|
|
|
void PreferredTypeBuilder::enterTypeCast(SourceLocation Tok,
|
|
void PreferredTypeBuilder::enterTypeCast(SourceLocation Tok,
|
|
QualType CastType) {
|
|
QualType CastType) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = !CastType.isNull() ? CastType.getCanonicalType() : QualType();
|
|
Type = !CastType.isNull() ? CastType.getCanonicalType() : QualType();
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|
|
|
|
|
|
void PreferredTypeBuilder::enterCondition(Sema &S, SourceLocation Tok) {
|
|
void PreferredTypeBuilder::enterCondition(Sema &S, SourceLocation Tok) {
|
|
|
|
+ ComputeType = nullptr;
|
|
Type = S.getASTContext().BoolTy;
|
|
Type = S.getASTContext().BoolTy;
|
|
ExpectedLoc = Tok;
|
|
ExpectedLoc = Tok;
|
|
}
|
|
}
|