in lib/src/code_generator/writer.dart [161:226]
String generate() {
final s = StringBuffer();
// Reset unique namers to initial state.
_resetUniqueNamersNamers();
// Write file header (if any).
if (header != null) {
s.write(header);
s.write('\n');
}
// Write auto generated declaration.
s.write(makeDoc(
'AUTO GENERATED FILE, DO NOT EDIT.\n\nGenerated by `package:ffigen`.'));
// Write neccesary imports.
for (final lib in libraryImports) {
s.write("import '${lib.importPath}' as ${lib.prefix};");
s.write('\n');
}
/// Write [lookUpBindings].
if (lookUpBindings.isNotEmpty) {
// Write doc comment for wrapper class.
if (classDocComment != null) {
s.write(makeDartDoc(classDocComment!));
}
// Write wrapper classs.
s.write('class $_className{\n');
// Write dylib.
s.write('/// Holds the symbol lookup function.\n');
s.write(
'final $ffiLibraryPrefix.Pointer<T> Function<T extends $ffiLibraryPrefix.NativeType>(String symbolName) $lookupFuncIdentifier;\n');
s.write('\n');
//Write doc comment for wrapper class constructor.
s.write(makeDartDoc('The symbols are looked up in [dynamicLibrary].'));
// Write wrapper class constructor.
s.write(
'$_className($ffiLibraryPrefix.DynamicLibrary dynamicLibrary): $lookupFuncIdentifier = dynamicLibrary.lookup;\n\n');
//Write doc comment for wrapper class named constructor.
s.write(makeDartDoc('The symbols are looked up with [lookup].'));
// Write wrapper class named constructor.
s.write(
'$_className.fromLookup($ffiLibraryPrefix.Pointer<T> Function<T extends $ffiLibraryPrefix.NativeType>(String symbolName) lookup): $lookupFuncIdentifier = lookup;\n\n');
for (final b in lookUpBindings) {
s.write(b.toBindingString(this).string);
}
if (symbolAddressWriter.shouldGenerate) {
s.write(symbolAddressWriter.writeObject(this));
}
s.write('}\n\n');
}
if (symbolAddressWriter.shouldGenerate) {
s.write(symbolAddressWriter.writeClass(this));
}
/// Write [noLookUpBindings].
for (final b in noLookUpBindings) {
s.write(b.toBindingString(this).string);
}
return s.toString();
}