Files
sdk/pkg/kernel/lib/testing/mock_sdk_program.dart
T
Konstantin Shcheglov bdedd6768b Add a way to use shared CanonicalName root to deserialize Program.
This allows for example to add SDK into a Program, then load the
"incomplete" Program A that has only the library A, and name sequences
that references SDK classes. Because we look into the nameRoot which
aleady has SDK CanonicalName(s), we can find these names while filling
the link table and use references which point to the existing SDK
AST nodes.  Then we can load another set of library cycles, etc.

At the end we have a set of self-consistent libraries that we can
feed into DillTarget/DillLoader and resolve anothersource target
against it.

This CL is based on https://codereview.chromium.org/2872903005/
which has not been reviewed yet.

R=kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2874723002 .
2017-05-12 10:42:08 -07:00

68 lines
2.4 KiB
Dart

// 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'), name: 'dart.core');
var asyncLib = new Library(Uri.parse('dart:async'), name: 'dart.async');
var internalLib =
new Library(Uri.parse('dart:_internal'), name: '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(libraries: [coreLib, asyncLib, internalLib]);
}