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

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

Issue 144343002: Rename kDummyTokenIndex to kNoSourcePos (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/runtime_entry_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 ASSERT(IsIdentifier()); 1174 ASSERT(IsIdentifier());
1175 const String& field_name = *CurrentLiteral(); 1175 const String& field_name = *CurrentLiteral();
1176 const Class& field_class = Class::Handle(func.Owner()); 1176 const Class& field_class = Class::Handle(func.Owner());
1177 const Field& field = 1177 const Field& field =
1178 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); 1178 Field::ZoneHandle(field_class.LookupInstanceField(field_name));
1179 1179
1180 LoadInstanceFieldNode* load_field = 1180 LoadInstanceFieldNode* load_field =
1181 new LoadInstanceFieldNode(ident_pos, load_receiver, field); 1181 new LoadInstanceFieldNode(ident_pos, load_receiver, field);
1182 1182
1183 ReturnNode* return_node = 1183 ReturnNode* return_node =
1184 new ReturnNode(Scanner::kDummyTokenIndex, load_field); 1184 new ReturnNode(Scanner::kNoSourcePos, load_field);
1185 current_block_->statements->Add(return_node); 1185 current_block_->statements->Add(return_node);
1186 return CloseBlock(); 1186 return CloseBlock();
1187 } 1187 }
1188 1188
1189 1189
1190 // Create AstNodes for an implicit instance setter method: 1190 // Create AstNodes for an implicit instance setter method:
1191 // LoadLocalNode 0 ('this') 1191 // LoadLocalNode 0 ('this')
1192 // LoadLocalNode 1 ('value') 1192 // LoadLocalNode 1 ('value')
1193 // SetInstanceField (field_name); 1193 // SetInstanceField (field_name);
1194 // ReturnNode (void); 1194 // ReturnNode (void);
(...skipping 23 matching lines...) Expand all
1218 1218
1219 LoadLocalNode* receiver = 1219 LoadLocalNode* receiver =
1220 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(0)); 1220 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(0));
1221 LoadLocalNode* value = 1221 LoadLocalNode* value =
1222 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(1)); 1222 new LoadLocalNode(ident_pos, current_block_->scope->VariableAt(1));
1223 1223
1224 EnsureExpressionTemp(); 1224 EnsureExpressionTemp();
1225 StoreInstanceFieldNode* store_field = 1225 StoreInstanceFieldNode* store_field =
1226 new StoreInstanceFieldNode(ident_pos, receiver, field, value); 1226 new StoreInstanceFieldNode(ident_pos, receiver, field, value);
1227 current_block_->statements->Add(store_field); 1227 current_block_->statements->Add(store_field);
1228 current_block_->statements->Add(new ReturnNode(Scanner::kDummyTokenIndex)); 1228 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos));
1229 return CloseBlock(); 1229 return CloseBlock();
1230 } 1230 }
1231 1231
1232 1232
1233 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { 1233 SequenceNode* Parser::ParseMethodExtractor(const Function& func) {
1234 TRACE_PARSER("ParseMethodExtractor"); 1234 TRACE_PARSER("ParseMethodExtractor");
1235 ParamList params; 1235 ParamList params;
1236 1236
1237 const intptr_t ident_pos = func.token_pos(); 1237 const intptr_t ident_pos = func.token_pos();
1238 const intptr_t invisible_pos = Scanner::kDummyTokenIndex;
1239 ASSERT(func.token_pos() == 0); 1238 ASSERT(func.token_pos() == 0);
1240 ASSERT(current_class().raw() == func.Owner()); 1239 ASSERT(current_class().raw() == func.Owner());
1241 params.AddReceiver(ReceiverType(current_class()), ident_pos); 1240 params.AddReceiver(ReceiverType(current_class()), ident_pos);
1242 ASSERT(func.num_fixed_parameters() == 1); // Receiver. 1241 ASSERT(func.num_fixed_parameters() == 1); // Receiver.
1243 ASSERT(!func.HasOptionalParameters()); 1242 ASSERT(!func.HasOptionalParameters());
1244 1243
1245 // Build local scope for function and populate with the formal parameters. 1244 // Build local scope for function and populate with the formal parameters.
1246 OpenFunctionBlock(func); 1245 OpenFunctionBlock(func);
1247 AddFormalParamsToScope(&params, current_block_->scope); 1246 AddFormalParamsToScope(&params, current_block_->scope);
1248 1247
1249 // Receiver is local 0. 1248 // Receiver is local 0.
1250 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1249 LocalVariable* receiver = current_block_->scope->VariableAt(0);
1251 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver); 1250 LoadLocalNode* load_receiver = new LoadLocalNode(ident_pos, receiver);
1252 1251
1253 ClosureNode* closure = new ClosureNode( 1252 ClosureNode* closure = new ClosureNode(
1254 ident_pos, 1253 ident_pos,
1255 Function::ZoneHandle(func.extracted_method_closure()), 1254 Function::ZoneHandle(func.extracted_method_closure()),
1256 load_receiver, 1255 load_receiver,
1257 NULL); 1256 NULL);
1258 1257
1259 ReturnNode* return_node = new ReturnNode(invisible_pos, closure); 1258 ReturnNode* return_node = new ReturnNode(Scanner::kNoSourcePos, closure);
1260 current_block_->statements->Add(return_node); 1259 current_block_->statements->Add(return_node);
1261 return CloseBlock(); 1260 return CloseBlock();
1262 } 1261 }
1263 1262
1264 1263
1265 void Parser::BuildDispatcherScope(const Function& func, 1264 void Parser::BuildDispatcherScope(const Function& func,
1266 const ArgumentsDescriptor& desc, 1265 const ArgumentsDescriptor& desc,
1267 Array& default_values) { 1266 Array& default_values) {
1268 ParamList params; 1267 ParamList params;
1269 // Receiver first. 1268 // Receiver first.
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 } 2413 }
2415 current_block_->statements->Add( 2414 current_block_->statements->Add(
2416 new StaticCallNode(call_pos, redirect_ctor, arguments)); 2415 new StaticCallNode(call_pos, redirect_ctor, arguments));
2417 } 2416 }
2418 2417
2419 2418
2420 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { 2419 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) {
2421 ASSERT(func.IsConstructor()); 2420 ASSERT(func.IsConstructor());
2422 ASSERT(func.Owner() == current_class().raw()); 2421 ASSERT(func.Owner() == current_class().raw());
2423 const intptr_t ctor_pos = TokenPos(); 2422 const intptr_t ctor_pos = TokenPos();
2424 const intptr_t dummy_pos = Scanner::kDummyTokenIndex;
2425 OpenFunctionBlock(func); 2423 OpenFunctionBlock(func);
2426 2424
2427 LocalVariable* receiver = new LocalVariable( 2425 LocalVariable* receiver = new LocalVariable(
2428 dummy_pos, Symbols::This(), *ReceiverType(current_class())); 2426 Scanner::kNoSourcePos, Symbols::This(), *ReceiverType(current_class()));
2429 current_block_->scope->AddVariable(receiver); 2427 current_block_->scope->AddVariable(receiver);
2430 2428
2431 LocalVariable* phase_parameter = new LocalVariable( 2429 LocalVariable* phase_parameter =
2432 dummy_pos, Symbols::PhaseParameter(), Type::ZoneHandle(Type::SmiType())); 2430 new LocalVariable(Scanner::kNoSourcePos,
2431 Symbols::PhaseParameter(),
2432 Type::ZoneHandle(Type::SmiType()));
2433 current_block_->scope->AddVariable(phase_parameter); 2433 current_block_->scope->AddVariable(phase_parameter);
2434 2434
2435 // Parse expressions of instance fields that have an explicit 2435 // Parse expressions of instance fields that have an explicit
2436 // initializer expression. 2436 // initializer expression.
2437 // The receiver must not be visible to field initializer expressions. 2437 // The receiver must not be visible to field initializer expressions.
2438 receiver->set_invisible(true); 2438 receiver->set_invisible(true);
2439 GrowableArray<Field*> initialized_fields; 2439 GrowableArray<Field*> initialized_fields;
2440 ParseInitializedInstanceFields( 2440 ParseInitializedInstanceFields(
2441 current_class(), receiver, &initialized_fields); 2441 current_class(), receiver, &initialized_fields);
2442 receiver->set_invisible(false); 2442 receiver->set_invisible(false);
(...skipping 15 matching lines...) Expand all
2458 // whether optional parameters are even allowed in this situation. 2458 // whether optional parameters are even allowed in this situation.
2459 // TODO(hausner): Remove this limitation if the language spec indeed 2459 // TODO(hausner): Remove this limitation if the language spec indeed
2460 // allows optional parameters. 2460 // allows optional parameters.
2461 if (func.HasOptionalParameters()) { 2461 if (func.HasOptionalParameters()) {
2462 ErrorMsg(ctor_pos, 2462 ErrorMsg(ctor_pos,
2463 "forwarding constructors must not have optional parameters"); 2463 "forwarding constructors must not have optional parameters");
2464 } 2464 }
2465 2465
2466 // Prepare user-defined arguments to be forwarded to super call. 2466 // Prepare user-defined arguments to be forwarded to super call.
2467 // The first user-defined argument is at position 2. 2467 // The first user-defined argument is at position 2.
2468 forwarding_args = new ArgumentListNode(dummy_pos); 2468 forwarding_args = new ArgumentListNode(Scanner::kNoSourcePos);
2469 for (int i = 2; i < func.NumParameters(); i++) { 2469 for (int i = 2; i < func.NumParameters(); i++) {
2470 LocalVariable* param = new LocalVariable( 2470 LocalVariable* param = new LocalVariable(
2471 dummy_pos, 2471 Scanner::kNoSourcePos,
2472 String::ZoneHandle(func.ParameterNameAt(i)), 2472 String::ZoneHandle(func.ParameterNameAt(i)),
2473 Type::ZoneHandle(Type::DynamicType())); 2473 Type::ZoneHandle(Type::DynamicType()));
2474 current_block_->scope->AddVariable(param); 2474 current_block_->scope->AddVariable(param);
2475 forwarding_args->Add(new LoadLocalNode(dummy_pos, param)); 2475 forwarding_args->Add(new LoadLocalNode(Scanner::kNoSourcePos, param));
2476 } 2476 }
2477 } 2477 }
2478 2478
2479 GenerateSuperConstructorCall(current_class(), 2479 GenerateSuperConstructorCall(current_class(),
2480 dummy_pos, 2480 Scanner::kNoSourcePos,
2481 receiver, 2481 receiver,
2482 forwarding_args); 2482 forwarding_args);
2483 CheckFieldsInitialized(current_class()); 2483 CheckFieldsInitialized(current_class());
2484 2484
2485 // Empty constructor body. 2485 // Empty constructor body.
2486 current_block_->statements->Add(new ReturnNode(dummy_pos)); 2486 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos));
2487 SequenceNode* statements = CloseBlock(); 2487 SequenceNode* statements = CloseBlock();
2488 return statements; 2488 return statements;
2489 } 2489 }
2490 2490
2491 2491
2492 void Parser::CheckRecursiveInvocation() { 2492 void Parser::CheckRecursiveInvocation() {
2493 const GrowableObjectArray& pending_functions = 2493 const GrowableObjectArray& pending_functions =
2494 GrowableObjectArray::Handle( 2494 GrowableObjectArray::Handle(
2495 isolate()->object_store()->pending_functions()); 2495 isolate()->object_store()->pending_functions());
2496 for (int i = 0; i < pending_functions.Length(); i++) { 2496 for (int i = 0; i < pending_functions.Length(); i++) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 2637
2638 SequenceNode* init_statements = CloseBlock(); 2638 SequenceNode* init_statements = CloseBlock();
2639 if (is_redirecting_constructor) { 2639 if (is_redirecting_constructor) {
2640 // A redirecting super constructor simply passes the phase parameter on to 2640 // A redirecting super constructor simply passes the phase parameter on to
2641 // the target which executes the corresponding phase. 2641 // the target which executes the corresponding phase.
2642 current_block_->statements->Add(init_statements); 2642 current_block_->statements->Add(init_statements);
2643 } else if (init_statements->length() > 0) { 2643 } else if (init_statements->length() > 0) {
2644 // Generate guard around the initializer code. 2644 // Generate guard around the initializer code.
2645 LocalVariable* phase_param = LookupPhaseParameter(); 2645 LocalVariable* phase_param = LookupPhaseParameter();
2646 AstNode* phase_value = new 2646 AstNode* phase_value = new
2647 LoadLocalNode(Scanner::kDummyTokenIndex, phase_param); 2647 LoadLocalNode(Scanner::kNoSourcePos, phase_param);
2648 AstNode* phase_check = new BinaryOpNode( 2648 AstNode* phase_check = new BinaryOpNode(
2649 Scanner::kDummyTokenIndex, Token::kBIT_AND, phase_value, 2649 Scanner::kNoSourcePos, Token::kBIT_AND, phase_value,
2650 new LiteralNode(Scanner::kDummyTokenIndex, 2650 new LiteralNode(Scanner::kNoSourcePos,
2651 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); 2651 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit))));
2652 AstNode* comparison = 2652 AstNode* comparison =
2653 new ComparisonNode(Scanner::kDummyTokenIndex, 2653 new ComparisonNode(Scanner::kNoSourcePos,
2654 Token::kNE_STRICT, 2654 Token::kNE_STRICT,
2655 phase_check, 2655 phase_check,
2656 new LiteralNode(TokenPos(), 2656 new LiteralNode(TokenPos(),
2657 Smi::ZoneHandle(Smi::New(0)))); 2657 Smi::ZoneHandle(Smi::New(0))));
2658 AstNode* guarded_init_statements = 2658 AstNode* guarded_init_statements =
2659 new IfNode(Scanner::kDummyTokenIndex, 2659 new IfNode(Scanner::kNoSourcePos,
2660 comparison, 2660 comparison,
2661 init_statements, 2661 init_statements,
2662 NULL); 2662 NULL);
2663 current_block_->statements->Add(guarded_init_statements); 2663 current_block_->statements->Add(guarded_init_statements);
2664 } 2664 }
2665 2665
2666 // Parsing of initializers done. Now we parse the constructor body 2666 // Parsing of initializers done. Now we parse the constructor body
2667 // and add the implicit super call to the super constructor's body 2667 // and add the implicit super call to the super constructor's body
2668 // if necessary. 2668 // if necessary.
2669 StaticCallNode* super_call = NULL; 2669 StaticCallNode* super_call = NULL;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 ConsumeToken(); 2768 ConsumeToken();
2769 } else { 2769 } else {
2770 UnexpectedToken(); 2770 UnexpectedToken();
2771 } 2771 }
2772 2772
2773 SequenceNode* ctor_block = CloseBlock(); 2773 SequenceNode* ctor_block = CloseBlock();
2774 if (ctor_block->length() > 0) { 2774 if (ctor_block->length() > 0) {
2775 // Generate guard around the constructor body code. 2775 // Generate guard around the constructor body code.
2776 LocalVariable* phase_param = LookupPhaseParameter(); 2776 LocalVariable* phase_param = LookupPhaseParameter();
2777 AstNode* phase_value = 2777 AstNode* phase_value =
2778 new LoadLocalNode(Scanner::kDummyTokenIndex, phase_param); 2778 new LoadLocalNode(Scanner::kNoSourcePos, phase_param);
2779 AstNode* phase_check = 2779 AstNode* phase_check =
2780 new BinaryOpNode(Scanner::kDummyTokenIndex, Token::kBIT_AND, 2780 new BinaryOpNode(Scanner::kNoSourcePos, Token::kBIT_AND,
2781 phase_value, 2781 phase_value,
2782 new LiteralNode(Scanner::kDummyTokenIndex, 2782 new LiteralNode(Scanner::kNoSourcePos,
2783 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody)))); 2783 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody))));
2784 AstNode* comparison = 2784 AstNode* comparison =
2785 new ComparisonNode(Scanner::kDummyTokenIndex, 2785 new ComparisonNode(Scanner::kNoSourcePos,
2786 Token::kNE_STRICT, 2786 Token::kNE_STRICT,
2787 phase_check, 2787 phase_check,
2788 new LiteralNode(body_pos, 2788 new LiteralNode(body_pos,
2789 Smi::ZoneHandle(Smi::New(0)))); 2789 Smi::ZoneHandle(Smi::New(0))));
2790 AstNode* guarded_block_statements = 2790 AstNode* guarded_block_statements =
2791 new IfNode(Scanner::kDummyTokenIndex, comparison, ctor_block, NULL); 2791 new IfNode(Scanner::kNoSourcePos, comparison, ctor_block, NULL);
2792 current_block_->statements->Add(guarded_block_statements); 2792 current_block_->statements->Add(guarded_block_statements);
2793 } 2793 }
2794 current_block_->statements->Add(new ReturnNode(func.end_token_pos())); 2794 current_block_->statements->Add(new ReturnNode(func.end_token_pos()));
2795 SequenceNode* statements = CloseBlock(); 2795 SequenceNode* statements = CloseBlock();
2796 return statements; 2796 return statements;
2797 } 2797 }
2798 2798
2799 2799
2800 // Parser is at the opening parenthesis of the formal parameter 2800 // Parser is at the opening parenthesis of the formal parameter
2801 // declaration of the function or constructor. 2801 // declaration of the function or constructor.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2952 func.set_end_token_pos(end_token_pos); 2952 func.set_end_token_pos(end_token_pos);
2953 SequenceNode* body = CloseBlock(); 2953 SequenceNode* body = CloseBlock();
2954 current_block_->statements->Add(body); 2954 current_block_->statements->Add(body);
2955 innermost_function_ = saved_innermost_function.raw(); 2955 innermost_function_ = saved_innermost_function.raw();
2956 last_used_try_index_ = saved_try_index; 2956 last_used_try_index_ = saved_try_index;
2957 return CloseBlock(); 2957 return CloseBlock();
2958 } 2958 }
2959 2959
2960 2960
2961 void Parser::AddEqualityNullCheck() { 2961 void Parser::AddEqualityNullCheck() {
2962 const intptr_t dummy_pos = Scanner::kDummyTokenIndex;
2963 AstNode* argument = 2962 AstNode* argument =
2964 new LoadLocalNode(dummy_pos, 2963 new LoadLocalNode(Scanner::kNoSourcePos,
2965 current_block_->scope->parent()->VariableAt(1)); 2964 current_block_->scope->parent()->VariableAt(1));
2966 LiteralNode* null_operand = 2965 LiteralNode* null_operand =
2967 new LiteralNode(dummy_pos, Instance::ZoneHandle()); 2966 new LiteralNode(Scanner::kNoSourcePos, Instance::ZoneHandle());
2968 ComparisonNode* check_arg = new ComparisonNode(dummy_pos, 2967 ComparisonNode* check_arg =
2969 Token::kEQ_STRICT, 2968 new ComparisonNode(Scanner::kNoSourcePos,
2970 argument, 2969 Token::kEQ_STRICT,
2971 null_operand); 2970 argument,
2972 ComparisonNode* result = new ComparisonNode(dummy_pos, 2971 null_operand);
2973 Token::kEQ_STRICT, 2972 ComparisonNode* result =
2974 LoadReceiver(dummy_pos), 2973 new ComparisonNode(Scanner::kNoSourcePos,
2975 null_operand); 2974 Token::kEQ_STRICT,
2976 SequenceNode* arg_is_null = new SequenceNode(dummy_pos, NULL); 2975 LoadReceiver(Scanner::kNoSourcePos),
2977 arg_is_null->Add(new ReturnNode(dummy_pos, result)); 2976 null_operand);
2978 IfNode* if_arg_null = new IfNode(dummy_pos, 2977 SequenceNode* arg_is_null = new SequenceNode(Scanner::kNoSourcePos, NULL);
2978 arg_is_null->Add(new ReturnNode(Scanner::kNoSourcePos, result));
2979 IfNode* if_arg_null = new IfNode(Scanner::kNoSourcePos,
2979 check_arg, 2980 check_arg,
2980 arg_is_null, 2981 arg_is_null,
2981 NULL); 2982 NULL);
2982 current_block_->statements->Add(if_arg_null); 2983 current_block_->statements->Add(if_arg_null);
2983 } 2984 }
2984 2985
2985 2986
2986 void Parser::SkipIf(Token::Kind token) { 2987 void Parser::SkipIf(Token::Kind token) {
2987 if (CurrentToken() == token) { 2988 if (CurrentToken() == token) {
2988 ConsumeToken(); 2989 ConsumeToken();
(...skipping 7801 matching lines...) Expand 10 before | Expand all | Expand 10 after
10790 void Parser::SkipQualIdent() { 10791 void Parser::SkipQualIdent() {
10791 ASSERT(IsIdentifier()); 10792 ASSERT(IsIdentifier());
10792 ConsumeToken(); 10793 ConsumeToken();
10793 if (CurrentToken() == Token::kPERIOD) { 10794 if (CurrentToken() == Token::kPERIOD) {
10794 ConsumeToken(); // Consume the kPERIOD token. 10795 ConsumeToken(); // Consume the kPERIOD token.
10795 ExpectIdentifier("identifier expected after '.'"); 10796 ExpectIdentifier("identifier expected after '.'");
10796 } 10797 }
10797 } 10798 }
10798 10799
10799 } // namespace dart 10800 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/runtime_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698