@@ -8067,43 +8067,36 @@ RawString* Function::GetSource() const {
80678067 Zone* zone = Thread::Current()->zone();
80688068 const Script& func_script = Script::Handle(zone, script());
80698069
8070- if (func_script.kind() == RawScript::kKernelTag) {
8071- intptr_t from_line;
8072- intptr_t from_col;
8073- intptr_t to_line;
8074- intptr_t to_col;
8075- intptr_t to_length;
8076- func_script.GetTokenLocation(token_pos(), &from_line, &from_col);
8077- func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col,
8078- &to_length);
8079-
8080- if (to_length == 1) {
8081- // Handle special cases for end tokens of closures (where we exclude the
8082- // last token):
8083- // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
8084- // (2) "foo(() => null);": End token is ')`, but we don't print it.
8085- // (3) "var foo = () => null;": End token is `;', but in this case the
8086- // token semicolon belongs to the assignment so we skip it.
8087- const String& src = String::Handle(func_script.Source());
8088- if (src.IsNull() || src.Length() == 0) {
8089- return Symbols::OptimizedOut().raw();
8090- }
8091- uint16_t end_char = src.CharAt(end_token_pos().value());
8092- if ((end_char == ',') || // Case 1.
8093- (end_char == ')') || // Case 2.
8094- (end_char == ';' &&
8095- String::Handle(zone, name())
8096- .Equals("<anonymous closure>"))) { // Case 3.
8097- to_length = 0;
8098- }
8099- }
8070+ intptr_t from_line;
8071+ intptr_t from_col;
8072+ intptr_t to_line;
8073+ intptr_t to_col;
8074+ intptr_t to_length;
8075+ func_script.GetTokenLocation(token_pos(), &from_line, &from_col);
8076+ func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col, &to_length);
81008077
8101- return func_script.GetSnippet(from_line, from_col, to_line,
8102- to_col + to_length);
8078+ if (to_length == 1) {
8079+ // Handle special cases for end tokens of closures (where we exclude the
8080+ // last token):
8081+ // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
8082+ // (2) "foo(() => null);": End token is ')`, but we don't print it.
8083+ // (3) "var foo = () => null;": End token is `;', but in this case the
8084+ // token semicolon belongs to the assignment so we skip it.
8085+ const String& src = String::Handle(func_script.Source());
8086+ if (src.IsNull() || src.Length() == 0) {
8087+ return Symbols::OptimizedOut().raw();
8088+ }
8089+ uint16_t end_char = src.CharAt(end_token_pos().value());
8090+ if ((end_char == ',') || // Case 1.
8091+ (end_char == ')') || // Case 2.
8092+ (end_char == ';' && String::Handle(zone, name())
8093+ .Equals("<anonymous closure>"))) { // Case 3.
8094+ to_length = 0;
8095+ }
81038096 }
81048097
8105- UNREACHABLE();
8106- return String::null( );
8098+ return func_script.GetSnippet(from_line, from_col, to_line,
8099+ to_col + to_length );
81078100}
81088101
81098102// Construct fingerprint from token stream. The token stream contains also
@@ -9518,7 +9511,7 @@ void Script::LookupSourceAndLineStarts(Zone* zone) const {
95189511 for (intptr_t i = 0; i < libs.Length(); i++) {
95199512 lib ^= libs.At(i);
95209513 script = lib.LookupScript(uri, /* useResolvedUri = */ true);
9521- if (!script.IsNull() && script.kind() == RawScript::kKernelTag ) {
9514+ if (!script.IsNull()) {
95229515 const auto& source = String::Handle(zone, script.Source());
95239516 const auto& line_starts = TypedData::Handle(zone, script.line_starts());
95249517 if (!source.IsNull() || !line_starts.IsNull()) {
@@ -9534,7 +9527,6 @@ void Script::LookupSourceAndLineStarts(Zone* zone) const {
95349527}
95359528
95369529RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
9537- ASSERT(kind() == RawScript::kKernelTag);
95389530 Zone* zone = Thread::Current()->zone();
95399531 const GrowableObjectArray& info =
95409532 GrowableObjectArray::Handle(zone, GrowableObjectArray::New());
@@ -9589,25 +9581,6 @@ RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
95899581 return info.raw();
95909582}
95919583
9592- const char* Script::GetKindAsCString() const {
9593- switch (kind()) {
9594- case RawScript::kScriptTag:
9595- return "script";
9596- case RawScript::kLibraryTag:
9597- return "library";
9598- case RawScript::kSourceTag:
9599- return "source";
9600- case RawScript::kEvaluateTag:
9601- return "evaluate";
9602- case RawScript::kKernelTag:
9603- return "kernel";
9604- default:
9605- UNIMPLEMENTED();
9606- }
9607- UNREACHABLE();
9608- return NULL;
9609- }
9610-
96119584void Script::set_url(const String& value) const {
96129585 StorePointer(&raw_ptr()->url_, value.raw());
96139586}
@@ -9662,31 +9635,25 @@ RawTypedData* Script::line_starts() const {
96629635RawArray* Script::debug_positions() const {
96639636#if !defined(DART_PRECOMPILED_RUNTIME)
96649637 Array& debug_positions_array = Array::Handle(raw_ptr()->debug_positions_);
9665- if (debug_positions_array.IsNull() && kind() == RawScript::kKernelTag ) {
9638+ if (debug_positions_array.IsNull()) {
96669639 // This is created lazily. Now we need it.
96679640 kernel::CollectTokenPositionsFor(*this);
96689641 }
96699642#endif // !defined(DART_PRECOMPILED_RUNTIME)
96709643 return raw_ptr()->debug_positions_;
96719644}
96729645
9673- void Script::set_kind(RawScript::Kind value) const {
9674- set_kind_and_tags(
9675- RawScript::KindBits::update(value, raw_ptr()->kind_and_tags_));
9676- }
9677-
9678- void Script::set_kind_and_tags(uint8_t value) const {
9679- StoreNonPointer(&raw_ptr()->kind_and_tags_, value);
9646+ void Script::set_flags(uint8_t value) const {
9647+ StoreNonPointer(&raw_ptr()->flags_, value);
96809648}
96819649
96829650void Script::SetLazyLookupSourceAndLineStarts(bool value) const {
9683- set_kind_and_tags (RawScript::LazyLookupSourceAndLineStartsBit::update(
9684- value, raw_ptr()->kind_and_tags_ ));
9651+ set_flags (RawScript::LazyLookupSourceAndLineStartsBit::update(
9652+ value, raw_ptr()->flags_ ));
96859653}
96869654
96879655bool Script::IsLazyLookupSourceAndLineStarts() const {
9688- return RawScript::LazyLookupSourceAndLineStartsBit::decode(
9689- raw_ptr()->kind_and_tags_);
9656+ return RawScript::LazyLookupSourceAndLineStartsBit::decode(raw_ptr()->flags_);
96909657}
96919658
96929659void Script::set_load_timestamp(int64_t value) const {
@@ -9715,31 +9682,12 @@ intptr_t Script::GetTokenLineUsingLineStarts(
97159682 return 0;
97169683 }
97179684
9718- if (kind() == RawScript::kKernelTag) {
97199685#if !defined(DART_PRECOMPILED_RUNTIME)
9720- kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
9721- return line_starts_reader.LineNumberForPosition(target_token_pos.value());
9686+ kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
9687+ return line_starts_reader.LineNumberForPosition(target_token_pos.value());
97229688#else
9723- return 0;
9689+ return 0;
97249690#endif // !defined(DART_PRECOMPILED_RUNTIME)
9725- } else {
9726- ASSERT(line_starts_data.Length() > 0);
9727- intptr_t offset = target_token_pos.Pos();
9728- intptr_t min = 0;
9729- intptr_t max = line_starts_data.Length() - 1;
9730-
9731- // Binary search to find the line containing this offset.
9732- while (min < max) {
9733- int midpoint = (max - min + 1) / 2 + min;
9734- int32_t token_pos = line_starts_data.GetInt32(midpoint * 4);
9735- if (token_pos > offset) {
9736- max = midpoint - 1;
9737- } else {
9738- min = midpoint;
9739- }
9740- }
9741- return min + 1; // Line numbers start at 1.
9742- }
97439691}
97449692
97459693#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -9767,7 +9715,6 @@ void Script::GetTokenLocation(TokenPosition token_pos,
97679715 ASSERT(line != NULL);
97689716 Zone* zone = Thread::Current()->zone();
97699717
9770- ASSERT(kind() == RawScript::kKernelTag);
97719718 LookupSourceAndLineStarts(zone);
97729719 if (line_starts() == TypedData::null()) {
97739720 // Scripts in the AOT snapshot do not have a line starts array.
@@ -9806,7 +9753,6 @@ void Script::GetTokenLocation(TokenPosition token_pos,
98069753void Script::TokenRangeAtLine(intptr_t line_number,
98079754 TokenPosition* first_token_index,
98089755 TokenPosition* last_token_index) const {
9809- ASSERT(kind() == RawScript::kKernelTag);
98109756 ASSERT(first_token_index != NULL && last_token_index != NULL);
98119757 ASSERT(line_number > 0);
98129758
@@ -9944,16 +9890,13 @@ RawScript* Script::New() {
99449890 return reinterpret_cast<RawScript*>(raw);
99459891}
99469892
9947- RawScript* Script::New(const String& url,
9948- const String& source,
9949- RawScript::Kind kind) {
9950- return Script::New(url, url, source, kind);
9893+ RawScript* Script::New(const String& url, const String& source) {
9894+ return Script::New(url, url, source);
99519895}
99529896
99539897RawScript* Script::New(const String& url,
99549898 const String& resolved_url,
9955- const String& source,
9956- RawScript::Kind kind) {
9899+ const String& source) {
99579900 Thread* thread = Thread::Current();
99589901 Zone* zone = thread->zone();
99599902 const Script& result = Script::Handle(zone, Script::New());
@@ -9962,8 +9905,7 @@ RawScript* Script::New(const String& url,
99629905 String::Handle(zone, Symbols::New(thread, resolved_url)));
99639906 result.set_source(source);
99649907 result.SetLocationOffset(0, 0);
9965- result.set_kind_and_tags(0);
9966- result.set_kind(kind);
9908+ result.set_flags(0);
99679909 result.set_kernel_script_index(0);
99689910 result.set_load_timestamp(
99699911 FLAG_remove_script_timestamps_for_test ? 0 : OS::GetCurrentTimeMillis());
@@ -22009,11 +21951,7 @@ static void PrintStackTraceFrame(Zone* zone,
2200921951 line = token_pos.value();
2201021952 } else {
2201121953 if (!script.IsNull() && token_pos.IsSourcePosition()) {
22012- if (script.HasSource() || script.kind() == RawScript::kKernelTag) {
22013- script.GetTokenLocation(token_pos.SourcePosition(), &line, &column);
22014- } else {
22015- script.GetTokenLocation(token_pos.SourcePosition(), &line, NULL);
22016- }
21954+ script.GetTokenLocation(token_pos.SourcePosition(), &line, &column);
2201721955 }
2201821956 }
2201921957
0 commit comments