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

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

Issue 9240014: Set breakpoint at url, line number (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) { 1578 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) {
1579 return function.raw(); 1579 return function.raw();
1580 } 1580 }
1581 } 1581 }
1582 1582
1583 // No function found. 1583 // No function found.
1584 return Function::null(); 1584 return Function::null();
1585 } 1585 }
1586 1586
1587 1587
1588 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const {
1589 // TODO(hausner): we can shortcut the negative case if we knew the
1590 // beginning and end token position of the class.
1591 Array& funcs = Array::Handle(functions());
1592 Function& func = Function::Handle();
1593 intptr_t len = funcs.Length();
1594 for (intptr_t i = 0; i < len; i++) {
1595 func ^= funcs.At(i);
1596 if ((func.token_index() <= token_index) &&
1597 (token_index < func.end_token_index())) {
1598 return func.raw();
1599 }
1600 }
1601
1602 // No function found.
1603 return Function::null();
1604 }
1605
1606
1588 RawField* Class::LookupInstanceField(const String& name) const { 1607 RawField* Class::LookupInstanceField(const String& name) const {
1589 ASSERT(is_finalized()); 1608 ASSERT(is_finalized());
1590 const Field& field = Field::Handle(LookupField(name)); 1609 const Field& field = Field::Handle(LookupField(name));
1591 if (!field.IsNull()) { 1610 if (!field.IsNull()) {
1592 if (field.is_static()) { 1611 if (field.is_static()) {
1593 // Name matches but it is not of the correct kind, return NULL. 1612 // Name matches but it is not of the correct kind, return NULL.
1594 return Field::null(); 1613 return Field::null();
1595 } 1614 }
1596 return field.raw(); 1615 return field.raw();
1597 } 1616 }
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 bool is_const, 3253 bool is_const,
3235 intptr_t token_index) { 3254 intptr_t token_index) {
3236 const Function& result = Function::Handle(Function::New()); 3255 const Function& result = Function::Handle(Function::New());
3237 result.set_parameter_types(Array::Handle(Array::Empty())); 3256 result.set_parameter_types(Array::Handle(Array::Empty()));
3238 result.set_parameter_names(Array::Handle(Array::Empty())); 3257 result.set_parameter_names(Array::Handle(Array::Empty()));
3239 result.set_name(name); 3258 result.set_name(name);
3240 result.set_kind(kind); 3259 result.set_kind(kind);
3241 result.set_is_static(is_static); 3260 result.set_is_static(is_static);
3242 result.set_is_const(is_const); 3261 result.set_is_const(is_const);
3243 result.set_token_index(token_index); 3262 result.set_token_index(token_index);
3263 result.set_end_token_index(token_index);
3244 result.set_num_fixed_parameters(0); 3264 result.set_num_fixed_parameters(0);
3245 result.set_num_optional_parameters(0); 3265 result.set_num_optional_parameters(0);
3246 result.set_invocation_counter(0); 3266 result.set_invocation_counter(0);
3247 result.set_deoptimization_counter(0); 3267 result.set_deoptimization_counter(0);
3248 result.set_is_optimizable(true); 3268 result.set_is_optimizable(true);
3249 return result.raw(); 3269 return result.raw();
3250 } 3270 }
3251 3271
3252 3272
3253 RawFunction* Function::NewClosureFunction(const String& name, 3273 RawFunction* Function::NewClosureFunction(const String& name,
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
3696 intptr_t* column) const { 3716 intptr_t* column) const {
3697 const String& src = String::Handle(source()); 3717 const String& src = String::Handle(source());
3698 const String& dummy_key = String::Handle(String::New("")); 3718 const String& dummy_key = String::Handle(String::New(""));
3699 Scanner scanner(src, dummy_key); 3719 Scanner scanner(src, dummy_key);
3700 scanner.ScanTo(token_index); 3720 scanner.ScanTo(token_index);
3701 *line = scanner.CurrentPosition().line; 3721 *line = scanner.CurrentPosition().line;
3702 *column = scanner.CurrentPosition().column; 3722 *column = scanner.CurrentPosition().column;
3703 } 3723 }
3704 3724
3705 3725
3726 intptr_t Script::TokenIndexAtLine(intptr_t line_number) const {
3727 const String& src = String::Handle(source());
3728 const String& dummy_key = String::Handle(String::New(""));
3729 Scanner scanner(src, dummy_key);
3730 return scanner.TokenIndexAtLine(line_number);
3731 }
3732
3733
3706 RawString* Script::GetLine(intptr_t line_number) const { 3734 RawString* Script::GetLine(intptr_t line_number) const {
3707 const String& src = String::Handle(source()); 3735 const String& src = String::Handle(source());
3708 intptr_t current_line = 1; 3736 intptr_t current_line = 1;
3709 intptr_t line_start = -1; 3737 intptr_t line_start = -1;
3710 intptr_t last_char = -1; 3738 intptr_t last_char = -1;
3711 for (intptr_t ix = 0; 3739 for (intptr_t ix = 0;
3712 (ix < src.Length()) && (current_line <= line_number); 3740 (ix < src.Length()) && (current_line <= line_number);
3713 ix++) { 3741 ix++) {
3714 if ((current_line == line_number) && (line_start < 0)) { 3742 if ((current_line == line_number) && (line_start < 0)) {
3715 line_start = ix; 3743 line_start = ix;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 } 4003 }
3976 4004
3977 4005
3978 void Library::AddClass(const Class& cls) const { 4006 void Library::AddClass(const Class& cls) const {
3979 AddObject(cls, String::Handle(cls.Name())); 4007 AddObject(cls, String::Handle(cls.Name()));
3980 // Link class to this library. 4008 // Link class to this library.
3981 cls.set_library(*this); 4009 cls.set_library(*this);
3982 } 4010 }
3983 4011
3984 4012
4013 // TODO(hausner): we might want to add a script dictionary to the
4014 // library class to make this lookup less cumbersome.
4015 RawScript* Library::LookupScript(const String& url) const {
4016 Object& entry = Object::Handle();
4017 Class& cls = Class::Handle();
4018 Function& func = Function::Handle();
4019 Field& field = Field::Handle();
4020 Script& owner_script = Script::Handle();
4021 String& owner_url = String::Handle();
4022
4023 DictionaryIterator it(*this);
4024 while (it.HasNext()) {
4025 entry = it.GetNext();
4026 if (entry.IsClass()) {
4027 cls ^= entry.raw();
4028 } else if (entry.IsFunction()) {
4029 func ^= entry.raw();
4030 cls = func.owner();
4031 } else if (entry.IsField()) {
4032 field ^= entry.raw();
4033 cls = field.owner();
4034 } else {
4035 continue;
4036 }
4037 owner_script = cls.script();
4038 if (owner_script.IsNull()) {
4039 continue;
4040 }
4041 owner_url = owner_script.url();
4042 if (owner_url.Equals(url)) {
4043 return owner_script.raw();
4044 }
4045 }
4046 return Script::null();
4047 }
4048
4049
4050 RawFunction* Library::LookupFunctionInSource(const String& script_url,
4051 intptr_t line_number) const {
4052 Script& script = Script::Handle(LookupScript(script_url));
4053 if (script.IsNull()) {
4054 // The given script url is not loaded into this library.
4055 return Function::null();
4056 }
4057
4058 // Determine token position at given line number.
4059 intptr_t token_index_at_line = script.TokenIndexAtLine(line_number);
4060 if (token_index_at_line < 0) {
4061 // Script does not contain the given line number.
4062 return Function::null();
4063 }
4064
4065 return LookupFunctionInScript(script, token_index_at_line);
4066 }
4067
4068
4069 RawFunction* Library::LookupFunctionInScript(const Script& script,
4070 intptr_t token_index) const {
4071 Object& entry = Object::Handle();
4072 Class& cls = Class::Handle();
4073 Function& func = Function::Handle();
4074 DictionaryIterator it(*this);
4075 while (it.HasNext()) {
4076 entry = it.GetNext();
4077 if (entry.IsFunction()) {
4078 func ^= entry.raw();
4079 cls = func.owner();
4080 if (script.raw() == cls.script()) {
4081 if ((func.token_index() <= token_index) &&
4082 (token_index < func.end_token_index())) {
4083 return func.raw();
4084 }
4085 }
4086 } else if (entry.IsClass()) {
4087 cls ^= entry.raw();
4088 if (script.raw() == cls.script()) {
4089 func = cls.LookupFunctionAtToken(token_index);
4090 if (!func.IsNull()) {
4091 return func.raw();
4092 }
4093 }
4094 }
4095 }
4096 return Function::null();
4097 }
4098
4099
3985 RawObject* Library::LookupLocalObject(const String& name) const { 4100 RawObject* Library::LookupLocalObject(const String& name) const {
3986 Isolate* isolate = Isolate::Current(); 4101 Isolate* isolate = Isolate::Current();
3987 const Array& dict = Array::Handle(isolate, dictionary()); 4102 const Array& dict = Array::Handle(isolate, dictionary());
3988 intptr_t dict_size = dict.Length() - 1; 4103 intptr_t dict_size = dict.Length() - 1;
3989 intptr_t index = name.Hash() % dict_size; 4104 intptr_t index = name.Hash() % dict_size;
3990 4105
3991 Object& entry = Object::Handle(isolate, Object::null()); 4106 Object& entry = Object::Handle(isolate, Object::null());
3992 Class& cls = Class::Handle(isolate, Class::null()); 4107 Class& cls = Class::Handle(isolate, Class::null());
3993 Function& func = Function::Handle(isolate, Function::null()); 4108 Function& func = Function::Handle(isolate, Function::null());
3994 Field& field = Field::Handle(isolate, Field::null()); 4109 Field& field = Field::Handle(isolate, Field::null());
(...skipping 3628 matching lines...) Expand 10 before | Expand all | Expand 10 after
7623 const String& str = String::Handle(pattern()); 7738 const String& str = String::Handle(pattern());
7624 const char* format = "JSRegExp: pattern=%s flags=%s"; 7739 const char* format = "JSRegExp: pattern=%s flags=%s";
7625 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7740 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7626 char* chars = reinterpret_cast<char*>( 7741 char* chars = reinterpret_cast<char*>(
7627 Isolate::Current()->current_zone()->Allocate(len + 1)); 7742 Isolate::Current()->current_zone()->Allocate(len + 1));
7628 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7743 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7629 return chars; 7744 return chars;
7630 } 7745 }
7631 7746
7632 } // namespace dart 7747 } // 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