]> granicus.if.org Git - clang/commitdiff
Move a bunch of code out of the ComplexExprEvaluator class definition;
authorEli Friedman <eli.friedman@gmail.com>
Mon, 16 Aug 2010 23:27:44 +0000 (23:27 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 16 Aug 2010 23:27:44 +0000 (23:27 +0000)
no functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp

index 3b288ec8b7fb8251a8a24e6c17dad76d74f66b28..2c8d617f6dcf14ea4432e0649f700d96ded38fc2 100644 (file)
@@ -1989,138 +1989,142 @@ public:
 
   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
 
-      Result.FloatReal = APFloat(Imag.getSemantics());
+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());
+    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 = APSInt(Imag.getBitWidth(), !Imag.isSigned());
+      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;
 
-  bool VisitCastExpr(CastExpr *E) {
-    Expr* SubExpr = E->getSubExpr();
-    QualType EltType = E->getType()->getAs<ComplexType>()->getElementType();
-    QualType SubType = SubExpr->getType();
+    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;
 
-    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) {