[cfe-commits] r41413 - in /cfe/trunk: AST/Expr.cpp AST/StmtDumper.cpp AST/StmtPrinter.cpp Sema/SemaExpr.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h include/clang/AST/StmtNodes.def
Chris Lattner
sabre at nondot.org
Sat Aug 25 20:42:45 PDT 2007
Author: lattner
Date: Sat Aug 25 22:42:43 2007
New Revision: 41413
URL: http://llvm.org/viewvc/llvm-project?rev=41413&view=rev
Log:
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))))
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/AST/StmtDumper.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Sat Aug 25 22:42:43 2007
@@ -738,6 +738,14 @@
Stmt::child_iterator FloatingLiteral::child_begin() { return NULL; }
Stmt::child_iterator FloatingLiteral::child_end() { return NULL; }
+// ImaginaryLiteral
+Stmt::child_iterator ImaginaryLiteral::child_begin() {
+ return reinterpret_cast<Stmt**>(&Val);
+}
+Stmt::child_iterator ImaginaryLiteral::child_end() {
+ return reinterpret_cast<Stmt**>(&Val)+1;
+}
+
// StringLiteral
Stmt::child_iterator StringLiteral::child_begin() { return NULL; }
Stmt::child_iterator StringLiteral::child_end() { return NULL; }
@@ -746,122 +754,104 @@
Stmt::child_iterator ParenExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Val);
}
-
Stmt::child_iterator ParenExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Val)+1;
}
// UnaryOperator
Stmt::child_iterator UnaryOperator::child_begin() {
return reinterpret_cast<Stmt**>(&Val);
}
-
Stmt::child_iterator UnaryOperator::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Val)+1;
}
// SizeOfAlignOfTypeExpr
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
- return NULL;
-}
-
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
- return NULL;
-}
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { return NULL; }
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() { return NULL; }
// ArraySubscriptExpr
Stmt::child_iterator ArraySubscriptExpr::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-
Stmt::child_iterator ArraySubscriptExpr::child_end() {
- return child_begin()+END_EXPR;
+ return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
}
// CallExpr
Stmt::child_iterator CallExpr::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-
Stmt::child_iterator CallExpr::child_end() {
- return child_begin()+NumArgs+ARGS_START;
+ return reinterpret_cast<Stmt**>(&SubExprs)+NumArgs+ARGS_START;
}
// MemberExpr
Stmt::child_iterator MemberExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Base);
}
-
Stmt::child_iterator MemberExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Base)+1;
}
// OCUVectorElementExpr
Stmt::child_iterator OCUVectorElementExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Base);
}
-
Stmt::child_iterator OCUVectorElementExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Base)+1;
}
// CompoundLiteralExpr
Stmt::child_iterator CompoundLiteralExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Init);
}
-
Stmt::child_iterator CompoundLiteralExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Init)+1;
}
// ImplicitCastExpr
Stmt::child_iterator ImplicitCastExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Op);
}
-
Stmt::child_iterator ImplicitCastExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Op)+1;
}
// CastExpr
Stmt::child_iterator CastExpr::child_begin() {
return reinterpret_cast<Stmt**>(&Op);
}
-
Stmt::child_iterator CastExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&Op)+1;
}
// BinaryOperator
Stmt::child_iterator BinaryOperator::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-
Stmt::child_iterator BinaryOperator::child_end() {
- return child_begin()+END_EXPR;
+ return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
}
// ConditionalOperator
Stmt::child_iterator ConditionalOperator::child_begin() {
return reinterpret_cast<Stmt**>(&SubExprs);
}
-
Stmt::child_iterator ConditionalOperator::child_end() {
- return child_begin()+END_EXPR;
+ return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
}
// AddrLabelExpr
Stmt::child_iterator AddrLabelExpr::child_begin() { return NULL; }
Stmt::child_iterator AddrLabelExpr::child_end() { return NULL; }
-
// StmtExpr
Stmt::child_iterator StmtExpr::child_begin() {
return reinterpret_cast<Stmt**>(&SubStmt);
}
-
Stmt::child_iterator StmtExpr::child_end() {
- return child_begin()+1;
+ return reinterpret_cast<Stmt**>(&SubStmt)+1;
}
// TypesCompatibleExpr
@@ -874,7 +864,7 @@
}
Stmt::child_iterator ChooseExpr::child_end() {
- return child_begin()+END_EXPR;
+ return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
}
// ObjCStringLiteral
Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Sat Aug 25 22:42:43 2007
@@ -328,6 +328,14 @@
DumpExpr(Node);
fprintf(F, " %f)", Node->getValue());
}
+
+void StmtDumper::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
+ DumpExpr(Node);
+ fprintf(F, "\n");
+ DumpSubTree(Node->getSubExpr());
+ fprintf(F, ")");
+}
+
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
DumpExpr(Str);
// FIXME: this doesn't print wstrings right.
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Sat Aug 25 22:42:43 2007
@@ -379,6 +379,12 @@
// FIXME: print value more precisely.
OS << Node->getValue();
}
+
+void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
+ PrintExpr(Node->getSubExpr());
+ OS << "i";
+}
+
void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
if (Str->isWide()) OS << 'L';
OS << '"';
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Aug 25 22:42:43 2007
@@ -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,
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Sat Aug 25 22:42:43 2007
@@ -210,7 +210,7 @@
35260CA40C7F75C000D66CE9 /* ExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExprCXX.cpp; path = AST/ExprCXX.cpp; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
- 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Aug 25 22:42:43 2007
@@ -216,7 +216,7 @@
};
class FloatingLiteral : public Expr {
- float Value; // FIXME
+ float Value; // FIXME: Change to APFloat
SourceLocation Loc;
public:
FloatingLiteral(float value, QualType type, SourceLocation l)
@@ -236,6 +236,31 @@
virtual child_iterator child_end();
};
+/// ImaginaryLiteral - We support imaginary integer and floating point literals,
+/// like "1.0i". We represent these as a wrapper around FloatingLiteral and
+/// IntegerLiteral classes. Instances of this class always have a Complex type
+/// whose element type matches the subexpression.
+///
+class ImaginaryLiteral : public Expr {
+ Expr *Val;
+public:
+ ImaginaryLiteral(Expr *val, QualType Ty)
+ : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
+
+ const Expr *getSubExpr() const { return Val; }
+ Expr *getSubExpr() { return Val; }
+
+ virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ImaginaryLiteralClass;
+ }
+ static bool classof(const ImaginaryLiteral *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
/// StringLiteral - This represents a string literal expression, e.g. "foo"
/// or L"bar" (wide strings). The actual string is returned by getStrData()
/// is NOT null-terminated, and the length of the string is determined by
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=41413&r1=41412&r2=41413&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Sat Aug 25 22:42:43 2007
@@ -49,21 +49,22 @@
STMT(33, DeclRefExpr , Expr)
STMT(34, IntegerLiteral , Expr)
STMT(35, FloatingLiteral , Expr)
-STMT(36, StringLiteral , Expr)
-STMT(37, CharacterLiteral , Expr)
-STMT(38, ParenExpr , Expr)
-STMT(39, UnaryOperator , Expr)
-STMT(40, SizeOfAlignOfTypeExpr , Expr)
-STMT(41, ArraySubscriptExpr , Expr)
-STMT(42, CallExpr , Expr)
-STMT(43, MemberExpr , Expr)
-STMT(44, CastExpr , Expr)
-STMT(45, BinaryOperator , Expr)
-STMT(46, CompoundAssignOperator, BinaryOperator)
-STMT(47, ConditionalOperator , Expr)
-STMT(48, ImplicitCastExpr , Expr)
-STMT(49, CompoundLiteralExpr , Expr)
-STMT(50, OCUVectorElementExpr , Expr)
+STMT(36, ImaginaryLiteral , Expr)
+STMT(37, StringLiteral , Expr)
+STMT(38, CharacterLiteral , Expr)
+STMT(39, ParenExpr , Expr)
+STMT(40, UnaryOperator , Expr)
+STMT(41, SizeOfAlignOfTypeExpr , Expr)
+STMT(42, ArraySubscriptExpr , Expr)
+STMT(43, CallExpr , Expr)
+STMT(44, MemberExpr , Expr)
+STMT(45, CastExpr , Expr)
+STMT(46, BinaryOperator , Expr)
+STMT(47, CompoundAssignOperator, BinaryOperator)
+STMT(48, ConditionalOperator , Expr)
+STMT(49, ImplicitCastExpr , Expr)
+STMT(50, CompoundLiteralExpr , Expr)
+STMT(51, OCUVectorElementExpr , Expr)
// GNU Extensions.
STMT(55, AddrLabelExpr , Expr)
More information about the cfe-commits
mailing list