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

Side by Side Diff: vm/snapshot_test.cc

Issue 10697055: Represent tokens as a compressed stream instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
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 unified diff | Download patch | Annotate | Revision Log
« vm/object.cc ('K') | « vm/snapshot.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 738
739 // Create a snapshot object using the buffer. 739 // Create a snapshot object using the buffer.
740 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 740 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
741 741
742 // Read object back from the snapshot. 742 // Read object back from the snapshot.
743 SnapshotReader reader(snapshot, Isolate::Current()); 743 SnapshotReader reader(snapshot, Isolate::Current());
744 Script& serialized_script = Script::Handle(); 744 Script& serialized_script = Script::Handle();
745 serialized_script ^= reader.ReadObject(); 745 serialized_script ^= reader.ReadObject();
746 746
747 // Check if the serialized script object matches the original script. 747 // Check if the serialized script object matches the original script.
748 String& expected_literal = String::Handle();
749 String& actual_literal = String::Handle();
748 String& str = String::Handle(); 750 String& str = String::Handle();
749 str ^= serialized_script.url(); 751 str ^= serialized_script.url();
750 EXPECT(url.Equals(str)); 752 EXPECT(url.Equals(str));
753
751 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 754 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens());
752 const TokenStream& serialized_tokens = 755 const TokenStream& serialized_tokens =
753 TokenStream::Handle(serialized_script.tokens()); 756 TokenStream::Handle(serialized_script.tokens());
754 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length()); 757 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length());
755 String& expected_literal = String::Handle(); 758 TokenStreamIterator expected_iterator(expected_tokens, 0);
Ivan Posva 2012/07/02 22:56:05 I am becoming more and more convinced that this sh
siva 2012/07/04 01:43:02 Done.
756 String& actual_literal = String::Handle(); 759 TokenStreamIterator serialized_iterator(serialized_tokens, 0);
757 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { 760 Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
758 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); 761 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind();
759 expected_literal ^= expected_tokens.LiteralAt(i); 762 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) {
760 actual_literal ^= serialized_tokens.LiteralAt(i); 763 EXPECT_EQ(expected_kind, serialized_kind);
764 expected_literal ^= expected_iterator.CurrentLiteral();
765 actual_literal ^= serialized_iterator.CurrentLiteral();
761 EXPECT(expected_literal.Equals(actual_literal)); 766 EXPECT(expected_literal.Equals(actual_literal));
767 expected_iterator.Advance();
768 serialized_iterator.Advance();
769 expected_kind = expected_iterator.CurrentTokenKind();
770 serialized_kind = serialized_iterator.CurrentTokenKind();
762 } 771 }
772
763 // Check if we are able to generate the source from the token stream. 773 // Check if we are able to generate the source from the token stream.
764 // Rescan this source and compare the token stream to see if they are 774 // Rescan this source and compare the token stream to see if they are
765 // the same. 775 // the same.
766 str ^= serialized_tokens.GenerateSource(); 776 str ^= serialized_tokens.GenerateSource();
767 const String& dummy_key = String::Handle(String::New("")); 777 const String& dummy_key = String::Handle(String::New(""));
768 Scanner scanner(str, dummy_key); 778 Scanner scanner(str, dummy_key);
769 const TokenStream& reconstructed_tokens = 779 const TokenStream& reconstructed_tokens =
770 TokenStream::Handle(TokenStream::New(scanner.GetStream())); 780 TokenStream::Handle(TokenStream::New(scanner.GetStream()));
771 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { 781 expected_iterator.SetCurrentPosition(0);
772 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); 782 TokenStreamIterator reconstructed_iterator(reconstructed_tokens, 0);
773 expected_literal ^= expected_tokens.LiteralAt(i); 783 expected_kind = expected_iterator.CurrentTokenKind();
774 actual_literal ^= reconstructed_tokens.LiteralAt(i); 784 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
785 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) {
786 EXPECT_EQ(expected_kind, reconstructed_kind);
787 expected_literal ^= expected_iterator.CurrentLiteral();
788 actual_literal ^= reconstructed_iterator.CurrentLiteral();
775 EXPECT(expected_literal.Equals(actual_literal)); 789 EXPECT(expected_literal.Equals(actual_literal));
790 expected_iterator.Advance();
791 reconstructed_iterator.Advance();
792 expected_kind = expected_iterator.CurrentTokenKind();
793 reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
776 } 794 }
777 795
778 free(buffer); 796 free(buffer);
779 } 797 }
780 798
781 799
782 // Only ia32 and x64 can run execution tests. 800 // Only ia32 and x64 can run execution tests.
783 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 801 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
784 UNIT_TEST_CASE(FullSnapshot) { 802 UNIT_TEST_CASE(FullSnapshot) {
785 const char* kScriptChars = 803 const char* kScriptChars =
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 EXPECT(Dart_ErrorHasException(result)); 1556 EXPECT(Dart_ErrorHasException(result));
1539 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", 1557 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n",
1540 Dart_GetError(result)); 1558 Dart_GetError(result));
1541 1559
1542 Dart_ExitScope(); 1560 Dart_ExitScope();
1543 } 1561 }
1544 1562
1545 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1563 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1546 1564
1547 } // namespace dart 1565 } // namespace dart
OLDNEW
« vm/object.cc ('K') | « vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698