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/parser.h" | 5 #include "vm/parser.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/flags.h" | 13 #include "vm/flags.h" |
14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
16 #include "vm/native_entry.h" | 16 #include "vm/native_entry.h" |
17 #include "vm/object.h" | 17 #include "vm/object.h" |
18 #include "vm/object_store.h" | 18 #include "vm/object_store.h" |
19 #include "vm/resolver.h" | 19 #include "vm/resolver.h" |
20 #include "vm/scopes.h" | 20 #include "vm/scopes.h" |
| 21 #include "vm/symbols.h" |
21 | 22 |
22 namespace dart { | 23 namespace dart { |
23 | 24 |
24 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
25 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
26 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
27 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); | 28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); |
28 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); | 29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); |
29 | 30 |
30 static void CheckedModeHandler(bool value) { | 31 static void CheckedModeHandler(bool value) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 stack_trace ^= Object::Clone(stack_trace, Heap::kOld); | 116 stack_trace ^= Object::Clone(stack_trace, Heap::kOld); |
116 } | 117 } |
117 return new ThrowNode(token_pos, | 118 return new ThrowNode(token_pos, |
118 new LiteralNode(token_pos, exception), | 119 new LiteralNode(token_pos, exception), |
119 new LiteralNode(token_pos, stack_trace)); | 120 new LiteralNode(token_pos, stack_trace)); |
120 } | 121 } |
121 | 122 |
122 | 123 |
123 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) { | 124 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) { |
124 return new LocalVariable(token_pos, | 125 return new LocalVariable(token_pos, |
125 String::ZoneHandle(String::NewSymbol(":expr_temp")), | 126 String::ZoneHandle(Symbols::New(":expr_temp")), |
126 Type::ZoneHandle(Type::DynamicType())); | 127 Type::ZoneHandle(Type::DynamicType())); |
127 } | 128 } |
128 | 129 |
129 | 130 |
130 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { | 131 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { |
131 ASSERT(node_sequence_ == NULL); | 132 ASSERT(node_sequence_ == NULL); |
132 ASSERT(node_sequence != NULL); | 133 ASSERT(node_sequence != NULL); |
133 node_sequence_ = node_sequence; | 134 node_sequence_ = node_sequence; |
134 const int num_fixed_params = function().num_fixed_parameters(); | 135 const int num_fixed_params = function().num_fixed_parameters(); |
135 const int num_opt_params = function().num_optional_parameters(); | 136 const int num_opt_params = function().num_optional_parameters(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 parameter_count, | 182 parameter_count, |
182 first_stack_local_index_, | 183 first_stack_local_index_, |
183 scope, | 184 scope, |
184 &context_owner); | 185 &context_owner); |
185 | 186 |
186 // If this function is not a closure function and if it contains captured | 187 // If this function is not a closure function and if it contains captured |
187 // variables, the context needs to be saved on entry and restored on exit. | 188 // variables, the context needs to be saved on entry and restored on exit. |
188 // Add and allocate a local variable to this purpose. | 189 // Add and allocate a local variable to this purpose. |
189 if ((context_owner != NULL) && !function().IsClosureFunction()) { | 190 if ((context_owner != NULL) && !function().IsClosureFunction()) { |
190 const String& context_var_name = String::ZoneHandle( | 191 const String& context_var_name = String::ZoneHandle( |
191 String::NewSymbol(LocalVariable::kSavedContextVarName)); | 192 Symbols::New(LocalVariable::kSavedContextVarName)); |
192 LocalVariable* context_var = | 193 LocalVariable* context_var = |
193 new LocalVariable(function().token_pos(), | 194 new LocalVariable(function().token_pos(), |
194 context_var_name, | 195 context_var_name, |
195 Type::ZoneHandle(Type::DynamicType())); | 196 Type::ZoneHandle(Type::DynamicType())); |
196 context_var->set_index(next_free_frame_index--); | 197 context_var->set_index(next_free_frame_index--); |
197 scope->AddVariable(context_var); | 198 scope->AddVariable(context_var); |
198 set_saved_context_var(context_var); | 199 set_saved_context_var(context_var); |
199 } | 200 } |
200 | 201 |
201 // Frame indices are relative to the frame pointer and are decreasing. | 202 // Frame indices are relative to the frame pointer and are decreasing. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 implicitly_final = false; | 431 implicitly_final = false; |
431 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 432 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
432 } | 433 } |
433 | 434 |
434 void AddFinalParameter(intptr_t name_pos, | 435 void AddFinalParameter(intptr_t name_pos, |
435 const char* name, | 436 const char* name, |
436 const AbstractType* type) { | 437 const AbstractType* type) { |
437 this->num_fixed_parameters++; | 438 this->num_fixed_parameters++; |
438 ParamDesc param; | 439 ParamDesc param; |
439 param.name_pos = name_pos; | 440 param.name_pos = name_pos; |
440 param.name = &String::ZoneHandle(String::NewSymbol(name)); | 441 param.name = &String::ZoneHandle(Symbols::New(name)); |
441 param.is_final = true; | 442 param.is_final = true; |
442 param.type = type; | 443 param.type = type; |
443 this->parameters->Add(param); | 444 this->parameters->Add(param); |
444 } | 445 } |
445 | 446 |
446 void AddReceiver(intptr_t name_pos) { | 447 void AddReceiver(intptr_t name_pos) { |
447 ASSERT(this->parameters->length() == 0); | 448 ASSERT(this->parameters->length() == 0); |
448 // The receiver does not need to be type checked. | 449 // The receiver does not need to be type checked. |
449 AddFinalParameter(name_pos, | 450 AddFinalParameter(name_pos, |
450 kThisName, | 451 kThisName, |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 // accesses to the field do not throw again, since initializers should only | 812 // accesses to the field do not throw again, since initializers should only |
812 // be executed once. | 813 // be executed once. |
813 SequenceNode* report_circular = new SequenceNode(TokenPos(), NULL); | 814 SequenceNode* report_circular = new SequenceNode(TokenPos(), NULL); |
814 report_circular->Add( | 815 report_circular->Add( |
815 new StoreStaticFieldNode( | 816 new StoreStaticFieldNode( |
816 TokenPos(), | 817 TokenPos(), |
817 field, | 818 field, |
818 new LiteralNode(TokenPos(), Instance::ZoneHandle()))); | 819 new LiteralNode(TokenPos(), Instance::ZoneHandle()))); |
819 // TODO(regis): Exception to throw is not specified by spec. | 820 // TODO(regis): Exception to throw is not specified by spec. |
820 const String& circular_error = String::ZoneHandle( | 821 const String& circular_error = String::ZoneHandle( |
821 String::NewSymbol("circular dependency in field initialization")); | 822 Symbols::New("circular dependency in field initialization")); |
822 report_circular->Add( | 823 report_circular->Add( |
823 new ThrowNode(TokenPos(), | 824 new ThrowNode(TokenPos(), |
824 new LiteralNode(TokenPos(), circular_error), | 825 new LiteralNode(TokenPos(), circular_error), |
825 NULL)); | 826 NULL)); |
826 AstNode* circular_check = | 827 AstNode* circular_check = |
827 new IfNode(TokenPos(), compare_circular, report_circular, NULL); | 828 new IfNode(TokenPos(), compare_circular, report_circular, NULL); |
828 current_block_->statements->Add(circular_check); | 829 current_block_->statements->Add(circular_check); |
829 | 830 |
830 // Generate code checking for uninitialized field. | 831 // Generate code checking for uninitialized field. |
831 AstNode* compare_uninitialized = new ComparisonNode( | 832 AstNode* compare_uninitialized = new ComparisonNode( |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 const Class& super_class = Class::Handle(current_class().SuperClass()); | 1236 const Class& super_class = Class::Handle(current_class().SuperClass()); |
1236 if (super_class.IsNull()) { | 1237 if (super_class.IsNull()) { |
1237 ErrorMsg(token_pos, "class '%s' does not have a superclass", | 1238 ErrorMsg(token_pos, "class '%s' does not have a superclass", |
1238 String::Handle(current_class().Name()).ToCString()); | 1239 String::Handle(current_class().Name()).ToCString()); |
1239 } | 1240 } |
1240 | 1241 |
1241 Function& super_func = | 1242 Function& super_func = |
1242 Function::Handle(ResolveDynamicFunction(super_class, name)); | 1243 Function::Handle(ResolveDynamicFunction(super_class, name)); |
1243 if (super_func.IsNull()) { | 1244 if (super_func.IsNull()) { |
1244 const String& no_such_method_name = | 1245 const String& no_such_method_name = |
1245 String::ZoneHandle(String::NewSymbol(kNoSuchMethodName)); | 1246 String::ZoneHandle(Symbols::New(kNoSuchMethodName)); |
1246 super_func = ResolveDynamicFunction(super_class, no_such_method_name); | 1247 super_func = ResolveDynamicFunction(super_class, no_such_method_name); |
1247 ASSERT(!super_func.IsNull()); | 1248 ASSERT(!super_func.IsNull()); |
1248 *is_no_such_method = true; | 1249 *is_no_such_method = true; |
1249 } else { | 1250 } else { |
1250 *is_no_such_method = false; | 1251 *is_no_such_method = false; |
1251 } | 1252 } |
1252 CheckFunctionIsCallable(token_pos, super_func); | 1253 CheckFunctionIsCallable(token_pos, super_func); |
1253 return super_func.raw(); | 1254 return super_func.raw(); |
1254 } | 1255 } |
1255 | 1256 |
1256 | 1257 |
1257 // Lookup class in the corelib implementation which contains various VM | 1258 // Lookup class in the corelib implementation which contains various VM |
1258 // helper methods and classes. | 1259 // helper methods and classes. |
1259 static RawClass* LookupImplClass(const String& class_name) { | 1260 static RawClass* LookupImplClass(const String& class_name) { |
1260 return Library::Handle(Library::CoreImplLibrary()).LookupClass(class_name); | 1261 return Library::Handle(Library::CoreImplLibrary()).LookupClass(class_name); |
1261 } | 1262 } |
1262 | 1263 |
1263 | 1264 |
1264 // Lookup class in the corelib which also contains various VM | 1265 // Lookup class in the corelib which also contains various VM |
1265 // helper methods and classes. Allow look up of private classes. | 1266 // helper methods and classes. Allow look up of private classes. |
1266 static RawClass* LookupCoreClass(const String& class_name) { | 1267 static RawClass* LookupCoreClass(const String& class_name) { |
1267 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 1268 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
1268 String& name = String::Handle(class_name.raw()); | 1269 String& name = String::Handle(class_name.raw()); |
1269 if (class_name.CharAt(0) == Scanner::kPrivateIdentifierStart) { | 1270 if (class_name.CharAt(0) == Scanner::kPrivateIdentifierStart) { |
1270 // Private identifiers are mangled on a per script basis. | 1271 // Private identifiers are mangled on a per script basis. |
1271 name = String::Concat(name, String::Handle(core_lib.private_key())); | 1272 name = String::Concat(name, String::Handle(core_lib.private_key())); |
1272 name = String::NewSymbol(name); | 1273 name = Symbols::New(name); |
1273 } | 1274 } |
1274 return core_lib.LookupClass(name); | 1275 return core_lib.LookupClass(name); |
1275 } | 1276 } |
1276 | 1277 |
1277 | 1278 |
1278 ArgumentListNode* Parser::BuildNoSuchMethodArguments( | 1279 ArgumentListNode* Parser::BuildNoSuchMethodArguments( |
1279 const String& function_name, | 1280 const String& function_name, |
1280 const ArgumentListNode& function_args) { | 1281 const ArgumentListNode& function_args) { |
1281 ASSERT(function_args.length() >= 1); // The receiver is the first argument. | 1282 ASSERT(function_args.length() >= 1); // The receiver is the first argument. |
1282 const intptr_t args_pos = function_args.token_pos(); | 1283 const intptr_t args_pos = function_args.token_pos(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 CreateTempConstVariable(operator_pos, index_expr->id(), "lix"); | 1349 CreateTempConstVariable(operator_pos, index_expr->id(), "lix"); |
1349 AstNode* save = | 1350 AstNode* save = |
1350 new StoreLocalNode(operator_pos, *temp, index_expr); | 1351 new StoreLocalNode(operator_pos, *temp, index_expr); |
1351 current_block_->statements->Add(save); | 1352 current_block_->statements->Add(save); |
1352 index_expr = new LoadLocalNode(operator_pos, *temp); | 1353 index_expr = new LoadLocalNode(operator_pos, *temp); |
1353 } | 1354 } |
1354 } | 1355 } |
1355 | 1356 |
1356 // Resolve the [] operator function in the superclass. | 1357 // Resolve the [] operator function in the superclass. |
1357 const String& index_operator_name = | 1358 const String& index_operator_name = |
1358 String::ZoneHandle(String::NewSymbol(Token::Str(Token::kINDEX))); | 1359 String::ZoneHandle(Symbols::New(Token::Str(Token::kINDEX))); |
1359 bool is_no_such_method = false; | 1360 bool is_no_such_method = false; |
1360 const Function& index_operator = Function::ZoneHandle( | 1361 const Function& index_operator = Function::ZoneHandle( |
1361 GetSuperFunction(operator_pos, | 1362 GetSuperFunction(operator_pos, |
1362 index_operator_name, | 1363 index_operator_name, |
1363 &is_no_such_method)); | 1364 &is_no_such_method)); |
1364 | 1365 |
1365 ArgumentListNode* index_op_arguments = new ArgumentListNode(operator_pos); | 1366 ArgumentListNode* index_op_arguments = new ArgumentListNode(operator_pos); |
1366 AstNode* receiver = LoadReceiver(operator_pos); | 1367 AstNode* receiver = LoadReceiver(operator_pos); |
1367 index_op_arguments->Add(receiver); | 1368 index_op_arguments->Add(receiver); |
1368 index_op_arguments->Add(index_expr); | 1369 index_op_arguments->Add(index_expr); |
1369 | 1370 |
1370 if (is_no_such_method) { | 1371 if (is_no_such_method) { |
1371 index_op_arguments = BuildNoSuchMethodArguments(index_operator_name, | 1372 index_op_arguments = BuildNoSuchMethodArguments(index_operator_name, |
1372 *index_op_arguments); | 1373 *index_op_arguments); |
1373 } | 1374 } |
1374 super_op = new StaticCallNode( | 1375 super_op = new StaticCallNode( |
1375 operator_pos, index_operator, index_op_arguments); | 1376 operator_pos, index_operator, index_op_arguments); |
1376 | 1377 |
1377 if (Token::IsAssignmentOperator(CurrentToken())) { | 1378 if (Token::IsAssignmentOperator(CurrentToken())) { |
1378 Token::Kind assignment_op = CurrentToken(); | 1379 Token::Kind assignment_op = CurrentToken(); |
1379 ConsumeToken(); | 1380 ConsumeToken(); |
1380 AstNode* value = ParseExpr(kAllowConst); | 1381 AstNode* value = ParseExpr(kAllowConst); |
1381 | 1382 |
1382 value = ExpandAssignableOp(operator_pos, assignment_op, super_op, value); | 1383 value = ExpandAssignableOp(operator_pos, assignment_op, super_op, value); |
1383 | 1384 |
1384 // Resolve the []= operator function in the superclass. | 1385 // Resolve the []= operator function in the superclass. |
1385 const String& assign_index_operator_name = String::ZoneHandle( | 1386 const String& assign_index_operator_name = String::ZoneHandle( |
1386 String::NewSymbol(Token::Str(Token::kASSIGN_INDEX))); | 1387 Symbols::New(Token::Str(Token::kASSIGN_INDEX))); |
1387 bool is_no_such_method = false; | 1388 bool is_no_such_method = false; |
1388 const Function& assign_index_operator = Function::ZoneHandle( | 1389 const Function& assign_index_operator = Function::ZoneHandle( |
1389 GetSuperFunction(operator_pos, | 1390 GetSuperFunction(operator_pos, |
1390 assign_index_operator_name, | 1391 assign_index_operator_name, |
1391 &is_no_such_method)); | 1392 &is_no_such_method)); |
1392 | 1393 |
1393 ArgumentListNode* operator_args = new ArgumentListNode(operator_pos); | 1394 ArgumentListNode* operator_args = new ArgumentListNode(operator_pos); |
1394 operator_args->Add(LoadReceiver(operator_pos)); | 1395 operator_args->Add(LoadReceiver(operator_pos)); |
1395 operator_args->Add(index_expr); | 1396 operator_args->Add(index_expr); |
1396 operator_args->Add(value); | 1397 operator_args->Add(value); |
1397 | 1398 |
1398 if (is_no_such_method) { | 1399 if (is_no_such_method) { |
1399 operator_args = BuildNoSuchMethodArguments(assign_index_operator_name, | 1400 operator_args = BuildNoSuchMethodArguments(assign_index_operator_name, |
1400 *operator_args); | 1401 *operator_args); |
1401 } | 1402 } |
1402 super_op = new StaticCallNode( | 1403 super_op = new StaticCallNode( |
1403 operator_pos, assign_index_operator, operator_args); | 1404 operator_pos, assign_index_operator, operator_args); |
1404 } | 1405 } |
1405 } else if (Token::CanBeOverloaded(CurrentToken())) { | 1406 } else if (Token::CanBeOverloaded(CurrentToken())) { |
1406 Token::Kind op = CurrentToken(); | 1407 Token::Kind op = CurrentToken(); |
1407 ConsumeToken(); | 1408 ConsumeToken(); |
1408 | 1409 |
1409 // Resolve the operator function in the superclass. | 1410 // Resolve the operator function in the superclass. |
1410 const String& operator_function_name = | 1411 const String& operator_function_name = |
1411 String::Handle(String::NewSymbol(Token::Str(op))); | 1412 String::Handle(Symbols::New(Token::Str(op))); |
1412 bool is_no_such_method = false; | 1413 bool is_no_such_method = false; |
1413 const Function& super_operator = Function::ZoneHandle( | 1414 const Function& super_operator = Function::ZoneHandle( |
1414 GetSuperFunction(operator_pos, | 1415 GetSuperFunction(operator_pos, |
1415 operator_function_name, | 1416 operator_function_name, |
1416 &is_no_such_method)); | 1417 &is_no_such_method)); |
1417 | 1418 |
1418 ASSERT(Token::Precedence(op) >= Token::Precedence(Token::kBIT_OR)); | 1419 ASSERT(Token::Precedence(op) >= Token::Precedence(Token::kBIT_OR)); |
1419 AstNode* other_operand = ParseBinaryExpr(Token::Precedence(op) + 1); | 1420 AstNode* other_operand = ParseBinaryExpr(Token::Precedence(op) + 1); |
1420 | 1421 |
1421 ArgumentListNode* op_arguments = new ArgumentListNode(operator_pos); | 1422 ArgumentListNode* op_arguments = new ArgumentListNode(operator_pos); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 LocalVariable* receiver) { | 1522 LocalVariable* receiver) { |
1522 const intptr_t supercall_pos = TokenPos(); | 1523 const intptr_t supercall_pos = TokenPos(); |
1523 const Class& super_class = Class::Handle(cls.SuperClass()); | 1524 const Class& super_class = Class::Handle(cls.SuperClass()); |
1524 // Omit the implicit super() if there is no super class (i.e. | 1525 // Omit the implicit super() if there is no super class (i.e. |
1525 // we're not compiling class Object), or if the super class is an | 1526 // we're not compiling class Object), or if the super class is an |
1526 // artificially generated "wrapper class" that has no constructor. | 1527 // artificially generated "wrapper class" that has no constructor. |
1527 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) { | 1528 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) { |
1528 return; | 1529 return; |
1529 } | 1530 } |
1530 String& ctor_name = String::Handle(super_class.Name()); | 1531 String& ctor_name = String::Handle(super_class.Name()); |
1531 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1532 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1532 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1533 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1533 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 1534 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
1534 // Implicit 'this' parameter is the first argument. | 1535 // Implicit 'this' parameter is the first argument. |
1535 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); | 1536 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); |
1536 arguments->Add(implicit_argument); | 1537 arguments->Add(implicit_argument); |
1537 // Implicit construction phase parameter is second argument. | 1538 // Implicit construction phase parameter is second argument. |
1538 AstNode* phase_parameter = | 1539 AstNode* phase_parameter = |
1539 new LiteralNode(supercall_pos, | 1540 new LiteralNode(supercall_pos, |
1540 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); | 1541 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); |
1541 arguments->Add(phase_parameter); | 1542 arguments->Add(phase_parameter); |
(...skipping 21 matching lines...) Expand all Loading... |
1563 | 1564 |
1564 AstNode* Parser::ParseSuperInitializer(const Class& cls, | 1565 AstNode* Parser::ParseSuperInitializer(const Class& cls, |
1565 LocalVariable* receiver) { | 1566 LocalVariable* receiver) { |
1566 TRACE_PARSER("ParseSuperInitializer"); | 1567 TRACE_PARSER("ParseSuperInitializer"); |
1567 ASSERT(CurrentToken() == Token::kSUPER); | 1568 ASSERT(CurrentToken() == Token::kSUPER); |
1568 const intptr_t supercall_pos = TokenPos(); | 1569 const intptr_t supercall_pos = TokenPos(); |
1569 ConsumeToken(); | 1570 ConsumeToken(); |
1570 const Class& super_class = Class::Handle(cls.SuperClass()); | 1571 const Class& super_class = Class::Handle(cls.SuperClass()); |
1571 ASSERT(!super_class.IsNull()); | 1572 ASSERT(!super_class.IsNull()); |
1572 String& ctor_name = String::Handle(super_class.Name()); | 1573 String& ctor_name = String::Handle(super_class.Name()); |
1573 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1574 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1574 if (CurrentToken() == Token::kPERIOD) { | 1575 if (CurrentToken() == Token::kPERIOD) { |
1575 ConsumeToken(); | 1576 ConsumeToken(); |
1576 ctor_suffix = String::Concat( | 1577 ctor_suffix = String::Concat( |
1577 ctor_suffix, *ExpectIdentifier("constructor name expected")); | 1578 ctor_suffix, *ExpectIdentifier("constructor name expected")); |
1578 } | 1579 } |
1579 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1580 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1580 if (CurrentToken() != Token::kLPAREN) { | 1581 if (CurrentToken() != Token::kLPAREN) { |
1581 ErrorMsg("parameter list expected"); | 1582 ErrorMsg("parameter list expected"); |
1582 } | 1583 } |
1583 | 1584 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 } | 1750 } |
1750 | 1751 |
1751 | 1752 |
1752 void Parser::ParseConstructorRedirection(const Class& cls, | 1753 void Parser::ParseConstructorRedirection(const Class& cls, |
1753 LocalVariable* receiver) { | 1754 LocalVariable* receiver) { |
1754 TRACE_PARSER("ParseConstructorRedirection"); | 1755 TRACE_PARSER("ParseConstructorRedirection"); |
1755 ASSERT(CurrentToken() == Token::kTHIS); | 1756 ASSERT(CurrentToken() == Token::kTHIS); |
1756 const intptr_t call_pos = TokenPos(); | 1757 const intptr_t call_pos = TokenPos(); |
1757 ConsumeToken(); | 1758 ConsumeToken(); |
1758 String& ctor_name = String::Handle(cls.Name()); | 1759 String& ctor_name = String::Handle(cls.Name()); |
1759 String& ctor_suffix = String::Handle(String::NewSymbol(".")); | 1760 String& ctor_suffix = String::Handle(Symbols::Dot()); |
1760 | 1761 |
1761 if (CurrentToken() == Token::kPERIOD) { | 1762 if (CurrentToken() == Token::kPERIOD) { |
1762 ConsumeToken(); | 1763 ConsumeToken(); |
1763 ctor_suffix = String::Concat( | 1764 ctor_suffix = String::Concat( |
1764 ctor_suffix, *ExpectIdentifier("constructor name expected")); | 1765 ctor_suffix, *ExpectIdentifier("constructor name expected")); |
1765 } | 1766 } |
1766 ctor_name = String::Concat(ctor_name, ctor_suffix); | 1767 ctor_name = String::Concat(ctor_name, ctor_suffix); |
1767 if (CurrentToken() != Token::kLPAREN) { | 1768 if (CurrentToken() != Token::kLPAREN) { |
1768 ErrorMsg("parameter list expected"); | 1769 ErrorMsg("parameter list expected"); |
1769 } | 1770 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 OpenFunctionBlock(func); | 1809 OpenFunctionBlock(func); |
1809 | 1810 |
1810 // Parse expressions of instance fields that have an explicit | 1811 // Parse expressions of instance fields that have an explicit |
1811 // initializers. | 1812 // initializers. |
1812 GrowableArray<FieldInitExpression> initializers; | 1813 GrowableArray<FieldInitExpression> initializers; |
1813 Class& cls = Class::Handle(func.owner()); | 1814 Class& cls = Class::Handle(func.owner()); |
1814 ParseInitializedInstanceFields(cls, &initializers); | 1815 ParseInitializedInstanceFields(cls, &initializers); |
1815 | 1816 |
1816 LocalVariable* receiver = new LocalVariable( | 1817 LocalVariable* receiver = new LocalVariable( |
1817 ctor_pos, | 1818 ctor_pos, |
1818 String::ZoneHandle(String::NewSymbol(kThisName)), | 1819 String::ZoneHandle(Symbols::New(kThisName)), |
1819 Type::ZoneHandle(Type::DynamicType())); | 1820 Type::ZoneHandle(Type::DynamicType())); |
1820 current_block_->scope->AddVariable(receiver); | 1821 current_block_->scope->AddVariable(receiver); |
1821 | 1822 |
1822 LocalVariable* phase_parameter = new LocalVariable( | 1823 LocalVariable* phase_parameter = new LocalVariable( |
1823 ctor_pos, | 1824 ctor_pos, |
1824 String::ZoneHandle(String::NewSymbol(kPhaseParameterName)), | 1825 String::ZoneHandle(Symbols::New(kPhaseParameterName)), |
1825 Type::ZoneHandle(Type::DynamicType())); | 1826 Type::ZoneHandle(Type::DynamicType())); |
1826 current_block_->scope->AddVariable(phase_parameter); | 1827 current_block_->scope->AddVariable(phase_parameter); |
1827 | 1828 |
1828 // Now that the "this" parameter is in scope, we can generate the code | 1829 // Now that the "this" parameter is in scope, we can generate the code |
1829 // to strore the initializer expressions in the respective instance fields. | 1830 // to strore the initializer expressions in the respective instance fields. |
1830 for (int i = 0; i < initializers.length(); i++) { | 1831 for (int i = 0; i < initializers.length(); i++) { |
1831 const Field* field = initializers[i].inst_field; | 1832 const Field* field = initializers[i].inst_field; |
1832 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); | 1833 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); |
1833 AstNode* field_init = | 1834 AstNode* field_init = |
1834 new StoreInstanceFieldNode(field->token_pos(), | 1835 new StoreInstanceFieldNode(field->token_pos(), |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 if (method->params.has_field_initializer) { | 2369 if (method->params.has_field_initializer) { |
2369 // Constructors that redirect to another constructor must not | 2370 // Constructors that redirect to another constructor must not |
2370 // initialize any fields using field initializer parameters. | 2371 // initialize any fields using field initializer parameters. |
2371 ErrorMsg(formal_param_pos, "Redirecting constructor " | 2372 ErrorMsg(formal_param_pos, "Redirecting constructor " |
2372 "may not use field initializer parameters"); | 2373 "may not use field initializer parameters"); |
2373 } | 2374 } |
2374 ConsumeToken(); // Colon. | 2375 ConsumeToken(); // Colon. |
2375 ExpectToken(Token::kTHIS); | 2376 ExpectToken(Token::kTHIS); |
2376 String& redir_name = String::ZoneHandle( | 2377 String& redir_name = String::ZoneHandle( |
2377 String::Concat(members->class_name(), | 2378 String::Concat(members->class_name(), |
2378 String::Handle(String::NewSymbol(".")))); | 2379 String::Handle(Symbols::Dot()))); |
2379 if (CurrentToken() == Token::kPERIOD) { | 2380 if (CurrentToken() == Token::kPERIOD) { |
2380 ConsumeToken(); | 2381 ConsumeToken(); |
2381 redir_name = String::Concat(redir_name, | 2382 redir_name = String::Concat(redir_name, |
2382 *ExpectIdentifier("constructor name expected")); | 2383 *ExpectIdentifier("constructor name expected")); |
2383 } | 2384 } |
2384 method->redirect_name = &redir_name; | 2385 method->redirect_name = &redir_name; |
2385 if (CurrentToken() != Token::kLPAREN) { | 2386 if (CurrentToken() != Token::kLPAREN) { |
2386 ErrorMsg("'(' expected"); | 2387 ErrorMsg("'(' expected"); |
2387 } | 2388 } |
2388 SkipToMatchingParenthesis(); | 2389 SkipToMatchingParenthesis(); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2704 member.type = &Type::ZoneHandle(Type::New(result_type_class, | 2705 member.type = &Type::ZoneHandle(Type::New(result_type_class, |
2705 TypeArguments::Handle(), | 2706 TypeArguments::Handle(), |
2706 factory_name.ident_pos)); | 2707 factory_name.ident_pos)); |
2707 } else { | 2708 } else { |
2708 member.name_pos = TokenPos(); | 2709 member.name_pos = TokenPos(); |
2709 member.name = CurrentLiteral(); | 2710 member.name = CurrentLiteral(); |
2710 ConsumeToken(); | 2711 ConsumeToken(); |
2711 } | 2712 } |
2712 // We must be dealing with a constructor or named constructor. | 2713 // We must be dealing with a constructor or named constructor. |
2713 member.kind = RawFunction::kConstructor; | 2714 member.kind = RawFunction::kConstructor; |
2714 String& ctor_suffix = String::ZoneHandle(String::NewSymbol(".")); | 2715 String& ctor_suffix = String::ZoneHandle(Symbols::Dot()); |
2715 if (CurrentToken() == Token::kPERIOD) { | 2716 if (CurrentToken() == Token::kPERIOD) { |
2716 // Named constructor. | 2717 // Named constructor. |
2717 ConsumeToken(); | 2718 ConsumeToken(); |
2718 const String* name = ExpectIdentifier("identifier expected"); | 2719 const String* name = ExpectIdentifier("identifier expected"); |
2719 ctor_suffix = String::Concat(ctor_suffix, *name); | 2720 ctor_suffix = String::Concat(ctor_suffix, *name); |
2720 } | 2721 } |
2721 *member.name = String::Concat(*member.name, ctor_suffix); | 2722 *member.name = String::Concat(*member.name, ctor_suffix); |
2722 // Ensure that names are symbols. | 2723 // Ensure that names are symbols. |
2723 *member.name = String::NewSymbol(*member.name); | 2724 *member.name = Symbols::New(*member.name); |
2724 if (member.type == NULL) { | 2725 if (member.type == NULL) { |
2725 ASSERT(!member.has_factory); | 2726 ASSERT(!member.has_factory); |
2726 // The body of the constructor cannot modify the type arguments of the | 2727 // The body of the constructor cannot modify the type arguments of the |
2727 // constructed instance, which is passed in as a hidden parameter. | 2728 // constructed instance, which is passed in as a hidden parameter. |
2728 // Therefore, there is no need to set the result type to be checked. | 2729 // Therefore, there is no need to set the result type to be checked. |
2729 member.type = &Type::ZoneHandle(Type::DynamicType()); | 2730 member.type = &Type::ZoneHandle(Type::DynamicType()); |
2730 } else { | 2731 } else { |
2731 // The type can only be already set in the factory case. | 2732 // The type can only be already set in the factory case. |
2732 if (!member.has_factory) { | 2733 if (!member.has_factory) { |
2733 ErrorMsg(member.name_pos, "constructor must not specify return type"); | 2734 ErrorMsg(member.name_pos, "constructor must not specify return type"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2775 if (!Token::CanBeOverloaded(CurrentToken())) { | 2776 if (!Token::CanBeOverloaded(CurrentToken())) { |
2776 ErrorMsg("invalid operator overloading"); | 2777 ErrorMsg("invalid operator overloading"); |
2777 } | 2778 } |
2778 if (member.has_static) { | 2779 if (member.has_static) { |
2779 ErrorMsg("operator overloading functions cannot be static"); | 2780 ErrorMsg("operator overloading functions cannot be static"); |
2780 } | 2781 } |
2781 operator_token = CurrentToken(); | 2782 operator_token = CurrentToken(); |
2782 member.kind = RawFunction::kFunction; | 2783 member.kind = RawFunction::kFunction; |
2783 member.name_pos = this->TokenPos(); | 2784 member.name_pos = this->TokenPos(); |
2784 member.name = | 2785 member.name = |
2785 &String::ZoneHandle(String::NewSymbol(Token::Str(operator_token))); | 2786 &String::ZoneHandle(Symbols::New(Token::Str(operator_token))); |
2786 ConsumeToken(); | 2787 ConsumeToken(); |
2787 } else if (IsIdentifier()) { | 2788 } else if (IsIdentifier()) { |
2788 member.name = CurrentLiteral(); | 2789 member.name = CurrentLiteral(); |
2789 member.name_pos = TokenPos(); | 2790 member.name_pos = TokenPos(); |
2790 ConsumeToken(); | 2791 ConsumeToken(); |
2791 } else { | 2792 } else { |
2792 ErrorMsg("identifier expected"); | 2793 ErrorMsg("identifier expected"); |
2793 } | 2794 } |
2794 | 2795 |
2795 ASSERT(member.name != NULL); | 2796 ASSERT(member.name != NULL); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2920 | 2921 |
2921 // 1. Add an implicit constructor if no explicit constructor is present. | 2922 // 1. Add an implicit constructor if no explicit constructor is present. |
2922 // 2. Check for cycles in constructor redirection. | 2923 // 2. Check for cycles in constructor redirection. |
2923 void Parser::CheckConstructors(ClassDesc* class_desc) { | 2924 void Parser::CheckConstructors(ClassDesc* class_desc) { |
2924 // Add an implicit constructor if no explicit constructor is present. | 2925 // Add an implicit constructor if no explicit constructor is present. |
2925 if (!class_desc->has_constructor()) { | 2926 if (!class_desc->has_constructor()) { |
2926 // The implicit constructor is unnamed, has no explicit parameter, | 2927 // The implicit constructor is unnamed, has no explicit parameter, |
2927 // and contains a supercall in the initializer list. | 2928 // and contains a supercall in the initializer list. |
2928 String& ctor_name = String::ZoneHandle( | 2929 String& ctor_name = String::ZoneHandle( |
2929 String::Concat(class_desc->class_name(), | 2930 String::Concat(class_desc->class_name(), |
2930 String::Handle(String::NewSymbol(".")))); | 2931 String::Handle(Symbols::Dot()))); |
2931 ctor_name = String::NewSymbol(ctor_name); | 2932 ctor_name = Symbols::New(ctor_name); |
2932 // The token position for the implicit constructor is the 'class' | 2933 // The token position for the implicit constructor is the 'class' |
2933 // keyword of the constructor's class. | 2934 // keyword of the constructor's class. |
2934 Function& ctor = Function::Handle( | 2935 Function& ctor = Function::Handle( |
2935 Function::New(ctor_name, | 2936 Function::New(ctor_name, |
2936 RawFunction::kConstructor, | 2937 RawFunction::kConstructor, |
2937 /* is_static = */ false, | 2938 /* is_static = */ false, |
2938 /* is_const = */ false, | 2939 /* is_const = */ false, |
2939 class_desc->token_pos())); | 2940 class_desc->token_pos())); |
2940 ParamList params; | 2941 ParamList params; |
2941 // Add implicit 'this' parameter. | 2942 // Add implicit 'this' parameter. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3003 | 3004 |
3004 | 3005 |
3005 void Parser::ParseFunctionTypeAlias( | 3006 void Parser::ParseFunctionTypeAlias( |
3006 const GrowableObjectArray& pending_classes) { | 3007 const GrowableObjectArray& pending_classes) { |
3007 TRACE_PARSER("ParseFunctionTypeAlias"); | 3008 TRACE_PARSER("ParseFunctionTypeAlias"); |
3008 ExpectToken(Token::kTYPEDEF); | 3009 ExpectToken(Token::kTYPEDEF); |
3009 | 3010 |
3010 // Allocate an interface to hold the type parameters and their bounds. | 3011 // Allocate an interface to hold the type parameters and their bounds. |
3011 // Make it the owner of the function type descriptor. | 3012 // Make it the owner of the function type descriptor. |
3012 const Class& alias_owner = Class::Handle( | 3013 const Class& alias_owner = Class::Handle( |
3013 Class::New(String::Handle(String::NewSymbol(":alias_owner")), | 3014 Class::New(String::Handle(Symbols::New(":alias_owner")), |
3014 Script::Handle(), | 3015 Script::Handle(), |
3015 TokenPos())); | 3016 TokenPos())); |
3016 alias_owner.set_is_interface(); | 3017 alias_owner.set_is_interface(); |
3017 alias_owner.set_library(library_); | 3018 alias_owner.set_library(library_); |
3018 set_current_class(alias_owner); | 3019 set_current_class(alias_owner); |
3019 | 3020 |
3020 // Parse the result type of the function type. | 3021 // Parse the result type of the function type. |
3021 AbstractType& result_type = Type::Handle(Type::DynamicType()); | 3022 AbstractType& result_type = Type::Handle(Type::DynamicType()); |
3022 if (CurrentToken() == Token::kVOID) { | 3023 if (CurrentToken() == Token::kVOID) { |
3023 ConsumeToken(); | 3024 ConsumeToken(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3156 ParseQualIdent(&factory_name); | 3157 ParseQualIdent(&factory_name); |
3157 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); | 3158 LibraryPrefix& lib_prefix = LibraryPrefix::Handle(); |
3158 if (factory_name.lib_prefix != NULL) { | 3159 if (factory_name.lib_prefix != NULL) { |
3159 lib_prefix = factory_name.lib_prefix->raw(); | 3160 lib_prefix = factory_name.lib_prefix->raw(); |
3160 } | 3161 } |
3161 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( | 3162 const UnresolvedClass& unresolved_factory_class = UnresolvedClass::Handle( |
3162 UnresolvedClass::New(lib_prefix, | 3163 UnresolvedClass::New(lib_prefix, |
3163 *factory_name.ident, | 3164 *factory_name.ident, |
3164 factory_name.ident_pos)); | 3165 factory_name.ident_pos)); |
3165 const Class& factory_class = Class::Handle( | 3166 const Class& factory_class = Class::Handle( |
3166 Class::New(String::Handle(String::NewSymbol(":factory_signature")), | 3167 Class::New(String::Handle(Symbols::New(":factory_signature")), |
3167 script_, | 3168 script_, |
3168 factory_name.ident_pos)); | 3169 factory_name.ident_pos)); |
3169 factory_class.set_library(library_); | 3170 factory_class.set_library(library_); |
3170 factory_class.set_is_finalized(); | 3171 factory_class.set_is_finalized(); |
3171 ParseTypeParameters(factory_class); | 3172 ParseTypeParameters(factory_class); |
3172 unresolved_factory_class.set_factory_signature_class(factory_class); | 3173 unresolved_factory_class.set_factory_signature_class(factory_class); |
3173 interface.set_factory_class(unresolved_factory_class); | 3174 interface.set_factory_class(unresolved_factory_class); |
3174 // If a type parameter list is included in the default factory clause (it | 3175 // If a type parameter list is included in the default factory clause (it |
3175 // can be omitted), verify that it matches the list of type parameters of | 3176 // can be omitted), verify that it matches the list of type parameters of |
3176 // the interface in number and names, but not necessarily in bounds. | 3177 // the interface in number and names, but not necessarily in bounds. |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3812 // They need to be registered with class finalization after parsing | 3813 // They need to be registered with class finalization after parsing |
3813 // has been completed. | 3814 // has been completed. |
3814 Isolate* isolate = Isolate::Current(); | 3815 Isolate* isolate = Isolate::Current(); |
3815 ObjectStore* object_store = isolate->object_store(); | 3816 ObjectStore* object_store = isolate->object_store(); |
3816 const GrowableObjectArray& pending_classes = | 3817 const GrowableObjectArray& pending_classes = |
3817 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); | 3818 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); |
3818 SetPosition(0); | 3819 SetPosition(0); |
3819 is_top_level_ = true; | 3820 is_top_level_ = true; |
3820 TopLevel top_level; | 3821 TopLevel top_level; |
3821 Class& toplevel_class = Class::Handle( | 3822 Class& toplevel_class = Class::Handle( |
3822 Class::New(String::ZoneHandle(String::NewSymbol("::")), | 3823 Class::New(String::ZoneHandle(Symbols::New("::")), |
3823 script_, | 3824 script_, |
3824 TokenPos())); | 3825 TokenPos())); |
3825 toplevel_class.set_library(library_); | 3826 toplevel_class.set_library(library_); |
3826 | 3827 |
3827 if (is_library_source()) { | 3828 if (is_library_source()) { |
3828 ParseLibraryDefinition(); | 3829 ParseLibraryDefinition(); |
3829 } | 3830 } |
3830 | 3831 |
3831 while (true) { | 3832 while (true) { |
3832 set_current_class(Class::Handle()); // No current class. | 3833 set_current_class(Class::Handle()); // No current class. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4030 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), | 4031 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), |
4031 native_name, | 4032 native_name, |
4032 native_function, | 4033 native_function, |
4033 num_parameters, | 4034 num_parameters, |
4034 has_opt_params, | 4035 has_opt_params, |
4035 is_instance_closure))); | 4036 is_instance_closure))); |
4036 } | 4037 } |
4037 | 4038 |
4038 | 4039 |
4039 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { | 4040 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { |
4040 const String& this_name = String::Handle(String::NewSymbol(kThisName)); | 4041 const String& this_name = String::Handle(Symbols::New(kThisName)); |
4041 return from_scope->LookupVariable(this_name, test_only); | 4042 return from_scope->LookupVariable(this_name, test_only); |
4042 } | 4043 } |
4043 | 4044 |
4044 | 4045 |
4045 LocalVariable* Parser::LookupPhaseParameter() { | 4046 LocalVariable* Parser::LookupPhaseParameter() { |
4046 const String& phase_name = | 4047 const String& phase_name = |
4047 String::Handle(String::NewSymbol(kPhaseParameterName)); | 4048 String::Handle(Symbols::New(kPhaseParameterName)); |
4048 const bool kTestOnly = false; | 4049 const bool kTestOnly = false; |
4049 return current_block_->scope->LookupVariable(phase_name, kTestOnly); | 4050 return current_block_->scope->LookupVariable(phase_name, kTestOnly); |
4050 } | 4051 } |
4051 | 4052 |
4052 | 4053 |
4053 void Parser::CaptureReceiver() { | 4054 void Parser::CaptureReceiver() { |
4054 ASSERT(current_block_->scope->function_level() > 0); | 4055 ASSERT(current_block_->scope->function_level() > 0); |
4055 const bool kTestOnly = false; | 4056 const bool kTestOnly = false; |
4056 // Side effect of lookup captures the receiver variable. | 4057 // Side effect of lookup captures the receiver variable. |
4057 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 4058 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4206 const intptr_t ident_pos = TokenPos(); | 4207 const intptr_t ident_pos = TokenPos(); |
4207 if (IsIdentifier()) { | 4208 if (IsIdentifier()) { |
4208 variable_name = CurrentLiteral(); | 4209 variable_name = CurrentLiteral(); |
4209 function_name = variable_name; | 4210 function_name = variable_name; |
4210 ConsumeToken(); | 4211 ConsumeToken(); |
4211 } else { | 4212 } else { |
4212 if (!is_literal) { | 4213 if (!is_literal) { |
4213 ErrorMsg("function name expected"); | 4214 ErrorMsg("function name expected"); |
4214 } | 4215 } |
4215 const String& anonymous_function_name = | 4216 const String& anonymous_function_name = |
4216 String::ZoneHandle(String::NewSymbol("function")); | 4217 String::ZoneHandle(Symbols::New("function")); |
4217 function_name = &anonymous_function_name; | 4218 function_name = &anonymous_function_name; |
4218 } | 4219 } |
4219 ASSERT(ident_pos >= 0); | 4220 ASSERT(ident_pos >= 0); |
4220 | 4221 |
4221 if (CurrentToken() != Token::kLPAREN) { | 4222 if (CurrentToken() != Token::kLPAREN) { |
4222 ErrorMsg("'(' expected"); | 4223 ErrorMsg("'(' expected"); |
4223 } | 4224 } |
4224 intptr_t function_pos = TokenPos(); | 4225 intptr_t function_pos = TokenPos(); |
4225 | 4226 |
4226 // Check whether we have parsed this closure function before, in a previous | 4227 // Check whether we have parsed this closure function before, in a previous |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4778 if (paren_found) { | 4779 if (paren_found) { |
4779 ExpectToken(Token::kRPAREN); | 4780 ExpectToken(Token::kRPAREN); |
4780 } | 4781 } |
4781 ExpectToken(Token::kLBRACE); | 4782 ExpectToken(Token::kLBRACE); |
4782 OpenBlock(); | 4783 OpenBlock(); |
4783 current_block_->scope->AddLabel(label); | 4784 current_block_->scope->AddLabel(label); |
4784 | 4785 |
4785 // Store switch expression in temporary local variable. | 4786 // Store switch expression in temporary local variable. |
4786 LocalVariable* temp_variable = | 4787 LocalVariable* temp_variable = |
4787 new LocalVariable(expr_pos, | 4788 new LocalVariable(expr_pos, |
4788 String::ZoneHandle(String::NewSymbol(":switch_expr")), | 4789 String::ZoneHandle(Symbols::New(":switch_expr")), |
4789 Type::ZoneHandle(Type::DynamicType())); | 4790 Type::ZoneHandle(Type::DynamicType())); |
4790 current_block_->scope->AddVariable(temp_variable); | 4791 current_block_->scope->AddVariable(temp_variable); |
4791 AstNode* save_switch_expr = | 4792 AstNode* save_switch_expr = |
4792 new StoreLocalNode(expr_pos, *temp_variable, switch_expr); | 4793 new StoreLocalNode(expr_pos, *temp_variable, switch_expr); |
4793 current_block_->statements->Add(save_switch_expr); | 4794 current_block_->statements->Add(save_switch_expr); |
4794 | 4795 |
4795 // Parse case clauses | 4796 // Parse case clauses |
4796 bool default_seen = false; | 4797 bool default_seen = false; |
4797 while (true) { | 4798 while (true) { |
4798 // Check for statement label | 4799 // Check for statement label |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4906 } | 4907 } |
4907 ExpectToken(Token::kIN); | 4908 ExpectToken(Token::kIN); |
4908 const intptr_t collection_pos = TokenPos(); | 4909 const intptr_t collection_pos = TokenPos(); |
4909 AstNode* collection_expr = ParseExpr(kAllowConst); | 4910 AstNode* collection_expr = ParseExpr(kAllowConst); |
4910 ExpectToken(Token::kRPAREN); | 4911 ExpectToken(Token::kRPAREN); |
4911 | 4912 |
4912 OpenBlock(); // Implicit block around while loop. | 4913 OpenBlock(); // Implicit block around while loop. |
4913 | 4914 |
4914 // Generate implicit iterator variable and add to scope. | 4915 // Generate implicit iterator variable and add to scope. |
4915 const String& iterator_name = | 4916 const String& iterator_name = |
4916 String::ZoneHandle(String::NewSymbol(":for-in-iter")); | 4917 String::ZoneHandle(Symbols::New(":for-in-iter")); |
4917 // We could set the type of the implicit iterator variable to Iterator<T> | 4918 // We could set the type of the implicit iterator variable to Iterator<T> |
4918 // where T is the type of the for loop variable. However, the type error | 4919 // where T is the type of the for loop variable. However, the type error |
4919 // would refer to the compiler generated iterator and could confuse the user. | 4920 // would refer to the compiler generated iterator and could confuse the user. |
4920 // It is better to leave the iterator untyped and postpone the type error | 4921 // It is better to leave the iterator untyped and postpone the type error |
4921 // until the loop variable is assigned to. | 4922 // until the loop variable is assigned to. |
4922 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); | 4923 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); |
4923 LocalVariable* iterator_var = | 4924 LocalVariable* iterator_var = |
4924 new LocalVariable(collection_pos, iterator_name, iterator_type); | 4925 new LocalVariable(collection_pos, iterator_name, iterator_type); |
4925 current_block_->scope->AddVariable(iterator_var); | 4926 current_block_->scope->AddVariable(iterator_var); |
4926 | 4927 |
4927 // Generate initialization of iterator variable. | 4928 // Generate initialization of iterator variable. |
4928 const String& iterator_method_name = | 4929 const String& iterator_method_name = |
4929 String::ZoneHandle(String::NewSymbol(kGetIteratorName)); | 4930 String::ZoneHandle(Symbols::New(kGetIteratorName)); |
4930 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); | 4931 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); |
4931 AstNode* get_iterator = new InstanceCallNode( | 4932 AstNode* get_iterator = new InstanceCallNode( |
4932 collection_pos, collection_expr, iterator_method_name, no_args); | 4933 collection_pos, collection_expr, iterator_method_name, no_args); |
4933 AstNode* iterator_init = | 4934 AstNode* iterator_init = |
4934 new StoreLocalNode(collection_pos, *iterator_var, get_iterator); | 4935 new StoreLocalNode(collection_pos, *iterator_var, get_iterator); |
4935 current_block_->statements->Add(iterator_init); | 4936 current_block_->statements->Add(iterator_init); |
4936 | 4937 |
4937 // Generate while loop condition. | 4938 // Generate while loop condition. |
4938 AstNode* iterator_has_next = new InstanceCallNode( | 4939 AstNode* iterator_has_next = new InstanceCallNode( |
4939 collection_pos, | 4940 collection_pos, |
4940 new LoadLocalNode(collection_pos, *iterator_var), | 4941 new LoadLocalNode(collection_pos, *iterator_var), |
4941 String::ZoneHandle(String::NewSymbol("hasNext")), | 4942 String::ZoneHandle(Symbols::New("hasNext")), |
4942 no_args); | 4943 no_args); |
4943 | 4944 |
4944 // Parse the for loop body. Ideally, we would use ParseNestedStatement() | 4945 // Parse the for loop body. Ideally, we would use ParseNestedStatement() |
4945 // here, but that does not work well because we have to insert an implicit | 4946 // here, but that does not work well because we have to insert an implicit |
4946 // variable assignment and potentially a variable declaration in the | 4947 // variable assignment and potentially a variable declaration in the |
4947 // loop body. | 4948 // loop body. |
4948 OpenLoopBlock(); | 4949 OpenLoopBlock(); |
4949 current_block_->scope->AddLabel(label); | 4950 current_block_->scope->AddLabel(label); |
4950 | 4951 |
4951 AstNode* iterator_next = new InstanceCallNode( | 4952 AstNode* iterator_next = new InstanceCallNode( |
4952 collection_pos, | 4953 collection_pos, |
4953 new LoadLocalNode(collection_pos, *iterator_var), | 4954 new LoadLocalNode(collection_pos, *iterator_var), |
4954 String::ZoneHandle(String::NewSymbol("next")), | 4955 String::ZoneHandle(Symbols::New("next")), |
4955 no_args); | 4956 no_args); |
4956 | 4957 |
4957 // Generate assignment of next iterator value to loop variable. | 4958 // Generate assignment of next iterator value to loop variable. |
4958 AstNode* loop_var_assignment = NULL; | 4959 AstNode* loop_var_assignment = NULL; |
4959 if (loop_var != NULL) { | 4960 if (loop_var != NULL) { |
4960 // The for loop declares a new variable. Add it to the loop body scope. | 4961 // The for loop declares a new variable. Add it to the loop body scope. |
4961 current_block_->scope->AddVariable(loop_var); | 4962 current_block_->scope->AddVariable(loop_var); |
4962 loop_var_assignment = | 4963 loop_var_assignment = |
4963 new StoreLocalNode(loop_var_pos, *loop_var, iterator_next); | 4964 new StoreLocalNode(loop_var_pos, *loop_var, iterator_next); |
4964 } else { | 4965 } else { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5059 NodeAsSequenceNode(incr_pos, increment, incr_scope), | 5060 NodeAsSequenceNode(incr_pos, increment, incr_scope), |
5060 body); | 5061 body); |
5061 } | 5062 } |
5062 | 5063 |
5063 | 5064 |
5064 // Calling VM-internal helpers, uses implementation core library. | 5065 // Calling VM-internal helpers, uses implementation core library. |
5065 AstNode* Parser::MakeStaticCall(const char* class_name, | 5066 AstNode* Parser::MakeStaticCall(const char* class_name, |
5066 const char* function_name, | 5067 const char* function_name, |
5067 ArgumentListNode* arguments) { | 5068 ArgumentListNode* arguments) { |
5068 const String& cls_name = | 5069 const String& cls_name = |
5069 String::Handle(String::NewSymbol(class_name)); | 5070 String::Handle(Symbols::New(class_name)); |
5070 const Class& cls = Class::Handle(LookupImplClass(cls_name)); | 5071 const Class& cls = Class::Handle(LookupImplClass(cls_name)); |
5071 ASSERT(!cls.IsNull()); | 5072 ASSERT(!cls.IsNull()); |
5072 const String& func_name = | 5073 const String& func_name = |
5073 String::ZoneHandle(String::NewSymbol(function_name)); | 5074 String::ZoneHandle(Symbols::New(function_name)); |
5074 const Function& func = Function::ZoneHandle( | 5075 const Function& func = Function::ZoneHandle( |
5075 Resolver::ResolveStatic(cls, | 5076 Resolver::ResolveStatic(cls, |
5076 func_name, | 5077 func_name, |
5077 arguments->length(), | 5078 arguments->length(), |
5078 arguments->names(), | 5079 arguments->names(), |
5079 Resolver::kIsQualified)); | 5080 Resolver::kIsQualified)); |
5080 ASSERT(!func.IsNull()); | 5081 ASSERT(!func.IsNull()); |
5081 CheckFunctionIsCallable(arguments->token_pos(), func); | 5082 CheckFunctionIsCallable(arguments->token_pos(), func); |
5082 return new StaticCallNode(arguments->token_pos(), func, arguments); | 5083 return new StaticCallNode(arguments->token_pos(), func, arguments); |
5083 } | 5084 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5259 // slot before processing the catch block handler. | 5260 // slot before processing the catch block handler. |
5260 // ':exception_var' - Used to save the current exception object that was | 5261 // ':exception_var' - Used to save the current exception object that was |
5261 // thrown. | 5262 // thrown. |
5262 // ':stacktrace_var' - Used to save the current stack trace object into which | 5263 // ':stacktrace_var' - Used to save the current stack trace object into which |
5263 // the stack trace was copied into when an exception was | 5264 // the stack trace was copied into when an exception was |
5264 // thrown. | 5265 // thrown. |
5265 // :exception_var and :stacktrace_var get set with the exception object | 5266 // :exception_var and :stacktrace_var get set with the exception object |
5266 // and the stacktrace object when an exception is thrown. | 5267 // and the stacktrace object when an exception is thrown. |
5267 // These three implicit variables can never be captured variables. | 5268 // These three implicit variables can never be captured variables. |
5268 const String& context_var_name = | 5269 const String& context_var_name = |
5269 String::ZoneHandle(String::NewSymbol(":saved_context_var")); | 5270 String::ZoneHandle(Symbols::New(":saved_context_var")); |
5270 LocalVariable* context_var = | 5271 LocalVariable* context_var = |
5271 current_block_->scope->LocalLookupVariable(context_var_name); | 5272 current_block_->scope->LocalLookupVariable(context_var_name); |
5272 if (context_var == NULL) { | 5273 if (context_var == NULL) { |
5273 context_var = new LocalVariable(TokenPos(), | 5274 context_var = new LocalVariable(TokenPos(), |
5274 context_var_name, | 5275 context_var_name, |
5275 Type::ZoneHandle(Type::DynamicType())); | 5276 Type::ZoneHandle(Type::DynamicType())); |
5276 current_block_->scope->AddVariable(context_var); | 5277 current_block_->scope->AddVariable(context_var); |
5277 } | 5278 } |
5278 const String& catch_excp_var_name = | 5279 const String& catch_excp_var_name = |
5279 String::ZoneHandle(String::NewSymbol(":exception_var")); | 5280 String::ZoneHandle(Symbols::New(":exception_var")); |
5280 LocalVariable* catch_excp_var = | 5281 LocalVariable* catch_excp_var = |
5281 current_block_->scope->LocalLookupVariable(catch_excp_var_name); | 5282 current_block_->scope->LocalLookupVariable(catch_excp_var_name); |
5282 if (catch_excp_var == NULL) { | 5283 if (catch_excp_var == NULL) { |
5283 catch_excp_var = new LocalVariable(TokenPos(), | 5284 catch_excp_var = new LocalVariable(TokenPos(), |
5284 catch_excp_var_name, | 5285 catch_excp_var_name, |
5285 Type::ZoneHandle(Type::DynamicType())); | 5286 Type::ZoneHandle(Type::DynamicType())); |
5286 current_block_->scope->AddVariable(catch_excp_var); | 5287 current_block_->scope->AddVariable(catch_excp_var); |
5287 } | 5288 } |
5288 const String& catch_trace_var_name = | 5289 const String& catch_trace_var_name = |
5289 String::ZoneHandle(String::NewSymbol(":stacktrace_var")); | 5290 String::ZoneHandle(Symbols::New(":stacktrace_var")); |
5290 LocalVariable* catch_trace_var = | 5291 LocalVariable* catch_trace_var = |
5291 current_block_->scope->LocalLookupVariable(catch_trace_var_name); | 5292 current_block_->scope->LocalLookupVariable(catch_trace_var_name); |
5292 if (catch_trace_var == NULL) { | 5293 if (catch_trace_var == NULL) { |
5293 catch_trace_var = new LocalVariable(TokenPos(), | 5294 catch_trace_var = new LocalVariable(TokenPos(), |
5294 catch_trace_var_name, | 5295 catch_trace_var_name, |
5295 Type::ZoneHandle(Type::DynamicType())); | 5296 Type::ZoneHandle(Type::DynamicType())); |
5296 current_block_->scope->AddVariable(catch_trace_var); | 5297 current_block_->scope->AddVariable(catch_trace_var); |
5297 } | 5298 } |
5298 | 5299 |
5299 const intptr_t try_pos = TokenPos(); | 5300 const intptr_t try_pos = TokenPos(); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5648 // Check if it is ok to do a rethrow. | 5649 // Check if it is ok to do a rethrow. |
5649 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); | 5650 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); |
5650 if (label == NULL || | 5651 if (label == NULL || |
5651 label->FunctionLevel() != current_block_->scope->function_level()) { | 5652 label->FunctionLevel() != current_block_->scope->function_level()) { |
5652 ErrorMsg("rethrow of an exception is not valid here"); | 5653 ErrorMsg("rethrow of an exception is not valid here"); |
5653 } | 5654 } |
5654 ASSERT(label->owner() != NULL); | 5655 ASSERT(label->owner() != NULL); |
5655 LocalScope* scope = label->owner()->parent(); | 5656 LocalScope* scope = label->owner()->parent(); |
5656 ASSERT(scope != NULL); | 5657 ASSERT(scope != NULL); |
5657 LocalVariable* excp_var = scope->LocalLookupVariable( | 5658 LocalVariable* excp_var = scope->LocalLookupVariable( |
5658 String::ZoneHandle(String::NewSymbol(":exception_var"))); | 5659 String::ZoneHandle(Symbols::New(":exception_var"))); |
5659 ASSERT(excp_var != NULL); | 5660 ASSERT(excp_var != NULL); |
5660 LocalVariable* trace_var = scope->LocalLookupVariable( | 5661 LocalVariable* trace_var = scope->LocalLookupVariable( |
5661 String::ZoneHandle(String::NewSymbol(":stacktrace_var"))); | 5662 String::ZoneHandle(Symbols::New(":stacktrace_var"))); |
5662 ASSERT(trace_var != NULL); | 5663 ASSERT(trace_var != NULL); |
5663 statement = new ThrowNode(statement_pos, | 5664 statement = new ThrowNode(statement_pos, |
5664 new LoadLocalNode(statement_pos, *excp_var), | 5665 new LoadLocalNode(statement_pos, *excp_var), |
5665 new LoadLocalNode(statement_pos, *trace_var)); | 5666 new LoadLocalNode(statement_pos, *trace_var)); |
5666 } | 5667 } |
5667 } else { | 5668 } else { |
5668 statement = ParseExpr(kAllowConst); | 5669 statement = ParseExpr(kAllowConst); |
5669 ExpectSemicolon(); | 5670 ExpectSemicolon(); |
5670 } | 5671 } |
5671 return statement; | 5672 return statement; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5940 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { | 5941 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { |
5941 ASSERT(type.IsMalformed()); | 5942 ASSERT(type.IsMalformed()); |
5942 ArgumentListNode* arguments = new ArgumentListNode(type_pos); | 5943 ArgumentListNode* arguments = new ArgumentListNode(type_pos); |
5943 // Location argument. | 5944 // Location argument. |
5944 arguments->Add(new LiteralNode( | 5945 arguments->Add(new LiteralNode( |
5945 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); | 5946 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); |
5946 // Src value argument. | 5947 // Src value argument. |
5947 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); | 5948 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); |
5948 // Dst type name argument. | 5949 // Dst type name argument. |
5949 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5950 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
5950 String::NewSymbol("malformed")))); | 5951 Symbols::New("malformed")))); |
5951 // Dst name argument. | 5952 // Dst name argument. |
5952 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5953 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
5953 String::NewSymbol("")))); | 5954 Symbols::New("")))); |
5954 // Malformed type error. | 5955 // Malformed type error. |
5955 const Error& error = Error::Handle(type.malformed_error()); | 5956 const Error& error = Error::Handle(type.malformed_error()); |
5956 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5957 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
5957 String::NewSymbol(error.ToErrorCString())))); | 5958 Symbols::New(error.ToErrorCString())))); |
5958 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); | 5959 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); |
5959 } | 5960 } |
5960 | 5961 |
5961 | 5962 |
5962 AstNode* Parser::ParseBinaryExpr(int min_preced) { | 5963 AstNode* Parser::ParseBinaryExpr(int min_preced) { |
5963 TRACE_PARSER("ParseBinaryExpr"); | 5964 TRACE_PARSER("ParseBinaryExpr"); |
5964 ASSERT(min_preced >= 4); | 5965 ASSERT(min_preced >= 4); |
5965 AstNode* left_operand = ParseUnaryExpr(); | 5966 AstNode* left_operand = ParseUnaryExpr(); |
5966 if (IsLiteral("as")) { // Not a reserved word. | 5967 if (IsLiteral("as")) { // Not a reserved word. |
5967 token_kind_ = Token::kAS; | 5968 token_kind_ = Token::kAS; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6067 } | 6068 } |
6068 | 6069 |
6069 | 6070 |
6070 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, | 6071 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, |
6071 intptr_t token_id, | 6072 intptr_t token_id, |
6072 const char* s) { | 6073 const char* s) { |
6073 char name[64]; | 6074 char name[64]; |
6074 OS::SNPrint(name, 64, ":%s%d", s, token_id); | 6075 OS::SNPrint(name, 64, ":%s%d", s, token_id); |
6075 LocalVariable* temp = | 6076 LocalVariable* temp = |
6076 new LocalVariable(token_pos, | 6077 new LocalVariable(token_pos, |
6077 String::ZoneHandle(String::NewSymbol(name)), | 6078 String::ZoneHandle(Symbols::New(name)), |
6078 Type::ZoneHandle(Type::DynamicType())); | 6079 Type::ZoneHandle(Type::DynamicType())); |
6079 temp->set_is_final(); | 6080 temp->set_is_final(); |
6080 current_block_->scope->AddVariable(temp); | 6081 current_block_->scope->AddVariable(temp); |
6081 return temp; | 6082 return temp; |
6082 } | 6083 } |
6083 | 6084 |
6084 | 6085 |
6085 // TODO(srdjan): Implement other optimizations. | 6086 // TODO(srdjan): Implement other optimizations. |
6086 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, | 6087 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, |
6087 Token::Kind binary_op, | 6088 Token::Kind binary_op, |
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7506 } | 7507 } |
7507 } | 7508 } |
7508 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); | 7509 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); |
7509 | 7510 |
7510 // Parse the list elements. Note: there may be an optional extra | 7511 // Parse the list elements. Note: there may be an optional extra |
7511 // comma after the last element. | 7512 // comma after the last element. |
7512 ArrayNode* list = new ArrayNode(TokenPos(), type_arguments); | 7513 ArrayNode* list = new ArrayNode(TokenPos(), type_arguments); |
7513 if (!is_empty_literal) { | 7514 if (!is_empty_literal) { |
7514 const bool saved_mode = SetAllowFunctionLiterals(true); | 7515 const bool saved_mode = SetAllowFunctionLiterals(true); |
7515 const String& dst_name = String::ZoneHandle( | 7516 const String& dst_name = String::ZoneHandle( |
7516 String::NewSymbol("list literal element")); | 7517 Symbols::New("list literal element")); |
7517 while (CurrentToken() != Token::kRBRACK) { | 7518 while (CurrentToken() != Token::kRBRACK) { |
7518 const intptr_t element_pos = TokenPos(); | 7519 const intptr_t element_pos = TokenPos(); |
7519 AstNode* element = ParseExpr(is_const); | 7520 AstNode* element = ParseExpr(is_const); |
7520 if (FLAG_enable_type_checks && | 7521 if (FLAG_enable_type_checks && |
7521 !is_const && | 7522 !is_const && |
7522 !element_type.IsDynamicType()) { | 7523 !element_type.IsDynamicType()) { |
7523 element = new AssignableNode(element_pos, | 7524 element = new AssignableNode(element_pos, |
7524 element, | 7525 element, |
7525 element_type, | 7526 element_type, |
7526 dst_name); | 7527 dst_name); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7564 } | 7565 } |
7565 } | 7566 } |
7566 const_list.SetAt(i, elem->AsLiteralNode()->literal()); | 7567 const_list.SetAt(i, elem->AsLiteralNode()->literal()); |
7567 } | 7568 } |
7568 const_list ^= const_list.Canonicalize(); | 7569 const_list ^= const_list.Canonicalize(); |
7569 const_list.MakeImmutable(); | 7570 const_list.MakeImmutable(); |
7570 return new LiteralNode(literal_pos, const_list); | 7571 return new LiteralNode(literal_pos, const_list); |
7571 } else { | 7572 } else { |
7572 // Factory call at runtime. | 7573 // Factory call at runtime. |
7573 String& list_literal_factory_class_name = String::Handle( | 7574 String& list_literal_factory_class_name = String::Handle( |
7574 String::NewSymbol(kListLiteralFactoryClassName)); | 7575 Symbols::New(kListLiteralFactoryClassName)); |
7575 const Class& list_literal_factory_class = | 7576 const Class& list_literal_factory_class = |
7576 Class::Handle(LookupCoreClass(list_literal_factory_class_name)); | 7577 Class::Handle(LookupCoreClass(list_literal_factory_class_name)); |
7577 ASSERT(!list_literal_factory_class.IsNull()); | 7578 ASSERT(!list_literal_factory_class.IsNull()); |
7578 const String& list_literal_factory_name = | 7579 const String& list_literal_factory_name = |
7579 String::Handle(String::NewSymbol(kListLiteralFactoryName)); | 7580 String::Handle(Symbols::New(kListLiteralFactoryName)); |
7580 const Function& list_literal_factory = Function::ZoneHandle( | 7581 const Function& list_literal_factory = Function::ZoneHandle( |
7581 list_literal_factory_class.LookupFactory(list_literal_factory_name)); | 7582 list_literal_factory_class.LookupFactory(list_literal_factory_name)); |
7582 ASSERT(!list_literal_factory.IsNull()); | 7583 ASSERT(!list_literal_factory.IsNull()); |
7583 if (!type_arguments.IsNull() && | 7584 if (!type_arguments.IsNull() && |
7584 !type_arguments.IsInstantiated() && | 7585 !type_arguments.IsInstantiated() && |
7585 (current_block_->scope->function_level() > 0)) { | 7586 (current_block_->scope->function_level() > 0)) { |
7586 // Make sure that the instantiator is captured. | 7587 // Make sure that the instantiator is captured. |
7587 CaptureReceiver(); | 7588 CaptureReceiver(); |
7588 } | 7589 } |
7589 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7590 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7690 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 7691 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
7691 map_type_arguments ^= map_type_arguments.Canonicalize(); | 7692 map_type_arguments ^= map_type_arguments.Canonicalize(); |
7692 | 7693 |
7693 // Parse the map entries. Note: there may be an optional extra | 7694 // Parse the map entries. Note: there may be an optional extra |
7694 // comma after the last entry. | 7695 // comma after the last entry. |
7695 // The kv_pair array is temporary and of element type Dynamic. It is passed | 7696 // The kv_pair array is temporary and of element type Dynamic. It is passed |
7696 // to the factory to initialize a properly typed map. | 7697 // to the factory to initialize a properly typed map. |
7697 ArrayNode* kv_pairs = | 7698 ArrayNode* kv_pairs = |
7698 new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); | 7699 new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); |
7699 const String& dst_name = String::ZoneHandle( | 7700 const String& dst_name = String::ZoneHandle( |
7700 String::NewSymbol("list literal element")); | 7701 Symbols::New("list literal element")); |
7701 while (CurrentToken() != Token::kRBRACE) { | 7702 while (CurrentToken() != Token::kRBRACE) { |
7702 AstNode* key = NULL; | 7703 AstNode* key = NULL; |
7703 if (CurrentToken() == Token::kSTRING) { | 7704 if (CurrentToken() == Token::kSTRING) { |
7704 key = ParseStringLiteral(); | 7705 key = ParseStringLiteral(); |
7705 } | 7706 } |
7706 if (key == NULL) { | 7707 if (key == NULL) { |
7707 ErrorMsg("map entry key must be string literal"); | 7708 ErrorMsg("map entry key must be string literal"); |
7708 } else if (is_const && !key->IsLiteralNode()) { | 7709 } else if (is_const && !key->IsLiteralNode()) { |
7709 ErrorMsg("map entry key must be compile time constant string"); | 7710 ErrorMsg("map entry key must be compile time constant string"); |
7710 } | 7711 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7762 String::Handle(value_type.Name()).ToCString()); | 7763 String::Handle(value_type.Name()).ToCString()); |
7763 } | 7764 } |
7764 } | 7765 } |
7765 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); | 7766 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); |
7766 } | 7767 } |
7767 key_value_array ^= key_value_array.Canonicalize(); | 7768 key_value_array ^= key_value_array.Canonicalize(); |
7768 key_value_array.MakeImmutable(); | 7769 key_value_array.MakeImmutable(); |
7769 | 7770 |
7770 // Construct the map object. | 7771 // Construct the map object. |
7771 const String& immutable_map_class_name = | 7772 const String& immutable_map_class_name = |
7772 String::Handle(String::NewSymbol(kImmutableMapName)); | 7773 String::Handle(Symbols::New(kImmutableMapName)); |
7773 const Class& immutable_map_class = | 7774 const Class& immutable_map_class = |
7774 Class::Handle(LookupImplClass(immutable_map_class_name)); | 7775 Class::Handle(LookupImplClass(immutable_map_class_name)); |
7775 ASSERT(!immutable_map_class.IsNull()); | 7776 ASSERT(!immutable_map_class.IsNull()); |
7776 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); | 7777 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); |
7777 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 7778 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); |
7778 const String& constr_name = | 7779 const String& constr_name = |
7779 String::Handle(String::NewSymbol(kImmutableMapConstructorName)); | 7780 String::Handle(Symbols::New(kImmutableMapConstructorName)); |
7780 const Function& map_constr = Function::ZoneHandle( | 7781 const Function& map_constr = Function::ZoneHandle( |
7781 immutable_map_class.LookupConstructor(constr_name)); | 7782 immutable_map_class.LookupConstructor(constr_name)); |
7782 ASSERT(!map_constr.IsNull()); | 7783 ASSERT(!map_constr.IsNull()); |
7783 const Object& constructor_result = Object::Handle( | 7784 const Object& constructor_result = Object::Handle( |
7784 EvaluateConstConstructorCall(immutable_map_class, | 7785 EvaluateConstConstructorCall(immutable_map_class, |
7785 map_type_arguments, | 7786 map_type_arguments, |
7786 map_constr, | 7787 map_constr, |
7787 constr_args)); | 7788 constr_args)); |
7788 if (constructor_result.IsUnhandledException()) { | 7789 if (constructor_result.IsUnhandledException()) { |
7789 return GenerateRethrow(literal_pos, constructor_result); | 7790 return GenerateRethrow(literal_pos, constructor_result); |
7790 } else { | 7791 } else { |
7791 const Instance& const_instance = Instance::Cast(constructor_result); | 7792 const Instance& const_instance = Instance::Cast(constructor_result); |
7792 return new LiteralNode(literal_pos, | 7793 return new LiteralNode(literal_pos, |
7793 Instance::ZoneHandle(const_instance.raw())); | 7794 Instance::ZoneHandle(const_instance.raw())); |
7794 } | 7795 } |
7795 } else { | 7796 } else { |
7796 // Factory call at runtime. | 7797 // Factory call at runtime. |
7797 String& map_literal_factory_class_name = String::Handle( | 7798 String& map_literal_factory_class_name = String::Handle( |
7798 String::NewSymbol(kMapLiteralFactoryClassName)); | 7799 Symbols::New(kMapLiteralFactoryClassName)); |
7799 const Class& map_literal_factory_class = | 7800 const Class& map_literal_factory_class = |
7800 Class::Handle(LookupCoreClass(map_literal_factory_class_name)); | 7801 Class::Handle(LookupCoreClass(map_literal_factory_class_name)); |
7801 ASSERT(!map_literal_factory_class.IsNull()); | 7802 ASSERT(!map_literal_factory_class.IsNull()); |
7802 const String& map_literal_factory_name = | 7803 const String& map_literal_factory_name = |
7803 String::Handle(String::NewSymbol(kMapLiteralFactoryName)); | 7804 String::Handle(Symbols::New(kMapLiteralFactoryName)); |
7804 const Function& map_literal_factory = Function::ZoneHandle( | 7805 const Function& map_literal_factory = Function::ZoneHandle( |
7805 map_literal_factory_class.LookupFactory(map_literal_factory_name)); | 7806 map_literal_factory_class.LookupFactory(map_literal_factory_name)); |
7806 ASSERT(!map_literal_factory.IsNull()); | 7807 ASSERT(!map_literal_factory.IsNull()); |
7807 if (!map_type_arguments.IsNull() && | 7808 if (!map_type_arguments.IsNull() && |
7808 !map_type_arguments.IsInstantiated() && | 7809 !map_type_arguments.IsInstantiated() && |
7809 (current_block_->scope->function_level() > 0)) { | 7810 (current_block_->scope->function_level() > 0)) { |
7810 // Make sure that the instantiator is captured. | 7811 // Make sure that the instantiator is captured. |
7811 CaptureReceiver(); | 7812 CaptureReceiver(); |
7812 } | 7813 } |
7813 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7814 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7849 return primary; | 7850 return primary; |
7850 } | 7851 } |
7851 | 7852 |
7852 | 7853 |
7853 static const String& BuildConstructorName(const String& type_class_name, | 7854 static const String& BuildConstructorName(const String& type_class_name, |
7854 const String* named_constructor) { | 7855 const String* named_constructor) { |
7855 // By convention, the static function implementing a named constructor 'C' | 7856 // By convention, the static function implementing a named constructor 'C' |
7856 // for class 'A' is labeled 'A.C', and the static function implementing the | 7857 // for class 'A' is labeled 'A.C', and the static function implementing the |
7857 // unnamed constructor for class 'A' is labeled 'A.'. | 7858 // unnamed constructor for class 'A' is labeled 'A.'. |
7858 // This convention prevents users from explicitly calling constructors. | 7859 // This convention prevents users from explicitly calling constructors. |
7859 const String& period = String::Handle(String::NewSymbol(".")); | 7860 const String& period = String::Handle(Symbols::Dot()); |
7860 String& constructor_name = | 7861 String& constructor_name = |
7861 String::Handle(String::Concat(type_class_name, period)); | 7862 String::Handle(String::Concat(type_class_name, period)); |
7862 if (named_constructor != NULL) { | 7863 if (named_constructor != NULL) { |
7863 constructor_name = String::Concat(constructor_name, *named_constructor); | 7864 constructor_name = String::Concat(constructor_name, *named_constructor); |
7864 } | 7865 } |
7865 return constructor_name; | 7866 return constructor_name; |
7866 } | 7867 } |
7867 | 7868 |
7868 | 7869 |
7869 AstNode* Parser::ParseNewOperator() { | 7870 AstNode* Parser::ParseNewOperator() { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8094 // mode at runtime that it is within its declared bounds. | 8095 // mode at runtime that it is within its declared bounds. |
8095 new_object = CreateConstructorCallNode( | 8096 new_object = CreateConstructorCallNode( |
8096 new_pos, type_arguments, constructor, arguments); | 8097 new_pos, type_arguments, constructor, arguments); |
8097 } | 8098 } |
8098 return new_object; | 8099 return new_object; |
8099 } | 8100 } |
8100 | 8101 |
8101 | 8102 |
8102 String& Parser::Interpolate(ArrayNode* values) { | 8103 String& Parser::Interpolate(ArrayNode* values) { |
8103 const String& class_name = | 8104 const String& class_name = |
8104 String::Handle(String::NewSymbol(kStringClassName)); | 8105 String::Handle(Symbols::New(kStringClassName)); |
8105 const Class& cls = Class::Handle(LookupImplClass(class_name)); | 8106 const Class& cls = Class::Handle(LookupImplClass(class_name)); |
8106 ASSERT(!cls.IsNull()); | 8107 ASSERT(!cls.IsNull()); |
8107 const String& func_name = String::Handle(String::NewSymbol(kInterpolateName)); | 8108 const String& func_name = String::Handle(Symbols::New(kInterpolateName)); |
8108 const Function& func = | 8109 const Function& func = |
8109 Function::Handle(cls.LookupStaticFunction(func_name)); | 8110 Function::Handle(cls.LookupStaticFunction(func_name)); |
8110 ASSERT(!func.IsNull()); | 8111 ASSERT(!func.IsNull()); |
8111 | 8112 |
8112 // Build the array of literal values to interpolate. | 8113 // Build the array of literal values to interpolate. |
8113 const Array& value_arr = Array::Handle(Array::New(values->length())); | 8114 const Array& value_arr = Array::Handle(Array::New(values->length())); |
8114 for (int i = 0; i < values->length(); i++) { | 8115 for (int i = 0; i < values->length(); i++) { |
8115 ASSERT(values->ElementAt(i)->IsLiteralNode()); | 8116 ASSERT(values->ElementAt(i)->IsLiteralNode()); |
8116 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); | 8117 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); |
8117 } | 8118 } |
8118 | 8119 |
8119 // Build argument array to pass to the interpolation function. | 8120 // Build argument array to pass to the interpolation function. |
8120 GrowableArray<const Object*> interpolate_arg; | 8121 GrowableArray<const Object*> interpolate_arg; |
8121 interpolate_arg.Add(&value_arr); | 8122 interpolate_arg.Add(&value_arr); |
8122 const Array& kNoArgumentNames = Array::Handle(); | 8123 const Array& kNoArgumentNames = Array::Handle(); |
8123 | 8124 |
8124 // Call interpolation function. | 8125 // Call interpolation function. |
8125 String& concatenated = String::ZoneHandle(); | 8126 String& concatenated = String::ZoneHandle(); |
8126 concatenated ^= DartEntry::InvokeStatic(func, | 8127 concatenated ^= DartEntry::InvokeStatic(func, |
8127 interpolate_arg, | 8128 interpolate_arg, |
8128 kNoArgumentNames); | 8129 kNoArgumentNames); |
8129 if (concatenated.IsUnhandledException()) { | 8130 if (concatenated.IsUnhandledException()) { |
8130 ErrorMsg("Exception thrown in Parser::Interpolate"); | 8131 ErrorMsg("Exception thrown in Parser::Interpolate"); |
8131 } | 8132 } |
8132 concatenated = String::NewSymbol(concatenated); | 8133 concatenated = Symbols::New(concatenated); |
8133 return concatenated; | 8134 return concatenated; |
8134 } | 8135 } |
8135 | 8136 |
8136 | 8137 |
8137 // A string literal consists of the concatenation of the next n tokens | 8138 // A string literal consists of the concatenation of the next n tokens |
8138 // that satisfy the EBNF grammar: | 8139 // that satisfy the EBNF grammar: |
8139 // literal = kSTRING {{ interpol } kSTRING } | 8140 // literal = kSTRING {{ interpol } kSTRING } |
8140 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END) | 8141 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END) |
8141 // In other words, the scanner breaks down interpolated strings so that | 8142 // In other words, the scanner breaks down interpolated strings so that |
8142 // a string literal always begins and ends with a kSTRING token. | 8143 // a string literal always begins and ends with a kSTRING token. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8298 } | 8299 } |
8299 } else { | 8300 } else { |
8300 // This is a qualified identifier with a library prefix so resolve | 8301 // This is a qualified identifier with a library prefix so resolve |
8301 // the identifier locally in that library (we do not include the | 8302 // the identifier locally in that library (we do not include the |
8302 // libraries imported by that library). | 8303 // libraries imported by that library). |
8303 primary = ResolveIdentInLibraryPrefixScope(*(qual_ident.lib_prefix), | 8304 primary = ResolveIdentInLibraryPrefixScope(*(qual_ident.lib_prefix), |
8304 qual_ident); | 8305 qual_ident); |
8305 } | 8306 } |
8306 ASSERT(primary != NULL); | 8307 ASSERT(primary != NULL); |
8307 } else if (CurrentToken() == Token::kTHIS) { | 8308 } else if (CurrentToken() == Token::kTHIS) { |
8308 const String& this_name = String::Handle(String::NewSymbol(kThisName)); | 8309 const String& this_name = String::Handle(Symbols::New(kThisName)); |
8309 LocalVariable* local = LookupLocalScope(this_name); | 8310 LocalVariable* local = LookupLocalScope(this_name); |
8310 if (local == NULL) { | 8311 if (local == NULL) { |
8311 ErrorMsg("receiver 'this' is not in scope"); | 8312 ErrorMsg("receiver 'this' is not in scope"); |
8312 } | 8313 } |
8313 primary = new LoadLocalNode(TokenPos(), *local); | 8314 primary = new LoadLocalNode(TokenPos(), *local); |
8314 ConsumeToken(); | 8315 ConsumeToken(); |
8315 } else if (CurrentToken() == Token::kINTEGER) { | 8316 } else if (CurrentToken() == Token::kINTEGER) { |
8316 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); | 8317 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
8317 primary = new LiteralNode(TokenPos(), literal); | 8318 primary = new LiteralNode(TokenPos(), literal); |
8318 ConsumeToken(); | 8319 ConsumeToken(); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8659 void Parser::SkipQualIdent() { | 8660 void Parser::SkipQualIdent() { |
8660 ASSERT(IsIdentifier()); | 8661 ASSERT(IsIdentifier()); |
8661 ConsumeToken(); | 8662 ConsumeToken(); |
8662 if (CurrentToken() == Token::kPERIOD) { | 8663 if (CurrentToken() == Token::kPERIOD) { |
8663 ConsumeToken(); // Consume the kPERIOD token. | 8664 ConsumeToken(); // Consume the kPERIOD token. |
8664 ExpectIdentifier("identifier expected after '.'"); | 8665 ExpectIdentifier("identifier expected after '.'"); |
8665 } | 8666 } |
8666 } | 8667 } |
8667 | 8668 |
8668 } // namespace dart | 8669 } // namespace dart |
OLD | NEW |