[cfe-commits] r125957 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/Sema/SemaExpr.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Feb 18 12:55:15 PST 2011


Author: akirtzidis
Date: Fri Feb 18 14:55:15 2011
New Revision: 125957

URL: http://llvm.org/viewvc/llvm-project?rev=125957&view=rev
Log:
Introduce ASTContext::getLogicalOperationType() to return bool or int, depending on language.
No functionality change.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=125957&r1=125956&r2=125957&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Feb 18 14:55:15 2011
@@ -844,6 +844,11 @@
     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.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=125957&r1=125956&r2=125957&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb 18 14:55:15 2011
@@ -6772,7 +6772,7 @@
   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 @@
   // 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 @@
     
     // 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:





More information about the cfe-commits mailing list