[cfe-dev] Adding getTypeSizeInBytes to ASTContext
Ken Dyck
Ken.Dyck at onsemi.com
Mon Nov 23 11:12:25 PST 2009
Sprinkled throughout clang are expressions of the form:
size = Context.getTypeSize(SomeType) / 8;
These expressions quite obviously assume that the width of a byte is 8
bits.
As a first step in eliminating this assumption and someday supporting
targets with byte widths other than 8 bits, the attached patch
introduces two new methods to ASTContext.
1. getByteSize(): returns the width of the target's character type (on
all existing targets it returns 8).
2: getTypeSizeInBytes(T): returns getTypeSize(T) / getByteSize(T),
i.e. the size of a given type in bytes.
With this patch applied, the above snippet could be replaced with:
size = Context.getTypeSizeInBytes(SomeType);
The getByteSize() method is intended for use by a follow-on patch that
will introduce getTypeAlignInBytes() and to replace literal 8s in other
parts of the code.
Any objections? Comments?
-Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASTContext-getTypeSizeInBytes.r89592.patch
Type: application/octet-stream
Size: 890 bytes
Desc: ASTContext-getTypeSizeInBytes.r89592.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091123/3b617996/attachment.obj>
More information about the cfe-dev
mailing list