Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 5657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5668 return raw_ptr()->private_key_; | 5668 return raw_ptr()->private_key_; |
| 5669 } | 5669 } |
| 5670 | 5670 |
| 5671 | 5671 |
| 5672 void TokenStream::SetPrivateKey(const String& value) const { | 5672 void TokenStream::SetPrivateKey(const String& value) const { |
| 5673 StorePointer(&raw_ptr()->private_key_, value.raw()); | 5673 StorePointer(&raw_ptr()->private_key_, value.raw()); |
| 5674 } | 5674 } |
| 5675 | 5675 |
| 5676 | 5676 |
| 5677 RawString* TokenStream::GenerateSource() const { | 5677 RawString* TokenStream::GenerateSource() const { |
| 5678 Iterator iterator(*this, 0); | 5678 Iterator iterator(*this, 0, Iterator::kAllTokens); |
| 5679 const ExternalTypedData& data = ExternalTypedData::Handle(GetStream()); | 5679 const ExternalTypedData& data = ExternalTypedData::Handle(GetStream()); |
| 5680 const GrowableObjectArray& literals = | 5680 const GrowableObjectArray& literals = |
| 5681 GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length())); | 5681 GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length())); |
| 5682 const String& private_key = String::Handle(PrivateKey()); | 5682 const String& private_key = String::Handle(PrivateKey()); |
| 5683 intptr_t private_len = private_key.Length(); | 5683 intptr_t private_len = private_key.Length(); |
| 5684 | 5684 |
| 5685 Token::Kind curr = iterator.CurrentTokenKind(); | 5685 Token::Kind curr = iterator.CurrentTokenKind(); |
| 5686 Token::Kind prev = Token::kILLEGAL; | 5686 Token::Kind prev = Token::kILLEGAL; |
| 5687 // Handles used in the loop. | 5687 // Handles used in the loop. |
| 5688 Object& obj = Object::Handle(); | 5688 Object& obj = Object::Handle(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5729 literal = String::SubString(literal, 0, literal.Length() - private_len); | 5729 literal = String::SubString(literal, 0, literal.Length() - private_len); |
| 5730 } | 5730 } |
| 5731 literals.Add(literal); | 5731 literals.Add(literal); |
| 5732 } else { | 5732 } else { |
| 5733 literals.Add(literal); | 5733 literals.Add(literal); |
| 5734 } | 5734 } |
| 5735 // Determine the separation text based on this current token. | 5735 // Determine the separation text based on this current token. |
| 5736 const String* separator = NULL; | 5736 const String* separator = NULL; |
| 5737 switch (curr) { | 5737 switch (curr) { |
| 5738 case Token::kLBRACE: | 5738 case Token::kLBRACE: |
| 5739 indent++; | |
| 5740 separator = &Symbols::NewLine(); | |
| 5741 break; | |
| 5742 case Token::kRBRACE: | 5739 case Token::kRBRACE: |
| 5743 if (indent == 0) { | |
| 5744 separator = &Symbols::TwoNewlines(); | |
| 5745 } else { | |
| 5746 separator = &Symbols::NewLine(); | |
| 5747 } | |
| 5748 break; | |
| 5749 case Token::kSEMICOLON: | |
| 5750 separator = &Symbols::NewLine(); | |
| 5751 break; | |
| 5752 case Token::kPERIOD: | 5740 case Token::kPERIOD: |
| 5753 case Token::kLPAREN: | |
| 5754 case Token::kLBRACK: | 5741 case Token::kLBRACK: |
| 5755 case Token::kINTERPOL_VAR: | 5742 case Token::kINTERPOL_VAR: |
| 5756 case Token::kINTERPOL_START: | 5743 case Token::kINTERPOL_START: |
| 5757 case Token::kINTERPOL_END: | 5744 case Token::kINTERPOL_END: |
| 5745 case Token::kBIT_NOT: | |
| 5746 break; | |
| 5747 case Token::kLPAREN: | |
| 5748 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.
| |
| 5749 break; | |
| 5750 case Token::kRPAREN: | |
| 5751 indent -= 2; | |
| 5752 separator = &Symbols::Blank(); | |
| 5753 break; | |
| 5754 case Token::kNEWLINE: | |
| 5755 if (prev == Token::kLBRACE) { | |
| 5756 indent++; | |
| 5757 } | |
| 5758 if (next == Token::kRBRACE) { | |
| 5759 indent--; | |
| 5760 } | |
| 5758 break; | 5761 break; |
| 5759 default: | 5762 default: |
| 5760 separator = &Symbols::Blank(); | 5763 separator = &Symbols::Blank(); |
| 5761 break; | 5764 break; |
| 5762 } | 5765 } |
| 5766 | |
| 5763 // Determine whether the separation text needs to be updated based on the | 5767 // Determine whether the separation text needs to be updated based on the |
| 5764 // next token. | 5768 // next token. |
| 5765 switch (next) { | 5769 switch (next) { |
| 5766 case Token::kRBRACE: | 5770 case Token::kRBRACE: |
| 5767 indent--; | |
| 5768 break; | 5771 break; |
| 5769 case Token::kSEMICOLON: | 5772 case Token::kSEMICOLON: |
| 5770 case Token::kPERIOD: | 5773 case Token::kPERIOD: |
| 5771 case Token::kCOMMA: | 5774 case Token::kCOMMA: |
| 5772 case Token::kLPAREN: | 5775 case Token::kLPAREN: |
| 5773 case Token::kRPAREN: | 5776 case Token::kRPAREN: |
| 5774 case Token::kLBRACK: | 5777 case Token::kLBRACK: |
| 5775 case Token::kRBRACK: | 5778 case Token::kRBRACK: |
| 5776 case Token::kINTERPOL_VAR: | 5779 case Token::kINTERPOL_VAR: |
| 5777 case Token::kINTERPOL_START: | 5780 case Token::kINTERPOL_START: |
| 5778 case Token::kINTERPOL_END: | 5781 case Token::kINTERPOL_END: |
| 5779 separator = NULL; | 5782 separator = NULL; |
| 5780 break; | 5783 break; |
| 5781 case Token::kELSE: | 5784 case Token::kELSE: |
| 5782 separator = &Symbols::Blank(); | 5785 separator = &Symbols::Blank(); |
| 5786 break; | |
| 5783 default: | 5787 default: |
| 5784 // Do nothing. | 5788 // Do nothing. |
| 5785 break; | 5789 break; |
| 5786 } | 5790 } |
| 5791 | |
| 5787 // Update the few cases where both tokens need to be taken into account. | 5792 // Update the few cases where both tokens need to be taken into account. |
| 5788 if (((curr == Token::kIF) || (curr == Token::kFOR)) && | 5793 if (((curr == Token::kIF) || (curr == Token::kFOR)) && |
| 5789 (next == Token::kLPAREN)) { | 5794 (next == Token::kLPAREN)) { |
| 5790 separator = &Symbols::Blank(); | 5795 separator = &Symbols::Blank(); |
| 5791 } else if ((curr == Token::kASSIGN) && (next == Token::kLPAREN)) { | 5796 } else if ((curr == Token::kASSIGN) && (next == Token::kLPAREN)) { |
| 5792 separator = &Symbols::Blank(); | 5797 separator = &Symbols::Blank(); |
| 5798 } else if ((curr == Token::kRETURN || | |
| 5799 curr == Token::kCONDITIONAL || | |
| 5800 Token::IsBinaryOperator(curr) || | |
| 5801 Token::IsEqualityOperator(curr)) && (next == Token::kLPAREN)) { | |
| 5802 separator = &Symbols::Blank(); | |
| 5793 } else if ((curr == Token::kLBRACE) && (next == Token::kRBRACE)) { | 5803 } else if ((curr == Token::kLBRACE) && (next == Token::kRBRACE)) { |
| 5794 separator = NULL; | 5804 separator = NULL; |
| 5805 } else if ((curr == Token::kSEMICOLON) && (next != Token::kNEWLINE)) { | |
| 5806 separator = &Symbols::Blank(); | |
| 5795 } | 5807 } |
| 5808 | |
| 5809 // Add the separator. | |
| 5796 if (separator != NULL) { | 5810 if (separator != NULL) { |
| 5797 literals.Add(*separator); | 5811 literals.Add(*separator); |
| 5798 if (separator == &Symbols::NewLine()) { | 5812 } |
| 5813 | |
| 5814 // Account for indentation in case we printed a newline. | |
| 5815 if (curr == Token::kNEWLINE) { | |
| 5799 for (int i = 0; i < indent; i++) { | 5816 for (int i = 0; i < indent; i++) { |
| 5800 literals.Add(Symbols::TwoSpaces()); | 5817 literals.Add(Symbols::TwoSpaces()); |
| 5801 } | 5818 } |
| 5802 } | |
| 5803 } | 5819 } |
| 5820 | |
| 5804 // Setup for next iteration. | 5821 // Setup for next iteration. |
| 5805 prev = curr; | 5822 prev = curr; |
| 5806 curr = next; | 5823 curr = next; |
| 5807 } | 5824 } |
| 5808 const Array& source = Array::Handle(Array::MakeArray(literals)); | 5825 const Array& source = Array::Handle(Array::MakeArray(literals)); |
| 5809 return String::ConcatAll(source); | 5826 return String::ConcatAll(source); |
| 5810 } | 5827 } |
| 5811 | 5828 |
| 5812 | 5829 |
| 5813 intptr_t TokenStream::ComputeSourcePosition(intptr_t tok_pos) const { | 5830 intptr_t TokenStream::ComputeSourcePosition(intptr_t tok_pos) const { |
| (...skipping 9123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14937 return "_MirrorReference"; | 14954 return "_MirrorReference"; |
| 14938 } | 14955 } |
| 14939 | 14956 |
| 14940 | 14957 |
| 14941 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14958 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14942 JSONObject jsobj(stream); | 14959 JSONObject jsobj(stream); |
| 14943 } | 14960 } |
| 14944 | 14961 |
| 14945 | 14962 |
| 14946 } // namespace dart | 14963 } // namespace dart |
| OLD | NEW |