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

Unified Diff: runtime/vm/object.cc

Issue 10823028: - Improve the formatting of generated source text. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 9912)
+++ runtime/vm/object.cc (working copy)
@@ -4562,9 +4562,13 @@
String& literal = String::Handle();
String& blank = String::Handle(String::New(" "));
String& newline = String::Handle(String::New("\n"));
+ String& two_newlines = String::Handle(String::New("\n\n"));
String& double_quotes = String::Handle(String::New("\""));
+ String& dollar = String::Handle(String::New("$"));
+ String& two_spaces = String::Handle(String::New(" "));
Object& obj = Object::Handle();
Token::Kind kind = iterator.CurrentTokenKind();
+ int indent = 0;
while (kind != Token::kEOS) {
obj = iterator.CurrentToken();
literal = iterator.MakeLiteralToken(obj);
@@ -4584,16 +4588,72 @@
literals.Add(literal);
}
literals.Add(double_quotes);
+ } else if (kind == Token::kINTERPOL_VAR) {
+ literals.Add(double_quotes);
+ literals.Add(dollar);
+ literals.Add(literal);
+ literals.Add(double_quotes);
+ } else if (kind == Token::kINTERPOL_START) {
+ literals.Add(double_quotes);
+ literals.Add(literal);
+ } else if (kind == Token::kINTERPOL_END) {
+ literals.Add(literal);
+ literals.Add(double_quotes);
} else {
literals.Add(literal);
}
- if (kind == Token::kLBRACE) {
- literals.Add(newline);
- } else {
- literals.Add(blank);
+ // Determine the separation text based on this current token.
+ const String* separator = NULL;
+ switch (kind) {
+ case Token::kLBRACE:
+ indent++;
+ separator = &newline;
+ break;
+ case Token::kRBRACE:
+ if (indent == 0) {
+ separator = &two_newlines;
+ } else {
+ separator = &newline;
+ }
+ break;
+ case Token::kSEMICOLON:
+ separator = &newline;
+ break;
+ case Token::kPERIOD:
+ case Token::kLPAREN:
+ break;
+ default:
+ separator = ␣
+ break;
}
+ // Advance the iterator.
iterator.Advance();
kind = iterator.CurrentTokenKind();
+ // Determine whether the separation text needs to be updated based on the
+ // next token.
+ switch (kind) {
+ case Token::kRBRACE:
+ indent--;
+ break;
+ case Token::kSEMICOLON:
+ case Token::kPERIOD:
+ case Token::kCOMMA:
+ case Token::kLPAREN:
+ case Token::kRPAREN:
+ separator = NULL;
+ break;
+ default:
+ // Do nothing.
+ break;
+ }
+ if (separator != NULL) {
+ literals.Add(*separator);
+ if (separator == &newline) {
+ for (int i = 0; i < indent; i++) {
+ literals.Add(two_spaces);
+ }
+ }
+ }
}
const Array& source = Array::Handle(Array::MakeArray(literals));
return String::ConcatAll(source);
« runtime/vm/dart.cc ('K') | « runtime/vm/dart.cc ('k') | runtime/vm/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698