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

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

Issue 23872010: Add metadata for type parameters (TypeVariableMirror). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed comments Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | 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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 6528 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Array& parts = Array::Handle(Array::New(3));
6551 String& part = String::Handle();
6552 part ^= MakeClassMetaName(Class::Handle(param.parameterized_class()));
6553 parts.SetAt(0, part);
6554 // We need to choose something different from field/function names, because it
6555 // is allowed to have type parameters and fields/functions with the same name
6556 // in a class.
6557 parts.SetAt(1, Symbols::Slash());
6558 part ^= param.name();
6559 parts.SetAt(2, part);
6560 return String::ConcatAll(parts);
6561 }
6562
6563
6549 void Library::AddMetadata(const Class& cls, 6564 void Library::AddMetadata(const Class& cls,
6550 const String& name, 6565 const String& name,
6551 intptr_t token_pos) const { 6566 intptr_t token_pos) const {
6552 const String& metaname = String::Handle(Symbols::New(name)); 6567 const String& metaname = String::Handle(Symbols::New(name));
6553 Field& field = Field::Handle(Field::New(metaname, 6568 Field& field = Field::Handle(Field::New(metaname,
6554 true, // is_static 6569 true, // is_static
6555 false, // is_final 6570 false, // is_final
6556 false, // is_const 6571 false, // is_const
6557 cls, 6572 cls,
6558 token_pos)); 6573 token_pos));
(...skipping 18 matching lines...) Expand all
6577 } 6592 }
6578 6593
6579 6594
6580 void Library::AddFunctionMetadata(const Function& func, 6595 void Library::AddFunctionMetadata(const Function& func,
6581 intptr_t token_pos) const { 6596 intptr_t token_pos) const {
6582 AddMetadata(Class::Handle(func.origin()), 6597 AddMetadata(Class::Handle(func.origin()),
6583 String::Handle(MakeFunctionMetaName(func)), 6598 String::Handle(MakeFunctionMetaName(func)),
6584 token_pos); 6599 token_pos);
6585 } 6600 }
6586 6601
6602
6603 void Library::AddTypeParameterMetadata(const TypeParameter& param,
6604 intptr_t token_pos) const {
6605 AddMetadata(Class::Handle(param.parameterized_class()),
6606 String::Handle(MakeTypeParameterMetaName(param)),
6607 token_pos);
6608 }
6609
6610
6587 void Library::AddLibraryMetadata(const Class& cls, intptr_t token_pos) const { 6611 void Library::AddLibraryMetadata(const Class& cls, intptr_t token_pos) const {
6588 AddMetadata(cls, Symbols::TopLevel(), token_pos); 6612 AddMetadata(cls, Symbols::TopLevel(), token_pos);
6589 } 6613 }
6590 6614
6591 6615
6592 RawString* Library::MakeMetadataName(const Object& obj) const { 6616 RawString* Library::MakeMetadataName(const Object& obj) const {
6593 if (obj.IsClass()) { 6617 if (obj.IsClass()) {
6594 return MakeClassMetaName(Class::Cast(obj)); 6618 return MakeClassMetaName(Class::Cast(obj));
6595 } else if (obj.IsField()) { 6619 } else if (obj.IsField()) {
6596 return MakeFieldMetaName(Field::Cast(obj)); 6620 return MakeFieldMetaName(Field::Cast(obj));
6597 } else if (obj.IsFunction()) { 6621 } else if (obj.IsFunction()) {
6598 return MakeFunctionMetaName(Function::Cast(obj)); 6622 return MakeFunctionMetaName(Function::Cast(obj));
6599 } else if (obj.IsLibrary()) { 6623 } else if (obj.IsLibrary()) {
6600 return Symbols::TopLevel().raw(); 6624 return Symbols::TopLevel().raw();
6625 } else if (obj.IsTypeParameter()) {
6626 return MakeTypeParameterMetaName(TypeParameter::Cast(obj));
6601 } 6627 }
6602 UNIMPLEMENTED(); 6628 UNIMPLEMENTED();
6603 return String::null(); 6629 return String::null();
6604 } 6630 }
6605 6631
6606 6632
6607 RawField* Library::GetMetadataField(const String& metaname) const { 6633 RawField* Library::GetMetadataField(const String& metaname) const {
6608 const GrowableObjectArray& metadata = 6634 const GrowableObjectArray& metadata =
6609 GrowableObjectArray::Handle(this->metadata()); 6635 GrowableObjectArray::Handle(this->metadata());
6610 Field& entry = Field::Handle(); 6636 Field& entry = Field::Handle();
6611 String& entryname = String::Handle(); 6637 String& entryname = String::Handle();
6612 intptr_t num_entries = metadata.Length(); 6638 intptr_t num_entries = metadata.Length();
6613 for (intptr_t i = 0; i < num_entries; i++) { 6639 for (intptr_t i = 0; i < num_entries; i++) {
6614 entry ^= metadata.At(i); 6640 entry ^= metadata.At(i);
6615 entryname = entry.name(); 6641 entryname = entry.name();
6616 if (entryname.Equals(metaname)) { 6642 if (entryname.Equals(metaname)) {
6617 return entry.raw(); 6643 return entry.raw();
6618 } 6644 }
6619 } 6645 }
6620 return Field::null(); 6646 return Field::null();
6621 } 6647 }
6622 6648
6623 6649
6624 RawObject* Library::GetMetadata(const Object& obj) const { 6650 RawObject* Library::GetMetadata(const Object& obj) const {
6625 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() && 6651 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() &&
6626 !obj.IsLibrary()) { 6652 !obj.IsLibrary() && !obj.IsTypeParameter()) {
6627 return Object::null(); 6653 return Object::null();
6628 } 6654 }
6629 const String& metaname = String::Handle(MakeMetadataName(obj)); 6655 const String& metaname = String::Handle(MakeMetadataName(obj));
6630 Field& field = Field::Handle(GetMetadataField(metaname)); 6656 Field& field = Field::Handle(GetMetadataField(metaname));
6631 if (field.IsNull()) { 6657 if (field.IsNull()) {
6632 // There is no metadata for this object. 6658 // There is no metadata for this object.
6633 return Object::empty_array().raw();; 6659 return Object::empty_array().raw();;
6634 } 6660 }
6635 Object& metadata = Object::Handle(); 6661 Object& metadata = Object::Handle();
6636 metadata = field.value(); 6662 metadata = field.value();
(...skipping 8248 matching lines...) Expand 10 before | Expand all | Expand 10 after
14885 return "_MirrorReference"; 14911 return "_MirrorReference";
14886 } 14912 }
14887 14913
14888 14914
14889 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14915 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14890 JSONObject jsobj(stream); 14916 JSONObject jsobj(stream);
14891 } 14917 }
14892 14918
14893 14919
14894 } // namespace dart 14920 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698