blob: 87ad9f332dd37ab7b18f15c63ca28817335e3e16 [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.
// @dart=2.12
import 'package:kernel/kernel.dart';
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
import 'package:kernel/core_types.dart';
import 'list_factory_specializer.dart';
typedef SpecializerTransformer = TreeNode Function(
StaticInvocation node, Member contextMember);
abstract class BaseSpecializer {
// Populated in constructors of subclasses.
final Map<Member, SpecializerTransformer> transformers = {};
class FactorySpecializer extends BaseSpecializer {
final ListFactorySpecializer _listFactorySpecializer;
FactorySpecializer(CoreTypes coreTypes, ClassHierarchy hierarchy)
: _listFactorySpecializer = ListFactorySpecializer(coreTypes, hierarchy) {
TreeNode transformStaticInvocation(
StaticInvocation invocation, Member contextMember) {
final target =;
final transformer = transformers[target];
if (transformer != null) {
return transformer(invocation, contextMember);
return invocation;