< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/tree/LayoutUtils.java

Print this page




 217         for (Cursor c : fieldTypes.collect(Collectors.toList())) {
 218             boolean isBitfield = c.isBitField();
 219             if (isBitfield && c.getBitFieldWidth() == 0) continue;
 220             long expectedOffset = offsetOf(parent, c);
 221             if (expectedOffset > offset) {
 222                 if (isUnion) {
 223                     throw new IllegalStateException("No padding in union elements!");
 224                 }
 225                 fieldLayouts.add(Padding.of(expectedOffset - offset));
 226                 actualSize += (expectedOffset - offset);
 227                 offset = expectedOffset;
 228             }
 229             if (isBitfield && !isUnion && pendingBitfieldStart == -1) {
 230                 pendingBitfieldStart = fieldLayouts.size();
 231             }
 232             if (!isBitfield && pendingBitfieldStart >= 0) {
 233                 //emit/replace bitfields
 234                 replaceBitfields(fieldLayouts, pendingBitfieldStart);
 235                 pendingBitfieldStart = -1;
 236             }
 237             Layout fieldLayout = (c.isAnonymous()) ?
 238                     getRecordLayoutInternal(offset, parent, c.type(), fieldMapper) :
 239                     fieldLayout(isUnion, c, fieldMapper);
 240             fieldLayouts.add(fieldLayout);
 241             long size = fieldSize(isUnion, c);
 242             if (isUnion) {
 243                 actualSize = Math.max(actualSize, size);
 244             } else {
 245                 offset += size;
 246                 actualSize += size;
 247             }
 248         }
 249         long expectedSize = t.size() * 8;
 250         if (actualSize < expectedSize) {
 251             fieldLayouts.add(Padding.of(expectedSize - actualSize));
 252         }
 253         if (pendingBitfieldStart >= 0) {
 254             //emit/replace bitfields
 255             replaceBitfields(fieldLayouts, pendingBitfieldStart);
 256         }
 257         Layout[] fields = fieldLayouts.toArray(new Layout[0]);




 217         for (Cursor c : fieldTypes.collect(Collectors.toList())) {
 218             boolean isBitfield = c.isBitField();
 219             if (isBitfield && c.getBitFieldWidth() == 0) continue;
 220             long expectedOffset = offsetOf(parent, c);
 221             if (expectedOffset > offset) {
 222                 if (isUnion) {
 223                     throw new IllegalStateException("No padding in union elements!");
 224                 }
 225                 fieldLayouts.add(Padding.of(expectedOffset - offset));
 226                 actualSize += (expectedOffset - offset);
 227                 offset = expectedOffset;
 228             }
 229             if (isBitfield && !isUnion && pendingBitfieldStart == -1) {
 230                 pendingBitfieldStart = fieldLayouts.size();
 231             }
 232             if (!isBitfield && pendingBitfieldStart >= 0) {
 233                 //emit/replace bitfields
 234                 replaceBitfields(fieldLayouts, pendingBitfieldStart);
 235                 pendingBitfieldStart = -1;
 236             }
 237             Layout fieldLayout = (c.isAnonymousStruct()) ?
 238                     getRecordLayoutInternal(offset, parent, c.type(), fieldMapper) :
 239                     fieldLayout(isUnion, c, fieldMapper);
 240             fieldLayouts.add(fieldLayout);
 241             long size = fieldSize(isUnion, c);
 242             if (isUnion) {
 243                 actualSize = Math.max(actualSize, size);
 244             } else {
 245                 offset += size;
 246                 actualSize += size;
 247             }
 248         }
 249         long expectedSize = t.size() * 8;
 250         if (actualSize < expectedSize) {
 251             fieldLayouts.add(Padding.of(expectedSize - actualSize));
 252         }
 253         if (pendingBitfieldStart >= 0) {
 254             //emit/replace bitfields
 255             replaceBitfields(fieldLayouts, pendingBitfieldStart);
 256         }
 257         Layout[] fields = fieldLayouts.toArray(new Layout[0]);


< prev index next >