add a new ImaginaryLiteral AST node that is used to
represent imaginary literals:
float _Complex A;
void foo() {
A = 1.0iF;
}
generates:
(BinaryOperator 0x2305ec0 '_Complex float' '='
(DeclRefExpr 0x2305e60 '_Complex float' Decl='A' 0x2305cf0)
(ImaginaryLiteral 0x2305f40 '_Complex float'
(FloatingLiteral 0x2305ea0 'float' 1.000000))))
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41413 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 1c53955..e4dd9bb 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -141,7 +141,15 @@
if (Literal.hadError)
return ExprResult(true);
- if (Literal.isIntegerLiteral()) {
+ Expr *Res;
+
+ if (Literal.isFloatingLiteral()) {
+ // FIXME: handle float values > 32 (including compute the real type...).
+ QualType Ty = Literal.isFloat ? Context.FloatTy : Context.DoubleTy;
+ Res = new FloatingLiteral(Literal.GetFloatValue(), Ty, Tok.getLocation());
+ } else if (!Literal.isIntegerLiteral()) {
+ return ExprResult(true);
+ } else {
QualType t;
// Get the value in the widest-possible width.
@@ -218,13 +226,14 @@
}
}
- return new IntegerLiteral(ResultVal, t, Tok.getLocation());
- } else if (Literal.isFloatingLiteral()) {
- // FIXME: handle float values > 32 (including compute the real type...).
- QualType Ty = Literal.isFloat ? Context.FloatTy : Context.DoubleTy;
- return new FloatingLiteral(Literal.GetFloatValue(), Ty, Tok.getLocation());
+ Res = new IntegerLiteral(ResultVal, t, Tok.getLocation());
}
- return ExprResult(true);
+
+ // If this is an imaginary literal, create the ImaginaryLiteral wrapper.
+ if (Literal.isImaginary)
+ Res = new ImaginaryLiteral(Res, Context.getComplexType(Res->getType()));
+
+ return Res;
}
Action::ExprResult Sema::ParseParenExpr(SourceLocation L, SourceLocation R,