| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 static void CheckedModeHandler(bool value) { | 31 static void CheckedModeHandler(bool value) { |
| 32 FLAG_enable_asserts = value; | 32 FLAG_enable_asserts = value; |
| 33 FLAG_enable_type_checks = value; | 33 FLAG_enable_type_checks = value; |
| 34 } | 34 } |
| 35 | 35 |
| 36 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 36 DEFINE_FLAG_HANDLER(CheckedModeHandler, |
| 37 enable_checked_mode, | 37 enable_checked_mode, |
| 38 "Enabled checked mode."); | 38 "Enabled checked mode."); |
| 39 | 39 |
| 40 // All references to Dart names are listed here. | |
| 41 static const char* kAssertionErrorName = "AssertionError"; | |
| 42 static const char* kTypeErrorName = "TypeError"; | |
| 43 static const char* kFallThroughErrorName = "FallThroughError"; | |
| 44 static const char* kStaticResolutionExceptionName = "StaticResolutionException"; | |
| 45 static const char* kThrowNewName = "_throwNew"; | |
| 46 static const char* kListLiteralFactoryClassName = "_ListLiteralFactory"; | |
| 47 static const char* kListLiteralFactoryName = "List.fromLiteral"; | |
| 48 static const char* kMapLiteralFactoryClassName = "_MapLiteralFactory"; | |
| 49 static const char* kMapLiteralFactoryName = "Map.fromLiteral"; | |
| 50 static const char* kImmutableMapName = "ImmutableMap"; | |
| 51 static const char* kImmutableMapConstructorName = "ImmutableMap._create"; | |
| 52 static const char* kStringClassName = "StringBase"; | |
| 53 static const char* kInterpolateName = "_interpolate"; | |
| 54 static const char* kThisName = "this"; | |
| 55 static const char* kPhaseParameterName = ":phase"; | |
| 56 static const char* kGetIteratorName = "iterator"; | |
| 57 static const char* kNoSuchMethodName = "noSuchMethod"; | |
| 58 | |
| 59 #if defined(DEBUG) | 40 #if defined(DEBUG) |
| 60 | 41 |
| 61 class TraceParser : public ValueObject { | 42 class TraceParser : public ValueObject { |
| 62 public: | 43 public: |
| 63 TraceParser(intptr_t token_pos, const Script& script, const char* msg) { | 44 TraceParser(intptr_t token_pos, const Script& script, const char* msg) { |
| 64 if (FLAG_trace_parser) { | 45 if (FLAG_trace_parser) { |
| 65 // Skips tracing of bootstrap libraries. | 46 // Skips tracing of bootstrap libraries. |
| 66 if (script.HasSource()) { | 47 if (script.HasSource()) { |
| 67 intptr_t line, column; | 48 intptr_t line, column; |
| 68 script.GetTokenLocation(token_pos, &line, &column); | 49 script.GetTokenLocation(token_pos, &line, &column); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 stack_trace ^= Object::Clone(stack_trace, Heap::kOld); | 97 stack_trace ^= Object::Clone(stack_trace, Heap::kOld); |
| 117 } | 98 } |
| 118 return new ThrowNode(token_pos, | 99 return new ThrowNode(token_pos, |
| 119 new LiteralNode(token_pos, exception), | 100 new LiteralNode(token_pos, exception), |
| 120 new LiteralNode(token_pos, stack_trace)); | 101 new LiteralNode(token_pos, stack_trace)); |
| 121 } | 102 } |
| 122 | 103 |
| 123 | 104 |
| 124 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) { | 105 LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_pos) { |
| 125 return new LocalVariable(token_pos, | 106 return new LocalVariable(token_pos, |
| 126 String::ZoneHandle(Symbols::New(":expr_temp")), | 107 String::ZoneHandle(Symbols::ExprTemp()), |
| 127 Type::ZoneHandle(Type::DynamicType())); | 108 Type::ZoneHandle(Type::DynamicType())); |
| 128 } | 109 } |
| 129 | 110 |
| 130 | 111 |
| 131 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { | 112 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { |
| 132 ASSERT(node_sequence_ == NULL); | 113 ASSERT(node_sequence_ == NULL); |
| 133 ASSERT(node_sequence != NULL); | 114 ASSERT(node_sequence != NULL); |
| 134 node_sequence_ = node_sequence; | 115 node_sequence_ = node_sequence; |
| 135 const int num_fixed_params = function().num_fixed_parameters(); | 116 const int num_fixed_params = function().num_fixed_parameters(); |
| 136 const int num_opt_params = function().num_optional_parameters(); | 117 const int num_opt_params = function().num_optional_parameters(); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 void Clear() { | 407 void Clear() { |
| 427 num_fixed_parameters = 0; | 408 num_fixed_parameters = 0; |
| 428 num_optional_parameters = 0; | 409 num_optional_parameters = 0; |
| 429 has_named_optional_parameters = false; | 410 has_named_optional_parameters = false; |
| 430 has_field_initializer = false; | 411 has_field_initializer = false; |
| 431 implicitly_final = false; | 412 implicitly_final = false; |
| 432 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 413 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
| 433 } | 414 } |
| 434 | 415 |
| 435 void AddFinalParameter(intptr_t name_pos, | 416 void AddFinalParameter(intptr_t name_pos, |
| 436 const char* name, | 417 String* name, |
| 437 const AbstractType* type) { | 418 const AbstractType* type) { |
| 438 this->num_fixed_parameters++; | 419 this->num_fixed_parameters++; |
| 439 ParamDesc param; | 420 ParamDesc param; |
| 440 param.name_pos = name_pos; | 421 param.name_pos = name_pos; |
| 441 param.name = &String::ZoneHandle(Symbols::New(name)); | 422 param.name = name; |
| 442 param.is_final = true; | 423 param.is_final = true; |
| 443 param.type = type; | 424 param.type = type; |
| 444 this->parameters->Add(param); | 425 this->parameters->Add(param); |
| 445 } | 426 } |
| 446 | 427 |
| 447 void AddReceiver(intptr_t name_pos) { | 428 void AddReceiver(intptr_t name_pos) { |
| 448 ASSERT(this->parameters->is_empty()); | 429 ASSERT(this->parameters->is_empty()); |
| 449 // The receiver does not need to be type checked. | 430 // The receiver does not need to be type checked. |
| 450 AddFinalParameter(name_pos, | 431 AddFinalParameter(name_pos, |
| 451 kThisName, | 432 &String::ZoneHandle(Symbols::This()), |
| 452 &Type::ZoneHandle(Type::DynamicType())); | 433 &Type::ZoneHandle(Type::DynamicType())); |
| 453 } | 434 } |
| 454 | 435 |
| 455 void SetImplicitlyFinal() { | 436 void SetImplicitlyFinal() { |
| 456 implicitly_final = true; | 437 implicitly_final = true; |
| 457 } | 438 } |
| 458 | 439 |
| 459 int num_fixed_parameters; | 440 int num_fixed_parameters; |
| 460 int num_optional_parameters; | 441 int num_optional_parameters; |
| 461 bool has_named_optional_parameters; // Indicates use of the new syntax. | 442 bool has_named_optional_parameters; // Indicates use of the new syntax. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 // TokenPos() returns the function's token position which points to | 885 // TokenPos() returns the function's token position which points to |
| 905 // the name of the field; we can use it to form the field_name. | 886 // the name of the field; we can use it to form the field_name. |
| 906 const String& field_name = *CurrentLiteral(); | 887 const String& field_name = *CurrentLiteral(); |
| 907 const Class& field_class = Class::ZoneHandle(func.owner()); | 888 const Class& field_class = Class::ZoneHandle(func.owner()); |
| 908 const Field& field = | 889 const Field& field = |
| 909 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 890 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
| 910 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); | 891 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
| 911 | 892 |
| 912 ParamList params; | 893 ParamList params; |
| 913 params.AddReceiver(TokenPos()); | 894 params.AddReceiver(TokenPos()); |
| 914 params.AddFinalParameter(TokenPos(), "value", &field_type); | 895 params.AddFinalParameter(TokenPos(), |
| 896 &String::ZoneHandle(Symbols::Value()), |
| 897 &field_type); |
| 915 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 898 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
| 916 ASSERT(func.num_optional_parameters() == 0); | 899 ASSERT(func.num_optional_parameters() == 0); |
| 917 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); | 900 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); |
| 918 | 901 |
| 919 // Build local scope for function and populate with the formal parameters. | 902 // Build local scope for function and populate with the formal parameters. |
| 920 OpenFunctionBlock(func); | 903 OpenFunctionBlock(func); |
| 921 AddFormalParamsToScope(¶ms, current_block_->scope); | 904 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 922 | 905 |
| 923 LoadLocalNode* receiver = | 906 LoadLocalNode* receiver = |
| 924 new LoadLocalNode(TokenPos(), *current_block_->scope->VariableAt(0)); | 907 new LoadLocalNode(TokenPos(), *current_block_->scope->VariableAt(0)); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 bool* is_no_such_method) { | 1218 bool* is_no_such_method) { |
| 1236 const Class& super_class = Class::Handle(current_class().SuperClass()); | 1219 const Class& super_class = Class::Handle(current_class().SuperClass()); |
| 1237 if (super_class.IsNull()) { | 1220 if (super_class.IsNull()) { |
| 1238 ErrorMsg(token_pos, "class '%s' does not have a superclass", | 1221 ErrorMsg(token_pos, "class '%s' does not have a superclass", |
| 1239 String::Handle(current_class().Name()).ToCString()); | 1222 String::Handle(current_class().Name()).ToCString()); |
| 1240 } | 1223 } |
| 1241 | 1224 |
| 1242 Function& super_func = | 1225 Function& super_func = |
| 1243 Function::Handle(ResolveDynamicFunction(super_class, name)); | 1226 Function::Handle(ResolveDynamicFunction(super_class, name)); |
| 1244 if (super_func.IsNull()) { | 1227 if (super_func.IsNull()) { |
| 1245 const String& no_such_method_name = | 1228 const String& no_such_method_name = String::Handle(Symbols::NoSuchMethod()); |
| 1246 String::ZoneHandle(Symbols::New(kNoSuchMethodName)); | |
| 1247 super_func = ResolveDynamicFunction(super_class, no_such_method_name); | 1229 super_func = ResolveDynamicFunction(super_class, no_such_method_name); |
| 1248 ASSERT(!super_func.IsNull()); | 1230 ASSERT(!super_func.IsNull()); |
| 1249 *is_no_such_method = true; | 1231 *is_no_such_method = true; |
| 1250 } else { | 1232 } else { |
| 1251 *is_no_such_method = false; | 1233 *is_no_such_method = false; |
| 1252 } | 1234 } |
| 1253 CheckFunctionIsCallable(token_pos, super_func); | 1235 CheckFunctionIsCallable(token_pos, super_func); |
| 1254 return super_func.raw(); | 1236 return super_func.raw(); |
| 1255 } | 1237 } |
| 1256 | 1238 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 CreateTempConstVariable(operator_pos, index_expr->id(), "lix"); | 1331 CreateTempConstVariable(operator_pos, index_expr->id(), "lix"); |
| 1350 AstNode* save = | 1332 AstNode* save = |
| 1351 new StoreLocalNode(operator_pos, *temp, index_expr); | 1333 new StoreLocalNode(operator_pos, *temp, index_expr); |
| 1352 current_block_->statements->Add(save); | 1334 current_block_->statements->Add(save); |
| 1353 index_expr = new LoadLocalNode(operator_pos, *temp); | 1335 index_expr = new LoadLocalNode(operator_pos, *temp); |
| 1354 } | 1336 } |
| 1355 } | 1337 } |
| 1356 | 1338 |
| 1357 // Resolve the [] operator function in the superclass. | 1339 // Resolve the [] operator function in the superclass. |
| 1358 const String& index_operator_name = | 1340 const String& index_operator_name = |
| 1359 String::ZoneHandle(Symbols::New(Token::Str(Token::kINDEX))); | 1341 String::ZoneHandle(Symbols::IndexToken()); |
| 1360 bool is_no_such_method = false; | 1342 bool is_no_such_method = false; |
| 1361 const Function& index_operator = Function::ZoneHandle( | 1343 const Function& index_operator = Function::ZoneHandle( |
| 1362 GetSuperFunction(operator_pos, | 1344 GetSuperFunction(operator_pos, |
| 1363 index_operator_name, | 1345 index_operator_name, |
| 1364 &is_no_such_method)); | 1346 &is_no_such_method)); |
| 1365 | 1347 |
| 1366 ArgumentListNode* index_op_arguments = new ArgumentListNode(operator_pos); | 1348 ArgumentListNode* index_op_arguments = new ArgumentListNode(operator_pos); |
| 1367 AstNode* receiver = LoadReceiver(operator_pos); | 1349 AstNode* receiver = LoadReceiver(operator_pos); |
| 1368 index_op_arguments->Add(receiver); | 1350 index_op_arguments->Add(receiver); |
| 1369 index_op_arguments->Add(index_expr); | 1351 index_op_arguments->Add(index_expr); |
| 1370 | 1352 |
| 1371 if (is_no_such_method) { | 1353 if (is_no_such_method) { |
| 1372 index_op_arguments = BuildNoSuchMethodArguments(index_operator_name, | 1354 index_op_arguments = BuildNoSuchMethodArguments(index_operator_name, |
| 1373 *index_op_arguments); | 1355 *index_op_arguments); |
| 1374 } | 1356 } |
| 1375 super_op = new StaticCallNode( | 1357 super_op = new StaticCallNode( |
| 1376 operator_pos, index_operator, index_op_arguments); | 1358 operator_pos, index_operator, index_op_arguments); |
| 1377 | 1359 |
| 1378 if (Token::IsAssignmentOperator(CurrentToken())) { | 1360 if (Token::IsAssignmentOperator(CurrentToken())) { |
| 1379 Token::Kind assignment_op = CurrentToken(); | 1361 Token::Kind assignment_op = CurrentToken(); |
| 1380 ConsumeToken(); | 1362 ConsumeToken(); |
| 1381 AstNode* value = ParseExpr(kAllowConst, kConsumeCascades); | 1363 AstNode* value = ParseExpr(kAllowConst, kConsumeCascades); |
| 1382 | 1364 |
| 1383 value = ExpandAssignableOp(operator_pos, assignment_op, super_op, value); | 1365 value = ExpandAssignableOp(operator_pos, assignment_op, super_op, value); |
| 1384 | 1366 |
| 1385 // Resolve the []= operator function in the superclass. | 1367 // Resolve the []= operator function in the superclass. |
| 1386 const String& assign_index_operator_name = String::ZoneHandle( | 1368 const String& assign_index_operator_name = |
| 1387 Symbols::New(Token::Str(Token::kASSIGN_INDEX))); | 1369 String::ZoneHandle(Symbols::AssignIndexToken()); |
| 1388 bool is_no_such_method = false; | 1370 bool is_no_such_method = false; |
| 1389 const Function& assign_index_operator = Function::ZoneHandle( | 1371 const Function& assign_index_operator = Function::ZoneHandle( |
| 1390 GetSuperFunction(operator_pos, | 1372 GetSuperFunction(operator_pos, |
| 1391 assign_index_operator_name, | 1373 assign_index_operator_name, |
| 1392 &is_no_such_method)); | 1374 &is_no_such_method)); |
| 1393 | 1375 |
| 1394 ArgumentListNode* operator_args = new ArgumentListNode(operator_pos); | 1376 ArgumentListNode* operator_args = new ArgumentListNode(operator_pos); |
| 1395 operator_args->Add(LoadReceiver(operator_pos)); | 1377 operator_args->Add(LoadReceiver(operator_pos)); |
| 1396 operator_args->Add(index_expr); | 1378 operator_args->Add(index_expr); |
| 1397 operator_args->Add(value); | 1379 operator_args->Add(value); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1809 OpenFunctionBlock(func); | 1791 OpenFunctionBlock(func); |
| 1810 | 1792 |
| 1811 // Parse expressions of instance fields that have an explicit | 1793 // Parse expressions of instance fields that have an explicit |
| 1812 // initializers. | 1794 // initializers. |
| 1813 GrowableArray<FieldInitExpression> initializers; | 1795 GrowableArray<FieldInitExpression> initializers; |
| 1814 Class& cls = Class::Handle(func.owner()); | 1796 Class& cls = Class::Handle(func.owner()); |
| 1815 ParseInitializedInstanceFields(cls, &initializers); | 1797 ParseInitializedInstanceFields(cls, &initializers); |
| 1816 | 1798 |
| 1817 LocalVariable* receiver = new LocalVariable( | 1799 LocalVariable* receiver = new LocalVariable( |
| 1818 ctor_pos, | 1800 ctor_pos, |
| 1819 String::ZoneHandle(Symbols::New(kThisName)), | 1801 String::ZoneHandle(Symbols::This()), |
| 1820 Type::ZoneHandle(Type::DynamicType())); | 1802 Type::ZoneHandle(Type::DynamicType())); |
| 1821 current_block_->scope->AddVariable(receiver); | 1803 current_block_->scope->AddVariable(receiver); |
| 1822 | 1804 |
| 1823 LocalVariable* phase_parameter = new LocalVariable( | 1805 LocalVariable* phase_parameter = new LocalVariable( |
| 1824 ctor_pos, | 1806 ctor_pos, |
| 1825 String::ZoneHandle(Symbols::New(kPhaseParameterName)), | 1807 String::ZoneHandle(Symbols::PhaseParameter()), |
| 1826 Type::ZoneHandle(Type::DynamicType())); | 1808 Type::ZoneHandle(Type::DynamicType())); |
| 1827 current_block_->scope->AddVariable(phase_parameter); | 1809 current_block_->scope->AddVariable(phase_parameter); |
| 1828 | 1810 |
| 1829 // Now that the "this" parameter is in scope, we can generate the code | 1811 // Now that the "this" parameter is in scope, we can generate the code |
| 1830 // to strore the initializer expressions in the respective instance fields. | 1812 // to strore the initializer expressions in the respective instance fields. |
| 1831 for (int i = 0; i < initializers.length(); i++) { | 1813 for (int i = 0; i < initializers.length(); i++) { |
| 1832 const Field* field = initializers[i].inst_field; | 1814 const Field* field = initializers[i].inst_field; |
| 1833 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); | 1815 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); |
| 1834 AstNode* field_init = | 1816 AstNode* field_init = |
| 1835 new StoreInstanceFieldNode(field->token_pos(), | 1817 new StoreInstanceFieldNode(field->token_pos(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 const bool allow_explicit_default_values = true; | 1859 const bool allow_explicit_default_values = true; |
| 1878 ASSERT(CurrentToken() == Token::kLPAREN); | 1860 ASSERT(CurrentToken() == Token::kLPAREN); |
| 1879 | 1861 |
| 1880 // Add implicit receiver parameter which is passed the allocated | 1862 // Add implicit receiver parameter which is passed the allocated |
| 1881 // but uninitialized instance to construct. | 1863 // but uninitialized instance to construct. |
| 1882 params.AddReceiver(TokenPos()); | 1864 params.AddReceiver(TokenPos()); |
| 1883 | 1865 |
| 1884 // Add implicit parameter for construction phase. | 1866 // Add implicit parameter for construction phase. |
| 1885 params.AddFinalParameter( | 1867 params.AddFinalParameter( |
| 1886 TokenPos(), | 1868 TokenPos(), |
| 1887 kPhaseParameterName, | 1869 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 1888 &Type::ZoneHandle(Type::DynamicType())); | 1870 &Type::ZoneHandle(Type::DynamicType())); |
| 1889 | 1871 |
| 1890 if (func.is_const()) { | 1872 if (func.is_const()) { |
| 1891 params.SetImplicitlyFinal(); | 1873 params.SetImplicitlyFinal(); |
| 1892 } | 1874 } |
| 1893 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 1875 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 1894 | 1876 |
| 1895 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 1877 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 1896 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 1878 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 1897 ASSERT(func.NumberOfParameters() == params.parameters->length()); | 1879 ASSERT(func.NumberOfParameters() == params.parameters->length()); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2326 const bool allow_explicit_default_values = true; | 2308 const bool allow_explicit_default_values = true; |
| 2327 const intptr_t formal_param_pos = TokenPos(); | 2309 const intptr_t formal_param_pos = TokenPos(); |
| 2328 method->params.Clear(); | 2310 method->params.Clear(); |
| 2329 if (has_this_param) { | 2311 if (has_this_param) { |
| 2330 method->params.AddReceiver(formal_param_pos); | 2312 method->params.AddReceiver(formal_param_pos); |
| 2331 } | 2313 } |
| 2332 // Constructors have an implicit parameter for the construction phase. | 2314 // Constructors have an implicit parameter for the construction phase. |
| 2333 if (method->IsConstructor()) { | 2315 if (method->IsConstructor()) { |
| 2334 method->params.AddFinalParameter( | 2316 method->params.AddFinalParameter( |
| 2335 TokenPos(), | 2317 TokenPos(), |
| 2336 kPhaseParameterName, | 2318 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 2337 &Type::ZoneHandle(Type::DynamicType())); | 2319 &Type::ZoneHandle(Type::DynamicType())); |
| 2338 } | 2320 } |
| 2339 if (are_implicitly_final) { | 2321 if (are_implicitly_final) { |
| 2340 method->params.SetImplicitlyFinal(); | 2322 method->params.SetImplicitlyFinal(); |
| 2341 } | 2323 } |
| 2342 ParseFormalParameterList(allow_explicit_default_values, &method->params); | 2324 ParseFormalParameterList(allow_explicit_default_values, &method->params); |
| 2343 if (method->IsGetter() || method->IsSetter()) { | 2325 if (method->IsGetter() || method->IsSetter()) { |
| 2344 int expected_num_parameters = 0; | 2326 int expected_num_parameters = 0; |
| 2345 if (method->IsGetter()) { | 2327 if (method->IsGetter()) { |
| 2346 expected_num_parameters = (method->has_static) ? 0 : 1; | 2328 expected_num_parameters = (method->has_static) ? 0 : 1; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 AddFormalParamsToFunction(¶ms, getter); | 2548 AddFormalParamsToFunction(¶ms, getter); |
| 2567 members->AddFunction(getter); | 2549 members->AddFunction(getter); |
| 2568 if (!field->has_final) { | 2550 if (!field->has_final) { |
| 2569 // Build a setter accessor for non-const fields. | 2551 // Build a setter accessor for non-const fields. |
| 2570 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); | 2552 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); |
| 2571 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 2553 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 2572 field->has_static, field->has_final, | 2554 field->has_static, field->has_final, |
| 2573 field->name_pos); | 2555 field->name_pos); |
| 2574 ParamList params; | 2556 ParamList params; |
| 2575 params.AddReceiver(TokenPos()); | 2557 params.AddReceiver(TokenPos()); |
| 2576 params.AddFinalParameter(TokenPos(), "value", field->type); | 2558 params.AddFinalParameter(TokenPos(), |
| 2559 &String::ZoneHandle(Symbols::Value()), |
| 2560 field->type); |
| 2577 setter.set_result_type(Type::Handle(Type::VoidType())); | 2561 setter.set_result_type(Type::Handle(Type::VoidType())); |
| 2578 AddFormalParamsToFunction(¶ms, setter); | 2562 AddFormalParamsToFunction(¶ms, setter); |
| 2579 members->AddFunction(setter); | 2563 members->AddFunction(setter); |
| 2580 } | 2564 } |
| 2581 } | 2565 } |
| 2582 | 2566 |
| 2583 if (CurrentToken() != Token::kCOMMA) { | 2567 if (CurrentToken() != Token::kCOMMA) { |
| 2584 break; | 2568 break; |
| 2585 } | 2569 } |
| 2586 ConsumeToken(); | 2570 ConsumeToken(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2937 RawFunction::kConstructor, | 2921 RawFunction::kConstructor, |
| 2938 /* is_static = */ false, | 2922 /* is_static = */ false, |
| 2939 /* is_const = */ false, | 2923 /* is_const = */ false, |
| 2940 class_desc->token_pos())); | 2924 class_desc->token_pos())); |
| 2941 ParamList params; | 2925 ParamList params; |
| 2942 // Add implicit 'this' parameter. | 2926 // Add implicit 'this' parameter. |
| 2943 params.AddReceiver(TokenPos()); | 2927 params.AddReceiver(TokenPos()); |
| 2944 // Add implicit parameter for construction phase. | 2928 // Add implicit parameter for construction phase. |
| 2945 params.AddFinalParameter( | 2929 params.AddFinalParameter( |
| 2946 TokenPos(), | 2930 TokenPos(), |
| 2947 kPhaseParameterName, | 2931 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 2948 &Type::ZoneHandle(Type::DynamicType())); | 2932 &Type::ZoneHandle(Type::DynamicType())); |
| 2949 | 2933 |
| 2950 AddFormalParamsToFunction(¶ms, ctor); | 2934 AddFormalParamsToFunction(¶ms, ctor); |
| 2951 // The body of the constructor cannot modify the type arguments of the | 2935 // The body of the constructor cannot modify the type arguments of the |
| 2952 // constructed instance, which is passed in as a hidden parameter. | 2936 // constructed instance, which is passed in as a hidden parameter. |
| 2953 // Therefore, there is no need to set the result type to be checked. | 2937 // Therefore, there is no need to set the result type to be checked. |
| 2954 const AbstractType& result_type = Type::ZoneHandle(Type::DynamicType()); | 2938 const AbstractType& result_type = Type::ZoneHandle(Type::DynamicType()); |
| 2955 ctor.set_result_type(result_type); | 2939 ctor.set_result_type(result_type); |
| 2956 class_desc->AddFunction(ctor); | 2940 class_desc->AddFunction(ctor); |
| 2957 } | 2941 } |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3813 // They need to be registered with class finalization after parsing | 3797 // They need to be registered with class finalization after parsing |
| 3814 // has been completed. | 3798 // has been completed. |
| 3815 Isolate* isolate = Isolate::Current(); | 3799 Isolate* isolate = Isolate::Current(); |
| 3816 ObjectStore* object_store = isolate->object_store(); | 3800 ObjectStore* object_store = isolate->object_store(); |
| 3817 const GrowableObjectArray& pending_classes = | 3801 const GrowableObjectArray& pending_classes = |
| 3818 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); | 3802 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); |
| 3819 SetPosition(0); | 3803 SetPosition(0); |
| 3820 is_top_level_ = true; | 3804 is_top_level_ = true; |
| 3821 TopLevel top_level; | 3805 TopLevel top_level; |
| 3822 Class& toplevel_class = Class::Handle( | 3806 Class& toplevel_class = Class::Handle( |
| 3823 Class::New(String::ZoneHandle(Symbols::New("::")), | 3807 Class::New(String::Handle(Symbols::TopLevel()), script_, TokenPos())); |
| 3824 script_, | |
| 3825 TokenPos())); | |
| 3826 toplevel_class.set_library(library_); | 3808 toplevel_class.set_library(library_); |
| 3827 | 3809 |
| 3828 if (is_library_source()) { | 3810 if (is_library_source()) { |
| 3829 ParseLibraryDefinition(); | 3811 ParseLibraryDefinition(); |
| 3830 } | 3812 } |
| 3831 | 3813 |
| 3832 while (true) { | 3814 while (true) { |
| 3833 set_current_class(Class::Handle()); // No current class. | 3815 set_current_class(Class::Handle()); // No current class. |
| 3834 if (CurrentToken() == Token::kCLASS) { | 3816 if (CurrentToken() == Token::kCLASS) { |
| 3835 ParseClassDefinition(pending_classes); | 3817 ParseClassDefinition(pending_classes); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4031 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), | 4013 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), |
| 4032 native_name, | 4014 native_name, |
| 4033 native_function, | 4015 native_function, |
| 4034 num_parameters, | 4016 num_parameters, |
| 4035 has_opt_params, | 4017 has_opt_params, |
| 4036 is_instance_closure))); | 4018 is_instance_closure))); |
| 4037 } | 4019 } |
| 4038 | 4020 |
| 4039 | 4021 |
| 4040 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { | 4022 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { |
| 4041 const String& this_name = String::Handle(Symbols::New(kThisName)); | 4023 const String& this_name = String::Handle(Symbols::This()); |
| 4042 return from_scope->LookupVariable(this_name, test_only); | 4024 return from_scope->LookupVariable(this_name, test_only); |
| 4043 } | 4025 } |
| 4044 | 4026 |
| 4045 | 4027 |
| 4046 LocalVariable* Parser::LookupPhaseParameter() { | 4028 LocalVariable* Parser::LookupPhaseParameter() { |
| 4047 const String& phase_name = | 4029 const String& phase_name = |
| 4048 String::Handle(Symbols::New(kPhaseParameterName)); | 4030 String::Handle(Symbols::PhaseParameter()); |
| 4049 const bool kTestOnly = false; | 4031 const bool kTestOnly = false; |
| 4050 return current_block_->scope->LookupVariable(phase_name, kTestOnly); | 4032 return current_block_->scope->LookupVariable(phase_name, kTestOnly); |
| 4051 } | 4033 } |
| 4052 | 4034 |
| 4053 | 4035 |
| 4054 void Parser::CaptureReceiver() { | 4036 void Parser::CaptureReceiver() { |
| 4055 ASSERT(current_block_->scope->function_level() > 0); | 4037 ASSERT(current_block_->scope->function_level() > 0); |
| 4056 const bool kTestOnly = false; | 4038 const bool kTestOnly = false; |
| 4057 // Side effect of lookup captures the receiver variable. | 4039 // Side effect of lookup captures the receiver variable. |
| 4058 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 4040 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4206 } | 4188 } |
| 4207 const intptr_t ident_pos = TokenPos(); | 4189 const intptr_t ident_pos = TokenPos(); |
| 4208 if (IsIdentifier()) { | 4190 if (IsIdentifier()) { |
| 4209 variable_name = CurrentLiteral(); | 4191 variable_name = CurrentLiteral(); |
| 4210 function_name = variable_name; | 4192 function_name = variable_name; |
| 4211 ConsumeToken(); | 4193 ConsumeToken(); |
| 4212 } else { | 4194 } else { |
| 4213 if (!is_literal) { | 4195 if (!is_literal) { |
| 4214 ErrorMsg("function name expected"); | 4196 ErrorMsg("function name expected"); |
| 4215 } | 4197 } |
| 4216 const String& anonymous_function_name = | 4198 function_name = &String::ZoneHandle(Symbols::Function()); |
| 4217 String::ZoneHandle(Symbols::New("function")); | |
| 4218 function_name = &anonymous_function_name; | |
| 4219 } | 4199 } |
| 4220 ASSERT(ident_pos >= 0); | 4200 ASSERT(ident_pos >= 0); |
| 4221 | 4201 |
| 4222 if (CurrentToken() != Token::kLPAREN) { | 4202 if (CurrentToken() != Token::kLPAREN) { |
| 4223 ErrorMsg("'(' expected"); | 4203 ErrorMsg("'(' expected"); |
| 4224 } | 4204 } |
| 4225 intptr_t function_pos = TokenPos(); | 4205 intptr_t function_pos = TokenPos(); |
| 4226 | 4206 |
| 4227 // Check whether we have parsed this closure function before, in a previous | 4207 // Check whether we have parsed this closure function before, in a previous |
| 4228 // compilation. If so, reuse the function object, else create a new one | 4208 // compilation. If so, reuse the function object, else create a new one |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4741 // End of switch statement. | 4721 // End of switch statement. |
| 4742 break; | 4722 break; |
| 4743 } | 4723 } |
| 4744 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { | 4724 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { |
| 4745 // End of this case clause. If there is a possible fall-through to | 4725 // End of this case clause. If there is a possible fall-through to |
| 4746 // the next case clause, throw an implicit FallThroughError. | 4726 // the next case clause, throw an implicit FallThroughError. |
| 4747 if (!abrupt_completing_seen) { | 4727 if (!abrupt_completing_seen) { |
| 4748 ArgumentListNode* arguments = new ArgumentListNode(TokenPos()); | 4728 ArgumentListNode* arguments = new ArgumentListNode(TokenPos()); |
| 4749 arguments->Add(new LiteralNode( | 4729 arguments->Add(new LiteralNode( |
| 4750 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); | 4730 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); |
| 4731 const String& cls_name = String::Handle(Symbols::FallThroughError()); |
| 4732 const String& func_name = String::Handle(Symbols::ThrowNew()); |
| 4751 current_block_->statements->Add( | 4733 current_block_->statements->Add( |
| 4752 MakeStaticCall(kFallThroughErrorName, kThrowNewName, arguments)); | 4734 MakeStaticCall(cls_name, func_name, arguments)); |
| 4753 } | 4735 } |
| 4754 break; | 4736 break; |
| 4755 } | 4737 } |
| 4756 // The next statement still belongs to this case. | 4738 // The next statement still belongs to this case. |
| 4757 AstNode* statement = ParseStatement(); | 4739 AstNode* statement = ParseStatement(); |
| 4758 if (statement != NULL) { | 4740 if (statement != NULL) { |
| 4759 current_block_->statements->Add(statement); | 4741 current_block_->statements->Add(statement); |
| 4760 abrupt_completing_seen |= IsAbruptCompleting(statement); | 4742 abrupt_completing_seen |= IsAbruptCompleting(statement); |
| 4761 } | 4743 } |
| 4762 } | 4744 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4913 } | 4895 } |
| 4914 } | 4896 } |
| 4915 ExpectToken(Token::kIN); | 4897 ExpectToken(Token::kIN); |
| 4916 const intptr_t collection_pos = TokenPos(); | 4898 const intptr_t collection_pos = TokenPos(); |
| 4917 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); | 4899 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); |
| 4918 ExpectToken(Token::kRPAREN); | 4900 ExpectToken(Token::kRPAREN); |
| 4919 | 4901 |
| 4920 OpenBlock(); // Implicit block around while loop. | 4902 OpenBlock(); // Implicit block around while loop. |
| 4921 | 4903 |
| 4922 // Generate implicit iterator variable and add to scope. | 4904 // Generate implicit iterator variable and add to scope. |
| 4923 const String& iterator_name = | 4905 const String& iterator_name = String::ZoneHandle(Symbols::ForInIter()); |
| 4924 String::ZoneHandle(Symbols::New(":for-in-iter")); | |
| 4925 // We could set the type of the implicit iterator variable to Iterator<T> | 4906 // We could set the type of the implicit iterator variable to Iterator<T> |
| 4926 // where T is the type of the for loop variable. However, the type error | 4907 // where T is the type of the for loop variable. However, the type error |
| 4927 // would refer to the compiler generated iterator and could confuse the user. | 4908 // would refer to the compiler generated iterator and could confuse the user. |
| 4928 // It is better to leave the iterator untyped and postpone the type error | 4909 // It is better to leave the iterator untyped and postpone the type error |
| 4929 // until the loop variable is assigned to. | 4910 // until the loop variable is assigned to. |
| 4930 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); | 4911 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); |
| 4931 LocalVariable* iterator_var = | 4912 LocalVariable* iterator_var = |
| 4932 new LocalVariable(collection_pos, iterator_name, iterator_type); | 4913 new LocalVariable(collection_pos, iterator_name, iterator_type); |
| 4933 current_block_->scope->AddVariable(iterator_var); | 4914 current_block_->scope->AddVariable(iterator_var); |
| 4934 | 4915 |
| 4935 // Generate initialization of iterator variable. | 4916 // Generate initialization of iterator variable. |
| 4936 const String& iterator_method_name = | 4917 const String& iterator_method_name = |
| 4937 String::ZoneHandle(Symbols::New(kGetIteratorName)); | 4918 String::ZoneHandle(Symbols::GetIterator()); |
| 4938 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); | 4919 ArgumentListNode* no_args = new ArgumentListNode(collection_pos); |
| 4939 AstNode* get_iterator = new InstanceCallNode( | 4920 AstNode* get_iterator = new InstanceCallNode( |
| 4940 collection_pos, collection_expr, iterator_method_name, no_args); | 4921 collection_pos, collection_expr, iterator_method_name, no_args); |
| 4941 AstNode* iterator_init = | 4922 AstNode* iterator_init = |
| 4942 new StoreLocalNode(collection_pos, *iterator_var, get_iterator); | 4923 new StoreLocalNode(collection_pos, *iterator_var, get_iterator); |
| 4943 current_block_->statements->Add(iterator_init); | 4924 current_block_->statements->Add(iterator_init); |
| 4944 | 4925 |
| 4945 // Generate while loop condition. | 4926 // Generate while loop condition. |
| 4946 AstNode* iterator_has_next = new InstanceCallNode( | 4927 AstNode* iterator_has_next = new InstanceCallNode( |
| 4947 collection_pos, | 4928 collection_pos, |
| 4948 new LoadLocalNode(collection_pos, *iterator_var), | 4929 new LoadLocalNode(collection_pos, *iterator_var), |
| 4949 String::ZoneHandle(Symbols::New("hasNext")), | 4930 String::ZoneHandle(Symbols::HasNext()), |
| 4950 no_args); | 4931 no_args); |
| 4951 | 4932 |
| 4952 // Parse the for loop body. Ideally, we would use ParseNestedStatement() | 4933 // Parse the for loop body. Ideally, we would use ParseNestedStatement() |
| 4953 // here, but that does not work well because we have to insert an implicit | 4934 // here, but that does not work well because we have to insert an implicit |
| 4954 // variable assignment and potentially a variable declaration in the | 4935 // variable assignment and potentially a variable declaration in the |
| 4955 // loop body. | 4936 // loop body. |
| 4956 OpenLoopBlock(); | 4937 OpenLoopBlock(); |
| 4957 current_block_->scope->AddLabel(label); | 4938 current_block_->scope->AddLabel(label); |
| 4958 | 4939 |
| 4959 AstNode* iterator_next = new InstanceCallNode( | 4940 AstNode* iterator_next = new InstanceCallNode( |
| 4960 collection_pos, | 4941 collection_pos, |
| 4961 new LoadLocalNode(collection_pos, *iterator_var), | 4942 new LoadLocalNode(collection_pos, *iterator_var), |
| 4962 String::ZoneHandle(Symbols::New("next")), | 4943 String::ZoneHandle(Symbols::Next()), |
| 4963 no_args); | 4944 no_args); |
| 4964 | 4945 |
| 4965 // Generate assignment of next iterator value to loop variable. | 4946 // Generate assignment of next iterator value to loop variable. |
| 4966 AstNode* loop_var_assignment = NULL; | 4947 AstNode* loop_var_assignment = NULL; |
| 4967 if (loop_var != NULL) { | 4948 if (loop_var != NULL) { |
| 4968 // The for loop declares a new variable. Add it to the loop body scope. | 4949 // The for loop declares a new variable. Add it to the loop body scope. |
| 4969 current_block_->scope->AddVariable(loop_var); | 4950 current_block_->scope->AddVariable(loop_var); |
| 4970 loop_var_assignment = | 4951 loop_var_assignment = |
| 4971 new StoreLocalNode(loop_var_pos, *loop_var, iterator_next); | 4952 new StoreLocalNode(loop_var_pos, *loop_var, iterator_next); |
| 4972 } else { | 4953 } else { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5063 return new ForNode(for_pos, | 5044 return new ForNode(for_pos, |
| 5064 label, | 5045 label, |
| 5065 NodeAsSequenceNode(init_pos, initializer, init_scope), | 5046 NodeAsSequenceNode(init_pos, initializer, init_scope), |
| 5066 condition, | 5047 condition, |
| 5067 NodeAsSequenceNode(incr_pos, increment, incr_scope), | 5048 NodeAsSequenceNode(incr_pos, increment, incr_scope), |
| 5068 body); | 5049 body); |
| 5069 } | 5050 } |
| 5070 | 5051 |
| 5071 | 5052 |
| 5072 // Calling VM-internal helpers, uses implementation core library. | 5053 // Calling VM-internal helpers, uses implementation core library. |
| 5073 AstNode* Parser::MakeStaticCall(const char* class_name, | 5054 AstNode* Parser::MakeStaticCall(const String& cls_name, |
| 5074 const char* function_name, | 5055 const String& func_name, |
| 5075 ArgumentListNode* arguments) { | 5056 ArgumentListNode* arguments) { |
| 5076 const String& cls_name = | |
| 5077 String::Handle(Symbols::New(class_name)); | |
| 5078 const Class& cls = Class::Handle(LookupImplClass(cls_name)); | 5057 const Class& cls = Class::Handle(LookupImplClass(cls_name)); |
| 5079 ASSERT(!cls.IsNull()); | 5058 ASSERT(!cls.IsNull()); |
| 5080 const String& func_name = | |
| 5081 String::ZoneHandle(Symbols::New(function_name)); | |
| 5082 const Function& func = Function::ZoneHandle( | 5059 const Function& func = Function::ZoneHandle( |
| 5083 Resolver::ResolveStatic(cls, | 5060 Resolver::ResolveStatic(cls, |
| 5084 func_name, | 5061 func_name, |
| 5085 arguments->length(), | 5062 arguments->length(), |
| 5086 arguments->names(), | 5063 arguments->names(), |
| 5087 Resolver::kIsQualified)); | 5064 Resolver::kIsQualified)); |
| 5088 ASSERT(!func.IsNull()); | 5065 ASSERT(!func.IsNull()); |
| 5089 CheckFunctionIsCallable(arguments->token_pos(), func); | 5066 CheckFunctionIsCallable(arguments->token_pos(), func); |
| 5090 return new StaticCallNode(arguments->token_pos(), func, arguments); | 5067 return new StaticCallNode(arguments->token_pos(), func, arguments); |
| 5091 } | 5068 } |
| 5092 | 5069 |
| 5093 | 5070 |
| 5094 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { | 5071 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { |
| 5095 ArgumentListNode* arguments = new ArgumentListNode(begin); | 5072 ArgumentListNode* arguments = new ArgumentListNode(begin); |
| 5096 arguments->Add(new LiteralNode(begin, | 5073 arguments->Add(new LiteralNode(begin, |
| 5097 Integer::ZoneHandle(Integer::New(begin)))); | 5074 Integer::ZoneHandle(Integer::New(begin)))); |
| 5098 arguments->Add(new LiteralNode(end, | 5075 arguments->Add(new LiteralNode(end, |
| 5099 Integer::ZoneHandle(Integer::New(end)))); | 5076 Integer::ZoneHandle(Integer::New(end)))); |
| 5100 return MakeStaticCall(kAssertionErrorName, kThrowNewName, arguments); | 5077 const String& cls_name = String::Handle(Symbols::AssertionError()); |
| 5078 const String& func_name = String::Handle(Symbols::ThrowNew()); |
| 5079 return MakeStaticCall(cls_name, func_name, arguments); |
| 5101 } | 5080 } |
| 5102 | 5081 |
| 5103 | 5082 |
| 5104 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { | 5083 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { |
| 5105 if (condition->IsClosureNode() || | 5084 if (condition->IsClosureNode() || |
| 5106 (condition->IsStoreLocalNode() && | 5085 (condition->IsStoreLocalNode() && |
| 5107 condition->AsStoreLocalNode()->value()->IsClosureNode())) { | 5086 condition->AsStoreLocalNode()->value()->IsClosureNode())) { |
| 5108 EnsureExpressionTemp(); | 5087 EnsureExpressionTemp(); |
| 5109 // Function literal in assert implies a call. | 5088 // Function literal in assert implies a call. |
| 5110 const intptr_t pos = condition->token_pos(); | 5089 const intptr_t pos = condition->token_pos(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5267 // slot before processing the catch block handler. | 5246 // slot before processing the catch block handler. |
| 5268 // ':exception_var' - Used to save the current exception object that was | 5247 // ':exception_var' - Used to save the current exception object that was |
| 5269 // thrown. | 5248 // thrown. |
| 5270 // ':stacktrace_var' - Used to save the current stack trace object into which | 5249 // ':stacktrace_var' - Used to save the current stack trace object into which |
| 5271 // the stack trace was copied into when an exception was | 5250 // the stack trace was copied into when an exception was |
| 5272 // thrown. | 5251 // thrown. |
| 5273 // :exception_var and :stacktrace_var get set with the exception object | 5252 // :exception_var and :stacktrace_var get set with the exception object |
| 5274 // and the stacktrace object when an exception is thrown. | 5253 // and the stacktrace object when an exception is thrown. |
| 5275 // These three implicit variables can never be captured variables. | 5254 // These three implicit variables can never be captured variables. |
| 5276 const String& context_var_name = | 5255 const String& context_var_name = |
| 5277 String::ZoneHandle(Symbols::New(":saved_context_var")); | 5256 String::ZoneHandle(Symbols::SavedContextVar()); |
| 5278 LocalVariable* context_var = | 5257 LocalVariable* context_var = |
| 5279 current_block_->scope->LocalLookupVariable(context_var_name); | 5258 current_block_->scope->LocalLookupVariable(context_var_name); |
| 5280 if (context_var == NULL) { | 5259 if (context_var == NULL) { |
| 5281 context_var = new LocalVariable(TokenPos(), | 5260 context_var = new LocalVariable(TokenPos(), |
| 5282 context_var_name, | 5261 context_var_name, |
| 5283 Type::ZoneHandle(Type::DynamicType())); | 5262 Type::ZoneHandle(Type::DynamicType())); |
| 5284 current_block_->scope->AddVariable(context_var); | 5263 current_block_->scope->AddVariable(context_var); |
| 5285 } | 5264 } |
| 5286 const String& catch_excp_var_name = | 5265 const String& catch_excp_var_name = |
| 5287 String::ZoneHandle(Symbols::New(":exception_var")); | 5266 String::ZoneHandle(Symbols::ExceptionVar()); |
| 5288 LocalVariable* catch_excp_var = | 5267 LocalVariable* catch_excp_var = |
| 5289 current_block_->scope->LocalLookupVariable(catch_excp_var_name); | 5268 current_block_->scope->LocalLookupVariable(catch_excp_var_name); |
| 5290 if (catch_excp_var == NULL) { | 5269 if (catch_excp_var == NULL) { |
| 5291 catch_excp_var = new LocalVariable(TokenPos(), | 5270 catch_excp_var = new LocalVariable(TokenPos(), |
| 5292 catch_excp_var_name, | 5271 catch_excp_var_name, |
| 5293 Type::ZoneHandle(Type::DynamicType())); | 5272 Type::ZoneHandle(Type::DynamicType())); |
| 5294 current_block_->scope->AddVariable(catch_excp_var); | 5273 current_block_->scope->AddVariable(catch_excp_var); |
| 5295 } | 5274 } |
| 5296 const String& catch_trace_var_name = | 5275 const String& catch_trace_var_name = |
| 5297 String::ZoneHandle(Symbols::New(":stacktrace_var")); | 5276 String::ZoneHandle(Symbols::StacktraceVar()); |
| 5298 LocalVariable* catch_trace_var = | 5277 LocalVariable* catch_trace_var = |
| 5299 current_block_->scope->LocalLookupVariable(catch_trace_var_name); | 5278 current_block_->scope->LocalLookupVariable(catch_trace_var_name); |
| 5300 if (catch_trace_var == NULL) { | 5279 if (catch_trace_var == NULL) { |
| 5301 catch_trace_var = new LocalVariable(TokenPos(), | 5280 catch_trace_var = new LocalVariable(TokenPos(), |
| 5302 catch_trace_var_name, | 5281 catch_trace_var_name, |
| 5303 Type::ZoneHandle(Type::DynamicType())); | 5282 Type::ZoneHandle(Type::DynamicType())); |
| 5304 current_block_->scope->AddVariable(catch_trace_var); | 5283 current_block_->scope->AddVariable(catch_trace_var); |
| 5305 } | 5284 } |
| 5306 | 5285 |
| 5307 const intptr_t try_pos = TokenPos(); | 5286 const intptr_t try_pos = TokenPos(); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5656 // Check if it is ok to do a rethrow. | 5635 // Check if it is ok to do a rethrow. |
| 5657 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); | 5636 SourceLabel* label = current_block_->scope->LookupInnermostCatchLabel(); |
| 5658 if (label == NULL || | 5637 if (label == NULL || |
| 5659 label->FunctionLevel() != current_block_->scope->function_level()) { | 5638 label->FunctionLevel() != current_block_->scope->function_level()) { |
| 5660 ErrorMsg("rethrow of an exception is not valid here"); | 5639 ErrorMsg("rethrow of an exception is not valid here"); |
| 5661 } | 5640 } |
| 5662 ASSERT(label->owner() != NULL); | 5641 ASSERT(label->owner() != NULL); |
| 5663 LocalScope* scope = label->owner()->parent(); | 5642 LocalScope* scope = label->owner()->parent(); |
| 5664 ASSERT(scope != NULL); | 5643 ASSERT(scope != NULL); |
| 5665 LocalVariable* excp_var = scope->LocalLookupVariable( | 5644 LocalVariable* excp_var = scope->LocalLookupVariable( |
| 5666 String::ZoneHandle(Symbols::New(":exception_var"))); | 5645 String::ZoneHandle(Symbols::ExceptionVar())); |
| 5667 ASSERT(excp_var != NULL); | 5646 ASSERT(excp_var != NULL); |
| 5668 LocalVariable* trace_var = scope->LocalLookupVariable( | 5647 LocalVariable* trace_var = scope->LocalLookupVariable( |
| 5669 String::ZoneHandle(Symbols::New(":stacktrace_var"))); | 5648 String::ZoneHandle(Symbols::StacktraceVar())); |
| 5670 ASSERT(trace_var != NULL); | 5649 ASSERT(trace_var != NULL); |
| 5671 statement = new ThrowNode(statement_pos, | 5650 statement = new ThrowNode(statement_pos, |
| 5672 new LoadLocalNode(statement_pos, *excp_var), | 5651 new LoadLocalNode(statement_pos, *excp_var), |
| 5673 new LoadLocalNode(statement_pos, *trace_var)); | 5652 new LoadLocalNode(statement_pos, *trace_var)); |
| 5674 } | 5653 } |
| 5675 } else { | 5654 } else { |
| 5676 statement = ParseExpr(kAllowConst, kConsumeCascades); | 5655 statement = ParseExpr(kAllowConst, kConsumeCascades); |
| 5677 ExpectSemicolon(); | 5656 ExpectSemicolon(); |
| 5678 } | 5657 } |
| 5679 return statement; | 5658 return statement; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5950 ArgumentListNode* arguments = new ArgumentListNode(type_pos); | 5929 ArgumentListNode* arguments = new ArgumentListNode(type_pos); |
| 5951 // Location argument. | 5930 // Location argument. |
| 5952 arguments->Add(new LiteralNode( | 5931 arguments->Add(new LiteralNode( |
| 5953 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); | 5932 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); |
| 5954 // Src value argument. | 5933 // Src value argument. |
| 5955 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); | 5934 arguments->Add(new LiteralNode(type_pos, Instance::ZoneHandle())); |
| 5956 // Dst type name argument. | 5935 // Dst type name argument. |
| 5957 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5936 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
| 5958 Symbols::New("malformed")))); | 5937 Symbols::New("malformed")))); |
| 5959 // Dst name argument. | 5938 // Dst name argument. |
| 5960 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5939 arguments->Add(new LiteralNode(type_pos, |
| 5961 Symbols::New("")))); | 5940 String::ZoneHandle(Symbols::Empty()))); |
| 5962 // Malformed type error. | 5941 // Malformed type error. |
| 5963 const Error& error = Error::Handle(type.malformed_error()); | 5942 const Error& error = Error::Handle(type.malformed_error()); |
| 5964 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5943 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
| 5965 Symbols::New(error.ToErrorCString())))); | 5944 Symbols::New(error.ToErrorCString())))); |
| 5966 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); | 5945 const String& cls_name = String::Handle(Symbols::TypeError()); |
| 5946 const String& func_name = String::Handle(Symbols::ThrowNew()); |
| 5947 return MakeStaticCall(cls_name, func_name, arguments); |
| 5967 } | 5948 } |
| 5968 | 5949 |
| 5969 | 5950 |
| 5970 AstNode* Parser::ParseBinaryExpr(int min_preced) { | 5951 AstNode* Parser::ParseBinaryExpr(int min_preced) { |
| 5971 TRACE_PARSER("ParseBinaryExpr"); | 5952 TRACE_PARSER("ParseBinaryExpr"); |
| 5972 ASSERT(min_preced >= 4); | 5953 ASSERT(min_preced >= 4); |
| 5973 AstNode* left_operand = ParseUnaryExpr(); | 5954 AstNode* left_operand = ParseUnaryExpr(); |
| 5974 if (IsLiteral("as")) { // Not a reserved word. | 5955 if (IsLiteral("as")) { // Not a reserved word. |
| 5975 token_kind_ = Token::kAS; | 5956 token_kind_ = Token::kAS; |
| 5976 } | 5957 } |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6479 // do not match or compile time error otherwise. | 6460 // do not match or compile time error otherwise. |
| 6480 const Function& test_func = Function::Handle( | 6461 const Function& test_func = Function::Handle( |
| 6481 Resolver::ResolveStaticByName(cls, func_name, Resolver::kIsQualified)); | 6462 Resolver::ResolveStaticByName(cls, func_name, Resolver::kIsQualified)); |
| 6482 if (test_func.IsNull()) { | 6463 if (test_func.IsNull()) { |
| 6483 ErrorMsg(ident_pos, "unresolved static method '%s'", | 6464 ErrorMsg(ident_pos, "unresolved static method '%s'", |
| 6484 func_name.ToCString()); | 6465 func_name.ToCString()); |
| 6485 } else { | 6466 } else { |
| 6486 ArgumentListNode* arguments = new ArgumentListNode(ident_pos); | 6467 ArgumentListNode* arguments = new ArgumentListNode(ident_pos); |
| 6487 arguments->Add(new LiteralNode( | 6468 arguments->Add(new LiteralNode( |
| 6488 TokenPos(), Integer::ZoneHandle(Integer::New(ident_pos)))); | 6469 TokenPos(), Integer::ZoneHandle(Integer::New(ident_pos)))); |
| 6489 return MakeStaticCall(kStaticResolutionExceptionName, | 6470 const String& cls_name = |
| 6490 kThrowNewName, | 6471 String::Handle(Symbols::StaticResolutionException()); |
| 6491 arguments); | 6472 const String& func_name = String::Handle(Symbols::ThrowNew()); |
| 6473 return MakeStaticCall(cls_name, func_name, arguments); |
| 6492 } | 6474 } |
| 6493 } | 6475 } |
| 6494 CheckFunctionIsCallable(call_pos, func); | 6476 CheckFunctionIsCallable(call_pos, func); |
| 6495 return new StaticCallNode(call_pos, func, arguments); | 6477 return new StaticCallNode(call_pos, func, arguments); |
| 6496 } | 6478 } |
| 6497 | 6479 |
| 6498 | 6480 |
| 6499 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { | 6481 AstNode* Parser::ParseInstanceCall(AstNode* receiver, const String& func_name) { |
| 6500 TRACE_PARSER("ParseInstanceCall"); | 6482 TRACE_PARSER("ParseInstanceCall"); |
| 6501 const intptr_t call_pos = TokenPos(); | 6483 const intptr_t call_pos = TokenPos(); |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7551 "a type variable"); | 7533 "a type variable"); |
| 7552 } | 7534 } |
| 7553 } | 7535 } |
| 7554 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); | 7536 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); |
| 7555 | 7537 |
| 7556 // Parse the list elements. Note: there may be an optional extra | 7538 // Parse the list elements. Note: there may be an optional extra |
| 7557 // comma after the last element. | 7539 // comma after the last element. |
| 7558 ArrayNode* list = new ArrayNode(TokenPos(), type_arguments); | 7540 ArrayNode* list = new ArrayNode(TokenPos(), type_arguments); |
| 7559 if (!is_empty_literal) { | 7541 if (!is_empty_literal) { |
| 7560 const bool saved_mode = SetAllowFunctionLiterals(true); | 7542 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7561 const String& dst_name = String::ZoneHandle( | 7543 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); |
| 7562 Symbols::New("list literal element")); | |
| 7563 while (CurrentToken() != Token::kRBRACK) { | 7544 while (CurrentToken() != Token::kRBRACK) { |
| 7564 const intptr_t element_pos = TokenPos(); | 7545 const intptr_t element_pos = TokenPos(); |
| 7565 AstNode* element = ParseExpr(is_const, kConsumeCascades); | 7546 AstNode* element = ParseExpr(is_const, kConsumeCascades); |
| 7566 if (FLAG_enable_type_checks && | 7547 if (FLAG_enable_type_checks && |
| 7567 !is_const && | 7548 !is_const && |
| 7568 !element_type.IsDynamicType()) { | 7549 !element_type.IsDynamicType()) { |
| 7569 element = new AssignableNode(element_pos, | 7550 element = new AssignableNode(element_pos, |
| 7570 element, | 7551 element, |
| 7571 element_type, | 7552 element_type, |
| 7572 dst_name); | 7553 dst_name); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7610 } | 7591 } |
| 7611 } | 7592 } |
| 7612 const_list.SetAt(i, elem->AsLiteralNode()->literal()); | 7593 const_list.SetAt(i, elem->AsLiteralNode()->literal()); |
| 7613 } | 7594 } |
| 7614 const_list ^= const_list.Canonicalize(); | 7595 const_list ^= const_list.Canonicalize(); |
| 7615 const_list.MakeImmutable(); | 7596 const_list.MakeImmutable(); |
| 7616 return new LiteralNode(literal_pos, const_list); | 7597 return new LiteralNode(literal_pos, const_list); |
| 7617 } else { | 7598 } else { |
| 7618 // Factory call at runtime. | 7599 // Factory call at runtime. |
| 7619 String& list_literal_factory_class_name = String::Handle( | 7600 String& list_literal_factory_class_name = String::Handle( |
| 7620 Symbols::New(kListLiteralFactoryClassName)); | 7601 Symbols::ListLiteralFactoryClass()); |
| 7621 const Class& list_literal_factory_class = | 7602 const Class& list_literal_factory_class = |
| 7622 Class::Handle(LookupCoreClass(list_literal_factory_class_name)); | 7603 Class::Handle(LookupCoreClass(list_literal_factory_class_name)); |
| 7623 ASSERT(!list_literal_factory_class.IsNull()); | 7604 ASSERT(!list_literal_factory_class.IsNull()); |
| 7624 const String& list_literal_factory_name = | 7605 const String& list_literal_factory_name = |
| 7625 String::Handle(Symbols::New(kListLiteralFactoryName)); | 7606 String::Handle(Symbols::ListLiteralFactory()); |
| 7626 const Function& list_literal_factory = Function::ZoneHandle( | 7607 const Function& list_literal_factory = Function::ZoneHandle( |
| 7627 list_literal_factory_class.LookupFactory(list_literal_factory_name)); | 7608 list_literal_factory_class.LookupFactory(list_literal_factory_name)); |
| 7628 ASSERT(!list_literal_factory.IsNull()); | 7609 ASSERT(!list_literal_factory.IsNull()); |
| 7629 if (!type_arguments.IsNull() && | 7610 if (!type_arguments.IsNull() && |
| 7630 !type_arguments.IsInstantiated() && | 7611 !type_arguments.IsInstantiated() && |
| 7631 (current_block_->scope->function_level() > 0)) { | 7612 (current_block_->scope->function_level() > 0)) { |
| 7632 // Make sure that the instantiator is captured. | 7613 // Make sure that the instantiator is captured. |
| 7633 CaptureReceiver(); | 7614 CaptureReceiver(); |
| 7634 } | 7615 } |
| 7635 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7616 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7735 } | 7716 } |
| 7736 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 7717 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
| 7737 map_type_arguments ^= map_type_arguments.Canonicalize(); | 7718 map_type_arguments ^= map_type_arguments.Canonicalize(); |
| 7738 | 7719 |
| 7739 // Parse the map entries. Note: there may be an optional extra | 7720 // Parse the map entries. Note: there may be an optional extra |
| 7740 // comma after the last entry. | 7721 // comma after the last entry. |
| 7741 // The kv_pair array is temporary and of element type Dynamic. It is passed | 7722 // The kv_pair array is temporary and of element type Dynamic. It is passed |
| 7742 // to the factory to initialize a properly typed map. | 7723 // to the factory to initialize a properly typed map. |
| 7743 ArrayNode* kv_pairs = | 7724 ArrayNode* kv_pairs = |
| 7744 new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); | 7725 new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); |
| 7745 const String& dst_name = String::ZoneHandle( | 7726 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); |
| 7746 Symbols::New("list literal element")); | |
| 7747 while (CurrentToken() != Token::kRBRACE) { | 7727 while (CurrentToken() != Token::kRBRACE) { |
| 7748 AstNode* key = NULL; | 7728 AstNode* key = NULL; |
| 7749 if (CurrentToken() == Token::kSTRING) { | 7729 if (CurrentToken() == Token::kSTRING) { |
| 7750 key = ParseStringLiteral(); | 7730 key = ParseStringLiteral(); |
| 7751 } | 7731 } |
| 7752 if (key == NULL) { | 7732 if (key == NULL) { |
| 7753 ErrorMsg("map entry key must be string literal"); | 7733 ErrorMsg("map entry key must be string literal"); |
| 7754 } else if (is_const && !key->IsLiteralNode()) { | 7734 } else if (is_const && !key->IsLiteralNode()) { |
| 7755 ErrorMsg("map entry key must be compile time constant string"); | 7735 ErrorMsg("map entry key must be compile time constant string"); |
| 7756 } | 7736 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7808 String::Handle(value_type.UserVisibleName()).ToCString()); | 7788 String::Handle(value_type.UserVisibleName()).ToCString()); |
| 7809 } | 7789 } |
| 7810 } | 7790 } |
| 7811 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); | 7791 key_value_array.SetAt(i, arg->AsLiteralNode()->literal()); |
| 7812 } | 7792 } |
| 7813 key_value_array ^= key_value_array.Canonicalize(); | 7793 key_value_array ^= key_value_array.Canonicalize(); |
| 7814 key_value_array.MakeImmutable(); | 7794 key_value_array.MakeImmutable(); |
| 7815 | 7795 |
| 7816 // Construct the map object. | 7796 // Construct the map object. |
| 7817 const String& immutable_map_class_name = | 7797 const String& immutable_map_class_name = |
| 7818 String::Handle(Symbols::New(kImmutableMapName)); | 7798 String::Handle(Symbols::ImmutableMap()); |
| 7819 const Class& immutable_map_class = | 7799 const Class& immutable_map_class = |
| 7820 Class::Handle(LookupImplClass(immutable_map_class_name)); | 7800 Class::Handle(LookupImplClass(immutable_map_class_name)); |
| 7821 ASSERT(!immutable_map_class.IsNull()); | 7801 ASSERT(!immutable_map_class.IsNull()); |
| 7822 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); | 7802 ArgumentListNode* constr_args = new ArgumentListNode(TokenPos()); |
| 7823 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); | 7803 constr_args->Add(new LiteralNode(literal_pos, key_value_array)); |
| 7824 const String& constr_name = | 7804 const String& constr_name = |
| 7825 String::Handle(Symbols::New(kImmutableMapConstructorName)); | 7805 String::Handle(Symbols::ImmutableMapConstructor()); |
| 7826 const Function& map_constr = Function::ZoneHandle( | 7806 const Function& map_constr = Function::ZoneHandle( |
| 7827 immutable_map_class.LookupConstructor(constr_name)); | 7807 immutable_map_class.LookupConstructor(constr_name)); |
| 7828 ASSERT(!map_constr.IsNull()); | 7808 ASSERT(!map_constr.IsNull()); |
| 7829 const Object& constructor_result = Object::Handle( | 7809 const Object& constructor_result = Object::Handle( |
| 7830 EvaluateConstConstructorCall(immutable_map_class, | 7810 EvaluateConstConstructorCall(immutable_map_class, |
| 7831 map_type_arguments, | 7811 map_type_arguments, |
| 7832 map_constr, | 7812 map_constr, |
| 7833 constr_args)); | 7813 constr_args)); |
| 7834 if (constructor_result.IsUnhandledException()) { | 7814 if (constructor_result.IsUnhandledException()) { |
| 7835 return GenerateRethrow(literal_pos, constructor_result); | 7815 return GenerateRethrow(literal_pos, constructor_result); |
| 7836 } else { | 7816 } else { |
| 7837 const Instance& const_instance = Instance::Cast(constructor_result); | 7817 const Instance& const_instance = Instance::Cast(constructor_result); |
| 7838 return new LiteralNode(literal_pos, | 7818 return new LiteralNode(literal_pos, |
| 7839 Instance::ZoneHandle(const_instance.raw())); | 7819 Instance::ZoneHandle(const_instance.raw())); |
| 7840 } | 7820 } |
| 7841 } else { | 7821 } else { |
| 7842 // Factory call at runtime. | 7822 // Factory call at runtime. |
| 7843 String& map_literal_factory_class_name = String::Handle( | 7823 String& map_literal_factory_class_name = String::Handle( |
| 7844 Symbols::New(kMapLiteralFactoryClassName)); | 7824 Symbols::MapLiteralFactoryClass()); |
| 7845 const Class& map_literal_factory_class = | 7825 const Class& map_literal_factory_class = |
| 7846 Class::Handle(LookupCoreClass(map_literal_factory_class_name)); | 7826 Class::Handle(LookupCoreClass(map_literal_factory_class_name)); |
| 7847 ASSERT(!map_literal_factory_class.IsNull()); | 7827 ASSERT(!map_literal_factory_class.IsNull()); |
| 7848 const String& map_literal_factory_name = | 7828 const String& map_literal_factory_name = |
| 7849 String::Handle(Symbols::New(kMapLiteralFactoryName)); | 7829 String::Handle(Symbols::MapLiteralFactory()); |
| 7850 const Function& map_literal_factory = Function::ZoneHandle( | 7830 const Function& map_literal_factory = Function::ZoneHandle( |
| 7851 map_literal_factory_class.LookupFactory(map_literal_factory_name)); | 7831 map_literal_factory_class.LookupFactory(map_literal_factory_name)); |
| 7852 ASSERT(!map_literal_factory.IsNull()); | 7832 ASSERT(!map_literal_factory.IsNull()); |
| 7853 if (!map_type_arguments.IsNull() && | 7833 if (!map_type_arguments.IsNull() && |
| 7854 !map_type_arguments.IsInstantiated() && | 7834 !map_type_arguments.IsInstantiated() && |
| 7855 (current_block_->scope->function_level() > 0)) { | 7835 (current_block_->scope->function_level() > 0)) { |
| 7856 // Make sure that the instantiator is captured. | 7836 // Make sure that the instantiator is captured. |
| 7857 CaptureReceiver(); | 7837 CaptureReceiver(); |
| 7858 } | 7838 } |
| 7859 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7839 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8139 // If the type argument vector is not instantiated, we verify in checked | 8119 // If the type argument vector is not instantiated, we verify in checked |
| 8140 // mode at runtime that it is within its declared bounds. | 8120 // mode at runtime that it is within its declared bounds. |
| 8141 new_object = CreateConstructorCallNode( | 8121 new_object = CreateConstructorCallNode( |
| 8142 new_pos, type_arguments, constructor, arguments); | 8122 new_pos, type_arguments, constructor, arguments); |
| 8143 } | 8123 } |
| 8144 return new_object; | 8124 return new_object; |
| 8145 } | 8125 } |
| 8146 | 8126 |
| 8147 | 8127 |
| 8148 String& Parser::Interpolate(ArrayNode* values) { | 8128 String& Parser::Interpolate(ArrayNode* values) { |
| 8149 const String& class_name = | 8129 const String& class_name = String::Handle(Symbols::StringBase()); |
| 8150 String::Handle(Symbols::New(kStringClassName)); | |
| 8151 const Class& cls = Class::Handle(LookupImplClass(class_name)); | 8130 const Class& cls = Class::Handle(LookupImplClass(class_name)); |
| 8152 ASSERT(!cls.IsNull()); | 8131 ASSERT(!cls.IsNull()); |
| 8153 const String& func_name = String::Handle(Symbols::New(kInterpolateName)); | 8132 const String& func_name = String::Handle(Symbols::Interpolate()); |
| 8154 const Function& func = | 8133 const Function& func = |
| 8155 Function::Handle(cls.LookupStaticFunction(func_name)); | 8134 Function::Handle(cls.LookupStaticFunction(func_name)); |
| 8156 ASSERT(!func.IsNull()); | 8135 ASSERT(!func.IsNull()); |
| 8157 | 8136 |
| 8158 // Build the array of literal values to interpolate. | 8137 // Build the array of literal values to interpolate. |
| 8159 const Array& value_arr = Array::Handle(Array::New(values->length())); | 8138 const Array& value_arr = Array::Handle(Array::New(values->length())); |
| 8160 for (int i = 0; i < values->length(); i++) { | 8139 for (int i = 0; i < values->length(); i++) { |
| 8161 ASSERT(values->ElementAt(i)->IsLiteralNode()); | 8140 ASSERT(values->ElementAt(i)->IsLiteralNode()); |
| 8162 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); | 8141 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); |
| 8163 } | 8142 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8233 } | 8212 } |
| 8234 values->AddElement(expr); | 8213 values->AddElement(expr); |
| 8235 } | 8214 } |
| 8236 } | 8215 } |
| 8237 if (is_compiletime_const) { | 8216 if (is_compiletime_const) { |
| 8238 primary = new LiteralNode(literal_start, Interpolate(values)); | 8217 primary = new LiteralNode(literal_start, Interpolate(values)); |
| 8239 } else { | 8218 } else { |
| 8240 ArgumentListNode* interpolate_arg = | 8219 ArgumentListNode* interpolate_arg = |
| 8241 new ArgumentListNode(values->token_pos()); | 8220 new ArgumentListNode(values->token_pos()); |
| 8242 interpolate_arg->Add(values); | 8221 interpolate_arg->Add(values); |
| 8243 primary = MakeStaticCall(kStringClassName, | 8222 const String& cls_name = String::Handle(Symbols::StringBase()); |
| 8244 kInterpolateName, | 8223 const String& func_name = String::Handle(Symbols::Interpolate()); |
| 8245 interpolate_arg); | 8224 primary = MakeStaticCall(cls_name, func_name, interpolate_arg); |
| 8246 } | 8225 } |
| 8247 return primary; | 8226 return primary; |
| 8248 } | 8227 } |
| 8249 | 8228 |
| 8250 | 8229 |
| 8251 // An import string literal consists of the concatenation of the next n tokens | 8230 // An import string literal consists of the concatenation of the next n tokens |
| 8252 // that satisfy the EBNF grammar: | 8231 // that satisfy the EBNF grammar: |
| 8253 // literal = kSTRING {{ interpol }+ kSTRING } | 8232 // literal = kSTRING {{ interpol }+ kSTRING } |
| 8254 // interpol = kINTERPOL_VAR | 8233 // interpol = kINTERPOL_VAR |
| 8255 // In other words, the scanner breaks down interpolated strings so that | 8234 // In other words, the scanner breaks down interpolated strings so that |
| 8256 // a string literal always begins and ends with a kSTRING token, and | 8235 // a string literal always begins and ends with a kSTRING token, and |
| 8257 // there are never two kSTRING tokens next to each other. | 8236 // there are never two kSTRING tokens next to each other. |
| 8258 String* Parser::ParseImportStringLiteral() { | 8237 String* Parser::ParseImportStringLiteral() { |
| 8259 TRACE_PARSER("ParseImportStringLiteral"); | 8238 TRACE_PARSER("ParseImportStringLiteral"); |
| 8260 if ((CurrentToken() == Token::kSTRING) && | 8239 if ((CurrentToken() == Token::kSTRING) && |
| 8261 (LookaheadToken(1) != Token::kINTERPOL_VAR) && | 8240 (LookaheadToken(1) != Token::kINTERPOL_VAR) && |
| 8262 (LookaheadToken(1) != Token::kINTERPOL_START)) { | 8241 (LookaheadToken(1) != Token::kINTERPOL_START)) { |
| 8263 // Common case: no interpolation. | 8242 // Common case: no interpolation. |
| 8264 String* result = CurrentLiteral(); | 8243 String* result = CurrentLiteral(); |
| 8265 ConsumeToken(); | 8244 ConsumeToken(); |
| 8266 return result; | 8245 return result; |
| 8267 } | 8246 } |
| 8268 // String interpolation needed. | 8247 // String interpolation needed. |
| 8269 String& result = String::ZoneHandle(String::New("")); | 8248 String& result = String::ZoneHandle(Symbols::Empty()); |
| 8270 String& resolved_name = String::Handle(); | 8249 String& resolved_name = String::Handle(); |
| 8271 while (CurrentToken() == Token::kSTRING) { | 8250 while (CurrentToken() == Token::kSTRING) { |
| 8272 result = String::Concat(result, *CurrentLiteral()); | 8251 result = String::Concat(result, *CurrentLiteral()); |
| 8273 ConsumeToken(); | 8252 ConsumeToken(); |
| 8274 if ((CurrentToken() != Token::kINTERPOL_VAR) && | 8253 if ((CurrentToken() != Token::kINTERPOL_VAR) && |
| 8275 (CurrentToken() != Token::kINTERPOL_START)) { | 8254 (CurrentToken() != Token::kINTERPOL_START)) { |
| 8276 break; | 8255 break; |
| 8277 } | 8256 } |
| 8278 while ((CurrentToken() == Token::kINTERPOL_VAR) || | 8257 while ((CurrentToken() == Token::kINTERPOL_VAR) || |
| 8279 (CurrentToken() == Token::kINTERPOL_START)) { | 8258 (CurrentToken() == Token::kINTERPOL_START)) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8344 } | 8323 } |
| 8345 } else { | 8324 } else { |
| 8346 // This is a qualified identifier with a library prefix so resolve | 8325 // This is a qualified identifier with a library prefix so resolve |
| 8347 // the identifier locally in that library (we do not include the | 8326 // the identifier locally in that library (we do not include the |
| 8348 // libraries imported by that library). | 8327 // libraries imported by that library). |
| 8349 primary = ResolveIdentInLibraryPrefixScope(*(qual_ident.lib_prefix), | 8328 primary = ResolveIdentInLibraryPrefixScope(*(qual_ident.lib_prefix), |
| 8350 qual_ident); | 8329 qual_ident); |
| 8351 } | 8330 } |
| 8352 ASSERT(primary != NULL); | 8331 ASSERT(primary != NULL); |
| 8353 } else if (CurrentToken() == Token::kTHIS) { | 8332 } else if (CurrentToken() == Token::kTHIS) { |
| 8354 const String& this_name = String::Handle(Symbols::New(kThisName)); | 8333 const String& this_name = String::Handle(Symbols::This()); |
| 8355 LocalVariable* local = LookupLocalScope(this_name); | 8334 LocalVariable* local = LookupLocalScope(this_name); |
| 8356 if (local == NULL) { | 8335 if (local == NULL) { |
| 8357 ErrorMsg("receiver 'this' is not in scope"); | 8336 ErrorMsg("receiver 'this' is not in scope"); |
| 8358 } | 8337 } |
| 8359 primary = new LoadLocalNode(TokenPos(), *local); | 8338 primary = new LoadLocalNode(TokenPos(), *local); |
| 8360 ConsumeToken(); | 8339 ConsumeToken(); |
| 8361 } else if (CurrentToken() == Token::kINTEGER) { | 8340 } else if (CurrentToken() == Token::kINTEGER) { |
| 8362 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); | 8341 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
| 8363 primary = new LiteralNode(TokenPos(), literal); | 8342 primary = new LiteralNode(TokenPos(), literal); |
| 8364 ConsumeToken(); | 8343 ConsumeToken(); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8705 void Parser::SkipQualIdent() { | 8684 void Parser::SkipQualIdent() { |
| 8706 ASSERT(IsIdentifier()); | 8685 ASSERT(IsIdentifier()); |
| 8707 ConsumeToken(); | 8686 ConsumeToken(); |
| 8708 if (CurrentToken() == Token::kPERIOD) { | 8687 if (CurrentToken() == Token::kPERIOD) { |
| 8709 ConsumeToken(); // Consume the kPERIOD token. | 8688 ConsumeToken(); // Consume the kPERIOD token. |
| 8710 ExpectIdentifier("identifier expected after '.'"); | 8689 ExpectIdentifier("identifier expected after '.'"); |
| 8711 } | 8690 } |
| 8712 } | 8691 } |
| 8713 | 8692 |
| 8714 } // namespace dart | 8693 } // namespace dart |
| OLD | NEW |