diff options
author | Ken Dyck <ken.dyck@onsemi.com> | 2011-01-15 18:38:59 +0000 |
---|---|---|
committer | Ken Dyck <ken.dyck@onsemi.com> | 2011-01-15 18:38:59 +0000 |
commit | eb6f5dc86531f794ba7746a2da4d28e37cf5da7e (patch) | |
tree | f18474d03690d020845248bc2aa1b2064acbb212 | |
parent | 2d78c374508dc1f4595fe5172b39bf51b07aa48c (diff) |
Add toCharUnitsInBits() to simplify the many calls to CharUnits::fromQuantity() of the form CharUnits::fromQuantity(bitSize, Context.getCharWidth()).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123542 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/ASTContext.h | 3 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 19 |
2 files changed, 15 insertions, 7 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 97388dc090..9d9147e546 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -1006,6 +1006,9 @@ public: return getTypeSize(CharTy); } + /// toCharUnitsFromBits - Convert a size in bits to a size in characters. + CharUnits toCharUnitsFromBits(int64_t BitSize) const; + /// getTypeSizeInChars - Return the size of the specified type, in characters. /// This method does not work on incomplete types. CharUnits getTypeSizeInChars(QualType T) const; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a18247d7ce..2e1a8c2d4b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -592,14 +592,14 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const { } } - return CharUnits::fromQuantity(Align / Target.getCharWidth()); + return toCharUnitsFromBits(Align); } std::pair<CharUnits, CharUnits> ASTContext::getTypeInfoInChars(const Type *T) { std::pair<uint64_t, unsigned> Info = getTypeInfo(T); - return std::make_pair(CharUnits::fromQuantity(Info.first / getCharWidth()), - CharUnits::fromQuantity(Info.second / getCharWidth())); + return std::make_pair(toCharUnitsFromBits(Info.first), + toCharUnitsFromBits(Info.second)); } std::pair<CharUnits, CharUnits> @@ -862,22 +862,27 @@ ASTContext::getTypeInfo(const Type *T) const { return std::make_pair(Width, Align); } +/// toCharUnitsFromBits - Convert a size in bits to a size in characters. +CharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { + return CharUnits::fromQuantity(BitSize / getCharWidth()); +} + /// getTypeSizeInChars - Return the size of the specified type, in characters. /// This method does not work on incomplete types. CharUnits ASTContext::getTypeSizeInChars(QualType T) const { - return CharUnits::fromQuantity(getTypeSize(T) / getCharWidth()); + return toCharUnitsFromBits(getTypeSize(T)); } CharUnits ASTContext::getTypeSizeInChars(const Type *T) const { - return CharUnits::fromQuantity(getTypeSize(T) / getCharWidth()); + return toCharUnitsFromBits(getTypeSize(T)); } /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in /// characters. This method does not work on incomplete types. CharUnits ASTContext::getTypeAlignInChars(QualType T) const { - return CharUnits::fromQuantity(getTypeAlign(T) / getCharWidth()); + return toCharUnitsFromBits(getTypeAlign(T)); } CharUnits ASTContext::getTypeAlignInChars(const Type *T) const { - return CharUnits::fromQuantity(getTypeAlign(T) / getCharWidth()); + return toCharUnitsFromBits(getTypeAlign(T)); } /// getPreferredTypeAlign - Return the "preferred" alignment of the specified |