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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/kernel/lib/testing/mock_sdk_program.dart
diff --git a/pkg/kernel/lib/testing/mock_sdk_program.dart b/pkg/kernel/lib/testing/mock_sdk_program.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8b375cae5d0e196cc3e0d4727a774afda83ce476
--- /dev/null
+++ b/pkg/kernel/lib/testing/mock_sdk_program.dart
@@ -0,0 +1,66 @@
+// Copyright (c) 2017, 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:kernel/ast.dart';
+
+/// Returns a [Program] object containing empty definitions of core SDK classes.
+Program createMockSdkProgram() {
+ var coreLib = new Library(Uri.parse('dart:core'));
+ var asyncLib = new Library(Uri.parse('dart:async'));
+ var internalLib = new Library(Uri.parse('dart:_internal'));
+
+ Class addClass(Library lib, Class c) {
+ lib.addClass(c);
+ return c;
+ }
+
+ var objectClass = addClass(coreLib, new Class(name: 'Object'));
+ var objectType = objectClass.rawType;
+
+ TypeParameter typeParam(String name, [DartType bound]) {
+ return new TypeParameter(name, bound ?? objectType);
+ }
+
+ Class class_(String name,
+ {Supertype supertype,
+ List<TypeParameter> typeParameters,
+ List<Supertype> implementedTypes}) {
+ return new Class(
+ name: name,
+ supertype: supertype ?? objectClass.asThisSupertype,
+ typeParameters: typeParameters,
+ implementedTypes: implementedTypes);
+ }
+
+ addClass(coreLib, class_('Null'));
+ addClass(coreLib, class_('bool'));
+ var num = addClass(coreLib, class_('num'));
+ addClass(coreLib, class_('String'));
+ var iterable =
+ addClass(coreLib, class_('Iterable', typeParameters: [typeParam('T')]));
+ {
+ var T = typeParam('T');
+ addClass(
+ coreLib,
+ class_('List', typeParameters: [
+ T
+ ], implementedTypes: [
+ new Supertype(iterable, [new TypeParameterType(T)])
+ ]));
+ }
+ addClass(
+ coreLib, class_('Map', typeParameters: [typeParam('K'), typeParam('V')]));
+ addClass(coreLib, class_('int', supertype: num.asThisSupertype));
+ addClass(coreLib, class_('double', supertype: num.asThisSupertype));
+ addClass(coreLib, class_('Iterator', typeParameters: [typeParam('T')]));
+ addClass(coreLib, class_('Symbol'));
+ addClass(coreLib, class_('Type'));
+ addClass(coreLib, class_('Function'));
+ addClass(coreLib, class_('Invocation'));
+ addClass(asyncLib, class_('Future', typeParameters: [typeParam('T')]));
+ addClass(asyncLib, class_('Stream', typeParameters: [typeParam('T')]));
+ addClass(internalLib, class_('Symbol'));
+
+ return new Program([coreLib, asyncLib, internalLib]);
+}

Powered by Google App Engine
This is Rietveld 408576698