blob: 54158a62e6e793038b4915c95603af85b5cbb4fd [file] [log] [blame]
// Copyright (c) 2025, 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:code_builder/code_builder.dart';
import '../interop_gen/namer.dart';
import 'documentation.dart';
import 'types.dart';
class GlobalOptions {
static int variadicArgsCount = 4;
static bool shouldEmitJsTypes = false;
static bool redeclareOverrides = true;
}
class Options {}
class DeclarationOptions extends Options {
bool override;
bool static;
DeclarationOptions({this.override = false, this.static = false});
TypeOptions toTypeOptions({bool nullable = false}) =>
TypeOptions(nullable: nullable);
}
class TypeOptions extends Options {
bool nullable;
String? url;
TypeOptions({this.nullable = false, this.url});
}
class ASTOptions {
bool parameter;
bool emitJSTypes;
int variadicArgsCount;
ASTOptions(
{this.parameter = false,
this.variadicArgsCount = 4,
this.emitJSTypes = false});
}
sealed class Node {
String? get name;
abstract final ID id;
String? get dartName;
Spec emit([Options? options]);
Node();
}
abstract class Declaration extends Node {
@override
String get name;
@override
Spec emit([covariant DeclarationOptions? options]);
}
abstract class NamedDeclaration extends Declaration {
@override
abstract String name;
abstract Documentation? documentation;
ReferredType asReferredType([List<Type>? typeArgs, String? url]) =>
ReferredType(
name: name, declaration: this, typeParams: typeArgs ?? [], url: url);
}
abstract interface class ExportableDeclaration extends Declaration {
/// Whether this declaration is exported.
bool get exported;
@override
abstract String? dartName;
@override
abstract String name;
}
abstract class Type extends Node {
@override
String? dartName;
@override
Reference emit([covariant TypeOptions? options]);
}
abstract class FieldDeclaration extends NamedDeclaration {
abstract final Type type;
}
abstract class CallableDeclaration extends NamedDeclaration {
abstract final List<ParameterDeclaration> parameters;
abstract final List<GenericType> typeParameters;
abstract final Type returnType;
}
enum DeclScope { private, protected, public }
class ParameterDeclaration {
final String name;
final bool optional;
final Type type;
final bool variadic;
ParameterDeclaration(
{required this.name,
this.optional = false,
required this.type,
this.variadic = false});
Parameter emit([DeclarationOptions? options]) {
return Parameter((p) => p
..name = name
..type = type.emit(TypeOptions(nullable: optional)));
}
}