[cfe-commits] r123542 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp

Ken Dyck ken.dyck at onsemi.com
Sat Jan 15 10:38:59 PST 2011


Author: kjdyck
Date: Sat Jan 15 12:38:59 2011
New Revision: 123542

URL: http://llvm.org/viewvc/llvm-project?rev=123542&view=rev
Log:
Add toCharUnitsInBits() to simplify the many calls to CharUnits::fromQuantity() of the form CharUnits::fromQuantity(bitSize, Context.getCharWidth()).

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=123542&r1=123541&r2=123542&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jan 15 12:38:59 2011
@@ -1006,6 +1006,9 @@
     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;

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=123542&r1=123541&r2=123542&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Jan 15 12:38:59 2011
@@ -592,14 +592,14 @@
     }
   }
 
-  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 @@
   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





More information about the cfe-commits mailing list