in lib/src/code_generator/compound.dart [105:155]
BindingString toBindingString(Writer w) {
final s = StringBuffer();
final enclosingClassName = name;
if (dartDoc != null) {
s.write(makeDartDoc(dartDoc!));
}
/// Adding [enclosingClassName] because dart doesn't allow class member
/// to have the same name as the class.
final localUniqueNamer = UniqueNamer({enclosingClassName});
/// Marking type names because dart doesn't allow class member to have the
/// same name as a type name used internally.
for (final m in members) {
localUniqueNamer.markUsed(m.type.getDartType(w));
}
/// Write @Packed(X) annotation if struct is packed.
if (isStruct && pack != null) {
s.write('@${w.ffiLibraryPrefix}.Packed($pack)\n');
}
final dartClassName = isStruct ? 'Struct' : 'Union';
// Write class declaration.
s.write(
'class $enclosingClassName extends ${w.ffiLibraryPrefix}.${isOpaque ? 'Opaque' : dartClassName}{\n');
const depth = ' ';
for (final m in members) {
final memberName = localUniqueNamer.makeUnique(m.name);
if (m.type.broadType == BroadType.ConstantArray) {
s.write(
'$depth@${w.ffiLibraryPrefix}.Array.multi(${_getArrayDimensionLengths(m.type)})\n');
s.write(
'${depth}external ${_getInlineArrayTypeString(m.type, w)} $memberName;\n\n');
} else {
if (m.dartDoc != null) {
s.write(depth + '/// ');
s.writeAll(m.dartDoc!.split('\n'), '\n' + depth + '/// ');
s.write('\n');
}
if (!m.type.sameDartAndCType(w)) {
s.write('$depth@${m.type.getCType(w)}()\n');
}
s.write('${depth}external ${m.type.getDartType(w)} $memberName;\n\n');
}
}
s.write('}\n\n');
return BindingString(
type: isStruct ? BindingStringType.struc : BindingStringType.union,
string: s.toString());
}