|
| 1 | +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +library dart2js.js_model.type_recipe; |
| 6 | + |
| 7 | +import '../elements/types.dart'; |
| 8 | + |
| 9 | +/// A TypeEnvironmentStructure describes the shape or layout of a reified type |
| 10 | +/// environment. |
| 11 | +/// |
| 12 | +/// A type environment maps type parameter variables to type values. The type |
| 13 | +/// variables are mostly elided in the runtime representation, replaced by |
| 14 | +/// indexes into the reified environment. |
| 15 | +abstract class TypeEnvironmentStructure {} |
| 16 | + |
| 17 | +/// A singleton type environment maps a binds a single value. |
| 18 | +class SingletonTypeEnvironmentStructure extends TypeEnvironmentStructure { |
| 19 | + final TypeVariableType variable; |
| 20 | + |
| 21 | + SingletonTypeEnvironmentStructure(this.variable); |
| 22 | + |
| 23 | + @override |
| 24 | + String toString() => 'SingletonTypeEnvironmentStructure($variable)'; |
| 25 | +} |
| 26 | + |
| 27 | +/// A type environment containing an interface type and/or a tuple of function |
| 28 | +/// type parameters. |
| 29 | +class FullTypeEnvironmentStructure extends TypeEnvironmentStructure { |
| 30 | + final InterfaceType classType; |
| 31 | + final List<TypeVariableType> bindings; |
| 32 | + |
| 33 | + FullTypeEnvironmentStructure({this.classType, this.bindings = const []}); |
| 34 | + |
| 35 | + @override |
| 36 | + String toString() => 'FullTypeEnvironmentStructure($classType, $bindings)'; |
| 37 | +} |
| 38 | + |
| 39 | +/// A TypeRecipe is evaluated against a type environment to produce either a |
| 40 | +/// type, or another type environment. |
| 41 | +abstract class TypeRecipe {} |
| 42 | + |
| 43 | +/// A recipe that yields a reified type. |
| 44 | +class TypeExpressionRecipe extends TypeRecipe { |
| 45 | + final DartType type; |
| 46 | + |
| 47 | + TypeExpressionRecipe(this.type); |
| 48 | + |
| 49 | + @override |
| 50 | + String toString() => 'TypeExpressionRecipe($type)'; |
| 51 | +} |
| 52 | + |
| 53 | +/// A recipe that yields a reified type environment. |
| 54 | +abstract class TypeEnvironmentRecipe extends TypeRecipe {} |
| 55 | + |
| 56 | +/// A recipe that yields a reified type environment that binds a single generic |
| 57 | +/// function type parameter. |
| 58 | +class SingletonTypeEnvironmentRecipe extends TypeEnvironmentRecipe { |
| 59 | + final DartType type; |
| 60 | + |
| 61 | + SingletonTypeEnvironmentRecipe(this.type); |
| 62 | + |
| 63 | + @override |
| 64 | + String toString() => 'SingletonTypeEnvironmentRecipe($type)'; |
| 65 | +} |
| 66 | + |
| 67 | +/// A recipe that yields a reified type environment that binds a class instance |
| 68 | +/// type and/or a tuple of types, usually generic function type arguments. |
| 69 | +/// |
| 70 | +/// With no class is also used as a tuple of types. |
| 71 | +class FullTypeEnvironmentRecipe extends TypeEnvironmentRecipe { |
| 72 | + /// Type expression for the interface type of a class scope. `null` for |
| 73 | + /// environments outside a class scope or a class scope where no supertype is |
| 74 | + /// generic, or where optimization has determined that no use of the |
| 75 | + /// environment requires any of the class type variables. |
| 76 | + final InterfaceType classType; |
| 77 | + |
| 78 | + // Type expressions for the tuple of function type arguments. |
| 79 | + final List<DartType> types; |
| 80 | + |
| 81 | + FullTypeEnvironmentRecipe({this.classType, this.types = const []}); |
| 82 | + |
| 83 | + @override |
| 84 | + String toString() => 'FullTypeEnvironmentRecipe($classType, $types)'; |
| 85 | +} |
0 commit comments