[cfe-commits] r52380 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/AST/Stmt.h lib/AST/ExprCXX.cpp lib/AST/Stmt.cpp
Ted Kremenek
kremenek at apple.com
Mon Jun 16 20:11:08 PDT 2008
Author: kremenek
Date: Mon Jun 16 22:11:08 2008
New Revision: 52380
URL: http://llvm.org/viewvc/llvm-project?rev=52380&view=rev
Log:
Fix more strict-aliasing warnings.
Fix indentation of class declarations in ExprCXX.h
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/Stmt.cpp
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=52380&r1=52379&r2=52380&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Mon Jun 16 22:11:08 2008
@@ -18,156 +18,156 @@
namespace clang {
- //===--------------------------------------------------------------------===//
- // C++ Expressions.
- //===--------------------------------------------------------------------===//
-
- /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
- ///
- class CXXCastExpr : public Expr {
- public:
- enum Opcode {
- DynamicCast,
- StaticCast,
- ReinterpretCast,
- ConstCast
- };
- private:
- QualType Ty;
- Opcode Opc;
- Expr *Op;
- SourceLocation Loc; // the location of the casting op
- public:
- CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l)
- : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {}
-
- QualType getDestType() const { return Ty; }
- Expr *getSubExpr() const { return Op; }
-
- Opcode getOpcode() const { return Opc; }
-
- /// getOpcodeStr - Turn an Opcode enum value into the string it represents,
- /// e.g. "reinterpret_cast".
- static const char *getOpcodeStr(Opcode Op) {
- // FIXME: move out of line.
- switch (Op) {
- default: assert(0 && "Not a C++ cast expression");
- case CXXCastExpr::ConstCast: return "const_cast";
- case CXXCastExpr::DynamicCast: return "dynamic_cast";
- case CXXCastExpr::ReinterpretCast: return "reinterpret_cast";
- case CXXCastExpr::StaticCast: return "static_cast";
- }
- }
-
- virtual SourceRange getSourceRange() const {
- return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
- }
- static bool classof(const Stmt *T) {
- return T->getStmtClass() == CXXCastExprClass;
- }
- static bool classof(const CXXCastExpr *) { return true; }
-
- // Iterators
- virtual child_iterator child_begin();
- virtual child_iterator child_end();
+//===--------------------------------------------------------------------===//
+// C++ Expressions.
+//===--------------------------------------------------------------------===//
+
+/// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
+///
+class CXXCastExpr : public Expr {
+public:
+ enum Opcode {
+ DynamicCast,
+ StaticCast,
+ ReinterpretCast,
+ ConstCast
};
+private:
+ QualType Ty;
+ Opcode Opc;
+ Stmt *Op;
+ SourceLocation Loc; // the location of the casting op
+public:
+ CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l)
+ : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {}
+
+ QualType getDestType() const { return Ty; }
+ Expr *getSubExpr() const { return cast<Expr>(Op); }
+
+ Opcode getOpcode() const { return Opc; }
+
+ /// getOpcodeStr - Turn an Opcode enum value into the string it represents,
+ /// e.g. "reinterpret_cast".
+ static const char *getOpcodeStr(Opcode Op) {
+ // FIXME: move out of line.
+ switch (Op) {
+ default: assert(0 && "Not a C++ cast expression");
+ case CXXCastExpr::ConstCast: return "const_cast";
+ case CXXCastExpr::DynamicCast: return "dynamic_cast";
+ case CXXCastExpr::ReinterpretCast: return "reinterpret_cast";
+ case CXXCastExpr::StaticCast: return "static_cast";
+ }
+ }
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
+ }
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CXXCastExprClass;
+ }
+ static bool classof(const CXXCastExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
+/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
+///
+class CXXBoolLiteralExpr : public Expr {
+ bool Value;
+ SourceLocation Loc;
+public:
+ CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
+ Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
+
+ bool getValue() const { return Value; }
- /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
- ///
- class CXXBoolLiteralExpr : public Expr {
- bool Value;
- SourceLocation Loc;
- public:
- CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
- Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- bool getValue() const { return Value; }
-
- virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CXXBoolLiteralExprClass;
+ }
+ static bool classof(const CXXBoolLiteralExpr *) { return true; }
- static bool classof(const Stmt *T) {
- return T->getStmtClass() == CXXBoolLiteralExprClass;
- }
- static bool classof(const CXXBoolLiteralExpr *) { return true; }
-
- // Iterators
- virtual child_iterator child_begin();
- virtual child_iterator child_end();
- };
-
- /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
- /// 'throw' and 'throw' assignment-expression. When
- /// assignment-expression isn't present, Op will be null.
- ///
- class CXXThrowExpr : public Expr {
- Expr *Op;
- SourceLocation ThrowLoc;
- public:
- // Ty is the void type which is used as the result type of the
- // exepression. The l is the location of the throw keyword. expr
- // can by null, if the optional expression to throw isn't present.
- CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
- Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {}
- const Expr *getSubExpr() const { return Op; }
- Expr *getSubExpr() { return Op; }
-
- virtual SourceRange getSourceRange() const {
- if (getSubExpr() == 0)
- return SourceRange(ThrowLoc, ThrowLoc);
- return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
- }
-
- static bool classof(const Stmt *T) {
- return T->getStmtClass() == CXXThrowExprClass;
- }
- static bool classof(const CXXThrowExpr *) { return true; }
-
- // Iterators
- virtual child_iterator child_begin();
- virtual child_iterator child_end();
- };
-
- /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
- /// function call argument that was created from the corresponding
- /// parameter's default argument, when the call did not explicitly
- /// supply arguments for all of the parameters.
- class CXXDefaultArgExpr : public Expr {
- ParmVarDecl *Param;
- public:
- // Param is the parameter whose default argument is used by this
- // expression.
- explicit CXXDefaultArgExpr(ParmVarDecl *param)
- : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()),
- Param(param) { }
-
- // Retrieve the parameter that the argument was created from.
- const ParmVarDecl *getParam() const { return Param; }
- ParmVarDecl *getParam() { return Param; }
-
- // Retrieve the actual argument to the function call.
- const Expr *getExpr() const { return Param->getDefaultArg(); }
- Expr *getExpr() { return Param->getDefaultArg(); }
-
- virtual SourceRange getSourceRange() const {
- // Default argument expressions have no representation in the
- // source, so they have an empty source range.
- return SourceRange();
- }
-
- static bool classof(const Stmt *T) {
- return T->getStmtClass() == CXXDefaultArgExprClass;
- }
- static bool classof(const CXXDefaultArgExpr *) { return true; }
-
- // Iterators
- virtual child_iterator child_begin();
- virtual child_iterator child_end();
-
- // Serialization
- virtual void EmitImpl(llvm::Serializer& S) const;
- static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D,
- ASTContext& C);
- };
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
+/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
+/// 'throw' and 'throw' assignment-expression. When
+/// assignment-expression isn't present, Op will be null.
+///
+class CXXThrowExpr : public Expr {
+ Stmt *Op;
+ SourceLocation ThrowLoc;
+public:
+ // Ty is the void type which is used as the result type of the
+ // exepression. The l is the location of the throw keyword. expr
+ // can by null, if the optional expression to throw isn't present.
+ CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
+ Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {}
+ const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
+ Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
+
+ virtual SourceRange getSourceRange() const {
+ if (getSubExpr() == 0)
+ return SourceRange(ThrowLoc, ThrowLoc);
+ return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CXXThrowExprClass;
+ }
+ static bool classof(const CXXThrowExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
+/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
+/// function call argument that was created from the corresponding
+/// parameter's default argument, when the call did not explicitly
+/// supply arguments for all of the parameters.
+class CXXDefaultArgExpr : public Expr {
+ ParmVarDecl *Param;
+public:
+ // Param is the parameter whose default argument is used by this
+ // expression.
+ explicit CXXDefaultArgExpr(ParmVarDecl *param)
+ : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()),
+ Param(param) { }
+
+ // Retrieve the parameter that the argument was created from.
+ const ParmVarDecl *getParam() const { return Param; }
+ ParmVarDecl *getParam() { return Param; }
+
+ // Retrieve the actual argument to the function call.
+ const Expr *getExpr() const { return Param->getDefaultArg(); }
+ Expr *getExpr() { return Param->getDefaultArg(); }
+
+ virtual SourceRange getSourceRange() const {
+ // Default argument expressions have no representation in the
+ // source, so they have an empty source range.
+ return SourceRange();
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CXXDefaultArgExprClass;
+ }
+ static bool classof(const CXXDefaultArgExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
+ // Serialization
+ virtual void EmitImpl(llvm::Serializer& S) const;
+ static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D,
+ ASTContext& C);
+};
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=52380&r1=52379&r2=52380&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Jun 16 22:11:08 2008
@@ -626,14 +626,15 @@
/// IndirectGotoStmt - This represents an indirect goto.
///
class IndirectGotoStmt : public Stmt {
- Expr *Target;
+ Stmt *Target;
// FIXME: Add location information (e.g. SourceLocation objects).
// When doing so, update the serialization routines.
public:
- IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), Target(target){}
+ IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass),
+ Target((Stmt*)target){}
- Expr *getTarget() { return Target; }
- const Expr *getTarget() const { return Target; }
+ Expr *getTarget();
+ const Expr *getTarget() const;
virtual SourceRange getSourceRange() const { return SourceRange(); }
@@ -707,14 +708,14 @@
/// depend on the return type of the function and the presence of an argument.
///
class ReturnStmt : public Stmt {
- Expr *RetExpr;
+ Stmt *RetExpr;
SourceLocation RetLoc;
public:
ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
- RetExpr(E), RetLoc(RL) {}
+ RetExpr((Stmt*) E), RetLoc(RL) {}
- const Expr *getRetValue() const { return RetExpr; }
- Expr *getRetValue() { return RetExpr; }
+ const Expr *getRetValue() const;
+ Expr *getRetValue();
virtual SourceRange getSourceRange() const;
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=52380&r1=52379&r2=52380&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Mon Jun 16 22:11:08 2008
@@ -20,12 +20,8 @@
// CXXCastExpr
-Stmt::child_iterator CXXCastExpr::child_begin() {
- return reinterpret_cast<Stmt**>(&Op);
-}
-Stmt::child_iterator CXXCastExpr::child_end() {
- return reinterpret_cast<Stmt**>(&Op)+1;
-}
+Stmt::child_iterator CXXCastExpr::child_begin() { return &Op; }
+Stmt::child_iterator CXXCastExpr::child_end() { return &Op+1; }
// CXXBoolLiteralExpr
Stmt::child_iterator CXXBoolLiteralExpr::child_begin() {
@@ -36,14 +32,10 @@
}
// CXXThrowExpr
-Stmt::child_iterator CXXThrowExpr::child_begin() {
- return reinterpret_cast<Stmt**>(&Op);
-}
+Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; }
Stmt::child_iterator CXXThrowExpr::child_end() {
// If Op is 0, we are processing throw; which has no children.
- if (Op == 0)
- return reinterpret_cast<Stmt**>(&Op)+0;
- return reinterpret_cast<Stmt**>(&Op)+1;
+ return Op ? &Op+1 : &Op;
}
// CXXDefaultArgExpr
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=52380&r1=52379&r2=52380&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon Jun 16 22:11:08 2008
@@ -246,11 +246,11 @@
Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
// IndirectGotoStmt
-Stmt::child_iterator IndirectGotoStmt::child_begin() {
- return reinterpret_cast<Stmt**>(&Target);
-}
+Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); }
+const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); }
-Stmt::child_iterator IndirectGotoStmt::child_end() { return ++child_begin(); }
+Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; }
+Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; }
// ContinueStmt
Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
@@ -261,14 +261,18 @@
Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
// ReturnStmt
-Stmt::child_iterator ReturnStmt::child_begin() {
- if (RetExpr) return reinterpret_cast<Stmt**>(&RetExpr);
- else return child_iterator();
+const Expr* ReturnStmt::getRetValue() const {
+ return cast_or_null<Expr>(RetExpr);
+}
+Expr* ReturnStmt::getRetValue() {
+ return cast_or_null<Expr>(RetExpr);
}
-Stmt::child_iterator ReturnStmt::child_end() {
- if (RetExpr) return reinterpret_cast<Stmt**>(&RetExpr)+1;
- else return child_iterator();
+Stmt::child_iterator ReturnStmt::child_begin() {
+ return &RetExpr;
+}
+Stmt::child_iterator ReturnStmt::child_end() {
+ return RetExpr ? &RetExpr+1 : &RetExpr;
}
// AsmStmt
More information about the cfe-commits
mailing list