[cfe-commits] r111207 - /cfe/trunk/lib/AST/ExprConstant.cpp

Eli Friedman eli.friedman at gmail.com
Mon Aug 16 16:27:44 PDT 2010


Author: efriedma
Date: Mon Aug 16 18:27:44 2010
New Revision: 111207

URL: http://llvm.org/viewvc/llvm-project?rev=111207&view=rev
Log:
Move a bunch of code out of the ComplexExprEvaluator class definition;
no functionality change.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=111207&r1=111206&r2=111207&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Aug 16 18:27:44 2010
@@ -1989,138 +1989,142 @@
 
   bool VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
 
-  bool VisitImaginaryLiteral(ImaginaryLiteral *E) {
-    Expr* SubExpr = E->getSubExpr();
+  bool VisitImaginaryLiteral(ImaginaryLiteral *E);
 
-    if (SubExpr->getType()->isRealFloatingType()) {
-      Result.makeComplexFloat();
-      APFloat &Imag = Result.FloatImag;
-      if (!EvaluateFloat(SubExpr, Imag, Info))
-        return false;
+  bool VisitCastExpr(CastExpr *E);
+
+  bool VisitBinaryOperator(const BinaryOperator *E);
+  bool VisitChooseExpr(const ChooseExpr *E)
+    { return Visit(E->getChosenSubExpr(Info.Ctx)); }
+  bool VisitUnaryExtension(const UnaryOperator *E)
+    { return Visit(E->getSubExpr()); }
+  // FIXME Missing: unary +/-/~, binary div, ImplicitValueInitExpr,
+  //                conditional ?:, comma
+};
+} // end anonymous namespace
+
+static bool EvaluateComplex(const Expr *E, ComplexValue &Result,
+                            EvalInfo &Info) {
+  assert(E->getType()->isAnyComplexType());
+  return ComplexExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E));
+}
+
+bool ComplexExprEvaluator::VisitImaginaryLiteral(ImaginaryLiteral *E) {
+  Expr* SubExpr = E->getSubExpr();
+
+  if (SubExpr->getType()->isRealFloatingType()) {
+    Result.makeComplexFloat();
+    APFloat &Imag = Result.FloatImag;
+    if (!EvaluateFloat(SubExpr, Imag, Info))
+      return false;
 
-      Result.FloatReal = APFloat(Imag.getSemantics());
+    Result.FloatReal = APFloat(Imag.getSemantics());
+    return true;
+  } else {
+    assert(SubExpr->getType()->isIntegerType() &&
+           "Unexpected imaginary literal.");
+
+    Result.makeComplexInt();
+    APSInt &Imag = Result.IntImag;
+    if (!EvaluateInteger(SubExpr, Imag, Info))
+      return false;
+
+    Result.IntReal = APSInt(Imag.getBitWidth(), !Imag.isSigned());
+    return true;
+  }
+}
+
+bool ComplexExprEvaluator::VisitCastExpr(CastExpr *E) {
+  Expr* SubExpr = E->getSubExpr();
+  QualType EltType = E->getType()->getAs<ComplexType>()->getElementType();
+  QualType SubType = SubExpr->getType();
+
+  if (SubType->isRealFloatingType()) {
+    APFloat &Real = Result.FloatReal;
+    if (!EvaluateFloat(SubExpr, Real, Info))
+      return false;
+
+    if (EltType->isRealFloatingType()) {
+      Result.makeComplexFloat();
+      Real = HandleFloatToFloatCast(EltType, SubType, Real, Info.Ctx);
+      Result.FloatImag = APFloat(Real.getSemantics());
       return true;
     } else {
-      assert(SubExpr->getType()->isIntegerType() &&
-             "Unexpected imaginary literal.");
-
       Result.makeComplexInt();
-      APSInt &Imag = Result.IntImag;
-      if (!EvaluateInteger(SubExpr, Imag, Info))
-        return false;
+      Result.IntReal = HandleFloatToIntCast(EltType, SubType, Real, Info.Ctx);
+      Result.IntImag = APSInt(Result.IntReal.getBitWidth(),
+                              !Result.IntReal.isSigned());
+      return true;
+    }
+  } else if (SubType->isIntegerType()) {
+    APSInt &Real = Result.IntReal;
+    if (!EvaluateInteger(SubExpr, Real, Info))
+      return false;
 
-      Result.IntReal = APSInt(Imag.getBitWidth(), !Imag.isSigned());
+    if (EltType->isRealFloatingType()) {
+      Result.makeComplexFloat();
+      Result.FloatReal
+        = HandleIntToFloatCast(EltType, SubType, Real, Info.Ctx);
+      Result.FloatImag = APFloat(Result.FloatReal.getSemantics());
+      return true;
+    } else {
+      Result.makeComplexInt();
+      Real = HandleIntToIntCast(EltType, SubType, Real, Info.Ctx);
+      Result.IntImag = APSInt(Real.getBitWidth(), !Real.isSigned());
       return true;
     }
-  }
+  } else if (const ComplexType *CT = SubType->getAs<ComplexType>()) {
+    if (!Visit(SubExpr))
+      return false;
 
-  bool VisitCastExpr(CastExpr *E) {
-    Expr* SubExpr = E->getSubExpr();
-    QualType EltType = E->getType()->getAs<ComplexType>()->getElementType();
-    QualType SubType = SubExpr->getType();
-
-    if (SubType->isRealFloatingType()) {
-      APFloat &Real = Result.FloatReal;
-      if (!EvaluateFloat(SubExpr, Real, Info))
-        return false;
+    QualType SrcType = CT->getElementType();
 
+    if (Result.isComplexFloat()) {
       if (EltType->isRealFloatingType()) {
         Result.makeComplexFloat();
-        Real = HandleFloatToFloatCast(EltType, SubType, Real, Info.Ctx);
-        Result.FloatImag = APFloat(Real.getSemantics());
+        Result.FloatReal = HandleFloatToFloatCast(EltType, SrcType,
+                                                  Result.FloatReal,
+                                                  Info.Ctx);
+        Result.FloatImag = HandleFloatToFloatCast(EltType, SrcType,
+                                                  Result.FloatImag,
+                                                  Info.Ctx);
         return true;
       } else {
         Result.makeComplexInt();
-        Result.IntReal = HandleFloatToIntCast(EltType, SubType, Real, Info.Ctx);
-        Result.IntImag = APSInt(Result.IntReal.getBitWidth(),
-                                !Result.IntReal.isSigned());
+        Result.IntReal = HandleFloatToIntCast(EltType, SrcType,
+                                              Result.FloatReal,
+                                              Info.Ctx);
+        Result.IntImag = HandleFloatToIntCast(EltType, SrcType,
+                                              Result.FloatImag,
+                                              Info.Ctx);
         return true;
       }
-    } else if (SubType->isIntegerType()) {
-      APSInt &Real = Result.IntReal;
-      if (!EvaluateInteger(SubExpr, Real, Info))
-        return false;
-
+    } else {
+      assert(Result.isComplexInt() && "Invalid evaluate result.");
       if (EltType->isRealFloatingType()) {
         Result.makeComplexFloat();
-        Result.FloatReal
-          = HandleIntToFloatCast(EltType, SubType, Real, Info.Ctx);
-        Result.FloatImag = APFloat(Result.FloatReal.getSemantics());
+        Result.FloatReal = HandleIntToFloatCast(EltType, SrcType,
+                                                Result.IntReal,
+                                                Info.Ctx);
+        Result.FloatImag = HandleIntToFloatCast(EltType, SrcType,
+                                                Result.IntImag,
+                                                Info.Ctx);
         return true;
       } else {
         Result.makeComplexInt();
-        Real = HandleIntToIntCast(EltType, SubType, Real, Info.Ctx);
-        Result.IntImag = APSInt(Real.getBitWidth(), !Real.isSigned());
+        Result.IntReal = HandleIntToIntCast(EltType, SrcType,
+                                            Result.IntReal,
+                                            Info.Ctx);
+        Result.IntImag = HandleIntToIntCast(EltType, SrcType,
+                                            Result.IntImag,
+                                            Info.Ctx);
         return true;
       }
-    } else if (const ComplexType *CT = SubType->getAs<ComplexType>()) {
-      if (!Visit(SubExpr))
-        return false;
-
-      QualType SrcType = CT->getElementType();
-
-      if (Result.isComplexFloat()) {
-        if (EltType->isRealFloatingType()) {
-          Result.makeComplexFloat();
-          Result.FloatReal = HandleFloatToFloatCast(EltType, SrcType,
-                                                    Result.FloatReal,
-                                                    Info.Ctx);
-          Result.FloatImag = HandleFloatToFloatCast(EltType, SrcType,
-                                                    Result.FloatImag,
-                                                    Info.Ctx);
-          return true;
-        } else {
-          Result.makeComplexInt();
-          Result.IntReal = HandleFloatToIntCast(EltType, SrcType,
-                                                Result.FloatReal,
-                                                Info.Ctx);
-          Result.IntImag = HandleFloatToIntCast(EltType, SrcType,
-                                                Result.FloatImag,
-                                                Info.Ctx);
-          return true;
-        }
-      } else {
-        assert(Result.isComplexInt() && "Invalid evaluate result.");
-        if (EltType->isRealFloatingType()) {
-          Result.makeComplexFloat();
-          Result.FloatReal = HandleIntToFloatCast(EltType, SrcType,
-                                                  Result.IntReal,
-                                                  Info.Ctx);
-          Result.FloatImag = HandleIntToFloatCast(EltType, SrcType,
-                                                  Result.IntImag,
-                                                  Info.Ctx);
-          return true;
-        } else {
-          Result.makeComplexInt();
-          Result.IntReal = HandleIntToIntCast(EltType, SrcType,
-                                              Result.IntReal,
-                                              Info.Ctx);
-          Result.IntImag = HandleIntToIntCast(EltType, SrcType,
-                                              Result.IntImag,
-                                              Info.Ctx);
-          return true;
-        }
-      }
     }
-
-    // FIXME: Handle more casts.
-    return false;
   }
 
-  bool VisitBinaryOperator(const BinaryOperator *E);
-  bool VisitChooseExpr(const ChooseExpr *E)
-    { return Visit(E->getChosenSubExpr(Info.Ctx)); }
-  bool VisitUnaryExtension(const UnaryOperator *E)
-    { return Visit(E->getSubExpr()); }
-  // FIXME Missing: unary +/-/~, binary div, ImplicitValueInitExpr,
-  //                conditional ?:, comma
-};
-} // end anonymous namespace
-
-static bool EvaluateComplex(const Expr *E, ComplexValue &Result,
-                            EvalInfo &Info) {
-  assert(E->getType()->isAnyComplexType());
-  return ComplexExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E));
+  // FIXME: Handle more casts.
+  return false;
 }
 
 bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {





More information about the cfe-commits mailing list