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

Unified Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 12446003: Support full dart2js output for dartdoc/apidoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 9 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart
diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart
index 1df0c815457d64e081b3bec5a907f8d0cbc26d88..3c78647e47b276c9cbb939fe44d03161727f2156 100644
--- a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart
+++ b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart
@@ -9,7 +9,7 @@ import 'dart:collection' show LinkedHashMap;
import 'dart:io';
import 'dart:uri';
-import '../../compiler.dart' as diagnostics;
+import '../../compiler.dart' as api;
import '../elements/elements.dart';
import '../resolution/resolution.dart' show ResolverTask, ResolverVisitor;
import '../apiimpl.dart' show Compiler;
@@ -84,8 +84,6 @@ Dart2JsTypeMirror _convertTypeToTypeMirror(
// TODO(johnniwinther): We need a mirror on malformed types.
return system.dynamicType;
}
- _diagnosticListener.internalError(
- "Unexpected type $type of kind ${type.kind}");
system.compiler.internalError("Unexpected type $type of kind ${type.kind}");
}
@@ -193,114 +191,96 @@ String _getOperatorFromOperatorName(String name) {
return newName;
}
-DiagnosticListener get _diagnosticListener {
- return const Dart2JsDiagnosticListener();
-}
-
-class Dart2JsDiagnosticListener implements DiagnosticListener {
- const Dart2JsDiagnosticListener();
-
- void cancel(String reason, {node, token, instruction, element}) {
- print(reason);
- }
-
- void log(message) {
- print(message);
- }
-
- void internalError(String message,
- {Node node, Token token, HInstruction instruction,
- Element element}) {
- cancel('Internal error: $message', node: node, token: token,
- instruction: instruction, element: element);
- }
-
- void internalErrorOnElement(Element element, String message) {
- internalError(message, element: element);
- }
-
- SourceSpan spanFromSpannable(Node node, [Uri uri]) {
- // TODO(johnniwinther): implement this.
- throw 'unimplemented';
- }
-
- void reportMessage(SourceSpan span, Diagnostic message,
- diagnostics.Diagnostic kind) {
- // TODO(johnniwinther): implement this.
- throw 'unimplemented';
- }
-
- bool onDeprecatedFeature(Spannable span, String feature) {
- // TODO(johnniwinther): implement this?
- throw 'unimplemented';
- }
-}
-
//------------------------------------------------------------------------------
// Compilation implementation
//------------------------------------------------------------------------------
-// TODO(johnniwinther): Support client configurable handlers/providers.
-class Dart2JsCompilation implements Compilation {
- Compiler _compiler;
- final Uri cwd;
- final SourceFileProvider provider;
-
- Dart2JsCompilation(Path script, Path libraryRoot,
- [Path packageRoot, List<String> opts = const <String>[]])
- : cwd = getCurrentDirectory(),
- provider = new SourceFileProvider() {
- var handler = new FormattingDiagnosticHandler(provider);
- var libraryUri = cwd.resolve('${libraryRoot}/');
- var packageUri;
- if (packageRoot != null) {
- packageUri = cwd.resolve('${packageRoot}/');
- } else {
- packageUri = libraryUri;
- }
- _compiler = new Compiler(provider.readStringFromUri,
- null,
- handler.diagnosticHandler,
- libraryUri, packageUri, opts);
- var scriptUri = cwd.resolve(script.toString());
- // TODO(johnniwinther): Detect file not found
- _compiler.run(scriptUri);
- }
-
- Dart2JsCompilation.library(List<Path> libraries, Path libraryRoot,
- [Path packageRoot, List<String> opts = const <String>[]])
- : cwd = getCurrentDirectory(),
- provider = new SourceFileProvider() {
- var libraryUri = cwd.resolve('${libraryRoot}/');
- var packageUri;
- if (packageRoot != null) {
- packageUri = cwd.resolve('${packageRoot}/');
- } else {
- packageUri = libraryUri;
- }
- opts = new List<String>.from(opts);
- opts.add('--analyze-signatures-only');
- opts.add('--analyze-all');
- _compiler = new Compiler(provider.readStringFromUri,
- null,
- silentDiagnosticHandler,
- libraryUri, packageUri, opts);
- var librariesUri = <Uri>[];
- for (Path library in libraries) {
- librariesUri.add(cwd.resolve(library.toString()));
- // TODO(johnniwinther): Detect file not found
+// TODO(johnniwinther): Support client configurable providers.
+
+/**
+ * Returns a future that completes to a non-null String when [script]
+ * has been successfully compiled.
+ *
+ * TODO(johnniwinther): The method is deprecated but here to support [Path]
+ * which is used through dartdoc.
+ */
+Future<String> compile(Path script,
+ Path libraryRoot,
+ {Path packageRoot,
+ List<String> options: const <String>[],
+ api.DiagnosticHandler diagnosticHandler}) {
+ Uri cwd = getCurrentDirectory();
+ SourceFileProvider provider = new SourceFileProvider();
+ if (diagnosticHandler == null) {
+ diagnosticHandler =
+ new FormattingDiagnosticHandler(provider).diagnosticHandler;
+ }
+ Uri scriptUri = cwd.resolve(script.toString());
+ Uri libraryUri = cwd.resolve('${libraryRoot}/');
+ Uri packageUri = null;
+ if (packageRoot != null) {
+ packageUri = cwd.resolve('${packageRoot}/');
+ }
+ return api.compile(scriptUri, libraryUri, packageUri,
+ provider.readStringFromUri, diagnosticHandler, options);
+}
+
+/**
+ * Analyzes set of libraries and provides a mirror system which can be used for
+ * static inspection of the source code.
+ */
+Future<MirrorSystem> analyze(List<Path> libraries,
+ Path libraryRoot,
+ {Path packageRoot,
+ List<String> options: const <String>[],
+ api.DiagnosticHandler diagnosticHandler}) {
+ Uri cwd = getCurrentDirectory();
+ SourceFileProvider provider = new SourceFileProvider();
+ if (diagnosticHandler == null) {
+ diagnosticHandler =
+ new FormattingDiagnosticHandler(provider).diagnosticHandler;
+ }
+ Uri libraryUri = cwd.resolve('${libraryRoot}/');
+ Uri packageUri = null;
+ if (packageRoot != null) {
+ packageUri = cwd.resolve('${packageRoot}/');
+ }
+ options = new List<String>.from(options);
+ options.add('--analyze-only');
+ options.add('--analyze-signatures-only');
+ options.add('--analyze-all');
+
+ bool compilationFailed = false;
+ void internalDiagnosticHandler(Uri uri, int begin, int end,
+ String message, api.Diagnostic kind) {
+ if (kind == api.Diagnostic.ERROR ||
+ kind == api.Diagnostic.CRASH) {
+ compilationFailed = true;
}
- _compiler.librariesToAnalyzeWhenRun = librariesUri;
- _compiler.run(null);
+ diagnosticHandler(uri, begin, end, message, kind);
+ }
+
+ // TODO(johnniwinther): Extract the following as an [analyze] method in
+ // [:compiler/compiler.dart:].
+ Compiler compiler = new Compiler(provider.readStringFromUri,
+ null,
+ internalDiagnosticHandler,
+ libraryUri, packageUri, options);
+ List<Uri> librariesUri = <Uri>[];
+ for (Path library in libraries) {
+ librariesUri.add(cwd.resolve(library.toString()));
+ }
+ compiler.librariesToAnalyzeWhenRun = librariesUri;
+ bool success = compiler.run(null);
+ if (success && !compilationFailed) {
+ return new Future<MirrorSystem>.immediate(
+ new Dart2JsMirrorSystem(compiler));
+ } else {
+ return new Future<MirrorSystem>.immediateError(
+ 'Failed to create mirror system.');
}
-
- MirrorSystem get mirrors => new Dart2JsMirrorSystem(_compiler);
-
- Future<String> compileToJavaScript() =>
- new Future<String>.immediate(_compiler.assembledCode);
}
-
//------------------------------------------------------------------------------
// Dart2Js specific extensions of mirror interfaces
//------------------------------------------------------------------------------
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698