From dbb36971c68ea944ac4b1fbe2d97fe7cca3b20ac Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 24 Aug 2007 21:16:53 +0000 Subject: [PATCH] Implement sema support for __real/__imag nodes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41375 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/Sema.h | 1 + Sema/SemaExpr.cpp | 16 +++++++++++++++- include/clang/AST/Expr.h | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Sema/Sema.h b/Sema/Sema.h index b758c3dd60..3eee2e3034 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -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, diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 102642432c..ea2ec4a25c 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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; } diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 566e5e66c8..f002cfede1 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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. -- 2.50.1