blob: 73209576281ab5e44c7f2572468a1697052b071b [file] [log] [blame]
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:ffigen/src/code_generator.dart';
import 'binding_string.dart';
import 'type.dart';
import 'utils.dart';
import 'writer.dart';
/// A simple Typealias, Expands to -
/// ```dart
/// typedef $name = $type;
/// );
/// ```
class Typealias extends NoLookUpBinding {
final Type type;
final bool _useDartType;
String? usr,
String? originalName,
String? dartDoc,
required String name,
required this.type,
/// If true, the binding string uses Dart type instead of C type.
/// E.g if C type is ffi.Void func(ffi.Int32), Dart type is void func(int).
bool useDartType = false,
}) : _useDartType = useDartType,
usr: usr,
name: name,
dartDoc: dartDoc,
originalName: originalName,
void addDependencies(Set<Binding> dependencies) {
if (dependencies.contains(this)) return;
BindingString toBindingString(Writer w) {
final sb = StringBuffer();
if (dartDoc != null) {
'typedef $name = ${_useDartType ? type.getDartType(w) : type.getCType(w)};\n');
return BindingString(
type: BindingStringType.typeDef, string: sb.toString());