Chromium Code Reviews| 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 6528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6539 | 6539 |
| 6540 static RawString* MakeFunctionMetaName(const Function& func) { | 6540 static RawString* MakeFunctionMetaName(const Function& func) { |
| 6541 const String& cname = | 6541 const String& cname = |
| 6542 String::Handle(MakeClassMetaName(Class::Handle(func.origin()))); | 6542 String::Handle(MakeClassMetaName(Class::Handle(func.origin()))); |
| 6543 String& fname = String::Handle(func.name()); | 6543 String& fname = String::Handle(func.name()); |
| 6544 fname = String::Concat(Symbols::At(), fname); | 6544 fname = String::Concat(Symbols::At(), fname); |
| 6545 return String::Concat(cname, fname); | 6545 return String::Concat(cname, fname); |
| 6546 } | 6546 } |
| 6547 | 6547 |
| 6548 | 6548 |
| 6549 static RawString* MakeTypeParameterMetaName(const TypeParameter& param) { | |
| 6550 const String& cname = String::Handle( | |
| 6551 MakeClassMetaName(Class::Handle(param.parameterized_class()))); | |
| 6552 String& pname = String::Handle(param.name()); | |
| 6553 // We need to choose something different from field/function names, because it | |
| 6554 // is allowed to have type parameters and fields/functions with the same name | |
| 6555 // in a class. | |
| 6556 pname = String::Concat(Symbols::Slash(), pname); | |
| 6557 return String::Concat(cname, pname); | |
|
siva
2013/09/14 00:58:41
Why not create an array and invoke String::ConcatA
Michael Lippautz (Google)
2013/09/16 16:44:35
Sure. Done.
| |
| 6558 } | |
| 6559 | |
| 6560 | |
| 6549 void Library::AddMetadata(const Class& cls, | 6561 void Library::AddMetadata(const Class& cls, |
| 6550 const String& name, | 6562 const String& name, |
| 6551 intptr_t token_pos) const { | 6563 intptr_t token_pos) const { |
| 6552 const String& metaname = String::Handle(Symbols::New(name)); | 6564 const String& metaname = String::Handle(Symbols::New(name)); |
| 6553 Field& field = Field::Handle(Field::New(metaname, | 6565 Field& field = Field::Handle(Field::New(metaname, |
| 6554 true, // is_static | 6566 true, // is_static |
| 6555 false, // is_final | 6567 false, // is_final |
| 6556 false, // is_const | 6568 false, // is_const |
| 6557 cls, | 6569 cls, |
| 6558 token_pos)); | 6570 token_pos)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 6577 } | 6589 } |
| 6578 | 6590 |
| 6579 | 6591 |
| 6580 void Library::AddFunctionMetadata(const Function& func, | 6592 void Library::AddFunctionMetadata(const Function& func, |
| 6581 intptr_t token_pos) const { | 6593 intptr_t token_pos) const { |
| 6582 AddMetadata(Class::Handle(func.origin()), | 6594 AddMetadata(Class::Handle(func.origin()), |
| 6583 String::Handle(MakeFunctionMetaName(func)), | 6595 String::Handle(MakeFunctionMetaName(func)), |
| 6584 token_pos); | 6596 token_pos); |
| 6585 } | 6597 } |
| 6586 | 6598 |
| 6599 | |
| 6600 void Library::AddTypeParameterMetadata(const TypeParameter& param, | |
| 6601 intptr_t token_pos) const { | |
| 6602 AddMetadata(Class::Handle(param.parameterized_class()), | |
| 6603 String::Handle(MakeTypeParameterMetaName(param)), | |
| 6604 token_pos); | |
| 6605 } | |
| 6606 | |
| 6607 | |
| 6587 void Library::AddLibraryMetadata(const Class& cls, intptr_t token_pos) const { | 6608 void Library::AddLibraryMetadata(const Class& cls, intptr_t token_pos) const { |
| 6588 AddMetadata(cls, Symbols::TopLevel(), token_pos); | 6609 AddMetadata(cls, Symbols::TopLevel(), token_pos); |
| 6589 } | 6610 } |
| 6590 | 6611 |
| 6591 | 6612 |
| 6592 RawString* Library::MakeMetadataName(const Object& obj) const { | 6613 RawString* Library::MakeMetadataName(const Object& obj) const { |
| 6593 if (obj.IsClass()) { | 6614 if (obj.IsClass()) { |
| 6594 return MakeClassMetaName(Class::Cast(obj)); | 6615 return MakeClassMetaName(Class::Cast(obj)); |
| 6595 } else if (obj.IsField()) { | 6616 } else if (obj.IsField()) { |
| 6596 return MakeFieldMetaName(Field::Cast(obj)); | 6617 return MakeFieldMetaName(Field::Cast(obj)); |
| 6597 } else if (obj.IsFunction()) { | 6618 } else if (obj.IsFunction()) { |
| 6598 return MakeFunctionMetaName(Function::Cast(obj)); | 6619 return MakeFunctionMetaName(Function::Cast(obj)); |
| 6599 } else if (obj.IsLibrary()) { | 6620 } else if (obj.IsLibrary()) { |
| 6600 return Symbols::TopLevel().raw(); | 6621 return Symbols::TopLevel().raw(); |
| 6622 } else if (obj.IsTypeParameter()) { | |
| 6623 return MakeTypeParameterMetaName(TypeParameter::Cast(obj)); | |
| 6601 } | 6624 } |
| 6602 UNIMPLEMENTED(); | 6625 UNIMPLEMENTED(); |
| 6603 return String::null(); | 6626 return String::null(); |
| 6604 } | 6627 } |
| 6605 | 6628 |
| 6606 | 6629 |
| 6607 RawField* Library::GetMetadataField(const String& metaname) const { | 6630 RawField* Library::GetMetadataField(const String& metaname) const { |
| 6608 const GrowableObjectArray& metadata = | 6631 const GrowableObjectArray& metadata = |
| 6609 GrowableObjectArray::Handle(this->metadata()); | 6632 GrowableObjectArray::Handle(this->metadata()); |
| 6610 Field& entry = Field::Handle(); | 6633 Field& entry = Field::Handle(); |
| 6611 String& entryname = String::Handle(); | 6634 String& entryname = String::Handle(); |
| 6612 intptr_t num_entries = metadata.Length(); | 6635 intptr_t num_entries = metadata.Length(); |
| 6613 for (intptr_t i = 0; i < num_entries; i++) { | 6636 for (intptr_t i = 0; i < num_entries; i++) { |
| 6614 entry ^= metadata.At(i); | 6637 entry ^= metadata.At(i); |
| 6615 entryname = entry.name(); | 6638 entryname = entry.name(); |
| 6616 if (entryname.Equals(metaname)) { | 6639 if (entryname.Equals(metaname)) { |
| 6617 return entry.raw(); | 6640 return entry.raw(); |
| 6618 } | 6641 } |
| 6619 } | 6642 } |
| 6620 return Field::null(); | 6643 return Field::null(); |
| 6621 } | 6644 } |
| 6622 | 6645 |
| 6623 | 6646 |
| 6624 RawObject* Library::GetMetadata(const Object& obj) const { | 6647 RawObject* Library::GetMetadata(const Object& obj) const { |
| 6625 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() && | 6648 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() && |
| 6626 !obj.IsLibrary()) { | 6649 !obj.IsLibrary() && !obj.IsTypeParameter()) { |
| 6627 return Object::null(); | 6650 return Object::null(); |
| 6628 } | 6651 } |
| 6629 const String& metaname = String::Handle(MakeMetadataName(obj)); | 6652 const String& metaname = String::Handle(MakeMetadataName(obj)); |
| 6630 Field& field = Field::Handle(GetMetadataField(metaname)); | 6653 Field& field = Field::Handle(GetMetadataField(metaname)); |
| 6631 if (field.IsNull()) { | 6654 if (field.IsNull()) { |
| 6632 // There is no metadata for this object. | 6655 // There is no metadata for this object. |
| 6633 return Object::empty_array().raw();; | 6656 return Object::empty_array().raw();; |
| 6634 } | 6657 } |
| 6635 Object& metadata = Object::Handle(); | 6658 Object& metadata = Object::Handle(); |
| 6636 metadata = field.value(); | 6659 metadata = field.value(); |
| (...skipping 8248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14885 return "_MirrorReference"; | 14908 return "_MirrorReference"; |
| 14886 } | 14909 } |
| 14887 | 14910 |
| 14888 | 14911 |
| 14889 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14912 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14890 JSONObject jsobj(stream); | 14913 JSONObject jsobj(stream); |
| 14891 } | 14914 } |
| 14892 | 14915 |
| 14893 | 14916 |
| 14894 } // namespace dart | 14917 } // namespace dart |
| OLD | NEW |