| 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 7393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7404 token_obj_(Object::Handle()), | 7404 token_obj_(Object::Handle()), |
| 7405 literal_token_(LiteralToken::Handle()), | 7405 literal_token_(LiteralToken::Handle()), |
| 7406 literal_str_(String::Handle()) { | 7406 literal_str_(String::Handle()) { |
| 7407 token_objects_.Add(Object::null_string()); | 7407 token_objects_.Add(Object::null_string()); |
| 7408 } | 7408 } |
| 7409 ~CompressedTokenStreamData() { | 7409 ~CompressedTokenStreamData() { |
| 7410 } | 7410 } |
| 7411 | 7411 |
| 7412 // Add an IDENT token into the stream and the token objects array. | 7412 // Add an IDENT token into the stream and the token objects array. |
| 7413 void AddIdentToken(const String* ident) { | 7413 void AddIdentToken(const String* ident) { |
| 7414 ASSERT(ident != NULL); | |
| 7415 ASSERT(ident->IsSymbol()); | |
| 7416 // If the IDENT token is already in the tokens object array use the | 7414 // If the IDENT token is already in the tokens object array use the |
| 7417 // same index instead of duplicating it. | 7415 // same index instead of duplicating it. |
| 7418 intptr_t index = FindIdentIndex(ident); | 7416 intptr_t index = FindIdentIndex(ident); |
| 7419 if (index == -1) { | 7417 if (index == -1) { |
| 7420 WriteIndex(token_objects_.Length()); | 7418 WriteIndex(token_objects_.Length()); |
| 7421 ASSERT(ident != NULL); | 7419 ASSERT(ident != NULL); |
| 7422 token_objects_.Add(*ident); | 7420 token_objects_.Add(*ident); |
| 7423 } else { | 7421 } else { |
| 7424 WriteIndex(index); | 7422 WriteIndex(index); |
| 7425 } | 7423 } |
| 7426 } | 7424 } |
| 7427 | 7425 |
| 7428 // Add a LITERAL token into the stream and the token objects array. | 7426 // Add a LITERAL token into the stream and the token objects array. |
| 7429 void AddLiteralToken(Token::Kind kind, const String* literal) { | 7427 void AddLiteralToken(Token::Kind kind, const String* literal) { |
| 7430 if (literal != NULL) { | 7428 // If the literal token is already in the tokens object array use the |
| 7431 // If the literal token is already in the tokens object array use the | 7429 // same index instead of duplicating it. |
| 7432 // same index instead of duplicating it. | 7430 intptr_t index = FindLiteralIndex(kind, literal); |
| 7433 intptr_t index = FindLiteralIndex(kind, literal); | 7431 if (index == -1) { |
| 7434 if (index == -1) { | 7432 WriteIndex(token_objects_.Length()); |
| 7435 WriteIndex(token_objects_.Length()); | 7433 ASSERT(literal != NULL); |
| 7436 ASSERT(literal != NULL); | 7434 literal_token_ = LiteralToken::New(kind, *literal); |
| 7437 literal_token_ = LiteralToken::New(kind, *literal); | 7435 token_objects_.Add(literal_token_); |
| 7438 token_objects_.Add(literal_token_); | |
| 7439 } else { | |
| 7440 WriteIndex(index); | |
| 7441 } | |
| 7442 } else { | 7436 } else { |
| 7443 WriteIndex(0); | 7437 WriteIndex(index); |
| 7444 } | 7438 } |
| 7445 } | 7439 } |
| 7446 | 7440 |
| 7447 // Add a simple token into the stream. | 7441 // Add a simple token into the stream. |
| 7448 void AddSimpleToken(intptr_t kind) { | 7442 void AddSimpleToken(intptr_t kind) { |
| 7449 stream_.WriteUnsigned(kind); | 7443 stream_.WriteUnsigned(kind); |
| 7450 } | 7444 } |
| 7451 | 7445 |
| 7452 // Return the compressed token stream. | 7446 // Return the compressed token stream. |
| 7453 uint8_t* GetStream() const { return buffer_; } | 7447 uint8_t* GetStream() const { return buffer_; } |
| 7454 | 7448 |
| 7455 // Return the compressed token stream length. | 7449 // Return the compressed token stream length. |
| 7456 intptr_t Length() const { return stream_.bytes_written(); } | 7450 intptr_t Length() const { return stream_.bytes_written(); } |
| 7457 | 7451 |
| 7458 // Return the token objects array. | 7452 // Return the token objects array. |
| 7459 const GrowableObjectArray& TokenObjects() const { | 7453 const GrowableObjectArray& TokenObjects() const { |
| 7460 return token_objects_; | 7454 return token_objects_; |
| 7461 } | 7455 } |
| 7462 | 7456 |
| 7463 private: | 7457 private: |
| 7464 intptr_t FindIdentIndex(const String* ident) { | 7458 intptr_t FindIdentIndex(const String* ident) { |
| 7465 ASSERT(ident != NULL); | 7459 ASSERT(ident != NULL); |
| 7460 ASSERT(ident->IsSymbol()); |
| 7466 intptr_t hash_value = ident->Hash() % kTableSize; | 7461 intptr_t hash_value = ident->Hash() % kTableSize; |
| 7467 GrowableArray<intptr_t>& value = ident_table_[hash_value]; | 7462 GrowableArray<intptr_t>& value = ident_table_[hash_value]; |
| 7468 for (intptr_t i = 0; i < value.length(); i++) { | 7463 for (intptr_t i = 0; i < value.length(); i++) { |
| 7469 intptr_t index = value[i]; | 7464 intptr_t index = value[i]; |
| 7470 token_obj_ = token_objects_.At(index); | 7465 if (token_objects_.At(index) == ident->raw()) { |
| 7471 if (token_obj_.IsString()) { | 7466 return index; |
| 7472 const String& ident_str = String::Cast(token_obj_); | |
| 7473 if (ident->Equals(ident_str)) { | |
| 7474 return index; | |
| 7475 } | |
| 7476 } | 7467 } |
| 7477 } | 7468 } |
| 7478 value.Add(token_objects_.Length()); | 7469 value.Add(token_objects_.Length()); |
| 7479 return -1; | 7470 return -1; |
| 7480 } | 7471 } |
| 7481 | 7472 |
| 7482 intptr_t FindLiteralIndex(Token::Kind kind, const String* literal) { | 7473 intptr_t FindLiteralIndex(Token::Kind kind, const String* literal) { |
| 7483 ASSERT(literal != NULL); | 7474 ASSERT(literal != NULL); |
| 7475 ASSERT(literal->IsSymbol()); |
| 7484 intptr_t hash_value = literal->Hash() % kTableSize; | 7476 intptr_t hash_value = literal->Hash() % kTableSize; |
| 7485 GrowableArray<intptr_t>& value = literal_table_[hash_value]; | 7477 GrowableArray<intptr_t>& value = literal_table_[hash_value]; |
| 7486 for (intptr_t i = 0; i < value.length(); i++) { | 7478 for (intptr_t i = 0; i < value.length(); i++) { |
| 7487 intptr_t index = value[i]; | 7479 intptr_t index = value[i]; |
| 7488 token_obj_ = token_objects_.At(index); | 7480 token_obj_ = token_objects_.At(index); |
| 7489 if (token_obj_.IsLiteralToken()) { | 7481 const LiteralToken& token = LiteralToken::Cast(token_obj_); |
| 7490 const LiteralToken& token = LiteralToken::Cast(token_obj_); | 7482 if ((kind == token.kind()) && (token.literal() == literal->raw())) { |
| 7491 literal_str_ = token.literal(); | 7483 return index; |
| 7492 if (kind == token.kind() && literal->Equals(literal_str_)) { | |
| 7493 return index; | |
| 7494 } | |
| 7495 } | 7484 } |
| 7496 } | 7485 } |
| 7497 value.Add(token_objects_.Length()); | 7486 value.Add(token_objects_.Length()); |
| 7498 return -1; | 7487 return -1; |
| 7499 } | 7488 } |
| 7500 | 7489 |
| 7501 void WriteIndex(intptr_t value) { | 7490 void WriteIndex(intptr_t value) { |
| 7502 stream_.WriteUnsigned(value + Token::kNumTokens); | 7491 stream_.WriteUnsigned(value + Token::kNumTokens); |
| 7503 } | 7492 } |
| 7504 | 7493 |
| (...skipping 11351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18856 return tag_label.ToCString(); | 18845 return tag_label.ToCString(); |
| 18857 } | 18846 } |
| 18858 | 18847 |
| 18859 | 18848 |
| 18860 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 18849 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 18861 Instance::PrintJSONImpl(stream, ref); | 18850 Instance::PrintJSONImpl(stream, ref); |
| 18862 } | 18851 } |
| 18863 | 18852 |
| 18864 | 18853 |
| 18865 } // namespace dart | 18854 } // namespace dart |
| OLD | NEW |