Files
sdk/pkg/kernel/lib/kernel.dart
T
Asger Feldthaus 062cb17ec4 [kernel] Strong mode: add interface targets and resynthesis of expression types.
The interface target can now be stored on PropertyGet, PropertySet, and
MethodInvocation  If set, we know the concrete target overrides or
implements that member.

All expressions have a method getStaticType for computing its type,
which relies on interface targets for the expressions that have one.

Expressions whose type is a least upper bound have the type stored
explicitly, so the definition of least upper bounds is contained only
in the frontend.

This is a work in progress towards strong mode support, it is still
not complete.

Still missing in the frontend:
- checks from implicit downcasts
- parameter checks from covariant override or covariant generics

Implemented but not part of this CL:
- subtype tests
- IR type checker (for debugging)

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/496717014 .
2016-09-06 11:40:13 +02:00

111 lines
3.5 KiB
Dart

// Copyright (c) 2016, 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.
/// Conventions for paths:
///
/// - Use the [Uri] class for paths that may have the `file`, `dart` or
/// `package` scheme. Never use [Uri] for relative paths.
/// - Use [String]s for all filenames and paths that have no scheme prefix.
/// - Never translate a `dart:` or `package:` URI into a `file:` URI, instead
/// translate it to a [String] if the file system path is needed.
/// - Only use [File] from dart:io at the last moment when it is needed.
///
library kernel;
import 'analyzer/loader.dart';
import 'ast.dart';
import 'binary/ast_to_binary.dart';
import 'binary/loader.dart';
import 'dart:async';
import 'dart:io';
import 'repository.dart';
import 'text/ast_to_text.dart';
export 'ast.dart';
export 'repository.dart';
Program loadProgramFromBinary(String path) {
Repository repository = new Repository();
return new BinaryLoader(repository).loadProgram(path);
}
/// Load a binary library from [path], unless [repository] already has
/// a loaded version of the library.
///
/// If provided, [repository] is used to link URIs to other [Library] objects.
///
/// [path] is relative to the working directory of the repository, or
/// the current working directory if no repository is given.
Library loadLibraryFromBinary(String path, [Repository repository]) {
repository ??= new Repository();
var library = repository.getLibrary(path);
new BinaryLoader(repository).ensureLibraryIsLoaded(library);
return library;
}
TreeNode loadProgramOrLibraryFromBinary(String path, [Repository repository]) {
repository ??= new Repository();
return new BinaryLoader(repository).loadProgramOrLibrary(path);
}
/// Loads a .dart library from [path], unless [repository] already has
/// a loaded version of that library.
Library loadLibraryFromDart(String path, [Repository repository]) {
repository ??= new Repository();
return new AnalyzerLoader(repository).loadLibrary(path);
}
/// Loads a .dart file from [path] and all of its transitive dependencies.
///
/// The resulting [Program] will have a main method if the library at [path]
/// contains a top-level method named "main", otherwise its main reference will
/// be `null`.
Program loadProgramFromDart(String path, Repository repository,
{bool strongMode: false}) {
return new AnalyzerLoader(repository, strongMode: strongMode)
.loadProgram(path);
}
Future writeLibraryToBinary(Library library, String path) {
var sink = new File(path).openWrite();
var future;
try {
new BinaryPrinter(sink).writeLibraryFile(library);
} finally {
future = sink.close();
}
return future;
}
Future writeProgramToBinary(Program program, String path) {
var sink = new File(path).openWrite();
var future;
try {
new BinaryPrinter(sink).writeProgramFile(program);
} finally {
future = sink.close();
}
return future;
}
void writeLibraryToText(Library library, [String path]) {
StringBuffer buffer = new StringBuffer();
new Printer(buffer).writeLibraryFile(library);
if (path == null) {
print(buffer);
} else {
new File(path).writeAsStringSync('$buffer');
}
}
void writeProgramToText(Program program, [String path]) {
StringBuffer buffer = new StringBuffer();
new Printer(buffer).writeProgramFile(program);
if (path == null) {
print(buffer);
} else {
new File(path).writeAsStringSync('$buffer');
}
}