diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
commit | 9092c3e0fa01f3139b016d05d267a89e3b07747a (patch) | |
tree | 137ebebcae16fb0ce7ab4af456992bbd8d22fced /include/clang/AST/APValue.h | |
parent | 4981926bf654fe5a2c3893f24ca44106b217e71e (diff) | |
download | FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.zip FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.tar.gz |
Update clang to r84119.
Diffstat (limited to 'include/clang/AST/APValue.h')
-rw-r--r-- | include/clang/AST/APValue.h | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/include/clang/AST/APValue.h b/include/clang/AST/APValue.h index 5d5abfe..94d258d 100644 --- a/include/clang/AST/APValue.h +++ b/include/clang/AST/APValue.h @@ -37,16 +37,16 @@ public: }; private: ValueKind Kind; - - struct ComplexAPSInt { - APSInt Real, Imag; + + struct ComplexAPSInt { + APSInt Real, Imag; ComplexAPSInt() : Real(1), Imag(1) {} }; struct ComplexAPFloat { APFloat Real, Imag; ComplexAPFloat() : Real(0.0), Imag(0.0) {} }; - + struct LV { Expr* Base; uint64_t Offset; @@ -57,16 +57,17 @@ private: Vec() : Elts(0), NumElts(0) {} ~Vec() { delete[] Elts; } }; - + enum { - MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ? + MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ? sizeof(ComplexAPSInt) : sizeof(ComplexAPFloat)) }; - - /// Data - space for the largest member in units of void*. This is an effort - /// to ensure that the APSInt/APFloat values have proper alignment. - void *Data[(MaxSize+sizeof(void*)-1)/sizeof(void*)]; - + + union { + void *Aligner; + char Data[MaxSize]; + }; + public: APValue() : Kind(Uninitialized) {} explicit APValue(const APSInt &I) : Kind(Uninitialized) { @@ -93,7 +94,7 @@ public: ~APValue() { MakeUninit(); } - + ValueKind getKind() const { return Kind; } bool isUninit() const { return Kind == Uninitialized; } bool isInt() const { return Kind == Int; } @@ -102,54 +103,54 @@ public: bool isComplexFloat() const { return Kind == ComplexFloat; } bool isLValue() const { return Kind == LValue; } bool isVector() const { return Kind == Vector; } - + void print(llvm::raw_ostream &OS) const; void dump() const; - + APSInt &getInt() { assert(isInt() && "Invalid accessor"); - return *(APSInt*)(void*)Data; + return *(APSInt*)(char*)Data; } const APSInt &getInt() const { return const_cast<APValue*>(this)->getInt(); } - + APFloat &getFloat() { assert(isFloat() && "Invalid accessor"); - return *(APFloat*)(void*)Data; + return *(APFloat*)(char*)Data; } const APFloat &getFloat() const { return const_cast<APValue*>(this)->getFloat(); } - + APValue &getVectorElt(unsigned i) const { assert(isVector() && "Invalid accessor"); - return ((Vec*)(void*)Data)->Elts[i]; + return ((Vec*)(char*)Data)->Elts[i]; } unsigned getVectorLength() const { assert(isVector() && "Invalid accessor"); return ((Vec*)(void *)Data)->NumElts; } - + APSInt &getComplexIntReal() { assert(isComplexInt() && "Invalid accessor"); - return ((ComplexAPSInt*)(void*)Data)->Real; + return ((ComplexAPSInt*)(char*)Data)->Real; } const APSInt &getComplexIntReal() const { return const_cast<APValue*>(this)->getComplexIntReal(); } - + APSInt &getComplexIntImag() { assert(isComplexInt() && "Invalid accessor"); - return ((ComplexAPSInt*)(void*)Data)->Imag; + return ((ComplexAPSInt*)(char*)Data)->Imag; } const APSInt &getComplexIntImag() const { return const_cast<APValue*>(this)->getComplexIntImag(); } - + APFloat &getComplexFloatReal() { assert(isComplexFloat() && "Invalid accessor"); - return ((ComplexAPFloat*)(void*)Data)->Real; + return ((ComplexAPFloat*)(char*)Data)->Real; } const APFloat &getComplexFloatReal() const { return const_cast<APValue*>(this)->getComplexFloatReal(); @@ -157,7 +158,7 @@ public: APFloat &getComplexFloatImag() { assert(isComplexFloat() && "Invalid accessor"); - return ((ComplexAPFloat*)(void*)Data)->Imag; + return ((ComplexAPFloat*)(char*)Data)->Imag; } const APFloat &getComplexFloatImag() const { return const_cast<APValue*>(this)->getComplexFloatImag(); @@ -171,44 +172,44 @@ public: assert(isLValue() && "Invalid accessor"); return ((const LV*)(const void*)Data)->Offset; } - + void setInt(const APSInt &I) { assert(isInt() && "Invalid accessor"); - *(APSInt*)(void*)Data = I; + *(APSInt*)(char*)Data = I; } void setFloat(const APFloat &F) { assert(isFloat() && "Invalid accessor"); - *(APFloat*)(void*)Data = F; + *(APFloat*)(char*)Data = F; } void setVector(const APValue *E, unsigned N) { assert(isVector() && "Invalid accessor"); - ((Vec*)(void*)Data)->Elts = new APValue[N]; - ((Vec*)(void*)Data)->NumElts = N; + ((Vec*)(char*)Data)->Elts = new APValue[N]; + ((Vec*)(char*)Data)->NumElts = N; for (unsigned i = 0; i != N; ++i) - ((Vec*)(void*)Data)->Elts[i] = E[i]; + ((Vec*)(char*)Data)->Elts[i] = E[i]; } void setComplexInt(const APSInt &R, const APSInt &I) { - assert(R.getBitWidth() == I.getBitWidth() && + assert(R.getBitWidth() == I.getBitWidth() && "Invalid complex int (type mismatch)."); assert(isComplexInt() && "Invalid accessor"); - ((ComplexAPSInt*)(void*)Data)->Real = R; - ((ComplexAPSInt*)(void*)Data)->Imag = I; + ((ComplexAPSInt*)(char*)Data)->Real = R; + ((ComplexAPSInt*)(char*)Data)->Imag = I; } void setComplexFloat(const APFloat &R, const APFloat &I) { - assert(&R.getSemantics() == &I.getSemantics() && + assert(&R.getSemantics() == &I.getSemantics() && "Invalid complex float (type mismatch)."); assert(isComplexFloat() && "Invalid accessor"); - ((ComplexAPFloat*)(void*)Data)->Real = R; - ((ComplexAPFloat*)(void*)Data)->Imag = I; + ((ComplexAPFloat*)(char*)Data)->Real = R; + ((ComplexAPFloat*)(char*)Data)->Imag = I; } void setLValue(Expr *B, uint64_t O) { assert(isLValue() && "Invalid accessor"); - ((LV*)(void*)Data)->Base = B; - ((LV*)(void*)Data)->Offset = O; + ((LV*)(char*)Data)->Base = B; + ((LV*)(char*)Data)->Offset = O; } - + const APValue &operator=(const APValue &RHS); - + private: void MakeUninit(); void MakeInt() { @@ -218,27 +219,27 @@ private: } void MakeFloat() { assert(isUninit() && "Bad state change"); - new ((APFloat*)(void*)Data) APFloat(0.0); + new ((void*)(char*)Data) APFloat(0.0); Kind = Float; } void MakeVector() { assert(isUninit() && "Bad state change"); - new ((Vec*)(void*)Data) Vec(); + new ((void*)(char*)Data) Vec(); Kind = Vector; } void MakeComplexInt() { assert(isUninit() && "Bad state change"); - new ((ComplexAPSInt*)(void*)Data) ComplexAPSInt(); + new ((void*)(char*)Data) ComplexAPSInt(); Kind = ComplexInt; } void MakeComplexFloat() { assert(isUninit() && "Bad state change"); - new ((ComplexAPFloat*)(void*)Data) ComplexAPFloat(); + new ((void*)(char*)Data) ComplexAPFloat(); Kind = ComplexFloat; } void MakeLValue() { assert(isUninit() && "Bad state change"); - new ((LV*)(void*)Data) LV(); + new ((void*)(char*)Data) LV(); Kind = LValue; } }; @@ -247,7 +248,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const APValue &V) { V.print(OS); return OS; } - + } // end namespace clang. #endif |