blob: ada848efcd5f2d482116d04c1b3f5f6c176b9ed7 [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;
String? usr,
String? originalName,
String? dartDoc,
required String name,
required this.type,
}) : super(
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) {
sb.write('typedef $name = ${type.getCType(w)};\n');
return BindingString(
type: BindingStringType.typeDef, string: sb.toString());