Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: pkg/kernel/lib/testing/mock_sdk_program.dart

Issue 2848083002: Implement Dart 1.0 LUB algorithm (for interface types) in kernel. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import 'package:kernel/ast.dart';
6
7 /// Returns a [Program] object containing empty definitions of core SDK classes.
8 Program createMockSdkProgram() {
9 var coreLib = new Library(Uri.parse('dart:core'));
10 var asyncLib = new Library(Uri.parse('dart:async'));
11 var internalLib = new Library(Uri.parse('dart:_internal'));
12
13 Class addClass(Library lib, Class c) {
14 lib.addClass(c);
15 return c;
16 }
17
18 var objectClass = addClass(coreLib, new Class(name: 'Object'));
19 var objectType = objectClass.rawType;
20
21 TypeParameter typeParam(String name, [DartType bound]) {
22 return new TypeParameter(name, bound ?? objectType);
23 }
24
25 Class class_(String name,
26 {Supertype supertype,
27 List<TypeParameter> typeParameters,
28 List<Supertype> implementedTypes}) {
29 return new Class(
30 name: name,
31 supertype: supertype ?? objectClass.asThisSupertype,
32 typeParameters: typeParameters,
33 implementedTypes: implementedTypes);
34 }
35
36 addClass(coreLib, class_('Null'));
37 addClass(coreLib, class_('bool'));
38 var num = addClass(coreLib, class_('num'));
39 addClass(coreLib, class_('String'));
40 var iterable =
41 addClass(coreLib, class_('Iterable', typeParameters: [typeParam('T')]));
42 {
43 var T = typeParam('T');
44 addClass(
45 coreLib,
46 class_('List', typeParameters: [
47 T
48 ], implementedTypes: [
49 new Supertype(iterable, [new TypeParameterType(T)])
50 ]));
51 }
52 addClass(
53 coreLib, class_('Map', typeParameters: [typeParam('K'), typeParam('V')]));
54 addClass(coreLib, class_('int', supertype: num.asThisSupertype));
55 addClass(coreLib, class_('double', supertype: num.asThisSupertype));
56 addClass(coreLib, class_('Iterator', typeParameters: [typeParam('T')]));
57 addClass(coreLib, class_('Symbol'));
58 addClass(coreLib, class_('Type'));
59 addClass(coreLib, class_('Function'));
60 addClass(coreLib, class_('Invocation'));
61 addClass(asyncLib, class_('Future', typeParameters: [typeParam('T')]));
62 addClass(asyncLib, class_('Stream', typeParameters: [typeParam('T')]));
63 addClass(internalLib, class_('Symbol'));
64
65 return new Program([coreLib, asyncLib, internalLib]);
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698