r200877 - Clean up some particularly ugly casting.
Benjamin Kramer
benny.kra at googlemail.com
Wed Feb 5 13:29:06 PST 2014
Author: d0k
Date: Wed Feb 5 15:29:05 2014
New Revision: 200877
URL: http://llvm.org/viewvc/llvm-project?rev=200877&view=rev
Log:
Clean up some particularly ugly casting.
No functionality change.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=200877&r1=200876&r2=200877&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Feb 5 15:29:05 2014
@@ -4205,18 +4205,14 @@ public:
/// and array-range designators.
unsigned getNumSubExprs() const { return NumSubExprs; }
- Expr *getSubExpr(unsigned Idx) {
+ Expr *getSubExpr(unsigned Idx) const {
assert(Idx < NumSubExprs && "Subscript out of range");
- char* Ptr = static_cast<char*>(static_cast<void *>(this));
- Ptr += sizeof(DesignatedInitExpr);
- return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
+ return cast<Expr>(reinterpret_cast<Stmt *const *>(this + 1)[Idx]);
}
void setSubExpr(unsigned Idx, Expr *E) {
assert(Idx < NumSubExprs && "Subscript out of range");
- char* Ptr = static_cast<char*>(static_cast<void *>(this));
- Ptr += sizeof(DesignatedInitExpr);
- reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
+ reinterpret_cast<Stmt **>(this + 1)[Idx] = E;
}
/// \brief Replaces the designator at index @p Idx with the series
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=200877&r1=200876&r2=200877&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Feb 5 15:29:05 2014
@@ -3789,30 +3789,21 @@ SourceLocation DesignatedInitExpr::getLo
Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const {
assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
- char *Ptr = static_cast<char *>(
- const_cast<void *>(static_cast<const void *>(this)));
- Ptr += sizeof(DesignatedInitExpr);
- Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
+ Stmt *const *SubExprs = reinterpret_cast<Stmt *const *>(this + 1);
return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
}
Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const {
assert(D.Kind == Designator::ArrayRangeDesignator &&
"Requires array range designator");
- char *Ptr = static_cast<char *>(
- const_cast<void *>(static_cast<const void *>(this)));
- Ptr += sizeof(DesignatedInitExpr);
- Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
+ Stmt *const *SubExprs = reinterpret_cast<Stmt *const *>(this + 1);
return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
}
Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const {
assert(D.Kind == Designator::ArrayRangeDesignator &&
"Requires array range designator");
- char *Ptr = static_cast<char *>(
- const_cast<void *>(static_cast<const void *>(this)));
- Ptr += sizeof(DesignatedInitExpr);
- Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
+ Stmt *const *SubExprs = reinterpret_cast<Stmt *const *>(this + 1);
return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2));
}
More information about the cfe-commits
mailing list