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

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

Issue 302703005: - Add isolate to ZoneHandle allocation in parser. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/globals.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 402
403 Token::Kind Parser::LookaheadToken(int num_tokens) { 403 Token::Kind Parser::LookaheadToken(int num_tokens) {
404 CompilerStats::num_tokens_lookahead++; 404 CompilerStats::num_tokens_lookahead++;
405 CompilerStats::num_token_checks++; 405 CompilerStats::num_token_checks++;
406 return tokens_iterator_.LookaheadTokenKind(num_tokens); 406 return tokens_iterator_.LookaheadTokenKind(num_tokens);
407 } 407 }
408 408
409 409
410 String* Parser::CurrentLiteral() const { 410 String* Parser::CurrentLiteral() const {
411 String& result = 411 String& result =
412 String::ZoneHandle(isolate_, tokens_iterator_.CurrentLiteral()); 412 String::ZoneHandle(I, tokens_iterator_.CurrentLiteral());
413 return &result; 413 return &result;
414 } 414 }
415 415
416 416
417 RawDouble* Parser::CurrentDoubleLiteral() const { 417 RawDouble* Parser::CurrentDoubleLiteral() const {
418 literal_token_ ^= tokens_iterator_.CurrentToken(); 418 literal_token_ ^= tokens_iterator_.CurrentToken();
419 ASSERT(literal_token_.kind() == Token::kDOUBLE); 419 ASSERT(literal_token_.kind() == Token::kDOUBLE);
420 return Double::RawCast(literal_token_.value()); 420 return Double::RawCast(literal_token_.value());
421 } 421 }
422 422
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 RawObject* Parser::ParseFunctionParameters(const Function& func) { 744 RawObject* Parser::ParseFunctionParameters(const Function& func) {
745 ASSERT(!func.IsNull()); 745 ASSERT(!func.IsNull());
746 Isolate* isolate = Isolate::Current(); 746 Isolate* isolate = Isolate::Current();
747 StackZone zone(isolate); 747 StackZone zone(isolate);
748 LongJumpScope jump; 748 LongJumpScope jump;
749 if (setjmp(*jump.Set()) == 0) { 749 if (setjmp(*jump.Set()) == 0) {
750 const Script& script = Script::Handle(isolate, func.script()); 750 const Script& script = Script::Handle(isolate, func.script());
751 const Class& owner = Class::Handle(isolate, func.Owner()); 751 const Class& owner = Class::Handle(isolate, func.Owner());
752 ASSERT(!owner.IsNull()); 752 ASSERT(!owner.IsNull());
753 ParsedFunction* parsed_function = new ParsedFunction( 753 ParsedFunction* parsed_function = new ParsedFunction(
754 Function::ZoneHandle(func.raw())); 754 Function::ZoneHandle(isolate, func.raw()));
755 Parser parser(script, parsed_function, func.token_pos()); 755 Parser parser(script, parsed_function, func.token_pos());
756 parser.SkipFunctionPreamble(); 756 parser.SkipFunctionPreamble();
757 ParamList params; 757 ParamList params;
758 parser.ParseFormalParameterList(true, true, &params); 758 parser.ParseFormalParameterList(true, true, &params);
759 ParamDesc* param = params.parameters->data(); 759 ParamDesc* param = params.parameters->data();
760 const int param_cnt = params.num_fixed_parameters + 760 const int param_cnt = params.num_fixed_parameters +
761 params.num_optional_parameters; 761 params.num_optional_parameters;
762 const Array& param_descriptor = 762 const Array& param_descriptor =
763 Array::Handle(Array::New(param_cnt * kParameterEntrySize)); 763 Array::Handle(Array::New(param_cnt * kParameterEntrySize));
764 for (int i = 0, j = 0; i < param_cnt; i++, j += kParameterEntrySize) { 764 for (int i = 0, j = 0; i < param_cnt; i++, j += kParameterEntrySize) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); 987 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved());
988 988
989 // Build local scope for function and populate with the formal parameters. 989 // Build local scope for function and populate with the formal parameters.
990 OpenFunctionBlock(func); 990 OpenFunctionBlock(func);
991 AddFormalParamsToScope(&params, current_block_->scope); 991 AddFormalParamsToScope(&params, current_block_->scope);
992 992
993 intptr_t ident_pos = TokenPos(); 993 intptr_t ident_pos = TokenPos();
994 const String& field_name = *ExpectIdentifier("field name expected"); 994 const String& field_name = *ExpectIdentifier("field name expected");
995 const Class& field_class = Class::Handle(isolate(), func.Owner()); 995 const Class& field_class = Class::Handle(isolate(), func.Owner());
996 const Field& field = 996 const Field& field =
997 Field::ZoneHandle(field_class.LookupStaticField(field_name)); 997 Field::ZoneHandle(I, field_class.LookupStaticField(field_name));
998 998
999 // Static final fields must have an initializer. 999 // Static final fields must have an initializer.
1000 ExpectToken(Token::kASSIGN); 1000 ExpectToken(Token::kASSIGN);
1001 1001
1002 const intptr_t expr_pos = TokenPos(); 1002 const intptr_t expr_pos = TokenPos();
1003 if (field.is_const()) { 1003 if (field.is_const()) {
1004 // We don't want to use ParseConstExpr() here because we don't want 1004 // We don't want to use ParseConstExpr() here because we don't want
1005 // the constant folding code to create, compile and execute a code 1005 // the constant folding code to create, compile and execute a code
1006 // fragment to evaluate the expression. Instead, we just make sure 1006 // fragment to evaluate the expression. Instead, we just make sure
1007 // the static const field initializer is a constant expression and 1007 // the static const field initializer is a constant expression and
(...skipping 25 matching lines...) Expand all
1033 new LoadStaticFieldNode(ident_pos, field), 1033 new LoadStaticFieldNode(ident_pos, field),
1034 new LiteralNode(ident_pos, Object::transition_sentinel())); 1034 new LiteralNode(ident_pos, Object::transition_sentinel()));
1035 // Set field to null prior to throwing exception, so that subsequent 1035 // Set field to null prior to throwing exception, so that subsequent
1036 // accesses to the field do not throw again, since initializers should only 1036 // accesses to the field do not throw again, since initializers should only
1037 // be executed once. 1037 // be executed once.
1038 SequenceNode* report_circular = new SequenceNode(ident_pos, NULL); 1038 SequenceNode* report_circular = new SequenceNode(ident_pos, NULL);
1039 report_circular->Add( 1039 report_circular->Add(
1040 new StoreStaticFieldNode( 1040 new StoreStaticFieldNode(
1041 ident_pos, 1041 ident_pos,
1042 field, 1042 field,
1043 new LiteralNode(ident_pos, Instance::ZoneHandle()))); 1043 new LiteralNode(ident_pos, Instance::ZoneHandle(I))));
1044 // Call CyclicInitializationError._throwNew(field_name). 1044 // Call CyclicInitializationError._throwNew(field_name).
1045 ArgumentListNode* error_arguments = new ArgumentListNode(ident_pos); 1045 ArgumentListNode* error_arguments = new ArgumentListNode(ident_pos);
1046 error_arguments->Add(new LiteralNode(ident_pos, field_name)); 1046 error_arguments->Add(new LiteralNode(ident_pos, field_name));
1047 report_circular->Add( 1047 report_circular->Add(
1048 MakeStaticCall(Symbols::CyclicInitializationError(), 1048 MakeStaticCall(Symbols::CyclicInitializationError(),
1049 Library::PrivateCoreLibName(Symbols::ThrowNew()), 1049 Library::PrivateCoreLibName(Symbols::ThrowNew()),
1050 error_arguments)); 1050 error_arguments));
1051 AstNode* circular_check = 1051 AstNode* circular_check =
1052 new IfNode(ident_pos, compare_circular, report_circular, NULL); 1052 new IfNode(ident_pos, compare_circular, report_circular, NULL);
1053 current_block_->statements->Add(circular_check); 1053 current_block_->statements->Add(circular_check);
1054 1054
1055 // Generate code checking for uninitialized field. 1055 // Generate code checking for uninitialized field.
1056 AstNode* compare_uninitialized = new ComparisonNode( 1056 AstNode* compare_uninitialized = new ComparisonNode(
1057 ident_pos, 1057 ident_pos,
1058 Token::kEQ_STRICT, 1058 Token::kEQ_STRICT,
1059 new LoadStaticFieldNode(ident_pos, field), 1059 new LoadStaticFieldNode(ident_pos, field),
1060 new LiteralNode(ident_pos, Object::sentinel())); 1060 new LiteralNode(ident_pos, Object::sentinel()));
1061 SequenceNode* initialize_field = new SequenceNode(ident_pos, NULL); 1061 SequenceNode* initialize_field = new SequenceNode(ident_pos, NULL);
1062 initialize_field->Add( 1062 initialize_field->Add(
1063 new StoreStaticFieldNode( 1063 new StoreStaticFieldNode(
1064 ident_pos, 1064 ident_pos,
1065 field, 1065 field,
1066 new LiteralNode(ident_pos, Object::transition_sentinel()))); 1066 new LiteralNode(ident_pos, Object::transition_sentinel())));
1067 const String& init_name = String::Handle(isolate(), Symbols::New( 1067 const String& init_name = String::Handle(isolate(), Symbols::New(
1068 String::Handle(isolate(), String::Concat( 1068 String::Handle(isolate(), String::Concat(
1069 Symbols::InitPrefix(), String::Handle(isolate(), field.name()))))); 1069 Symbols::InitPrefix(), String::Handle(isolate(), field.name())))));
1070 const Function& init_function = Function::ZoneHandle( 1070 const Function& init_function = Function::ZoneHandle(I,
1071 field_class.LookupStaticFunction(init_name)); 1071 field_class.LookupStaticFunction(init_name));
1072 ASSERT(!init_function.IsNull()); 1072 ASSERT(!init_function.IsNull());
1073 ArgumentListNode* arguments = new ArgumentListNode(expr_pos); 1073 ArgumentListNode* arguments = new ArgumentListNode(expr_pos);
1074 StaticCallNode* init_call = 1074 StaticCallNode* init_call =
1075 new StaticCallNode(expr_pos, init_function, arguments); 1075 new StaticCallNode(expr_pos, init_function, arguments);
1076 initialize_field->Add(init_call); 1076 initialize_field->Add(init_call);
1077 1077
1078 AstNode* uninitialized_check = 1078 AstNode* uninitialized_check =
1079 new IfNode(ident_pos, compare_uninitialized, initialize_field, NULL); 1079 new IfNode(ident_pos, compare_uninitialized, initialize_field, NULL);
1080 current_block_->statements->Add(uninitialized_check); 1080 current_block_->statements->Add(uninitialized_check);
(...skipping 24 matching lines...) Expand all
1105 ExpectIdentifier("identifier expected"); 1105 ExpectIdentifier("identifier expected");
1106 ExpectToken(Token::kASSIGN); 1106 ExpectToken(Token::kASSIGN);
1107 intptr_t token_pos = TokenPos(); 1107 intptr_t token_pos = TokenPos();
1108 1108
1109 // Synthesize a try-catch block to wrap the initializer expression. 1109 // Synthesize a try-catch block to wrap the initializer expression.
1110 LocalVariable* context_var = 1110 LocalVariable* context_var =
1111 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); 1111 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar());
1112 if (context_var == NULL) { 1112 if (context_var == NULL) {
1113 context_var = new LocalVariable(token_pos, 1113 context_var = new LocalVariable(token_pos,
1114 Symbols::SavedTryContextVar(), 1114 Symbols::SavedTryContextVar(),
1115 Type::ZoneHandle(Type::DynamicType())); 1115 Type::ZoneHandle(I, Type::DynamicType()));
1116 current_block_->scope->AddVariable(context_var); 1116 current_block_->scope->AddVariable(context_var);
1117 } 1117 }
1118 LocalVariable* catch_excp_var = 1118 LocalVariable* catch_excp_var =
1119 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); 1119 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar());
1120 if (catch_excp_var == NULL) { 1120 if (catch_excp_var == NULL) {
1121 catch_excp_var = new LocalVariable(token_pos, 1121 catch_excp_var = new LocalVariable(
1122 Symbols::ExceptionVar(), 1122 token_pos,
1123 Type::ZoneHandle(Type::DynamicType())); 1123 Symbols::ExceptionVar(),
1124 Type::ZoneHandle(I, Type::DynamicType()));
1124 current_block_->scope->AddVariable(catch_excp_var); 1125 current_block_->scope->AddVariable(catch_excp_var);
1125 } 1126 }
1126 LocalVariable* catch_trace_var = 1127 LocalVariable* catch_trace_var =
1127 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar()); 1128 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar());
1128 if (catch_trace_var == NULL) { 1129 if (catch_trace_var == NULL) {
1129 catch_trace_var = new LocalVariable(token_pos, 1130 catch_trace_var = new LocalVariable(
1130 Symbols::StackTraceVar(), 1131 token_pos,
1131 Type::ZoneHandle(Type::DynamicType())); 1132 Symbols::StackTraceVar(),
1133 Type::ZoneHandle(I, Type::DynamicType()));
1132 current_block_->scope->AddVariable(catch_trace_var); 1134 current_block_->scope->AddVariable(catch_trace_var);
1133 } 1135 }
1134 1136
1135 OpenBlock(); // Start try block. 1137 OpenBlock(); // Start try block.
1136 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); 1138 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades);
1137 const Field& field = Field::ZoneHandle(func.saved_static_field()); 1139 const Field& field = Field::ZoneHandle(I, func.saved_static_field());
1138 ASSERT(!field.is_const()); 1140 ASSERT(!field.is_const());
1139 StoreStaticFieldNode* store = new StoreStaticFieldNode(field.token_pos(), 1141 StoreStaticFieldNode* store = new StoreStaticFieldNode(field.token_pos(),
1140 field, 1142 field,
1141 expr); 1143 expr);
1142 current_block_->statements->Add(store); 1144 current_block_->statements->Add(store);
1143 SequenceNode* try_block = CloseBlock(); // End try block. 1145 SequenceNode* try_block = CloseBlock(); // End try block.
1144 1146
1145 OpenBlock(); // Start catch handler list. 1147 OpenBlock(); // Start catch handler list.
1146 OpenBlock(); // Start catch clause. 1148 OpenBlock(); // Start catch clause.
1147 AstNode* compare_transition_sentinel = new ComparisonNode( 1149 AstNode* compare_transition_sentinel = new ComparisonNode(
1148 token_pos, 1150 token_pos,
1149 Token::kEQ_STRICT, 1151 Token::kEQ_STRICT,
1150 new LoadStaticFieldNode(ident_pos, field), 1152 new LoadStaticFieldNode(ident_pos, field),
1151 new LiteralNode(field.token_pos(), Object::transition_sentinel())); 1153 new LiteralNode(field.token_pos(), Object::transition_sentinel()));
1152 1154
1153 SequenceNode* store_null = new SequenceNode(token_pos, NULL); 1155 SequenceNode* store_null = new SequenceNode(token_pos, NULL);
1154 store_null->Add(new StoreStaticFieldNode( 1156 store_null->Add(new StoreStaticFieldNode(
1155 field.token_pos(), 1157 field.token_pos(),
1156 field, 1158 field,
1157 new LiteralNode(token_pos, Instance::ZoneHandle()))); 1159 new LiteralNode(token_pos, Instance::ZoneHandle(I))));
1158 AstNode* transition_sentinel_check = 1160 AstNode* transition_sentinel_check =
1159 new IfNode(token_pos, compare_transition_sentinel, store_null, NULL); 1161 new IfNode(token_pos, compare_transition_sentinel, store_null, NULL);
1160 current_block_->statements->Add(transition_sentinel_check); 1162 current_block_->statements->Add(transition_sentinel_check);
1161 1163
1162 current_block_->statements->Add( 1164 current_block_->statements->Add(
1163 new ThrowNode(token_pos, 1165 new ThrowNode(token_pos,
1164 new LoadLocalNode(token_pos, catch_excp_var), 1166 new LoadLocalNode(token_pos, catch_excp_var),
1165 new LoadLocalNode(token_pos, catch_trace_var))); 1167 new LoadLocalNode(token_pos, catch_trace_var)));
1166 SequenceNode* catch_clause = CloseBlock(); // End catch clause. 1168 SequenceNode* catch_clause = CloseBlock(); // End catch clause.
1167 1169
1168 current_block_->statements->Add(catch_clause); 1170 current_block_->statements->Add(catch_clause);
1169 SequenceNode* catch_handler_list = CloseBlock(); // End catch handler list. 1171 SequenceNode* catch_handler_list = CloseBlock(); // End catch handler list.
1170 CatchClauseNode* catch_block = 1172 CatchClauseNode* catch_block =
1171 new CatchClauseNode(token_pos, 1173 new CatchClauseNode(token_pos,
1172 catch_handler_list, 1174 catch_handler_list,
1173 Array::ZoneHandle(Object::empty_array().raw()), 1175 Array::ZoneHandle(I, Object::empty_array().raw()),
1174 context_var, 1176 context_var,
1175 catch_excp_var, 1177 catch_excp_var,
1176 catch_trace_var, 1178 catch_trace_var,
1177 CatchClauseNode::kInvalidTryIndex, 1179 CatchClauseNode::kInvalidTryIndex,
1178 false); // No stack trace needed. 1180 false); // No stack trace needed.
1179 1181
1180 AstNode* try_catch_node = new TryCatchNode(token_pos, 1182 AstNode* try_catch_node = new TryCatchNode(token_pos,
1181 try_block, 1183 try_block,
1182 context_var, 1184 context_var,
1183 catch_block, 1185 catch_block,
(...skipping 23 matching lines...) Expand all
1207 OpenFunctionBlock(func); 1209 OpenFunctionBlock(func);
1208 AddFormalParamsToScope(&params, current_block_->scope); 1210 AddFormalParamsToScope(&params, current_block_->scope);
1209 1211
1210 // Receiver is local 0. 1212 // Receiver is local 0.
1211 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1213 LocalVariable* receiver = current_block_->scope->VariableAt(0);
1212 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); 1214 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver);
1213 ASSERT(IsIdentifier()); 1215 ASSERT(IsIdentifier());
1214 const String& field_name = *CurrentLiteral(); 1216 const String& field_name = *CurrentLiteral();
1215 const Class& field_class = Class::Handle(isolate(), func.Owner()); 1217 const Class& field_class = Class::Handle(isolate(), func.Owner());
1216 const Field& field = 1218 const Field& field =
1217 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); 1219 Field::ZoneHandle(I, field_class.LookupInstanceField(field_name));
1218 1220
1219 LoadInstanceFieldNode* load_field = 1221 LoadInstanceFieldNode* load_field =
1220 new LoadInstanceFieldNode(ident_pos, load_receiver, field); 1222 new LoadInstanceFieldNode(ident_pos, load_receiver, field);
1221 1223
1222 ReturnNode* return_node = 1224 ReturnNode* return_node =
1223 new ReturnNode(Scanner::kNoSourcePos, load_field); 1225 new ReturnNode(Scanner::kNoSourcePos, load_field);
1224 current_block_->statements->Add(return_node); 1226 current_block_->statements->Add(return_node);
1225 return CloseBlock(); 1227 return CloseBlock();
1226 } 1228 }
1227 1229
1228 1230
1229 // Create AstNodes for an implicit instance setter method: 1231 // Create AstNodes for an implicit instance setter method:
1230 // LoadLocalNode 0 ('this') 1232 // LoadLocalNode 0 ('this')
1231 // LoadLocalNode 1 ('value') 1233 // LoadLocalNode 1 ('value')
1232 // SetInstanceField (field_name); 1234 // SetInstanceField (field_name);
1233 // ReturnNode (void); 1235 // ReturnNode (void);
1234 SequenceNode* Parser::ParseInstanceSetter(const Function& func) { 1236 SequenceNode* Parser::ParseInstanceSetter(const Function& func) {
1235 TRACE_PARSER("ParseInstanceSetter"); 1237 TRACE_PARSER("ParseInstanceSetter");
1236 // func.token_pos() points to the name of the field. 1238 // func.token_pos() points to the name of the field.
1237 const intptr_t ident_pos = func.token_pos(); 1239 const intptr_t ident_pos = func.token_pos();
1238 const String& field_name = *CurrentLiteral(); 1240 const String& field_name = *CurrentLiteral();
1239 const Class& field_class = Class::ZoneHandle(func.Owner()); 1241 const Class& field_class = Class::ZoneHandle(I, func.Owner());
1240 const Field& field = 1242 const Field& field =
1241 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); 1243 Field::ZoneHandle(I, field_class.LookupInstanceField(field_name));
1242 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); 1244 const AbstractType& field_type = AbstractType::ZoneHandle(I, field.type());
1243 1245
1244 ParamList params; 1246 ParamList params;
1245 ASSERT(current_class().raw() == func.Owner()); 1247 ASSERT(current_class().raw() == func.Owner());
1246 params.AddReceiver(ReceiverType(current_class()), ident_pos); 1248 params.AddReceiver(ReceiverType(current_class()), ident_pos);
1247 params.AddFinalParameter(ident_pos, 1249 params.AddFinalParameter(ident_pos,
1248 &Symbols::Value(), 1250 &Symbols::Value(),
1249 &field_type); 1251 &field_type);
1250 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. 1252 ASSERT(func.num_fixed_parameters() == 2); // receiver, value.
1251 ASSERT(!func.HasOptionalParameters()); 1253 ASSERT(!func.HasOptionalParameters());
1252 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsVoidType()); 1254 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsVoidType());
(...skipping 30 matching lines...) Expand all
1283 // Build local scope for function and populate with the formal parameters. 1285 // Build local scope for function and populate with the formal parameters.
1284 OpenFunctionBlock(func); 1286 OpenFunctionBlock(func);
1285 AddFormalParamsToScope(&params, current_block_->scope); 1287 AddFormalParamsToScope(&params, current_block_->scope);
1286 1288
1287 // Receiver is local 0. 1289 // Receiver is local 0.
1288 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1290 LocalVariable* receiver = current_block_->scope->VariableAt(0);
1289 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); 1291 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver);
1290 1292
1291 ClosureNode* closure = new ClosureNode( 1293 ClosureNode* closure = new ClosureNode(
1292 ident_pos, 1294 ident_pos,
1293 Function::ZoneHandle(func.extracted_method_closure()), 1295 Function::ZoneHandle(I, func.extracted_method_closure()),
1294 load_receiver, 1296 load_receiver,
1295 NULL); 1297 NULL);
1296 1298
1297 ReturnNode* return_node = new ReturnNode(Scanner::kNoSourcePos, closure); 1299 ReturnNode* return_node = new ReturnNode(Scanner::kNoSourcePos, closure);
1298 current_block_->statements->Add(return_node); 1300 current_block_->statements->Add(return_node);
1299 return CloseBlock(); 1301 return CloseBlock();
1300 } 1302 }
1301 1303
1302 1304
1303 void Parser::BuildDispatcherScope(const Function& func, 1305 void Parser::BuildDispatcherScope(const Function& func,
1304 const ArgumentsDescriptor& desc, 1306 const ArgumentsDescriptor& desc,
1305 Array* default_values) { 1307 Array* default_values) {
1306 ParamList params; 1308 ParamList params;
1307 // Receiver first. 1309 // Receiver first.
1308 intptr_t token_pos = func.token_pos(); 1310 intptr_t token_pos = func.token_pos();
1309 params.AddReceiver(ReceiverType(current_class()), token_pos); 1311 params.AddReceiver(ReceiverType(current_class()), token_pos);
1310 // Remaining positional parameters. 1312 // Remaining positional parameters.
1311 intptr_t i = 1; 1313 intptr_t i = 1;
1312 for (; i < desc.PositionalCount(); ++i) { 1314 for (; i < desc.PositionalCount(); ++i) {
1313 ParamDesc p; 1315 ParamDesc p;
1314 char name[64]; 1316 char name[64];
1315 OS::SNPrint(name, 64, ":p%" Pd, i); 1317 OS::SNPrint(name, 64, ":p%" Pd, i);
1316 p.name = &String::ZoneHandle(Symbols::New(name)); 1318 p.name = &String::ZoneHandle(I, Symbols::New(name));
1317 p.type = &Type::ZoneHandle(Type::DynamicType()); 1319 p.type = &Type::ZoneHandle(I, Type::DynamicType());
1318 params.parameters->Add(p); 1320 params.parameters->Add(p);
1319 params.num_fixed_parameters++; 1321 params.num_fixed_parameters++;
1320 } 1322 }
1321 ASSERT(desc.PositionalCount() == params.num_fixed_parameters); 1323 ASSERT(desc.PositionalCount() == params.num_fixed_parameters);
1322 1324
1323 // Named parameters. 1325 // Named parameters.
1324 for (; i < desc.Count(); ++i) { 1326 for (; i < desc.Count(); ++i) {
1325 ParamDesc p; 1327 ParamDesc p;
1326 intptr_t index = i - desc.PositionalCount(); 1328 intptr_t index = i - desc.PositionalCount();
1327 p.name = &String::ZoneHandle(desc.NameAt(index)); 1329 p.name = &String::ZoneHandle(I, desc.NameAt(index));
1328 p.type = &Type::ZoneHandle(Type::DynamicType()); 1330 p.type = &Type::ZoneHandle(I, Type::DynamicType());
1329 p.default_value = &Object::ZoneHandle(); 1331 p.default_value = &Object::ZoneHandle();
1330 params.parameters->Add(p); 1332 params.parameters->Add(p);
1331 params.num_optional_parameters++; 1333 params.num_optional_parameters++;
1332 params.has_optional_named_parameters = true; 1334 params.has_optional_named_parameters = true;
1333 } 1335 }
1334 ASSERT(desc.NamedCount() == params.num_optional_parameters); 1336 ASSERT(desc.NamedCount() == params.num_optional_parameters);
1335 1337
1336 SetupDefaultsForOptionalParams(&params, default_values); 1338 SetupDefaultsForOptionalParams(&params, default_values);
1337 1339
1338 // Build local scope for function and populate with the formal parameters. 1340 // Build local scope for function and populate with the formal parameters.
(...skipping 17 matching lines...) Expand all
1356 BuildDispatcherScope(func, desc, default_values); 1358 BuildDispatcherScope(func, desc, default_values);
1357 1359
1358 // Receiver is local 0. 1360 // Receiver is local 0.
1359 LocalScope* scope = current_block_->scope; 1361 LocalScope* scope = current_block_->scope;
1360 ArgumentListNode* func_args = new ArgumentListNode(token_pos); 1362 ArgumentListNode* func_args = new ArgumentListNode(token_pos);
1361 for (intptr_t i = 0; i < desc.Count(); ++i) { 1363 for (intptr_t i = 0; i < desc.Count(); ++i) {
1362 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); 1364 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i)));
1363 } 1365 }
1364 1366
1365 if (desc.NamedCount() > 0) { 1367 if (desc.NamedCount() > 0) {
1366 const Array& arg_names = Array::ZoneHandle(Array::New(desc.NamedCount())); 1368 const Array& arg_names =
1369 Array::ZoneHandle(I, Array::New(desc.NamedCount()));
1367 for (intptr_t i = 0; i < arg_names.Length(); ++i) { 1370 for (intptr_t i = 0; i < arg_names.Length(); ++i) {
1368 arg_names.SetAt(i, String::Handle(isolate(), desc.NameAt(i))); 1371 arg_names.SetAt(i, String::Handle(isolate(), desc.NameAt(i)));
1369 } 1372 }
1370 func_args->set_names(arg_names); 1373 func_args->set_names(arg_names);
1371 } 1374 }
1372 1375
1373 const String& func_name = String::ZoneHandle(func.name()); 1376 const String& func_name = String::ZoneHandle(I, func.name());
1374 ArgumentListNode* arguments = BuildNoSuchMethodArguments( 1377 ArgumentListNode* arguments = BuildNoSuchMethodArguments(
1375 token_pos, func_name, *func_args, NULL, false); 1378 token_pos, func_name, *func_args, NULL, false);
1376 const Function& no_such_method = Function::ZoneHandle( 1379 const Function& no_such_method = Function::ZoneHandle(I,
1377 Resolver::ResolveDynamicAnyArgs(Class::Handle( 1380 Resolver::ResolveDynamicAnyArgs(Class::Handle(
1378 isolate(), func.Owner()), Symbols::NoSuchMethod())); 1381 isolate(), func.Owner()), Symbols::NoSuchMethod()));
1379 StaticCallNode* call = 1382 StaticCallNode* call =
1380 new StaticCallNode(token_pos, no_such_method, arguments); 1383 new StaticCallNode(token_pos, no_such_method, arguments);
1381 1384
1382 ReturnNode* return_node = new ReturnNode(token_pos, call); 1385 ReturnNode* return_node = new ReturnNode(token_pos, call);
1383 current_block_->statements->Add(return_node); 1386 current_block_->statements->Add(return_node);
1384 return CloseBlock(); 1387 return CloseBlock();
1385 } 1388 }
1386 1389
(...skipping 13 matching lines...) Expand all
1400 1403
1401 // Set up scope for this function. 1404 // Set up scope for this function.
1402 BuildDispatcherScope(func, desc, default_values); 1405 BuildDispatcherScope(func, desc, default_values);
1403 1406
1404 // Receiver is local 0. 1407 // Receiver is local 0.
1405 LocalScope* scope = current_block_->scope; 1408 LocalScope* scope = current_block_->scope;
1406 ArgumentListNode* no_args = new ArgumentListNode(token_pos); 1409 ArgumentListNode* no_args = new ArgumentListNode(token_pos);
1407 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); 1410 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0));
1408 1411
1409 const String& name = String::Handle(isolate(), func.name()); 1412 const String& name = String::Handle(isolate(), func.name());
1410 const String& getter_name = String::ZoneHandle( 1413 const String& getter_name = String::ZoneHandle(I,
1411 Symbols::New(String::Handle(isolate(), Field::GetterName(name)))); 1414 Symbols::New(String::Handle(isolate(), Field::GetterName(name))));
1412 InstanceCallNode* getter_call = new(isolate()) InstanceCallNode( 1415 InstanceCallNode* getter_call = new(isolate()) InstanceCallNode(
1413 token_pos, receiver, getter_name, no_args); 1416 token_pos, receiver, getter_name, no_args);
1414 1417
1415 // Pass arguments 1..n to the closure call. 1418 // Pass arguments 1..n to the closure call.
1416 ArgumentListNode* args = new ArgumentListNode(token_pos); 1419 ArgumentListNode* args = new ArgumentListNode(token_pos);
1417 const Array& names = Array::Handle( 1420 const Array& names = Array::Handle(
1418 isolate(), Array::New(desc.NamedCount(), Heap::kOld)); 1421 isolate(), Array::New(desc.NamedCount(), Heap::kOld));
1419 // Positional parameters. 1422 // Positional parameters.
1420 intptr_t i = 1; 1423 intptr_t i = 1;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 1506
1504 void Parser::ParseFormalParameter(bool allow_explicit_default_value, 1507 void Parser::ParseFormalParameter(bool allow_explicit_default_value,
1505 bool evaluate_metadata, 1508 bool evaluate_metadata,
1506 ParamList* params) { 1509 ParamList* params) {
1507 TRACE_PARSER("ParseFormalParameter"); 1510 TRACE_PARSER("ParseFormalParameter");
1508 ParamDesc parameter; 1511 ParamDesc parameter;
1509 bool var_seen = false; 1512 bool var_seen = false;
1510 bool this_seen = false; 1513 bool this_seen = false;
1511 1514
1512 if (evaluate_metadata && (CurrentToken() == Token::kAT)) { 1515 if (evaluate_metadata && (CurrentToken() == Token::kAT)) {
1513 parameter.metadata = &Array::ZoneHandle(EvaluateMetadata()); 1516 parameter.metadata = &Array::ZoneHandle(I, EvaluateMetadata());
1514 } else { 1517 } else {
1515 SkipMetadata(); 1518 SkipMetadata();
1516 } 1519 }
1517 1520
1518 if (CurrentToken() == Token::kFINAL) { 1521 if (CurrentToken() == Token::kFINAL) {
1519 ConsumeToken(); 1522 ConsumeToken();
1520 parameter.is_final = true; 1523 parameter.is_final = true;
1521 } else if (CurrentToken() == Token::kVAR) { 1524 } else if (CurrentToken() == Token::kVAR) {
1522 ConsumeToken(); 1525 ConsumeToken();
1523 var_seen = true; 1526 var_seen = true;
1524 // The parameter type is the 'dynamic' type. 1527 // The parameter type is the 'dynamic' type.
1525 // If this is an initializing formal, its type will be set to the type of 1528 // If this is an initializing formal, its type will be set to the type of
1526 // the respective field when the constructor is fully parsed. 1529 // the respective field when the constructor is fully parsed.
1527 parameter.type = &Type::ZoneHandle(Type::DynamicType()); 1530 parameter.type = &Type::ZoneHandle(I, Type::DynamicType());
1528 } 1531 }
1529 if (CurrentToken() == Token::kTHIS) { 1532 if (CurrentToken() == Token::kTHIS) {
1530 ConsumeToken(); 1533 ConsumeToken();
1531 ExpectToken(Token::kPERIOD); 1534 ExpectToken(Token::kPERIOD);
1532 this_seen = true; 1535 this_seen = true;
1533 parameter.is_field_initializer = true; 1536 parameter.is_field_initializer = true;
1534 } 1537 }
1535 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) { 1538 if ((parameter.type == NULL) && (CurrentToken() == Token::kVOID)) {
1536 ConsumeToken(); 1539 ConsumeToken();
1537 // This must later be changed to a closure type if we recognize 1540 // This must later be changed to a closure type if we recognize
1538 // a closure/function type parameter. We check this at the end 1541 // a closure/function type parameter. We check this at the end
1539 // of ParseFormalParameter. 1542 // of ParseFormalParameter.
1540 parameter.type = &Type::ZoneHandle(Type::VoidType()); 1543 parameter.type = &Type::ZoneHandle(I, Type::VoidType());
1541 } 1544 }
1542 if (parameter.type == NULL) { 1545 if (parameter.type == NULL) {
1543 // At this point, we must see an identifier for the type or the 1546 // At this point, we must see an identifier for the type or the
1544 // function parameter. 1547 // function parameter.
1545 if (!IsIdentifier()) { 1548 if (!IsIdentifier()) {
1546 ErrorMsg("parameter name or type expected"); 1549 ErrorMsg("parameter name or type expected");
1547 } 1550 }
1548 // We have not seen a parameter type yet, so we check if the next 1551 // We have not seen a parameter type yet, so we check if the next
1549 // identifier could represent a type before parsing it. 1552 // identifier could represent a type before parsing it.
1550 Token::Kind follower = LookaheadToken(1); 1553 Token::Kind follower = LookaheadToken(1);
1551 // We have an identifier followed by a 'follower' token. 1554 // We have an identifier followed by a 'follower' token.
1552 // We either parse a type or assume that no type is specified. 1555 // We either parse a type or assume that no type is specified.
1553 if ((follower == Token::kLT) || // Parameterized type. 1556 if ((follower == Token::kLT) || // Parameterized type.
1554 (follower == Token::kPERIOD) || // Qualified class name of type. 1557 (follower == Token::kPERIOD) || // Qualified class name of type.
1555 Token::IsIdentifier(follower) || // Parameter name following a type. 1558 Token::IsIdentifier(follower) || // Parameter name following a type.
1556 (follower == Token::kTHIS)) { // Field parameter following a type. 1559 (follower == Token::kTHIS)) { // Field parameter following a type.
1557 // The types of formal parameters are never ignored, even in unchecked 1560 // The types of formal parameters are never ignored, even in unchecked
1558 // mode, because they are part of the function type of closurized 1561 // mode, because they are part of the function type of closurized
1559 // functions appearing in type tests with typedefs. 1562 // functions appearing in type tests with typedefs.
1560 parameter.has_explicit_type = true; 1563 parameter.has_explicit_type = true;
1561 parameter.type = &AbstractType::ZoneHandle( 1564 parameter.type = &AbstractType::ZoneHandle(I,
1562 ParseType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters : 1565 ParseType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters :
1563 ClassFinalizer::kCanonicalize)); 1566 ClassFinalizer::kCanonicalize));
1564 } else { 1567 } else {
1565 // If this is an initializing formal, its type will be set to the type of 1568 // If this is an initializing formal, its type will be set to the type of
1566 // the respective field when the constructor is fully parsed. 1569 // the respective field when the constructor is fully parsed.
1567 parameter.type = &Type::ZoneHandle(Type::DynamicType()); 1570 parameter.type = &Type::ZoneHandle(I, Type::DynamicType());
1568 } 1571 }
1569 } 1572 }
1570 if (!this_seen && (CurrentToken() == Token::kTHIS)) { 1573 if (!this_seen && (CurrentToken() == Token::kTHIS)) {
1571 ConsumeToken(); 1574 ConsumeToken();
1572 ExpectToken(Token::kPERIOD); 1575 ExpectToken(Token::kPERIOD);
1573 this_seen = true; 1576 this_seen = true;
1574 parameter.is_field_initializer = true; 1577 parameter.is_field_initializer = true;
1575 } 1578 }
1576 1579
1577 // At this point, we must see an identifier for the parameter name. 1580 // At this point, we must see an identifier for the parameter name.
(...skipping 28 matching lines...) Expand all
1606 const AbstractType& result_type = 1609 const AbstractType& result_type =
1607 AbstractType::Handle(isolate(), parameter.type->raw()); 1610 AbstractType::Handle(isolate(), parameter.type->raw());
1608 1611
1609 // Finish parsing the function type parameter. 1612 // Finish parsing the function type parameter.
1610 ParamList func_params; 1613 ParamList func_params;
1611 1614
1612 // Add implicit closure object parameter. 1615 // Add implicit closure object parameter.
1613 func_params.AddFinalParameter( 1616 func_params.AddFinalParameter(
1614 TokenPos(), 1617 TokenPos(),
1615 &Symbols::ClosureParameter(), 1618 &Symbols::ClosureParameter(),
1616 &Type::ZoneHandle(Type::DynamicType())); 1619 &Type::ZoneHandle(I, Type::DynamicType()));
1617 1620
1618 const bool no_explicit_default_values = false; 1621 const bool no_explicit_default_values = false;
1619 ParseFormalParameterList(no_explicit_default_values, false, &func_params); 1622 ParseFormalParameterList(no_explicit_default_values, false, &func_params);
1620 1623
1621 // The field 'is_static' has no meaning for signature functions. 1624 // The field 'is_static' has no meaning for signature functions.
1622 const Function& signature_function = Function::Handle(isolate(), 1625 const Function& signature_function = Function::Handle(isolate(),
1623 Function::New(*parameter.name, 1626 Function::New(*parameter.name,
1624 RawFunction::kSignatureFunction, 1627 RawFunction::kSignatureFunction,
1625 /* is_static = */ false, 1628 /* is_static = */ false,
1626 /* is_const = */ false, 1629 /* is_const = */ false,
1627 /* is_abstract = */ false, 1630 /* is_abstract = */ false,
1628 /* is_external = */ false, 1631 /* is_external = */ false,
1629 /* is_native = */ false, 1632 /* is_native = */ false,
1630 current_class(), 1633 current_class(),
1631 parameter.name_pos)); 1634 parameter.name_pos));
1632 signature_function.set_result_type(result_type); 1635 signature_function.set_result_type(result_type);
1633 AddFormalParamsToFunction(&func_params, signature_function); 1636 AddFormalParamsToFunction(&func_params, signature_function);
1634 const String& signature = String::Handle(isolate(), 1637 const String& signature = String::Handle(isolate(),
1635 signature_function.Signature()); 1638 signature_function.Signature());
1636 // Lookup the signature class, i.e. the class whose name is the signature. 1639 // Lookup the signature class, i.e. the class whose name is the signature.
1637 // We only lookup in the current library, but not in its imports, and only 1640 // We only lookup in the current library, but not in its imports, and only
1638 // create a new canonical signature class if it does not exist yet. 1641 // create a new canonical signature class if it does not exist yet.
1639 Class& signature_class = Class::ZoneHandle( 1642 Class& signature_class = Class::ZoneHandle(I,
1640 library_.LookupLocalClass(signature)); 1643 library_.LookupLocalClass(signature));
1641 if (signature_class.IsNull()) { 1644 if (signature_class.IsNull()) {
1642 signature_class = Class::NewSignatureClass(signature, 1645 signature_class = Class::NewSignatureClass(signature,
1643 signature_function, 1646 signature_function,
1644 script_, 1647 script_,
1645 parameter.name_pos); 1648 parameter.name_pos);
1646 // Record the function signature class in the current library, unless 1649 // Record the function signature class in the current library, unless
1647 // we are currently skipping a formal parameter list, in which case 1650 // we are currently skipping a formal parameter list, in which case
1648 // the signature class could remain unfinalized. 1651 // the signature class could remain unfinalized.
1649 if (!params->skipped) { 1652 if (!params->skipped) {
1650 library_.AddClass(signature_class); 1653 library_.AddClass(signature_class);
1651 } 1654 }
1652 } else { 1655 } else {
1653 signature_function.set_signature_class(signature_class); 1656 signature_function.set_signature_class(signature_class);
1654 } 1657 }
1655 ASSERT(signature_function.signature_class() == signature_class.raw()); 1658 ASSERT(signature_function.signature_class() == signature_class.raw());
1656 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); 1659 Type& signature_type =
1660 Type::ZoneHandle(I, signature_class.SignatureType());
1657 if (!is_top_level_ && !signature_type.IsFinalized()) { 1661 if (!is_top_level_ && !signature_type.IsFinalized()) {
1658 signature_type ^= ClassFinalizer::FinalizeType( 1662 signature_type ^= ClassFinalizer::FinalizeType(
1659 signature_class, signature_type, ClassFinalizer::kCanonicalize); 1663 signature_class, signature_type, ClassFinalizer::kCanonicalize);
1660 } 1664 }
1661 // A signature type itself cannot be malformed or malbounded, only its 1665 // A signature type itself cannot be malformed or malbounded, only its
1662 // signature function's result type or parameter types may be. 1666 // signature function's result type or parameter types may be.
1663 ASSERT(!signature_type.IsMalformed()); 1667 ASSERT(!signature_type.IsMalformed());
1664 ASSERT(!signature_type.IsMalbounded()); 1668 ASSERT(!signature_type.IsMalbounded());
1665 // The type of the parameter is now the signature type. 1669 // The type of the parameter is now the signature type.
1666 parameter.type = &signature_type; 1670 parameter.type = &signature_type;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 String::Handle(isolate(), current_class().Name()).ToCString()); 1803 String::Handle(isolate(), current_class().Name()).ToCString());
1800 } 1804 }
1801 Function& super_func = Function::Handle(isolate(), 1805 Function& super_func = Function::Handle(isolate(),
1802 Resolver::ResolveDynamicAnyArgs(super_class, name)); 1806 Resolver::ResolveDynamicAnyArgs(super_class, name));
1803 if (!super_func.IsNull() && 1807 if (!super_func.IsNull() &&
1804 !super_func.AreValidArguments(arguments->length(), 1808 !super_func.AreValidArguments(arguments->length(),
1805 arguments->names(), 1809 arguments->names(),
1806 NULL)) { 1810 NULL)) {
1807 super_func = Function::null(); 1811 super_func = Function::null();
1808 } else if (super_func.IsNull() && resolve_getter) { 1812 } else if (super_func.IsNull() && resolve_getter) {
1809 const String& getter_name = String::ZoneHandle(Field::GetterName(name)); 1813 const String& getter_name = String::ZoneHandle(I, Field::GetterName(name));
1810 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); 1814 super_func = Resolver::ResolveDynamicAnyArgs(super_class, getter_name);
1811 ASSERT(super_func.IsNull() || 1815 ASSERT(super_func.IsNull() ||
1812 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter)); 1816 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter));
1813 } 1817 }
1814 if (super_func.IsNull()) { 1818 if (super_func.IsNull()) {
1815 super_func = 1819 super_func =
1816 Resolver::ResolveDynamicAnyArgs(super_class, Symbols::NoSuchMethod()); 1820 Resolver::ResolveDynamicAnyArgs(super_class, Symbols::NoSuchMethod());
1817 ASSERT(!super_func.IsNull()); 1821 ASSERT(!super_func.IsNull());
1818 *is_no_such_method = true; 1822 *is_no_such_method = true;
1819 } else { 1823 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 const intptr_t supercall_pos = TokenPos(); 1902 const intptr_t supercall_pos = TokenPos();
1899 1903
1900 // 'this' parameter is the first argument to super call. 1904 // 'this' parameter is the first argument to super call.
1901 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1905 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1902 AstNode* receiver = LoadReceiver(supercall_pos); 1906 AstNode* receiver = LoadReceiver(supercall_pos);
1903 arguments->Add(receiver); 1907 arguments->Add(receiver);
1904 ParseActualParameters(arguments, kAllowConst); 1908 ParseActualParameters(arguments, kAllowConst);
1905 1909
1906 const bool kResolveGetter = true; 1910 const bool kResolveGetter = true;
1907 bool is_no_such_method = false; 1911 bool is_no_such_method = false;
1908 const Function& super_function = Function::ZoneHandle( 1912 const Function& super_function = Function::ZoneHandle(I,
1909 GetSuperFunction(supercall_pos, 1913 GetSuperFunction(supercall_pos,
1910 function_name, 1914 function_name,
1911 arguments, 1915 arguments,
1912 kResolveGetter, 1916 kResolveGetter,
1913 &is_no_such_method)); 1917 &is_no_such_method));
1914 if (super_function.IsGetterFunction() || 1918 if (super_function.IsGetterFunction() ||
1915 super_function.IsImplicitGetterFunction()) { 1919 super_function.IsImplicitGetterFunction()) {
1916 const Class& super_class = Class::ZoneHandle(current_class().SuperClass()); 1920 const Class& super_class =
1921 Class::ZoneHandle(I, current_class().SuperClass());
1917 AstNode* closure = new StaticGetterNode(supercall_pos, 1922 AstNode* closure = new StaticGetterNode(supercall_pos,
1918 LoadReceiver(supercall_pos), 1923 LoadReceiver(supercall_pos),
1919 /* is_super_getter */ true, 1924 /* is_super_getter */ true,
1920 super_class, 1925 super_class,
1921 function_name); 1926 function_name);
1922 // 'this' is not passed as parameter to the closure. 1927 // 'this' is not passed as parameter to the closure.
1923 ArgumentListNode* closure_arguments = new ArgumentListNode(supercall_pos); 1928 ArgumentListNode* closure_arguments = new ArgumentListNode(supercall_pos);
1924 for (int i = 1; i < arguments->length(); i++) { 1929 for (int i = 1; i < arguments->length(); i++) {
1925 closure_arguments->Add(arguments->NodeAt(i)); 1930 closure_arguments->Add(arguments->NodeAt(i));
1926 } 1931 }
(...skipping 14 matching lines...) Expand all
1941 1946
1942 1947
1943 AstNode* Parser::BuildUnarySuperOperator(Token::Kind op, PrimaryNode* super) { 1948 AstNode* Parser::BuildUnarySuperOperator(Token::Kind op, PrimaryNode* super) {
1944 ASSERT(super->IsSuper()); 1949 ASSERT(super->IsSuper());
1945 AstNode* super_op = NULL; 1950 AstNode* super_op = NULL;
1946 const intptr_t super_pos = super->token_pos(); 1951 const intptr_t super_pos = super->token_pos();
1947 if ((op == Token::kNEGATE) || 1952 if ((op == Token::kNEGATE) ||
1948 (op == Token::kBIT_NOT)) { 1953 (op == Token::kBIT_NOT)) {
1949 // Resolve the operator function in the superclass. 1954 // Resolve the operator function in the superclass.
1950 const String& operator_function_name = 1955 const String& operator_function_name =
1951 String::ZoneHandle(Symbols::New(Token::Str(op))); 1956 String::ZoneHandle(I, Symbols::New(Token::Str(op)));
1952 ArgumentListNode* op_arguments = new ArgumentListNode(super_pos); 1957 ArgumentListNode* op_arguments = new ArgumentListNode(super_pos);
1953 AstNode* receiver = LoadReceiver(super_pos); 1958 AstNode* receiver = LoadReceiver(super_pos);
1954 op_arguments->Add(receiver); 1959 op_arguments->Add(receiver);
1955 const bool kResolveGetter = false; 1960 const bool kResolveGetter = false;
1956 bool is_no_such_method = false; 1961 bool is_no_such_method = false;
1957 const Function& super_operator = Function::ZoneHandle( 1962 const Function& super_operator = Function::ZoneHandle(I,
1958 GetSuperFunction(super_pos, 1963 GetSuperFunction(super_pos,
1959 operator_function_name, 1964 operator_function_name,
1960 op_arguments, 1965 op_arguments,
1961 kResolveGetter, 1966 kResolveGetter,
1962 &is_no_such_method)); 1967 &is_no_such_method));
1963 if (is_no_such_method) { 1968 if (is_no_such_method) {
1964 op_arguments = BuildNoSuchMethodArguments( 1969 op_arguments = BuildNoSuchMethodArguments(
1965 super_pos, operator_function_name, *op_arguments, NULL, true); 1970 super_pos, operator_function_name, *op_arguments, NULL, true);
1966 } 1971 }
1967 super_op = new StaticCallNode(super_pos, super_operator, op_arguments); 1972 super_op = new StaticCallNode(super_pos, super_operator, op_arguments);
1968 } else { 1973 } else {
1969 ErrorMsg(super_pos, "illegal super operator call"); 1974 ErrorMsg(super_pos, "illegal super operator call");
1970 } 1975 }
1971 return super_op; 1976 return super_op;
1972 } 1977 }
1973 1978
1974 1979
1975 AstNode* Parser::ParseSuperOperator() { 1980 AstNode* Parser::ParseSuperOperator() {
1976 TRACE_PARSER("ParseSuperOperator"); 1981 TRACE_PARSER("ParseSuperOperator");
1977 AstNode* super_op = NULL; 1982 AstNode* super_op = NULL;
1978 const intptr_t operator_pos = TokenPos(); 1983 const intptr_t operator_pos = TokenPos();
1979 1984
1980 if (CurrentToken() == Token::kLBRACK) { 1985 if (CurrentToken() == Token::kLBRACK) {
1981 ConsumeToken(); 1986 ConsumeToken();
1982 AstNode* index_expr = ParseExpr(kAllowConst, kConsumeCascades); 1987 AstNode* index_expr = ParseExpr(kAllowConst, kConsumeCascades);
1983 ExpectToken(Token::kRBRACK); 1988 ExpectToken(Token::kRBRACK);
1984 AstNode* receiver = LoadReceiver(operator_pos); 1989 AstNode* receiver = LoadReceiver(operator_pos);
1985 const Class& super_class = Class::ZoneHandle(current_class().SuperClass()); 1990 const Class& super_class =
1991 Class::ZoneHandle(I, current_class().SuperClass());
1986 ASSERT(!super_class.IsNull()); 1992 ASSERT(!super_class.IsNull());
1987 super_op = 1993 super_op =
1988 new LoadIndexedNode(operator_pos, receiver, index_expr, super_class); 1994 new LoadIndexedNode(operator_pos, receiver, index_expr, super_class);
1989 } else { 1995 } else {
1990 ASSERT(Token::CanBeOverloaded(CurrentToken()) || 1996 ASSERT(Token::CanBeOverloaded(CurrentToken()) ||
1991 (CurrentToken() == Token::kNE)); 1997 (CurrentToken() == Token::kNE));
1992 Token::Kind op = CurrentToken(); 1998 Token::Kind op = CurrentToken();
1993 ConsumeToken(); 1999 ConsumeToken();
1994 2000
1995 bool negate_result = false; 2001 bool negate_result = false;
1996 if (op == Token::kNE) { 2002 if (op == Token::kNE) {
1997 op = Token::kEQ; 2003 op = Token::kEQ;
1998 negate_result = true; 2004 negate_result = true;
1999 } 2005 }
2000 2006
2001 ASSERT(Token::Precedence(op) >= Token::Precedence(Token::kEQ)); 2007 ASSERT(Token::Precedence(op) >= Token::Precedence(Token::kEQ));
2002 AstNode* other_operand = ParseBinaryExpr(Token::Precedence(op) + 1); 2008 AstNode* other_operand = ParseBinaryExpr(Token::Precedence(op) + 1);
2003 2009
2004 ArgumentListNode* op_arguments = new ArgumentListNode(operator_pos); 2010 ArgumentListNode* op_arguments = new ArgumentListNode(operator_pos);
2005 AstNode* receiver = LoadReceiver(operator_pos); 2011 AstNode* receiver = LoadReceiver(operator_pos);
2006 op_arguments->Add(receiver); 2012 op_arguments->Add(receiver);
2007 op_arguments->Add(other_operand); 2013 op_arguments->Add(other_operand);
2008 2014
2009 // Resolve the operator function in the superclass. 2015 // Resolve the operator function in the superclass.
2010 const String& operator_function_name = 2016 const String& operator_function_name =
2011 String::ZoneHandle(Symbols::New(Token::Str(op))); 2017 String::ZoneHandle(I, Symbols::New(Token::Str(op)));
2012 const bool kResolveGetter = false; 2018 const bool kResolveGetter = false;
2013 bool is_no_such_method = false; 2019 bool is_no_such_method = false;
2014 const Function& super_operator = Function::ZoneHandle( 2020 const Function& super_operator = Function::ZoneHandle(I,
2015 GetSuperFunction(operator_pos, 2021 GetSuperFunction(operator_pos,
2016 operator_function_name, 2022 operator_function_name,
2017 op_arguments, 2023 op_arguments,
2018 kResolveGetter, 2024 kResolveGetter,
2019 &is_no_such_method)); 2025 &is_no_such_method));
2020 if (is_no_such_method) { 2026 if (is_no_such_method) {
2021 op_arguments = BuildNoSuchMethodArguments( 2027 op_arguments = BuildNoSuchMethodArguments(
2022 operator_pos, operator_function_name, *op_arguments, NULL, true); 2028 operator_pos, operator_function_name, *op_arguments, NULL, true);
2023 } 2029 }
2024 super_op = new StaticCallNode(operator_pos, super_operator, op_arguments); 2030 super_op = new StaticCallNode(operator_pos, super_operator, op_arguments);
2025 if (negate_result) { 2031 if (negate_result) {
2026 super_op = new UnaryOpNode(operator_pos, Token::kNOT, super_op); 2032 super_op = new UnaryOpNode(operator_pos, Token::kNOT, super_op);
2027 } 2033 }
2028 } 2034 }
2029 return super_op; 2035 return super_op;
2030 } 2036 }
2031 2037
2032 2038
2033 ClosureNode* Parser::CreateImplicitClosureNode(const Function& func, 2039 ClosureNode* Parser::CreateImplicitClosureNode(const Function& func,
2034 intptr_t token_pos, 2040 intptr_t token_pos,
2035 AstNode* receiver) { 2041 AstNode* receiver) {
2036 Function& implicit_closure_function = 2042 Function& implicit_closure_function =
2037 Function::ZoneHandle(func.ImplicitClosureFunction()); 2043 Function::ZoneHandle(I, func.ImplicitClosureFunction());
2038 if (receiver != NULL) { 2044 if (receiver != NULL) {
2039 // If we create an implicit instance closure from inside a closure of a 2045 // If we create an implicit instance closure from inside a closure of a
2040 // parameterized class, make sure that the receiver is captured as 2046 // parameterized class, make sure that the receiver is captured as
2041 // instantiator. 2047 // instantiator.
2042 if (current_block_->scope->function_level() > 0) { 2048 if (current_block_->scope->function_level() > 0) {
2043 const Class& signature_class = Class::Handle(isolate(), 2049 const Class& signature_class = Class::Handle(isolate(),
2044 implicit_closure_function.signature_class()); 2050 implicit_closure_function.signature_class());
2045 if (signature_class.NumTypeParameters() > 0) { 2051 if (signature_class.NumTypeParameters() > 0) {
2046 CaptureInstantiator(); 2052 CaptureInstantiator();
2047 } 2053 }
2048 } 2054 }
2049 } 2055 }
2050 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); 2056 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL);
2051 } 2057 }
2052 2058
2053 2059
2054 AstNode* Parser::ParseSuperFieldAccess(const String& field_name, 2060 AstNode* Parser::ParseSuperFieldAccess(const String& field_name,
2055 intptr_t field_pos) { 2061 intptr_t field_pos) {
2056 TRACE_PARSER("ParseSuperFieldAccess"); 2062 TRACE_PARSER("ParseSuperFieldAccess");
2057 const Class& super_class = Class::ZoneHandle(current_class().SuperClass()); 2063 const Class& super_class = Class::ZoneHandle(I, current_class().SuperClass());
2058 if (super_class.IsNull()) { 2064 if (super_class.IsNull()) {
2059 ErrorMsg("class '%s' does not have a superclass", 2065 ErrorMsg("class '%s' does not have a superclass",
2060 String::Handle(isolate(), current_class().Name()).ToCString()); 2066 String::Handle(isolate(), current_class().Name()).ToCString());
2061 } 2067 }
2062 AstNode* implicit_argument = LoadReceiver(field_pos); 2068 AstNode* implicit_argument = LoadReceiver(field_pos);
2063 2069
2064 const String& getter_name = 2070 const String& getter_name =
2065 String::ZoneHandle(Field::GetterName(field_name)); 2071 String::ZoneHandle(I, Field::GetterName(field_name));
2066 const Function& super_getter = Function::ZoneHandle( 2072 const Function& super_getter = Function::ZoneHandle(I,
2067 Resolver::ResolveDynamicAnyArgs(super_class, getter_name)); 2073 Resolver::ResolveDynamicAnyArgs(super_class, getter_name));
2068 if (super_getter.IsNull()) { 2074 if (super_getter.IsNull()) {
2069 const String& setter_name = 2075 const String& setter_name =
2070 String::ZoneHandle(Field::SetterName(field_name)); 2076 String::ZoneHandle(I, Field::SetterName(field_name));
2071 const Function& super_setter = Function::ZoneHandle( 2077 const Function& super_setter = Function::ZoneHandle(I,
2072 Resolver::ResolveDynamicAnyArgs(super_class, setter_name)); 2078 Resolver::ResolveDynamicAnyArgs(super_class, setter_name));
2073 if (super_setter.IsNull()) { 2079 if (super_setter.IsNull()) {
2074 // Check if this is an access to an implicit closure using 'super'. 2080 // Check if this is an access to an implicit closure using 'super'.
2075 // If a function exists of the specified field_name then try 2081 // If a function exists of the specified field_name then try
2076 // accessing it as a getter, at runtime we will handle this by 2082 // accessing it as a getter, at runtime we will handle this by
2077 // creating an implicit closure of the function and returning it. 2083 // creating an implicit closure of the function and returning it.
2078 const Function& super_function = Function::ZoneHandle( 2084 const Function& super_function = Function::ZoneHandle(I,
2079 Resolver::ResolveDynamicAnyArgs(super_class, field_name)); 2085 Resolver::ResolveDynamicAnyArgs(super_class, field_name));
2080 if (!super_function.IsNull()) { 2086 if (!super_function.IsNull()) {
2081 // In case CreateAssignmentNode is called later on this 2087 // In case CreateAssignmentNode is called later on this
2082 // CreateImplicitClosureNode, it will be replaced by a StaticSetterNode. 2088 // CreateImplicitClosureNode, it will be replaced by a StaticSetterNode.
2083 return CreateImplicitClosureNode(super_function, 2089 return CreateImplicitClosureNode(super_function,
2084 field_pos, 2090 field_pos,
2085 implicit_argument); 2091 implicit_argument);
2086 } 2092 }
2087 // No function or field exists of the specified field_name. 2093 // No function or field exists of the specified field_name.
2088 // Emit a StaticGetterNode anyway, so that noSuchMethod gets called. 2094 // Emit a StaticGetterNode anyway, so that noSuchMethod gets called.
(...skipping 20 matching lines...) Expand all
2109 String& super_ctor_name = String::Handle(isolate(), super_class.Name()); 2115 String& super_ctor_name = String::Handle(isolate(), super_class.Name());
2110 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot()); 2116 super_ctor_name = String::Concat(super_ctor_name, Symbols::Dot());
2111 2117
2112 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 2118 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
2113 // Implicit 'this' parameter is the first argument. 2119 // Implicit 'this' parameter is the first argument.
2114 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 2120 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
2115 arguments->Add(implicit_argument); 2121 arguments->Add(implicit_argument);
2116 // Implicit construction phase parameter is second argument. 2122 // Implicit construction phase parameter is second argument.
2117 AstNode* phase_parameter = 2123 AstNode* phase_parameter =
2118 new LiteralNode(supercall_pos, 2124 new LiteralNode(supercall_pos,
2119 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 2125 Smi::ZoneHandle(I, Smi::New(Function::kCtorPhaseAll)));
2120 arguments->Add(phase_parameter); 2126 arguments->Add(phase_parameter);
2121 2127
2122 // If this is a super call in a forwarding constructor, add the user- 2128 // If this is a super call in a forwarding constructor, add the user-
2123 // defined arguments to the super call and adjust the the super 2129 // defined arguments to the super call and adjust the the super
2124 // constructor name to the respective named constructor if necessary. 2130 // constructor name to the respective named constructor if necessary.
2125 if (forwarding_args != NULL) { 2131 if (forwarding_args != NULL) {
2126 for (int i = 0; i < forwarding_args->length(); i++) { 2132 for (int i = 0; i < forwarding_args->length(); i++) {
2127 arguments->Add(forwarding_args->NodeAt(i)); 2133 arguments->Add(forwarding_args->NodeAt(i));
2128 } 2134 }
2129 String& ctor_name = String::Handle(isolate(), current_function().name()); 2135 String& ctor_name = String::Handle(isolate(), current_function().name());
2130 String& class_name = String::Handle(isolate(), cls.Name()); 2136 String& class_name = String::Handle(isolate(), cls.Name());
2131 if (ctor_name.Length() > class_name.Length() + 1) { 2137 if (ctor_name.Length() > class_name.Length() + 1) {
2132 // Generating a forwarding call to a named constructor 'C.n'. 2138 // Generating a forwarding call to a named constructor 'C.n'.
2133 // Add the constructor name 'n' to the super constructor. 2139 // Add the constructor name 'n' to the super constructor.
2134 ctor_name = String::SubString(ctor_name, class_name.Length() + 1); 2140 ctor_name = String::SubString(ctor_name, class_name.Length() + 1);
2135 super_ctor_name = String::Concat(super_ctor_name, ctor_name); 2141 super_ctor_name = String::Concat(super_ctor_name, ctor_name);
2136 } 2142 }
2137 } 2143 }
2138 2144
2139 // Resolve super constructor function and check arguments. 2145 // Resolve super constructor function and check arguments.
2140 const Function& super_ctor = Function::ZoneHandle( 2146 const Function& super_ctor = Function::ZoneHandle(I,
2141 super_class.LookupConstructor(super_ctor_name)); 2147 super_class.LookupConstructor(super_ctor_name));
2142 if (super_ctor.IsNull()) { 2148 if (super_ctor.IsNull()) {
2143 ErrorMsg(supercall_pos, 2149 ErrorMsg(supercall_pos,
2144 "unresolved implicit call to super constructor '%s()'", 2150 "unresolved implicit call to super constructor '%s()'",
2145 String::Handle(isolate(), super_class.Name()).ToCString()); 2151 String::Handle(isolate(), super_class.Name()).ToCString());
2146 } 2152 }
2147 if (current_function().is_const() && !super_ctor.is_const()) { 2153 if (current_function().is_const() && !super_ctor.is_const()) {
2148 ErrorMsg(supercall_pos, "implicit call to non-const super constructor"); 2154 ErrorMsg(supercall_pos, "implicit call to non-const super constructor");
2149 } 2155 }
2150 2156
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 2188 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
2183 // 'this' parameter is the first argument to super class constructor. 2189 // 'this' parameter is the first argument to super class constructor.
2184 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); 2190 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver);
2185 arguments->Add(implicit_argument); 2191 arguments->Add(implicit_argument);
2186 // Second implicit parameter is the construction phase. We optimistically 2192 // Second implicit parameter is the construction phase. We optimistically
2187 // assume that we can execute both the super initializer and the super 2193 // assume that we can execute both the super initializer and the super
2188 // constructor body. We may later change this to only execute the 2194 // constructor body. We may later change this to only execute the
2189 // super initializer. 2195 // super initializer.
2190 AstNode* phase_parameter = 2196 AstNode* phase_parameter =
2191 new LiteralNode(supercall_pos, 2197 new LiteralNode(supercall_pos,
2192 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 2198 Smi::ZoneHandle(I, Smi::New(Function::kCtorPhaseAll)));
2193 arguments->Add(phase_parameter); 2199 arguments->Add(phase_parameter);
2194 // 'this' parameter must not be accessible to the other super call arguments. 2200 // 'this' parameter must not be accessible to the other super call arguments.
2195 receiver->set_invisible(true); 2201 receiver->set_invisible(true);
2196 ParseActualParameters(arguments, kAllowConst); 2202 ParseActualParameters(arguments, kAllowConst);
2197 receiver->set_invisible(false); 2203 receiver->set_invisible(false);
2198 2204
2199 // Resolve the constructor. 2205 // Resolve the constructor.
2200 const Function& super_ctor = Function::ZoneHandle( 2206 const Function& super_ctor = Function::ZoneHandle(I,
2201 super_class.LookupConstructor(ctor_name)); 2207 super_class.LookupConstructor(ctor_name));
2202 if (super_ctor.IsNull()) { 2208 if (super_ctor.IsNull()) {
2203 ErrorMsg(supercall_pos, 2209 ErrorMsg(supercall_pos,
2204 "super class constructor '%s' not found", 2210 "super class constructor '%s' not found",
2205 ctor_name.ToCString()); 2211 ctor_name.ToCString());
2206 } 2212 }
2207 if (current_function().is_const() && !super_ctor.is_const()) { 2213 if (current_function().is_const() && !super_ctor.is_const()) {
2208 ErrorMsg(supercall_pos, "super constructor must be const"); 2214 ErrorMsg(supercall_pos, "super constructor must be const");
2209 } 2215 }
2210 String& error_message = String::Handle(isolate()); 2216 String& error_message = String::Handle(isolate());
(...skipping 27 matching lines...) Expand all
2238 AstNode* init_expr = ParseConditionalExpr(); 2244 AstNode* init_expr = ParseConditionalExpr();
2239 if (CurrentToken() == Token::kCASCADE) { 2245 if (CurrentToken() == Token::kCASCADE) {
2240 init_expr = ParseCascades(init_expr); 2246 init_expr = ParseCascades(init_expr);
2241 } 2247 }
2242 receiver->set_invisible(false); 2248 receiver->set_invisible(false);
2243 SetAllowFunctionLiterals(saved_mode); 2249 SetAllowFunctionLiterals(saved_mode);
2244 if (current_function().is_const() && !init_expr->IsPotentiallyConst()) { 2250 if (current_function().is_const() && !init_expr->IsPotentiallyConst()) {
2245 ErrorMsg(field_pos, 2251 ErrorMsg(field_pos,
2246 "initializer expression must be compile time constant."); 2252 "initializer expression must be compile time constant.");
2247 } 2253 }
2248 Field& field = Field::ZoneHandle(cls.LookupInstanceField(field_name)); 2254 Field& field = Field::ZoneHandle(I, cls.LookupInstanceField(field_name));
2249 if (field.IsNull()) { 2255 if (field.IsNull()) {
2250 ErrorMsg(field_pos, "unresolved reference to instance field '%s'", 2256 ErrorMsg(field_pos, "unresolved reference to instance field '%s'",
2251 field_name.ToCString()); 2257 field_name.ToCString());
2252 } 2258 }
2253 CheckDuplicateFieldInit(field_pos, initialized_fields, &field); 2259 CheckDuplicateFieldInit(field_pos, initialized_fields, &field);
2254 AstNode* instance = new LoadLocalNode(field_pos, receiver); 2260 AstNode* instance = new LoadLocalNode(field_pos, receiver);
2255 EnsureExpressionTemp(); 2261 EnsureExpressionTemp();
2256 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); 2262 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr);
2257 } 2263 }
2258 2264
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 void Parser::ParseInitializedInstanceFields(const Class& cls, 2333 void Parser::ParseInitializedInstanceFields(const Class& cls,
2328 LocalVariable* receiver, 2334 LocalVariable* receiver,
2329 GrowableArray<Field*>* initialized_fields) { 2335 GrowableArray<Field*>* initialized_fields) {
2330 TRACE_PARSER("ParseInitializedInstanceFields"); 2336 TRACE_PARSER("ParseInitializedInstanceFields");
2331 const Array& fields = Array::Handle(isolate(), cls.fields()); 2337 const Array& fields = Array::Handle(isolate(), cls.fields());
2332 Field& f = Field::Handle(isolate()); 2338 Field& f = Field::Handle(isolate());
2333 const intptr_t saved_pos = TokenPos(); 2339 const intptr_t saved_pos = TokenPos();
2334 for (int i = 0; i < fields.Length(); i++) { 2340 for (int i = 0; i < fields.Length(); i++) {
2335 f ^= fields.At(i); 2341 f ^= fields.At(i);
2336 if (!f.is_static() && f.has_initializer()) { 2342 if (!f.is_static() && f.has_initializer()) {
2337 Field& field = Field::ZoneHandle(); 2343 Field& field = Field::ZoneHandle(I);
2338 field ^= fields.At(i); 2344 field ^= fields.At(i);
2339 if (field.is_final()) { 2345 if (field.is_final()) {
2340 // Final fields with initializer expression may not be initialized 2346 // Final fields with initializer expression may not be initialized
2341 // again by constructors. Remember that this field is already 2347 // again by constructors. Remember that this field is already
2342 // initialized. 2348 // initialized.
2343 initialized_fields->Add(&field); 2349 initialized_fields->Add(&field);
2344 } 2350 }
2345 AstNode* init_expr = NULL; 2351 AstNode* init_expr = NULL;
2346 if (current_class().raw() != field.origin()) { 2352 if (current_class().raw() != field.origin()) {
2347 init_expr = ParseExternalInitializedField(field); 2353 init_expr = ParseExternalInitializedField(field);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 arguments->Add(implicit_argument); 2451 arguments->Add(implicit_argument);
2446 // Construction phase parameter is second argument. 2452 // Construction phase parameter is second argument.
2447 LocalVariable* phase_param = LookupPhaseParameter(); 2453 LocalVariable* phase_param = LookupPhaseParameter();
2448 ASSERT(phase_param != NULL); 2454 ASSERT(phase_param != NULL);
2449 AstNode* phase_argument = new LoadLocalNode(call_pos, phase_param); 2455 AstNode* phase_argument = new LoadLocalNode(call_pos, phase_param);
2450 arguments->Add(phase_argument); 2456 arguments->Add(phase_argument);
2451 receiver->set_invisible(true); 2457 receiver->set_invisible(true);
2452 ParseActualParameters(arguments, kAllowConst); 2458 ParseActualParameters(arguments, kAllowConst);
2453 receiver->set_invisible(false); 2459 receiver->set_invisible(false);
2454 // Resolve the constructor. 2460 // Resolve the constructor.
2455 const Function& redirect_ctor = Function::ZoneHandle( 2461 const Function& redirect_ctor = Function::ZoneHandle(I,
2456 cls.LookupConstructor(ctor_name)); 2462 cls.LookupConstructor(ctor_name));
2457 if (redirect_ctor.IsNull()) { 2463 if (redirect_ctor.IsNull()) {
2458 ErrorMsg(call_pos, "constructor '%s' not found", ctor_name.ToCString()); 2464 ErrorMsg(call_pos, "constructor '%s' not found", ctor_name.ToCString());
2459 } 2465 }
2460 String& error_message = String::Handle(isolate()); 2466 String& error_message = String::Handle(isolate());
2461 if (!redirect_ctor.AreValidArguments(arguments->length(), 2467 if (!redirect_ctor.AreValidArguments(arguments->length(),
2462 arguments->names(), 2468 arguments->names(),
2463 &error_message)) { 2469 &error_message)) {
2464 ErrorMsg(call_pos, 2470 ErrorMsg(call_pos,
2465 "invalid arguments passed to constructor '%s': %s", 2471 "invalid arguments passed to constructor '%s': %s",
(...skipping 11 matching lines...) Expand all
2477 const intptr_t ctor_pos = TokenPos(); 2483 const intptr_t ctor_pos = TokenPos();
2478 OpenFunctionBlock(func); 2484 OpenFunctionBlock(func);
2479 2485
2480 LocalVariable* receiver = new LocalVariable( 2486 LocalVariable* receiver = new LocalVariable(
2481 Scanner::kNoSourcePos, Symbols::This(), *ReceiverType(current_class())); 2487 Scanner::kNoSourcePos, Symbols::This(), *ReceiverType(current_class()));
2482 current_block_->scope->InsertParameterAt(0, receiver); 2488 current_block_->scope->InsertParameterAt(0, receiver);
2483 2489
2484 LocalVariable* phase_parameter = 2490 LocalVariable* phase_parameter =
2485 new LocalVariable(Scanner::kNoSourcePos, 2491 new LocalVariable(Scanner::kNoSourcePos,
2486 Symbols::PhaseParameter(), 2492 Symbols::PhaseParameter(),
2487 Type::ZoneHandle(Type::SmiType())); 2493 Type::ZoneHandle(I, Type::SmiType()));
2488 current_block_->scope->InsertParameterAt(1, phase_parameter); 2494 current_block_->scope->InsertParameterAt(1, phase_parameter);
2489 2495
2490 // Parse expressions of instance fields that have an explicit 2496 // Parse expressions of instance fields that have an explicit
2491 // initializer expression. 2497 // initializer expression.
2492 // The receiver must not be visible to field initializer expressions. 2498 // The receiver must not be visible to field initializer expressions.
2493 receiver->set_invisible(true); 2499 receiver->set_invisible(true);
2494 GrowableArray<Field*> initialized_fields; 2500 GrowableArray<Field*> initialized_fields;
2495 ParseInitializedInstanceFields( 2501 ParseInitializedInstanceFields(
2496 current_class(), receiver, &initialized_fields); 2502 current_class(), receiver, &initialized_fields);
2497 receiver->set_invisible(false); 2503 receiver->set_invisible(false);
(...skipping 19 matching lines...) Expand all
2517 ErrorMsg(ctor_pos, 2523 ErrorMsg(ctor_pos,
2518 "forwarding constructors must not have optional parameters"); 2524 "forwarding constructors must not have optional parameters");
2519 } 2525 }
2520 2526
2521 // Prepare user-defined arguments to be forwarded to super call. 2527 // Prepare user-defined arguments to be forwarded to super call.
2522 // The first user-defined argument is at position 2. 2528 // The first user-defined argument is at position 2.
2523 forwarding_args = new ArgumentListNode(Scanner::kNoSourcePos); 2529 forwarding_args = new ArgumentListNode(Scanner::kNoSourcePos);
2524 for (int i = 2; i < func.NumParameters(); i++) { 2530 for (int i = 2; i < func.NumParameters(); i++) {
2525 LocalVariable* param = new LocalVariable( 2531 LocalVariable* param = new LocalVariable(
2526 Scanner::kNoSourcePos, 2532 Scanner::kNoSourcePos,
2527 String::ZoneHandle(func.ParameterNameAt(i)), 2533 String::ZoneHandle(I, func.ParameterNameAt(i)),
2528 Type::ZoneHandle(Type::DynamicType())); 2534 Type::ZoneHandle(I, Type::DynamicType()));
2529 current_block_->scope->InsertParameterAt(i, param); 2535 current_block_->scope->InsertParameterAt(i, param);
2530 forwarding_args->Add(new LoadLocalNode(Scanner::kNoSourcePos, param)); 2536 forwarding_args->Add(new LoadLocalNode(Scanner::kNoSourcePos, param));
2531 } 2537 }
2532 } 2538 }
2533 2539
2534 GenerateSuperConstructorCall(current_class(), 2540 GenerateSuperConstructorCall(current_class(),
2535 Scanner::kNoSourcePos, 2541 Scanner::kNoSourcePos,
2536 receiver, 2542 receiver,
2537 forwarding_args); 2543 forwarding_args);
2538 CheckFieldsInitialized(current_class()); 2544 CheckFieldsInitialized(current_class());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 2598
2593 // Add implicit receiver parameter which is passed the allocated 2599 // Add implicit receiver parameter which is passed the allocated
2594 // but uninitialized instance to construct. 2600 // but uninitialized instance to construct.
2595 ASSERT(current_class().raw() == func.Owner()); 2601 ASSERT(current_class().raw() == func.Owner());
2596 params.AddReceiver(ReceiverType(current_class()), func.token_pos()); 2602 params.AddReceiver(ReceiverType(current_class()), func.token_pos());
2597 2603
2598 // Add implicit parameter for construction phase. 2604 // Add implicit parameter for construction phase.
2599 params.AddFinalParameter( 2605 params.AddFinalParameter(
2600 TokenPos(), 2606 TokenPos(),
2601 &Symbols::PhaseParameter(), 2607 &Symbols::PhaseParameter(),
2602 &Type::ZoneHandle(Type::SmiType())); 2608 &Type::ZoneHandle(I, Type::SmiType()));
2603 2609
2604 if (func.is_const()) { 2610 if (func.is_const()) {
2605 params.SetImplicitlyFinal(); 2611 params.SetImplicitlyFinal();
2606 } 2612 }
2607 ParseFormalParameterList(allow_explicit_default_values, false, &params); 2613 ParseFormalParameterList(allow_explicit_default_values, false, &params);
2608 2614
2609 SetupDefaultsForOptionalParams(&params, default_parameter_values); 2615 SetupDefaultsForOptionalParams(&params, default_parameter_values);
2610 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved()); 2616 ASSERT(AbstractType::Handle(isolate(), func.result_type()).IsResolved());
2611 ASSERT(func.NumParameters() == params.parameters->length()); 2617 ASSERT(func.NumParameters() == params.parameters->length());
2612 2618
(...skipping 26 matching lines...) Expand all
2639 } 2645 }
2640 2646
2641 // Turn formal field parameters into field initializers. 2647 // Turn formal field parameters into field initializers.
2642 if (params.has_field_initializer) { 2648 if (params.has_field_initializer) {
2643 // First two parameters are implicit receiver and phase. 2649 // First two parameters are implicit receiver and phase.
2644 ASSERT(params.parameters->length() >= 2); 2650 ASSERT(params.parameters->length() >= 2);
2645 for (int i = 2; i < params.parameters->length(); i++) { 2651 for (int i = 2; i < params.parameters->length(); i++) {
2646 ParamDesc& param = (*params.parameters)[i]; 2652 ParamDesc& param = (*params.parameters)[i];
2647 if (param.is_field_initializer) { 2653 if (param.is_field_initializer) {
2648 const String& field_name = *param.name; 2654 const String& field_name = *param.name;
2649 Field& field = Field::ZoneHandle(cls.LookupInstanceField(field_name)); 2655 Field& field =
2656 Field::ZoneHandle(I, cls.LookupInstanceField(field_name));
2650 if (field.IsNull()) { 2657 if (field.IsNull()) {
2651 ErrorMsg(param.name_pos, 2658 ErrorMsg(param.name_pos,
2652 "unresolved reference to instance field '%s'", 2659 "unresolved reference to instance field '%s'",
2653 field_name.ToCString()); 2660 field_name.ToCString());
2654 } 2661 }
2655 if (is_redirecting_constructor) { 2662 if (is_redirecting_constructor) {
2656 ErrorMsg(param.name_pos, 2663 ErrorMsg(param.name_pos,
2657 "redirecting constructors may not have " 2664 "redirecting constructors may not have "
2658 "initializing formal parameters"); 2665 "initializing formal parameters");
2659 } 2666 }
2660 CheckDuplicateFieldInit(param.name_pos, &initialized_fields, &field); 2667 CheckDuplicateFieldInit(param.name_pos, &initialized_fields, &field);
2661 2668
2662 if (!param.has_explicit_type) { 2669 if (!param.has_explicit_type) {
2663 const AbstractType& field_type = 2670 const AbstractType& field_type =
2664 AbstractType::ZoneHandle(field.type()); 2671 AbstractType::ZoneHandle(I, field.type());
2665 param.type = &field_type; 2672 param.type = &field_type;
2666 // Parameter type was already set to dynamic when parsing the class 2673 // Parameter type was already set to dynamic when parsing the class
2667 // declaration: fix it. 2674 // declaration: fix it.
2668 func.SetParameterTypeAt(i, field_type); 2675 func.SetParameterTypeAt(i, field_type);
2669 } 2676 }
2670 2677
2671 AstNode* instance = new LoadLocalNode(param.name_pos, receiver); 2678 AstNode* instance = new LoadLocalNode(param.name_pos, receiver);
2672 // Initializing formals cannot be used in the explicit initializer 2679 // Initializing formals cannot be used in the explicit initializer
2673 // list, nor can they be used in the constructor body. 2680 // list, nor can they be used in the constructor body.
2674 // Thus, they are set to be invisible when added to the scope. 2681 // Thus, they are set to be invisible when added to the scope.
(...skipping 21 matching lines...) Expand all
2696 // the target which executes the corresponding phase. 2703 // the target which executes the corresponding phase.
2697 current_block_->statements->Add(init_statements); 2704 current_block_->statements->Add(init_statements);
2698 } else if (init_statements->length() > 0) { 2705 } else if (init_statements->length() > 0) {
2699 // Generate guard around the initializer code. 2706 // Generate guard around the initializer code.
2700 LocalVariable* phase_param = LookupPhaseParameter(); 2707 LocalVariable* phase_param = LookupPhaseParameter();
2701 AstNode* phase_value = new 2708 AstNode* phase_value = new
2702 LoadLocalNode(Scanner::kNoSourcePos, phase_param); 2709 LoadLocalNode(Scanner::kNoSourcePos, phase_param);
2703 AstNode* phase_check = new BinaryOpNode( 2710 AstNode* phase_check = new BinaryOpNode(
2704 Scanner::kNoSourcePos, Token::kBIT_AND, phase_value, 2711 Scanner::kNoSourcePos, Token::kBIT_AND, phase_value,
2705 new LiteralNode(Scanner::kNoSourcePos, 2712 new LiteralNode(Scanner::kNoSourcePos,
2706 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); 2713 Smi::ZoneHandle(I, Smi::New(Function::kCtorPhaseInit))));
2707 AstNode* comparison = 2714 AstNode* comparison =
2708 new ComparisonNode(Scanner::kNoSourcePos, 2715 new ComparisonNode(Scanner::kNoSourcePos,
2709 Token::kNE_STRICT, 2716 Token::kNE_STRICT,
2710 phase_check, 2717 phase_check,
2711 new LiteralNode(TokenPos(), 2718 new LiteralNode(TokenPos(),
2712 Smi::ZoneHandle(Smi::New(0)))); 2719 Smi::ZoneHandle(I, Smi::New(0))));
2713 AstNode* guarded_init_statements = 2720 AstNode* guarded_init_statements =
2714 new IfNode(Scanner::kNoSourcePos, 2721 new IfNode(Scanner::kNoSourcePos,
2715 comparison, 2722 comparison,
2716 init_statements, 2723 init_statements,
2717 NULL); 2724 NULL);
2718 current_block_->statements->Add(guarded_init_statements); 2725 current_block_->statements->Add(guarded_init_statements);
2719 } 2726 }
2720 2727
2721 // Parsing of initializers done. Now we parse the constructor body 2728 // Parsing of initializers done. Now we parse the constructor body
2722 // and add the implicit super call to the super constructor's body 2729 // and add the implicit super call to the super constructor's body
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2764 } 2771 }
2765 } 2772 }
2766 OpenBlock(); // Block to collect constructor body nodes. 2773 OpenBlock(); // Block to collect constructor body nodes.
2767 intptr_t body_pos = TokenPos(); 2774 intptr_t body_pos = TokenPos();
2768 2775
2769 // Insert the implicit super call to the super constructor body. 2776 // Insert the implicit super call to the super constructor body.
2770 if (super_call != NULL) { 2777 if (super_call != NULL) {
2771 ArgumentListNode* initializer_args = super_call->arguments(); 2778 ArgumentListNode* initializer_args = super_call->arguments();
2772 const Function& super_ctor = super_call->function(); 2779 const Function& super_ctor = super_call->function();
2773 // Patch the initializer call so it only executes the super initializer. 2780 // Patch the initializer call so it only executes the super initializer.
2774 initializer_args->SetNodeAt(1, 2781 initializer_args->SetNodeAt(1, new LiteralNode(
2775 new LiteralNode(body_pos, 2782 body_pos, Smi::ZoneHandle(I, Smi::New(Function::kCtorPhaseInit))));
2776 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit))));
2777 2783
2778 ArgumentListNode* super_call_args = new ArgumentListNode(body_pos); 2784 ArgumentListNode* super_call_args = new ArgumentListNode(body_pos);
2779 // First argument is the receiver. 2785 // First argument is the receiver.
2780 super_call_args->Add(new LoadLocalNode(body_pos, receiver)); 2786 super_call_args->Add(new LoadLocalNode(body_pos, receiver));
2781 // Second argument is the construction phase argument. 2787 // Second argument is the construction phase argument.
2782 AstNode* phase_parameter = 2788 AstNode* phase_parameter = new(I) LiteralNode(
2783 new LiteralNode(body_pos, 2789 body_pos, Smi::ZoneHandle(I, Smi::New(Function::kCtorPhaseBody)));
2784 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody)));
2785 super_call_args->Add(phase_parameter); 2790 super_call_args->Add(phase_parameter);
2786 super_call_args->set_names(initializer_args->names()); 2791 super_call_args->set_names(initializer_args->names());
2787 for (int i = 2; i < initializer_args->length(); i++) { 2792 for (int i = 2; i < initializer_args->length(); i++) {
2788 AstNode* arg = initializer_args->NodeAt(i); 2793 AstNode* arg = initializer_args->NodeAt(i);
2789 if (arg->IsLiteralNode()) { 2794 if (arg->IsLiteralNode()) {
2790 LiteralNode* lit = arg->AsLiteralNode(); 2795 LiteralNode* lit = arg->AsLiteralNode();
2791 super_call_args->Add(new LiteralNode(body_pos, lit->literal())); 2796 super_call_args->Add(new LiteralNode(body_pos, lit->literal()));
2792 } else { 2797 } else {
2793 ASSERT(arg->IsLoadLocalNode() || arg->IsStoreLocalNode()); 2798 ASSERT(arg->IsLoadLocalNode() || arg->IsStoreLocalNode());
2794 if (arg->IsLoadLocalNode()) { 2799 if (arg->IsLoadLocalNode()) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 2885
2881 ParamList params; 2886 ParamList params;
2882 // An instance closure function may capture and access the receiver, but via 2887 // An instance closure function may capture and access the receiver, but via
2883 // the context and not via the first formal parameter. 2888 // the context and not via the first formal parameter.
2884 if (func.IsClosureFunction()) { 2889 if (func.IsClosureFunction()) {
2885 // The first parameter of a closure function is the closure object. 2890 // The first parameter of a closure function is the closure object.
2886 ASSERT(!func.is_const()); // Closure functions cannot be const. 2891 ASSERT(!func.is_const()); // Closure functions cannot be const.
2887 params.AddFinalParameter( 2892 params.AddFinalParameter(
2888 TokenPos(), 2893 TokenPos(),
2889 &Symbols::ClosureParameter(), 2894 &Symbols::ClosureParameter(),
2890 &Type::ZoneHandle(Type::DynamicType())); 2895 &Type::ZoneHandle(I, Type::DynamicType()));
2891 } else if (!func.is_static()) { 2896 } else if (!func.is_static()) {
2892 // Static functions do not have a receiver. 2897 // Static functions do not have a receiver.
2893 ASSERT(current_class().raw() == func.Owner()); 2898 ASSERT(current_class().raw() == func.Owner());
2894 params.AddReceiver(ReceiverType(current_class()), func.token_pos()); 2899 params.AddReceiver(ReceiverType(current_class()), func.token_pos());
2895 } else if (func.IsFactory()) { 2900 } else if (func.IsFactory()) {
2896 // The first parameter of a factory is the TypeArguments vector of 2901 // The first parameter of a factory is the TypeArguments vector of
2897 // the type of the instance to be allocated. 2902 // the type of the instance to be allocated.
2898 params.AddFinalParameter( 2903 params.AddFinalParameter(
2899 TokenPos(), 2904 TokenPos(),
2900 &Symbols::TypeArgumentsParameter(), 2905 &Symbols::TypeArgumentsParameter(),
2901 &Type::ZoneHandle(Type::DynamicType())); 2906 &Type::ZoneHandle(I, Type::DynamicType()));
2902 } 2907 }
2903 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction()); 2908 ASSERT((CurrentToken() == Token::kLPAREN) || func.IsGetterFunction());
2904 const bool allow_explicit_default_values = true; 2909 const bool allow_explicit_default_values = true;
2905 if (func.IsGetterFunction()) { 2910 if (func.IsGetterFunction()) {
2906 // Populate function scope with the formal parameters. Since in this case 2911 // Populate function scope with the formal parameters. Since in this case
2907 // we are compiling a getter this will at most populate the receiver. 2912 // we are compiling a getter this will at most populate the receiver.
2908 AddFormalParamsToScope(&params, current_block_->scope); 2913 AddFormalParamsToScope(&params, current_block_->scope);
2909 } else { 2914 } else {
2910 ParseFormalParameterList(allow_explicit_default_values, false, &params); 2915 ParseFormalParameterList(allow_explicit_default_values, false, &params);
2911 2916
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 const Class& owner = Class::Handle(isolate(), func.Owner()); 2985 const Class& owner = Class::Handle(isolate(), func.Owner());
2981 if (!owner.IsObjectClass()) { 2986 if (!owner.IsObjectClass()) {
2982 AddEqualityNullCheck(); 2987 AddEqualityNullCheck();
2983 } 2988 }
2984 } 2989 }
2985 ParseNativeFunctionBlock(&params, func); 2990 ParseNativeFunctionBlock(&params, func);
2986 end_token_pos = TokenPos(); 2991 end_token_pos = TokenPos();
2987 ExpectSemicolon(); 2992 ExpectSemicolon();
2988 } else if (func.is_external()) { 2993 } else if (func.is_external()) {
2989 // Body of an external method contains a single throw. 2994 // Body of an external method contains a single throw.
2990 const String& function_name = String::ZoneHandle(func.name()); 2995 const String& function_name = String::ZoneHandle(I, func.name());
2991 // TODO(regis): For an instance function, pass the receiver to 2996 // TODO(regis): For an instance function, pass the receiver to
2992 // NoSuchMethodError. 2997 // NoSuchMethodError.
2993 current_block_->statements->Add( 2998 current_block_->statements->Add(
2994 ThrowNoSuchMethodError(TokenPos(), 2999 ThrowNoSuchMethodError(TokenPos(),
2995 current_class(), 3000 current_class(),
2996 function_name, 3001 function_name,
2997 NULL, // No arguments. 3002 NULL, // No arguments.
2998 func.is_static() ? 3003 func.is_static() ?
2999 InvocationMirror::kStatic : 3004 InvocationMirror::kStatic :
3000 InvocationMirror::kDynamic, 3005 InvocationMirror::kDynamic,
(...skipping 13 matching lines...) Expand all
3014 last_used_try_index_ = saved_try_index; 3019 last_used_try_index_ = saved_try_index;
3015 return CloseBlock(); 3020 return CloseBlock();
3016 } 3021 }
3017 3022
3018 3023
3019 void Parser::AddEqualityNullCheck() { 3024 void Parser::AddEqualityNullCheck() {
3020 AstNode* argument = 3025 AstNode* argument =
3021 new LoadLocalNode(Scanner::kNoSourcePos, 3026 new LoadLocalNode(Scanner::kNoSourcePos,
3022 current_block_->scope->parent()->VariableAt(1)); 3027 current_block_->scope->parent()->VariableAt(1));
3023 LiteralNode* null_operand = 3028 LiteralNode* null_operand =
3024 new LiteralNode(Scanner::kNoSourcePos, Instance::ZoneHandle()); 3029 new LiteralNode(Scanner::kNoSourcePos, Instance::ZoneHandle(I));
3025 ComparisonNode* check_arg = 3030 ComparisonNode* check_arg =
3026 new ComparisonNode(Scanner::kNoSourcePos, 3031 new ComparisonNode(Scanner::kNoSourcePos,
3027 Token::kEQ_STRICT, 3032 Token::kEQ_STRICT,
3028 argument, 3033 argument,
3029 null_operand); 3034 null_operand);
3030 ComparisonNode* result = 3035 ComparisonNode* result =
3031 new ComparisonNode(Scanner::kNoSourcePos, 3036 new ComparisonNode(Scanner::kNoSourcePos,
3032 Token::kEQ_STRICT, 3037 Token::kEQ_STRICT,
3033 LoadReceiver(Scanner::kNoSourcePos), 3038 LoadReceiver(Scanner::kNoSourcePos),
3034 null_operand); 3039 null_operand);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 qual_ident->ident_pos = TokenPos(); 3101 qual_ident->ident_pos = TokenPos();
3097 qual_ident->ident = CurrentLiteral(); 3102 qual_ident->ident = CurrentLiteral();
3098 qual_ident->lib_prefix = NULL; 3103 qual_ident->lib_prefix = NULL;
3099 ConsumeToken(); 3104 ConsumeToken();
3100 if (CurrentToken() == Token::kPERIOD) { 3105 if (CurrentToken() == Token::kPERIOD) {
3101 // An identifier cannot be resolved in a local scope when top level parsing. 3106 // An identifier cannot be resolved in a local scope when top level parsing.
3102 if (is_top_level_ || 3107 if (is_top_level_ ||
3103 !ResolveIdentInLocalScope(qual_ident->ident_pos, 3108 !ResolveIdentInLocalScope(qual_ident->ident_pos,
3104 *(qual_ident->ident), 3109 *(qual_ident->ident),
3105 NULL)) { 3110 NULL)) {
3106 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(); 3111 LibraryPrefix& lib_prefix = LibraryPrefix::ZoneHandle(I);
3107 if (!current_class().IsMixinApplication()) { 3112 if (!current_class().IsMixinApplication()) {
3108 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident)); 3113 lib_prefix = current_class().LookupLibraryPrefix(*(qual_ident->ident));
3109 } else { 3114 } else {
3110 // TODO(hausner): Should we resolve the prefix via the library scope 3115 // TODO(hausner): Should we resolve the prefix via the library scope
3111 // rather than via the class? 3116 // rather than via the class?
3112 Class& cls = Class::Handle(isolate(), 3117 Class& cls = Class::Handle(isolate(),
3113 parsed_function()->function().origin()); 3118 parsed_function()->function().origin());
3114 lib_prefix = cls.LookupLibraryPrefix(*(qual_ident->ident)); 3119 lib_prefix = cls.LookupLibraryPrefix(*(qual_ident->ident));
3115 } 3120 }
3116 if (!lib_prefix.IsNull()) { 3121 if (!lib_prefix.IsNull()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 method->params.Clear(); 3171 method->params.Clear();
3167 // Static functions do not have a receiver. 3172 // Static functions do not have a receiver.
3168 // The first parameter of a factory is the TypeArguments vector of 3173 // The first parameter of a factory is the TypeArguments vector of
3169 // the type of the instance to be allocated. 3174 // the type of the instance to be allocated.
3170 if (!method->has_static || method->IsConstructor()) { 3175 if (!method->has_static || method->IsConstructor()) {
3171 method->params.AddReceiver(ReceiverType(current_class()), formal_param_pos); 3176 method->params.AddReceiver(ReceiverType(current_class()), formal_param_pos);
3172 } else if (method->IsFactory()) { 3177 } else if (method->IsFactory()) {
3173 method->params.AddFinalParameter( 3178 method->params.AddFinalParameter(
3174 formal_param_pos, 3179 formal_param_pos,
3175 &Symbols::TypeArgumentsParameter(), 3180 &Symbols::TypeArgumentsParameter(),
3176 &Type::ZoneHandle(Type::DynamicType())); 3181 &Type::ZoneHandle(I, Type::DynamicType()));
3177 } 3182 }
3178 // Constructors have an implicit parameter for the construction phase. 3183 // Constructors have an implicit parameter for the construction phase.
3179 if (method->IsConstructor()) { 3184 if (method->IsConstructor()) {
3180 method->params.AddFinalParameter( 3185 method->params.AddFinalParameter(
3181 TokenPos(), 3186 TokenPos(),
3182 &Symbols::PhaseParameter(), 3187 &Symbols::PhaseParameter(),
3183 &Type::ZoneHandle(Type::SmiType())); 3188 &Type::ZoneHandle(I, Type::SmiType()));
3184 } 3189 }
3185 if (are_implicitly_final) { 3190 if (are_implicitly_final) {
3186 method->params.SetImplicitlyFinal(); 3191 method->params.SetImplicitlyFinal();
3187 } 3192 }
3188 if (!method->IsGetter()) { 3193 if (!method->IsGetter()) {
3189 ParseFormalParameterList(allow_explicit_default_values, 3194 ParseFormalParameterList(allow_explicit_default_values,
3190 false, 3195 false,
3191 &method->params); 3196 &method->params);
3192 } 3197 }
3193 3198
(...skipping 10 matching lines...) Expand all
3204 CheckOperatorArity(*method); 3209 CheckOperatorArity(*method);
3205 } 3210 }
3206 3211
3207 // Mangle the name for getter and setter functions and check function 3212 // Mangle the name for getter and setter functions and check function
3208 // arity. 3213 // arity.
3209 if (method->IsGetter() || method->IsSetter()) { 3214 if (method->IsGetter() || method->IsSetter()) {
3210 int expected_num_parameters = 0; 3215 int expected_num_parameters = 0;
3211 if (method->IsGetter()) { 3216 if (method->IsGetter()) {
3212 expected_num_parameters = (method->has_static) ? 0 : 1; 3217 expected_num_parameters = (method->has_static) ? 0 : 1;
3213 method->dict_name = method->name; 3218 method->dict_name = method->name;
3214 method->name = &String::ZoneHandle(Field::GetterSymbol(*method->name)); 3219 method->name = &String::ZoneHandle(I, Field::GetterSymbol(*method->name));
3215 } else { 3220 } else {
3216 ASSERT(method->IsSetter()); 3221 ASSERT(method->IsSetter());
3217 expected_num_parameters = (method->has_static) ? 1 : 2; 3222 expected_num_parameters = (method->has_static) ? 1 : 2;
3218 method->dict_name = 3223 method->dict_name = &String::ZoneHandle(I,
3219 &String::ZoneHandle(String::Concat(*method->name, Symbols::Equals())); 3224 String::Concat(*method->name, Symbols::Equals()));
3220 method->name = &String::ZoneHandle(Field::SetterSymbol(*method->name)); 3225 method->name = &String::ZoneHandle(I, Field::SetterSymbol(*method->name));
3221 } 3226 }
3222 if ((method->params.num_fixed_parameters != expected_num_parameters) || 3227 if ((method->params.num_fixed_parameters != expected_num_parameters) ||
3223 (method->params.num_optional_parameters != 0)) { 3228 (method->params.num_optional_parameters != 0)) {
3224 ErrorMsg(method->name_pos, "illegal %s parameters", 3229 ErrorMsg(method->name_pos, "illegal %s parameters",
3225 method->IsGetter() ? "getter" : "setter"); 3230 method->IsGetter() ? "getter" : "setter");
3226 } 3231 }
3227 } 3232 }
3228 3233
3229 // Parse redirecting factory constructor. 3234 // Parse redirecting factory constructor.
3230 Type& redirection_type = Type::Handle(isolate()); 3235 Type& redirection_type = Type::Handle(isolate());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 // Redirected constructor: either this(...) or this.xxx(...). 3276 // Redirected constructor: either this(...) or this.xxx(...).
3272 is_redirecting = true; 3277 is_redirecting = true;
3273 if (method->params.has_field_initializer) { 3278 if (method->params.has_field_initializer) {
3274 // Constructors that redirect to another constructor must not 3279 // Constructors that redirect to another constructor must not
3275 // initialize any fields using field initializer parameters. 3280 // initialize any fields using field initializer parameters.
3276 ErrorMsg(formal_param_pos, "Redirecting constructor " 3281 ErrorMsg(formal_param_pos, "Redirecting constructor "
3277 "may not use field initializer parameters"); 3282 "may not use field initializer parameters");
3278 } 3283 }
3279 ConsumeToken(); // Colon. 3284 ConsumeToken(); // Colon.
3280 ExpectToken(Token::kTHIS); 3285 ExpectToken(Token::kTHIS);
3281 String& redir_name = String::ZoneHandle( 3286 String& redir_name = String::ZoneHandle(I,
3282 String::Concat(members->class_name(), Symbols::Dot())); 3287 String::Concat(members->class_name(), Symbols::Dot()));
3283 if (CurrentToken() == Token::kPERIOD) { 3288 if (CurrentToken() == Token::kPERIOD) {
3284 ConsumeToken(); 3289 ConsumeToken();
3285 redir_name = String::Concat(redir_name, 3290 redir_name = String::Concat(redir_name,
3286 *ExpectIdentifier("constructor name expected")); 3291 *ExpectIdentifier("constructor name expected"));
3287 } 3292 }
3288 method->redirect_name = &redir_name; 3293 method->redirect_name = &redir_name;
3289 CheckToken(Token::kLPAREN); 3294 CheckToken(Token::kLPAREN);
3290 SkipToMatchingParenthesis(); 3295 SkipToMatchingParenthesis();
3291 } else { 3296 } else {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
3457 ErrorMsg("keyword 'external' not allowed in field declaration"); 3462 ErrorMsg("keyword 'external' not allowed in field declaration");
3458 } 3463 }
3459 if (field->has_factory) { 3464 if (field->has_factory) {
3460 ErrorMsg("keyword 'factory' not allowed in field declaration"); 3465 ErrorMsg("keyword 'factory' not allowed in field declaration");
3461 } 3466 }
3462 if (!field->has_static && field->has_const) { 3467 if (!field->has_static && field->has_const) {
3463 ErrorMsg(field->name_pos, "instance field may not be 'const'"); 3468 ErrorMsg(field->name_pos, "instance field may not be 'const'");
3464 } 3469 }
3465 Function& getter = Function::Handle(isolate()); 3470 Function& getter = Function::Handle(isolate());
3466 Function& setter = Function::Handle(isolate()); 3471 Function& setter = Function::Handle(isolate());
3467 Field& class_field = Field::ZoneHandle(); 3472 Field& class_field = Field::ZoneHandle(I);
3468 Instance& init_value = Instance::Handle(isolate()); 3473 Instance& init_value = Instance::Handle(isolate());
3469 while (true) { 3474 while (true) {
3470 bool has_initializer = CurrentToken() == Token::kASSIGN; 3475 bool has_initializer = CurrentToken() == Token::kASSIGN;
3471 bool has_simple_literal = false; 3476 bool has_simple_literal = false;
3472 if (has_initializer) { 3477 if (has_initializer) {
3473 ConsumeToken(); 3478 ConsumeToken();
3474 init_value = Object::sentinel().raw(); 3479 init_value = Object::sentinel().raw();
3475 // For static fields, the initialization expression will be parsed 3480 // For static fields, the initialization expression will be parsed
3476 // through the kImplicitStaticFinalGetter method invocation/compilation. 3481 // through the kImplicitStaticFinalGetter method invocation/compilation.
3477 // For instance fields, the expression is parsed when a constructor 3482 // For instance fields, the expression is parsed when a constructor
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3528 /* is_abstract = */ false, 3533 /* is_abstract = */ false,
3529 /* is_external = */ false, 3534 /* is_external = */ false,
3530 /* is_native = */ false, 3535 /* is_native = */ false,
3531 current_class(), 3536 current_class(),
3532 field->name_pos); 3537 field->name_pos);
3533 getter.set_result_type(*field->type); 3538 getter.set_result_type(*field->type);
3534 members->AddFunction(getter); 3539 members->AddFunction(getter);
3535 3540
3536 // Create initializer function for non-const fields. 3541 // Create initializer function for non-const fields.
3537 if (!class_field.is_const()) { 3542 if (!class_field.is_const()) {
3538 const Function& init_function = Function::ZoneHandle( 3543 const Function& init_function = Function::ZoneHandle(I,
3539 Function::NewStaticInitializer(class_field)); 3544 Function::NewStaticInitializer(class_field));
3540 members->AddFunction(init_function); 3545 members->AddFunction(init_function);
3541 } 3546 }
3542 } 3547 }
3543 } 3548 }
3544 3549
3545 // For instance fields, we create implicit getter and setter methods. 3550 // For instance fields, we create implicit getter and setter methods.
3546 if (!field->has_static) { 3551 if (!field->has_static) {
3547 String& getter_name = String::Handle(isolate(), 3552 String& getter_name = String::Handle(isolate(),
3548 Field::GetterSymbol(*field->name)); 3553 Field::GetterSymbol(*field->name));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 if (CurrentToken() == Token::kVAR) { 3676 if (CurrentToken() == Token::kVAR) {
3672 if (member.has_const) { 3677 if (member.has_const) {
3673 ErrorMsg("identifier expected after 'const'"); 3678 ErrorMsg("identifier expected after 'const'");
3674 } 3679 }
3675 if (member.has_final) { 3680 if (member.has_final) {
3676 ErrorMsg("identifier expected after 'final'"); 3681 ErrorMsg("identifier expected after 'final'");
3677 } 3682 }
3678 ConsumeToken(); 3683 ConsumeToken();
3679 member.has_var = true; 3684 member.has_var = true;
3680 // The member type is the 'dynamic' type. 3685 // The member type is the 'dynamic' type.
3681 member.type = &Type::ZoneHandle(Type::DynamicType()); 3686 member.type = &Type::ZoneHandle(I, Type::DynamicType());
3682 } else if (CurrentToken() == Token::kFACTORY) { 3687 } else if (CurrentToken() == Token::kFACTORY) {
3683 ConsumeToken(); 3688 ConsumeToken();
3684 if (member.has_static) { 3689 if (member.has_static) {
3685 ErrorMsg("factory method cannot be explicitly marked static"); 3690 ErrorMsg("factory method cannot be explicitly marked static");
3686 } 3691 }
3687 member.has_factory = true; 3692 member.has_factory = true;
3688 member.has_static = true; 3693 member.has_static = true;
3689 // The result type depends on the name of the factory method. 3694 // The result type depends on the name of the factory method.
3690 } 3695 }
3691 // Optionally parse a type. 3696 // Optionally parse a type.
3692 if (CurrentToken() == Token::kVOID) { 3697 if (CurrentToken() == Token::kVOID) {
3693 if (member.has_var || member.has_factory) { 3698 if (member.has_var || member.has_factory) {
3694 ErrorMsg("void not expected"); 3699 ErrorMsg("void not expected");
3695 } 3700 }
3696 ConsumeToken(); 3701 ConsumeToken();
3697 ASSERT(member.type == NULL); 3702 ASSERT(member.type == NULL);
3698 member.type = &Type::ZoneHandle(Type::VoidType()); 3703 member.type = &Type::ZoneHandle(I, Type::VoidType());
3699 } else if (CurrentToken() == Token::kIDENT) { 3704 } else if (CurrentToken() == Token::kIDENT) {
3700 // This is either a type name or the name of a method/constructor/field. 3705 // This is either a type name or the name of a method/constructor/field.
3701 if ((member.type == NULL) && !member.has_factory) { 3706 if ((member.type == NULL) && !member.has_factory) {
3702 // We have not seen a member type yet, so we check if the next 3707 // We have not seen a member type yet, so we check if the next
3703 // identifier could represent a type before parsing it. 3708 // identifier could represent a type before parsing it.
3704 Token::Kind follower = LookaheadToken(1); 3709 Token::Kind follower = LookaheadToken(1);
3705 // We have an identifier followed by a 'follower' token. 3710 // We have an identifier followed by a 'follower' token.
3706 // We either parse a type or assume that no type is specified. 3711 // We either parse a type or assume that no type is specified.
3707 if ((follower == Token::kLT) || // Parameterized type. 3712 if ((follower == Token::kLT) || // Parameterized type.
3708 (follower == Token::kGET) || // Getter following a type. 3713 (follower == Token::kGET) || // Getter following a type.
3709 (follower == Token::kSET) || // Setter following a type. 3714 (follower == Token::kSET) || // Setter following a type.
3710 (follower == Token::kOPERATOR) || // Operator following a type. 3715 (follower == Token::kOPERATOR) || // Operator following a type.
3711 (Token::IsIdentifier(follower)) || // Member name following a type. 3716 (Token::IsIdentifier(follower)) || // Member name following a type.
3712 ((follower == Token::kPERIOD) && // Qualified class name of type, 3717 ((follower == Token::kPERIOD) && // Qualified class name of type,
3713 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr. 3718 (LookaheadToken(3) != Token::kLPAREN))) { // but not a named constr.
3714 ASSERT(is_top_level_); 3719 ASSERT(is_top_level_);
3715 // The declared type of fields is never ignored, even in unchecked mode, 3720 // The declared type of fields is never ignored, even in unchecked mode,
3716 // because getters and setters could be closurized at some time (not 3721 // because getters and setters could be closurized at some time (not
3717 // supported yet). 3722 // supported yet).
3718 member.type = &AbstractType::ZoneHandle( 3723 member.type = &AbstractType::ZoneHandle(I,
3719 ParseType(ClassFinalizer::kResolveTypeParameters)); 3724 ParseType(ClassFinalizer::kResolveTypeParameters));
3720 } 3725 }
3721 } 3726 }
3722 } 3727 }
3723 3728
3724 // Optionally parse a (possibly named) constructor name or factory. 3729 // Optionally parse a (possibly named) constructor name or factory.
3725 if (IsIdentifier() && 3730 if (IsIdentifier() &&
3726 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) { 3731 (CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
3727 member.name_pos = TokenPos(); 3732 member.name_pos = TokenPos();
3728 member.name = CurrentLiteral(); // Unqualified identifier. 3733 member.name = CurrentLiteral(); // Unqualified identifier.
(...skipping 13 matching lines...) Expand all
3742 } 3747 }
3743 // Do not bypass class resolution by using current_class() directly, since 3748 // Do not bypass class resolution by using current_class() directly, since
3744 // it may be a patch class. 3749 // it may be a patch class.
3745 const Object& result_type_class = Object::Handle(isolate(), 3750 const Object& result_type_class = Object::Handle(isolate(),
3746 UnresolvedClass::New(LibraryPrefix::Handle(isolate()), 3751 UnresolvedClass::New(LibraryPrefix::Handle(isolate()),
3747 *member.name, 3752 *member.name,
3748 member.name_pos)); 3753 member.name_pos));
3749 // The type arguments of the result type are the type parameters of the 3754 // The type arguments of the result type are the type parameters of the
3750 // current class. Note that in the case of a patch class, they are copied 3755 // current class. Note that in the case of a patch class, they are copied
3751 // from the class being patched. 3756 // from the class being patched.
3752 member.type = &Type::ZoneHandle(Type::New( 3757 member.type = &Type::ZoneHandle(I, Type::New(
3753 result_type_class, 3758 result_type_class,
3754 TypeArguments::Handle(isolate(), current_class().type_parameters()), 3759 TypeArguments::Handle(isolate(), current_class().type_parameters()),
3755 member.name_pos)); 3760 member.name_pos));
3756 3761
3757 // We must be dealing with a constructor or named constructor. 3762 // We must be dealing with a constructor or named constructor.
3758 member.kind = RawFunction::kConstructor; 3763 member.kind = RawFunction::kConstructor;
3759 *member.name = String::Concat(*member.name, Symbols::Dot()); 3764 *member.name = String::Concat(*member.name, Symbols::Dot());
3760 if (CurrentToken() == Token::kPERIOD) { 3765 if (CurrentToken() == Token::kPERIOD) {
3761 // Named constructor. 3766 // Named constructor.
3762 ConsumeToken(); 3767 ConsumeToken();
(...skipping 20 matching lines...) Expand all
3783 (LookaheadToken(1) != Token::kCOMMA) && 3788 (LookaheadToken(1) != Token::kCOMMA) &&
3784 (LookaheadToken(1) != Token::kSEMICOLON)) { 3789 (LookaheadToken(1) != Token::kSEMICOLON)) {
3785 ConsumeToken(); 3790 ConsumeToken();
3786 member.kind = RawFunction::kSetterFunction; 3791 member.kind = RawFunction::kSetterFunction;
3787 member.name_pos = this->TokenPos(); 3792 member.name_pos = this->TokenPos();
3788 member.name = ExpectIdentifier("identifier expected"); 3793 member.name = ExpectIdentifier("identifier expected");
3789 CheckToken(Token::kLPAREN); 3794 CheckToken(Token::kLPAREN);
3790 // The grammar allows a return type, so member.type is not always NULL here. 3795 // The grammar allows a return type, so member.type is not always NULL here.
3791 // If no return type is specified, the return type of the setter is dynamic. 3796 // If no return type is specified, the return type of the setter is dynamic.
3792 if (member.type == NULL) { 3797 if (member.type == NULL) {
3793 member.type = &Type::ZoneHandle(Type::DynamicType()); 3798 member.type = &Type::ZoneHandle(I, Type::DynamicType());
3794 } 3799 }
3795 } else if ((CurrentToken() == Token::kOPERATOR) && !member.has_var && 3800 } else if ((CurrentToken() == Token::kOPERATOR) && !member.has_var &&
3796 (LookaheadToken(1) != Token::kLPAREN) && 3801 (LookaheadToken(1) != Token::kLPAREN) &&
3797 (LookaheadToken(1) != Token::kASSIGN) && 3802 (LookaheadToken(1) != Token::kASSIGN) &&
3798 (LookaheadToken(1) != Token::kCOMMA) && 3803 (LookaheadToken(1) != Token::kCOMMA) &&
3799 (LookaheadToken(1) != Token::kSEMICOLON)) { 3804 (LookaheadToken(1) != Token::kSEMICOLON)) {
3800 ConsumeToken(); 3805 ConsumeToken();
3801 if (!Token::CanBeOverloaded(CurrentToken())) { 3806 if (!Token::CanBeOverloaded(CurrentToken())) {
3802 ErrorMsg("invalid operator overloading"); 3807 ErrorMsg("invalid operator overloading");
3803 } 3808 }
3804 if (member.has_static) { 3809 if (member.has_static) {
3805 ErrorMsg("operator overloading functions cannot be static"); 3810 ErrorMsg("operator overloading functions cannot be static");
3806 } 3811 }
3807 member.operator_token = CurrentToken(); 3812 member.operator_token = CurrentToken();
3808 member.has_operator = true; 3813 member.has_operator = true;
3809 member.kind = RawFunction::kRegularFunction; 3814 member.kind = RawFunction::kRegularFunction;
3810 member.name_pos = this->TokenPos(); 3815 member.name_pos = this->TokenPos();
3811 member.name = 3816 member.name =
3812 &String::ZoneHandle(Symbols::New(Token::Str(member.operator_token))); 3817 &String::ZoneHandle(I, Symbols::New(Token::Str(member.operator_token)));
3813 ConsumeToken(); 3818 ConsumeToken();
3814 } else if (IsIdentifier()) { 3819 } else if (IsIdentifier()) {
3815 member.name = CurrentLiteral(); 3820 member.name = CurrentLiteral();
3816 member.name_pos = TokenPos(); 3821 member.name_pos = TokenPos();
3817 ConsumeToken(); 3822 ConsumeToken();
3818 } else { 3823 } else {
3819 ErrorMsg("identifier expected"); 3824 ErrorMsg("identifier expected");
3820 } 3825 }
3821 3826
3822 ASSERT(member.name != NULL); 3827 ASSERT(member.name != NULL);
3823 if (CurrentToken() == Token::kLPAREN || member.IsGetter()) { 3828 if (CurrentToken() == Token::kLPAREN || member.IsGetter()) {
3824 // Constructor or method. 3829 // Constructor or method.
3825 if (member.type == NULL) { 3830 if (member.type == NULL) {
3826 member.type = &Type::ZoneHandle(Type::DynamicType()); 3831 member.type = &Type::ZoneHandle(I, Type::DynamicType());
3827 } 3832 }
3828 ASSERT(member.IsFactory() == member.has_factory); 3833 ASSERT(member.IsFactory() == member.has_factory);
3829 ParseMethodOrConstructor(members, &member); 3834 ParseMethodOrConstructor(members, &member);
3830 } else if (CurrentToken() == Token::kSEMICOLON || 3835 } else if (CurrentToken() == Token::kSEMICOLON ||
3831 CurrentToken() == Token::kCOMMA || 3836 CurrentToken() == Token::kCOMMA ||
3832 CurrentToken() == Token::kASSIGN) { 3837 CurrentToken() == Token::kASSIGN) {
3833 // Field definition. 3838 // Field definition.
3834 if (member.has_const) { 3839 if (member.has_const) {
3835 // const fields are implicitly final. 3840 // const fields are implicitly final.
3836 member.has_final = true; 3841 member.has_final = true;
3837 } 3842 }
3838 if (member.type == NULL) { 3843 if (member.type == NULL) {
3839 if (member.has_final) { 3844 if (member.has_final) {
3840 member.type = &Type::ZoneHandle(Type::DynamicType()); 3845 member.type = &Type::ZoneHandle(I, Type::DynamicType());
3841 } else { 3846 } else {
3842 ErrorMsg("missing 'var', 'final', 'const' or type" 3847 ErrorMsg("missing 'var', 'final', 'const' or type"
3843 " in field declaration"); 3848 " in field declaration");
3844 } 3849 }
3845 } 3850 }
3846 ParseFieldDefinition(members, &member); 3851 ParseFieldDefinition(members, &member);
3847 } else { 3852 } else {
3848 UnexpectedToken(); 3853 UnexpectedToken();
3849 } 3854 }
3850 current_member_ = NULL; 3855 current_member_ = NULL;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
4083 if (!orig_class.ApplyPatch(cls, &error)) { 4088 if (!orig_class.ApplyPatch(cls, &error)) {
4084 AppendErrorMsg(error, class_pos, "applying patch failed"); 4089 AppendErrorMsg(error, class_pos, "applying patch failed");
4085 } 4090 }
4086 } 4091 }
4087 } 4092 }
4088 4093
4089 4094
4090 // Add an implicit constructor to the given class. 4095 // Add an implicit constructor to the given class.
4091 void Parser::AddImplicitConstructor(const Class& cls) { 4096 void Parser::AddImplicitConstructor(const Class& cls) {
4092 // The implicit constructor is unnamed, has no explicit parameter. 4097 // The implicit constructor is unnamed, has no explicit parameter.
4093 String& ctor_name = String::ZoneHandle(cls.Name()); 4098 String& ctor_name = String::ZoneHandle(I, cls.Name());
4094 ctor_name = String::Concat(ctor_name, Symbols::Dot()); 4099 ctor_name = String::Concat(ctor_name, Symbols::Dot());
4095 ctor_name = Symbols::New(ctor_name); 4100 ctor_name = Symbols::New(ctor_name);
4096 // To indicate that this is an implicit constructor, we set the 4101 // To indicate that this is an implicit constructor, we set the
4097 // token position and end token position of the function 4102 // token position and end token position of the function
4098 // to the token position of the class. 4103 // to the token position of the class.
4099 Function& ctor = Function::Handle(isolate(), 4104 Function& ctor = Function::Handle(isolate(),
4100 Function::New(ctor_name, 4105 Function::New(ctor_name,
4101 RawFunction::kConstructor, 4106 RawFunction::kConstructor,
4102 /* is_static = */ false, 4107 /* is_static = */ false,
4103 /* is_const = */ false, 4108 /* is_const = */ false,
4104 /* is_abstract = */ false, 4109 /* is_abstract = */ false,
4105 /* is_external = */ false, 4110 /* is_external = */ false,
4106 /* is_native = */ false, 4111 /* is_native = */ false,
4107 cls, 4112 cls,
4108 cls.token_pos())); 4113 cls.token_pos()));
4109 ctor.set_end_token_pos(ctor.token_pos()); 4114 ctor.set_end_token_pos(ctor.token_pos());
4110 if (library_.is_dart_scheme() && library_.IsPrivate(ctor_name)) { 4115 if (library_.is_dart_scheme() && library_.IsPrivate(ctor_name)) {
4111 ctor.set_is_visible(false); 4116 ctor.set_is_visible(false);
4112 } 4117 }
4113 4118
4114 ParamList params; 4119 ParamList params;
4115 // Add implicit 'this' parameter. 4120 // Add implicit 'this' parameter.
4116 const AbstractType* receiver_type = ReceiverType(cls); 4121 const AbstractType* receiver_type = ReceiverType(cls);
4117 params.AddReceiver(receiver_type, cls.token_pos()); 4122 params.AddReceiver(receiver_type, cls.token_pos());
4118 // Add implicit parameter for construction phase. 4123 // Add implicit parameter for construction phase.
4119 params.AddFinalParameter(cls.token_pos(), 4124 params.AddFinalParameter(cls.token_pos(),
4120 &Symbols::PhaseParameter(), 4125 &Symbols::PhaseParameter(),
4121 &Type::ZoneHandle(Type::SmiType())); 4126 &Type::ZoneHandle(I, Type::SmiType()));
4122 4127
4123 AddFormalParamsToFunction(&params, ctor); 4128 AddFormalParamsToFunction(&params, ctor);
4124 // The body of the constructor cannot modify the type of the constructed 4129 // The body of the constructor cannot modify the type of the constructed
4125 // instance, which is passed in as the receiver. 4130 // instance, which is passed in as the receiver.
4126 ctor.set_result_type(*receiver_type); 4131 ctor.set_result_type(*receiver_type);
4127 cls.AddFunction(ctor); 4132 cls.AddFunction(ctor);
4128 } 4133 }
4129 4134
4130 4135
4131 // Check for cycles in constructor redirection. 4136 // Check for cycles in constructor redirection.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
4320 &result_type); 4325 &result_type);
4321 } 4326 }
4322 // Parse the formal parameters of the function type. 4327 // Parse the formal parameters of the function type.
4323 CheckToken(Token::kLPAREN, "formal parameter list expected"); 4328 CheckToken(Token::kLPAREN, "formal parameter list expected");
4324 ParamList func_params; 4329 ParamList func_params;
4325 4330
4326 // Add implicit closure object parameter. 4331 // Add implicit closure object parameter.
4327 func_params.AddFinalParameter( 4332 func_params.AddFinalParameter(
4328 TokenPos(), 4333 TokenPos(),
4329 &Symbols::ClosureParameter(), 4334 &Symbols::ClosureParameter(),
4330 &Type::ZoneHandle(Type::DynamicType())); 4335 &Type::ZoneHandle(I, Type::DynamicType()));
4331 4336
4332 const bool no_explicit_default_values = false; 4337 const bool no_explicit_default_values = false;
4333 ParseFormalParameterList(no_explicit_default_values, false, &func_params); 4338 ParseFormalParameterList(no_explicit_default_values, false, &func_params);
4334 ExpectSemicolon(); 4339 ExpectSemicolon();
4335 // The field 'is_static' has no meaning for signature functions. 4340 // The field 'is_static' has no meaning for signature functions.
4336 Function& signature_function = Function::Handle(isolate(), 4341 Function& signature_function = Function::Handle(isolate(),
4337 Function::New(*alias_name, 4342 Function::New(*alias_name,
4338 RawFunction::kSignatureFunction, 4343 RawFunction::kSignatureFunction,
4339 /* is_static = */ false, 4344 /* is_static = */ false,
4340 /* is_const = */ false, 4345 /* is_const = */ false,
(...skipping 10 matching lines...) Expand all
4351 4356
4352 const String& signature = String::Handle(isolate(), 4357 const String& signature = String::Handle(isolate(),
4353 signature_function.Signature()); 4358 signature_function.Signature());
4354 if (FLAG_trace_parser) { 4359 if (FLAG_trace_parser) {
4355 OS::Print("TopLevel parsing function type alias '%s'\n", 4360 OS::Print("TopLevel parsing function type alias '%s'\n",
4356 signature.ToCString()); 4361 signature.ToCString());
4357 } 4362 }
4358 // Lookup the signature class, i.e. the class whose name is the signature. 4363 // Lookup the signature class, i.e. the class whose name is the signature.
4359 // We only lookup in the current library, but not in its imports, and only 4364 // We only lookup in the current library, but not in its imports, and only
4360 // create a new canonical signature class if it does not exist yet. 4365 // create a new canonical signature class if it does not exist yet.
4361 Class& signature_class = Class::ZoneHandle( 4366 Class& signature_class = Class::ZoneHandle(I,
4362 library_.LookupLocalClass(signature)); 4367 library_.LookupLocalClass(signature));
4363 if (signature_class.IsNull()) { 4368 if (signature_class.IsNull()) {
4364 signature_class = Class::NewSignatureClass(signature, 4369 signature_class = Class::NewSignatureClass(signature,
4365 signature_function, 4370 signature_function,
4366 script_, 4371 script_,
4367 alias_name_pos); 4372 alias_name_pos);
4368 // Record the function signature class in the current library. 4373 // Record the function signature class in the current library.
4369 library_.AddClass(signature_class); 4374 library_.AddClass(signature_class);
4370 } else { 4375 } else {
4371 // Forget the just created signature function and use the existing one. 4376 // Forget the just created signature function and use the existing one.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 } 4623 }
4619 4624
4620 4625
4621 void Parser::ParseTopLevelVariable(TopLevel* top_level, 4626 void Parser::ParseTopLevelVariable(TopLevel* top_level,
4622 intptr_t metadata_pos) { 4627 intptr_t metadata_pos) {
4623 TRACE_PARSER("ParseTopLevelVariable"); 4628 TRACE_PARSER("ParseTopLevelVariable");
4624 const bool is_const = (CurrentToken() == Token::kCONST); 4629 const bool is_const = (CurrentToken() == Token::kCONST);
4625 // Const fields are implicitly final. 4630 // Const fields are implicitly final.
4626 const bool is_final = is_const || (CurrentToken() == Token::kFINAL); 4631 const bool is_final = is_const || (CurrentToken() == Token::kFINAL);
4627 const bool is_static = true; 4632 const bool is_static = true;
4628 const AbstractType& type = AbstractType::ZoneHandle(ParseConstFinalVarOrType( 4633 const AbstractType& type = AbstractType::ZoneHandle(I,
4629 ClassFinalizer::kResolveTypeParameters)); 4634 ParseConstFinalVarOrType(ClassFinalizer::kResolveTypeParameters));
4630 Field& field = Field::Handle(isolate()); 4635 Field& field = Field::Handle(isolate());
4631 Function& getter = Function::Handle(isolate()); 4636 Function& getter = Function::Handle(isolate());
4632 while (true) { 4637 while (true) {
4633 const intptr_t name_pos = TokenPos(); 4638 const intptr_t name_pos = TokenPos();
4634 String& var_name = *ExpectIdentifier("variable name expected"); 4639 String& var_name = *ExpectIdentifier("variable name expected");
4635 4640
4636 if (library_.LookupLocalObject(var_name) != Object::null()) { 4641 if (library_.LookupLocalObject(var_name) != Object::null()) {
4637 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString()); 4642 ErrorMsg(name_pos, "'%s' is already defined", var_name.ToCString());
4638 } 4643 }
4639 4644
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4683 /* is_abstract = */ false, 4688 /* is_abstract = */ false,
4684 /* is_external = */ false, 4689 /* is_external = */ false,
4685 /* is_native = */ false, 4690 /* is_native = */ false,
4686 current_class(), 4691 current_class(),
4687 name_pos); 4692 name_pos);
4688 getter.set_result_type(type); 4693 getter.set_result_type(type);
4689 top_level->functions.Add(getter); 4694 top_level->functions.Add(getter);
4690 4695
4691 // Create initializer function. 4696 // Create initializer function.
4692 if (!field.is_const()) { 4697 if (!field.is_const()) {
4693 const Function& init_function = Function::ZoneHandle( 4698 const Function& init_function = Function::ZoneHandle(I,
4694 Function::NewStaticInitializer(field)); 4699 Function::NewStaticInitializer(field));
4695 top_level->functions.Add(init_function); 4700 top_level->functions.Add(init_function);
4696 } 4701 }
4697 } 4702 }
4698 } else if (is_final) { 4703 } else if (is_final) {
4699 ErrorMsg(name_pos, "missing initializer for final or const variable"); 4704 ErrorMsg(name_pos, "missing initializer for final or const variable");
4700 } 4705 }
4701 4706
4702 if (CurrentToken() == Token::kCOMMA) { 4707 if (CurrentToken() == Token::kCOMMA) {
4703 ConsumeToken(); 4708 ConsumeToken();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
4852 const intptr_t name_pos = TokenPos(); 4857 const intptr_t name_pos = TokenPos();
4853 const String* field_name = ExpectIdentifier("accessor name expected"); 4858 const String* field_name = ExpectIdentifier("accessor name expected");
4854 4859
4855 const intptr_t accessor_pos = TokenPos(); 4860 const intptr_t accessor_pos = TokenPos();
4856 ParamList params; 4861 ParamList params;
4857 4862
4858 if (!is_getter) { 4863 if (!is_getter) {
4859 const bool allow_explicit_default_values = true; 4864 const bool allow_explicit_default_values = true;
4860 ParseFormalParameterList(allow_explicit_default_values, false, &params); 4865 ParseFormalParameterList(allow_explicit_default_values, false, &params);
4861 } 4866 }
4862 String& accessor_name = String::ZoneHandle(); 4867 String& accessor_name = String::ZoneHandle(I);
4863 int expected_num_parameters = -1; 4868 int expected_num_parameters = -1;
4864 if (is_getter) { 4869 if (is_getter) {
4865 expected_num_parameters = 0; 4870 expected_num_parameters = 0;
4866 accessor_name = Field::GetterSymbol(*field_name); 4871 accessor_name = Field::GetterSymbol(*field_name);
4867 } else { 4872 } else {
4868 expected_num_parameters = 1; 4873 expected_num_parameters = 1;
4869 accessor_name = Field::SetterSymbol(*field_name); 4874 accessor_name = Field::SetterSymbol(*field_name);
4870 } 4875 }
4871 if ((params.num_fixed_parameters != expected_num_parameters) || 4876 if ((params.num_fixed_parameters != expected_num_parameters) ||
4872 (params.num_optional_parameters != 0)) { 4877 (params.num_optional_parameters != 0)) {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
5462 native_name.ToCString(), func.NumParameters()); 5467 native_name.ToCString(), func.NumParameters());
5463 } 5468 }
5464 func.SetIsNativeAutoSetupScope(auto_setup_scope); 5469 func.SetIsNativeAutoSetupScope(auto_setup_scope);
5465 5470
5466 // Now add the NativeBodyNode and return statement. 5471 // Now add the NativeBodyNode and return statement.
5467 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); 5472 Dart_NativeEntryResolver resolver = library.native_entry_resolver();
5468 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); 5473 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver);
5469 current_block_->statements->Add(new(isolate()) ReturnNode( 5474 current_block_->statements->Add(new(isolate()) ReturnNode(
5470 TokenPos(), new(isolate()) NativeBodyNode( 5475 TokenPos(), new(isolate()) NativeBodyNode(
5471 TokenPos(), 5476 TokenPos(),
5472 Function::ZoneHandle(func.raw()), 5477 Function::ZoneHandle(I, func.raw()),
5473 native_name, 5478 native_name,
5474 native_function, 5479 native_function,
5475 current_block_->scope, 5480 current_block_->scope,
5476 is_bootstrap_native))); 5481 is_bootstrap_native)));
5477 } 5482 }
5478 5483
5479 5484
5480 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { 5485 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) {
5481 ASSERT(!current_function().is_static()); 5486 ASSERT(!current_function().is_static());
5482 return from_scope->LookupVariable(Symbols::This(), test_only); 5487 return from_scope->LookupVariable(Symbols::This(), test_only);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5564 if (is_const) { 5569 if (is_const) {
5565 ASSERT(expr->IsLiteralNode()); 5570 ASSERT(expr->IsLiteralNode());
5566 variable->SetConstValue(expr->AsLiteralNode()->literal()); 5571 variable->SetConstValue(expr->AsLiteralNode()->literal());
5567 } 5572 }
5568 } else if (is_final || is_const) { 5573 } else if (is_final || is_const) {
5569 ErrorMsg(ident_pos, 5574 ErrorMsg(ident_pos,
5570 "missing initialization of 'final' or 'const' variable"); 5575 "missing initialization of 'final' or 'const' variable");
5571 } else { 5576 } else {
5572 // Initialize variable with null. 5577 // Initialize variable with null.
5573 AstNode* null_expr = new(isolate()) LiteralNode( 5578 AstNode* null_expr = new(isolate()) LiteralNode(
5574 ident_pos, Instance::ZoneHandle()); 5579 ident_pos, Instance::ZoneHandle(I));
5575 initialization = new(isolate()) StoreLocalNode( 5580 initialization = new(isolate()) StoreLocalNode(
5576 ident_pos, variable, null_expr); 5581 ident_pos, variable, null_expr);
5577 } 5582 }
5578 5583
5579 ASSERT(current_block_ != NULL); 5584 ASSERT(current_block_ != NULL);
5580 const intptr_t previous_pos = 5585 const intptr_t previous_pos =
5581 current_block_->scope->PreviousReferencePos(ident); 5586 current_block_->scope->PreviousReferencePos(ident);
5582 if (previous_pos >= 0) { 5587 if (previous_pos >= 0) {
5583 ASSERT(!script_.IsNull()); 5588 ASSERT(!script_.IsNull());
5584 if (previous_pos > ident_pos) { 5589 if (previous_pos > ident_pos) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
5657 5662
5658 5663
5659 // Returns ast nodes of the variable initialization. Variables without an 5664 // Returns ast nodes of the variable initialization. Variables without an
5660 // explicit initializer are initialized to null. If several variables are 5665 // explicit initializer are initialized to null. If several variables are
5661 // declared, the individual initializers are collected in a sequence node. 5666 // declared, the individual initializers are collected in a sequence node.
5662 AstNode* Parser::ParseVariableDeclarationList() { 5667 AstNode* Parser::ParseVariableDeclarationList() {
5663 TRACE_PARSER("ParseVariableDeclarationList"); 5668 TRACE_PARSER("ParseVariableDeclarationList");
5664 SkipMetadata(); 5669 SkipMetadata();
5665 bool is_final = (CurrentToken() == Token::kFINAL); 5670 bool is_final = (CurrentToken() == Token::kFINAL);
5666 bool is_const = (CurrentToken() == Token::kCONST); 5671 bool is_const = (CurrentToken() == Token::kCONST);
5667 const AbstractType& type = AbstractType::ZoneHandle(ParseConstFinalVarOrType( 5672 const AbstractType& type = AbstractType::ZoneHandle(I,
5668 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize : 5673 ParseConstFinalVarOrType(FLAG_enable_type_checks ?
5669 ClassFinalizer::kIgnore)); 5674 ClassFinalizer::kCanonicalize : ClassFinalizer::kIgnore));
5670 if (!IsIdentifier()) { 5675 if (!IsIdentifier()) {
5671 ErrorMsg("identifier expected"); 5676 ErrorMsg("identifier expected");
5672 } 5677 }
5673 5678
5674 AstNode* initializers = ParseVariableDeclaration(type, is_final, is_const); 5679 AstNode* initializers = ParseVariableDeclaration(type, is_final, is_const);
5675 ASSERT(initializers != NULL); 5680 ASSERT(initializers != NULL);
5676 while (CurrentToken() == Token::kCOMMA) { 5681 while (CurrentToken() == Token::kCOMMA) {
5677 ConsumeToken(); 5682 ConsumeToken();
5678 if (!IsIdentifier()) { 5683 if (!IsIdentifier()) {
5679 ErrorMsg("identifier expected after comma"); 5684 ErrorMsg("identifier expected after comma");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5729 line_number); 5734 line_number);
5730 } 5735 }
5731 } 5736 }
5732 CheckToken(Token::kLPAREN); 5737 CheckToken(Token::kLPAREN);
5733 5738
5734 // Check whether we have parsed this closure function before, in a previous 5739 // Check whether we have parsed this closure function before, in a previous
5735 // compilation. If so, reuse the function object, else create a new one 5740 // compilation. If so, reuse the function object, else create a new one
5736 // and register it in the current class. 5741 // and register it in the current class.
5737 // Note that we cannot share the same closure function between the closurized 5742 // Note that we cannot share the same closure function between the closurized
5738 // and non-closurized versions of the same parent function. 5743 // and non-closurized versions of the same parent function.
5739 Function& function = Function::ZoneHandle(); 5744 Function& function = Function::ZoneHandle(I);
5740 bool is_new_closure = false; 5745 bool is_new_closure = false;
5741 // TODO(hausner): There could be two different closures at the given 5746 // TODO(hausner): There could be two different closures at the given
5742 // function_pos, one enclosed in a closurized function and one enclosed in the 5747 // function_pos, one enclosed in a closurized function and one enclosed in the
5743 // non-closurized version of this same function. 5748 // non-closurized version of this same function.
5744 function = current_class().LookupClosureFunction(function_pos); 5749 function = current_class().LookupClosureFunction(function_pos);
5745 if (function.IsNull() || (function.token_pos() != function_pos) || 5750 if (function.IsNull() || (function.token_pos() != function_pos) ||
5746 (function.parent_function() != innermost_function().raw())) { 5751 (function.parent_function() != innermost_function().raw())) {
5747 // The function will be registered in the lookup table by the 5752 // The function will be registered in the lookup table by the
5748 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure 5753 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure
5749 // function has been properly setup. 5754 // function has been properly setup.
5750 is_new_closure = true; 5755 is_new_closure = true;
5751 function = Function::NewClosureFunction(*function_name, 5756 function = Function::NewClosureFunction(*function_name,
5752 innermost_function(), 5757 innermost_function(),
5753 function_pos); 5758 function_pos);
5754 function.set_result_type(result_type); 5759 function.set_result_type(result_type);
5755 } 5760 }
5756 5761
5757 // The function type needs to be finalized at compile time, since the closure 5762 // The function type needs to be finalized at compile time, since the closure
5758 // may be type checked at run time when assigned to a function variable, 5763 // may be type checked at run time when assigned to a function variable,
5759 // passed as a function argument, or returned as a function result. 5764 // passed as a function argument, or returned as a function result.
5760 5765
5761 LocalVariable* function_variable = NULL; 5766 LocalVariable* function_variable = NULL;
5762 Type& function_type = Type::ZoneHandle(); 5767 Type& function_type = Type::ZoneHandle(I);
5763 if (variable_name != NULL) { 5768 if (variable_name != NULL) {
5764 // Since the function type depends on the signature of the closure function, 5769 // Since the function type depends on the signature of the closure function,
5765 // it cannot be determined before the formal parameter list of the closure 5770 // it cannot be determined before the formal parameter list of the closure
5766 // function is parsed. Therefore, we set the function type to a new 5771 // function is parsed. Therefore, we set the function type to a new
5767 // parameterized type to be patched after the actual type is known. 5772 // parameterized type to be patched after the actual type is known.
5768 // We temporarily use the class of the Function interface. 5773 // We temporarily use the class of the Function interface.
5769 const Class& unknown_signature_class = Class::Handle(isolate(), 5774 const Class& unknown_signature_class = Class::Handle(isolate(),
5770 Type::Handle(isolate(), Type::Function()).type_class()); 5775 Type::Handle(isolate(), Type::Function()).type_class());
5771 function_type = Type::New(unknown_signature_class, 5776 function_type = Type::New(unknown_signature_class,
5772 TypeArguments::Handle(isolate()), function_pos); 5777 TypeArguments::Handle(isolate()), function_pos);
(...skipping 25 matching lines...) Expand all
5798 5803
5799 // Parse the local function. 5804 // Parse the local function.
5800 Array& default_parameter_values = Array::Handle(isolate()); 5805 Array& default_parameter_values = Array::Handle(isolate());
5801 SequenceNode* statements = Parser::ParseFunc(function, 5806 SequenceNode* statements = Parser::ParseFunc(function,
5802 &default_parameter_values); 5807 &default_parameter_values);
5803 5808
5804 // Now that the local function has formal parameters, lookup the signature 5809 // Now that the local function has formal parameters, lookup the signature
5805 // class in the current library (but not in its imports) and only create a new 5810 // class in the current library (but not in its imports) and only create a new
5806 // canonical signature class if it does not exist yet. 5811 // canonical signature class if it does not exist yet.
5807 const String& signature = String::Handle(isolate(), function.Signature()); 5812 const String& signature = String::Handle(isolate(), function.Signature());
5808 Class& signature_class = Class::ZoneHandle(); 5813 Class& signature_class = Class::ZoneHandle(I);
5809 if (!is_new_closure) { 5814 if (!is_new_closure) {
5810 signature_class = function.signature_class(); 5815 signature_class = function.signature_class();
5811 } 5816 }
5812 if (signature_class.IsNull()) { 5817 if (signature_class.IsNull()) {
5813 signature_class = library_.LookupLocalClass(signature); 5818 signature_class = library_.LookupLocalClass(signature);
5814 } 5819 }
5815 if (signature_class.IsNull()) { 5820 if (signature_class.IsNull()) {
5816 // If we don't have a signature class yet, this must be a closure we 5821 // If we don't have a signature class yet, this must be a closure we
5817 // have not parsed before. 5822 // have not parsed before.
5818 ASSERT(is_new_closure); 5823 ASSERT(is_new_closure);
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
6418 // End of switch statement. 6423 // End of switch statement.
6419 break; 6424 break;
6420 } 6425 }
6421 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) { 6426 if ((next_token == Token::kCASE) || (next_token == Token::kDEFAULT)) {
6422 // End of this case clause. If there is a possible fall-through to 6427 // End of this case clause. If there is a possible fall-through to
6423 // the next case clause, throw an implicit FallThroughError. 6428 // the next case clause, throw an implicit FallThroughError.
6424 if (!abrupt_completing_seen) { 6429 if (!abrupt_completing_seen) {
6425 ArgumentListNode* arguments = new(isolate()) ArgumentListNode( 6430 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(
6426 TokenPos()); 6431 TokenPos());
6427 arguments->Add(new(isolate()) LiteralNode( 6432 arguments->Add(new(isolate()) LiteralNode(
6428 TokenPos(), Integer::ZoneHandle(Integer::New(TokenPos())))); 6433 TokenPos(), Integer::ZoneHandle(I, Integer::New(TokenPos()))));
6429 current_block_->statements->Add( 6434 current_block_->statements->Add(
6430 MakeStaticCall(Symbols::FallThroughError(), 6435 MakeStaticCall(Symbols::FallThroughError(),
6431 Library::PrivateCoreLibName(Symbols::ThrowNew()), 6436 Library::PrivateCoreLibName(Symbols::ThrowNew()),
6432 arguments)); 6437 arguments));
6433 } 6438 }
6434 break; 6439 break;
6435 } 6440 }
6436 // The next statement still belongs to this case. 6441 // The next statement still belongs to this case.
6437 AstNode* statement = ParseStatement(); 6442 AstNode* statement = ParseStatement();
6438 if (statement != NULL) { 6443 if (statement != NULL) {
(...skipping 20 matching lines...) Expand all
6459 ExpectToken(Token::kRPAREN); 6464 ExpectToken(Token::kRPAREN);
6460 ExpectToken(Token::kLBRACE); 6465 ExpectToken(Token::kLBRACE);
6461 OpenBlock(); 6466 OpenBlock();
6462 current_block_->scope->AddLabel(label); 6467 current_block_->scope->AddLabel(label);
6463 6468
6464 // Store switch expression in temporary local variable. The type of the 6469 // Store switch expression in temporary local variable. The type of the
6465 // variable is set to dynamic. It will later be patched to match the 6470 // variable is set to dynamic. It will later be patched to match the
6466 // type of the case clause expressions. Therefore, we have to allocate 6471 // type of the case clause expressions. Therefore, we have to allocate
6467 // a new type representing dynamic and can't reuse the canonical 6472 // a new type representing dynamic and can't reuse the canonical
6468 // type object for dynamic. 6473 // type object for dynamic.
6469 const Type& temp_var_type = Type::ZoneHandle(isolate(), 6474 const Type& temp_var_type = Type::ZoneHandle(I,
6470 Type::New(Class::Handle(isolate(), Object::dynamic_class()), 6475 Type::New(Class::Handle(isolate(), Object::dynamic_class()),
6471 TypeArguments::Handle(isolate()), 6476 TypeArguments::Handle(isolate()),
6472 expr_pos)); 6477 expr_pos));
6473 temp_var_type.SetIsFinalized(); 6478 temp_var_type.SetIsFinalized();
6474 LocalVariable* temp_variable = new(isolate()) LocalVariable( 6479 LocalVariable* temp_variable = new(isolate()) LocalVariable(
6475 expr_pos, Symbols::SwitchExpr(), temp_var_type); 6480 expr_pos, Symbols::SwitchExpr(), temp_var_type);
6476 current_block_->scope->AddVariable(temp_variable); 6481 current_block_->scope->AddVariable(temp_variable);
6477 AstNode* save_switch_expr = new(isolate()) StoreLocalNode( 6482 AstNode* save_switch_expr = new(isolate()) StoreLocalNode(
6478 expr_pos, temp_variable, switch_expr); 6483 expr_pos, temp_variable, switch_expr);
6479 current_block_->statements->Add(save_switch_expr); 6484 current_block_->statements->Add(save_switch_expr);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
6586 } 6591 }
6587 const String* loop_var_name = NULL; 6592 const String* loop_var_name = NULL;
6588 LocalVariable* loop_var = NULL; 6593 LocalVariable* loop_var = NULL;
6589 intptr_t loop_var_pos = 0; 6594 intptr_t loop_var_pos = 0;
6590 if (LookaheadToken(1) == Token::kIN) { 6595 if (LookaheadToken(1) == Token::kIN) {
6591 loop_var_pos = TokenPos(); 6596 loop_var_pos = TokenPos();
6592 loop_var_name = ExpectIdentifier("variable name expected"); 6597 loop_var_name = ExpectIdentifier("variable name expected");
6593 } else { 6598 } else {
6594 // The case without a type is handled above, so require a type here. 6599 // The case without a type is handled above, so require a type here.
6595 const AbstractType& type = 6600 const AbstractType& type =
6596 AbstractType::ZoneHandle(ParseConstFinalVarOrType( 6601 AbstractType::ZoneHandle(I, ParseConstFinalVarOrType(
6597 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize : 6602 FLAG_enable_type_checks ? ClassFinalizer::kCanonicalize :
6598 ClassFinalizer::kIgnore)); 6603 ClassFinalizer::kIgnore));
6599 loop_var_pos = TokenPos(); 6604 loop_var_pos = TokenPos();
6600 loop_var_name = ExpectIdentifier("variable name expected"); 6605 loop_var_name = ExpectIdentifier("variable name expected");
6601 loop_var = new(isolate()) LocalVariable(loop_var_pos, *loop_var_name, type); 6606 loop_var = new(isolate()) LocalVariable(loop_var_pos, *loop_var_name, type);
6602 if (is_final) { 6607 if (is_final) {
6603 loop_var->set_is_final(); 6608 loop_var->set_is_final();
6604 } 6609 }
6605 } 6610 }
6606 ExpectToken(Token::kIN); 6611 ExpectToken(Token::kIN);
6607 const intptr_t collection_pos = TokenPos(); 6612 const intptr_t collection_pos = TokenPos();
6608 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades); 6613 AstNode* collection_expr = ParseExpr(kAllowConst, kConsumeCascades);
6609 ExpectToken(Token::kRPAREN); 6614 ExpectToken(Token::kRPAREN);
6610 6615
6611 OpenBlock(); // Implicit block around while loop. 6616 OpenBlock(); // Implicit block around while loop.
6612 6617
6613 // Generate implicit iterator variable and add to scope. 6618 // Generate implicit iterator variable and add to scope.
6614 // We could set the type of the implicit iterator variable to Iterator<T> 6619 // We could set the type of the implicit iterator variable to Iterator<T>
6615 // where T is the type of the for loop variable. However, the type error 6620 // where T is the type of the for loop variable. However, the type error
6616 // would refer to the compiler generated iterator and could confuse the user. 6621 // would refer to the compiler generated iterator and could confuse the user.
6617 // It is better to leave the iterator untyped and postpone the type error 6622 // It is better to leave the iterator untyped and postpone the type error
6618 // until the loop variable is assigned to. 6623 // until the loop variable is assigned to.
6619 const AbstractType& iterator_type = Type::ZoneHandle(Type::DynamicType()); 6624 const AbstractType& iterator_type = Type::ZoneHandle(I, Type::DynamicType());
6620 LocalVariable* iterator_var = new(isolate()) LocalVariable( 6625 LocalVariable* iterator_var = new(isolate()) LocalVariable(
6621 collection_pos, Symbols::ForInIter(), iterator_type); 6626 collection_pos, Symbols::ForInIter(), iterator_type);
6622 current_block_->scope->AddVariable(iterator_var); 6627 current_block_->scope->AddVariable(iterator_var);
6623 6628
6624 // Generate initialization of iterator variable. 6629 // Generate initialization of iterator variable.
6625 ArgumentListNode* no_args = new(isolate()) ArgumentListNode(collection_pos); 6630 ArgumentListNode* no_args = new(isolate()) ArgumentListNode(collection_pos);
6626 AstNode* get_iterator = new(isolate()) InstanceGetterNode( 6631 AstNode* get_iterator = new(isolate()) InstanceGetterNode(
6627 collection_pos, collection_expr, Symbols::GetIterator()); 6632 collection_pos, collection_expr, Symbols::GetIterator());
6628 AstNode* iterator_init = 6633 AstNode* iterator_init =
6629 new(isolate()) StoreLocalNode(collection_pos, iterator_var, get_iterator); 6634 new(isolate()) StoreLocalNode(collection_pos, iterator_var, get_iterator);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
6752 } 6757 }
6753 6758
6754 6759
6755 // Calling VM-internal helpers, uses implementation core library. 6760 // Calling VM-internal helpers, uses implementation core library.
6756 AstNode* Parser::MakeStaticCall(const String& cls_name, 6761 AstNode* Parser::MakeStaticCall(const String& cls_name,
6757 const String& func_name, 6762 const String& func_name,
6758 ArgumentListNode* arguments) { 6763 ArgumentListNode* arguments) {
6759 const Class& cls = Class::Handle(isolate(), 6764 const Class& cls = Class::Handle(isolate(),
6760 Library::LookupCoreClass(cls_name)); 6765 Library::LookupCoreClass(cls_name));
6761 ASSERT(!cls.IsNull()); 6766 ASSERT(!cls.IsNull());
6762 const Function& func = Function::ZoneHandle( 6767 const Function& func = Function::ZoneHandle(I,
6763 Resolver::ResolveStatic(cls, 6768 Resolver::ResolveStatic(cls,
6764 func_name, 6769 func_name,
6765 arguments->length(), 6770 arguments->length(),
6766 arguments->names())); 6771 arguments->names()));
6767 ASSERT(!func.IsNull()); 6772 ASSERT(!func.IsNull());
6768 return new(isolate()) StaticCallNode(arguments->token_pos(), func, arguments); 6773 return new(isolate()) StaticCallNode(arguments->token_pos(), func, arguments);
6769 } 6774 }
6770 6775
6771 6776
6772 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { 6777 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) {
6773 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(begin); 6778 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(begin);
6774 arguments->Add(new(isolate()) LiteralNode(begin, 6779 arguments->Add(new(isolate()) LiteralNode(begin,
6775 Integer::ZoneHandle(Integer::New(begin)))); 6780 Integer::ZoneHandle(I, Integer::New(begin))));
6776 arguments->Add(new(isolate()) LiteralNode(end, 6781 arguments->Add(new(isolate()) LiteralNode(end,
6777 Integer::ZoneHandle(Integer::New(end)))); 6782 Integer::ZoneHandle(I, Integer::New(end))));
6778 return MakeStaticCall(Symbols::AssertionError(), 6783 return MakeStaticCall(Symbols::AssertionError(),
6779 Library::PrivateCoreLibName(Symbols::ThrowNew()), 6784 Library::PrivateCoreLibName(Symbols::ThrowNew()),
6780 arguments); 6785 arguments);
6781 } 6786 }
6782 6787
6783 6788
6784 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { 6789 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) {
6785 if (condition->IsClosureNode() || 6790 if (condition->IsClosureNode() ||
6786 (condition->IsStoreLocalNode() && 6791 (condition->IsStoreLocalNode() &&
6787 condition->AsStoreLocalNode()->value()->IsClosureNode())) { 6792 condition->AsStoreLocalNode()->value()->IsClosureNode())) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
6952 GrowableArray<SequenceNode*> catch_blocks; 6957 GrowableArray<SequenceNode*> catch_blocks;
6953 while ((CurrentToken() == Token::kCATCH) || IsLiteral("on")) { 6958 while ((CurrentToken() == Token::kCATCH) || IsLiteral("on")) {
6954 // Open a block that contains the if or an unconditional body. It's 6959 // Open a block that contains the if or an unconditional body. It's
6955 // closed in the loop that builds the if-then-else nest. 6960 // closed in the loop that builds the if-then-else nest.
6956 OpenBlock(); 6961 OpenBlock();
6957 const intptr_t catch_pos = TokenPos(); 6962 const intptr_t catch_pos = TokenPos();
6958 CatchParamDesc exception_param; 6963 CatchParamDesc exception_param;
6959 CatchParamDesc stack_trace_param; 6964 CatchParamDesc stack_trace_param;
6960 if (IsLiteral("on")) { 6965 if (IsLiteral("on")) {
6961 ConsumeToken(); 6966 ConsumeToken();
6962 exception_param.type = &AbstractType::ZoneHandle( 6967 exception_param.type = &AbstractType::ZoneHandle(I,
6963 ParseType(ClassFinalizer::kCanonicalize)); 6968 ParseType(ClassFinalizer::kCanonicalize));
6964 } else { 6969 } else {
6965 exception_param.type = &AbstractType::ZoneHandle(Type::DynamicType()); 6970 exception_param.type = &AbstractType::ZoneHandle(I, Type::DynamicType());
6966 } 6971 }
6967 if (CurrentToken() == Token::kCATCH) { 6972 if (CurrentToken() == Token::kCATCH) {
6968 ConsumeToken(); // Consume the 'catch'. 6973 ConsumeToken(); // Consume the 'catch'.
6969 ExpectToken(Token::kLPAREN); 6974 ExpectToken(Token::kLPAREN);
6970 exception_param.token_pos = TokenPos(); 6975 exception_param.token_pos = TokenPos();
6971 exception_param.name = ExpectIdentifier("identifier expected"); 6976 exception_param.name = ExpectIdentifier("identifier expected");
6972 if (CurrentToken() == Token::kCOMMA) { 6977 if (CurrentToken() == Token::kCOMMA) {
6973 ConsumeToken(); 6978 ConsumeToken();
6974 // TODO(hausner): Make implicit type be StackTrace, not dynamic. 6979 // TODO(hausner): Make implicit type be StackTrace, not dynamic.
6975 stack_trace_param.type = 6980 stack_trace_param.type =
6976 &AbstractType::ZoneHandle(Type::DynamicType()); 6981 &AbstractType::ZoneHandle(I, Type::DynamicType());
6977 stack_trace_param.token_pos = TokenPos(); 6982 stack_trace_param.token_pos = TokenPos();
6978 stack_trace_param.name = ExpectIdentifier("identifier expected"); 6983 stack_trace_param.name = ExpectIdentifier("identifier expected");
6979 } 6984 }
6980 ExpectToken(Token::kRPAREN); 6985 ExpectToken(Token::kRPAREN);
6981 } 6986 }
6982 6987
6983 // Create a block containing the catch clause parameters and the 6988 // Create a block containing the catch clause parameters and the
6984 // following code: 6989 // following code:
6985 // 1) Store exception object and stack trace object into user-defined 6990 // 1) Store exception object and stack trace object into user-defined
6986 // variables (as needed). 6991 // variables (as needed).
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
7127 // was thrown. 7132 // was thrown.
7128 // :exception_var and :stack_trace_var get set with the exception object 7133 // :exception_var and :stack_trace_var get set with the exception object
7129 // and the stack trace object when an exception is thrown. These three 7134 // and the stack trace object when an exception is thrown. These three
7130 // implicit variables can never be captured. 7135 // implicit variables can never be captured.
7131 LocalVariable* context_var = 7136 LocalVariable* context_var =
7132 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); 7137 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar());
7133 if (context_var == NULL) { 7138 if (context_var == NULL) {
7134 context_var = new(isolate()) LocalVariable( 7139 context_var = new(isolate()) LocalVariable(
7135 TokenPos(), 7140 TokenPos(),
7136 Symbols::SavedTryContextVar(), 7141 Symbols::SavedTryContextVar(),
7137 Type::ZoneHandle(Type::DynamicType())); 7142 Type::ZoneHandle(I, Type::DynamicType()));
7138 current_block_->scope->AddVariable(context_var); 7143 current_block_->scope->AddVariable(context_var);
7139 } 7144 }
7140 LocalVariable* exception_var = 7145 LocalVariable* exception_var =
7141 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); 7146 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar());
7142 if (exception_var == NULL) { 7147 if (exception_var == NULL) {
7143 exception_var = new(isolate()) LocalVariable( 7148 exception_var = new(isolate()) LocalVariable(
7144 TokenPos(), 7149 TokenPos(),
7145 Symbols::ExceptionVar(), 7150 Symbols::ExceptionVar(),
7146 Type::ZoneHandle(Type::DynamicType())); 7151 Type::ZoneHandle(I, Type::DynamicType()));
7147 current_block_->scope->AddVariable(exception_var); 7152 current_block_->scope->AddVariable(exception_var);
7148 } 7153 }
7149 LocalVariable* stack_trace_var = 7154 LocalVariable* stack_trace_var =
7150 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar()); 7155 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar());
7151 if (stack_trace_var == NULL) { 7156 if (stack_trace_var == NULL) {
7152 stack_trace_var = new(isolate()) LocalVariable( 7157 stack_trace_var = new(isolate()) LocalVariable(
7153 TokenPos(), 7158 TokenPos(),
7154 Symbols::StackTraceVar(), 7159 Symbols::StackTraceVar(),
7155 Type::ZoneHandle(Type::DynamicType())); 7160 Type::ZoneHandle(I, Type::DynamicType()));
7156 current_block_->scope->AddVariable(stack_trace_var); 7161 current_block_->scope->AddVariable(stack_trace_var);
7157 } 7162 }
7158 7163
7159 const intptr_t try_pos = TokenPos(); 7164 const intptr_t try_pos = TokenPos();
7160 ConsumeToken(); // Consume the 'try'. 7165 ConsumeToken(); // Consume the 'try'.
7161 7166
7162 SourceLabel* try_label = NULL; 7167 SourceLabel* try_label = NULL;
7163 if (label_name != NULL) { 7168 if (label_name != NULL) {
7164 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement); 7169 try_label = SourceLabel::New(try_pos, label_name, SourceLabel::kStatement);
7165 OpenBlock(); 7170 OpenBlock();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
7215 node_index += 1; 7220 node_index += 1;
7216 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index); 7221 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index);
7217 tokens_iterator_.SetCurrentPosition(finally_pos); 7222 tokens_iterator_.SetCurrentPosition(finally_pos);
7218 } 7223 }
7219 finally_block = ParseFinallyBlock(); 7224 finally_block = ParseFinallyBlock();
7220 } 7225 }
7221 7226
7222 CatchClauseNode* catch_clause = new(isolate()) CatchClauseNode( 7227 CatchClauseNode* catch_clause = new(isolate()) CatchClauseNode(
7223 handler_pos, 7228 handler_pos,
7224 catch_handler_list, 7229 catch_handler_list,
7225 Array::ZoneHandle(Array::MakeArray(handler_types)), 7230 Array::ZoneHandle(I, Array::MakeArray(handler_types)),
7226 context_var, 7231 context_var,
7227 exception_var, 7232 exception_var,
7228 stack_trace_var, 7233 stack_trace_var,
7229 (finally_block != NULL) ? 7234 (finally_block != NULL) ?
7230 AllocateTryIndex() : CatchClauseNode::kInvalidTryIndex, 7235 AllocateTryIndex() : CatchClauseNode::kInvalidTryIndex,
7231 needs_stack_trace); 7236 needs_stack_trace);
7232 7237
7233 // Now create the try/catch ast node and return it. If there is a label 7238 // Now create the try/catch ast node and return it. If there is a label
7234 // on the try/catch, close the block that's embedding the try statement 7239 // on the try/catch, close the block that's embedding the try statement
7235 // and attach the label to it. 7240 // and attach the label to it.
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
7587 return sequence; 7592 return sequence;
7588 } 7593 }
7589 return node->AsSequenceNode(); 7594 return node->AsSequenceNode();
7590 } 7595 }
7591 7596
7592 7597
7593 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) { 7598 AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) {
7594 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(type_pos); 7599 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(type_pos);
7595 // Location argument. 7600 // Location argument.
7596 arguments->Add(new(isolate()) LiteralNode( 7601 arguments->Add(new(isolate()) LiteralNode(
7597 type_pos, Integer::ZoneHandle(Integer::New(type_pos)))); 7602 type_pos, Integer::ZoneHandle(I, Integer::New(type_pos))));
7598 // Src value argument. 7603 // Src value argument.
7599 arguments->Add(new(isolate()) LiteralNode(type_pos, Instance::ZoneHandle())); 7604 arguments->Add(new(isolate()) LiteralNode(type_pos, Instance::ZoneHandle(I)));
7600 // Dst type name argument. 7605 // Dst type name argument.
7601 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Malformed())); 7606 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Malformed()));
7602 // Dst name argument. 7607 // Dst name argument.
7603 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Empty())); 7608 arguments->Add(new(isolate()) LiteralNode(type_pos, Symbols::Empty()));
7604 // Malformed type error or malbounded type error. 7609 // Malformed type error or malbounded type error.
7605 const Error& error = Error::Handle(isolate(), type.error()); 7610 const Error& error = Error::Handle(isolate(), type.error());
7606 ASSERT(!error.IsNull()); 7611 ASSERT(!error.IsNull());
7607 arguments->Add(new(isolate()) LiteralNode(type_pos, String::ZoneHandle( 7612 arguments->Add(new(isolate()) LiteralNode(type_pos, String::ZoneHandle(I,
7608 Symbols::New(error.ToErrorCString())))); 7613 Symbols::New(error.ToErrorCString()))));
7609 return MakeStaticCall(Symbols::TypeError(), 7614 return MakeStaticCall(Symbols::TypeError(),
7610 Library::PrivateCoreLibName(Symbols::ThrowNew()), 7615 Library::PrivateCoreLibName(Symbols::ThrowNew()),
7611 arguments); 7616 arguments);
7612 } 7617 }
7613 7618
7614 7619
7615 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos, 7620 AstNode* Parser::ThrowNoSuchMethodError(intptr_t call_pos,
7616 const Class& cls, 7621 const Class& cls,
7617 const String& function_name, 7622 const String& function_name,
7618 ArgumentListNode* function_arguments, 7623 ArgumentListNode* function_arguments,
7619 InvocationMirror::Call im_call, 7624 InvocationMirror::Call im_call,
7620 InvocationMirror::Type im_type, 7625 InvocationMirror::Type im_type,
7621 Function* func) { 7626 Function* func) {
7622 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(call_pos); 7627 ArgumentListNode* arguments = new(isolate()) ArgumentListNode(call_pos);
7623 // Object receiver. 7628 // Object receiver.
7624 // TODO(regis): For now, we pass a class literal of the unresolved 7629 // TODO(regis): For now, we pass a class literal of the unresolved
7625 // method's owner, but this is not specified and will probably change. 7630 // method's owner, but this is not specified and will probably change.
7626 Type& type = Type::ZoneHandle( 7631 Type& type = Type::ZoneHandle(I,
7627 Type::New(cls, TypeArguments::Handle(isolate()), call_pos, Heap::kOld)); 7632 Type::New(cls, TypeArguments::Handle(isolate()), call_pos, Heap::kOld));
7628 type ^= ClassFinalizer::FinalizeType( 7633 type ^= ClassFinalizer::FinalizeType(
7629 current_class(), type, ClassFinalizer::kCanonicalize); 7634 current_class(), type, ClassFinalizer::kCanonicalize);
7630 arguments->Add(new(isolate()) LiteralNode(call_pos, type)); 7635 arguments->Add(new(isolate()) LiteralNode(call_pos, type));
7631 // String memberName. 7636 // String memberName.
7632 arguments->Add(new(isolate()) LiteralNode( 7637 arguments->Add(new(isolate()) LiteralNode(
7633 call_pos, String::ZoneHandle(Symbols::New(function_name)))); 7638 call_pos, String::ZoneHandle(I, Symbols::New(function_name))));
7634 // Smi invocation_type. 7639 // Smi invocation_type.
7635 if (cls.IsTopLevel()) { 7640 if (cls.IsTopLevel()) {
7636 ASSERT(im_call == InvocationMirror::kStatic || 7641 ASSERT(im_call == InvocationMirror::kStatic ||
7637 im_call == InvocationMirror::kTopLevel); 7642 im_call == InvocationMirror::kTopLevel);
7638 im_call = InvocationMirror::kTopLevel; 7643 im_call = InvocationMirror::kTopLevel;
7639 } 7644 }
7640 arguments->Add(new(isolate()) LiteralNode(call_pos, Smi::ZoneHandle( 7645 arguments->Add(new(isolate()) LiteralNode(call_pos, Smi::ZoneHandle(I,
7641 Smi::New(InvocationMirror::EncodeType(im_call, im_type))))); 7646 Smi::New(InvocationMirror::EncodeType(im_call, im_type)))));
7642 // List arguments. 7647 // List arguments.
7643 if (function_arguments == NULL) { 7648 if (function_arguments == NULL) {
7644 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle())); 7649 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle(I)));
7645 } else { 7650 } else {
7646 ArrayNode* array = new(isolate()) ArrayNode( 7651 ArrayNode* array = new(isolate()) ArrayNode(
7647 call_pos, 7652 call_pos,
7648 Type::ZoneHandle(Type::ArrayType()), 7653 Type::ZoneHandle(I, Type::ArrayType()),
7649 function_arguments->nodes()); 7654 function_arguments->nodes());
7650 arguments->Add(array); 7655 arguments->Add(array);
7651 } 7656 }
7652 // List argumentNames. 7657 // List argumentNames.
7653 if (function_arguments == NULL) { 7658 if (function_arguments == NULL) {
7654 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle())); 7659 arguments->Add(new(isolate()) LiteralNode(call_pos, Array::ZoneHandle(I)));
7655 } else { 7660 } else {
7656 arguments->Add(new(isolate()) LiteralNode( 7661 arguments->Add(new(isolate()) LiteralNode(
7657 call_pos, function_arguments->names())); 7662 call_pos, function_arguments->names()));
7658 } 7663 }
7659 7664
7660 // List existingArgumentNames. 7665 // List existingArgumentNames.
7661 // Check if there exists a function with the same name unless caller 7666 // Check if there exists a function with the same name unless caller
7662 // has done the lookup already. If there is a function with the same 7667 // has done the lookup already. If there is a function with the same
7663 // name but incompatible parameters, inform the NoSuchMethodError what the 7668 // name but incompatible parameters, inform the NoSuchMethodError what the
7664 // expected parameters are. 7669 // expected parameters are.
7665 Function& function = Function::Handle(isolate()); 7670 Function& function = Function::Handle(isolate());
7666 if (func != NULL) { 7671 if (func != NULL) {
7667 function = func->raw(); 7672 function = func->raw();
7668 } else { 7673 } else {
7669 function = cls.LookupStaticFunction(function_name); 7674 function = cls.LookupStaticFunction(function_name);
7670 } 7675 }
7671 Array& array = Array::ZoneHandle(); 7676 Array& array = Array::ZoneHandle(I);
7672 if (!function.IsNull()) { 7677 if (!function.IsNull()) {
7673 // The constructor for NoSuchMethodError takes a list of existing 7678 // The constructor for NoSuchMethodError takes a list of existing
7674 // parameter names to produce a descriptive error message explaining 7679 // parameter names to produce a descriptive error message explaining
7675 // the parameter mismatch. The problem is that the array of names 7680 // the parameter mismatch. The problem is that the array of names
7676 // does not describe which parameters are optional positional or 7681 // does not describe which parameters are optional positional or
7677 // named, which can lead to confusing error messages. 7682 // named, which can lead to confusing error messages.
7678 // Since the NoSuchMethodError class only uses the list to produce 7683 // Since the NoSuchMethodError class only uses the list to produce
7679 // a string describing the expected parameters, we construct a more 7684 // a string describing the expected parameters, we construct a more
7680 // descriptive string here and pass it as the only element of the 7685 // descriptive string here and pass it as the only element of the
7681 // "existingArgumentNames" array of the NoSuchMethodError constructor. 7686 // "existingArgumentNames" array of the NoSuchMethodError constructor.
(...skipping 29 matching lines...) Expand all
7711 AstNode* right_operand = NULL; 7716 AstNode* right_operand = NULL;
7712 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { 7717 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) {
7713 right_operand = ParseBinaryExpr(current_preced + 1); 7718 right_operand = ParseBinaryExpr(current_preced + 1);
7714 } else { 7719 } else {
7715 // For 'is' and 'as' we expect the right operand to be a type. 7720 // For 'is' and 'as' we expect the right operand to be a type.
7716 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { 7721 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) {
7717 ConsumeToken(); 7722 ConsumeToken();
7718 op_kind = Token::kISNOT; 7723 op_kind = Token::kISNOT;
7719 } 7724 }
7720 const intptr_t type_pos = TokenPos(); 7725 const intptr_t type_pos = TokenPos();
7721 const AbstractType& type = AbstractType::ZoneHandle( 7726 const AbstractType& type = AbstractType::ZoneHandle(I,
7722 ParseType(ClassFinalizer::kCanonicalize)); 7727 ParseType(ClassFinalizer::kCanonicalize));
7723 if (!type.IsInstantiated() && 7728 if (!type.IsInstantiated() &&
7724 (current_block_->scope->function_level() > 0)) { 7729 (current_block_->scope->function_level() > 0)) {
7725 // Make sure that the instantiator is captured. 7730 // Make sure that the instantiator is captured.
7726 CaptureInstantiator(); 7731 CaptureInstantiator();
7727 } 7732 }
7728 right_operand = new(isolate()) TypeNode(type_pos, type); 7733 right_operand = new(isolate()) TypeNode(type_pos, type);
7729 // In production mode, the type may be malformed. 7734 // In production mode, the type may be malformed.
7730 // In checked mode, the type may be malformed or malbounded. 7735 // In checked mode, the type may be malformed or malbounded.
7731 if (((op_kind == Token::kIS) || (op_kind == Token::kISNOT) || 7736 if (((op_kind == Token::kIS) || (op_kind == Token::kISNOT) ||
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
7789 parsed_function()->EnsureExpressionTemp(); 7794 parsed_function()->EnsureExpressionTemp();
7790 } 7795 }
7791 7796
7792 7797
7793 void Parser::EnsureSavedCurrentContext() { 7798 void Parser::EnsureSavedCurrentContext() {
7794 // Used later by the flow_graph_builder to save current context. 7799 // Used later by the flow_graph_builder to save current context.
7795 if (!parsed_function()->has_saved_current_context_var()) { 7800 if (!parsed_function()->has_saved_current_context_var()) {
7796 LocalVariable* temp = new(isolate()) LocalVariable( 7801 LocalVariable* temp = new(isolate()) LocalVariable(
7797 current_function().token_pos(), 7802 current_function().token_pos(),
7798 Symbols::SavedCurrentContextVar(), 7803 Symbols::SavedCurrentContextVar(),
7799 Type::ZoneHandle(Type::DynamicType())); 7804 Type::ZoneHandle(I, Type::DynamicType()));
7800 ASSERT(temp != NULL); 7805 ASSERT(temp != NULL);
7801 parsed_function()->set_saved_current_context_var(temp); 7806 parsed_function()->set_saved_current_context_var(temp);
7802 } 7807 }
7803 } 7808 }
7804 7809
7805 7810
7806 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, 7811 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos,
7807 const char* s) { 7812 const char* s) {
7808 char name[64]; 7813 char name[64];
7809 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); 7814 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos);
7810 LocalVariable* temp = new(isolate()) LocalVariable( 7815 LocalVariable* temp = new(isolate()) LocalVariable(
7811 token_pos, 7816 token_pos,
7812 String::ZoneHandle(Symbols::New(name)), 7817 String::ZoneHandle(I, Symbols::New(name)),
7813 Type::ZoneHandle(Type::DynamicType())); 7818 Type::ZoneHandle(I, Type::DynamicType()));
7814 temp->set_is_final(); 7819 temp->set_is_final();
7815 current_block_->scope->AddVariable(temp); 7820 current_block_->scope->AddVariable(temp);
7816 return temp; 7821 return temp;
7817 } 7822 }
7818 7823
7819 7824
7820 // TODO(srdjan): Implement other optimizations. 7825 // TODO(srdjan): Implement other optimizations.
7821 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, 7826 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos,
7822 Token::Kind binary_op, 7827 Token::Kind binary_op,
7823 AstNode* lhs, 7828 AstNode* lhs,
7824 AstNode* rhs) { 7829 AstNode* rhs) {
7825 LiteralNode* lhs_literal = lhs->AsLiteralNode(); 7830 LiteralNode* lhs_literal = lhs->AsLiteralNode();
7826 LiteralNode* rhs_literal = rhs->AsLiteralNode(); 7831 LiteralNode* rhs_literal = rhs->AsLiteralNode();
7827 if ((lhs_literal != NULL) && (rhs_literal != NULL)) { 7832 if ((lhs_literal != NULL) && (rhs_literal != NULL)) {
7828 if (lhs_literal->literal().IsDouble() && 7833 if (lhs_literal->literal().IsDouble() &&
7829 rhs_literal->literal().IsDouble()) { 7834 rhs_literal->literal().IsDouble()) {
7830 double left_double = Double::Cast(lhs_literal->literal()).value(); 7835 double left_double = Double::Cast(lhs_literal->literal()).value();
7831 double right_double = Double::Cast(rhs_literal->literal()).value(); 7836 double right_double = Double::Cast(rhs_literal->literal()).value();
7832 if (binary_op == Token::kDIV) { 7837 if (binary_op == Token::kDIV) {
7833 const Double& dbl_obj = Double::ZoneHandle( 7838 const Double& dbl_obj = Double::ZoneHandle(I,
7834 Double::NewCanonical((left_double / right_double))); 7839 Double::NewCanonical((left_double / right_double)));
7835 return new(isolate()) LiteralNode(op_pos, dbl_obj); 7840 return new(isolate()) LiteralNode(op_pos, dbl_obj);
7836 } 7841 }
7837 } 7842 }
7838 } 7843 }
7839 if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) { 7844 if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) {
7840 EnsureExpressionTemp(); 7845 EnsureExpressionTemp();
7841 } 7846 }
7842 if (binary_op == Token::kBIT_AND) { 7847 if (binary_op == Token::kBIT_AND) {
7843 // Normalize so that rhs is a literal if any is. 7848 // Normalize so that rhs is a literal if any is.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7979 return Token::IsIdentifier(token) || (token == Token::kRBRACK); 7984 return Token::IsIdentifier(token) || (token == Token::kRBRACK);
7980 } 7985 }
7981 7986
7982 7987
7983 AstNode* Parser::CreateAssignmentNode(AstNode* original, 7988 AstNode* Parser::CreateAssignmentNode(AstNode* original,
7984 AstNode* rhs, 7989 AstNode* rhs,
7985 const String* left_ident, 7990 const String* left_ident,
7986 intptr_t left_pos) { 7991 intptr_t left_pos) {
7987 AstNode* result = original->MakeAssignmentNode(rhs); 7992 AstNode* result = original->MakeAssignmentNode(rhs);
7988 if (result == NULL) { 7993 if (result == NULL) {
7989 String& name = String::ZoneHandle(); 7994 String& name = String::ZoneHandle(I);
7990 const Class* target_cls = &current_class(); 7995 const Class* target_cls = &current_class();
7991 if (original->IsTypeNode()) { 7996 if (original->IsTypeNode()) {
7992 name = Symbols::New(original->AsTypeNode()->TypeName()); 7997 name = Symbols::New(original->AsTypeNode()->TypeName());
7993 } else if (original->IsLoadStaticFieldNode()) { 7998 } else if (original->IsLoadStaticFieldNode()) {
7994 name = original->AsLoadStaticFieldNode()->field().name(); 7999 name = original->AsLoadStaticFieldNode()->field().name();
7995 target_cls = &Class::Handle(isolate(), 8000 target_cls = &Class::Handle(isolate(),
7996 original->AsLoadStaticFieldNode()->field().owner()); 8001 original->AsLoadStaticFieldNode()->field().owner());
7997 } else if ((left_ident != NULL) && 8002 } else if ((left_ident != NULL) &&
7998 (original->IsLiteralNode() || 8003 (original->IsLiteralNode() ||
7999 original->IsLoadLocalNode())) { 8004 original->IsLoadLocalNode())) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
8075 } 8080 }
8076 // The result is an expression with the (side effects of the) cascade 8081 // The result is an expression with the (side effects of the) cascade
8077 // sequence followed by the (value of the) receiver temp variable load. 8082 // sequence followed by the (value of the) receiver temp variable load.
8078 cascade->AddNode(new(isolate()) LoadLocalNode( 8083 cascade->AddNode(new(isolate()) LoadLocalNode(
8079 cascade_pos, cascade_receiver_var)); 8084 cascade_pos, cascade_receiver_var));
8080 return cascade; 8085 return cascade;
8081 } 8086 }
8082 8087
8083 8088
8084 // Convert loading of a static const field into a literal node. 8089 // Convert loading of a static const field into a literal node.
8085 static AstNode* LiteralIfStaticConst(AstNode* expr) { 8090 static AstNode* LiteralIfStaticConst(Isolate* iso, AstNode* expr) {
8086 if (expr->IsLoadStaticFieldNode()) { 8091 if (expr->IsLoadStaticFieldNode()) {
8087 const Field& field = expr->AsLoadStaticFieldNode()->field(); 8092 const Field& field = expr->AsLoadStaticFieldNode()->field();
8088 if (field.is_const()) { 8093 if (field.is_const()) {
8089 ASSERT(field.value() != Object::sentinel().raw()); 8094 ASSERT(field.value() != Object::sentinel().raw());
8090 ASSERT(field.value() != Object::transition_sentinel().raw()); 8095 ASSERT(field.value() != Object::transition_sentinel().raw());
8091 return new LiteralNode(expr->token_pos(), 8096 return new(iso) LiteralNode(expr->token_pos(),
8092 Instance::ZoneHandle(field.value())); 8097 Instance::ZoneHandle(iso, field.value()));
8093 } 8098 }
8094 } 8099 }
8095 return expr; 8100 return expr;
8096 } 8101 }
8097 8102
8098 8103
8099 AstNode* Parser::ParseExpr(bool require_compiletime_const, 8104 AstNode* Parser::ParseExpr(bool require_compiletime_const,
8100 bool consume_cascades) { 8105 bool consume_cascades) {
8101 TRACE_PARSER("ParseExpr"); 8106 TRACE_PARSER("ParseExpr");
8102 String* expr_ident = 8107 String* expr_ident =
8103 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; 8108 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL;
8104 const intptr_t expr_pos = TokenPos(); 8109 const intptr_t expr_pos = TokenPos();
8105 8110
8106 if (CurrentToken() == Token::kTHROW) { 8111 if (CurrentToken() == Token::kTHROW) {
8107 ConsumeToken(); 8112 ConsumeToken();
8108 if (CurrentToken() == Token::kSEMICOLON) { 8113 if (CurrentToken() == Token::kSEMICOLON) {
8109 ErrorMsg("expression expected after throw"); 8114 ErrorMsg("expression expected after throw");
8110 } 8115 }
8111 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades); 8116 AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades);
8112 return new(isolate()) ThrowNode(expr_pos, expr, NULL); 8117 return new(isolate()) ThrowNode(expr_pos, expr, NULL);
8113 } 8118 }
8114 AstNode* expr = ParseConditionalExpr(); 8119 AstNode* expr = ParseConditionalExpr();
8115 if (!Token::IsAssignmentOperator(CurrentToken())) { 8120 if (!Token::IsAssignmentOperator(CurrentToken())) {
8116 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) { 8121 if ((CurrentToken() == Token::kCASCADE) && consume_cascades) {
8117 return ParseCascades(expr); 8122 return ParseCascades(expr);
8118 } 8123 }
8119 if (require_compiletime_const) { 8124 if (require_compiletime_const) {
8120 expr = FoldConstExpr(expr_pos, expr); 8125 expr = FoldConstExpr(expr_pos, expr);
8121 } else { 8126 } else {
8122 expr = LiteralIfStaticConst(expr); 8127 expr = LiteralIfStaticConst(I, expr);
8123 } 8128 }
8124 return expr; 8129 return expr;
8125 } 8130 }
8126 // Assignment expressions. 8131 // Assignment expressions.
8127 if (!IsLegalAssignableSyntax(expr, TokenPos())) { 8132 if (!IsLegalAssignableSyntax(expr, TokenPos())) {
8128 ErrorMsg(expr_pos, "expression is not assignable"); 8133 ErrorMsg(expr_pos, "expression is not assignable");
8129 } 8134 }
8130 const Token::Kind assignment_op = CurrentToken(); 8135 const Token::Kind assignment_op = CurrentToken();
8131 const intptr_t assignment_pos = TokenPos(); 8136 const intptr_t assignment_pos = TokenPos();
8132 ConsumeToken(); 8137 ConsumeToken();
8133 const intptr_t right_expr_pos = TokenPos(); 8138 const intptr_t right_expr_pos = TokenPos();
8134 if (require_compiletime_const && (assignment_op != Token::kASSIGN)) { 8139 if (require_compiletime_const && (assignment_op != Token::kASSIGN)) {
8135 ErrorMsg(right_expr_pos, "expression is not a valid compile-time constant"); 8140 ErrorMsg(right_expr_pos, "expression is not a valid compile-time constant");
8136 } 8141 }
8137 AstNode* right_expr = ParseExpr(require_compiletime_const, consume_cascades); 8142 AstNode* right_expr = ParseExpr(require_compiletime_const, consume_cascades);
8138 if (assignment_op != Token::kASSIGN) { 8143 if (assignment_op != Token::kASSIGN) {
8139 // Compound assignment: store inputs with side effects into temp. locals. 8144 // Compound assignment: store inputs with side effects into temp. locals.
8140 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); 8145 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr);
8141 AstNode* assigned_value = 8146 AstNode* assigned_value =
8142 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); 8147 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr);
8143 AstNode* assign_expr = 8148 AstNode* assign_expr =
8144 CreateAssignmentNode(expr, assigned_value, expr_ident, expr_pos); 8149 CreateAssignmentNode(expr, assigned_value, expr_ident, expr_pos);
8145 ASSERT(assign_expr != NULL); 8150 ASSERT(assign_expr != NULL);
8146 let_expr->AddNode(assign_expr); 8151 let_expr->AddNode(assign_expr);
8147 return let_expr; 8152 return let_expr;
8148 } else { 8153 } else {
8149 AstNode* assigned_value = LiteralIfStaticConst(right_expr); 8154 AstNode* assigned_value = LiteralIfStaticConst(I, right_expr);
8150 AstNode* assign_expr = 8155 AstNode* assign_expr =
8151 CreateAssignmentNode(expr, assigned_value, expr_ident, expr_pos); 8156 CreateAssignmentNode(expr, assigned_value, expr_ident, expr_pos);
8152 ASSERT(assign_expr != NULL); 8157 ASSERT(assign_expr != NULL);
8153 return assign_expr; 8158 return assign_expr;
8154 } 8159 }
8155 } 8160 }
8156 8161
8157 8162
8158 LiteralNode* Parser::ParseConstExpr() { 8163 LiteralNode* Parser::ParseConstExpr() {
8159 TRACE_PARSER("ParseConstExpr"); 8164 TRACE_PARSER("ParseConstExpr");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
8209 ErrorMsg(expr_pos, "expression is not assignable"); 8214 ErrorMsg(expr_pos, "expression is not assignable");
8210 } 8215 }
8211 // Is prefix. 8216 // Is prefix.
8212 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); 8217 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr);
8213 Token::Kind binary_op = 8218 Token::Kind binary_op =
8214 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; 8219 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB;
8215 BinaryOpNode* add = new(isolate()) BinaryOpNode( 8220 BinaryOpNode* add = new(isolate()) BinaryOpNode(
8216 op_pos, 8221 op_pos,
8217 binary_op, 8222 binary_op,
8218 expr, 8223 expr,
8219 new(isolate()) LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); 8224 new(isolate()) LiteralNode(op_pos, Smi::ZoneHandle(I, Smi::New(1))));
8220 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); 8225 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos);
8221 ASSERT(store != NULL); 8226 ASSERT(store != NULL);
8222 let_expr->AddNode(store); 8227 let_expr->AddNode(store);
8223 expr = let_expr; 8228 expr = let_expr;
8224 } else { 8229 } else {
8225 expr = ParsePostfixExpr(); 8230 expr = ParsePostfixExpr();
8226 } 8231 }
8227 return expr; 8232 return expr;
8228 } 8233 }
8229 8234
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
8282 8287
8283 8288
8284 AstNode* Parser::ParseStaticCall(const Class& cls, 8289 AstNode* Parser::ParseStaticCall(const Class& cls,
8285 const String& func_name, 8290 const String& func_name,
8286 intptr_t ident_pos) { 8291 intptr_t ident_pos) {
8287 TRACE_PARSER("ParseStaticCall"); 8292 TRACE_PARSER("ParseStaticCall");
8288 const intptr_t call_pos = TokenPos(); 8293 const intptr_t call_pos = TokenPos();
8289 ASSERT(CurrentToken() == Token::kLPAREN); 8294 ASSERT(CurrentToken() == Token::kLPAREN);
8290 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); 8295 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst);
8291 const int num_arguments = arguments->length(); 8296 const int num_arguments = arguments->length();
8292 const Function& func = Function::ZoneHandle( 8297 const Function& func = Function::ZoneHandle(I,
8293 Resolver::ResolveStatic(cls, 8298 Resolver::ResolveStatic(cls,
8294 func_name, 8299 func_name,
8295 num_arguments, 8300 num_arguments,
8296 arguments->names())); 8301 arguments->names()));
8297 if (func.IsNull()) { 8302 if (func.IsNull()) {
8298 // Check if there is a static field of the same name, it could be a closure 8303 // Check if there is a static field of the same name, it could be a closure
8299 // and so we try and invoke the closure. 8304 // and so we try and invoke the closure.
8300 AstNode* closure = NULL; 8305 AstNode* closure = NULL;
8301 const Field& field = Field::ZoneHandle(cls.LookupStaticField(func_name)); 8306 const Field& field = Field::ZoneHandle(I, cls.LookupStaticField(func_name));
8302 Function& func = Function::ZoneHandle(); 8307 Function& func = Function::ZoneHandle(I);
8303 if (field.IsNull()) { 8308 if (field.IsNull()) {
8304 // No field, check if we have an explicit getter function. 8309 // No field, check if we have an explicit getter function.
8305 const String& getter_name = 8310 const String& getter_name =
8306 String::ZoneHandle(Field::GetterName(func_name)); 8311 String::ZoneHandle(I, Field::GetterName(func_name));
8307 const int kNumArguments = 0; // no arguments. 8312 const int kNumArguments = 0; // no arguments.
8308 func = Resolver::ResolveStatic(cls, 8313 func = Resolver::ResolveStatic(cls,
8309 getter_name, 8314 getter_name,
8310 kNumArguments, 8315 kNumArguments,
8311 Object::empty_array()); 8316 Object::empty_array());
8312 if (!func.IsNull()) { 8317 if (!func.IsNull()) {
8313 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); 8318 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter);
8314 closure = new(isolate()) StaticGetterNode(call_pos, 8319 closure = new(isolate()) StaticGetterNode(
8315 NULL, 8320 call_pos,
8316 false, 8321 NULL,
8317 Class::ZoneHandle(cls.raw()), 8322 false,
8318 func_name); 8323 Class::ZoneHandle(I, cls.raw()),
8324 func_name);
8319 return BuildClosureCall(call_pos, closure, arguments); 8325 return BuildClosureCall(call_pos, closure, arguments);
8320 } 8326 }
8321 } else { 8327 } else {
8322 closure = GenerateStaticFieldLookup(field, call_pos); 8328 closure = GenerateStaticFieldLookup(field, call_pos);
8323 return BuildClosureCall(call_pos, closure, arguments); 8329 return BuildClosureCall(call_pos, closure, arguments);
8324 } 8330 }
8325 // Could not resolve static method: throw a NoSuchMethodError. 8331 // Could not resolve static method: throw a NoSuchMethodError.
8326 return ThrowNoSuchMethodError(ident_pos, 8332 return ThrowNoSuchMethodError(ident_pos,
8327 cls, 8333 cls,
8328 func_name, 8334 func_name,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
8369 // If the static field has an initializer, initialize the field at compile 8375 // If the static field has an initializer, initialize the field at compile
8370 // time, which is only possible if the field is const. 8376 // time, which is only possible if the field is const.
8371 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); 8377 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos);
8372 if (initializing_getter != NULL) { 8378 if (initializing_getter != NULL) {
8373 // The field is not yet initialized and could not be initialized at compile 8379 // The field is not yet initialized and could not be initialized at compile
8374 // time. The getter will initialize the field. 8380 // time. The getter will initialize the field.
8375 return initializing_getter; 8381 return initializing_getter;
8376 } 8382 }
8377 // The field is initialized. 8383 // The field is initialized.
8378 ASSERT(field.is_static()); 8384 ASSERT(field.is_static());
8379 const Class& field_owner = Class::ZoneHandle(field.owner()); 8385 const Class& field_owner = Class::ZoneHandle(I, field.owner());
8380 const String& field_name = String::ZoneHandle(field.name()); 8386 const String& field_name = String::ZoneHandle(I, field.name());
8381 const String& getter_name = String::Handle(isolate(), 8387 const String& getter_name = String::Handle(isolate(),
8382 Field::GetterName(field_name)); 8388 Field::GetterName(field_name));
8383 const Function& getter = Function::Handle(isolate(), 8389 const Function& getter = Function::Handle(isolate(),
8384 field_owner.LookupStaticFunction(getter_name)); 8390 field_owner.LookupStaticFunction(getter_name));
8385 // Never load field directly if there is a getter (deterministic AST). 8391 // Never load field directly if there is a getter (deterministic AST).
8386 if (getter.IsNull() || field.is_const()) { 8392 if (getter.IsNull() || field.is_const()) {
8387 return new(isolate()) LoadStaticFieldNode( 8393 return new(isolate()) LoadStaticFieldNode(
8388 ident_pos, Field::ZoneHandle(field.raw())); 8394 ident_pos, Field::ZoneHandle(I, field.raw()));
8389 } else { 8395 } else {
8390 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter); 8396 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter);
8391 return new(isolate()) StaticGetterNode(ident_pos, 8397 return new(isolate()) StaticGetterNode(ident_pos,
8392 NULL, // Receiver. 8398 NULL, // Receiver.
8393 false, // is_super_getter. 8399 false, // is_super_getter.
8394 field_owner, 8400 field_owner,
8395 field_name); 8401 field_name);
8396 } 8402 }
8397 } 8403 }
8398 8404
8399 8405
8400 AstNode* Parser::ParseStaticFieldAccess(const Class& cls, 8406 AstNode* Parser::ParseStaticFieldAccess(const Class& cls,
8401 const String& field_name, 8407 const String& field_name,
8402 intptr_t ident_pos, 8408 intptr_t ident_pos,
8403 bool consume_cascades) { 8409 bool consume_cascades) {
8404 TRACE_PARSER("ParseStaticFieldAccess"); 8410 TRACE_PARSER("ParseStaticFieldAccess");
8405 AstNode* access = NULL; 8411 AstNode* access = NULL;
8406 const Field& field = Field::ZoneHandle(cls.LookupStaticField(field_name)); 8412 const Field& field = Field::ZoneHandle(I, cls.LookupStaticField(field_name));
8407 Function& func = Function::ZoneHandle(); 8413 Function& func = Function::ZoneHandle(I);
8408 if (field.IsNull()) { 8414 if (field.IsNull()) {
8409 // No field, check if we have an explicit getter function. 8415 // No field, check if we have an explicit getter function.
8410 const String& getter_name = 8416 const String& getter_name =
8411 String::ZoneHandle(Field::GetterName(field_name)); 8417 String::ZoneHandle(I, Field::GetterName(field_name));
8412 const int kNumArguments = 0; // no arguments. 8418 const int kNumArguments = 0; // no arguments.
8413 func = Resolver::ResolveStatic(cls, 8419 func = Resolver::ResolveStatic(cls,
8414 getter_name, 8420 getter_name,
8415 kNumArguments, 8421 kNumArguments,
8416 Object::empty_array()); 8422 Object::empty_array());
8417 if (func.IsNull()) { 8423 if (func.IsNull()) {
8418 // We might be referring to an implicit closure, check to see if 8424 // We might be referring to an implicit closure, check to see if
8419 // there is a function of the same name. 8425 // there is a function of the same name.
8420 func = cls.LookupStaticFunction(field_name); 8426 func = cls.LookupStaticFunction(field_name);
8421 if (!func.IsNull()) { 8427 if (!func.IsNull()) {
8422 access = CreateImplicitClosureNode(func, ident_pos, NULL); 8428 access = CreateImplicitClosureNode(func, ident_pos, NULL);
8423 } else { 8429 } else {
8424 // No function to closurize found found. 8430 // No function to closurize found found.
8425 // This field access may turn out to be a call to the setter. 8431 // This field access may turn out to be a call to the setter.
8426 // Create a getter call, which may later be turned into 8432 // Create a getter call, which may later be turned into
8427 // a setter call, or else the backend will generate 8433 // a setter call, or else the backend will generate
8428 // a throw NoSuchMethodError(). 8434 // a throw NoSuchMethodError().
8429 access = new(isolate()) StaticGetterNode( 8435 access = new(I) StaticGetterNode(ident_pos,
8430 ident_pos, NULL, false, Class::ZoneHandle(cls.raw()), field_name); 8436 NULL,
8437 false,
8438 Class::ZoneHandle(I, cls.raw()),
8439 field_name);
8431 } 8440 }
8432 } else { 8441 } else {
8433 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); 8442 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter);
8434 access = new(isolate()) StaticGetterNode( 8443 access = new(isolate()) StaticGetterNode(
8435 ident_pos, NULL, false, Class::ZoneHandle(cls.raw()), field_name); 8444 ident_pos, NULL, false, Class::ZoneHandle(I, cls.raw()), field_name);
8436 } 8445 }
8437 } else { 8446 } else {
8438 access = GenerateStaticFieldLookup(field, ident_pos); 8447 access = GenerateStaticFieldLookup(field, ident_pos);
8439 } 8448 }
8440 return access; 8449 return access;
8441 } 8450 }
8442 8451
8443 8452
8444 AstNode* Parser::LoadFieldIfUnresolved(AstNode* node) { 8453 AstNode* Parser::LoadFieldIfUnresolved(AstNode* node) {
8445 if (!node->IsPrimaryNode()) { 8454 if (!node->IsPrimaryNode()) {
(...skipping 15 matching lines...) Expand all
8461 "unresolved identifier '%s' is not a compile-time constant", 8470 "unresolved identifier '%s' is not a compile-time constant",
8462 name.ToCString()); 8471 name.ToCString());
8463 } 8472 }
8464 if (current_function().is_static() || 8473 if (current_function().is_static() ||
8465 current_function().IsInFactoryScope()) { 8474 current_function().IsInFactoryScope()) {
8466 StaticGetterNode* getter = 8475 StaticGetterNode* getter =
8467 new(isolate()) StaticGetterNode( 8476 new(isolate()) StaticGetterNode(
8468 primary->token_pos(), 8477 primary->token_pos(),
8469 NULL, // No receiver. 8478 NULL, // No receiver.
8470 false, // Not a super getter. 8479 false, // Not a super getter.
8471 Class::ZoneHandle(current_class().raw()), 8480 Class::ZoneHandle(I, current_class().raw()),
8472 name); 8481 name);
8473 getter->set_is_deferred(primary->is_deferred_reference()); 8482 getter->set_is_deferred(primary->is_deferred_reference());
8474 return getter; 8483 return getter;
8475 } else { 8484 } else {
8476 AstNode* receiver = LoadReceiver(primary->token_pos()); 8485 AstNode* receiver = LoadReceiver(primary->token_pos());
8477 return CallGetter(node->token_pos(), receiver, name); 8486 return CallGetter(node->token_pos(), receiver, name);
8478 } 8487 }
8479 } 8488 }
8480 return primary; 8489 return primary;
8481 } 8490 }
8482 8491
8483 8492
8484 AstNode* Parser::LoadClosure(PrimaryNode* primary) { 8493 AstNode* Parser::LoadClosure(PrimaryNode* primary) {
8485 ASSERT(primary->primary().IsFunction()); 8494 ASSERT(primary->primary().IsFunction());
8486 const Function& func = 8495 const Function& func =
8487 Function::CheckedZoneHandle(primary->primary().raw()); 8496 Function::CheckedZoneHandle(primary->primary().raw());
8488 const String& funcname = String::ZoneHandle(func.name()); 8497 const String& funcname = String::ZoneHandle(I, func.name());
8489 if (func.is_static()) { 8498 if (func.is_static()) {
8490 // Static function access. 8499 // Static function access.
8491 ClosureNode* closure = 8500 ClosureNode* closure =
8492 CreateImplicitClosureNode(func, primary->token_pos(), NULL); 8501 CreateImplicitClosureNode(func, primary->token_pos(), NULL);
8493 closure->set_is_deferred(primary->is_deferred_reference()); 8502 closure->set_is_deferred(primary->is_deferred_reference());
8494 return closure; 8503 return closure;
8495 } else { 8504 } else {
8496 // Instance function access. 8505 // Instance function access.
8497 if (parsing_metadata_) { 8506 if (parsing_metadata_) {
8498 ErrorMsg(primary->token_pos(), 8507 ErrorMsg(primary->token_pos(),
(...skipping 20 matching lines...) Expand all
8519 AstNode* selector = NULL; 8528 AstNode* selector = NULL;
8520 if (CurrentToken() == Token::kPERIOD) { 8529 if (CurrentToken() == Token::kPERIOD) {
8521 ConsumeToken(); 8530 ConsumeToken();
8522 if (left->IsPrimaryNode()) { 8531 if (left->IsPrimaryNode()) {
8523 PrimaryNode* primary_node = left->AsPrimaryNode(); 8532 PrimaryNode* primary_node = left->AsPrimaryNode();
8524 const intptr_t primary_pos = primary_node->token_pos(); 8533 const intptr_t primary_pos = primary_node->token_pos();
8525 if (primary_node->primary().IsFunction()) { 8534 if (primary_node->primary().IsFunction()) {
8526 left = LoadClosure(primary_node); 8535 left = LoadClosure(primary_node);
8527 } else if (primary_node->primary().IsTypeParameter()) { 8536 } else if (primary_node->primary().IsTypeParameter()) {
8528 if (current_function().is_static()) { 8537 if (current_function().is_static()) {
8529 const String& name = String::ZoneHandle( 8538 const String& name = String::ZoneHandle(I,
8530 TypeParameter::Cast(primary_node->primary()).name()); 8539 TypeParameter::Cast(primary_node->primary()).name());
8531 ErrorMsg(primary_pos, 8540 ErrorMsg(primary_pos,
8532 "cannot access type parameter '%s' from static function", 8541 "cannot access type parameter '%s' from static function",
8533 name.ToCString()); 8542 name.ToCString());
8534 } 8543 }
8535 if (current_block_->scope->function_level() > 0) { 8544 if (current_block_->scope->function_level() > 0) {
8536 // Make sure that the instantiator is captured. 8545 // Make sure that the instantiator is captured.
8537 CaptureInstantiator(); 8546 CaptureInstantiator();
8538 } 8547 }
8539 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8548 TypeParameter& type_parameter = TypeParameter::ZoneHandle(I);
8540 type_parameter ^= ClassFinalizer::FinalizeType( 8549 type_parameter ^= ClassFinalizer::FinalizeType(
8541 current_class(), 8550 current_class(),
8542 TypeParameter::Cast(primary_node->primary()), 8551 TypeParameter::Cast(primary_node->primary()),
8543 ClassFinalizer::kCanonicalize); 8552 ClassFinalizer::kCanonicalize);
8544 ASSERT(!type_parameter.IsMalformed()); 8553 ASSERT(!type_parameter.IsMalformed());
8545 left = new(isolate()) TypeNode(primary->token_pos(), type_parameter); 8554 left = new(isolate()) TypeNode(primary->token_pos(), type_parameter);
8546 } else { 8555 } else {
8547 // Super field access handled in ParseSuperFieldAccess(), 8556 // Super field access handled in ParseSuperFieldAccess(),
8548 // super calls handled in ParseSuperCall(). 8557 // super calls handled in ParseSuperCall().
8549 ASSERT(!primary_node->IsSuper()); 8558 ASSERT(!primary_node->IsSuper());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
8594 SetAllowFunctionLiterals(saved_mode); 8603 SetAllowFunctionLiterals(saved_mode);
8595 ExpectToken(Token::kRBRACK); 8604 ExpectToken(Token::kRBRACK);
8596 AstNode* array = left; 8605 AstNode* array = left;
8597 if (left->IsPrimaryNode()) { 8606 if (left->IsPrimaryNode()) {
8598 PrimaryNode* primary_node = left->AsPrimaryNode(); 8607 PrimaryNode* primary_node = left->AsPrimaryNode();
8599 const intptr_t primary_pos = primary_node->token_pos(); 8608 const intptr_t primary_pos = primary_node->token_pos();
8600 if (primary_node->primary().IsFunction()) { 8609 if (primary_node->primary().IsFunction()) {
8601 array = LoadClosure(primary_node); 8610 array = LoadClosure(primary_node);
8602 } else if (primary_node->primary().IsClass()) { 8611 } else if (primary_node->primary().IsClass()) {
8603 const Class& type_class = Class::Cast(primary_node->primary()); 8612 const Class& type_class = Class::Cast(primary_node->primary());
8604 AbstractType& type = Type::ZoneHandle( 8613 AbstractType& type = Type::ZoneHandle(I,
8605 Type::New(type_class, TypeArguments::Handle(isolate()), 8614 Type::New(type_class, TypeArguments::Handle(isolate()),
8606 primary_pos, Heap::kOld)); 8615 primary_pos, Heap::kOld));
8607 type ^= ClassFinalizer::FinalizeType( 8616 type ^= ClassFinalizer::FinalizeType(
8608 current_class(), type, ClassFinalizer::kCanonicalize); 8617 current_class(), type, ClassFinalizer::kCanonicalize);
8609 // Type may be malbounded, but not malformed. 8618 // Type may be malbounded, but not malformed.
8610 ASSERT(!type.IsMalformed()); 8619 ASSERT(!type.IsMalformed());
8611 array = new(isolate()) TypeNode(primary_pos, type); 8620 array = new(isolate()) TypeNode(primary_pos, type);
8612 } else if (primary_node->primary().IsTypeParameter()) { 8621 } else if (primary_node->primary().IsTypeParameter()) {
8613 if (current_function().is_static()) { 8622 if (current_function().is_static()) {
8614 const String& name = String::ZoneHandle( 8623 const String& name = String::ZoneHandle(I,
8615 TypeParameter::Cast(primary_node->primary()).name()); 8624 TypeParameter::Cast(primary_node->primary()).name());
8616 ErrorMsg(primary_pos, 8625 ErrorMsg(primary_pos,
8617 "cannot access type parameter '%s' from static function", 8626 "cannot access type parameter '%s' from static function",
8618 name.ToCString()); 8627 name.ToCString());
8619 } 8628 }
8620 if (current_block_->scope->function_level() > 0) { 8629 if (current_block_->scope->function_level() > 0) {
8621 // Make sure that the instantiator is captured. 8630 // Make sure that the instantiator is captured.
8622 CaptureInstantiator(); 8631 CaptureInstantiator();
8623 } 8632 }
8624 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8633 TypeParameter& type_parameter = TypeParameter::ZoneHandle(I);
8625 type_parameter ^= ClassFinalizer::FinalizeType( 8634 type_parameter ^= ClassFinalizer::FinalizeType(
8626 current_class(), 8635 current_class(),
8627 TypeParameter::Cast(primary_node->primary()), 8636 TypeParameter::Cast(primary_node->primary()),
8628 ClassFinalizer::kCanonicalize); 8637 ClassFinalizer::kCanonicalize);
8629 ASSERT(!type_parameter.IsMalformed()); 8638 ASSERT(!type_parameter.IsMalformed());
8630 array = new(isolate()) TypeNode(primary_pos, type_parameter); 8639 array = new(isolate()) TypeNode(primary_pos, type_parameter);
8631 } else { 8640 } else {
8632 UNREACHABLE(); // Internal parser error. 8641 UNREACHABLE(); // Internal parser error.
8633 } 8642 }
8634 } 8643 }
8635 selector = new(isolate()) LoadIndexedNode( 8644 selector = new(isolate()) LoadIndexedNode(
8636 bracket_pos, array, index, Class::ZoneHandle()); 8645 bracket_pos, array, index, Class::ZoneHandle(I));
8637 } else if (CurrentToken() == Token::kLPAREN) { 8646 } else if (CurrentToken() == Token::kLPAREN) {
8638 if (left->IsPrimaryNode()) { 8647 if (left->IsPrimaryNode()) {
8639 PrimaryNode* primary_node = left->AsPrimaryNode(); 8648 PrimaryNode* primary_node = left->AsPrimaryNode();
8640 const intptr_t primary_pos = primary_node->token_pos(); 8649 const intptr_t primary_pos = primary_node->token_pos();
8641 if (primary_node->primary().IsFunction()) { 8650 if (primary_node->primary().IsFunction()) {
8642 const Function& func = Function::Cast(primary_node->primary()); 8651 const Function& func = Function::Cast(primary_node->primary());
8643 const String& func_name = String::ZoneHandle(func.name()); 8652 const String& func_name = String::ZoneHandle(I, func.name());
8644 if (func.is_static()) { 8653 if (func.is_static()) {
8645 // Parse static function call. 8654 // Parse static function call.
8646 Class& cls = Class::Handle(isolate(), func.Owner()); 8655 Class& cls = Class::Handle(isolate(), func.Owner());
8647 selector = ParseStaticCall(cls, func_name, primary_pos); 8656 selector = ParseStaticCall(cls, func_name, primary_pos);
8648 } else { 8657 } else {
8649 // Dynamic function call on implicit "this" parameter. 8658 // Dynamic function call on implicit "this" parameter.
8650 if (current_function().is_static()) { 8659 if (current_function().is_static()) {
8651 ErrorMsg(primary_pos, 8660 ErrorMsg(primary_pos,
8652 "cannot access instance method '%s' " 8661 "cannot access instance method '%s' "
8653 "from static function", 8662 "from static function",
(...skipping 14 matching lines...) Expand all
8668 name, 8677 name,
8669 NULL, // No arguments. 8678 NULL, // No arguments.
8670 InvocationMirror::kStatic, 8679 InvocationMirror::kStatic,
8671 InvocationMirror::kMethod, 8680 InvocationMirror::kMethod,
8672 NULL); // No existing function. 8681 NULL); // No existing function.
8673 } else { 8682 } else {
8674 // Treat as call to unresolved (instance) method. 8683 // Treat as call to unresolved (instance) method.
8675 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); 8684 selector = ParseInstanceCall(LoadReceiver(primary_pos), name);
8676 } 8685 }
8677 } else if (primary_node->primary().IsTypeParameter()) { 8686 } else if (primary_node->primary().IsTypeParameter()) {
8678 const String& name = String::ZoneHandle( 8687 const String& name = String::ZoneHandle(I,
8679 TypeParameter::Cast(primary_node->primary()).name()); 8688 TypeParameter::Cast(primary_node->primary()).name());
8680 if (current_function().is_static()) { 8689 if (current_function().is_static()) {
8681 // Treat as this.T(), because T is in scope. 8690 // Treat as this.T(), because T is in scope.
8682 ErrorMsg(primary_pos, 8691 ErrorMsg(primary_pos,
8683 "cannot access type parameter '%s' from static function", 8692 "cannot access type parameter '%s' from static function",
8684 name.ToCString()); 8693 name.ToCString());
8685 } else { 8694 } else {
8686 // Treat as call to unresolved (instance) method. 8695 // Treat as call to unresolved (instance) method.
8687 selector = ParseInstanceCall(LoadReceiver(primary_pos), name); 8696 selector = ParseInstanceCall(LoadReceiver(primary_pos), name);
8688 } 8697 }
8689 } else if (primary_node->primary().IsClass()) { 8698 } else if (primary_node->primary().IsClass()) {
8690 const Class& type_class = Class::Cast(primary_node->primary()); 8699 const Class& type_class = Class::Cast(primary_node->primary());
8691 AbstractType& type = Type::ZoneHandle(Type::New( 8700 AbstractType& type = Type::ZoneHandle(I, Type::New(
8692 type_class, TypeArguments::Handle(isolate()), primary_pos)); 8701 type_class, TypeArguments::Handle(isolate()), primary_pos));
8693 type ^= ClassFinalizer::FinalizeType( 8702 type ^= ClassFinalizer::FinalizeType(
8694 current_class(), type, ClassFinalizer::kCanonicalize); 8703 current_class(), type, ClassFinalizer::kCanonicalize);
8695 // Type may be malbounded, but not malformed. 8704 // Type may be malbounded, but not malformed.
8696 ASSERT(!type.IsMalformed()); 8705 ASSERT(!type.IsMalformed());
8697 selector = new(isolate()) TypeNode(primary_pos, type); 8706 selector = new(isolate()) TypeNode(primary_pos, type);
8698 } else { 8707 } else {
8699 UNREACHABLE(); // Internal parser error. 8708 UNREACHABLE(); // Internal parser error.
8700 } 8709 }
8701 } else { 8710 } else {
(...skipping 13 matching lines...) Expand all
8715 // No (more) selectors to parse. 8724 // No (more) selectors to parse.
8716 left = LoadFieldIfUnresolved(left); 8725 left = LoadFieldIfUnresolved(left);
8717 if (left->IsPrimaryNode()) { 8726 if (left->IsPrimaryNode()) {
8718 PrimaryNode* primary_node = left->AsPrimaryNode(); 8727 PrimaryNode* primary_node = left->AsPrimaryNode();
8719 const intptr_t primary_pos = primary->token_pos(); 8728 const intptr_t primary_pos = primary->token_pos();
8720 if (primary_node->primary().IsFunction()) { 8729 if (primary_node->primary().IsFunction()) {
8721 // Treat as implicit closure. 8730 // Treat as implicit closure.
8722 left = LoadClosure(primary_node); 8731 left = LoadClosure(primary_node);
8723 } else if (primary_node->primary().IsClass()) { 8732 } else if (primary_node->primary().IsClass()) {
8724 const Class& type_class = Class::Cast(primary_node->primary()); 8733 const Class& type_class = Class::Cast(primary_node->primary());
8725 AbstractType& type = Type::ZoneHandle(Type::New( 8734 AbstractType& type = Type::ZoneHandle(I, Type::New(
8726 type_class, TypeArguments::Handle(isolate()), primary_pos)); 8735 type_class, TypeArguments::Handle(isolate()), primary_pos));
8727 type = ClassFinalizer::FinalizeType( 8736 type = ClassFinalizer::FinalizeType(
8728 current_class(), type, ClassFinalizer::kCanonicalize); 8737 current_class(), type, ClassFinalizer::kCanonicalize);
8729 // Type may be malbounded, but not malformed. 8738 // Type may be malbounded, but not malformed.
8730 ASSERT(!type.IsMalformed()); 8739 ASSERT(!type.IsMalformed());
8731 left = new(isolate()) TypeNode(primary_pos, type); 8740 left = new(isolate()) TypeNode(primary_pos, type);
8732 } else if (primary_node->primary().IsTypeParameter()) { 8741 } else if (primary_node->primary().IsTypeParameter()) {
8733 if (current_function().is_static()) { 8742 if (current_function().is_static()) {
8734 const String& name = String::ZoneHandle( 8743 const String& name = String::ZoneHandle(I,
8735 TypeParameter::Cast(primary_node->primary()).name()); 8744 TypeParameter::Cast(primary_node->primary()).name());
8736 ErrorMsg(primary_pos, 8745 ErrorMsg(primary_pos,
8737 "cannot access type parameter '%s' from static function", 8746 "cannot access type parameter '%s' from static function",
8738 name.ToCString()); 8747 name.ToCString());
8739 } 8748 }
8740 if (current_block_->scope->function_level() > 0) { 8749 if (current_block_->scope->function_level() > 0) {
8741 // Make sure that the instantiator is captured. 8750 // Make sure that the instantiator is captured.
8742 CaptureInstantiator(); 8751 CaptureInstantiator();
8743 } 8752 }
8744 TypeParameter& type_parameter = TypeParameter::ZoneHandle(); 8753 TypeParameter& type_parameter = TypeParameter::ZoneHandle(I);
8745 type_parameter ^= ClassFinalizer::FinalizeType( 8754 type_parameter ^= ClassFinalizer::FinalizeType(
8746 current_class(), 8755 current_class(),
8747 TypeParameter::Cast(primary_node->primary()), 8756 TypeParameter::Cast(primary_node->primary()),
8748 ClassFinalizer::kCanonicalize); 8757 ClassFinalizer::kCanonicalize);
8749 ASSERT(!type_parameter.IsMalformed()); 8758 ASSERT(!type_parameter.IsMalformed());
8750 left = new(isolate()) TypeNode(primary_pos, type_parameter); 8759 left = new(isolate()) TypeNode(primary_pos, type_parameter);
8751 } else if (primary_node->IsSuper()) { 8760 } else if (primary_node->IsSuper()) {
8752 // Return "super" to handle unary super operator calls, 8761 // Return "super" to handle unary super operator calls,
8753 // or to report illegal use of "super" otherwise. 8762 // or to report illegal use of "super" otherwise.
8754 left = primary_node; 8763 left = primary_node;
(...skipping 26 matching lines...) Expand all
8781 ConsumeToken(); 8790 ConsumeToken();
8782 // Not prefix. 8791 // Not prefix.
8783 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); 8792 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr);
8784 LocalVariable* temp = let_expr->AddInitializer(expr); 8793 LocalVariable* temp = let_expr->AddInitializer(expr);
8785 Token::Kind binary_op = 8794 Token::Kind binary_op =
8786 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; 8795 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB;
8787 BinaryOpNode* add = new(isolate()) BinaryOpNode( 8796 BinaryOpNode* add = new(isolate()) BinaryOpNode(
8788 expr_pos, 8797 expr_pos,
8789 binary_op, 8798 binary_op,
8790 new(isolate()) LoadLocalNode(expr_pos, temp), 8799 new(isolate()) LoadLocalNode(expr_pos, temp),
8791 new(isolate()) LiteralNode(expr_pos, Smi::ZoneHandle(Smi::New(1)))); 8800 new(isolate()) LiteralNode(expr_pos, Smi::ZoneHandle(I, Smi::New(1))));
8792 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos); 8801 AstNode* store = CreateAssignmentNode(expr, add, expr_ident, expr_pos);
8793 ASSERT(store != NULL); 8802 ASSERT(store != NULL);
8794 // The result is a pair of the (side effects of the) store followed by 8803 // The result is a pair of the (side effects of the) store followed by
8795 // the (value of the) initial value temp variable load. 8804 // the (value of the) initial value temp variable load.
8796 let_expr->AddNode(store); 8805 let_expr->AddNode(store);
8797 let_expr->AddNode(new(isolate()) LoadLocalNode(expr_pos, temp)); 8806 let_expr->AddNode(new(isolate()) LoadLocalNode(expr_pos, temp));
8798 return let_expr; 8807 return let_expr;
8799 } 8808 }
8800 return expr; 8809 return expr;
8801 } 8810 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
8983 return result.raw(); 8992 return result.raw();
8984 } 8993 }
8985 8994
8986 8995
8987 // If the field is already initialized, return no ast (NULL). 8996 // If the field is already initialized, return no ast (NULL).
8988 // Otherwise, if the field is constant, initialize the field and return no ast. 8997 // Otherwise, if the field is constant, initialize the field and return no ast.
8989 // If the field is not initialized and not const, return the ast for the getter. 8998 // If the field is not initialized and not const, return the ast for the getter.
8990 AstNode* Parser::RunStaticFieldInitializer(const Field& field, 8999 AstNode* Parser::RunStaticFieldInitializer(const Field& field,
8991 intptr_t field_ref_pos) { 9000 intptr_t field_ref_pos) {
8992 ASSERT(field.is_static()); 9001 ASSERT(field.is_static());
8993 const Class& field_owner = Class::ZoneHandle(isolate(), field.owner()); 9002 const Class& field_owner = Class::ZoneHandle(I, field.owner());
8994 const String& field_name = String::ZoneHandle(isolate(), field.name()); 9003 const String& field_name = String::ZoneHandle(I, field.name());
8995 const String& getter_name = String::Handle(isolate(), 9004 const String& getter_name = String::Handle(isolate(),
8996 Field::GetterName(field_name)); 9005 Field::GetterName(field_name));
8997 const Function& getter = Function::Handle( 9006 const Function& getter = Function::Handle(
8998 isolate(), field_owner.LookupStaticFunction(getter_name)); 9007 isolate(), field_owner.LookupStaticFunction(getter_name));
8999 const Instance& value = Instance::Handle(isolate(), field.value()); 9008 const Instance& value = Instance::Handle(isolate(), field.value());
9000 if (value.raw() == Object::transition_sentinel().raw()) { 9009 if (value.raw() == Object::transition_sentinel().raw()) {
9001 if (field.is_const()) { 9010 if (field.is_const()) {
9002 ErrorMsg("circular dependency while initializing static field '%s'", 9011 ErrorMsg("circular dependency while initializing static field '%s'",
9003 field_name.ToCString()); 9012 field_name.ToCString());
9004 } else { 9013 } else {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
9178 } 9187 }
9179 9188
9180 // Check if an instance/static function exists. 9189 // Check if an instance/static function exists.
9181 func = cls.LookupFunction(ident); 9190 func = cls.LookupFunction(ident);
9182 if (!func.IsNull() && 9191 if (!func.IsNull() &&
9183 (func.IsDynamicFunction() || 9192 (func.IsDynamicFunction() ||
9184 func.IsStaticFunction() || 9193 func.IsStaticFunction() ||
9185 func.is_abstract())) { 9194 func.is_abstract())) {
9186 if (node != NULL) { 9195 if (node != NULL) {
9187 *node = new(isolate()) PrimaryNode( 9196 *node = new(isolate()) PrimaryNode(
9188 ident_pos, Function::ZoneHandle(isolate(), func.raw())); 9197 ident_pos, Function::ZoneHandle(I, func.raw()));
9189 } 9198 }
9190 return true; 9199 return true;
9191 } 9200 }
9192 9201
9193 // Now check if a getter/setter method exists for it in which case 9202 // Now check if a getter/setter method exists for it in which case
9194 // it is still a field. 9203 // it is still a field.
9195 func = cls.LookupGetterFunction(ident); 9204 func = cls.LookupGetterFunction(ident);
9196 if (!func.IsNull()) { 9205 if (!func.IsNull()) {
9197 if (func.IsDynamicFunction() || func.is_abstract()) { 9206 if (func.IsDynamicFunction() || func.is_abstract()) {
9198 if (node != NULL) { 9207 if (node != NULL) {
(...skipping 17 matching lines...) Expand all
9216 "'%s' is not a compile-time constant", 9225 "'%s' is not a compile-time constant",
9217 ident.ToCString()); 9226 ident.ToCString());
9218 } 9227 }
9219 if (!current_function().is_static() && 9228 if (!current_function().is_static() &&
9220 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { 9229 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) {
9221 receiver = LoadReceiver(ident_pos); 9230 receiver = LoadReceiver(ident_pos);
9222 } 9231 }
9223 *node = new(isolate()) StaticGetterNode(ident_pos, 9232 *node = new(isolate()) StaticGetterNode(ident_pos,
9224 receiver, 9233 receiver,
9225 false, 9234 false,
9226 Class::ZoneHandle(isolate(), cls.raw()), 9235 Class::ZoneHandle(I, cls.raw()),
9227 ident); 9236 ident);
9228 } 9237 }
9229 return true; 9238 return true;
9230 } 9239 }
9231 } 9240 }
9232 func = cls.LookupSetterFunction(ident); 9241 func = cls.LookupSetterFunction(ident);
9233 if (!func.IsNull()) { 9242 if (!func.IsNull()) {
9234 if (func.IsDynamicFunction() || func.is_abstract()) { 9243 if (func.IsDynamicFunction() || func.is_abstract()) {
9235 if (node != NULL) { 9244 if (node != NULL) {
9236 // We create a getter node even though a getter doesn't exist as 9245 // We create a getter node even though a getter doesn't exist as
9237 // it could be followed by an assignment which will convert it to 9246 // it could be followed by an assignment which will convert it to
9238 // a setter node. If there is no assignment we will get an error 9247 // a setter node. If there is no assignment we will get an error
9239 // when we try to invoke the getter. 9248 // when we try to invoke the getter.
9240 CheckInstanceFieldAccess(ident_pos, ident); 9249 CheckInstanceFieldAccess(ident_pos, ident);
9241 ASSERT(AbstractType::Handle(isolate(), 9250 ASSERT(AbstractType::Handle(isolate(),
9242 func.result_type()).IsResolved()); 9251 func.result_type()).IsResolved());
9243 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); 9252 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident);
9244 } 9253 }
9245 return true; 9254 return true;
9246 } else if (func.IsStaticFunction()) { 9255 } else if (func.IsStaticFunction()) {
9247 if (node != NULL) { 9256 if (node != NULL) {
9248 // We create a getter node even though a getter doesn't exist as 9257 // We create a getter node even though a getter doesn't exist as
9249 // it could be followed by an assignment which will convert it to 9258 // it could be followed by an assignment which will convert it to
9250 // a setter node. If there is no assignment we will get an error 9259 // a setter node. If there is no assignment we will get an error
9251 // when we try to invoke the getter. 9260 // when we try to invoke the getter.
9252 *node = new(isolate()) StaticGetterNode( 9261 *node = new(isolate()) StaticGetterNode(
9253 ident_pos, 9262 ident_pos,
9254 NULL, 9263 NULL,
9255 false, 9264 false,
9256 Class::ZoneHandle(isolate(), cls.raw()), 9265 Class::ZoneHandle(I, cls.raw()),
9257 ident); 9266 ident);
9258 } 9267 }
9259 return true; 9268 return true;
9260 } 9269 }
9261 } 9270 }
9262 9271
9263 // Nothing found in scope of current class. 9272 // Nothing found in scope of current class.
9264 if (node != NULL) { 9273 if (node != NULL) {
9265 *node = NULL; 9274 *node = NULL;
9266 } 9275 }
(...skipping 14 matching lines...) Expand all
9281 // Resolve an identifier by checking the global scope of the current 9290 // Resolve an identifier by checking the global scope of the current
9282 // library. If not found in the current library, then look in the scopes 9291 // library. If not found in the current library, then look in the scopes
9283 // of all libraries that are imported without a library prefix. 9292 // of all libraries that are imported without a library prefix.
9284 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos, 9293 AstNode* Parser::ResolveIdentInCurrentLibraryScope(intptr_t ident_pos,
9285 const String& ident) { 9294 const String& ident) {
9286 TRACE_PARSER("ResolveIdentInCurrentLibraryScope"); 9295 TRACE_PARSER("ResolveIdentInCurrentLibraryScope");
9287 HANDLESCOPE(isolate()); 9296 HANDLESCOPE(isolate());
9288 const Object& obj = Object::Handle(isolate(), library_.ResolveName(ident)); 9297 const Object& obj = Object::Handle(isolate(), library_.ResolveName(ident));
9289 if (obj.IsClass()) { 9298 if (obj.IsClass()) {
9290 const Class& cls = Class::Cast(obj); 9299 const Class& cls = Class::Cast(obj);
9291 return new(isolate()) PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); 9300 return new(isolate()) PrimaryNode(
9301 ident_pos, Class::ZoneHandle(I, cls.raw()));
9292 } else if (obj.IsField()) { 9302 } else if (obj.IsField()) {
9293 const Field& field = Field::Cast(obj); 9303 const Field& field = Field::Cast(obj);
9294 ASSERT(field.is_static()); 9304 ASSERT(field.is_static());
9295 return GenerateStaticFieldLookup(field, ident_pos); 9305 return GenerateStaticFieldLookup(field, ident_pos);
9296 } else if (obj.IsFunction()) { 9306 } else if (obj.IsFunction()) {
9297 const Function& func = Function::Cast(obj); 9307 const Function& func = Function::Cast(obj);
9298 ASSERT(func.is_static()); 9308 ASSERT(func.is_static());
9299 if (func.IsGetterFunction() || func.IsSetterFunction()) { 9309 if (func.IsGetterFunction() || func.IsSetterFunction()) {
9300 return new(isolate()) StaticGetterNode(ident_pos, 9310 return new(isolate()) StaticGetterNode(ident_pos,
9301 /* receiver */ NULL, 9311 /* receiver */ NULL,
9302 /* is_super_getter */ false, 9312 /* is_super_getter */ false,
9303 Class::ZoneHandle(func.Owner()), 9313 Class::ZoneHandle(I, func.Owner()),
9304 ident); 9314 ident);
9305 9315
9306 } else { 9316 } else {
9307 return new(isolate()) PrimaryNode(ident_pos, 9317 return new(isolate()) PrimaryNode(ident_pos,
9308 Function::ZoneHandle(func.raw())); 9318 Function::ZoneHandle(I, func.raw()));
9309 } 9319 }
9310 } else { 9320 } else {
9311 ASSERT(obj.IsNull() || obj.IsLibraryPrefix()); 9321 ASSERT(obj.IsNull() || obj.IsLibraryPrefix());
9312 } 9322 }
9313 // Lexically unresolved primary identifiers are referenced by their name. 9323 // Lexically unresolved primary identifiers are referenced by their name.
9314 return new(isolate()) PrimaryNode(ident_pos, ident); 9324 return new(isolate()) PrimaryNode(ident_pos, ident);
9315 } 9325 }
9316 9326
9317 9327
9318 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix, 9328 RawClass* Parser::ResolveClassInPrefixScope(const LibraryPrefix& prefix,
(...skipping 26 matching lines...) Expand all
9345 parsed_function()->AddDeferredPrefix(prefix); 9355 parsed_function()->AddDeferredPrefix(prefix);
9346 } 9356 }
9347 } 9357 }
9348 const bool is_deferred = prefix.is_deferred_load(); 9358 const bool is_deferred = prefix.is_deferred_load();
9349 if (obj.IsNull()) { 9359 if (obj.IsNull()) {
9350 // Unresolved prefixed primary identifier. 9360 // Unresolved prefixed primary identifier.
9351 return NULL; 9361 return NULL;
9352 } else if (obj.IsClass()) { 9362 } else if (obj.IsClass()) {
9353 const Class& cls = Class::Cast(obj); 9363 const Class& cls = Class::Cast(obj);
9354 PrimaryNode* primary = 9364 PrimaryNode* primary =
9355 new(isolate()) PrimaryNode(ident_pos, Class::ZoneHandle(cls.raw())); 9365 new(isolate()) PrimaryNode(ident_pos, Class::ZoneHandle(I, cls.raw()));
9356 primary->set_is_deferred(is_deferred); 9366 primary->set_is_deferred(is_deferred);
9357 return primary; 9367 return primary;
9358 } else if (obj.IsField()) { 9368 } else if (obj.IsField()) {
9359 const Field& field = Field::Cast(obj); 9369 const Field& field = Field::Cast(obj);
9360 ASSERT(field.is_static()); 9370 ASSERT(field.is_static());
9361 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos); 9371 AstNode* get_field = GenerateStaticFieldLookup(field, ident_pos);
9362 ASSERT(get_field != NULL); 9372 ASSERT(get_field != NULL);
9363 ASSERT(get_field->IsLoadStaticFieldNode() || 9373 ASSERT(get_field->IsLoadStaticFieldNode() ||
9364 get_field->IsStaticGetterNode()); 9374 get_field->IsStaticGetterNode());
9365 if (get_field->IsLoadStaticFieldNode()) { 9375 if (get_field->IsLoadStaticFieldNode()) {
9366 get_field->AsLoadStaticFieldNode()->set_is_deferred(is_deferred); 9376 get_field->AsLoadStaticFieldNode()->set_is_deferred(is_deferred);
9367 } else if (get_field->IsStaticGetterNode()) { 9377 } else if (get_field->IsStaticGetterNode()) {
9368 get_field->AsStaticGetterNode()->set_is_deferred(is_deferred); 9378 get_field->AsStaticGetterNode()->set_is_deferred(is_deferred);
9369 } 9379 }
9370 return get_field; 9380 return get_field;
9371 } else if (obj.IsFunction()) { 9381 } else if (obj.IsFunction()) {
9372 const Function& func = Function::Cast(obj); 9382 const Function& func = Function::Cast(obj);
9373 ASSERT(func.is_static()); 9383 ASSERT(func.is_static());
9374 if (func.IsGetterFunction() || func.IsSetterFunction()) { 9384 if (func.IsGetterFunction() || func.IsSetterFunction()) {
9375 StaticGetterNode* getter = 9385 StaticGetterNode* getter =
9376 new(isolate()) StaticGetterNode(ident_pos, 9386 new(isolate()) StaticGetterNode(ident_pos,
9377 /* receiver */ NULL, 9387 /* receiver */ NULL,
9378 /* is_super_getter */ false, 9388 /* is_super_getter */ false,
9379 Class::ZoneHandle(isolate(), func.Owner()), 9389 Class::ZoneHandle(I, func.Owner()),
9380 ident); 9390 ident);
9381 getter->set_is_deferred(is_deferred); 9391 getter->set_is_deferred(is_deferred);
9382 return getter; 9392 return getter;
9383 } else { 9393 } else {
9384 PrimaryNode* primary = new(isolate()) PrimaryNode( 9394 PrimaryNode* primary = new(isolate()) PrimaryNode(
9385 ident_pos, Function::ZoneHandle(isolate(), func.raw())); 9395 ident_pos, Function::ZoneHandle(I, func.raw()));
9386 primary->set_is_deferred(is_deferred); 9396 primary->set_is_deferred(is_deferred);
9387 return primary; 9397 return primary;
9388 } 9398 }
9389 } 9399 }
9390 // All possible object types are handled above. 9400 // All possible object types are handled above.
9391 UNREACHABLE(); 9401 UNREACHABLE();
9392 return NULL; 9402 return NULL;
9393 } 9403 }
9394 9404
9395 9405
9396 // Resolve identifier. Issue an error message if 9406 // Resolve identifier. Issue an error message if
9397 // the ident refers to a method and allow_closure_names is false. 9407 // the ident refers to a method and allow_closure_names is false.
9398 // If the name cannot be resolved, turn it into an instance field access 9408 // If the name cannot be resolved, turn it into an instance field access
9399 // if we're compiling an instance method, or generate 9409 // if we're compiling an instance method, or generate
9400 // throw NoSuchMethodError if we're compiling a static method. 9410 // throw NoSuchMethodError if we're compiling a static method.
9401 AstNode* Parser::ResolveIdent(intptr_t ident_pos, 9411 AstNode* Parser::ResolveIdent(intptr_t ident_pos,
9402 const String& ident, 9412 const String& ident,
9403 bool allow_closure_names) { 9413 bool allow_closure_names) {
9404 TRACE_PARSER("ResolveIdent"); 9414 TRACE_PARSER("ResolveIdent");
9405 // First try to find the variable in the local scope (block scope or 9415 // First try to find the variable in the local scope (block scope or
9406 // class scope). 9416 // class scope).
9407 AstNode* resolved = NULL; 9417 AstNode* resolved = NULL;
9408 ResolveIdentInLocalScope(ident_pos, ident, &resolved); 9418 ResolveIdentInLocalScope(ident_pos, ident, &resolved);
9409 if (resolved == NULL) { 9419 if (resolved == NULL) {
9410 // Check whether the identifier is a type parameter. 9420 // Check whether the identifier is a type parameter.
9411 if (!current_class().IsNull()) { 9421 if (!current_class().IsNull()) {
9412 TypeParameter& type_parameter = TypeParameter::ZoneHandle( 9422 TypeParameter& type_parameter = TypeParameter::ZoneHandle(I,
9413 current_class().LookupTypeParameter(ident)); 9423 current_class().LookupTypeParameter(ident));
9414 if (!type_parameter.IsNull()) { 9424 if (!type_parameter.IsNull()) {
9415 if (current_block_->scope->function_level() > 0) { 9425 if (current_block_->scope->function_level() > 0) {
9416 // Make sure that the instantiator is captured. 9426 // Make sure that the instantiator is captured.
9417 CaptureInstantiator(); 9427 CaptureInstantiator();
9418 } 9428 }
9419 type_parameter ^= ClassFinalizer::FinalizeType( 9429 type_parameter ^= ClassFinalizer::FinalizeType(
9420 current_class(), type_parameter, ClassFinalizer::kCanonicalize); 9430 current_class(), type_parameter, ClassFinalizer::kCanonicalize);
9421 ASSERT(!type_parameter.IsMalformed()); 9431 ASSERT(!type_parameter.IsMalformed());
9422 return new(isolate()) TypeNode(ident_pos, type_parameter); 9432 return new(isolate()) TypeNode(ident_pos, type_parameter);
(...skipping 27 matching lines...) Expand all
9450 } 9460 }
9451 } else if (primary->primary().IsFunction()) { 9461 } else if (primary->primary().IsFunction()) {
9452 if (allow_closure_names) { 9462 if (allow_closure_names) {
9453 resolved = LoadClosure(primary); 9463 resolved = LoadClosure(primary);
9454 } else { 9464 } else {
9455 ErrorMsg(ident_pos, "illegal reference to method '%s'", 9465 ErrorMsg(ident_pos, "illegal reference to method '%s'",
9456 ident.ToCString()); 9466 ident.ToCString());
9457 } 9467 }
9458 } else if (primary->primary().IsClass()) { 9468 } else if (primary->primary().IsClass()) {
9459 const Class& type_class = Class::Cast(primary->primary()); 9469 const Class& type_class = Class::Cast(primary->primary());
9460 AbstractType& type = Type::ZoneHandle( 9470 AbstractType& type = Type::ZoneHandle(I,
9461 Type::New(type_class, TypeArguments::Handle(isolate()), primary_pos)); 9471 Type::New(type_class, TypeArguments::Handle(isolate()), primary_pos));
9462 type ^= ClassFinalizer::FinalizeType( 9472 type ^= ClassFinalizer::FinalizeType(
9463 current_class(), type, ClassFinalizer::kCanonicalize); 9473 current_class(), type, ClassFinalizer::kCanonicalize);
9464 // Type may be malbounded, but not malformed. 9474 // Type may be malbounded, but not malformed.
9465 ASSERT(!type.IsMalformed()); 9475 ASSERT(!type.IsMalformed());
9466 resolved = new(isolate()) TypeNode(primary_pos, type); 9476 resolved = new(isolate()) TypeNode(primary_pos, type);
9467 } 9477 }
9468 } 9478 }
9469 return resolved; 9479 return resolved;
9470 } 9480 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
9566 AstNode* Parser::ParseListLiteral(intptr_t type_pos, 9576 AstNode* Parser::ParseListLiteral(intptr_t type_pos,
9567 bool is_const, 9577 bool is_const,
9568 const TypeArguments& type_arguments) { 9578 const TypeArguments& type_arguments) {
9569 TRACE_PARSER("ParseListLiteral"); 9579 TRACE_PARSER("ParseListLiteral");
9570 ASSERT(type_pos >= 0); 9580 ASSERT(type_pos >= 0);
9571 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX); 9581 ASSERT(CurrentToken() == Token::kLBRACK || CurrentToken() == Token::kINDEX);
9572 const intptr_t literal_pos = TokenPos(); 9582 const intptr_t literal_pos = TokenPos();
9573 bool is_empty_literal = CurrentToken() == Token::kINDEX; 9583 bool is_empty_literal = CurrentToken() == Token::kINDEX;
9574 ConsumeToken(); 9584 ConsumeToken();
9575 9585
9576 AbstractType& element_type = Type::ZoneHandle(Type::DynamicType()); 9586 AbstractType& element_type = Type::ZoneHandle(I, Type::DynamicType());
9577 TypeArguments& list_type_arguments = 9587 TypeArguments& list_type_arguments =
9578 TypeArguments::ZoneHandle(type_arguments.raw()); 9588 TypeArguments::ZoneHandle(I, type_arguments.raw());
9579 // If no type argument vector is provided, leave it as null, which is 9589 // If no type argument vector is provided, leave it as null, which is
9580 // equivalent to using dynamic as the type argument for the element type. 9590 // equivalent to using dynamic as the type argument for the element type.
9581 if (!list_type_arguments.IsNull()) { 9591 if (!list_type_arguments.IsNull()) {
9582 ASSERT(list_type_arguments.Length() > 0); 9592 ASSERT(list_type_arguments.Length() > 0);
9583 // List literals take a single type argument. 9593 // List literals take a single type argument.
9584 if (list_type_arguments.Length() == 1) { 9594 if (list_type_arguments.Length() == 1) {
9585 element_type = list_type_arguments.TypeAt(0); 9595 element_type = list_type_arguments.TypeAt(0);
9586 ASSERT(!element_type.IsMalformed()); // Would be mapped to dynamic. 9596 ASSERT(!element_type.IsMalformed()); // Would be mapped to dynamic.
9587 ASSERT(!element_type.IsMalbounded()); // No declared bound in List. 9597 ASSERT(!element_type.IsMalbounded()); // No declared bound in List.
9588 if (element_type.IsDynamicType()) { 9598 if (element_type.IsDynamicType()) {
9589 list_type_arguments = TypeArguments::null(); 9599 list_type_arguments = TypeArguments::null();
9590 } else if (is_const && !element_type.IsInstantiated()) { 9600 } else if (is_const && !element_type.IsInstantiated()) {
9591 ErrorMsg(type_pos, 9601 ErrorMsg(type_pos,
9592 "the type argument of a constant list literal cannot include " 9602 "the type argument of a constant list literal cannot include "
9593 "a type variable"); 9603 "a type variable");
9594 } 9604 }
9595 } else { 9605 } else {
9596 if (FLAG_error_on_bad_type) { 9606 if (FLAG_error_on_bad_type) {
9597 ErrorMsg(type_pos, 9607 ErrorMsg(type_pos,
9598 "a list literal takes one type argument specifying " 9608 "a list literal takes one type argument specifying "
9599 "the element type"); 9609 "the element type");
9600 } 9610 }
9601 // Ignore type arguments. 9611 // Ignore type arguments.
9602 list_type_arguments = TypeArguments::null(); 9612 list_type_arguments = TypeArguments::null();
9603 } 9613 }
9604 } 9614 }
9605 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1)); 9615 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1));
9606 const Class& array_class = Class::Handle(isolate(), 9616 const Class& array_class = Class::Handle(isolate(),
9607 isolate()->object_store()->array_class()); 9617 isolate()->object_store()->array_class());
9608 Type& type = Type::ZoneHandle( 9618 Type& type = Type::ZoneHandle(I,
9609 Type::New(array_class, list_type_arguments, type_pos)); 9619 Type::New(array_class, list_type_arguments, type_pos));
9610 type ^= ClassFinalizer::FinalizeType( 9620 type ^= ClassFinalizer::FinalizeType(
9611 current_class(), type, ClassFinalizer::kCanonicalize); 9621 current_class(), type, ClassFinalizer::kCanonicalize);
9612 GrowableArray<AstNode*> element_list; 9622 GrowableArray<AstNode*> element_list;
9613 // Parse the list elements. Note: there may be an optional extra 9623 // Parse the list elements. Note: there may be an optional extra
9614 // comma after the last element. 9624 // comma after the last element.
9615 if (!is_empty_literal) { 9625 if (!is_empty_literal) {
9616 const bool saved_mode = SetAllowFunctionLiterals(true); 9626 const bool saved_mode = SetAllowFunctionLiterals(true);
9617 while (CurrentToken() != Token::kRBRACK) { 9627 while (CurrentToken() != Token::kRBRACK) {
9618 const intptr_t element_pos = TokenPos(); 9628 const intptr_t element_pos = TokenPos();
(...skipping 13 matching lines...) Expand all
9632 ErrorMsg("comma or ']' expected"); 9642 ErrorMsg("comma or ']' expected");
9633 } 9643 }
9634 } 9644 }
9635 ExpectToken(Token::kRBRACK); 9645 ExpectToken(Token::kRBRACK);
9636 SetAllowFunctionLiterals(saved_mode); 9646 SetAllowFunctionLiterals(saved_mode);
9637 } 9647 }
9638 9648
9639 if (is_const) { 9649 if (is_const) {
9640 // Allocate and initialize the const list at compile time. 9650 // Allocate and initialize the const list at compile time.
9641 Array& const_list = 9651 Array& const_list =
9642 Array::ZoneHandle(Array::New(element_list.length(), Heap::kOld)); 9652 Array::ZoneHandle(I, Array::New(element_list.length(), Heap::kOld));
9643 const_list.SetTypeArguments( 9653 const_list.SetTypeArguments(
9644 TypeArguments::Handle(isolate(), list_type_arguments.Canonicalize())); 9654 TypeArguments::Handle(isolate(), list_type_arguments.Canonicalize()));
9645 Error& malformed_error = Error::Handle(isolate()); 9655 Error& malformed_error = Error::Handle(isolate());
9646 for (int i = 0; i < element_list.length(); i++) { 9656 for (int i = 0; i < element_list.length(); i++) {
9647 AstNode* elem = element_list[i]; 9657 AstNode* elem = element_list[i];
9648 // Arguments have been evaluated to a literal value already. 9658 // Arguments have been evaluated to a literal value already.
9649 ASSERT(elem->IsLiteralNode()); 9659 ASSERT(elem->IsLiteralNode());
9650 ASSERT(!is_top_level_); // We cannot check unresolved types. 9660 ASSERT(!is_top_level_); // We cannot check unresolved types.
9651 if (FLAG_enable_type_checks && 9661 if (FLAG_enable_type_checks &&
9652 !element_type.IsDynamicType() && 9662 !element_type.IsDynamicType() &&
(...skipping 17 matching lines...) Expand all
9670 const_list.SetAt(i, elem->AsLiteralNode()->literal()); 9680 const_list.SetAt(i, elem->AsLiteralNode()->literal());
9671 } 9681 }
9672 const_list ^= TryCanonicalize(const_list, literal_pos); 9682 const_list ^= TryCanonicalize(const_list, literal_pos);
9673 const_list.MakeImmutable(); 9683 const_list.MakeImmutable();
9674 return new(isolate()) LiteralNode(literal_pos, const_list); 9684 return new(isolate()) LiteralNode(literal_pos, const_list);
9675 } else { 9685 } else {
9676 // Factory call at runtime. 9686 // Factory call at runtime.
9677 const Class& factory_class = 9687 const Class& factory_class =
9678 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::List())); 9688 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::List()));
9679 ASSERT(!factory_class.IsNull()); 9689 ASSERT(!factory_class.IsNull());
9680 const Function& factory_method = Function::ZoneHandle( 9690 const Function& factory_method = Function::ZoneHandle(I,
9681 factory_class.LookupFactory( 9691 factory_class.LookupFactory(
9682 Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); 9692 Library::PrivateCoreLibName(Symbols::ListLiteralFactory())));
9683 ASSERT(!factory_method.IsNull()); 9693 ASSERT(!factory_method.IsNull());
9684 if (!list_type_arguments.IsNull() && 9694 if (!list_type_arguments.IsNull() &&
9685 !list_type_arguments.IsInstantiated() && 9695 !list_type_arguments.IsInstantiated() &&
9686 (current_block_->scope->function_level() > 0)) { 9696 (current_block_->scope->function_level() > 0)) {
9687 // Make sure that the instantiator is captured. 9697 // Make sure that the instantiator is captured.
9688 CaptureInstantiator(); 9698 CaptureInstantiator();
9689 } 9699 }
9690 TypeArguments& factory_type_args = 9700 TypeArguments& factory_type_args =
9691 TypeArguments::ZoneHandle(list_type_arguments.raw()); 9701 TypeArguments::ZoneHandle(I, list_type_arguments.raw());
9692 // If the factory class extends other parameterized classes, adjust the 9702 // If the factory class extends other parameterized classes, adjust the
9693 // type argument vector. 9703 // type argument vector.
9694 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { 9704 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) {
9695 ASSERT(factory_type_args.Length() == 1); 9705 ASSERT(factory_type_args.Length() == 1);
9696 Type& factory_type = Type::Handle(isolate(), Type::New( 9706 Type& factory_type = Type::Handle(isolate(), Type::New(
9697 factory_class, factory_type_args, type_pos, Heap::kNew)); 9707 factory_class, factory_type_args, type_pos, Heap::kNew));
9698 factory_type ^= ClassFinalizer::FinalizeType( 9708 factory_type ^= ClassFinalizer::FinalizeType(
9699 current_class(), factory_type, ClassFinalizer::kFinalize); 9709 current_class(), factory_type, ClassFinalizer::kFinalize);
9700 factory_type_args = factory_type.arguments(); 9710 factory_type_args = factory_type.arguments();
9701 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); 9711 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments());
9702 } 9712 }
9703 factory_type_args = factory_type_args.Canonicalize(); 9713 factory_type_args = factory_type_args.Canonicalize();
9704 ArgumentListNode* factory_param = new(isolate()) ArgumentListNode( 9714 ArgumentListNode* factory_param = new(isolate()) ArgumentListNode(
9705 literal_pos); 9715 literal_pos);
9706 if (element_list.length() == 0) { 9716 if (element_list.length() == 0) {
9707 // TODO(srdjan): Use Object::empty_array once issue 9871 has been fixed. 9717 // TODO(srdjan): Use Object::empty_array once issue 9871 has been fixed.
9708 Array& empty_array = Array::ZoneHandle(Object::empty_array().raw()); 9718 Array& empty_array = Array::ZoneHandle(I, Object::empty_array().raw());
9709 LiteralNode* empty_array_literal = 9719 LiteralNode* empty_array_literal =
9710 new(isolate()) LiteralNode(TokenPos(), empty_array); 9720 new(isolate()) LiteralNode(TokenPos(), empty_array);
9711 factory_param->Add(empty_array_literal); 9721 factory_param->Add(empty_array_literal);
9712 } else { 9722 } else {
9713 ArrayNode* list = new(isolate()) ArrayNode( 9723 ArrayNode* list = new(isolate()) ArrayNode(
9714 TokenPos(), type, element_list); 9724 TokenPos(), type, element_list);
9715 factory_param->Add(list); 9725 factory_param->Add(list);
9716 } 9726 }
9717 return CreateConstructorCallNode(literal_pos, 9727 return CreateConstructorCallNode(literal_pos,
9718 factory_type_args, 9728 factory_type_args,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
9762 9772
9763 AstNode* Parser::ParseMapLiteral(intptr_t type_pos, 9773 AstNode* Parser::ParseMapLiteral(intptr_t type_pos,
9764 bool is_const, 9774 bool is_const,
9765 const TypeArguments& type_arguments) { 9775 const TypeArguments& type_arguments) {
9766 TRACE_PARSER("ParseMapLiteral"); 9776 TRACE_PARSER("ParseMapLiteral");
9767 ASSERT(type_pos >= 0); 9777 ASSERT(type_pos >= 0);
9768 ASSERT(CurrentToken() == Token::kLBRACE); 9778 ASSERT(CurrentToken() == Token::kLBRACE);
9769 const intptr_t literal_pos = TokenPos(); 9779 const intptr_t literal_pos = TokenPos();
9770 ConsumeToken(); 9780 ConsumeToken();
9771 9781
9772 AbstractType& key_type = Type::ZoneHandle(Type::DynamicType()); 9782 AbstractType& key_type = Type::ZoneHandle(I, Type::DynamicType());
9773 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); 9783 AbstractType& value_type = Type::ZoneHandle(I, Type::DynamicType());
9774 TypeArguments& map_type_arguments = 9784 TypeArguments& map_type_arguments =
9775 TypeArguments::ZoneHandle(type_arguments.raw()); 9785 TypeArguments::ZoneHandle(I, type_arguments.raw());
9776 // If no type argument vector is provided, leave it as null, which is 9786 // If no type argument vector is provided, leave it as null, which is
9777 // equivalent to using dynamic as the type argument for the both key and value 9787 // equivalent to using dynamic as the type argument for the both key and value
9778 // types. 9788 // types.
9779 if (!map_type_arguments.IsNull()) { 9789 if (!map_type_arguments.IsNull()) {
9780 ASSERT(map_type_arguments.Length() > 0); 9790 ASSERT(map_type_arguments.Length() > 0);
9781 // Map literals take two type arguments. 9791 // Map literals take two type arguments.
9782 if (map_type_arguments.Length() == 2) { 9792 if (map_type_arguments.Length() == 2) {
9783 key_type = map_type_arguments.TypeAt(0); 9793 key_type = map_type_arguments.TypeAt(0);
9784 value_type = map_type_arguments.TypeAt(1); 9794 value_type = map_type_arguments.TypeAt(1);
9785 // Malformed type arguments are mapped to dynamic. 9795 // Malformed type arguments are mapped to dynamic.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
9852 ASSERT(kv_pairs_list.length() % 2 == 0); 9862 ASSERT(kv_pairs_list.length() % 2 == 0);
9853 ExpectToken(Token::kRBRACE); 9863 ExpectToken(Token::kRBRACE);
9854 9864
9855 if (is_const) { 9865 if (is_const) {
9856 // Create the key-value pair array, canonicalize it and then create 9866 // Create the key-value pair array, canonicalize it and then create
9857 // the immutable map object with it. This all happens at compile time. 9867 // the immutable map object with it. This all happens at compile time.
9858 // The resulting immutable map object is returned as a literal. 9868 // The resulting immutable map object is returned as a literal.
9859 9869
9860 // First, create the canonicalized key-value pair array. 9870 // First, create the canonicalized key-value pair array.
9861 Array& key_value_array = 9871 Array& key_value_array =
9862 Array::ZoneHandle(Array::New(kv_pairs_list.length(), Heap::kOld)); 9872 Array::ZoneHandle(I, Array::New(kv_pairs_list.length(), Heap::kOld));
9863 AbstractType& arg_type = Type::Handle(isolate()); 9873 AbstractType& arg_type = Type::Handle(isolate());
9864 Error& malformed_error = Error::Handle(isolate()); 9874 Error& malformed_error = Error::Handle(isolate());
9865 for (int i = 0; i < kv_pairs_list.length(); i++) { 9875 for (int i = 0; i < kv_pairs_list.length(); i++) {
9866 AstNode* arg = kv_pairs_list[i]; 9876 AstNode* arg = kv_pairs_list[i];
9867 // Arguments have been evaluated to a literal value already. 9877 // Arguments have been evaluated to a literal value already.
9868 ASSERT(arg->IsLiteralNode()); 9878 ASSERT(arg->IsLiteralNode());
9869 ASSERT(!is_top_level_); // We cannot check unresolved types. 9879 ASSERT(!is_top_level_); // We cannot check unresolved types.
9870 if (FLAG_enable_type_checks) { 9880 if (FLAG_enable_type_checks) {
9871 if ((i % 2) == 0) { 9881 if ((i % 2) == 0) {
9872 // Check key type. 9882 // Check key type.
(...skipping 30 matching lines...) Expand all
9903 // Construct the map object. 9913 // Construct the map object.
9904 const Class& immutable_map_class = Class::Handle(isolate(), 9914 const Class& immutable_map_class = Class::Handle(isolate(),
9905 Library::LookupCoreClass(Symbols::ImmutableMap())); 9915 Library::LookupCoreClass(Symbols::ImmutableMap()));
9906 ASSERT(!immutable_map_class.IsNull()); 9916 ASSERT(!immutable_map_class.IsNull());
9907 // If the immutable map class extends other parameterized classes, we need 9917 // If the immutable map class extends other parameterized classes, we need
9908 // to adjust the type argument vector. This is currently not the case. 9918 // to adjust the type argument vector. This is currently not the case.
9909 ASSERT(immutable_map_class.NumTypeArguments() == 2); 9919 ASSERT(immutable_map_class.NumTypeArguments() == 2);
9910 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(TokenPos()); 9920 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(TokenPos());
9911 constr_args->Add(new(isolate()) LiteralNode(literal_pos, key_value_array)); 9921 constr_args->Add(new(isolate()) LiteralNode(literal_pos, key_value_array));
9912 const Function& map_constr = 9922 const Function& map_constr =
9913 Function::ZoneHandle(immutable_map_class.LookupConstructor( 9923 Function::ZoneHandle(I, immutable_map_class.LookupConstructor(
9914 Library::PrivateCoreLibName(Symbols::ImmutableMapConstructor()))); 9924 Library::PrivateCoreLibName(Symbols::ImmutableMapConstructor())));
9915 ASSERT(!map_constr.IsNull()); 9925 ASSERT(!map_constr.IsNull());
9916 const Object& constructor_result = Object::Handle(isolate(), 9926 const Object& constructor_result = Object::Handle(isolate(),
9917 EvaluateConstConstructorCall(immutable_map_class, 9927 EvaluateConstConstructorCall(immutable_map_class,
9918 map_type_arguments, 9928 map_type_arguments,
9919 map_constr, 9929 map_constr,
9920 constr_args)); 9930 constr_args));
9921 if (constructor_result.IsUnhandledException()) { 9931 if (constructor_result.IsUnhandledException()) {
9922 AppendErrorMsg(Error::Cast(constructor_result), 9932 AppendErrorMsg(Error::Cast(constructor_result),
9923 literal_pos, 9933 literal_pos,
9924 "error executing const Map constructor"); 9934 "error executing const Map constructor");
9925 } else { 9935 } else {
9926 const Instance& const_instance = Instance::Cast(constructor_result); 9936 const Instance& const_instance = Instance::Cast(constructor_result);
9927 return new(isolate()) LiteralNode( 9937 return new(isolate()) LiteralNode(
9928 literal_pos, Instance::ZoneHandle(const_instance.raw())); 9938 literal_pos, Instance::ZoneHandle(I, const_instance.raw()));
9929 } 9939 }
9930 } else { 9940 } else {
9931 // Factory call at runtime. 9941 // Factory call at runtime.
9932 const Class& factory_class = 9942 const Class& factory_class =
9933 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::Map())); 9943 Class::Handle(isolate(), Library::LookupCoreClass(Symbols::Map()));
9934 ASSERT(!factory_class.IsNull()); 9944 ASSERT(!factory_class.IsNull());
9935 const Function& factory_method = Function::ZoneHandle( 9945 const Function& factory_method = Function::ZoneHandle(I,
9936 factory_class.LookupFactory( 9946 factory_class.LookupFactory(
9937 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); 9947 Library::PrivateCoreLibName(Symbols::MapLiteralFactory())));
9938 ASSERT(!factory_method.IsNull()); 9948 ASSERT(!factory_method.IsNull());
9939 if (!map_type_arguments.IsNull() && 9949 if (!map_type_arguments.IsNull() &&
9940 !map_type_arguments.IsInstantiated() && 9950 !map_type_arguments.IsInstantiated() &&
9941 (current_block_->scope->function_level() > 0)) { 9951 (current_block_->scope->function_level() > 0)) {
9942 // Make sure that the instantiator is captured. 9952 // Make sure that the instantiator is captured.
9943 CaptureInstantiator(); 9953 CaptureInstantiator();
9944 } 9954 }
9945 TypeArguments& factory_type_args = 9955 TypeArguments& factory_type_args =
9946 TypeArguments::ZoneHandle(map_type_arguments.raw()); 9956 TypeArguments::ZoneHandle(I, map_type_arguments.raw());
9947 // If the factory class extends other parameterized classes, adjust the 9957 // If the factory class extends other parameterized classes, adjust the
9948 // type argument vector. 9958 // type argument vector.
9949 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { 9959 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) {
9950 ASSERT(factory_type_args.Length() == 2); 9960 ASSERT(factory_type_args.Length() == 2);
9951 Type& factory_type = Type::Handle(isolate(), Type::New( 9961 Type& factory_type = Type::Handle(isolate(), Type::New(
9952 factory_class, factory_type_args, type_pos, Heap::kNew)); 9962 factory_class, factory_type_args, type_pos, Heap::kNew));
9953 factory_type ^= ClassFinalizer::FinalizeType( 9963 factory_type ^= ClassFinalizer::FinalizeType(
9954 current_class(), factory_type, ClassFinalizer::kFinalize); 9964 current_class(), factory_type, ClassFinalizer::kFinalize);
9955 factory_type_args = factory_type.arguments(); 9965 factory_type_args = factory_type.arguments();
9956 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); 9966 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments());
9957 } 9967 }
9958 factory_type_args = factory_type_args.Canonicalize(); 9968 factory_type_args = factory_type_args.Canonicalize();
9959 ArgumentListNode* factory_param = 9969 ArgumentListNode* factory_param =
9960 new(isolate()) ArgumentListNode(literal_pos); 9970 new(isolate()) ArgumentListNode(literal_pos);
9961 // The kv_pair array is temporary and of element type dynamic. It is passed 9971 // The kv_pair array is temporary and of element type dynamic. It is passed
9962 // to the factory to initialize a properly typed map. 9972 // to the factory to initialize a properly typed map.
9963 ArrayNode* kv_pairs = new(isolate()) ArrayNode( 9973 ArrayNode* kv_pairs = new(isolate()) ArrayNode(
9964 TokenPos(), 9974 TokenPos(),
9965 Type::ZoneHandle(Type::ArrayType()), 9975 Type::ZoneHandle(I, Type::ArrayType()),
9966 kv_pairs_list); 9976 kv_pairs_list);
9967 factory_param->Add(kv_pairs); 9977 factory_param->Add(kv_pairs);
9968 return CreateConstructorCallNode(literal_pos, 9978 return CreateConstructorCallNode(literal_pos,
9969 factory_type_args, 9979 factory_type_args,
9970 factory_method, 9980 factory_method,
9971 factory_param); 9981 factory_param);
9972 } 9982 }
9973 UNREACHABLE(); 9983 UNREACHABLE();
9974 return NULL; 9984 return NULL;
9975 } 9985 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
10023 ErrorMsg("illegal symbol literal"); 10033 ErrorMsg("illegal symbol literal");
10024 } 10034 }
10025 // Lookup class Symbol from internal library and call the 10035 // Lookup class Symbol from internal library and call the
10026 // constructor to create a symbol instance. 10036 // constructor to create a symbol instance.
10027 const Library& lib = Library::Handle(isolate(), Library::InternalLibrary()); 10037 const Library& lib = Library::Handle(isolate(), Library::InternalLibrary());
10028 const Class& symbol_class = Class::Handle(isolate(), 10038 const Class& symbol_class = Class::Handle(isolate(),
10029 lib.LookupClass(Symbols::Symbol())); 10039 lib.LookupClass(Symbols::Symbol()));
10030 ASSERT(!symbol_class.IsNull()); 10040 ASSERT(!symbol_class.IsNull());
10031 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(symbol_pos); 10041 ArgumentListNode* constr_args = new(isolate()) ArgumentListNode(symbol_pos);
10032 constr_args->Add(new(isolate()) LiteralNode( 10042 constr_args->Add(new(isolate()) LiteralNode(
10033 symbol_pos, String::ZoneHandle(Symbols::New(symbol)))); 10043 symbol_pos, String::ZoneHandle(I, Symbols::New(symbol))));
10034 const Function& constr = Function::ZoneHandle( 10044 const Function& constr = Function::ZoneHandle(I,
10035 symbol_class.LookupConstructor(Symbols::SymbolCtor())); 10045 symbol_class.LookupConstructor(Symbols::SymbolCtor()));
10036 ASSERT(!constr.IsNull()); 10046 ASSERT(!constr.IsNull());
10037 const Object& result = Object::Handle(isolate(), 10047 const Object& result = Object::Handle(isolate(),
10038 EvaluateConstConstructorCall(symbol_class, 10048 EvaluateConstConstructorCall(symbol_class,
10039 TypeArguments::Handle(isolate()), 10049 TypeArguments::Handle(isolate()),
10040 constr, 10050 constr,
10041 constr_args)); 10051 constr_args));
10042 if (result.IsUnhandledException()) { 10052 if (result.IsUnhandledException()) {
10043 AppendErrorMsg(Error::Cast(result), 10053 AppendErrorMsg(Error::Cast(result),
10044 symbol_pos, 10054 symbol_pos,
10045 "error executing const Symbol constructor"); 10055 "error executing const Symbol constructor");
10046 } 10056 }
10047 const Instance& instance = Instance::Cast(result); 10057 const Instance& instance = Instance::Cast(result);
10048 return new(isolate()) LiteralNode(symbol_pos, 10058 return new(isolate()) LiteralNode(symbol_pos,
10049 Instance::ZoneHandle(instance.raw())); 10059 Instance::ZoneHandle(I, instance.raw()));
10050 } 10060 }
10051 10061
10052 10062
10053 static String& BuildConstructorName(const String& type_class_name, 10063 static String& BuildConstructorName(const String& type_class_name,
10054 const String* named_constructor) { 10064 const String* named_constructor) {
10055 // By convention, the static function implementing a named constructor 'C' 10065 // By convention, the static function implementing a named constructor 'C'
10056 // for class 'A' is labeled 'A.C', and the static function implementing the 10066 // for class 'A' is labeled 'A.C', and the static function implementing the
10057 // unnamed constructor for class 'A' is labeled 'A.'. 10067 // unnamed constructor for class 'A' is labeled 'A.'.
10058 // This convention prevents users from explicitly calling constructors. 10068 // This convention prevents users from explicitly calling constructors.
10059 String& constructor_name = 10069 String& constructor_name =
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
10115 const Error& error = Error::Handle(isolate(), type.error()); 10125 const Error& error = Error::Handle(isolate(), type.error());
10116 ErrorMsg(error); 10126 ErrorMsg(error);
10117 } 10127 }
10118 return ThrowTypeError(type_pos, type); 10128 return ThrowTypeError(type_pos, type);
10119 } 10129 }
10120 10130
10121 // Resolve the type and optional identifier to a constructor or factory. 10131 // Resolve the type and optional identifier to a constructor or factory.
10122 Class& type_class = Class::Handle(isolate(), type.type_class()); 10132 Class& type_class = Class::Handle(isolate(), type.type_class());
10123 String& type_class_name = String::Handle(isolate(), type_class.Name()); 10133 String& type_class_name = String::Handle(isolate(), type_class.Name());
10124 TypeArguments& type_arguments = 10134 TypeArguments& type_arguments =
10125 TypeArguments::ZoneHandle(type.arguments()); 10135 TypeArguments::ZoneHandle(I, type.arguments());
10126 10136
10127 // A constructor has an implicit 'this' parameter (instance to construct) 10137 // A constructor has an implicit 'this' parameter (instance to construct)
10128 // and a factory has an implicit 'this' parameter (type_arguments). 10138 // and a factory has an implicit 'this' parameter (type_arguments).
10129 // A constructor has a second implicit 'phase' parameter. 10139 // A constructor has a second implicit 'phase' parameter.
10130 intptr_t arguments_length = arguments->length() + 2; 10140 intptr_t arguments_length = arguments->length() + 2;
10131 10141
10132 // An additional type check of the result of a redirecting factory may be 10142 // An additional type check of the result of a redirecting factory may be
10133 // required. 10143 // required.
10134 AbstractType& type_bound = AbstractType::ZoneHandle(); 10144 AbstractType& type_bound = AbstractType::ZoneHandle(I);
10135 10145
10136 // Make sure that an appropriate constructor exists. 10146 // Make sure that an appropriate constructor exists.
10137 String& constructor_name = 10147 String& constructor_name =
10138 BuildConstructorName(type_class_name, named_constructor); 10148 BuildConstructorName(type_class_name, named_constructor);
10139 Function& constructor = Function::ZoneHandle( 10149 Function& constructor = Function::ZoneHandle(I,
10140 type_class.LookupConstructor(constructor_name)); 10150 type_class.LookupConstructor(constructor_name));
10141 if (constructor.IsNull()) { 10151 if (constructor.IsNull()) {
10142 constructor = type_class.LookupFactory(constructor_name); 10152 constructor = type_class.LookupFactory(constructor_name);
10143 if (constructor.IsNull()) { 10153 if (constructor.IsNull()) {
10144 const String& external_constructor_name = 10154 const String& external_constructor_name =
10145 (named_constructor ? constructor_name : type_class_name); 10155 (named_constructor ? constructor_name : type_class_name);
10146 // Replace the type with a malformed type and compile a throw or report a 10156 // Replace the type with a malformed type and compile a throw or report a
10147 // compile-time error if the constructor is const. 10157 // compile-time error if the constructor is const.
10148 if (is_const) { 10158 if (is_const) {
10149 type = ClassFinalizer::NewFinalizedMalformedType( 10159 type = ClassFinalizer::NewFinalizedMalformedType(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
10211 ASSERT(!constructor.IsNull()); 10221 ASSERT(!constructor.IsNull());
10212 if (type_class.is_abstract() && !constructor.IsFactory()) { 10222 if (type_class.is_abstract() && !constructor.IsFactory()) {
10213 // Evaluate arguments before throwing. 10223 // Evaluate arguments before throwing.
10214 LetNode* result = new(isolate()) LetNode(call_pos); 10224 LetNode* result = new(isolate()) LetNode(call_pos);
10215 for (intptr_t i = 0; i < arguments->length(); ++i) { 10225 for (intptr_t i = 0; i < arguments->length(); ++i) {
10216 result->AddNode(arguments->NodeAt(i)); 10226 result->AddNode(arguments->NodeAt(i));
10217 } 10227 }
10218 ArgumentListNode* error_arguments = 10228 ArgumentListNode* error_arguments =
10219 new(isolate()) ArgumentListNode(type_pos); 10229 new(isolate()) ArgumentListNode(type_pos);
10220 error_arguments->Add(new(isolate()) LiteralNode( 10230 error_arguments->Add(new(isolate()) LiteralNode(
10221 TokenPos(), Integer::ZoneHandle(Integer::New(type_pos)))); 10231 TokenPos(), Integer::ZoneHandle(I, Integer::New(type_pos))));
10222 error_arguments->Add(new(isolate()) LiteralNode( 10232 error_arguments->Add(new(isolate()) LiteralNode(
10223 TokenPos(), String::ZoneHandle(type_class_name.raw()))); 10233 TokenPos(), String::ZoneHandle(I, type_class_name.raw())));
10224 result->AddNode( 10234 result->AddNode(
10225 MakeStaticCall(Symbols::AbstractClassInstantiationError(), 10235 MakeStaticCall(Symbols::AbstractClassInstantiationError(),
10226 Library::PrivateCoreLibName(Symbols::ThrowNew()), 10236 Library::PrivateCoreLibName(Symbols::ThrowNew()),
10227 error_arguments)); 10237 error_arguments));
10228 return result; 10238 return result;
10229 } 10239 }
10230 String& error_message = String::Handle(isolate()); 10240 String& error_message = String::Handle(isolate());
10231 if (!constructor.AreValidArguments(arguments_length, 10241 if (!constructor.AreValidArguments(arguments_length,
10232 arguments->names(), 10242 arguments->names(),
10233 &error_message)) { 10243 &error_message)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
10278 // It's a compile-time error if invocation of a const constructor 10288 // It's a compile-time error if invocation of a const constructor
10279 // call fails. 10289 // call fails.
10280 AppendErrorMsg(Error::Cast(constructor_result), 10290 AppendErrorMsg(Error::Cast(constructor_result),
10281 new_pos, 10291 new_pos,
10282 "error while evaluating const constructor"); 10292 "error while evaluating const constructor");
10283 } else { 10293 } else {
10284 // Const constructors can return null in the case where a const native 10294 // Const constructors can return null in the case where a const native
10285 // factory returns a null value. Thus we cannot use a Instance::Cast here. 10295 // factory returns a null value. Thus we cannot use a Instance::Cast here.
10286 Instance& const_instance = Instance::Handle(isolate()); 10296 Instance& const_instance = Instance::Handle(isolate());
10287 const_instance ^= constructor_result.raw(); 10297 const_instance ^= constructor_result.raw();
10288 new_object = new(isolate()) LiteralNode(new_pos, 10298 new_object = new(isolate()) LiteralNode(
10289 Instance::ZoneHandle(const_instance.raw())); 10299 new_pos, Instance::ZoneHandle(I, const_instance.raw()));
10290 if (!type_bound.IsNull()) { 10300 if (!type_bound.IsNull()) {
10291 ASSERT(!type_bound.IsMalformed()); 10301 ASSERT(!type_bound.IsMalformed());
10292 Error& malformed_error = Error::Handle(isolate()); 10302 Error& malformed_error = Error::Handle(isolate());
10293 ASSERT(!is_top_level_); // We cannot check unresolved types. 10303 ASSERT(!is_top_level_); // We cannot check unresolved types.
10294 if (!const_instance.IsInstanceOf(type_bound, 10304 if (!const_instance.IsInstanceOf(type_bound,
10295 TypeArguments::Handle(isolate()), 10305 TypeArguments::Handle(isolate()),
10296 &malformed_error)) { 10306 &malformed_error)) {
10297 type_bound = ClassFinalizer::NewFinalizedMalformedType( 10307 type_bound = ClassFinalizer::NewFinalizedMalformedType(
10298 malformed_error, 10308 malformed_error,
10299 script_, 10309 script_,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
10349 10359
10350 // Call interpolation function. 10360 // Call interpolation function.
10351 Object& result = Object::Handle(isolate()); 10361 Object& result = Object::Handle(isolate());
10352 { 10362 {
10353 PAUSETIMERSCOPE(isolate(), time_compilation); 10363 PAUSETIMERSCOPE(isolate(), time_compilation);
10354 result = DartEntry::InvokeFunction(func, interpolate_arg); 10364 result = DartEntry::InvokeFunction(func, interpolate_arg);
10355 } 10365 }
10356 if (result.IsUnhandledException()) { 10366 if (result.IsUnhandledException()) {
10357 ErrorMsg("%s", Error::Cast(result).ToErrorCString()); 10367 ErrorMsg("%s", Error::Cast(result).ToErrorCString());
10358 } 10368 }
10359 String& concatenated = String::ZoneHandle(isolate()); 10369 String& concatenated = String::ZoneHandle(I);
10360 concatenated ^= result.raw(); 10370 concatenated ^= result.raw();
10361 concatenated = Symbols::New(concatenated); 10371 concatenated = Symbols::New(concatenated);
10362 return concatenated; 10372 return concatenated;
10363 } 10373 }
10364 10374
10365 10375
10366 // A string literal consists of the concatenation of the next n tokens 10376 // A string literal consists of the concatenation of the next n tokens
10367 // that satisfy the EBNF grammar: 10377 // that satisfy the EBNF grammar:
10368 // literal = kSTRING {{ interpol } kSTRING } 10378 // literal = kSTRING {{ interpol } kSTRING }
10369 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END) 10379 // interpol = kINTERPOL_VAR | (kINTERPOL_START expression kINTERPOL_END)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
10440 primary = new(isolate()) LiteralNode( 10450 primary = new(isolate()) LiteralNode(
10441 literal_start, Interpolate(values_list)); 10451 literal_start, Interpolate(values_list));
10442 } else { 10452 } else {
10443 const Array& strings = Array::Handle(isolate(), 10453 const Array& strings = Array::Handle(isolate(),
10444 Array::New(values_list.length())); 10454 Array::New(values_list.length()));
10445 for (int i = 0; i < values_list.length(); i++) { 10455 for (int i = 0; i < values_list.length(); i++) {
10446 const Instance& part = values_list[i]->AsLiteralNode()->literal(); 10456 const Instance& part = values_list[i]->AsLiteralNode()->literal();
10447 ASSERT(part.IsString()); 10457 ASSERT(part.IsString());
10448 strings.SetAt(i, String::Cast(part)); 10458 strings.SetAt(i, String::Cast(part));
10449 } 10459 }
10450 String& lit = String::ZoneHandle(String::ConcatAll(strings, Heap::kOld)); 10460 String& lit = String::ZoneHandle(I,
10461 String::ConcatAll(strings, Heap::kOld));
10451 lit = Symbols::New(lit); 10462 lit = Symbols::New(lit);
10452 primary = new(isolate()) LiteralNode(literal_start, lit); 10463 primary = new(isolate()) LiteralNode(literal_start, lit);
10453 } 10464 }
10454 } else { 10465 } else {
10455 ArrayNode* values = new(isolate()) ArrayNode( 10466 ArrayNode* values = new(isolate()) ArrayNode(
10456 TokenPos(), 10467 TokenPos(),
10457 Type::ZoneHandle(Type::ArrayType()), 10468 Type::ZoneHandle(I, Type::ArrayType()),
10458 values_list); 10469 values_list);
10459 primary = new(isolate()) StringInterpolateNode(TokenPos(), values); 10470 primary = new(isolate()) StringInterpolateNode(TokenPos(), values);
10460 } 10471 }
10461 return primary; 10472 return primary;
10462 } 10473 }
10463 10474
10464 10475
10465 AstNode* Parser::ParsePrimary() { 10476 AstNode* Parser::ParsePrimary() {
10466 TRACE_PARSER("ParsePrimary"); 10477 TRACE_PARSER("ParsePrimary");
10467 ASSERT(!is_top_level_); 10478 ASSERT(!is_top_level_);
10468 AstNode* primary = NULL; 10479 AstNode* primary = NULL;
10469 if (IsFunctionLiteral()) { 10480 if (IsFunctionLiteral()) {
10470 // The name of a literal function is visible from inside the function, but 10481 // The name of a literal function is visible from inside the function, but
10471 // must not collide with names in the scope declaring the literal. 10482 // must not collide with names in the scope declaring the literal.
10472 OpenBlock(); 10483 OpenBlock();
10473 primary = ParseFunctionStatement(true); 10484 primary = ParseFunctionStatement(true);
10474 CloseBlock(); 10485 CloseBlock();
10475 } else if (IsIdentifier()) { 10486 } else if (IsIdentifier()) {
10476 QualIdent qual_ident; 10487 QualIdent qual_ident;
10477 intptr_t qual_ident_pos = TokenPos(); 10488 intptr_t qual_ident_pos = TokenPos();
10478 ParseQualIdent(&qual_ident); 10489 ParseQualIdent(&qual_ident);
10479 if (qual_ident.lib_prefix == NULL) { 10490 if (qual_ident.lib_prefix == NULL) {
10480 if (!ResolveIdentInLocalScope(qual_ident.ident_pos, 10491 if (!ResolveIdentInLocalScope(qual_ident.ident_pos,
10481 *qual_ident.ident, 10492 *qual_ident.ident,
10482 &primary)) { 10493 &primary)) {
10483 // Check whether the identifier is a type parameter. 10494 // Check whether the identifier is a type parameter.
10484 if (!current_class().IsNull()) { 10495 if (!current_class().IsNull()) {
10485 TypeParameter& type_param = TypeParameter::ZoneHandle( 10496 TypeParameter& type_param = TypeParameter::ZoneHandle(I,
10486 current_class().LookupTypeParameter(*(qual_ident.ident))); 10497 current_class().LookupTypeParameter(*(qual_ident.ident)));
10487 if (!type_param.IsNull()) { 10498 if (!type_param.IsNull()) {
10488 return new(isolate()) PrimaryNode(qual_ident.ident_pos, type_param); 10499 return new(isolate()) PrimaryNode(qual_ident.ident_pos, type_param);
10489 } 10500 }
10490 } 10501 }
10491 // This is a non-local unqualified identifier so resolve the 10502 // This is a non-local unqualified identifier so resolve the
10492 // identifier locally in the main app library and all libraries 10503 // identifier locally in the main app library and all libraries
10493 // imported by it. 10504 // imported by it.
10494 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos, 10505 primary = ResolveIdentInCurrentLibraryScope(qual_ident.ident_pos,
10495 *qual_ident.ident); 10506 *qual_ident.ident);
(...skipping 24 matching lines...) Expand all
10520 // later, when we know more about how the unresolved name is used. 10531 // later, when we know more about how the unresolved name is used.
10521 // For example, we don't know yet whether the unresolved name 10532 // For example, we don't know yet whether the unresolved name
10522 // refers to a getter or a setter. However, it is more awkward 10533 // refers to a getter or a setter. However, it is more awkward
10523 // to distinuish four NoSuchMethodError cases all over the place 10534 // to distinuish four NoSuchMethodError cases all over the place
10524 // in the parser. The four cases are: prefixed vs non-prefixed 10535 // in the parser. The four cases are: prefixed vs non-prefixed
10525 // name, static vs dynamic context in which the unresolved name 10536 // name, static vs dynamic context in which the unresolved name
10526 // is used. We cheat a little here by looking at the next token 10537 // is used. We cheat a little here by looking at the next token
10527 // to determine whether we have an unresolved method call or 10538 // to determine whether we have an unresolved method call or
10528 // field access. 10539 // field access.
10529 String& qualified_name = 10540 String& qualified_name =
10530 String::ZoneHandle(qual_ident.lib_prefix->name()); 10541 String::ZoneHandle(I, qual_ident.lib_prefix->name());
10531 qualified_name = String::Concat(qualified_name, Symbols::Dot()); 10542 qualified_name = String::Concat(qualified_name, Symbols::Dot());
10532 qualified_name = String::Concat(qualified_name, *qual_ident.ident); 10543 qualified_name = String::Concat(qualified_name, *qual_ident.ident);
10533 qualified_name = Symbols::New(qualified_name); 10544 qualified_name = Symbols::New(qualified_name);
10534 InvocationMirror::Type call_type = 10545 InvocationMirror::Type call_type =
10535 CurrentToken() == Token::kLPAREN ? 10546 CurrentToken() == Token::kLPAREN ?
10536 InvocationMirror::kMethod : InvocationMirror::kGetter; 10547 InvocationMirror::kMethod : InvocationMirror::kGetter;
10537 primary = ThrowNoSuchMethodError(qual_ident_pos, 10548 primary = ThrowNoSuchMethodError(qual_ident_pos,
10538 current_class(), 10549 current_class(),
10539 qualified_name, 10550 qualified_name,
10540 NULL, // No arguments. 10551 NULL, // No arguments.
10541 InvocationMirror::kTopLevel, 10552 InvocationMirror::kTopLevel,
10542 call_type, 10553 call_type,
10543 NULL); // No existing function. 10554 NULL); // No existing function.
10544 } 10555 }
10545 } 10556 }
10546 } 10557 }
10547 ASSERT(primary != NULL); 10558 ASSERT(primary != NULL);
10548 } else if (CurrentToken() == Token::kTHIS) { 10559 } else if (CurrentToken() == Token::kTHIS) {
10549 LocalVariable* local = LookupLocalScope(Symbols::This()); 10560 LocalVariable* local = LookupLocalScope(Symbols::This());
10550 if (local == NULL) { 10561 if (local == NULL) {
10551 ErrorMsg("receiver 'this' is not in scope"); 10562 ErrorMsg("receiver 'this' is not in scope");
10552 } 10563 }
10553 primary = new(isolate()) LoadLocalNode(TokenPos(), local); 10564 primary = new(isolate()) LoadLocalNode(TokenPos(), local);
10554 ConsumeToken(); 10565 ConsumeToken();
10555 } else if (CurrentToken() == Token::kINTEGER) { 10566 } else if (CurrentToken() == Token::kINTEGER) {
10556 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); 10567 const Integer& literal = Integer::ZoneHandle(I, CurrentIntegerLiteral());
10557 primary = new(isolate()) LiteralNode(TokenPos(), literal); 10568 primary = new(isolate()) LiteralNode(TokenPos(), literal);
10558 ConsumeToken(); 10569 ConsumeToken();
10559 } else if (CurrentToken() == Token::kTRUE) { 10570 } else if (CurrentToken() == Token::kTRUE) {
10560 primary = new(isolate()) LiteralNode(TokenPos(), Bool::True()); 10571 primary = new(isolate()) LiteralNode(TokenPos(), Bool::True());
10561 ConsumeToken(); 10572 ConsumeToken();
10562 } else if (CurrentToken() == Token::kFALSE) { 10573 } else if (CurrentToken() == Token::kFALSE) {
10563 primary = new(isolate()) LiteralNode(TokenPos(), Bool::False()); 10574 primary = new(isolate()) LiteralNode(TokenPos(), Bool::False());
10564 ConsumeToken(); 10575 ConsumeToken();
10565 } else if (CurrentToken() == Token::kNULL) { 10576 } else if (CurrentToken() == Token::kNULL) {
10566 primary = new(isolate()) LiteralNode(TokenPos(), Instance::ZoneHandle()); 10577 primary = new(isolate()) LiteralNode(TokenPos(), Instance::ZoneHandle(I));
10567 ConsumeToken(); 10578 ConsumeToken();
10568 } else if (CurrentToken() == Token::kLPAREN) { 10579 } else if (CurrentToken() == Token::kLPAREN) {
10569 ConsumeToken(); 10580 ConsumeToken();
10570 const bool saved_mode = SetAllowFunctionLiterals(true); 10581 const bool saved_mode = SetAllowFunctionLiterals(true);
10571 primary = ParseExpr(kAllowConst, kConsumeCascades); 10582 primary = ParseExpr(kAllowConst, kConsumeCascades);
10572 SetAllowFunctionLiterals(saved_mode); 10583 SetAllowFunctionLiterals(saved_mode);
10573 ExpectToken(Token::kRPAREN); 10584 ExpectToken(Token::kRPAREN);
10574 } else if (CurrentToken() == Token::kDOUBLE) { 10585 } else if (CurrentToken() == Token::kDOUBLE) {
10575 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); 10586 Double& double_value = Double::ZoneHandle(I, CurrentDoubleLiteral());
10576 if (double_value.IsNull()) { 10587 if (double_value.IsNull()) {
10577 ErrorMsg("invalid double literal"); 10588 ErrorMsg("invalid double literal");
10578 } 10589 }
10579 primary = new(isolate()) LiteralNode(TokenPos(), double_value); 10590 primary = new(isolate()) LiteralNode(TokenPos(), double_value);
10580 ConsumeToken(); 10591 ConsumeToken();
10581 } else if (CurrentToken() == Token::kSTRING) { 10592 } else if (CurrentToken() == Token::kSTRING) {
10582 primary = ParseStringLiteral(true); 10593 primary = ParseStringLiteral(true);
10583 } else if (CurrentToken() == Token::kNEW) { 10594 } else if (CurrentToken() == Token::kNEW) {
10584 ConsumeToken(); 10595 ConsumeToken();
10585 primary = ParseNewOperator(Token::kNEW); 10596 primary = ParseNewOperator(Token::kNEW);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
10652 } else if (expr->IsLoadLocalNode() && 10663 } else if (expr->IsLoadLocalNode() &&
10653 expr->AsLoadLocalNode()->local().IsConst()) { 10664 expr->AsLoadLocalNode()->local().IsConst()) {
10654 return *expr->AsLoadLocalNode()->local().ConstValue(); 10665 return *expr->AsLoadLocalNode()->local().ConstValue();
10655 } else if (expr->IsLoadStaticFieldNode()) { 10666 } else if (expr->IsLoadStaticFieldNode()) {
10656 const Field& field = expr->AsLoadStaticFieldNode()->field(); 10667 const Field& field = expr->AsLoadStaticFieldNode()->field();
10657 // We already checked that this field is const and has been 10668 // We already checked that this field is const and has been
10658 // initialized. 10669 // initialized.
10659 ASSERT(field.is_const()); 10670 ASSERT(field.is_const());
10660 ASSERT(field.value() != Object::sentinel().raw()); 10671 ASSERT(field.value() != Object::sentinel().raw());
10661 ASSERT(field.value() != Object::transition_sentinel().raw()); 10672 ASSERT(field.value() != Object::transition_sentinel().raw());
10662 return Instance::ZoneHandle(field.value()); 10673 return Instance::ZoneHandle(I, field.value());
10663 } else { 10674 } else {
10664 ASSERT(expr->EvalConstExpr() != NULL); 10675 ASSERT(expr->EvalConstExpr() != NULL);
10665 ReturnNode* ret = new(isolate()) ReturnNode(expr->token_pos(), expr); 10676 ReturnNode* ret = new(isolate()) ReturnNode(expr->token_pos(), expr);
10666 // Compile time constant expressions cannot reference anything from a 10677 // Compile time constant expressions cannot reference anything from a
10667 // local scope. 10678 // local scope.
10668 LocalScope* empty_scope = new(isolate()) LocalScope(NULL, 0, 0); 10679 LocalScope* empty_scope = new(isolate()) LocalScope(NULL, 0, 0);
10669 SequenceNode* seq = new(isolate()) SequenceNode(expr->token_pos(), 10680 SequenceNode* seq = new(isolate()) SequenceNode(expr->token_pos(),
10670 empty_scope); 10681 empty_scope);
10671 seq->Add(ret); 10682 seq->Add(ret);
10672 10683
10673 Object& result = Object::Handle(isolate(), Compiler::ExecuteOnce(seq)); 10684 Object& result = Object::Handle(isolate(), Compiler::ExecuteOnce(seq));
10674 if (result.IsError()) { 10685 if (result.IsError()) {
10675 AppendErrorMsg(Error::Cast(result), 10686 AppendErrorMsg(Error::Cast(result),
10676 expr_pos, 10687 expr_pos,
10677 "error evaluating constant expression"); 10688 "error evaluating constant expression");
10678 } 10689 }
10679 ASSERT(result.IsInstance()); 10690 ASSERT(result.IsInstance());
10680 Instance& value = Instance::ZoneHandle(); 10691 Instance& value = Instance::ZoneHandle(I);
10681 value ^= result.raw(); 10692 value ^= result.raw();
10682 value = TryCanonicalize(value, TokenPos()); 10693 value = TryCanonicalize(value, TokenPos());
10683 return value; 10694 return value;
10684 } 10695 }
10685 } 10696 }
10686 10697
10687 10698
10688 void Parser::SkipFunctionLiteral() { 10699 void Parser::SkipFunctionLiteral() {
10689 if (IsIdentifier()) { 10700 if (IsIdentifier()) {
10690 if (LookaheadToken(1) != Token::kLPAREN) { 10701 if (LookaheadToken(1) != Token::kLPAREN) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
11010 void Parser::SkipQualIdent() { 11021 void Parser::SkipQualIdent() {
11011 ASSERT(IsIdentifier()); 11022 ASSERT(IsIdentifier());
11012 ConsumeToken(); 11023 ConsumeToken();
11013 if (CurrentToken() == Token::kPERIOD) { 11024 if (CurrentToken() == Token::kPERIOD) {
11014 ConsumeToken(); // Consume the kPERIOD token. 11025 ConsumeToken(); // Consume the kPERIOD token.
11015 ExpectIdentifier("identifier expected after '.'"); 11026 ExpectIdentifier("identifier expected after '.'");
11016 } 11027 }
11017 } 11028 }
11018 11029
11019 } // namespace dart 11030 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/globals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698