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

Side by Side Diff: vm/object.cc

Issue 10632009: Make the parser agnostic to the TokenStream implementation. This is the first step towards compacti… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 | « vm/object.h ('k') | vm/opt_code_generator_ia32.h » ('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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 // way as the owner class of its non-static signature function. 1031 // way as the owner class of its non-static signature function.
1032 // It is not type parameterized if its signature function is static. 1032 // It is not type parameterized if its signature function is static.
1033 // See Class::NewSignatureClass() for the setup of its type parameters. 1033 // See Class::NewSignatureClass() for the setup of its type parameters.
1034 // During type finalization, the type arguments of the super class of the 1034 // During type finalization, the type arguments of the super class of the
1035 // owner class of its signature function will be prepended to the type 1035 // owner class of its signature function will be prepended to the type
1036 // argument vector. Therefore, we only need to set the type arguments 1036 // argument vector. Therefore, we only need to set the type arguments
1037 // matching the type parameters here. 1037 // matching the type parameters here.
1038 const TypeArguments& signature_type_arguments = 1038 const TypeArguments& signature_type_arguments =
1039 TypeArguments::Handle(type_parameters()); 1039 TypeArguments::Handle(type_parameters());
1040 const Type& signature_type = Type::Handle( 1040 const Type& signature_type = Type::Handle(
1041 Type::New(*this, signature_type_arguments, token_index())); 1041 Type::New(*this, signature_type_arguments, token_pos()));
1042 1042
1043 // Return the still unfinalized signature type. 1043 // Return the still unfinalized signature type.
1044 ASSERT(!signature_type.IsFinalized()); 1044 ASSERT(!signature_type.IsFinalized());
1045 return signature_type.raw(); 1045 return signature_type.raw();
1046 } 1046 }
1047 1047
1048 1048
1049 template <class FakeObject> 1049 template <class FakeObject>
1050 RawClass* Class::New() { 1050 RawClass* Class::New() {
1051 Class& class_class = Class::Handle(Object::class_class()); 1051 Class& class_class = Class::Handle(Object::class_class());
(...skipping 12 matching lines...) Expand all
1064 result.set_instance_kind(FakeObject::kInstanceKind); 1064 result.set_instance_kind(FakeObject::kInstanceKind);
1065 result.set_id((FakeObject::kInstanceKind != kInstance) ? 1065 result.set_id((FakeObject::kInstanceKind != kInstance) ?
1066 FakeObject::kInstanceKind : kIllegalObjectKind); 1066 FakeObject::kInstanceKind : kIllegalObjectKind);
1067 result.raw_ptr()->is_const_ = false; 1067 result.raw_ptr()->is_const_ = false;
1068 result.raw_ptr()->is_interface_ = false; 1068 result.raw_ptr()->is_interface_ = false;
1069 // VM backed classes are almost ready: run checks and resolve class 1069 // VM backed classes are almost ready: run checks and resolve class
1070 // references, but do not recompute size. 1070 // references, but do not recompute size.
1071 result.raw_ptr()->class_state_ = RawClass::kPreFinalized; 1071 result.raw_ptr()->class_state_ = RawClass::kPreFinalized;
1072 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; 1072 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments;
1073 result.raw_ptr()->num_native_fields_ = 0; 1073 result.raw_ptr()->num_native_fields_ = 0;
1074 result.raw_ptr()->token_index_ = Scanner::kDummyTokenIndex; 1074 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex;
1075 result.InitEmptyFields(); 1075 result.InitEmptyFields();
1076 Isolate::Current()->class_table()->Register(result); 1076 Isolate::Current()->class_table()->Register(result);
1077 return result.raw(); 1077 return result.raw();
1078 } 1078 }
1079 1079
1080 1080
1081 // Initialize class fields of type Array with empty array. 1081 // Initialize class fields of type Array with empty array.
1082 void Class::InitEmptyFields() { 1082 void Class::InitEmptyFields() {
1083 const Array& empty_array = Array::Handle(Array::Empty()); 1083 const Array& empty_array = Array::Handle(Array::Empty());
1084 if (empty_array.IsNull()) { 1084 if (empty_array.IsNull()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); 1127 GrowableObjectArray::Handle(raw_ptr()->closure_functions_);
1128 if (closures.IsNull()) { 1128 if (closures.IsNull()) {
1129 closures = GrowableObjectArray::New(4); 1129 closures = GrowableObjectArray::New(4);
1130 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); 1130 StorePointer(&raw_ptr()->closure_functions_, closures.raw());
1131 } 1131 }
1132 ASSERT(function.IsNonImplicitClosureFunction()); 1132 ASSERT(function.IsNonImplicitClosureFunction());
1133 closures.Add(function); 1133 closures.Add(function);
1134 } 1134 }
1135 1135
1136 1136
1137 // Lookup the innermost closure function that contains token at token_index. 1137 // Lookup the innermost closure function that contains token at token_pos.
1138 RawFunction* Class::LookupClosureFunction(intptr_t token_index) const { 1138 RawFunction* Class::LookupClosureFunction(intptr_t token_pos) const {
1139 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) { 1139 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) {
1140 return Function::null(); 1140 return Function::null();
1141 } 1141 }
1142 const GrowableObjectArray& closures = 1142 const GrowableObjectArray& closures =
1143 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); 1143 GrowableObjectArray::Handle(raw_ptr()->closure_functions_);
1144 Function& closure = Function::Handle(); 1144 Function& closure = Function::Handle();
1145 intptr_t num_closures = closures.Length(); 1145 intptr_t num_closures = closures.Length();
1146 intptr_t best_fit_token_index = -1; 1146 intptr_t best_fit_token_pos = -1;
1147 intptr_t best_fit_index = -1; 1147 intptr_t best_fit_index = -1;
1148 for (intptr_t i = 0; i < num_closures; i++) { 1148 for (intptr_t i = 0; i < num_closures; i++) {
1149 closure ^= closures.At(i); 1149 closure ^= closures.At(i);
1150 ASSERT(!closure.IsNull()); 1150 ASSERT(!closure.IsNull());
1151 if ((closure.token_index() <= token_index) && 1151 if ((closure.token_pos() <= token_pos) &&
1152 (token_index < closure.end_token_index()) && 1152 (token_pos < closure.end_token_pos()) &&
1153 (best_fit_token_index < closure.token_index())) { 1153 (best_fit_token_pos < closure.token_pos())) {
1154 best_fit_index = i; 1154 best_fit_index = i;
1155 best_fit_token_index = closure.token_index(); 1155 best_fit_token_pos = closure.token_pos();
1156 } 1156 }
1157 } 1157 }
1158 closure = Function::null(); 1158 closure = Function::null();
1159 if (best_fit_index >= 0) { 1159 if (best_fit_index >= 0) {
1160 closure ^= closures.At(best_fit_index); 1160 closure ^= closures.At(best_fit_index);
1161 } 1161 }
1162 return closure.raw(); 1162 return closure.raw();
1163 } 1163 }
1164 1164
1165 1165
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 1278
1279 1279
1280 void Class::set_factory_class(const Object& value) const { 1280 void Class::set_factory_class(const Object& value) const {
1281 StorePointer(&raw_ptr()->factory_class_, value.raw()); 1281 StorePointer(&raw_ptr()->factory_class_, value.raw());
1282 } 1282 }
1283 1283
1284 1284
1285 // Return a TypeParameter if the type_name is a type parameter of this class. 1285 // Return a TypeParameter if the type_name is a type parameter of this class.
1286 // Return null otherwise. 1286 // Return null otherwise.
1287 RawTypeParameter* Class::LookupTypeParameter(const String& type_name, 1287 RawTypeParameter* Class::LookupTypeParameter(const String& type_name,
1288 intptr_t token_index) const { 1288 intptr_t token_pos) const {
1289 ASSERT(!type_name.IsNull()); 1289 ASSERT(!type_name.IsNull());
1290 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1290 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1291 if (!type_params.IsNull()) { 1291 if (!type_params.IsNull()) {
1292 intptr_t num_type_params = type_params.Length(); 1292 intptr_t num_type_params = type_params.Length();
1293 TypeParameter& type_param = TypeParameter::Handle(); 1293 TypeParameter& type_param = TypeParameter::Handle();
1294 String& type_param_name = String::Handle(); 1294 String& type_param_name = String::Handle();
1295 for (intptr_t i = 0; i < num_type_params; i++) { 1295 for (intptr_t i = 0; i < num_type_params; i++) {
1296 type_param ^= type_params.TypeAt(i); 1296 type_param ^= type_params.TypeAt(i);
1297 type_param_name = type_param.Name(); 1297 type_param_name = type_param.Name();
1298 if (type_param_name.Equals(type_name)) { 1298 if (type_param_name.Equals(type_name)) {
1299 intptr_t index = type_param.Index(); 1299 intptr_t index = type_param.Index();
1300 // Create a non-finalized new TypeParameter with the given token_index. 1300 // Create a non-finalized new TypeParameter with the given token_pos.
1301 if (type_param.IsFinalized()) { 1301 if (type_param.IsFinalized()) {
1302 // The index was adjusted during finalization. Revert. 1302 // The index was adjusted during finalization. Revert.
1303 index -= NumTypeArguments() - num_type_params; 1303 index -= NumTypeArguments() - num_type_params;
1304 } else { 1304 } else {
1305 ASSERT(type_param.Index() == i); 1305 ASSERT(type_param.Index() == i);
1306 } 1306 }
1307 return TypeParameter::New(*this, index, type_name, token_index); 1307 return TypeParameter::New(*this, index, type_name, token_pos);
1308 } 1308 }
1309 } 1309 }
1310 } 1310 }
1311 return TypeParameter::null(); 1311 return TypeParameter::null();
1312 } 1312 }
1313 1313
1314 1314
1315 void Class::CalculateFieldOffsets() const { 1315 void Class::CalculateFieldOffsets() const {
1316 Array& flds = Array::Handle(fields()); 1316 Array& flds = Array::Handle(fields());
1317 const Class& super = Class::Handle(SuperClass()); 1317 const Class& super = Class::Handle(SuperClass());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 result.raw_ptr()->num_native_fields_ = 0; 1409 result.raw_ptr()->num_native_fields_ = 0;
1410 result.InitEmptyFields(); 1410 result.InitEmptyFields();
1411 Isolate::Current()->class_table()->Register(result); 1411 Isolate::Current()->class_table()->Register(result);
1412 return result.raw(); 1412 return result.raw();
1413 } 1413 }
1414 1414
1415 1415
1416 template <class FakeInstance> 1416 template <class FakeInstance>
1417 RawClass* Class::New(const String& name, 1417 RawClass* Class::New(const String& name,
1418 const Script& script, 1418 const Script& script,
1419 intptr_t token_index) { 1419 intptr_t token_pos) {
1420 Class& result = Class::Handle(New<FakeInstance>(kIllegalObjectKind)); 1420 Class& result = Class::Handle(New<FakeInstance>(kIllegalObjectKind));
1421 result.set_name(name); 1421 result.set_name(name);
1422 result.set_script(script); 1422 result.set_script(script);
1423 result.set_token_index(token_index); 1423 result.set_token_pos(token_pos);
1424 return result.raw(); 1424 return result.raw();
1425 } 1425 }
1426 1426
1427 1427
1428 RawClass* Class::New(const String& name, 1428 RawClass* Class::New(const String& name,
1429 const Script& script, 1429 const Script& script,
1430 intptr_t token_index) { 1430 intptr_t token_pos) {
1431 Class& result = Class::Handle(New<Instance>(name, script, token_index)); 1431 Class& result = Class::Handle(New<Instance>(name, script, token_pos));
1432 return result.raw(); 1432 return result.raw();
1433 } 1433 }
1434 1434
1435 1435
1436 RawClass* Class::NewInterface(const String& name, 1436 RawClass* Class::NewInterface(const String& name,
1437 const Script& script, 1437 const Script& script,
1438 intptr_t token_index) { 1438 intptr_t token_pos) {
1439 Class& result = Class::Handle(New<Instance>(name, script, token_index)); 1439 Class& result = Class::Handle(New<Instance>(name, script, token_pos));
1440 result.set_is_interface(); 1440 result.set_is_interface();
1441 return result.raw(); 1441 return result.raw();
1442 } 1442 }
1443 1443
1444 1444
1445 RawClass* Class::NewSignatureClass(const String& name, 1445 RawClass* Class::NewSignatureClass(const String& name,
1446 const Function& signature_function, 1446 const Function& signature_function,
1447 const Script& script) { 1447 const Script& script) {
1448 ASSERT(!signature_function.IsNull()); 1448 ASSERT(!signature_function.IsNull());
1449 const Class& owner_class = Class::Handle(signature_function.owner()); 1449 const Class& owner_class = Class::Handle(signature_function.owner());
1450 ASSERT(!owner_class.IsNull()); 1450 ASSERT(!owner_class.IsNull());
1451 TypeArguments& type_parameters = TypeArguments::Handle(); 1451 TypeArguments& type_parameters = TypeArguments::Handle();
1452 TypeArguments& type_parameter_bounds = TypeArguments::Handle(); 1452 TypeArguments& type_parameter_bounds = TypeArguments::Handle();
1453 // A signature class extends class Instance and is parameterized in the same 1453 // A signature class extends class Instance and is parameterized in the same
1454 // way as the owner class of its non-static signature function. 1454 // way as the owner class of its non-static signature function.
1455 // It is not type parameterized if its signature function is static. 1455 // It is not type parameterized if its signature function is static.
1456 if (!signature_function.is_static()) { 1456 if (!signature_function.is_static()) {
1457 if ((owner_class.NumTypeParameters() > 0) && 1457 if ((owner_class.NumTypeParameters() > 0) &&
1458 !signature_function.HasInstantiatedSignature()) { 1458 !signature_function.HasInstantiatedSignature()) {
1459 type_parameters = owner_class.type_parameters(); 1459 type_parameters = owner_class.type_parameters();
1460 type_parameter_bounds = owner_class.type_parameter_bounds(); 1460 type_parameter_bounds = owner_class.type_parameter_bounds();
1461 } 1461 }
1462 } 1462 }
1463 const intptr_t token_index = signature_function.token_index(); 1463 const intptr_t token_pos = signature_function.token_pos();
1464 Class& result = Class::Handle(New<Closure>(name, script, token_index)); 1464 Class& result = Class::Handle(New<Closure>(name, script, token_pos));
1465 const Type& super_type = Type::Handle(Type::ObjectType()); 1465 const Type& super_type = Type::Handle(Type::ObjectType());
1466 ASSERT(!super_type.IsNull()); 1466 ASSERT(!super_type.IsNull());
1467 result.set_super_type(super_type); 1467 result.set_super_type(super_type);
1468 result.set_signature_function(signature_function); 1468 result.set_signature_function(signature_function);
1469 result.set_type_parameters(type_parameters); 1469 result.set_type_parameters(type_parameters);
1470 result.set_type_parameter_bounds(type_parameter_bounds); 1470 result.set_type_parameter_bounds(type_parameter_bounds);
1471 result.SetFields(Array::Handle(Array::Empty())); 1471 result.SetFields(Array::Handle(Array::Empty()));
1472 result.SetFunctions(Array::Handle(Array::Empty())); 1472 result.SetFunctions(Array::Handle(Array::Empty()));
1473 result.set_type_arguments_instance_field_offset( 1473 result.set_type_arguments_instance_field_offset(
1474 Closure::type_arguments_offset()); 1474 Closure::type_arguments_offset());
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 ASSERT(value.IsSymbol()); 1653 ASSERT(value.IsSymbol());
1654 StorePointer(&raw_ptr()->name_, value.raw()); 1654 StorePointer(&raw_ptr()->name_, value.raw());
1655 } 1655 }
1656 1656
1657 1657
1658 void Class::set_script(const Script& value) const { 1658 void Class::set_script(const Script& value) const {
1659 StorePointer(&raw_ptr()->script_, value.raw()); 1659 StorePointer(&raw_ptr()->script_, value.raw());
1660 } 1660 }
1661 1661
1662 1662
1663 void Class::set_token_index(intptr_t token_index) const { 1663 void Class::set_token_pos(intptr_t token_pos) const {
1664 ASSERT(token_index >= 0); 1664 ASSERT(token_pos >= 0);
1665 raw_ptr()->token_index_ = token_index; 1665 raw_ptr()->token_pos_ = token_pos;
1666 } 1666 }
1667 1667
1668 1668
1669 void Class::set_is_interface() const { 1669 void Class::set_is_interface() const {
1670 raw_ptr()->is_interface_ = true; 1670 raw_ptr()->is_interface_ = true;
1671 } 1671 }
1672 1672
1673 1673
1674 void Class::set_is_const() const { 1674 void Class::set_is_const() const {
1675 raw_ptr()->is_const_ = true; 1675 raw_ptr()->is_const_ = true;
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { 1997 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) {
1998 return function.raw(); 1998 return function.raw();
1999 } 1999 }
2000 } 2000 }
2001 2001
2002 // No function found. 2002 // No function found.
2003 return Function::null(); 2003 return Function::null();
2004 } 2004 }
2005 2005
2006 2006
2007 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const { 2007 RawFunction* Class::LookupFunctionAtToken(intptr_t token_pos) const {
2008 // TODO(hausner): we can shortcut the negative case if we knew the 2008 // TODO(hausner): we can shortcut the negative case if we knew the
2009 // beginning and end token position of the class. 2009 // beginning and end token position of the class.
2010 Function& func = Function::Handle(); 2010 Function& func = Function::Handle();
2011 func = LookupClosureFunction(token_index); 2011 func = LookupClosureFunction(token_pos);
2012 if (!func.IsNull()) { 2012 if (!func.IsNull()) {
2013 return func.raw(); 2013 return func.raw();
2014 } 2014 }
2015 Array& funcs = Array::Handle(functions()); 2015 Array& funcs = Array::Handle(functions());
2016 intptr_t len = funcs.Length(); 2016 intptr_t len = funcs.Length();
2017 for (intptr_t i = 0; i < len; i++) { 2017 for (intptr_t i = 0; i < len; i++) {
2018 func ^= funcs.At(i); 2018 func ^= funcs.At(i);
2019 if ((func.token_index() <= token_index) && 2019 if ((func.token_pos() <= token_pos) &&
2020 (token_index < func.end_token_index())) { 2020 (token_pos < func.end_token_pos())) {
2021 return func.raw(); 2021 return func.raw();
2022 } 2022 }
2023 } 2023 }
2024 // No function found. 2024 // No function found.
2025 return Function::null(); 2025 return Function::null();
2026 } 2026 }
2027 2027
2028 2028
2029 RawField* Class::LookupInstanceField(const String& name) const { 2029 RawField* Class::LookupInstanceField(const String& name) const {
2030 ASSERT(is_finalized()); 2030 ASSERT(is_finalized());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 set_constants(new_canonical_list); 2115 set_constants(new_canonical_list);
2116 new_canonical_list.SetAt(index, constant); 2116 new_canonical_list.SetAt(index, constant);
2117 } else { 2117 } else {
2118 canonical_list.SetAt(index, constant); 2118 canonical_list.SetAt(index, constant);
2119 } 2119 }
2120 } 2120 }
2121 2121
2122 2122
2123 RawUnresolvedClass* UnresolvedClass::New(const LibraryPrefix& library_prefix, 2123 RawUnresolvedClass* UnresolvedClass::New(const LibraryPrefix& library_prefix,
2124 const String& ident, 2124 const String& ident,
2125 intptr_t token_index) { 2125 intptr_t token_pos) {
2126 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New()); 2126 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New());
2127 type.set_library_prefix(library_prefix); 2127 type.set_library_prefix(library_prefix);
2128 type.set_ident(ident); 2128 type.set_ident(ident);
2129 type.set_token_index(token_index); 2129 type.set_token_pos(token_pos);
2130 return type.raw(); 2130 return type.raw();
2131 } 2131 }
2132 2132
2133 2133
2134 RawUnresolvedClass* UnresolvedClass::New() { 2134 RawUnresolvedClass* UnresolvedClass::New() {
2135 const Class& unresolved_class_class = 2135 const Class& unresolved_class_class =
2136 Class::Handle(Object::unresolved_class_class()); 2136 Class::Handle(Object::unresolved_class_class());
2137 RawObject* raw = Object::Allocate(unresolved_class_class, 2137 RawObject* raw = Object::Allocate(unresolved_class_class,
2138 UnresolvedClass::InstanceSize(), 2138 UnresolvedClass::InstanceSize(),
2139 Heap::kNew); 2139 Heap::kNew);
2140 return reinterpret_cast<RawUnresolvedClass*>(raw); 2140 return reinterpret_cast<RawUnresolvedClass*>(raw);
2141 } 2141 }
2142 2142
2143 2143
2144 void UnresolvedClass::set_token_index(intptr_t token_index) const { 2144 void UnresolvedClass::set_token_pos(intptr_t token_pos) const {
2145 ASSERT(token_index >= 0); 2145 ASSERT(token_pos >= 0);
2146 raw_ptr()->token_index_ = token_index; 2146 raw_ptr()->token_pos_ = token_pos;
2147 } 2147 }
2148 2148
2149 2149
2150 void UnresolvedClass::set_ident(const String& ident) const { 2150 void UnresolvedClass::set_ident(const String& ident) const {
2151 StorePointer(&raw_ptr()->ident_, ident.raw()); 2151 StorePointer(&raw_ptr()->ident_, ident.raw());
2152 } 2152 }
2153 2153
2154 2154
2155 void UnresolvedClass::set_library_prefix( 2155 void UnresolvedClass::set_library_prefix(
2156 const LibraryPrefix& library_prefix) const { 2156 const LibraryPrefix& library_prefix) const {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 } 2213 }
2214 2214
2215 2215
2216 RawAbstractTypeArguments* AbstractType::arguments() const { 2216 RawAbstractTypeArguments* AbstractType::arguments() const {
2217 // AbstractType is an abstract class. 2217 // AbstractType is an abstract class.
2218 UNREACHABLE(); 2218 UNREACHABLE();
2219 return NULL; 2219 return NULL;
2220 } 2220 }
2221 2221
2222 2222
2223 intptr_t AbstractType::token_index() const { 2223 intptr_t AbstractType::token_pos() const {
2224 // AbstractType is an abstract class. 2224 // AbstractType is an abstract class.
2225 UNREACHABLE(); 2225 UNREACHABLE();
2226 return -1; 2226 return -1;
2227 } 2227 }
2228 2228
2229 2229
2230 bool AbstractType::IsInstantiated() const { 2230 bool AbstractType::IsInstantiated() const {
2231 // AbstractType is an abstract class. 2231 // AbstractType is an abstract class.
2232 UNREACHABLE(); 2232 UNREACHABLE();
2233 return false; 2233 return false;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2653 RawAbstractType* Type::InstantiateFrom( 2653 RawAbstractType* Type::InstantiateFrom(
2654 const AbstractTypeArguments& instantiator_type_arguments) const { 2654 const AbstractTypeArguments& instantiator_type_arguments) const {
2655 ASSERT(IsFinalized()); 2655 ASSERT(IsFinalized());
2656 ASSERT(!IsInstantiated()); 2656 ASSERT(!IsInstantiated());
2657 AbstractTypeArguments& type_arguments = 2657 AbstractTypeArguments& type_arguments =
2658 AbstractTypeArguments::Handle(arguments()); 2658 AbstractTypeArguments::Handle(arguments());
2659 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); 2659 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments);
2660 const Class& cls = Class::Handle(type_class()); 2660 const Class& cls = Class::Handle(type_class());
2661 ASSERT(cls.is_finalized()); 2661 ASSERT(cls.is_finalized());
2662 Type& instantiated_type = Type::Handle( 2662 Type& instantiated_type = Type::Handle(
2663 Type::New(cls, type_arguments, token_index())); 2663 Type::New(cls, type_arguments, token_pos()));
2664 ASSERT(type_arguments.IsNull() || 2664 ASSERT(type_arguments.IsNull() ||
2665 (type_arguments.Length() == cls.NumTypeArguments())); 2665 (type_arguments.Length() == cls.NumTypeArguments()));
2666 instantiated_type.set_is_finalized_instantiated(); 2666 instantiated_type.set_is_finalized_instantiated();
2667 return instantiated_type.raw(); 2667 return instantiated_type.raw();
2668 } 2668 }
2669 2669
2670 2670
2671 bool Type::Equals(const AbstractType& other) const { 2671 bool Type::Equals(const AbstractType& other) const {
2672 ASSERT(IsFinalized() && other.IsFinalized()); 2672 ASSERT(IsFinalized() && other.IsFinalized());
2673 if (raw() == other.raw()) { 2673 if (raw() == other.raw()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2769 const Class& type_class = Class::Handle(Object::type_class()); 2769 const Class& type_class = Class::Handle(Object::type_class());
2770 RawObject* raw = Object::Allocate(type_class, 2770 RawObject* raw = Object::Allocate(type_class,
2771 Type::InstanceSize(), 2771 Type::InstanceSize(),
2772 Heap::kOld); 2772 Heap::kOld);
2773 return reinterpret_cast<RawType*>(raw); 2773 return reinterpret_cast<RawType*>(raw);
2774 } 2774 }
2775 2775
2776 2776
2777 RawType* Type::New(const Object& clazz, 2777 RawType* Type::New(const Object& clazz,
2778 const AbstractTypeArguments& arguments, 2778 const AbstractTypeArguments& arguments,
2779 intptr_t token_index) { 2779 intptr_t token_pos) {
2780 const Type& result = Type::Handle(Type::New()); 2780 const Type& result = Type::Handle(Type::New());
2781 result.set_type_class(clazz); 2781 result.set_type_class(clazz);
2782 result.set_arguments(arguments); 2782 result.set_arguments(arguments);
2783 result.set_token_index(token_index); 2783 result.set_token_pos(token_pos);
2784 result.raw_ptr()->type_state_ = RawType::kAllocated; 2784 result.raw_ptr()->type_state_ = RawType::kAllocated;
2785 return result.raw(); 2785 return result.raw();
2786 } 2786 }
2787 2787
2788 2788
2789 void Type::set_token_index(intptr_t token_index) const { 2789 void Type::set_token_pos(intptr_t token_pos) const {
2790 ASSERT(token_index >= 0); 2790 ASSERT(token_pos >= 0);
2791 raw_ptr()->token_index_ = token_index; 2791 raw_ptr()->token_pos_ = token_pos;
2792 } 2792 }
2793 2793
2794 2794
2795 void Type::set_type_state(int8_t state) const { 2795 void Type::set_type_state(int8_t state) const {
2796 ASSERT((state == RawType::kAllocated) || 2796 ASSERT((state == RawType::kAllocated) ||
2797 (state == RawType::kBeingFinalized) || 2797 (state == RawType::kBeingFinalized) ||
2798 (state == RawType::kFinalizedInstantiated) || 2798 (state == RawType::kFinalizedInstantiated) ||
2799 (state == RawType::kFinalizedUninstantiated)); 2799 (state == RawType::kFinalizedUninstantiated));
2800 raw_ptr()->type_state_ = state; 2800 raw_ptr()->type_state_ = state;
2801 } 2801 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 RawObject* raw = Object::Allocate(type_parameter_class, 2917 RawObject* raw = Object::Allocate(type_parameter_class,
2918 TypeParameter::InstanceSize(), 2918 TypeParameter::InstanceSize(),
2919 Heap::kOld); 2919 Heap::kOld);
2920 return reinterpret_cast<RawTypeParameter*>(raw); 2920 return reinterpret_cast<RawTypeParameter*>(raw);
2921 } 2921 }
2922 2922
2923 2923
2924 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, 2924 RawTypeParameter* TypeParameter::New(const Class& parameterized_class,
2925 intptr_t index, 2925 intptr_t index,
2926 const String& name, 2926 const String& name,
2927 intptr_t token_index) { 2927 intptr_t token_pos) {
2928 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); 2928 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New());
2929 result.set_parameterized_class(parameterized_class); 2929 result.set_parameterized_class(parameterized_class);
2930 result.set_index(index); 2930 result.set_index(index);
2931 result.set_name(name); 2931 result.set_name(name);
2932 result.set_token_index(token_index); 2932 result.set_token_pos(token_pos);
2933 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; 2933 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated;
2934 return result.raw(); 2934 return result.raw();
2935 } 2935 }
2936 2936
2937 2937
2938 void TypeParameter::set_token_index(intptr_t token_index) const { 2938 void TypeParameter::set_token_pos(intptr_t token_pos) const {
2939 ASSERT(token_index >= 0); 2939 ASSERT(token_pos >= 0);
2940 raw_ptr()->token_index_ = token_index; 2940 raw_ptr()->token_pos_ = token_pos;
2941 } 2941 }
2942 2942
2943 2943
2944 void TypeParameter::set_type_state(int8_t state) const { 2944 void TypeParameter::set_type_state(int8_t state) const {
2945 ASSERT((state == RawTypeParameter::kAllocated) || 2945 ASSERT((state == RawTypeParameter::kAllocated) ||
2946 (state == RawTypeParameter::kBeingFinalized) || 2946 (state == RawTypeParameter::kBeingFinalized) ||
2947 (state == RawTypeParameter::kFinalizedUninstantiated)); 2947 (state == RawTypeParameter::kFinalizedUninstantiated));
2948 raw_ptr()->type_state_ = state; 2948 raw_ptr()->type_state_ = state;
2949 } 2949 }
2950 2950
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 if (!type_class.IsDynamicClass()) { 3124 if (!type_class.IsDynamicClass()) {
3125 return false; 3125 return false;
3126 } 3126 }
3127 } 3127 }
3128 return true; 3128 return true;
3129 } 3129 }
3130 3130
3131 3131
3132 static RawError* FormatError(const Error& prev_error, 3132 static RawError* FormatError(const Error& prev_error,
3133 const Script& script, 3133 const Script& script,
3134 intptr_t token_index, 3134 intptr_t token_pos,
3135 const char* format, ...) { 3135 const char* format, ...) {
3136 va_list args; 3136 va_list args;
3137 va_start(args, format); 3137 va_start(args, format);
3138 if (prev_error.IsNull()) { 3138 if (prev_error.IsNull()) {
3139 return Parser::FormatError(script, token_index, "Error", format, args); 3139 return Parser::FormatError(script, token_pos, "Error", format, args);
3140 } else { 3140 } else {
3141 return Parser::FormatErrorWithAppend(prev_error, script, token_index, 3141 return Parser::FormatErrorWithAppend(prev_error, script, token_pos,
3142 "Error", format, args); 3142 "Error", format, args);
3143 } 3143 }
3144 } 3144 }
3145 3145
3146 3146
3147 bool AbstractTypeArguments::IsWithinBoundsOf( 3147 bool AbstractTypeArguments::IsWithinBoundsOf(
3148 const Class& cls, 3148 const Class& cls,
3149 const AbstractTypeArguments& bounds_instantiator, 3149 const AbstractTypeArguments& bounds_instantiator,
3150 Error* malformed_error) const { 3150 Error* malformed_error) const {
3151 ASSERT(FLAG_enable_type_checks); 3151 ASSERT(FLAG_enable_type_checks);
(...skipping 27 matching lines...) Expand all
3179 const String& type_argument_name = String::Handle(type.Name()); 3179 const String& type_argument_name = String::Handle(type.Name());
3180 const String& class_name = String::Handle(cls.Name()); 3180 const String& class_name = String::Handle(cls.Name());
3181 const String& bound_name = String::Handle(bound.Name()); 3181 const String& bound_name = String::Handle(bound.Name());
3182 const Script& script = Script::Handle(cls.script()); 3182 const Script& script = Script::Handle(cls.script());
3183 // Since the bound was canonicalized, its token index was lost, 3183 // Since the bound was canonicalized, its token index was lost,
3184 // therefore, use the token index of the corresponding type parameter. 3184 // therefore, use the token index of the corresponding type parameter.
3185 const TypeArguments& type_parameters = 3185 const TypeArguments& type_parameters =
3186 TypeArguments::Handle(cls.type_parameters()); 3186 TypeArguments::Handle(cls.type_parameters());
3187 type = type_parameters.TypeAt(i); 3187 type = type_parameters.TypeAt(i);
3188 *malformed_error ^= FormatError(malformed_bound_error, 3188 *malformed_error ^= FormatError(malformed_bound_error,
3189 script, type.token_index(), 3189 script, type.token_pos(),
3190 "type argument '%s' does not " 3190 "type argument '%s' does not "
3191 "extend bound '%s' of '%s'\n", 3191 "extend bound '%s' of '%s'\n",
3192 type_argument_name.ToCString(), 3192 type_argument_name.ToCString(),
3193 bound_name.ToCString(), 3193 bound_name.ToCString(),
3194 class_name.ToCString()); 3194 class_name.ToCString());
3195 } 3195 }
3196 return false; 3196 return false;
3197 } 3197 }
3198 } 3198 }
3199 } 3199 }
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 void Function::set_is_static(bool is_static) const { 3604 void Function::set_is_static(bool is_static) const {
3605 raw_ptr()->is_static_ = is_static; 3605 raw_ptr()->is_static_ = is_static;
3606 } 3606 }
3607 3607
3608 3608
3609 void Function::set_is_const(bool is_const) const { 3609 void Function::set_is_const(bool is_const) const {
3610 raw_ptr()->is_const_ = is_const; 3610 raw_ptr()->is_const_ = is_const;
3611 } 3611 }
3612 3612
3613 3613
3614 void Function::set_token_index(intptr_t pos) const { 3614 void Function::set_token_pos(intptr_t pos) const {
3615 ASSERT(pos >= 0); 3615 ASSERT(pos >= 0);
3616 raw_ptr()->token_index_ = pos; 3616 raw_ptr()->token_pos_ = pos;
3617 } 3617 }
3618 3618
3619 3619
3620 void Function::set_num_fixed_parameters(intptr_t n) const { 3620 void Function::set_num_fixed_parameters(intptr_t n) const {
3621 ASSERT(n >= 0); 3621 ASSERT(n >= 0);
3622 raw_ptr()->num_fixed_parameters_ = n; 3622 raw_ptr()->num_fixed_parameters_ = n;
3623 } 3623 }
3624 3624
3625 3625
3626 void Function::set_num_optional_parameters(intptr_t n) const { 3626 void Function::set_num_optional_parameters(intptr_t n) const {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
3902 Function::InstanceSize(), 3902 Function::InstanceSize(),
3903 Heap::kOld); 3903 Heap::kOld);
3904 return reinterpret_cast<RawFunction*>(raw); 3904 return reinterpret_cast<RawFunction*>(raw);
3905 } 3905 }
3906 3906
3907 3907
3908 RawFunction* Function::New(const String& name, 3908 RawFunction* Function::New(const String& name,
3909 RawFunction::Kind kind, 3909 RawFunction::Kind kind,
3910 bool is_static, 3910 bool is_static,
3911 bool is_const, 3911 bool is_const,
3912 intptr_t token_index) { 3912 intptr_t token_pos) {
3913 const Function& result = Function::Handle(Function::New()); 3913 const Function& result = Function::Handle(Function::New());
3914 result.set_parameter_types(Array::Handle(Array::Empty())); 3914 result.set_parameter_types(Array::Handle(Array::Empty()));
3915 result.set_parameter_names(Array::Handle(Array::Empty())); 3915 result.set_parameter_names(Array::Handle(Array::Empty()));
3916 result.set_name(name); 3916 result.set_name(name);
3917 result.set_kind(kind); 3917 result.set_kind(kind);
3918 result.set_is_static(is_static); 3918 result.set_is_static(is_static);
3919 result.set_is_const(is_const); 3919 result.set_is_const(is_const);
3920 result.set_token_index(token_index); 3920 result.set_token_pos(token_pos);
3921 result.set_end_token_index(token_index); 3921 result.set_end_token_pos(token_pos);
3922 result.set_num_fixed_parameters(0); 3922 result.set_num_fixed_parameters(0);
3923 result.set_num_optional_parameters(0); 3923 result.set_num_optional_parameters(0);
3924 result.set_usage_counter(0); 3924 result.set_usage_counter(0);
3925 result.set_deoptimization_counter(0); 3925 result.set_deoptimization_counter(0);
3926 result.set_is_optimizable(true); 3926 result.set_is_optimizable(true);
3927 result.set_is_native(false); 3927 result.set_is_native(false);
3928 return result.raw(); 3928 return result.raw();
3929 } 3929 }
3930 3930
3931 3931
3932 RawFunction* Function::NewClosureFunction(const String& name, 3932 RawFunction* Function::NewClosureFunction(const String& name,
3933 const Function& parent, 3933 const Function& parent,
3934 intptr_t token_index) { 3934 intptr_t token_pos) {
3935 ASSERT(!parent.IsNull()); 3935 ASSERT(!parent.IsNull());
3936 const Class& parent_class = Class::Handle(parent.owner()); 3936 const Class& parent_class = Class::Handle(parent.owner());
3937 ASSERT(!parent_class.IsNull()); 3937 ASSERT(!parent_class.IsNull());
3938 const Function& result = Function::Handle( 3938 const Function& result = Function::Handle(
3939 Function::New(name, 3939 Function::New(name,
3940 RawFunction::kClosureFunction, 3940 RawFunction::kClosureFunction,
3941 /* is_static = */ parent.is_static(), 3941 /* is_static = */ parent.is_static(),
3942 /* is_const = */ false, 3942 /* is_const = */ false,
3943 token_index)); 3943 token_pos));
3944 result.set_parent_function(parent); 3944 result.set_parent_function(parent);
3945 result.set_owner(parent_class); 3945 result.set_owner(parent_class);
3946 return result.raw(); 3946 return result.raw();
3947 } 3947 }
3948 3948
3949 3949
3950 RawFunction* Function::ImplicitClosureFunction() const { 3950 RawFunction* Function::ImplicitClosureFunction() const {
3951 // Return the existing implicit closure function if any. 3951 // Return the existing implicit closure function if any.
3952 if (raw_ptr()->implicit_closure_function_ != Function::null()) { 3952 if (raw_ptr()->implicit_closure_function_ != Function::null()) {
3953 return raw_ptr()->implicit_closure_function_; 3953 return raw_ptr()->implicit_closure_function_;
3954 } 3954 }
3955 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); 3955 ASSERT(!IsSignatureFunction() && !IsClosureFunction());
3956 // Create closure function. 3956 // Create closure function.
3957 const String& closure_name = String::Handle(name()); 3957 const String& closure_name = String::Handle(name());
3958 const Function& closure_function = Function::Handle( 3958 const Function& closure_function = Function::Handle(
3959 NewClosureFunction(closure_name, *this, token_index())); 3959 NewClosureFunction(closure_name, *this, token_pos()));
3960 3960
3961 // Set closure function's context scope. 3961 // Set closure function's context scope.
3962 ContextScope& context_scope = ContextScope::Handle(); 3962 ContextScope& context_scope = ContextScope::Handle();
3963 if (is_static()) { 3963 if (is_static()) {
3964 context_scope ^= ContextScope::New(0); 3964 context_scope ^= ContextScope::New(0);
3965 } else { 3965 } else {
3966 context_scope ^= LocalScope::CreateImplicitClosureScope(*this); 3966 context_scope ^= LocalScope::CreateImplicitClosureScope(*this);
3967 } 3967 }
3968 closure_function.set_context_scope(context_scope); 3968 closure_function.set_context_scope(context_scope);
3969 3969
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
4261 RawObject* raw = Object::Allocate(field_class, 4261 RawObject* raw = Object::Allocate(field_class,
4262 Field::InstanceSize(), 4262 Field::InstanceSize(),
4263 Heap::kOld); 4263 Heap::kOld);
4264 return reinterpret_cast<RawField*>(raw); 4264 return reinterpret_cast<RawField*>(raw);
4265 } 4265 }
4266 4266
4267 4267
4268 RawField* Field::New(const String& name, 4268 RawField* Field::New(const String& name,
4269 bool is_static, 4269 bool is_static,
4270 bool is_final, 4270 bool is_final,
4271 intptr_t token_index) { 4271 intptr_t token_pos) {
4272 const Field& result = Field::Handle(Field::New()); 4272 const Field& result = Field::Handle(Field::New());
4273 result.set_name(name); 4273 result.set_name(name);
4274 result.set_is_static(is_static); 4274 result.set_is_static(is_static);
4275 if (is_static) { 4275 if (is_static) {
4276 result.set_value(Instance::Handle()); 4276 result.set_value(Instance::Handle());
4277 } else { 4277 } else {
4278 result.SetOffset(0); 4278 result.SetOffset(0);
4279 } 4279 }
4280 result.set_is_final(is_final); 4280 result.set_is_final(is_final);
4281 result.set_token_index(token_index); 4281 result.set_token_pos(token_pos);
4282 result.set_has_initializer(false); 4282 result.set_has_initializer(false);
4283 return result.raw(); 4283 return result.raw();
4284 } 4284 }
4285 4285
4286 4286
4287 const char* Field::ToCString() const { 4287 const char* Field::ToCString() const {
4288 const char* kF0 = is_static() ? " static" : ""; 4288 const char* kF0 = is_static() ? " static" : "";
4289 const char* kF1 = is_final() ? " final" : ""; 4289 const char* kF1 = is_final() ? " final" : "";
4290 const char* kFormat = "Field <%s.%s>:%s%s"; 4290 const char* kFormat = "Field <%s.%s>:%s%s";
4291 const char* field_name = String::Handle(name()).ToCString(); 4291 const char* field_name = String::Handle(name()).ToCString();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4509 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer); 4509 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer);
4510 const String& src = String::Handle(source()); 4510 const String& src = String::Handle(source());
4511 Scanner scanner(src, private_key); 4511 Scanner scanner(src, private_key);
4512 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream()))); 4512 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream())));
4513 if (FLAG_compiler_stats) { 4513 if (FLAG_compiler_stats) {
4514 CompilerStats::src_length += src.Length(); 4514 CompilerStats::src_length += src.Length();
4515 } 4515 }
4516 } 4516 }
4517 4517
4518 4518
4519 void Script::GetTokenLocation(intptr_t token_index, 4519 void Script::GetTokenLocation(intptr_t token_pos,
4520 intptr_t* line, 4520 intptr_t* line,
4521 intptr_t* column) const { 4521 intptr_t* column) const {
4522 const String& src = String::Handle(source()); 4522 const String& src = String::Handle(source());
4523 const String& dummy_key = String::Handle(String::New("")); 4523 const String& dummy_key = String::Handle(String::New(""));
4524 Scanner scanner(src, dummy_key); 4524 Scanner scanner(src, dummy_key);
4525 scanner.ScanTo(token_index); 4525 scanner.ScanTo(token_pos);
4526 *line = scanner.CurrentPosition().line; 4526 *line = scanner.CurrentPosition().line;
4527 *column = scanner.CurrentPosition().column; 4527 *column = scanner.CurrentPosition().column;
4528 } 4528 }
4529 4529
4530 4530
4531 intptr_t Script::TokenIndexAtLine(intptr_t line_number) const { 4531 intptr_t Script::TokenIndexAtLine(intptr_t line_number) const {
4532 const String& src = String::Handle(source()); 4532 const String& src = String::Handle(source());
4533 const String& dummy_key = String::Handle(String::New("")); 4533 const String& dummy_key = String::Handle(String::New(""));
4534 Scanner scanner(src, dummy_key); 4534 Scanner scanner(src, dummy_key);
4535 return scanner.TokenIndexAtLine(line_number); 4535 return scanner.TokenIndexAtLine(line_number);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 4893
4894 RawFunction* Library::LookupFunctionInSource(const String& script_url, 4894 RawFunction* Library::LookupFunctionInSource(const String& script_url,
4895 intptr_t line_number) const { 4895 intptr_t line_number) const {
4896 Script& script = Script::Handle(LookupScript(script_url)); 4896 Script& script = Script::Handle(LookupScript(script_url));
4897 if (script.IsNull()) { 4897 if (script.IsNull()) {
4898 // The given script url is not loaded into this library. 4898 // The given script url is not loaded into this library.
4899 return Function::null(); 4899 return Function::null();
4900 } 4900 }
4901 4901
4902 // Determine token position at given line number. 4902 // Determine token position at given line number.
4903 intptr_t token_index_at_line = script.TokenIndexAtLine(line_number); 4903 intptr_t token_pos_at_line = script.TokenIndexAtLine(line_number);
4904 if (token_index_at_line < 0) { 4904 if (token_pos_at_line < 0) {
4905 // Script does not contain the given line number. 4905 // Script does not contain the given line number.
4906 return Function::null(); 4906 return Function::null();
4907 } 4907 }
4908 4908
4909 return LookupFunctionInScript(script, token_index_at_line); 4909 return LookupFunctionInScript(script, token_pos_at_line);
4910 } 4910 }
4911 4911
4912 4912
4913 RawFunction* Library::LookupFunctionInScript(const Script& script, 4913 RawFunction* Library::LookupFunctionInScript(const Script& script,
4914 intptr_t token_index) const { 4914 intptr_t token_pos) const {
4915 Class& cls = Class::Handle(); 4915 Class& cls = Class::Handle();
4916 Function& func = Function::Handle(); 4916 Function& func = Function::Handle();
4917 ClassDictionaryIterator it(*this); 4917 ClassDictionaryIterator it(*this);
4918 while (it.HasNext()) { 4918 while (it.HasNext()) {
4919 cls = it.GetNextClass(); 4919 cls = it.GetNextClass();
4920 if (script.raw() == cls.script()) { 4920 if (script.raw() == cls.script()) {
4921 func = cls.LookupFunctionAtToken(token_index); 4921 func = cls.LookupFunctionAtToken(token_pos);
4922 if (!func.IsNull()) { 4922 if (!func.IsNull()) {
4923 return func.raw(); 4923 return func.raw();
4924 } 4924 }
4925 } 4925 }
4926 } 4926 }
4927 // Look in anonymous classes for toplevel functions. 4927 // Look in anonymous classes for toplevel functions.
4928 Array& anon_classes = Array::Handle(this->raw_ptr()->anonymous_classes_); 4928 Array& anon_classes = Array::Handle(this->raw_ptr()->anonymous_classes_);
4929 intptr_t num_anonymous = raw_ptr()->num_anonymous_; 4929 intptr_t num_anonymous = raw_ptr()->num_anonymous_;
4930 for (int i = 0; i < num_anonymous; i++) { 4930 for (int i = 0; i < num_anonymous; i++) {
4931 cls ^= anon_classes.At(i); 4931 cls ^= anon_classes.At(i);
4932 ASSERT(!cls.IsNull()); 4932 ASSERT(!cls.IsNull());
4933 if (script.raw() == cls.script()) { 4933 if (script.raw() == cls.script()) {
4934 func = cls.LookupFunctionAtToken(token_index); 4934 func = cls.LookupFunctionAtToken(token_pos);
4935 if (!func.IsNull()) { 4935 if (!func.IsNull()) {
4936 return func.raw(); 4936 return func.raw();
4937 } 4937 }
4938 } 4938 }
4939 } 4939 }
4940 return Function::null(); 4940 return Function::null();
4941 } 4941 }
4942 4942
4943 4943
4944 RawObject* Library::LookupLocalObject(const String& name) const { 4944 RawObject* Library::LookupLocalObject(const String& name) const {
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
6411 RawInstructions* instr; 6411 RawInstructions* instr;
6412 instr = isolate->heap()->FindObjectInCodeSpace(&visitor); 6412 instr = isolate->heap()->FindObjectInCodeSpace(&visitor);
6413 if (instr != Instructions::null()) { 6413 if (instr != Instructions::null()) {
6414 return instr->ptr()->code_; 6414 return instr->ptr()->code_;
6415 } 6415 }
6416 return Code::null(); 6416 return Code::null();
6417 } 6417 }
6418 6418
6419 6419
6420 intptr_t Code::GetTokenIndexOfPC(uword pc) const { 6420 intptr_t Code::GetTokenIndexOfPC(uword pc) const {
6421 intptr_t token_index = -1; 6421 intptr_t token_pos = -1;
6422 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); 6422 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors());
6423 for (intptr_t i = 0; i < descriptors.Length(); i++) { 6423 for (intptr_t i = 0; i < descriptors.Length(); i++) {
6424 if (descriptors.PC(i) == pc) { 6424 if (descriptors.PC(i) == pc) {
6425 token_index = descriptors.TokenIndex(i); 6425 token_pos = descriptors.TokenIndex(i);
6426 break; 6426 break;
6427 } 6427 }
6428 } 6428 }
6429 return token_index; 6429 return token_pos;
6430 } 6430 }
6431 6431
6432 6432
6433 uword Code::GetDeoptPcAtNodeId(intptr_t node_id) const { 6433 uword Code::GetDeoptPcAtNodeId(intptr_t node_id) const {
6434 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); 6434 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors());
6435 for (intptr_t i = 0; i < descriptors.Length(); i++) { 6435 for (intptr_t i = 0; i < descriptors.Length(); i++) {
6436 if ((descriptors.NodeId(i) == node_id) && 6436 if ((descriptors.NodeId(i) == node_id) &&
6437 (descriptors.DescriptorKind(i) == PcDescriptors::kDeopt)) { 6437 (descriptors.DescriptorKind(i) == PcDescriptors::kDeopt)) {
6438 return descriptors.PC(i); 6438 return descriptors.PC(i);
6439 } 6439 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
6562 RawObject* raw = Object::Allocate(context_scope_class, size, Heap::kOld); 6562 RawObject* raw = Object::Allocate(context_scope_class, size, Heap::kOld);
6563 NoGCScope no_gc; 6563 NoGCScope no_gc;
6564 result ^= raw; 6564 result ^= raw;
6565 result.set_num_variables(num_variables); 6565 result.set_num_variables(num_variables);
6566 } 6566 }
6567 return result.raw(); 6567 return result.raw();
6568 } 6568 }
6569 6569
6570 6570
6571 intptr_t ContextScope::TokenIndexAt(intptr_t scope_index) const { 6571 intptr_t ContextScope::TokenIndexAt(intptr_t scope_index) const {
6572 return Smi::Value(VariableDescAddr(scope_index)->token_index); 6572 return Smi::Value(VariableDescAddr(scope_index)->token_pos);
6573 } 6573 }
6574 6574
6575 6575
6576 void ContextScope::SetTokenIndexAt(intptr_t scope_index, 6576 void ContextScope::SetTokenIndexAt(intptr_t scope_index,
6577 intptr_t token_index) const { 6577 intptr_t token_pos) const {
6578 VariableDescAddr(scope_index)->token_index = Smi::New(token_index); 6578 VariableDescAddr(scope_index)->token_pos = Smi::New(token_pos);
6579 } 6579 }
6580 6580
6581 6581
6582 RawString* ContextScope::NameAt(intptr_t scope_index) const { 6582 RawString* ContextScope::NameAt(intptr_t scope_index) const {
6583 return VariableDescAddr(scope_index)->name; 6583 return VariableDescAddr(scope_index)->name;
6584 } 6584 }
6585 6585
6586 6586
6587 void ContextScope::SetNameAt(intptr_t scope_index, const String& name) const { 6587 void ContextScope::SetNameAt(intptr_t scope_index, const String& name) const {
6588 VariableDescAddr(scope_index)->name = name.raw(); 6588 VariableDescAddr(scope_index)->name = name.raw();
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after
10068 // for each frame. 10068 // for each frame.
10069 intptr_t total_len = 0; 10069 intptr_t total_len = 0;
10070 const char* kFormat = verbose ? 10070 const char* kFormat = verbose ?
10071 " %d. Function: '%s%s%s' url: '%s' line:%d col:%d code-entry: 0x%x\n" : 10071 " %d. Function: '%s%s%s' url: '%s' line:%d col:%d code-entry: 0x%x\n" :
10072 " %d. Function: '%s%s%s' url: '%s' line:%d col:%d\n"; 10072 " %d. Function: '%s%s%s' url: '%s' line:%d col:%d\n";
10073 GrowableArray<char*> frame_strings; 10073 GrowableArray<char*> frame_strings;
10074 for (intptr_t i = 0; i < Length(); i++) { 10074 for (intptr_t i = 0; i < Length(); i++) {
10075 function = FunctionAtFrame(i); 10075 function = FunctionAtFrame(i);
10076 code = CodeAtFrame(i); 10076 code = CodeAtFrame(i);
10077 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); 10077 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i));
10078 intptr_t token_index = code.GetTokenIndexOfPC(pc); 10078 intptr_t token_pos = code.GetTokenIndexOfPC(pc);
10079 function_class = function.owner(); 10079 function_class = function.owner();
10080 script = function_class.script(); 10080 script = function_class.script();
10081 function_name = function.name(); 10081 function_name = function.name();
10082 class_name = function_class.Name(); 10082 class_name = function_class.Name();
10083 url = script.url(); 10083 url = script.url();
10084 intptr_t line = -1; 10084 intptr_t line = -1;
10085 intptr_t column = -1; 10085 intptr_t column = -1;
10086 if (token_index >= 0) { 10086 if (token_pos >= 0) {
10087 script.GetTokenLocation(token_index, &line, &column); 10087 script.GetTokenLocation(token_pos, &line, &column);
10088 } 10088 }
10089 intptr_t len = OS::SNPrint(NULL, 0, kFormat, 10089 intptr_t len = OS::SNPrint(NULL, 0, kFormat,
10090 i, 10090 i,
10091 class_name.ToCString(), 10091 class_name.ToCString(),
10092 function_class.IsTopLevel() ? "" : ".", 10092 function_class.IsTopLevel() ? "" : ".",
10093 function_name.ToCString(), 10093 function_name.ToCString(),
10094 url.ToCString(), 10094 url.ToCString(),
10095 line, column, 10095 line, column,
10096 code.EntryPoint()); 10096 code.EntryPoint());
10097 total_len += len; 10097 total_len += len;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
10216 const String& str = String::Handle(pattern()); 10216 const String& str = String::Handle(pattern());
10217 const char* format = "JSRegExp: pattern=%s flags=%s"; 10217 const char* format = "JSRegExp: pattern=%s flags=%s";
10218 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10218 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10219 char* chars = reinterpret_cast<char*>( 10219 char* chars = reinterpret_cast<char*>(
10220 Isolate::Current()->current_zone()->Allocate(len + 1)); 10220 Isolate::Current()->current_zone()->Allocate(len + 1));
10221 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10221 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10222 return chars; 10222 return chars;
10223 } 10223 }
10224 10224
10225 } // namespace dart 10225 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | vm/opt_code_generator_ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698