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

Unified Diff: runtime/vm/object.cc

Issue 24272007: Use newline tokens when generating source from tokenstream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: added comment Created 7 years, 3 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 | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 85f0f08a8bf1618970a3a6163230133e701852b1..7bae66e59fe6ac754f0b027ef312b6be49271c58 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5748,7 +5748,7 @@ void TokenStream::SetPrivateKey(const String& value) const {
RawString* TokenStream::GenerateSource() const {
- Iterator iterator(*this, 0);
+ Iterator iterator(*this, 0, Iterator::kAllTokens);
const ExternalTypedData& data = ExternalTypedData::Handle(GetStream());
const GrowableObjectArray& literals =
GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length()));
@@ -5809,35 +5809,47 @@ RawString* TokenStream::GenerateSource() const {
const String* separator = NULL;
switch (curr) {
case Token::kLBRACE:
- indent++;
- separator = &Symbols::NewLine();
- break;
case Token::kRBRACE:
- if (indent == 0) {
- separator = &Symbols::TwoNewlines();
- } else {
- separator = &Symbols::NewLine();
- }
- break;
- case Token::kSEMICOLON:
- separator = &Symbols::NewLine();
- break;
case Token::kPERIOD:
- case Token::kLPAREN:
case Token::kLBRACK:
case Token::kINTERPOL_VAR:
case Token::kINTERPOL_START:
case Token::kINTERPOL_END:
+ case Token::kBIT_NOT:
+ break;
+ // In case we see an opening parentheses '(' we increase the indent to
+ // align multi-line parameters accordingly. The indent will be removed as
+ // soon as we see the matching closing parentheses ')'.
+ //
+ // Example:
+ // SomeVeryLongMethod(
+ // "withVeryLongParameter",
+ // "andAnotherVeryLongParameter",
+ // "andAnotherVeryLongParameter2") { ...
+ case Token::kLPAREN:
+ indent += 2;
+ break;
+ case Token::kRPAREN:
+ indent -= 2;
+ separator = &Symbols::Blank();
+ break;
+ case Token::kNEWLINE:
+ if (prev == Token::kLBRACE) {
+ indent++;
+ }
+ if (next == Token::kRBRACE) {
+ indent--;
+ }
break;
default:
separator = &Symbols::Blank();
break;
}
+
// Determine whether the separation text needs to be updated based on the
// next token.
switch (next) {
case Token::kRBRACE:
- indent--;
break;
case Token::kSEMICOLON:
case Token::kPERIOD:
@@ -5853,27 +5865,41 @@ RawString* TokenStream::GenerateSource() const {
break;
case Token::kELSE:
separator = &Symbols::Blank();
+ break;
default:
// Do nothing.
break;
}
+
// Update the few cases where both tokens need to be taken into account.
if (((curr == Token::kIF) || (curr == Token::kFOR)) &&
(next == Token::kLPAREN)) {
separator = &Symbols::Blank();
} else if ((curr == Token::kASSIGN) && (next == Token::kLPAREN)) {
separator = &Symbols::Blank();
+ } else if ((curr == Token::kRETURN ||
+ curr == Token::kCONDITIONAL ||
+ Token::IsBinaryOperator(curr) ||
+ Token::IsEqualityOperator(curr)) && (next == Token::kLPAREN)) {
+ separator = &Symbols::Blank();
} else if ((curr == Token::kLBRACE) && (next == Token::kRBRACE)) {
separator = NULL;
+ } else if ((curr == Token::kSEMICOLON) && (next != Token::kNEWLINE)) {
+ separator = &Symbols::Blank();
}
+
+ // Add the separator.
if (separator != NULL) {
literals.Add(*separator);
- if (separator == &Symbols::NewLine()) {
+ }
+
+ // Account for indentation in case we printed a newline.
+ if (curr == Token::kNEWLINE) {
for (int i = 0; i < indent; i++) {
literals.Add(Symbols::TwoSpaces());
}
- }
}
+
// Setup for next iteration.
prev = curr;
curr = next;
« no previous file with comments | « no previous file | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698