aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-02-18 20:55:15 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-02-18 20:55:15 +0000
commit16f744beaaa30bf3847740ca8e8beb6f0d3a0b93 (patch)
treedde10893824001217fa712f37b67e663ae0db551
parent2846b97965e980ad2e7c8d444b82cc21d733a699 (diff)
Introduce ASTContext::getLogicalOperationType() to return bool or int, depending on language.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125957 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ASTContext.h5
-rw-r--r--lib/Sema/SemaExpr.cpp6
2 files changed, 8 insertions, 3 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 244cf26b89..7d2bd14ea9 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -844,6 +844,11 @@ public:
return QualType();
}
+ /// \brief The result type of logical operations, '<', '>', '!=', etc.
+ QualType getLogicalOperationType() const {
+ return getLangOptions().CPlusPlus ? BoolTy : IntTy;
+ }
+
/// getObjCEncodingForType - Emit the ObjC type encoding for the
/// given type into \arg S. If \arg NameFields is specified then
/// record field names are also encoded.
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 92e671165b..d5e6e77c3e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -6772,7 +6772,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
rType = rex->getType();
// The result of comparisons is 'bool' in C++, 'int' in C.
- QualType ResultTy = getLangOptions().CPlusPlus ? Context.BoolTy:Context.IntTy;
+ QualType ResultTy = Context.getLogicalOperationType();
if (isRelational) {
if (lType->isRealType() && rType->isRealType())
@@ -7051,7 +7051,7 @@ QualType Sema::CheckVectorCompareOperands(Expr *&lex, Expr *&rex,
// If AltiVec, the comparison results in a numeric type, i.e.
// bool for C++, int for C
if (getLangOptions().AltiVec)
- return (getLangOptions().CPlusPlus ? Context.BoolTy : Context.IntTy);
+ return Context.getLogicalOperationType();
QualType lType = lex->getType();
QualType rType = rex->getType();
@@ -8303,7 +8303,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
// LNot always has type int. C99 6.5.3.3p5.
// In C++, it's bool. C++ 5.3.1p8
- resultType = getLangOptions().CPlusPlus ? Context.BoolTy : Context.IntTy;
+ resultType = Context.getLogicalOperationType();
break;
case UO_Real:
case UO_Imag: