From b0fcc59e19508dca2dc809fb5c83e19c4d3e9ffc Mon Sep 17 00:00:00 2001 From: Ken Dyck Date: Fri, 11 Feb 2011 01:54:29 +0000 Subject: Add a helper function, ASTContext::toBits(), that converts sizes in CharUnits to sizes in bits, and use it to tidy up the places where the conversion was done explicitly. llvm-svn: 125332 --- clang/lib/AST/ASTContext.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'clang/lib/AST/ASTContext.cpp') diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 6b267432586..03c0abd3c62 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -847,7 +847,7 @@ ASTContext::getTypeInfo(const Type *T) const { case Type::ObjCInterface: { const ObjCInterfaceType *ObjCI = cast(T); const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); - Width = Layout.getSize().getQuantity() * getCharWidth(); + Width = toBits(Layout.getSize()); Align = Layout.getAlignment(); break; } @@ -866,7 +866,7 @@ ASTContext::getTypeInfo(const Type *T) const { const RecordType *RT = cast(TT); const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); - Width = Layout.getSize().getQuantity() * getCharWidth(); + Width = toBits(Layout.getSize()); Align = Layout.getAlignment(); break; } @@ -923,6 +923,11 @@ CharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { return CharUnits::fromQuantity(BitSize / getCharWidth()); } +/// toBits - Convert a size in characters to a size in characters. +int64_t ASTContext::toBits(CharUnits CharSize) const { + return CharSize.getQuantity() * 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 { -- cgit v1.2.3