Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 62a47e4a5d96e267f67c835e632ef0ce0c3a05a9..16d3119ca64d6b12d5992658c286d34c82d9acc5 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -5675,7 +5675,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())); |
| @@ -5736,35 +5736,38 @@ 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; |
| + case Token::kLPAREN: |
| + indent += 2; |
|
Ivan Posva
2013/09/19 23:42:00
Please add comment explaining why this indent is u
Michael Lippautz (Google)
2013/09/20 16:36:29
Done.
|
| + 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: |
| @@ -5780,27 +5783,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; |