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

Side by Side Diff: runtime/vm/object.cc

Issue 2587673004: Include source in kernel. (Closed)
Patch Set: Fixed some rebase errors Created 3 years, 11 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
« no previous file with comments | « runtime/vm/object.h ('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 "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/become.h" 10 #include "vm/become.h"
(...skipping 3459 matching lines...) Expand 10 before | Expand all | Expand 10 after
3470 3470
3471 3471
3472 TokenPosition Class::ComputeEndTokenPos() const { 3472 TokenPosition Class::ComputeEndTokenPos() const {
3473 // Return the begin token for synthetic classes. 3473 // Return the begin token for synthetic classes.
3474 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { 3474 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) {
3475 return token_pos(); 3475 return token_pos();
3476 } 3476 }
3477 Zone* zone = Thread::Current()->zone(); 3477 Zone* zone = Thread::Current()->zone();
3478 const Script& scr = Script::Handle(zone, script()); 3478 const Script& scr = Script::Handle(zone, script());
3479 ASSERT(!scr.IsNull()); 3479 ASSERT(!scr.IsNull());
3480
3481 if (scr.kind() == RawScript::kKernelTag) {
3482 return TokenPosition::kMinSource;
3483 }
3484
3480 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); 3485 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens());
3481 if (tkns.IsNull()) { 3486 if (tkns.IsNull()) {
3482 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); 3487 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
3483 return TokenPosition::kNoSource; 3488 return TokenPosition::kNoSource;
3484 } 3489 }
3485 TokenStream::Iterator tkit(zone, tkns, token_pos(), 3490 TokenStream::Iterator tkit(zone, tkns, token_pos(),
3486 TokenStream::Iterator::kNoNewlines); 3491 TokenStream::Iterator::kNoNewlines);
3487 intptr_t level = 0; 3492 intptr_t level = 0;
3488 while (tkit.CurrentTokenKind() != Token::kEOS) { 3493 while (tkit.CurrentTokenKind() != Token::kEOS) {
3489 if (tkit.CurrentTokenKind() == Token::kLBRACE) { 3494 if (tkit.CurrentTokenKind() == Token::kLBRACE) {
(...skipping 5290 matching lines...) Expand 10 before | Expand all | Expand 10 after
8780 RawString* Script::Source() const { 8785 RawString* Script::Source() const {
8781 String& source = String::Handle(raw_ptr()->source_); 8786 String& source = String::Handle(raw_ptr()->source_);
8782 if (source.IsNull()) { 8787 if (source.IsNull()) {
8783 return GenerateSource(); 8788 return GenerateSource();
8784 } 8789 }
8785 return raw_ptr()->source_; 8790 return raw_ptr()->source_;
8786 } 8791 }
8787 8792
8788 8793
8789 RawString* Script::GenerateSource() const { 8794 RawString* Script::GenerateSource() const {
8795 if (kind() == RawScript::kKernelTag) {
8796 // In kernel it's embedded.
8797 return raw_ptr()->source_;
8798 }
8799
8790 const TokenStream& token_stream = TokenStream::Handle(tokens()); 8800 const TokenStream& token_stream = TokenStream::Handle(tokens());
8791 if (token_stream.IsNull()) { 8801 if (token_stream.IsNull()) {
8792 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); 8802 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT);
8793 return String::null(); 8803 return String::null();
8794 } 8804 }
8795 return token_stream.GenerateSource(); 8805 return token_stream.GenerateSource();
8796 } 8806 }
8797 8807
8798 8808
8799 void Script::set_compile_time_constants(const Array& value) const { 8809 void Script::set_compile_time_constants(const Array& value) const {
8800 StorePointer(&raw_ptr()->compile_time_constants_, value.raw()); 8810 StorePointer(&raw_ptr()->compile_time_constants_, value.raw());
8801 } 8811 }
8802 8812
8803 8813
8804 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { 8814 RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
8805 Zone* zone = Thread::Current()->zone(); 8815 Zone* zone = Thread::Current()->zone();
8806 const GrowableObjectArray& info = 8816 const GrowableObjectArray& info =
8807 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); 8817 GrowableObjectArray::Handle(zone, GrowableObjectArray::New());
8808 const String& source = String::Handle(zone, Source()); 8818 const String& source = String::Handle(zone, Source());
8809 const String& key = Symbols::Empty(); 8819 const String& key = Symbols::Empty();
8810 const Object& line_separator = Object::Handle(zone); 8820 const Object& line_separator = Object::Handle(zone);
8821 Smi& value = Smi::Handle(zone);
8822
8823 if (kind() == RawScript::kKernelTag) {
8824 const Array& line_starts_array = Array::Handle(line_starts());
8825 if (line_starts_array.IsNull()) {
8826 // Scripts in the AOT snapshot do not have a line starts array.
8827 // A well-formed line number array has a leading null.
8828 info.Add(line_separator); // New line.
8829 return info.raw();
8830 }
8831 intptr_t line_count = line_starts_array.Length();
8832 ASSERT(line_count > 0);
8833
8834 for (int i = 0; i < line_count; i++) {
8835 info.Add(line_separator); // New line.
8836 value = Smi::New(i + 1);
8837 info.Add(value); // Line number.
8838 value ^= line_starts_array.At(i);
8839 info.Add(value); // Token position.
8840 value = Smi::New(1);
8841 info.Add(value); // Column.
8842 }
8843 return info.raw();
8844 }
8845
8811 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); 8846 const TokenStream& tkns = TokenStream::Handle(zone, tokens());
8812 Smi& value = Smi::Handle(zone);
8813 String& tokenValue = String::Handle(zone); 8847 String& tokenValue = String::Handle(zone);
8814 ASSERT(!tkns.IsNull()); 8848 ASSERT(!tkns.IsNull());
8815 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, 8849 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource,
8816 TokenStream::Iterator::kAllTokens); 8850 TokenStream::Iterator::kAllTokens);
8817 int current_line = -1; 8851 int current_line = -1;
8818 Scanner s(source, key); 8852 Scanner s(source, key);
8819 s.Scan(); 8853 s.Scan();
8820 bool skippedNewline = false; 8854 bool skippedNewline = false;
8821 while (tkit.CurrentTokenKind() != Token::kEOS) { 8855 while (tkit.CurrentTokenKind() != Token::kEOS) {
8822 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { 8856 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
8934 StoreNonPointer(&raw_ptr()->load_timestamp_, value); 8968 StoreNonPointer(&raw_ptr()->load_timestamp_, value);
8935 } 8969 }
8936 8970
8937 8971
8938 void Script::set_tokens(const TokenStream& value) const { 8972 void Script::set_tokens(const TokenStream& value) const {
8939 StorePointer(&raw_ptr()->tokens_, value.raw()); 8973 StorePointer(&raw_ptr()->tokens_, value.raw());
8940 } 8974 }
8941 8975
8942 8976
8943 void Script::Tokenize(const String& private_key, bool use_shared_tokens) const { 8977 void Script::Tokenize(const String& private_key, bool use_shared_tokens) const {
8978 if (kind() == RawScript::kKernelTag) {
8979 return;
8980 }
8981
8944 Thread* thread = Thread::Current(); 8982 Thread* thread = Thread::Current();
8945 Zone* zone = thread->zone(); 8983 Zone* zone = thread->zone();
8946 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); 8984 const TokenStream& tkns = TokenStream::Handle(zone, tokens());
8947 if (!tkns.IsNull()) { 8985 if (!tkns.IsNull()) {
8948 // Already tokenized. 8986 // Already tokenized.
8949 return; 8987 return;
8950 } 8988 }
8951 // Get the source, scan and allocate the token stream. 8989 // Get the source, scan and allocate the token stream.
8952 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); 8990 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId);
8953 CSTAT_TIMER_SCOPE(thread, scanner_timer); 8991 CSTAT_TIMER_SCOPE(thread, scanner_timer);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
9000 9038
9001 smi ^= line_starts_array.At(midpoint); 9039 smi ^= line_starts_array.At(midpoint);
9002 if (smi.Value() > offset) { 9040 if (smi.Value() > offset) {
9003 max = midpoint - 1; 9041 max = midpoint - 1;
9004 } else { 9042 } else {
9005 min = midpoint; 9043 min = midpoint;
9006 } 9044 }
9007 } 9045 }
9008 *line = min + 1; 9046 *line = min + 1;
9009 smi ^= line_starts_array.At(min); 9047 smi ^= line_starts_array.At(min);
9010 *column = offset - smi.Value() + 1; 9048 if (column != NULL) {
9049 *column = offset - smi.Value() + 1;
9050 }
9011 if (token_len != NULL) { 9051 if (token_len != NULL) {
9012 *token_len = 1; 9052 *token_len = 1;
9013 } 9053 }
9014 return; 9054 return;
9015 } 9055 }
9016 9056
9017 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); 9057 const TokenStream& tkns = TokenStream::Handle(zone, tokens());
9018 if (tkns.IsNull()) { 9058 if (tkns.IsNull()) {
9019 ASSERT((Dart::snapshot_kind() == Snapshot::kAppAOT)); 9059 ASSERT((Dart::snapshot_kind() == Snapshot::kAppAOT));
9020 *line = -1; 9060 *line = -1;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
9059 } 9099 }
9060 } 9100 }
9061 } 9101 }
9062 9102
9063 9103
9064 void Script::TokenRangeAtLine(intptr_t line_number, 9104 void Script::TokenRangeAtLine(intptr_t line_number,
9065 TokenPosition* first_token_index, 9105 TokenPosition* first_token_index,
9066 TokenPosition* last_token_index) const { 9106 TokenPosition* last_token_index) const {
9067 ASSERT(first_token_index != NULL && last_token_index != NULL); 9107 ASSERT(first_token_index != NULL && last_token_index != NULL);
9068 ASSERT(line_number > 0); 9108 ASSERT(line_number > 0);
9109
9110 if (kind() == RawScript::kKernelTag) {
9111 const Array& line_starts_array = Array::Handle(line_starts());
9112 if (line_starts_array.IsNull()) {
9113 // Scripts in the AOT snapshot do not have a line starts array.
9114 *first_token_index = TokenPosition::kNoSource;
9115 *last_token_index = TokenPosition::kNoSource;
9116 return;
9117 }
9118 ASSERT(line_starts_array.Length() >= line_number);
9119 Smi& value = Smi::Handle();
9120 value ^= line_starts_array.At(line_number - 1);
9121 *first_token_index = TokenPosition(value.Value());
9122 if (line_starts_array.Length() > line_number) {
9123 value ^= line_starts_array.At(line_number);
9124 *last_token_index = TokenPosition(value.Value() - 1);
9125 } else {
9126 // Length of source is last possible token in this script.
9127 *last_token_index = TokenPosition(String::Handle(Source()).Length());
9128 }
9129 return;
9130 }
9131
9069 Zone* zone = Thread::Current()->zone(); 9132 Zone* zone = Thread::Current()->zone();
9070 *first_token_index = TokenPosition::kNoSource; 9133 *first_token_index = TokenPosition::kNoSource;
9071 *last_token_index = TokenPosition::kNoSource; 9134 *last_token_index = TokenPosition::kNoSource;
9072 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); 9135 const TokenStream& tkns = TokenStream::Handle(zone, tokens());
9073 line_number -= line_offset(); 9136 line_number -= line_offset();
9074 if (line_number < 1) line_number = 1; 9137 if (line_number < 1) line_number = 1;
9075 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, 9138 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource,
9076 TokenStream::Iterator::kAllTokens); 9139 TokenStream::Iterator::kAllTokens);
9077 // Scan through the token stream to the required line. 9140 // Scan through the token stream to the required line.
9078 intptr_t cur_line = 1; 9141 intptr_t cur_line = 1;
(...skipping 13833 matching lines...) Expand 10 before | Expand all | Expand 10 after
22912 return UserTag::null(); 22975 return UserTag::null();
22913 } 22976 }
22914 22977
22915 22978
22916 const char* UserTag::ToCString() const { 22979 const char* UserTag::ToCString() const {
22917 const String& tag_label = String::Handle(label()); 22980 const String& tag_label = String::Handle(label());
22918 return tag_label.ToCString(); 22981 return tag_label.ToCString();
22919 } 22982 }
22920 22983
22921 } // namespace dart 22984 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698