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

Unified Diff: pkg/compiler/lib/src/tree/prettyprint.dart

Issue 1196433002: Create and test source mapping for invocations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 5 years, 6 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 | « pkg/compiler/lib/src/ssa/nodes.dart ('k') | pkg/compiler/lib/src/use_unused_api.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/tree/prettyprint.dart
diff --git a/pkg/compiler/lib/src/tree/prettyprint.dart b/pkg/compiler/lib/src/tree/prettyprint.dart
index f01963b663a7c29a8b6e4828136aa5ce47dfff2a..ab4c87c8883f6aa05b0e255fd2b3c96e1f1fff35 100644
--- a/pkg/compiler/lib/src/tree/prettyprint.dart
+++ b/pkg/compiler/lib/src/tree/prettyprint.dart
@@ -10,100 +10,18 @@ part of tree;
* TODO(smok): Add main() to run from command-line to print out tree for given
* .dart file.
*/
-class PrettyPrinter extends Indentation implements Visitor {
-
- StringBuffer sb;
- Link<String> tagStack;
-
- PrettyPrinter() :
- sb = new StringBuffer(),
- tagStack = const Link<String>();
-
- void pushTag(String tag) {
- tagStack = tagStack.prepend(tag);
- indentMore();
- }
-
- String popTag() {
- assert(!tagStack.isEmpty);
- String tag = tagStack.head;
- tagStack = tagStack.tail;
- indentLess();
- return tag;
- }
-
- /**
- * Adds given string to result string.
- */
- void add(String string) {
- sb.write(string);
- }
-
- void addBeginAndEndTokensToParams(Node node, Map params) {
+class PrettyPrinter extends Indentation with Tagging<Node> implements Visitor {
+ @override
+ void addDefaultParameters(Node node, Map params) {
params['getBeginToken'] = tokenToStringOrNull(node.getBeginToken());
params['getEndToken'] = tokenToStringOrNull(node.getEndToken());
}
- /**
- * Adds given node type to result string.
- * The method "opens" the node, meaning that all output after calling
- * this method and before calling closeNode() will represent contents
- * of given node.
- */
- void openNode(Node node, String type, [Map params]) {
- if (params == null) params = new Map();
- addCurrentIndent();
- sb.write("<");
- addBeginAndEndTokensToParams(node, params);
- addTypeWithParams(type, params);
- sb.write(">\n");
- pushTag(type);
- }
-
- /**
- * Adds given node to result string.
- */
- void openAndCloseNode(Node node, String type, [Map params]) {
- if (params == null) params = new Map();
- addCurrentIndent();
- sb.write("<");
- addBeginAndEndTokensToParams(node, params);
- addTypeWithParams(type, params);
- sb.write("/>\n");
- }
-
- /**
- * Closes current node type.
- */
- void closeNode() {
- String tag = popTag();
- addCurrentIndent();
- sb.write("</");
- addTypeWithParams(tag);
- sb.write(">\n");
- }
-
- void addTypeWithParams(String type, [Map params]) {
- if (params == null) params = new Map();
- sb.write("${type}");
- params.forEach((k, v) {
- String value;
- if (v != null) {
- var str = v;
- if (v is Token) str = v.value;
- value = str
- .replaceAll("<", "&lt;")
- .replaceAll(">", "&gt;")
- .replaceAll('"', "'");
- } else {
- value = "[null]";
- }
- sb.write(' $k="$value"');
- });
- }
-
- void addCurrentIndent() {
- sb.write(indentation);
+ String valueToString(var value) {
+ if (value is Token) {
+ return value.value;
+ }
+ return value;
}
/**
« no previous file with comments | « pkg/compiler/lib/src/ssa/nodes.dart ('k') | pkg/compiler/lib/src/use_unused_api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698