]> granicus.if.org Git - clang/commitdiff
Implement sema support for __real/__imag nodes.
authorChris Lattner <sabre@nondot.org>
Fri, 24 Aug 2007 21:16:53 +0000 (21:16 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 24 Aug 2007 21:16:53 +0000 (21:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41375 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/Expr.h

index b758c3dd60e4062e14003b99f9cc92473906fa0f..3eee2e30343c84568ec9477ed17a445b37800468 100644 (file)
@@ -420,6 +420,7 @@ private:
   QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
   QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc, 
                                      bool isSizeof);
+  QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isImag);
   
   /// type checking primary expressions.
   QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
index 102642432cb65a6a89270023b278c653f700f6e7..ea2ec4a25c1f8087ae8ee25307ba5af47a533cc8 100644 (file)
@@ -271,6 +271,15 @@ ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
   return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, resultType, OpLoc, RPLoc);
 }
 
+QualType Sema::CheckRealImagOperand(Expr *&V, SourceLocation Loc, bool isImag) {
+  DefaultFunctionArrayConversion(V);
+  
+  if (const ComplexType *CT = V->getType()->getAsComplexType())
+    return CT->getElementType();
+  return V->getType();
+}
+
+
 
 Action::ExprResult Sema::ParsePostfixUnaryOp(SourceLocation OpLoc, 
                                              tok::TokenKind Kind,
@@ -1586,8 +1595,13 @@ Action::ExprResult Sema::ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
   case UnaryOperator::AlignOf:
     resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc, false);
     break;
+  case UnaryOperator::Real:
+    resultType = CheckRealImagOperand(Input, OpLoc, false);
+    break;
+  case UnaryOperator::Imag:
+    resultType = CheckRealImagOperand(Input, OpLoc, true);
+    break;
   case UnaryOperator::Extension:
-    // FIXME: does __extension__ cause any promotions? I would think not.
     resultType = Input->getType();
     break;
   }
index 566e5e66c80a321a0055d2eba76d111cab910a1c..f002cfede16de99ebe681571fd92ff663fc9542b 100644 (file)
@@ -297,6 +297,13 @@ public:
 /// UnaryOperator - This represents the unary-expression's (except sizeof of
 /// types), the postinc/postdec operators from postfix-expression, and various
 /// extensions.
+///
+/// Notes on various nodes:
+///
+/// Real/Imag - These return the real/imag part of a complex operand.  If
+///   applied to a non-complex value, the former returns its operand and the
+///   later returns zero in the type of the operand.
+///
 class UnaryOperator : public Expr {
 public:
   // Note that additions to this should also update the StmtVisitor class.