blob: ea955ac1c978c46c10c5a6bd00a21cc9a32237c0 [file] [log] [blame]
// 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 'dart:core' hide MapEntry;
import 'package:kernel/kernel.dart';
import 'package:kernel/core_types.dart';
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/target/targets.dart';
/// A kernel [Target] to configure the Dart Front End for dartdevc.
class DevCompilerTarget extends Target {
bool get strongMode => true; // the only correct answer
String get name => 'dartdevc';
List<String> get extraRequiredLibraries => const [
bool mayDefineRestrictedType(Uri uri) =>
uri.scheme == 'dart' &&
(uri.path == 'core' || uri.path == '_interceptors');
bool enableNative(Uri uri) => uri.scheme == 'dart';
bool get nativeExtensionExpectsString => false;
bool get errorOnUnexactWebIntLiterals => true;
bool get enableNoSuchMethodForwarders => true;
void performModularTransformationsOnLibraries(Component component,
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
{void logger(String msg)}) {}
Expression instantiateInvocation(CoreTypes coreTypes, Expression receiver,
String name, Arguments arguments, int offset, bool isSuper) {
// TODO(jmesserly): preserve source information?
// (These method are synthetic. Also unclear if the offset will correspond
// to the file where the class resides, or the file where the method we're
// mocking resides).
Expression createInvocation(String name, List<Expression> positional) {
// TODO(jmesserly): this uses the implementation _Invocation class,
// because the CFE does not resolve the redirecting factory constructors
// like it would for user code. Our code generator expects all redirecting
// factories to be resolved to the real constructor.
var ctor = coreTypes.index
.getClass('dart:core', '_Invocation')
.firstWhere((c) => == name);
return ConstructorInvocation(ctor, Arguments(positional));
if (name.startsWith('get:')) {
return createInvocation('getter', [SymbolLiteral(name.substring(4))]);
if (name.startsWith('set:')) {
return createInvocation('setter', [
SymbolLiteral(name.substring(4) + '='),
var ctorArgs = <Expression>[SymbolLiteral(name)];
bool isGeneric = arguments.types.isNotEmpty;
if (isGeneric) {
ListLiteral( => TypeLiteral(t)).toList()));
} else {
if (arguments.named.isNotEmpty) {
.map((n) => MapEntry(SymbolLiteral(, n.value))
keyType: coreTypes.symbolClass.rawType));
return createInvocation('method', ctorArgs);
Expression instantiateNoSuchMethodError(CoreTypes coreTypes,
Expression receiver, String name, Arguments arguments, int offset,
{bool isMethod = false,
bool isGetter = false,
bool isSetter = false,
bool isField = false,
bool isLocalVariable = false,
bool isDynamic = false,
bool isSuper = false,
bool isStatic = false,
bool isConstructor = false,
bool isTopLevel = false}) {
// TODO(sigmund): implement;
return InvalidExpression(null);