mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[ddc] Print AST of compiled libraries with summarize-text flag.
Moves dart2js DebugPrinter and Indentation to pkg/kernel/lib/text and produces the AST of compiled libraries when ddc is run using the --summarize-text flag. Change-Id: I195ff99a0929ac12791b4f7b6c5e755b19065c23 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208460 Commit-Queue: Riley Porter <rileyporter@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
1689a82229
commit
b36dcbf00b
13 changed files with 29 additions and 22 deletions
|
@ -7,9 +7,10 @@
|
|||
|
||||
library dart2js.helpers;
|
||||
|
||||
import 'package:kernel/text/indentation.dart' show Indentation;
|
||||
|
||||
import '../common.dart';
|
||||
import '../diagnostics/invariant.dart' show DEBUG_MODE;
|
||||
import '../util/util.dart';
|
||||
|
||||
export 'debug_collection.dart';
|
||||
export 'expensive_map.dart';
|
||||
|
@ -89,6 +90,7 @@ ReportHere get reportHere {
|
|||
|
||||
/// Implementation of [reportHere]
|
||||
_reportHere(DiagnosticReporter reporter, Spannable node, String debugMessage) {
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
reporter.reportInfoMessage(
|
||||
node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'});
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import 'dart:async' show EventSink;
|
|||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:kernel/text/indentation.dart' show Indentation;
|
||||
|
||||
import '../../compiler.dart';
|
||||
import '../common.dart';
|
||||
import '../compiler.dart' show Compiler;
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
library js.debug;
|
||||
|
||||
import 'package:js_ast/js_ast.dart';
|
||||
import 'package:kernel/text/indentation.dart' show Indentation, Tagging;
|
||||
|
||||
import '../io/code_output.dart' show BufferedCodeOutput;
|
||||
import '../util/util.dart' show Indentation, Tagging;
|
||||
|
||||
/// Unparse the JavaScript [node].
|
||||
String nodeToString(Node node, {bool pretty: false}) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:kernel/ast.dart' as ir;
|
|||
import 'package:kernel/class_hierarchy.dart' as ir;
|
||||
import 'package:kernel/core_types.dart' as ir;
|
||||
import 'package:kernel/src/bounds_checks.dart' as ir;
|
||||
|
||||
import 'package:kernel/text/debug_printer.dart';
|
||||
import 'package:kernel/type_environment.dart' as ir;
|
||||
|
||||
import '../closure.dart' show BoxLocal, ThisLocal;
|
||||
|
@ -27,7 +27,6 @@ import '../environment.dart';
|
|||
import '../ir/cached_static_type.dart';
|
||||
import '../ir/closure.dart';
|
||||
import '../ir/constants.dart';
|
||||
import '../ir/debug.dart';
|
||||
import '../ir/element_map.dart';
|
||||
import '../ir/types.dart';
|
||||
import '../ir/visitors.dart';
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:kernel/ast.dart' as ir;
|
|||
import 'package:kernel/class_hierarchy.dart' as ir;
|
||||
import 'package:kernel/core_types.dart' as ir;
|
||||
import 'package:kernel/src/bounds_checks.dart' as ir;
|
||||
import 'package:kernel/text/debug_printer.dart';
|
||||
import 'package:kernel/type_environment.dart' as ir;
|
||||
|
||||
import '../common.dart';
|
||||
|
@ -26,7 +27,6 @@ import '../environment.dart';
|
|||
import '../frontend_strategy.dart';
|
||||
import '../ir/annotations.dart';
|
||||
import '../ir/constants.dart';
|
||||
import '../ir/debug.dart';
|
||||
import '../ir/element_map.dart';
|
||||
import '../ir/impact.dart';
|
||||
import '../ir/impact_data.dart';
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
library tracer;
|
||||
|
||||
import 'package:kernel/text/indentation.dart' show Indentation;
|
||||
|
||||
import '../compiler_new.dart' as api;
|
||||
import 'options.dart' show CompilerOptions;
|
||||
import 'ssa/nodes.dart' as ssa show HGraph;
|
||||
import 'ssa/ssa_tracer.dart' show HTracer;
|
||||
import 'util/util.dart' show Indentation;
|
||||
import 'world.dart' show JClosedWorld;
|
||||
|
||||
String TRACE_FILTER_PATTERN_FOR_TEST;
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
library dart2js.util;
|
||||
|
||||
import 'package:front_end/src/api_unstable/dart2js.dart'
|
||||
show $BACKSLASH, $CR, $DEL, $DQ, $LF, $LS, $PS, $TAB, Link;
|
||||
show $BACKSLASH, $CR, $DEL, $DQ, $LF, $LS, $PS, $TAB;
|
||||
|
||||
export 'maplet.dart';
|
||||
export 'setlet.dart';
|
||||
|
||||
part 'indentation.dart';
|
||||
|
||||
/// Helper functions for creating hash codes.
|
||||
class Hashing {
|
||||
/// If an integer is masked by this constant, the result is guaranteed to be
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'package:kernel/core_types.dart';
|
|||
import 'package:kernel/kernel.dart';
|
||||
import 'package:kernel/target/targets.dart';
|
||||
import 'package:kernel/text/ast_to_text.dart' as kernel show Printer;
|
||||
import 'package:kernel/text/debug_printer.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:source_maps/source_maps.dart' show SourceMapBuilder;
|
||||
|
||||
|
@ -88,7 +89,7 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
..addOption('packages', help: 'The package spec file to use.')
|
||||
// TODO(jmesserly): is this still useful for us, or can we remove it now?
|
||||
..addFlag('summarize-text',
|
||||
help: 'Emit API summary in a .js.txt file.',
|
||||
help: 'Emit API summary and AST in .js.txt and .ast.xml files.',
|
||||
defaultsTo: false,
|
||||
hide: true)
|
||||
..addFlag('track-widget-creation',
|
||||
|
@ -413,6 +414,8 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
var sb = StringBuffer();
|
||||
kernel.Printer(sb).writeComponentFile(component);
|
||||
outFiles.add(File(outPaths.first + '.txt').writeAsString(sb.toString()));
|
||||
outFiles.add(File(outPaths.first.split('.')[0] + '.ast.xml')
|
||||
.writeAsString(DebugPrinter.prettyPrint(compiledLibraries)));
|
||||
}
|
||||
|
||||
final importToSummary = Map<Library, Component>.identity();
|
||||
|
|
|
@ -299,6 +299,7 @@ deemed
|
|||
deepest
|
||||
deeply
|
||||
def
|
||||
defaulting
|
||||
degrades
|
||||
degree
|
||||
del
|
||||
|
@ -821,6 +822,7 @@ offs
|
|||
ogham
|
||||
oked
|
||||
op
|
||||
opens
|
||||
opt
|
||||
optimizations
|
||||
opting
|
||||
|
@ -1037,6 +1039,7 @@ res
|
|||
residue
|
||||
resource
|
||||
respond
|
||||
restoring
|
||||
restriction
|
||||
resumed
|
||||
ret
|
||||
|
@ -1211,6 +1214,7 @@ synth
|
|||
t
|
||||
tagged
|
||||
tagger
|
||||
tagging
|
||||
tags
|
||||
tailor
|
||||
taking
|
||||
|
|
|
@ -8,14 +8,14 @@ library kernel.debug;
|
|||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
||||
import '../util/util.dart' show Indentation, Tagging;
|
||||
import 'indentation.dart' show Indentation, Tagging;
|
||||
|
||||
class DebugPrinter extends Visitor<void>
|
||||
with Indentation, Tagging<Node>, VisitorVoidMixin {
|
||||
@override
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
void visitNodeWithChildren(Node node, String type, [Map params]) {
|
||||
void visitNodeWithChildren(Node node, String type, [Map? params]) {
|
||||
openNode(node, type, params);
|
||||
node.visitChildren(this);
|
||||
closeNode();
|
||||
|
@ -102,7 +102,7 @@ class DebugPrinter extends Visitor<void>
|
|||
|
||||
/// Pretty-prints given node tree into string.
|
||||
static String prettyPrint(Node node) {
|
||||
var p = new DebugPrinter();
|
||||
DebugPrinter p = new DebugPrinter();
|
||||
node.accept(p);
|
||||
return p.sb.toString();
|
||||
}
|
|
@ -2,9 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.12
|
||||
|
||||
part of dart2js.util;
|
||||
import 'package:_fe_analyzer_shared/src/util/link.dart' show Link;
|
||||
|
||||
/// Indentation utility class. Should be used as a mixin in most cases.
|
||||
class Indentation {
|
||||
|
@ -48,7 +46,7 @@ class Indentation {
|
|||
/// upon return of [f] and returning its result.
|
||||
indentBlock(Function f) {
|
||||
indentMore();
|
||||
var result = f();
|
||||
dynamic result = f();
|
||||
indentLess();
|
||||
return result;
|
||||
}
|
||||
|
@ -135,5 +133,5 @@ abstract class Tagging<N> implements Indentation {
|
|||
}
|
||||
|
||||
/// Converts a parameter value into a string.
|
||||
String valueToString(var value) => value;
|
||||
String valueToString(dynamic value) => value;
|
||||
}
|
|
@ -8,6 +8,8 @@ publish_to: none
|
|||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
_fe_analyzer_shared:
|
||||
path: ../_fe_analyzer_shared
|
||||
dev_dependencies:
|
||||
args: '>=0.13.4 <2.0.0'
|
||||
expect:
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// 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.
|
||||
|
||||
// @dart = 2.7
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'package:compiler/src/util/util.dart' show Indentation;
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:kernel/text/indentation.dart' show Indentation;
|
||||
|
||||
main() {
|
||||
Indentation ind = new Indentation();
|
Loading…
Reference in a new issue