From 6514d87c1aa5b544d02c3822fe41217e2051673d Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 8 Jun 2009 15:36:55 +0000 Subject: Import Clang r73070. --- lib/Sema/Sema.h | 4 ++++ lib/Sema/SemaExpr.cpp | 10 ++++----- lib/Sema/SemaExprObjC.cpp | 37 +++++++++++++++++++++----------- lib/Sema/SemaTemplateDeduction.cpp | 31 ++++++++++++++++++++++++++ lib/Sema/SemaTemplateInstantiateExpr.cpp | 25 ++++++++++++--------- 5 files changed, 79 insertions(+), 28 deletions(-) (limited to 'lib/Sema') diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index d3bfef6..c558293 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1696,6 +1696,10 @@ public: virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **Strings, unsigned NumStrings); + + Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, + QualType EncodedType, + SourceLocation RParenLoc); virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation EncodeLoc, SourceLocation LParenLoc, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ee5132a..da32d4e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3003,8 +3003,8 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, compositeType = Context.getObjCIdType(); } else if (LHSBPT || RHSBPT) { if (!sameKind - || !Context.typesAreBlockCompatible(lhptee.getUnqualifiedType(), - rhptee.getUnqualifiedType())) + || !Context.typesAreCompatible(lhptee.getUnqualifiedType(), + rhptee.getUnqualifiedType())) Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange(); return QualType(); @@ -3218,7 +3218,7 @@ Sema::CheckBlockPointerTypesForAssignment(QualType lhsType, if (lhptee.getCVRQualifiers() != rhptee.getCVRQualifiers()) ConvTy = CompatiblePointerDiscardsQualifiers; - if (!Context.typesAreBlockCompatible(lhptee, rhptee)) + if (!Context.typesAreCompatible(lhptee, rhptee)) return IncompatibleBlockPointer; return ConvTy; } @@ -3978,7 +3978,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, QualType rpointee = rType->getAsBlockPointerType()->getPointeeType(); if (!LHSIsNull && !RHSIsNull && - !Context.typesAreBlockCompatible(lpointee, rpointee)) { + !Context.typesAreCompatible(lpointee, rpointee)) { Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); } @@ -5220,7 +5220,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, QualType BlockTy; if (!BSI->hasPrototype) - BlockTy = Context.getFunctionNoProtoType(RetTy); + BlockTy = Context.getFunctionType(RetTy, 0, 0, false, 0); else BlockTy = Context.getFunctionType(RetTy, ArgTypes.data(), ArgTypes.size(), BSI->isVariadic, 0); diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index eabc87d..b6cf9d8 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -92,6 +92,29 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } +Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, + QualType EncodedType, + SourceLocation RParenLoc) { + QualType StrTy; + if (EncodedType->isDependentType()) + StrTy = Context.DependentTy; + else { + std::string Str; + Context.getObjCEncodingForType(EncodedType, Str); + + // The type of @encode is the same as the type of the corresponding string, + // which is an array type. + StrTy = Context.CharTy; + // A C++ string literal has a const-qualified element type (C++ 2.13.4p1). + if (getLangOptions().CPlusPlus) + StrTy.addConst(); + StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1), + ArrayType::Normal, 0); + } + + return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc); +} + Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation EncodeLoc, SourceLocation LParenLoc, @@ -99,19 +122,7 @@ Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation RParenLoc) { QualType EncodedType = QualType::getFromOpaquePtr(ty); - std::string Str; - Context.getObjCEncodingForType(EncodedType, Str); - - // The type of @encode is the same as the type of the corresponding string, - // which is an array type. - QualType StrTy = Context.CharTy; - // A C++ string literal has a const-qualified element type (C++ 2.13.4p1). - if (getLangOptions().CPlusPlus) - StrTy.addConst(); - StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1), - ArrayType::Normal, 0); - - return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc); + return BuildObjCEncodeExpression(AtLoc, EncodedType, RParenLoc); } Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel, diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 812b319..db7e622 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -265,6 +265,37 @@ static bool DeduceTemplateArguments(ASTContext &Context, QualType Param, return false; } + case Type::FunctionProto: { + const FunctionProtoType *FunctionProtoArg = + dyn_cast(Arg); + if (!FunctionProtoArg) + return false; + + const FunctionProtoType *FunctionProtoParam = + cast(Param); + + // Check return types. + if (!DeduceTemplateArguments(Context, + FunctionProtoParam->getResultType(), + FunctionProtoArg->getResultType(), + Deduced)) + return false; + + if (FunctionProtoParam->getNumArgs() != FunctionProtoArg->getNumArgs()) + return false; + + for (unsigned I = 0, N = FunctionProtoParam->getNumArgs(); I != N; ++I) { + // Check argument types. + if (!DeduceTemplateArguments(Context, + FunctionProtoParam->getArgType(I), + FunctionProtoArg->getArgType(I), + Deduced)) + return false; + } + + return true; + } + default: break; } diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 5ba42f2..fa5fdee 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -1216,15 +1216,22 @@ TemplateExprInstantiator::VisitCXXUnresolvedMemberExpr( // Objective-C Expressions //---------------------------------------------------------------------------- Sema::OwningExprResult -TemplateExprInstantiator::VisitObjCStringLiteral(ObjCStringLiteral *E) { - assert(false && "FIXME: Template instantiations for ObjC expressions"); - return SemaRef.ExprError(); +TemplateExprInstantiator::VisitObjCStringLiteral(ObjCStringLiteral *E) { + return SemaRef.Owned(E->Clone(SemaRef.Context)); } Sema::OwningExprResult -TemplateExprInstantiator::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { - assert(false && "FIXME: Template instantiations for ObjC expressions"); - return SemaRef.ExprError(); +TemplateExprInstantiator::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { + QualType EncodedType = SemaRef.InstantiateType(E->getEncodedType(), + TemplateArgs, + /*FIXME:*/E->getAtLoc(), + DeclarationName()); + if (EncodedType.isNull()) + return SemaRef.ExprError(); + + return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(E->getAtLoc(), + EncodedType, + E->getRParenLoc())); } Sema::OwningExprResult @@ -1235,14 +1242,12 @@ TemplateExprInstantiator::VisitObjCMessageExpr(ObjCMessageExpr *E) { Sema::OwningExprResult TemplateExprInstantiator::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { - assert(false && "FIXME: Template instantiations for ObjC expressions"); - return SemaRef.ExprError(); + return SemaRef.Owned(E->Clone(SemaRef.Context)); } Sema::OwningExprResult TemplateExprInstantiator::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { - assert(false && "FIXME: Template instantiations for ObjC expressions"); - return SemaRef.ExprError(); + return SemaRef.Owned(E->Clone(SemaRef.Context)); } Sema::OwningExprResult -- cgit v1.1