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 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3415 ASSERT(!token_pos.IsClassifying()); | 3415 ASSERT(!token_pos.IsClassifying()); |
3416 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); | 3416 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); |
3417 } | 3417 } |
3418 | 3418 |
3419 | 3419 |
3420 TokenPosition Class::ComputeEndTokenPos() const { | 3420 TokenPosition Class::ComputeEndTokenPos() const { |
3421 // Return the begin token for synthetic classes. | 3421 // Return the begin token for synthetic classes. |
3422 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { | 3422 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { |
3423 return token_pos(); | 3423 return token_pos(); |
3424 } | 3424 } |
3425 const Script& scr = Script::Handle(script()); | 3425 Zone* zone = Thread::Current()->zone(); |
| 3426 const Script& scr = Script::Handle(zone, script()); |
3426 ASSERT(!scr.IsNull()); | 3427 ASSERT(!scr.IsNull()); |
3427 const TokenStream& tkns = TokenStream::Handle(scr.tokens()); | 3428 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); |
3428 if (tkns.IsNull()) { | 3429 if (tkns.IsNull()) { |
3429 ASSERT(Dart::IsRunningPrecompiledCode()); | 3430 ASSERT(Dart::IsRunningPrecompiledCode()); |
3430 return TokenPosition::kNoSource; | 3431 return TokenPosition::kNoSource; |
3431 } | 3432 } |
3432 TokenStream::Iterator tkit(tkns, | 3433 TokenStream::Iterator tkit(zone, |
| 3434 tkns, |
3433 token_pos(), | 3435 token_pos(), |
3434 TokenStream::Iterator::kNoNewlines); | 3436 TokenStream::Iterator::kNoNewlines); |
3435 intptr_t level = 0; | 3437 intptr_t level = 0; |
3436 while (tkit.CurrentTokenKind() != Token::kEOS) { | 3438 while (tkit.CurrentTokenKind() != Token::kEOS) { |
3437 if (tkit.CurrentTokenKind() == Token::kLBRACE) { | 3439 if (tkit.CurrentTokenKind() == Token::kLBRACE) { |
3438 level++; | 3440 level++; |
3439 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) { | 3441 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) { |
3440 if (--level == 0) { | 3442 if (--level == 0) { |
3441 return tkit.CurrentPosition(); | 3443 return tkit.CurrentPosition(); |
3442 } | 3444 } |
(...skipping 3627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7070 type = ParameterTypeAt(i); | 7072 type = ParameterTypeAt(i); |
7071 if (!type.IsInstantiated()) { | 7073 if (!type.IsInstantiated()) { |
7072 return false; | 7074 return false; |
7073 } | 7075 } |
7074 } | 7076 } |
7075 return true; | 7077 return true; |
7076 } | 7078 } |
7077 | 7079 |
7078 | 7080 |
7079 RawClass* Function::Owner() const { | 7081 RawClass* Function::Owner() const { |
| 7082 if (raw_ptr()->owner_->IsClass()) { |
| 7083 return Class::RawCast(raw_ptr()->owner_); |
| 7084 } |
7080 const Object& obj = Object::Handle(raw_ptr()->owner_); | 7085 const Object& obj = Object::Handle(raw_ptr()->owner_); |
7081 if (obj.IsClass()) { | |
7082 return Class::Cast(obj).raw(); | |
7083 } | |
7084 ASSERT(obj.IsPatchClass()); | 7086 ASSERT(obj.IsPatchClass()); |
7085 return PatchClass::Cast(obj).patched_class(); | 7087 return PatchClass::Cast(obj).patched_class(); |
7086 } | 7088 } |
7087 | 7089 |
7088 | 7090 |
7089 RawClass* Function::origin() const { | 7091 RawClass* Function::origin() const { |
| 7092 if (raw_ptr()->owner_->IsClass()) { |
| 7093 return Class::RawCast(raw_ptr()->owner_); |
| 7094 } |
7090 const Object& obj = Object::Handle(raw_ptr()->owner_); | 7095 const Object& obj = Object::Handle(raw_ptr()->owner_); |
7091 if (obj.IsClass()) { | |
7092 return Class::Cast(obj).raw(); | |
7093 } | |
7094 ASSERT(obj.IsPatchClass()); | 7096 ASSERT(obj.IsPatchClass()); |
7095 return PatchClass::Cast(obj).origin_class(); | 7097 return PatchClass::Cast(obj).origin_class(); |
7096 } | 7098 } |
7097 | 7099 |
7098 | 7100 |
7099 RawScript* Function::script() const { | 7101 RawScript* Function::script() const { |
7100 if (token_pos() == TokenPosition::kMinSource) { | 7102 if (token_pos() == TokenPosition::kMinSource) { |
7101 // Testing for position 0 is an optimization that relies on temporary | 7103 // Testing for position 0 is an optimization that relies on temporary |
7102 // eval functions having token position 0. | 7104 // eval functions having token position 0. |
7103 const Script& script = Script::Handle(eval_script()); | 7105 const Script& script = Script::Handle(eval_script()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7156 | 7158 |
7157 | 7159 |
7158 RawString* Function::GetSource() const { | 7160 RawString* Function::GetSource() const { |
7159 if (IsImplicitConstructor() || IsSignatureFunction()) { | 7161 if (IsImplicitConstructor() || IsSignatureFunction()) { |
7160 // We may need to handle more cases when the restrictions on mixins are | 7162 // We may need to handle more cases when the restrictions on mixins are |
7161 // relaxed. In particular we might start associating some source with the | 7163 // relaxed. In particular we might start associating some source with the |
7162 // forwarding constructors when it becomes possible to specify a particular | 7164 // forwarding constructors when it becomes possible to specify a particular |
7163 // constructor from the mixin to use. | 7165 // constructor from the mixin to use. |
7164 return String::null(); | 7166 return String::null(); |
7165 } | 7167 } |
7166 const Script& func_script = Script::Handle(script()); | 7168 Zone* zone = Thread::Current()->zone(); |
7167 const TokenStream& stream = TokenStream::Handle(func_script.tokens()); | 7169 const Script& func_script = Script::Handle(zone, script()); |
| 7170 const TokenStream& stream = TokenStream::Handle(zone, func_script.tokens()); |
7168 if (!func_script.HasSource()) { | 7171 if (!func_script.HasSource()) { |
7169 // When source is not available, avoid printing the whole token stream and | 7172 // When source is not available, avoid printing the whole token stream and |
7170 // doing expensive position calculations. | 7173 // doing expensive position calculations. |
7171 return stream.GenerateSource(token_pos(), end_token_pos().Next()); | 7174 return stream.GenerateSource(token_pos(), end_token_pos().Next()); |
7172 } | 7175 } |
7173 | 7176 |
7174 const TokenStream::Iterator tkit(stream, end_token_pos()); | 7177 const TokenStream::Iterator tkit(zone, stream, end_token_pos()); |
7175 intptr_t from_line; | 7178 intptr_t from_line; |
7176 intptr_t from_col; | 7179 intptr_t from_col; |
7177 intptr_t to_line; | 7180 intptr_t to_line; |
7178 intptr_t to_col; | 7181 intptr_t to_col; |
7179 func_script.GetTokenLocation(token_pos(), &from_line, &from_col); | 7182 func_script.GetTokenLocation(token_pos(), &from_line, &from_col); |
7180 func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col); | 7183 func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col); |
7181 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); | 7184 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); |
7182 // Handle special cases for end tokens of closures (where we exclude the last | 7185 // Handle special cases for end tokens of closures (where we exclude the last |
7183 // token): | 7186 // token): |
7184 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. | 7187 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. |
7185 // (2) "foo(() => null);": End token is ')`, but we don't print it. | 7188 // (2) "foo(() => null);": End token is ')`, but we don't print it. |
7186 // (3) "var foo = () => null;": End token is `;', but in this case the token | 7189 // (3) "var foo = () => null;": End token is `;', but in this case the token |
7187 // semicolon belongs to the assignment so we skip it. | 7190 // semicolon belongs to the assignment so we skip it. |
7188 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. | 7191 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. |
7189 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. | 7192 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. |
7190 (tkit.CurrentTokenKind() == Token::kSEMICOLON && | 7193 (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
7191 String::Handle(name()).Equals("<anonymous closure>"))) { // Case 3. | 7194 String::Handle(zone, name()).Equals("<anonymous closure>"))) { // Cas 3. |
7192 last_tok_len = 0; | 7195 last_tok_len = 0; |
7193 } | 7196 } |
7194 const String& result = String::Handle(func_script.GetSnippet( | 7197 const String& result = String::Handle(zone, func_script.GetSnippet( |
7195 from_line, from_col, to_line, to_col + last_tok_len)); | 7198 from_line, from_col, to_line, to_col + last_tok_len)); |
7196 ASSERT(!result.IsNull()); | 7199 ASSERT(!result.IsNull()); |
7197 return result.raw(); | 7200 return result.raw(); |
7198 } | 7201 } |
7199 | 7202 |
7200 | 7203 |
7201 // Construct fingerprint from token stream. The token stream contains also | 7204 // Construct fingerprint from token stream. The token stream contains also |
7202 // arguments. | 7205 // arguments. |
7203 int32_t Function::SourceFingerprint() const { | 7206 int32_t Function::SourceFingerprint() const { |
7204 uint32_t result = 0; | 7207 uint32_t result = 0; |
7205 TokenStream::Iterator tokens_iterator(TokenStream::Handle( | 7208 Zone* zone = Thread::Current()->zone(); |
7206 Script::Handle(script()).tokens()), token_pos()); | 7209 TokenStream::Iterator tokens_iterator( |
7207 Object& obj = Object::Handle(); | 7210 zone, |
7208 String& literal = String::Handle(); | 7211 TokenStream::Handle(zone, Script::Handle(zone, script()).tokens()), |
| 7212 token_pos()); |
| 7213 Object& obj = Object::Handle(zone); |
| 7214 String& literal = String::Handle(zone); |
7209 while (tokens_iterator.CurrentPosition() < end_token_pos()) { | 7215 while (tokens_iterator.CurrentPosition() < end_token_pos()) { |
7210 uint32_t val = 0; | 7216 uint32_t val = 0; |
7211 obj = tokens_iterator.CurrentToken(); | 7217 obj = tokens_iterator.CurrentToken(); |
7212 if (obj.IsSmi()) { | 7218 if (obj.IsSmi()) { |
7213 val = Smi::Cast(obj).Value(); | 7219 val = Smi::Cast(obj).Value(); |
7214 } else { | 7220 } else { |
7215 literal = tokens_iterator.MakeLiteralToken(obj); | 7221 literal = tokens_iterator.MakeLiteralToken(obj); |
7216 val = literal.Hash(); | 7222 val = literal.Hash(); |
7217 } | 7223 } |
7218 result = 31 * result + val; | 7224 result = 31 * result + val; |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8213 StorePointer(&raw_ptr()->private_key_, value.raw()); | 8219 StorePointer(&raw_ptr()->private_key_, value.raw()); |
8214 } | 8220 } |
8215 | 8221 |
8216 RawString* TokenStream::GenerateSource() const { | 8222 RawString* TokenStream::GenerateSource() const { |
8217 return GenerateSource(TokenPosition::kMinSource, | 8223 return GenerateSource(TokenPosition::kMinSource, |
8218 TokenPosition::kMaxSource); | 8224 TokenPosition::kMaxSource); |
8219 } | 8225 } |
8220 | 8226 |
8221 RawString* TokenStream::GenerateSource(TokenPosition start_pos, | 8227 RawString* TokenStream::GenerateSource(TokenPosition start_pos, |
8222 TokenPosition end_pos) const { | 8228 TokenPosition end_pos) const { |
8223 Iterator iterator(*this, start_pos, Iterator::kAllTokens); | 8229 Zone* zone = Thread::Current()->zone(); |
8224 const ExternalTypedData& data = ExternalTypedData::Handle(GetStream()); | 8230 Iterator iterator(zone, *this, start_pos, Iterator::kAllTokens); |
| 8231 const ExternalTypedData& data = ExternalTypedData::Handle(zone, GetStream()); |
8225 const GrowableObjectArray& literals = | 8232 const GrowableObjectArray& literals = |
8226 GrowableObjectArray::Handle(GrowableObjectArray::New(data.Length())); | 8233 GrowableObjectArray::Handle(zone, |
8227 const String& private_key = String::Handle(PrivateKey()); | 8234 GrowableObjectArray::New(data.Length())); |
| 8235 const String& private_key = String::Handle(zone, PrivateKey()); |
8228 intptr_t private_len = private_key.Length(); | 8236 intptr_t private_len = private_key.Length(); |
8229 | 8237 |
8230 Token::Kind curr = iterator.CurrentTokenKind(); | 8238 Token::Kind curr = iterator.CurrentTokenKind(); |
8231 Token::Kind prev = Token::kILLEGAL; | 8239 Token::Kind prev = Token::kILLEGAL; |
8232 // Handles used in the loop. | 8240 // Handles used in the loop. |
8233 Object& obj = Object::Handle(); | 8241 Object& obj = Object::Handle(zone); |
8234 String& literal = String::Handle(); | 8242 String& literal = String::Handle(zone); |
8235 // Current indentation level. | 8243 // Current indentation level. |
8236 int indent = 0; | 8244 int indent = 0; |
8237 | 8245 |
8238 while ((curr != Token::kEOS) && (iterator.CurrentPosition() < end_pos)) { | 8246 while ((curr != Token::kEOS) && (iterator.CurrentPosition() < end_pos)) { |
8239 // Remember current values for this token. | 8247 // Remember current values for this token. |
8240 obj = iterator.CurrentToken(); | 8248 obj = iterator.CurrentToken(); |
8241 literal = iterator.MakeLiteralToken(obj); | 8249 literal = iterator.MakeLiteralToken(obj); |
8242 // Advance to be able to use next token kind. | 8250 // Advance to be able to use next token kind. |
8243 iterator.Advance(); | 8251 iterator.Advance(); |
8244 Token::Kind next = iterator.CurrentTokenKind(); | 8252 Token::Kind next = iterator.CurrentTokenKind(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8398 prev = curr; | 8406 prev = curr; |
8399 curr = next; | 8407 curr = next; |
8400 } | 8408 } |
8401 const Array& source = Array::Handle(Array::MakeArray(literals)); | 8409 const Array& source = Array::Handle(Array::MakeArray(literals)); |
8402 return String::ConcatAll(source); | 8410 return String::ConcatAll(source); |
8403 } | 8411 } |
8404 | 8412 |
8405 | 8413 |
8406 TokenPosition TokenStream::ComputeSourcePosition( | 8414 TokenPosition TokenStream::ComputeSourcePosition( |
8407 TokenPosition tok_pos) const { | 8415 TokenPosition tok_pos) const { |
8408 Iterator iterator(*this, TokenPosition::kMinSource, Iterator::kAllTokens); | 8416 Zone* zone = Thread::Current()->zone(); |
| 8417 Iterator iterator(zone, |
| 8418 *this, |
| 8419 TokenPosition::kMinSource, |
| 8420 Iterator::kAllTokens); |
8409 TokenPosition src_pos = TokenPosition::kMinSource; | 8421 TokenPosition src_pos = TokenPosition::kMinSource; |
8410 Token::Kind kind = iterator.CurrentTokenKind(); | 8422 Token::Kind kind = iterator.CurrentTokenKind(); |
8411 while ((iterator.CurrentPosition() < tok_pos) && (kind != Token::kEOS)) { | 8423 while ((iterator.CurrentPosition() < tok_pos) && (kind != Token::kEOS)) { |
8412 iterator.Advance(); | 8424 iterator.Advance(); |
8413 kind = iterator.CurrentTokenKind(); | 8425 kind = iterator.CurrentTokenKind(); |
8414 src_pos.Next(); | 8426 src_pos.Next(); |
8415 } | 8427 } |
8416 return src_pos; | 8428 return src_pos; |
8417 } | 8429 } |
8418 | 8430 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8662 isolate->object_store()->set_token_objects(GrowableObjectArray::Handle()); | 8674 isolate->object_store()->set_token_objects(GrowableObjectArray::Handle()); |
8663 isolate->object_store()->set_token_objects_map(Array::null_array()); | 8675 isolate->object_store()->set_token_objects_map(Array::null_array()); |
8664 } | 8676 } |
8665 | 8677 |
8666 | 8678 |
8667 const char* TokenStream::ToCString() const { | 8679 const char* TokenStream::ToCString() const { |
8668 return "TokenStream"; | 8680 return "TokenStream"; |
8669 } | 8681 } |
8670 | 8682 |
8671 | 8683 |
8672 TokenStream::Iterator::Iterator(const TokenStream& tokens, | 8684 TokenStream::Iterator::Iterator(Zone* zone, |
| 8685 const TokenStream& tokens, |
8673 TokenPosition token_pos, | 8686 TokenPosition token_pos, |
8674 Iterator::StreamType stream_type) | 8687 Iterator::StreamType stream_type) |
8675 : tokens_(TokenStream::Handle(tokens.raw())), | 8688 : tokens_(TokenStream::Handle(zone, tokens.raw())), |
8676 data_(ExternalTypedData::Handle(tokens.GetStream())), | 8689 data_(ExternalTypedData::Handle(zone, tokens.GetStream())), |
8677 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), | 8690 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), |
8678 token_objects_(Array::Handle( | 8691 token_objects_(Array::Handle(zone, |
8679 GrowableObjectArray::Handle(tokens.TokenObjects()).data())), | 8692 GrowableObjectArray::Handle(zone, tokens.TokenObjects()).data())), |
8680 obj_(Object::Handle()), | 8693 obj_(Object::Handle(zone)), |
8681 cur_token_pos_(token_pos.Pos()), | 8694 cur_token_pos_(token_pos.Pos()), |
8682 cur_token_kind_(Token::kILLEGAL), | 8695 cur_token_kind_(Token::kILLEGAL), |
8683 cur_token_obj_index_(-1), | 8696 cur_token_obj_index_(-1), |
8684 stream_type_(stream_type) { | 8697 stream_type_(stream_type) { |
8685 ASSERT(token_pos != TokenPosition::kNoSource); | 8698 ASSERT(token_pos != TokenPosition::kNoSource); |
8686 if (token_pos.IsReal()) { | 8699 if (token_pos.IsReal()) { |
8687 SetCurrentPosition(token_pos); | 8700 SetCurrentPosition(token_pos); |
8688 } | 8701 } |
8689 } | 8702 } |
8690 | 8703 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8833 Zone* zone = Thread::Current()->zone(); | 8846 Zone* zone = Thread::Current()->zone(); |
8834 const GrowableObjectArray& info = | 8847 const GrowableObjectArray& info = |
8835 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 8848 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
8836 const String& source = String::Handle(zone, Source()); | 8849 const String& source = String::Handle(zone, Source()); |
8837 const String& key = Symbols::Empty(); | 8850 const String& key = Symbols::Empty(); |
8838 const Object& line_separator = Object::Handle(zone); | 8851 const Object& line_separator = Object::Handle(zone); |
8839 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8852 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8840 Smi& value = Smi::Handle(zone); | 8853 Smi& value = Smi::Handle(zone); |
8841 String& tokenValue = String::Handle(zone); | 8854 String& tokenValue = String::Handle(zone); |
8842 ASSERT(!tkns.IsNull()); | 8855 ASSERT(!tkns.IsNull()); |
8843 TokenStream::Iterator tkit(tkns, | 8856 TokenStream::Iterator tkit(zone, |
| 8857 tkns, |
8844 TokenPosition::kMinSource, | 8858 TokenPosition::kMinSource, |
8845 TokenStream::Iterator::kAllTokens); | 8859 TokenStream::Iterator::kAllTokens); |
8846 int current_line = -1; | 8860 int current_line = -1; |
8847 Scanner s(source, key); | 8861 Scanner s(source, key); |
8848 s.Scan(); | 8862 s.Scan(); |
8849 bool skippedNewline = false; | 8863 bool skippedNewline = false; |
8850 while (tkit.CurrentTokenKind() != Token::kEOS) { | 8864 while (tkit.CurrentTokenKind() != Token::kEOS) { |
8851 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8865 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8852 // Skip newlines from the token stream. | 8866 // Skip newlines from the token stream. |
8853 skippedNewline = true; | 8867 skippedNewline = true; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8982 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); | 8996 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); |
8983 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8997 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
8984 } | 8998 } |
8985 | 8999 |
8986 | 9000 |
8987 void Script::GetTokenLocation(TokenPosition token_pos, | 9001 void Script::GetTokenLocation(TokenPosition token_pos, |
8988 intptr_t* line, | 9002 intptr_t* line, |
8989 intptr_t* column, | 9003 intptr_t* column, |
8990 intptr_t* token_len) const { | 9004 intptr_t* token_len) const { |
8991 ASSERT(line != NULL); | 9005 ASSERT(line != NULL); |
8992 const TokenStream& tkns = TokenStream::Handle(tokens()); | 9006 Zone* zone = Thread::Current()->zone(); |
| 9007 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8993 if (tkns.IsNull()) { | 9008 if (tkns.IsNull()) { |
8994 ASSERT(Dart::IsRunningPrecompiledCode()); | 9009 ASSERT(Dart::IsRunningPrecompiledCode()); |
8995 *line = -1; | 9010 *line = -1; |
8996 if (column != NULL) { | 9011 if (column != NULL) { |
8997 *column = -1; | 9012 *column = -1; |
8998 } | 9013 } |
8999 if (token_len != NULL) { | 9014 if (token_len != NULL) { |
9000 *token_len = 1; | 9015 *token_len = 1; |
9001 } | 9016 } |
9002 return; | 9017 return; |
9003 } | 9018 } |
9004 if (column == NULL) { | 9019 if (column == NULL) { |
9005 TokenStream::Iterator tkit(tkns, | 9020 TokenStream::Iterator tkit(zone, |
| 9021 tkns, |
9006 TokenPosition::kMinSource, | 9022 TokenPosition::kMinSource, |
9007 TokenStream::Iterator::kAllTokens); | 9023 TokenStream::Iterator::kAllTokens); |
9008 intptr_t cur_line = line_offset() + 1; | 9024 intptr_t cur_line = line_offset() + 1; |
9009 while ((tkit.CurrentPosition() < token_pos) && | 9025 while ((tkit.CurrentPosition() < token_pos) && |
9010 (tkit.CurrentTokenKind() != Token::kEOS)) { | 9026 (tkit.CurrentTokenKind() != Token::kEOS)) { |
9011 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 9027 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
9012 cur_line++; | 9028 cur_line++; |
9013 } | 9029 } |
9014 tkit.Advance(); | 9030 tkit.Advance(); |
9015 } | 9031 } |
9016 *line = cur_line; | 9032 *line = cur_line; |
9017 } else { | 9033 } else { |
9018 const String& src = String::Handle(Source()); | 9034 const String& src = String::Handle(zone, Source()); |
9019 TokenPosition src_pos = tkns.ComputeSourcePosition(token_pos); | 9035 TokenPosition src_pos = tkns.ComputeSourcePosition(token_pos); |
9020 Scanner scanner(src, Symbols::Empty()); | 9036 Scanner scanner(src, Symbols::Empty()); |
9021 scanner.ScanTo(src_pos); | 9037 scanner.ScanTo(src_pos); |
9022 intptr_t relative_line = scanner.CurrentPosition().line; | 9038 intptr_t relative_line = scanner.CurrentPosition().line; |
9023 *line = relative_line + line_offset(); | 9039 *line = relative_line + line_offset(); |
9024 *column = scanner.CurrentPosition().column; | 9040 *column = scanner.CurrentPosition().column; |
9025 if (token_len != NULL) { | 9041 if (token_len != NULL) { |
9026 if (scanner.current_token().literal != NULL) { | 9042 if (scanner.current_token().literal != NULL) { |
9027 *token_len = scanner.current_token().literal->Length(); | 9043 *token_len = scanner.current_token().literal->Length(); |
9028 } else { | 9044 } else { |
9029 *token_len = 1; | 9045 *token_len = 1; |
9030 } | 9046 } |
9031 } | 9047 } |
9032 // On the first line of the script we must add the column offset. | 9048 // On the first line of the script we must add the column offset. |
9033 if (relative_line == 1) { | 9049 if (relative_line == 1) { |
9034 *column += col_offset(); | 9050 *column += col_offset(); |
9035 } | 9051 } |
9036 } | 9052 } |
9037 } | 9053 } |
9038 | 9054 |
9039 | 9055 |
9040 void Script::TokenRangeAtLine(intptr_t line_number, | 9056 void Script::TokenRangeAtLine(intptr_t line_number, |
9041 TokenPosition* first_token_index, | 9057 TokenPosition* first_token_index, |
9042 TokenPosition* last_token_index) const { | 9058 TokenPosition* last_token_index) const { |
9043 ASSERT(first_token_index != NULL && last_token_index != NULL); | 9059 ASSERT(first_token_index != NULL && last_token_index != NULL); |
9044 ASSERT(line_number > 0); | 9060 ASSERT(line_number > 0); |
| 9061 Zone* zone = Thread::Current()->zone(); |
9045 *first_token_index = TokenPosition::kNoSource; | 9062 *first_token_index = TokenPosition::kNoSource; |
9046 *last_token_index = TokenPosition::kNoSource; | 9063 *last_token_index = TokenPosition::kNoSource; |
9047 const TokenStream& tkns = TokenStream::Handle(tokens()); | 9064 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
9048 line_number -= line_offset(); | 9065 line_number -= line_offset(); |
9049 if (line_number < 1) line_number = 1; | 9066 if (line_number < 1) line_number = 1; |
9050 TokenStream::Iterator tkit(tkns, | 9067 TokenStream::Iterator tkit(zone, |
| 9068 tkns, |
9051 TokenPosition::kMinSource, | 9069 TokenPosition::kMinSource, |
9052 TokenStream::Iterator::kAllTokens); | 9070 TokenStream::Iterator::kAllTokens); |
9053 // Scan through the token stream to the required line. | 9071 // Scan through the token stream to the required line. |
9054 intptr_t cur_line = 1; | 9072 intptr_t cur_line = 1; |
9055 while (cur_line < line_number && tkit.CurrentTokenKind() != Token::kEOS) { | 9073 while (cur_line < line_number && tkit.CurrentTokenKind() != Token::kEOS) { |
9056 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 9074 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
9057 cur_line++; | 9075 cur_line++; |
9058 } | 9076 } |
9059 tkit.Advance(); | 9077 tkit.Advance(); |
9060 } | 9078 } |
(...skipping 7297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16358 void Type::SetIsBeingFinalized() const { | 16376 void Type::SetIsBeingFinalized() const { |
16359 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); | 16377 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); |
16360 set_type_state(RawType::kBeingFinalized); | 16378 set_type_state(RawType::kBeingFinalized); |
16361 } | 16379 } |
16362 | 16380 |
16363 | 16381 |
16364 bool Type::IsMalformed() const { | 16382 bool Type::IsMalformed() const { |
16365 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { | 16383 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
16366 return false; // Valid type, but not a function type. | 16384 return false; // Valid type, but not a function type. |
16367 } | 16385 } |
16368 const LanguageError& type_error = LanguageError::Handle(error()); | 16386 if (!raw_ptr()->sig_or_err_.error_->IsLanguageError()) { |
16369 if (type_error.IsNull()) { | |
16370 return false; // Valid function type. | 16387 return false; // Valid function type. |
16371 } | 16388 } |
| 16389 const LanguageError& type_error = LanguageError::Handle(error()); |
| 16390 ASSERT(!type_error.IsNull()); |
16372 return type_error.kind() == Report::kMalformedType; | 16391 return type_error.kind() == Report::kMalformedType; |
16373 } | 16392 } |
16374 | 16393 |
16375 | 16394 |
16376 bool Type::IsMalbounded() const { | 16395 bool Type::IsMalbounded() const { |
16377 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { | 16396 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
16378 return false; // Valid type, but not a function type. | 16397 return false; // Valid type, but not a function type. |
16379 } | 16398 } |
16380 if (!Isolate::Current()->type_checks()) { | 16399 if (!Isolate::Current()->type_checks()) { |
16381 return false; | 16400 return false; |
16382 } | 16401 } |
16383 const LanguageError& type_error = LanguageError::Handle(error()); | 16402 if (!raw_ptr()->sig_or_err_.error_->IsLanguageError()) { |
16384 if (type_error.IsNull()) { | |
16385 return false; // Valid function type. | 16403 return false; // Valid function type. |
16386 } | 16404 } |
| 16405 const LanguageError& type_error = LanguageError::Handle(error()); |
| 16406 ASSERT(!type_error.IsNull()); |
16387 return type_error.kind() == Report::kMalboundedType; | 16407 return type_error.kind() == Report::kMalboundedType; |
16388 } | 16408 } |
16389 | 16409 |
16390 | 16410 |
16391 bool Type::IsMalformedOrMalbounded() const { | 16411 bool Type::IsMalformedOrMalbounded() const { |
16392 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { | 16412 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
16393 return false; // Valid type, but not a function type. | 16413 return false; // Valid type, but not a function type. |
16394 } | 16414 } |
16395 const LanguageError& type_error = LanguageError::Handle(error()); | 16415 const LanguageError& type_error = LanguageError::Handle(error()); |
16396 if (type_error.IsNull()) { | 16416 if (type_error.IsNull()) { |
16397 return false; // Valid function type. | 16417 return false; // Valid function type. |
16398 } | 16418 } |
16399 if (type_error.kind() == Report::kMalformedType) { | 16419 if (type_error.kind() == Report::kMalformedType) { |
16400 return true; | 16420 return true; |
16401 } | 16421 } |
16402 ASSERT(type_error.kind() == Report::kMalboundedType); | 16422 ASSERT(type_error.kind() == Report::kMalboundedType); |
16403 return Isolate::Current()->type_checks(); | 16423 return Isolate::Current()->type_checks(); |
16404 } | 16424 } |
16405 | 16425 |
16406 | 16426 |
16407 RawLanguageError* Type::error() const { | 16427 RawLanguageError* Type::error() const { |
16408 const Object& type_error = Object::Handle(raw_ptr()->sig_or_err_.error_); | 16428 if (raw_ptr()->sig_or_err_.error_->IsLanguageError()) { |
16409 if (type_error.IsLanguageError()) { | 16429 return LanguageError::RawCast(raw_ptr()->sig_or_err_.error_); |
16410 return LanguageError::RawCast(type_error.raw()); | |
16411 } | 16430 } |
16412 return LanguageError::null(); | 16431 return LanguageError::null(); |
16413 } | 16432 } |
16414 | 16433 |
16415 | 16434 |
16416 void Type::set_error(const LanguageError& value) const { | 16435 void Type::set_error(const LanguageError& value) const { |
16417 StorePointer(&raw_ptr()->sig_or_err_.error_, value.raw()); | 16436 StorePointer(&raw_ptr()->sig_or_err_.error_, value.raw()); |
16418 } | 16437 } |
16419 | 16438 |
16420 | 16439 |
(...skipping 5982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22403 return UserTag::null(); | 22422 return UserTag::null(); |
22404 } | 22423 } |
22405 | 22424 |
22406 | 22425 |
22407 const char* UserTag::ToCString() const { | 22426 const char* UserTag::ToCString() const { |
22408 const String& tag_label = String::Handle(label()); | 22427 const String& tag_label = String::Handle(label()); |
22409 return tag_label.ToCString(); | 22428 return tag_label.ToCString(); |
22410 } | 22429 } |
22411 | 22430 |
22412 } // namespace dart | 22431 } // namespace dart |
OLD | NEW |